19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
+
+
+
+
+
+
|
*/
#import "OGKDisplay.h"
#import "OGKEvent.h"
#import "OGKEventQueue.h"
#import "OGKBitmap.h"
#import "TestMain.h"
@interface TestMain ()
- (void)draw;
- (void)handleEvents;
- (void)toggleAnimation;
@end
OF_APPLICATION_DELEGATE(TestMain)
@implementation TestMain
- (void)display: (OGKDisplay*)display
wasClosed: (OGKCloseEvent*)event
{
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
+
+
+
|
break;
case OGK_KEY_LEFT:
rotation.angle -= M_PI / 128;
break;
case OGK_KEY_RIGHT:
rotation.angle += M_PI / 128;
break;
case OGK_KEY_A:
[self toggleAnimation];
break;
case OGK_KEY_Q:
running = NO;
break;
}
}
- (void)mouseWasMoved: (OGKMouseMovedEvent*)event
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
- (void)handleEvents
{
[eventQueue handleEvents];
}
- (void)draw
{
ogk_rotation_t localRotation;
@synchronized (self) {
localRotation = rotation;
}
[OGKBitmap clearToColor: OGK_COLOR_BLACK];
[bitmap drawAtPosition: position
scale: scale
rotation: rotation
rotation: localRotation
tint: tint];
[display update];
}
- (void)toggleAnimation
{
@synchronized (self) {
if (animationThread != nil) {
stopAnimation = YES;
[animationThread join];
animationThread = nil;
stopAnimation = NO;
return;
}
animationThread = [OFThread threadWithBlock: ^ (id object) {
while (!stopAnimation) {
@synchronized (self) {
rotation.angle -= M_PI / 256;
}
[OFThread sleepForTimeInterval: 0.01];
}
return nil;
}];
[animationThread start];
}
}
- (void)applicationDidFinishLaunching
{
ogk_display_flags_t flags =
OGK_DISPLAY_FLAGS_RESIZABLE |
OGK_DISPLAY_FLAGS_VSYNC;
|