1#include "LED.h" 2 3 4#define LED_COLLON 10 5#define LED_NONE 11 6#define LED_MINUS 12 7 8 9@implementation LED 10 11- initWithFrame:(NSRect)frameRect 12{ 13 NSBundle *bundle = [NSBundle mainBundle]; 14 NSString *imagePath; 15 int i; 16 17 18 self = [super initWithFrame: frameRect]; 19 20 for(i = 0; i < 13; i++) 21 { 22 imagePath = [bundle pathForResource: [NSString stringWithFormat: @"led%d", i] ofType: @"tiff"]; 23 led[i] = [[NSImage alloc] initWithContentsOfFile: imagePath]; 24 if(led[i] == nil) NSLog(@"Couldn't load led%d.tiff", i); 25 } 26 27 28 return self; 29} 30 31- (void)dealloc 32{ 33 int i; 34 35 for(i = 0; i < 13; i++) 36 { 37 [led[i] release]; 38 } 39 40 [super dealloc]; 41} 42 43- (void)setTrack:(int)_track 44{ 45 track = _track; 46} 47 48- (void)setMin:(int)_min 49{ 50 min = _min; 51} 52 53- (void)setSec:(int)_sec 54{ 55 sec = _sec; 56} 57 58- (void)setNoCD 59{ 60 sec = -1; 61 min = -1; 62 track = -1; 63} 64 65- (void)drawRect:(NSRect)_rect 66{ 67 NSPoint point; 68 NSRect rect = [self bounds]; 69 float pad_x = (rect.size.width - 124) / 3; 70 float pad_y = (rect.size.height - 22) / 2; 71 72 73 // $BOH$NIA2h(B 74 PSsetgray(NSBlack); 75 NSRectFill(rect); 76 PSsetgray(NSWhite); 77 PSmoveto(1, 1); 78 PSlineto(rect.size.width - 1, 1); 79 PSlineto(rect.size.width - 1, rect.size.height); 80 PSstroke(); 81 82 // $B%3%m%s$NIA2h(B 83 point = NSMakePoint(pad_x + 40 + pad_x + 40 , pad_y); 84 [led[10] compositeToPoint: point operation: NSCompositeCopy]; 85 86 87 // $B?t;z$NItJ,$NIA2h(B 88 if(sec < 0) 89 { 90 // CD$B$,F~$C$F$$$J$$;~(B 91 point = NSMakePoint(pad_x + 40 + pad_x + 40 + 4, pad_y); 92 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 93 point = NSMakePoint(pad_x + 40 + pad_x + 40 + 4 + 20, pad_y); 94 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 95 point = NSMakePoint(pad_x + 40 + pad_x, pad_y); 96 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 97 point = NSMakePoint(pad_x + 40 + pad_x + 20, pad_y); 98 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 99 point = NSMakePoint(pad_x, pad_y); 100 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 101 point = NSMakePoint(pad_x + 20, pad_y); 102 [led[12] compositeToPoint: point operation: NSCompositeCopy]; 103 } 104 else 105 { 106 int n1; 107 int n2; 108 109 110 n1 = (sec % 100) / 10; 111 n2 = sec % 10; 112 point = NSMakePoint(pad_x + 40 + pad_x + 40 + 4, pad_y); 113 [led[n1] compositeToPoint: point operation: NSCompositeCopy]; 114 point = NSMakePoint(pad_x + 40 + pad_x + 40 + 4 + 20, pad_y ); 115 [led[n2] compositeToPoint: point operation: NSCompositeCopy]; 116 117 n1 = (min % 100) / 10; 118 n2 = min % 10; 119 point = NSMakePoint(pad_x + 40 + pad_x, pad_y); 120 [led[n1] compositeToPoint: point operation: NSCompositeCopy]; 121 point = NSMakePoint(pad_x + 40 + pad_x + 20, pad_y); 122 [led[n2] compositeToPoint: point operation: NSCompositeCopy]; 123 124 n1 = (track % 100) / 10; 125 n2 = track % 10; 126 point = NSMakePoint(pad_x, pad_y); 127 [led[n1] compositeToPoint: point operation: NSCompositeCopy]; 128 point = NSMakePoint(pad_x + 20, pad_y); 129 [led[n2] compositeToPoint: point operation: NSCompositeCopy]; 130 } 131} 132 133@end 134