ObjGameKit  Check-in [d5c8cc4029]

Overview
Comment:Add a test animation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d5c8cc4029b36a41669dc46eed92eae711ad920b862f2eaa24c390463b50f9a3
User & Date: js on 2012-08-28 20:10:57
Other Links: manifest | tags
Context
2012-09-09
13:18
Adjust to ObjFW change. Leaf check-in: c977e39bbe user: js tags: trunk
2012-08-28
20:10
Add a test animation. check-in: d5c8cc4029 user: js tags: trunk
20:00
Add OGKCharacterTypedEvent. check-in: 1f8de6b2e2 user: js tags: trunk
Changes

Modified tests/TestMain.h from [2166ed5054] to [7e7dd1e48b].

30
31
32
33
34
35
36


37
38
	OGKEventQueue *eventQueue;
	OGKBitmap *bitmap;
	of_point_t position;
	of_dimension_t scale;
	BOOL running;
	ogk_rotation_t rotation;
	ogk_color_t tint;


}
@end







>
>


30
31
32
33
34
35
36
37
38
39
40
	OGKEventQueue *eventQueue;
	OGKBitmap *bitmap;
	of_point_t position;
	of_dimension_t scale;
	BOOL running;
	ogk_rotation_t rotation;
	ogk_color_t tint;
	OFThread *animationThread;
	BOOL stopAnimation;
}
@end

Modified tests/TestMain.m from [cf73ffbefb] to [a1fc7a3a43].

19
20
21
22
23
24
25






26
27
28
29
30
31
32
 */

#import "OGKDisplay.h"
#import "OGKEvent.h"
#import "OGKEventQueue.h"
#import "OGKBitmap.h"
#import "TestMain.h"







OF_APPLICATION_DELEGATE(TestMain)

@implementation TestMain
- (void)display: (OGKDisplay*)display
      wasClosed: (OGKCloseEvent*)event
{







>
>
>
>
>
>







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
		break;
	case OGK_KEY_LEFT:
		rotation.angle -= M_PI / 128;
		break;
	case OGK_KEY_RIGHT:
		rotation.angle += M_PI / 128;
		break;



	case OGK_KEY_Q:
		running = NO;
		break;
	}
}

- (void)mouseWasMoved: (OGKMouseMovedEvent*)event







>
>
>







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
- (void)handleEvents
{
	[eventQueue handleEvents];
}

- (void)draw
{





	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: position
			 scale: scale
		      rotation: rotation
			  tint: tint];
	[display update];
}

























- (void)applicationDidFinishLaunching
{
	ogk_display_flags_t flags =
	    OGK_DISPLAY_FLAGS_RESIZABLE |
	    OGK_DISPLAY_FLAGS_VSYNC;








>
>
>
>
>



|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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: 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;