Add a test animation.

This commit is contained in:
Jonathan Schleifer 2012-08-28 22:10:57 +02:00
parent 0dca20000d
commit 41f4494b98
2 changed files with 41 additions and 1 deletions

View file

@ -34,5 +34,7 @@
BOOL running; BOOL running;
ogk_rotation_t rotation; ogk_rotation_t rotation;
ogk_color_t tint; ogk_color_t tint;
OFThread *animationThread;
BOOL stopAnimation;
} }
@end @end

View file

@ -24,6 +24,12 @@
#import "OGKBitmap.h" #import "OGKBitmap.h"
#import "TestMain.h" #import "TestMain.h"
@interface TestMain ()
- (void)draw;
- (void)handleEvents;
- (void)toggleAnimation;
@end
OF_APPLICATION_DELEGATE(TestMain) OF_APPLICATION_DELEGATE(TestMain)
@implementation TestMain @implementation TestMain
@ -70,6 +76,9 @@ OF_APPLICATION_DELEGATE(TestMain)
case OGK_KEY_RIGHT: case OGK_KEY_RIGHT:
rotation.angle += M_PI / 128; rotation.angle += M_PI / 128;
break; break;
case OGK_KEY_A:
[self toggleAnimation];
break;
case OGK_KEY_Q: case OGK_KEY_Q:
running = NO; running = NO;
break; break;
@ -114,14 +123,43 @@ OF_APPLICATION_DELEGATE(TestMain)
- (void)draw - (void)draw
{ {
ogk_rotation_t localRotation;
@synchronized (self) {
localRotation = rotation;
}
[OGKBitmap clearToColor: OGK_COLOR_BLACK]; [OGKBitmap clearToColor: OGK_COLOR_BLACK];
[bitmap drawAtPosition: position [bitmap drawAtPosition: position
scale: scale scale: scale
rotation: rotation rotation: localRotation
tint: tint]; tint: tint];
[display update]; [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 - (void)applicationDidFinishLaunching
{ {
ogk_display_flags_t flags = ogk_display_flags_t flags =