Make sheet window scalable

This commit is contained in:
Matthias Neeracher 2006-12-02 23:05:12 +00:00
parent afe4f8078d
commit 94f23e92f2
9 changed files with 58 additions and 28 deletions

View File

@ -1,7 +1,7 @@
{ {
IBClasses = ( IBClasses = (
{ {
ACTIONS = {engrave = id; showLog = id; showOutput = id; }; ACTIONS = {engrave = id; showLog = id; showOutput = id; zoomIn = id; zoomOut = id; };
CLASS = FirstResponder; CLASS = FirstResponder;
LANGUAGE = ObjC; LANGUAGE = ObjC;
SUPERCLASS = NSObject; SUPERCLASS = NSObject;
@ -30,7 +30,14 @@
{ {
CLASS = VLSheetWindow; CLASS = VLSheetWindow;
LANGUAGE = ObjC; LANGUAGE = ObjC;
OUTLETS = {logToolItem = id; outputToolItem = id; playToolItem = id; runToolItem = id; }; OUTLETS = {
logToolItem = id;
outputToolItem = id;
playToolItem = id;
runToolItem = id;
zoomInToolItem = id;
zoomOutToolItem = id;
};
SUPERCLASS = NSWindowController; SUPERCLASS = NSWindowController;
} }
); );

Binary file not shown.

View File

@ -1,7 +1,13 @@
{ {
IBClasses = ( IBClasses = (
{ {
ACTIONS = {"" = id; }; ACTIONS = {
"" = id;
goToNextPage = id;
goToPreviousPage = id;
zoomIn = id;
zoomOut = id;
};
CLASS = FirstResponder; CLASS = FirstResponder;
LANGUAGE = ObjC; LANGUAGE = ObjC;
SUPERCLASS = NSObject; SUPERCLASS = NSObject;

View File

@ -3,15 +3,15 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>IBDocumentLocation</key> <key>IBDocumentLocation</key>
<string>57 42 356 240 0 0 1024 746 </string> <string>79 46 356 240 0 0 1280 778 </string>
<key>IBFramework Version</key> <key>IBFramework Version</key>
<string>453.0</string> <string>453.0</string>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>11</integer>
<integer>5</integer> <integer>5</integer>
<integer>11</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>9A294</string> <string>9A300</string>
</dict> </dict>
</plist> </plist>

Binary file not shown.

View File

@ -55,6 +55,7 @@ enum VLRecalc {
@class VLEditable; @class VLEditable;
@interface VLSheetView : NSView { @interface VLSheetView : NSView {
NSImage ** fMusic;
VLRecalc fNeedsRecalc; VLRecalc fNeedsRecalc;
char fClickMode; char fClickMode;
float fClefKeyW; float fClefKeyW;

View File

@ -19,8 +19,6 @@
@implementation VLSheetView @implementation VLSheetView
static NSImage ** sMusic;
static NSString * sElementNames[kMusicElements] = { static NSString * sElementNames[kMusicElements] = {
@"g-clef", @"g-clef",
@"flat", @"flat",
@ -70,20 +68,18 @@ static float sFlatPos[] = {
{ {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
if (!sMusic) { NSBundle * b = [NSBundle mainBundle];
NSBundle * b = [NSBundle mainBundle]; fMusic = new NSImage * [kMusicElements];
sMusic = new NSImage * [kMusicElements]; for (int i=0; i<kMusicElements; ++i) {
for (int i=0; i<kMusicElements; ++i) { NSString * name =
NSString * name = [b pathForResource:sElementNames[i] ofType:@"eps"
[b pathForResource:sElementNames[i] ofType:@"eps" inDirectory:@"Music"];
inDirectory:@"Music"]; fMusic[i] = [[NSImage alloc] initByReferencingFile: name];
sMusic[i] = [[NSImage alloc] initWithContentsOfFile: name]; NSSize sz = [fMusic[i] size];
NSSize sz = [sMusic[i] size]; sz.width *= kImgScale;
sz.width *= kImgScale; sz.height*= kImgScale;
sz.height*= kImgScale; [fMusic[i] setScalesWhenResized:YES];
[sMusic[i] setScalesWhenResized:YES]; [fMusic[i] setSize:sz];
[sMusic[i] setSize:sz];
}
} }
fNeedsRecalc = kFirstRecalc; fNeedsRecalc = kFirstRecalc;
fClickMode = ' '; fClickMode = ' ';
@ -120,7 +116,7 @@ static float sFlatPos[] = {
- (NSImage *) musicElement:(VLMusicElement)elt - (NSImage *) musicElement:(VLMusicElement)elt
{ {
return sMusic[elt]; return fMusic[elt];
} }
- (float) systemY:(int)system - (float) systemY:(int)system
@ -255,8 +251,10 @@ VLMusicElement sSemi2Accidental[12][12] = {
NSScrollView * scroll = [self enclosingScrollView]; NSScrollView * scroll = [self enclosingScrollView];
NSSize sz = [scroll contentSize]; NSSize sz = [scroll contentSize];
#if 0
sz.width *= fDisplayScale; sz.width *= fDisplayScale;
sz.height *= fDisplayScale; sz.height *= fDisplayScale;
#endif
const VLSong * song = [self song]; const VLSong * song = [self song];
const VLProperties & prop = song->fProperties.front(); const VLProperties & prop = song->fProperties.front();
@ -266,7 +264,7 @@ VLMusicElement sSemi2Accidental[12][12] = {
fDivPerGroup = prop.fDivisions * (fQuarterBeats / fGroups); fDivPerGroup = prop.fDivisions * (fQuarterBeats / fGroups);
fClefKeyW = kClefX+kClefW+(std::labs(prop.fKey)+1)*kKeyW; fClefKeyW = kClefX+kClefW+(std::labs(prop.fKey)+1)*kKeyW;
fMeasureW = fGroups*(fDivPerGroup+1)*kNoteW; fMeasureW = fGroups*(fDivPerGroup+1)*kNoteW;
fMeasPerSystem = (int)std::floor((sz.width-fClefKeyW) / fMeasureW); fMeasPerSystem = std::max<int>(1, std::floor((sz.width-fClefKeyW) / fDisplayScale / fMeasureW));
fNumSystems = (song->CountMeasures()+fMeasPerSystem-1)/fMeasPerSystem; fNumSystems = (song->CountMeasures()+fMeasPerSystem-1)/fMeasPerSystem;
sz.height = fNumSystems*kSystemH; sz.height = fNumSystems*kSystemH;
@ -720,21 +718,26 @@ static int8_t sSharpAcc[] = {
- (void) setScaleFactor:(float)scale - (void) setScaleFactor:(float)scale
{ {
float ratio = scale/fDisplayScale;
for (int i=0; i<kMusicElements; ++i) {
NSSize sz = [fMusic[i] size];
sz.width *= ratio;
sz.height*= ratio;
[fMusic[i] setSize:sz];
}
fDisplayScale= scale; fDisplayScale= scale;
fNeedsRecalc = kRecalc; fNeedsRecalc = kRecalc;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
#if 0
- (IBAction) zoomIn: (id) sender - (IBAction) zoomIn: (id) sender
{ {
[self setScaleFactor: fDisplayScale * sqrt(2.0)]; [self setScaleFactor: fDisplayScale * sqrt(sqrt(2.0))];
} }
- (IBAction) zoomOut: (id) sender - (IBAction) zoomOut: (id) sender
{ {
[self setScaleFactor: fDisplayScale / sqrt(2.0)]; [self setScaleFactor: fDisplayScale / sqrt(sqrt(2.0))];
} }
#endif
@end @end

View File

@ -28,6 +28,8 @@
IBOutlet id outputToolItem; IBOutlet id outputToolItem;
IBOutlet id logToolItem; IBOutlet id logToolItem;
IBOutlet id playToolItem; IBOutlet id playToolItem;
IBOutlet id zoomInToolItem;
IBOutlet id zoomOutToolItem;
} }
- (VLEditable *) editTarget; - (VLEditable *) editTarget;

View File

@ -47,6 +47,8 @@ static NSString* sOutputToolbarItemIdentifier = @"Output Toolbar Item Identifie
static NSString* sLogToolbarItemIdentifier = @"Log Toolbar Item Identifier"; static NSString* sLogToolbarItemIdentifier = @"Log Toolbar Item Identifier";
static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier"; static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier"; static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
static NSString* sZoomInToolbarItemIdentifier = @"Zoom In Toolbar Item Identifier";
static NSString* sZoomOutToolbarItemIdentifier = @"Zoom Out Toolbar Item Identifier";
- (id)initWithWindow:(NSWindow *)window - (id)initWithWindow:(NSWindow *)window
{ {
@ -90,6 +92,10 @@ static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
prototype = runToolItem; prototype = runToolItem;
else if ([itemIdent isEqual: sPlayToolbarItemIdentifier]) else if ([itemIdent isEqual: sPlayToolbarItemIdentifier])
prototype = playToolItem; prototype = playToolItem;
else if ([itemIdent isEqual: sZoomInToolbarItemIdentifier])
prototype = zoomInToolItem;
else if ([itemIdent isEqual: sZoomOutToolbarItemIdentifier])
prototype = zoomOutToolItem;
if (prototype) { if (prototype) {
toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease]; toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
@ -110,6 +116,9 @@ static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
return [NSArray arrayWithObjects: return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier, sRunToolbarItemIdentifier,
sPlayToolbarItemIdentifier, sPlayToolbarItemIdentifier,
NSToolbarSeparatorItemIdentifier,
sZoomInToolbarItemIdentifier,
sZoomOutToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
sOutputToolbarItemIdentifier, sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier, nil]; sLogToolbarItemIdentifier, nil];
@ -119,6 +128,8 @@ static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
return [NSArray arrayWithObjects: return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier, sRunToolbarItemIdentifier,
sPlayToolbarItemIdentifier, sPlayToolbarItemIdentifier,
sZoomInToolbarItemIdentifier,
sZoomOutToolbarItemIdentifier,
sOutputToolbarItemIdentifier, sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier, sLogToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier, NSToolbarCustomizeToolbarItemIdentifier,