Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,7 +1,9 @@ +ALLEGRO_MODULES = allegro-5.0 allegro_main-5.0 allegro_image-5.0 + all: @mkdir -p build @objfw-compile --lib 0.0 -o objgamekit --builddir build *.m \ - --arc `pkg-config --cflags --libs allegro-5.0 allegro_main-5.0` + --arc `pkg-config --cflags --libs ${ALLEGRO_MODULES}` clean: @rm -fr build libobjgamekit.* *~ ADDED src/OGKBitmap.h Index: src/OGKBitmap.h ================================================================== --- src/OGKBitmap.h +++ src/OGKBitmap.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012 Jonathan Schleifer + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from the + * use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.) The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2.) Altered source versions must be plainly marked as such, and must not + * be misrepresented as being the original software. + * 3.) This notice may not be removed or altered from any source distribution. + */ + +#include + +#import + +typedef struct ogk_color_t { + float red, green, blue, alpha; +} ogk_color_t; + +static OF_INLINE ogk_color_t +ogk_color(float red, float green, float blue, float alpha) +{ + ogk_color_t color = { red, green, blue, alpha}; + + return color; +} + +extern ogk_color_t OGK_COLOR_BLACK; + +@interface OGKBitmap: OFObject +{ + ALLEGRO_BITMAP *bitmap; +} + ++ (void)setTarget: (id)target; ++ (void)clearToColor: (ogk_color_t)color; +- initWithSize: (of_dimension_t)size; +- initWithFile: (OFString*)file; +- (void)drawAtPosition: (of_point_t)position; +- (ALLEGRO_BITMAP*)OGK_allegroBitmap; +@end ADDED src/OGKBitmap.m Index: src/OGKBitmap.m ================================================================== --- src/OGKBitmap.m +++ src/OGKBitmap.m @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012 Jonathan Schleifer + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from the + * use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.) The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2.) Altered source versions must be plainly marked as such, and must not + * be misrepresented as being the original software. + * 3.) This notice may not be removed or altered from any source distribution. + */ + +#include +#include + +#import "OGKBitmap.h" +#import "OGKDisplay.h" + +ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 }; + +@implementation OGKBitmap ++ (void)initialize +{ + if (self != [OGKBitmap class]) + return; + + if (!al_install_system(ALLEGRO_VERSION_INT, NULL) || + !al_init_image_addon()) + @throw [OFInitializationFailedException + exceptionWithClass: self]; +} + ++ (void)setTarget: (id)target +{ + if ([target isKindOfClass: [OGKDisplay class]]) + al_set_target_backbuffer([target OGK_allegroDisplay]); + else + al_set_target_bitmap([target OGK_allegroBitmap]); +} + ++ (void)clearToColor: (ogk_color_t)color +{ + al_clear_to_color( + al_map_rgb(color.red * 256, color.green * 256, color.blue * 256)); +} + +- initWithSize: (of_dimension_t)size +{ + self = [super init]; + + bitmap = al_create_bitmap(size.width, size.height); + + if (bitmap == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: [self class]]; + + return self; +} + +- initWithFile: (OFString*)path +{ + self = [super init]; + + bitmap = al_load_bitmap( + [path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]); + + if (bitmap == NULL) + @throw [OFInitializationFailedException + exceptionWithClass: [self class]]; + + return self; +} + +- (void)drawAtPosition: (of_point_t)position +{ + al_draw_bitmap(bitmap, position.x, position.y, 0); +} + +- (ALLEGRO_BITMAP*)OGK_allegroBitmap +{ + return bitmap; +} +@end Index: src/OGKDisplay.h ================================================================== --- src/OGKDisplay.h +++ src/OGKDisplay.h @@ -25,13 +25,11 @@ @interface OGKDisplay: OFObject { ALLEGRO_DISPLAY *display; } -+ displayWithSize: (of_dimension_t)size - fullscreen: (BOOL)fullscreen - resizable: (BOOL)resizable; - initWithSize: (of_dimension_t)size fullscreen: (BOOL)fullscreen resizable: (BOOL)resizable; +- (void)update; - (ALLEGRO_DISPLAY*)OGK_allegroDisplay; @end Index: src/OGKDisplay.m ================================================================== --- src/OGKDisplay.m +++ src/OGKDisplay.m @@ -29,19 +29,10 @@ if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) @throw [OFInitializationFailedException exceptionWithClass: self]; } -+ displayWithSize: (of_dimension_t)size - fullscreen: (BOOL)fullscreen - resizable: (BOOL)resizable -{ - return [[self alloc] initWithSize: size - fullscreen: fullscreen - resizable: resizable]; -} - - initWithSize: (of_dimension_t)size fullscreen: (BOOL)fullscreen resizable: (BOOL)resizable { int flags = 0; @@ -72,11 +63,16 @@ - (void)dealloc { if (display != NULL) al_destroy_display(display); } + +- (void)update +{ + al_flip_display(); +} - (ALLEGRO_DISPLAY*)OGK_allegroDisplay { return display; } @end Index: test/Makefile ================================================================== --- test/Makefile +++ test/Makefile @@ -1,7 +1,9 @@ +ALLEGRO_MODULES = allegro-5.0 allegro_main-5.0 allegro_image-5.0 + all: @objfw-compile -o test --arc *.m \ -I../src -L../src -lobjgamekit \ - `pkg-config --cflags --libs allegro-5.0 allegro_main-5.0` + `pkg-config --cflags --libs ${ALLEGRO_MODULES}` clean: @rm -f test *.o *~ Index: test/TestMain.h ================================================================== --- test/TestMain.h +++ test/TestMain.h @@ -20,13 +20,15 @@ #import #import "OGKDisplay.h" #import "OGKEventQueue.h" +#import "OGKBitmap.h" @interface TestMain: OFObject { OGKDisplay *display; OGKEventQueue *eventQueue; + OGKBitmap *bitmap; BOOL running; } @end Index: test/TestMain.m ================================================================== --- test/TestMain.m +++ test/TestMain.m @@ -19,10 +19,11 @@ */ #import "OGKDisplay.h" #import "OGKEvent.h" #import "OGKEventQueue.h" +#import "OGKBitmap.h" #import "TestMain.h" OF_APPLICATION_DELEGATE(TestMain) @implementation TestMain @@ -61,10 +62,22 @@ { of_log(@"Mouse button was released: %d (X=%.f Y=%.f WX=%.f WY=%.f)", event.button, event.cursor.x, event.cursor.y, event.wheel.x, event.wheel.y); } + +- (void)handleEvents +{ + [eventQueue handleNextEvent]; +} + +- (void)draw +{ + [OGKBitmap clearToColor: OGK_COLOR_BLACK]; + [bitmap drawAtPosition: of_point(160, 120)]; + [display update]; +} - (void)applicationDidFinishLaunching { display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480) fullscreen: NO @@ -74,13 +87,16 @@ [eventQueue registerDisplay: display]; [eventQueue registerKeyboard]; [eventQueue registerMouse]; + bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"]; + for (running = YES; running;) { @autoreleasepool { - [eventQueue handleNextEvent]; + [self handleEvents]; + [self draw]; } } } - (void)applicationWillTerminate ADDED test/test.bmp Index: test/test.bmp ================================================================== --- test/test.bmp +++ test/test.bmp cannot compute difference between binary files