Centralize drawing method (tried to switch to drawAtPoint, but that does the wrong thing)

This commit is contained in:
Matthias Neeracher 2012-05-19 22:37:58 +02:00
parent 0487d549e2
commit 86456c8422
4 changed files with 33 additions and 30 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -5,7 +5,7 @@
// //
// (MN) Matthias Neeracher // (MN) Matthias Neeracher
// //
// Copyright © 2005-2011 Matthias Neeracher // Copyright © 2005-2012 Matthias Neeracher
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@ -161,6 +161,13 @@ const uint32_t kNoMeasure = (uint32_t)-1;
@end @end
@interface NSImage (VLSheetViewDrawing)
- (void) drawAllAtPoint:(NSPoint)p operation:(NSCompositingOperation)op;
- (void) drawAllAtPoint:(NSPoint)p;
@end
// Local Variables: // Local Variables:
// mode:ObjC // mode:ObjC
// End: // End:

View File

@ -457,9 +457,7 @@ const char * sBreak[3] = {"", "\xE2\xA4\xBE", "\xE2\x8E\x98"};
[bz setLineWidth:2.0]; [bz setLineWidth:2.0];
} }
if (song->fGoToCoda == m || song->fCoda == m) if (song->fGoToCoda == m || song->fCoda == m)
[[self musicElement:kMusicCoda] [[self musicElement:kMusicCoda] drawAllAtPoint:NSMakePoint(x+kCodaX, yy+kCodaY)];
compositeToPoint: NSMakePoint(x+kCodaX, yy+kCodaY)
operation: NSCompositeSourceOver];
} }
} }
@ -485,9 +483,7 @@ const char * sBreak[3] = {"", "\xE2\xA4\xBE", "\xE2\x8E\x98"};
// //
// Draw clef // Draw clef
// //
[[self musicElement:kMusicGClef] [[self musicElement:kMusicGClef] drawAllAtPoint:NSMakePoint(kClefX, kSystemY+kClefY)];
compositeToPoint: NSMakePoint(kClefX, kSystemY+kClefY)
operation: NSCompositeSourceOver];
// //
// Draw measure # // Draw measure #
// //
@ -500,19 +496,13 @@ const char * sBreak[3] = {"", "\xE2\xA4\xBE", "\xE2\x8E\x98"};
if (kProp.fKey > 0) { if (kProp.fKey > 0) {
float x = kClefX+kClefW; float x = kClefX+kClefW;
for (int i=0; i<kProp.fKey; ++i) { for (int i=0; i<kProp.fKey; ++i) {
[[self musicElement:kMusicSharp] [[self musicElement:kMusicSharp] drawAllAtPoint:NSMakePoint(x, kSystemY+sSharpPos[i]+kSharpY)];
compositeToPoint:
NSMakePoint(x, kSystemY+sSharpPos[i]+kSharpY)
operation: NSCompositeSourceOver];
x += kAccW; x += kAccW;
} }
} else if (kProp.fKey < 0) { } else if (kProp.fKey < 0) {
float x = kClefX+kClefW; float x = kClefX+kClefW;
for (int i=0; -i>kProp.fKey; ++i) { for (int i=0; -i>kProp.fKey; ++i) {
[[self musicElement: kMusicFlat] [[self musicElement: kMusicFlat] drawAllAtPoint:NSMakePoint(x, kSystemY+sFlatPos[i]+kFlatY)];
compositeToPoint:
NSMakePoint(x, kSystemY+sFlatPos[i]+kFlatY)
operation: NSCompositeSourceOver];
x += kAccW; x += kAccW;
} }
} }
@ -1051,3 +1041,17 @@ const float kSemiFloor = -1.0f*kLineH;
@end @end
@implementation NSImage (VLSheetViewDrawing)
- (void) drawAllAtPoint:(NSPoint)p operation:(NSCompositingOperation)op
{
[self compositeToPoint:p operation:op];
}
- (void) drawAllAtPoint:(NSPoint)p
{
[self compositeToPoint:p operation:NSCompositeSourceOver];
}
@end

View File

@ -127,9 +127,7 @@
} }
NSPoint xy = NSMakePoint(cursorX-kNoteX, cursorY); NSPoint xy = NSMakePoint(cursorX-kNoteX, cursorY);
[[self musicElement:cursorElt] [[self musicElement:cursorElt] drawAllAtPoint:xy];
compositeToPoint:xy
operation: NSCompositeSourceOver];
if (accidental) { if (accidental) {
xy.y += kNoteY; xy.y += kNoteY;
@ -156,9 +154,7 @@
xy.y += kNaturalY; xy.y += kNaturalY;
break; break;
} }
[[self musicElement:accidental] [[self musicElement:accidental] drawAllAtPoint:xy];
compositeToPoint:xy
operation: NSCompositeSourceOver];
} }
} }
@ -198,8 +194,7 @@
s.x -= 2.0f; s.x -= 2.0f;
break; break;
} }
[head compositeToPoint:p [head drawAllAtPoint:p operation:NSCompositePlusDarker];
operation: NSCompositePlusDarker];
// //
// Draw accidental // Draw accidental
// //
@ -230,8 +225,7 @@
default: default:
break; break;
} }
[[self musicElement:accidental] [[self musicElement:accidental] drawAllAtPoint:at];
compositeToPoint:at operation: NSCompositeSourceOver];
} }
// //
// Draw stem // Draw stem
@ -261,8 +255,7 @@
[bz lineToPoint:s1]; [bz lineToPoint:s1];
[bz stroke]; [bz stroke];
if (flag) if (flag)
[flag compositeToPoint:s [flag drawAllAtPoint:s operation:NSCompositePlusDarker];
operation: NSCompositePlusDarker];
} }
// //
// Draw tie // Draw tie
@ -319,8 +312,7 @@
p.x -= kNoteX; p.x -= kNoteX;
break; break;
} }
[head compositeToPoint:p [head drawAllAtPoint:p];
operation: NSCompositeSourceOver];
} }
- (void) drawTuplet:(uint16_t)tuplet bracketFrom:(int)startX to:(int)endX atY:(int)y - (void) drawTuplet:(uint16_t)tuplet bracketFrom:(int)startX to:(int)endX atY:(int)y