@@ -34,6 +34,30 @@ @implementation MyDigitalStick
34
34
@synthesize left = bLeft;
35
35
@synthesize right = bRight;
36
36
37
+ - (void )setUp : (BOOL )anup
38
+ {
39
+ bUp = anup;
40
+ self.needsDisplay = YES ;
41
+ }
42
+
43
+ - (void )setDown : (BOOL )adown
44
+ {
45
+ bDown = adown;
46
+ self.needsDisplay = YES ;
47
+ }
48
+
49
+ - (void )setLeft : (BOOL )aleft
50
+ {
51
+ bLeft = aleft;
52
+ self.needsDisplay = YES ;
53
+ }
54
+
55
+ - (void )setRight : (BOOL )aright
56
+ {
57
+ bRight = aright;
58
+ self.needsDisplay = YES ;
59
+ }
60
+
37
61
+ (NSBezierPath *)makeTriangle : (int )start inRectangle : (NSRect )rect ;
38
62
{
39
63
// Create path
@@ -68,11 +92,6 @@ - (id)initWithFrame:(NSRect)frameRect
68
92
if ((self = [super initWithFrame: frameRect]) != nil ) {
69
93
NSRect rect = [self bounds ], triangle;
70
94
71
- [self addObserver: self forKeyPath: @" up" options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
72
- [self addObserver: self forKeyPath: @" down" options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
73
- [self addObserver: self forKeyPath: @" left" options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
74
- [self addObserver: self forKeyPath: @" right" options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
75
-
76
95
triangle.origin .x = INSET_AMOUNT;
77
96
triangle.origin .y = INSET_AMOUNT;
78
97
triangle.size .width =- INSET_AMOUNT * 2 ;
@@ -93,21 +112,6 @@ - (id)initWithFrame:(NSRect)frameRect
93
112
return self;
94
113
}
95
114
96
- - (void )dealloc
97
- {
98
- [self removeObserver: self forKeyPath: @" up" ];
99
- [self removeObserver: self forKeyPath: @" down" ];
100
- [self removeObserver: self forKeyPath: @" left" ];
101
- [self removeObserver: self forKeyPath: @" right" ];
102
- }
103
-
104
- - (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context
105
- {
106
- if (object == self) {
107
- [self setNeedsDisplay: YES ];
108
- }
109
- }
110
-
111
115
- (void )drawRect : (NSRect )rect
112
116
{
113
117
NSRect area = [self bounds ];
0 commit comments