char gen.

This commit is contained in:
Kelvin Sherlock 2018-02-28 10:23:44 -05:00
parent e7ebb7b573
commit 0bc20c6fa8
5 changed files with 46 additions and 13 deletions

View File

@ -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> *)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.

View File

@ -8,6 +8,7 @@
#import <AppKit/AppKit.h>
@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

View File

@ -85,6 +85,11 @@
[super setBackgroundColor: color];
}
-(void)setTitleCharacterGenerator: (CharacterGenerator *)characterGenerator {
[_textLabel setCharacterGenerator: characterGenerator];
}
-(void)awakeFromNib
{

View File

@ -8,12 +8,15 @@
#import <Cocoa/Cocoa.h>
@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

View File

@ -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];
}