Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Highlight keys in virtual Keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrajca committed Jun 5, 2012
1 parent e2f635f commit f7a558b
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Classes/KeyboardView.m
Expand Up @@ -26,6 +26,7 @@ @implementation Key

@implementation KeyboardView {
NSMutableArray *_keys;
Key *_selectedKey;
}

#define BLACK_KEY_OFFSET 14.0f
Expand Down Expand Up @@ -87,18 +88,28 @@ - (void)drawRect:(NSRect)dirtyRect {
[[NSColor colorWithCalibratedWhite:0.4f alpha:1.0f] set];
NSRectFill([self bounds]);

[[NSColor whiteColor] set];

for (Key *key in _keys) {
if (key.white)
if (key.white) {
[[NSColor whiteColor] set];
NSRectFill(key.frame);

if (key == _selectedKey) {
[[NSColor blueColor] set];
NSRectFill(key.frame);
}
}
}

[[NSColor blackColor] set];

for (Key *key in _keys) {
if (!key.white)
if (!key.white) {
[[NSColor blackColor] set];
NSRectFill(key.frame);

if (key == _selectedKey) {
[[NSColor blueColor] set];
NSRectFill(NSInsetRect(key.frame, 2.0f, 2.0f));
}
}
}
}

Expand All @@ -119,17 +130,21 @@ - (Key *)keyWithEvent:(NSEvent *)event {
}

- (void)mouseDown:(NSEvent *)theEvent {
Key *key = [self keyWithEvent:theEvent];
_selectedKey = [self keyWithEvent:theEvent];

if (_selectedKey)
[_delegate keyboardView:self noteOn:_selectedKey.value];

if (key)
[_delegate keyboardView:self noteOn:key.value];
[self setNeedsDisplay:YES];
}

- (void)mouseUp:(NSEvent *)theEvent {
Key *key = [self keyWithEvent:theEvent];
if (_selectedKey) {
[_delegate keyboardView:self noteOff:_selectedKey.value];
_selectedKey = nil;
}

if (key)
[_delegate keyboardView:self noteOff:key.value];
[self setNeedsDisplay:YES];
}

@end

0 comments on commit f7a558b

Please sign in to comment.