diff --git a/Views/EmulatorView.mm b/Views/EmulatorView.mm index 46a2477..31f0ff9 100644 --- a/Views/EmulatorView.mm +++ b/Views/EmulatorView.mm @@ -143,12 +143,32 @@ _screen.setFD(fd); } +-(void)setCharacterGenerator: (CharacterGenerator *)generator { + if (generator != _charGen) { + [_charGen release]; + _charGen = [generator retain]; + NSSize size = [_charGen characterSize]; + _charWidth = size.width; + _charHeight = size.height; + + } +} + +-(void)setEmulator:(NSObject *)emulator { + if (_emulator == emulator) return; + [_emulator release]; + _emulator = [emulator retain]; + if ([emulator respondsToSelector: @selector(characterGenerator)]) { + id cg = [emulator characterGenerator]; + if (cg) [self setCharacterGenerator: cg]; + } + +} + #pragma mark - -(void)awakeFromNib { - NSSize size; - _charWidth = 7; _charHeight = 16; @@ -168,7 +188,7 @@ _screen.setFD(_fd); _screen.setView(self); - _charGen = [[CharacterGenerator generator] retain]; + [self setCharacterGenerator: [CharacterGenerator generatorForCharacterSet: CGApple80]]; _cursorType = Screen::CursorTypeUnderscore; @@ -179,10 +199,6 @@ _cursors[Screen::CursorTypeCrossHatch] = [[_charGen imageForCharacter: 0x7f] retain]; - size = [_charGen characterSize]; - _charWidth = size.width; - _charHeight = size.height; - // enable drag+drop for files/urls. diff --git a/Views/EmulatorWindow.h b/Views/EmulatorWindow.h index 0aaba33..8b24db0 100644 --- a/Views/EmulatorWindow.h +++ b/Views/EmulatorWindow.h @@ -8,6 +8,7 @@ #import @class TextLabel; +@class CharacterGenerator; @interface EmulatorWindow : NSWindow { @@ -16,5 +17,5 @@ @property (assign) IBOutlet TextLabel *textLabel; -(void)setTitleTextColor: (NSColor *)color; - +-(void)setTitleCharacterGenerator: (CharacterGenerator *)characterGenerator; @end diff --git a/Views/EmulatorWindow.m b/Views/EmulatorWindow.m index 61929d3..c88d890 100644 --- a/Views/EmulatorWindow.m +++ b/Views/EmulatorWindow.m @@ -85,6 +85,11 @@ [super setBackgroundColor: color]; } +-(void)setTitleCharacterGenerator: (CharacterGenerator *)characterGenerator { + [_textLabel setCharacterGenerator: characterGenerator]; +} + + -(void)awakeFromNib { diff --git a/Views/TextLabel.h b/Views/TextLabel.h index c56993c..87616de 100644 --- a/Views/TextLabel.h +++ b/Views/TextLabel.h @@ -8,12 +8,15 @@ #import +@class CharacterGenerator; + @interface TextLabel : NSView { NSString *_text; NSColor *_color; + CharacterGenerator *_generator; } @property (nonatomic, retain) NSString *text; @property (nonatomic, retain) NSColor *color; - +@property (nonatomic, retain) CharacterGenerator *characterGenerator; @end diff --git a/Views/TextLabel.m b/Views/TextLabel.m index 5b4dcc8..5bcd30e 100644 --- a/Views/TextLabel.m +++ b/Views/TextLabel.m @@ -14,6 +14,7 @@ @synthesize text = _text; @synthesize color = _color; +@synthesize characterGenerator = _characterGenerator; -(void) setText:(NSString *)text { if (_text == text) return; @@ -29,6 +30,14 @@ [self setNeedsDisplay: YES]; } +-(void) setCharacterGenerator:(CharacterGenerator *)characterGenerator { + if (_characterGenerator == characterGenerator) return; + [_characterGenerator release]; + _characterGenerator = [characterGenerator retain]; + [self setNeedsDisplay: YES]; +} + + /* -(BOOL)isFlipped { return YES; @@ -55,9 +64,7 @@ if (!length) return; if (!_color) return; - CharacterGenerator *gen = [CharacterGenerator generator]; - - NSSize sz = [gen characterSize]; + NSSize sz = [_characterGenerator characterSize]; NSRect frame = [self frame]; @@ -75,7 +82,7 @@ for (unsigned i = 0; i < length; ++i) { unichar c = [_text characterAtIndex: i]; - [gen drawCharacter: c atPoint: point]; + [_characterGenerator drawCharacter: c atPoint: point]; point.x += sz.width; if (point.x > NSWidth(frame)) break; } @@ -89,6 +96,7 @@ if (!_text) _text = [@"Testing!" retain]; if (!_color) _color = [[NSColor greenColor] retain]; + if (!_characterGenerator) _characterGenerator = [[CharacterGenerator generatorForCharacterSet: CGApple80] retain]; }