Index: src/OGKBitmap.h ================================================================== --- src/OGKBitmap.h +++ src/OGKBitmap.h @@ -23,18 +23,31 @@ #import typedef struct ogk_color_t { float red, green, blue, alpha; } ogk_color_t; + +typedef struct ogk_rotation_t { + of_point_t center; + float angle; +} ogk_rotation_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; } + +static OF_INLINE ogk_rotation_t +ogk_rotation(float x, float y, float angle) +{ + ogk_rotation_t rotation = { of_point(x, y), angle }; + + return rotation; +} extern ogk_color_t OGK_COLOR_BLACK; @interface OGKBitmap: OFObject { @@ -65,8 +78,20 @@ region: (of_rectangle_t)region tint: (ogk_color_t)tint; - (void)drawAtPosition: (of_point_t)position region: (of_rectangle_t)region scale: (of_dimension_t)scale + tint: (ogk_color_t)tint; +- (void)drawAtPosition: (of_point_t)position + rotation: (ogk_rotation_t)rotation; +- (void)drawAtPosition: (of_point_t)position + scale: (of_dimension_t)scale + rotation: (ogk_rotation_t)rotation; +- (void)drawAtPosition: (of_point_t)position + rotation: (ogk_rotation_t)rotation + tint: (ogk_color_t)tint; +- (void)drawAtPosition: (of_point_t)position + scale: (of_dimension_t)scale + rotation: (ogk_rotation_t)rotation tint: (ogk_color_t)tint; - (ALLEGRO_BITMAP*)OGK_allegroBitmap; @end Index: src/OGKBitmap.m ================================================================== --- src/OGKBitmap.m +++ src/OGKBitmap.m @@ -188,11 +188,46 @@ region.origin.x, region.origin.y, region.size.width, region.size.height, position.x, position.y, scale.width * al_get_bitmap_width(bitmap), scale.height * al_get_bitmap_height(bitmap), 0); } + +- (void)drawAtPosition: (of_point_t)position + rotation: (ogk_rotation_t)rotation +{ + al_draw_rotated_bitmap(bitmap, rotation.center.x, rotation.center.y, + position.x, position.y, rotation.angle, 0); +} + +- (void)drawAtPosition: (of_point_t)position + scale: (of_dimension_t)scale + rotation: (ogk_rotation_t)rotation +{ + al_draw_scaled_rotated_bitmap(bitmap, rotation.center.x, + rotation.center.y, position.x, position.y, scale.width, + scale.height, rotation.angle, 0); +} + +- (void)drawAtPosition: (of_point_t)position + rotation: (ogk_rotation_t)rotation + tint: (ogk_color_t)tint +{ + al_draw_tinted_rotated_bitmap(bitmap, ogk_color_to_allegro(tint), + rotation.center.x, rotation.center.y, position.x, position.y, + rotation.angle, 0); +} + +- (void)drawAtPosition: (of_point_t)position + scale: (of_dimension_t)scale + rotation: (ogk_rotation_t)rotation + tint: (ogk_color_t)tint +{ + al_draw_tinted_scaled_rotated_bitmap(bitmap, ogk_color_to_allegro(tint), + rotation.center.x, rotation.center.y, position.x, position.y, + scale.width, scale.height, rotation.angle, 0); +} - (ALLEGRO_BITMAP*)OGK_allegroBitmap { return bitmap; } @end Index: tests/TestMain.h ================================================================== --- tests/TestMain.h +++ tests/TestMain.h @@ -30,8 +30,9 @@ OGKEventQueue *eventQueue; OGKBitmap *bitmap; of_point_t position; of_dimension_t scale; BOOL running; + ogk_rotation_t rotation; ogk_color_t tint; } @end Index: tests/TestMain.m ================================================================== --- tests/TestMain.m +++ tests/TestMain.m @@ -49,10 +49,16 @@ tint = ogk_color(0.5, 0.5, 1, 0); break; case OGK_KEY_N: tint = ogk_color(1, 1, 1, 0); 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; } } @@ -102,10 +108,11 @@ - (void)draw { [OGKBitmap clearToColor: OGK_COLOR_BLACK]; [bitmap drawAtPosition: position scale: scale + rotation: rotation tint: tint]; [display update]; } - (void)applicationDidFinishLaunching @@ -133,10 +140,12 @@ [eventQueue registerMouse]; bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"]; position = of_point(display.size.width / 2, display.size.height / 2); scale = of_dimension(1, 1); + rotation = ogk_rotation(bitmap.size.width / 2, bitmap.size.height / 2, + 0); tint = ogk_color(1, 1, 1, 0); for (running = YES; running;) { @autoreleasepool { [self handleEvents];