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 = (
{
ACTIONS = {engrave = id; showLog = id; showOutput = id; };
ACTIONS = {engrave = id; showLog = id; showOutput = id; zoomIn = id; zoomOut = id; };
CLASS = FirstResponder;
LANGUAGE = ObjC;
SUPERCLASS = NSObject;
@ -30,7 +30,14 @@
{
CLASS = VLSheetWindow;
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;
}
);

Binary file not shown.

View File

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

View File

@ -3,15 +3,15 @@
<plist version="1.0">
<dict>
<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>
<string>453.0</string>
<key>IBOpenObjects</key>
<array>
<integer>11</integer>
<integer>5</integer>
<integer>11</integer>
</array>
<key>IBSystem Version</key>
<string>9A294</string>
<string>9A300</string>
</dict>
</plist>

Binary file not shown.

View File

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

View File

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

View File

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

View File

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