| 1 |
// |
| 2 |
// PianoRollRulerView.m |
| 3 |
// |
| 4 |
/* |
| 5 |
Copyright (c) 2000-2016 Toshi Nagata. All rights reserved. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation version 2 of the License. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
*/ |
| 16 |
|
| 17 |
#import "PianoRollRulerView.h" |
| 18 |
#import "MDHeaders.h" |
| 19 |
#import "NSWindowControllerAdditions.h" // For sharedLayoutManager |
| 20 |
|
| 21 |
@implementation PianoRollRulerView |
| 22 |
|
| 23 |
- (void)dealloc |
| 24 |
{ |
| 25 |
[labels release]; |
| 26 |
[super dealloc]; |
| 27 |
} |
| 28 |
|
| 29 |
- (void)recalcLabels |
| 30 |
{ |
| 31 |
int index, n; |
| 32 |
[labels release]; |
| 33 |
labels = [[NSMutableArray allocWithZone: [self zone]] initWithCapacity: 37]; |
| 34 |
for (index = -17; index <= +19; index++) { |
| 35 |
char name[8]; |
| 36 |
n = MDEventStaffIndexToNoteNumber(index); |
| 37 |
MDEventNoteNumberToNoteName(n, name); |
| 38 |
/* [labels addObject: |
| 39 |
[[[NSCell allocWithZone: [self zone]] |
| 40 |
initTextCell: [NSString stringWithCString: name]] autorelease]]; */ |
| 41 |
[labels addObject: [NSString stringWithUTF8String: name]]; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
- (void)drawRect:(NSRect)aRect |
| 46 |
{ |
| 47 |
// NSCell *cell; |
| 48 |
NSRect rect; |
| 49 |
float scale; |
| 50 |
NSPoint pt; |
| 51 |
int n, index; |
| 52 |
if (labels == nil) |
| 53 |
[self recalcLabels]; |
| 54 |
rect = [self bounds]; |
| 55 |
pt = NSMakePoint(rect.origin.x + rect.size.width - 0.5f, rect.origin.y); |
| 56 |
[NSBezierPath strokeLineFromPoint: pt toPoint: NSMakePoint(pt.x, pt.y + rect.size.height)]; |
| 57 |
// rect.size.height = 0.0; |
| 58 |
rect.origin.x = rect.origin.x + rect.size.width - 32.0f; |
| 59 |
rect.size.height = [[NSWindowController sharedLayoutManager] defaultLineHeightForFont:[GraphicRulerView rulerLabelFont]]; |
| 60 |
rect.size.width = 32.0f; |
| 61 |
scale = [(GraphicClientView *)[self clientView] yScale]; |
| 62 |
for (index = -17; index <= +19; index++) { |
| 63 |
n = MDEventStaffIndexToNoteNumber(index); |
| 64 |
if (n < 0 || n >= 128) |
| 65 |
continue; |
| 66 |
pt = [self convertPoint: NSMakePoint(0, n * scale) fromView: clientView]; |
| 67 |
rect.origin.y = pt.y - rect.size.height * 0.2f; |
| 68 |
if (NSIntersectsRect(rect, aRect)) { |
| 69 |
[[labels objectAtIndex: index + 17] drawAtPoint: rect.origin withAttributes: nil]; |
| 70 |
} |
| 71 |
/* cell = (NSCell *)[labels objectAtIndex: index + 17]; |
| 72 |
if (rect.size.height == 0.0) { |
| 73 |
rect.size.height = [[NSWindowManager sharedLayoutManager] defaultLineHeightForFont:[cell font]]; |
| 74 |
rect.origin.y = -rect.size.height * 2; |
| 75 |
} |
| 76 |
pt = [self convertPoint: NSMakePoint(0, n * scale) fromView: clientView]; |
| 77 |
pt.y -= rect.size.height * 0.5; |
| 78 |
if (rect.origin.y + rect.size.height <= pt.y) { |
| 79 |
rect.origin.y = pt.y; |
| 80 |
[[cell stringValue] drawAtPoint: rect.origin withAttributes: nil]; |
| 81 |
// [cell drawInteriorWithFrame: rect inView: self]; |
| 82 |
} */ |
| 83 |
} |
| 84 |
[super drawRect:aRect]; |
| 85 |
|
| 86 |
/* [[[self clientView] dataSource] setInfoText: |
| 87 |
[NSString stringWithFormat: @"frame %@, bounds %@, client: frame %@, bounds %@", |
| 88 |
NSStringFromRect([[self superview] frame]), |
| 89 |
NSStringFromRect([[self superview] bounds]), |
| 90 |
NSStringFromRect([[[self clientView] superview] frame]), |
| 91 |
NSStringFromRect([[[self clientView] superview] bounds]) |
| 92 |
]]; */ |
| 93 |
} |
| 94 |
|
| 95 |
@end |