Add methods for drawing rotated.
This commit is contained in:
parent
563ae054a9
commit
a98c97edb2
4 changed files with 70 additions and 0 deletions
|
@ -26,6 +26,11 @@ typedef struct ogk_color_t {
|
||||||
float red, green, blue, alpha;
|
float red, green, blue, alpha;
|
||||||
} ogk_color_t;
|
} ogk_color_t;
|
||||||
|
|
||||||
|
typedef struct ogk_rotation_t {
|
||||||
|
of_point_t center;
|
||||||
|
float angle;
|
||||||
|
} ogk_rotation_t;
|
||||||
|
|
||||||
static OF_INLINE ogk_color_t
|
static OF_INLINE ogk_color_t
|
||||||
ogk_color(float red, float green, float blue, float alpha)
|
ogk_color(float red, float green, float blue, float alpha)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +39,14 @@ ogk_color(float red, float green, float blue, float alpha)
|
||||||
return color;
|
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;
|
extern ogk_color_t OGK_COLOR_BLACK;
|
||||||
|
|
||||||
@interface OGKBitmap: OFObject
|
@interface OGKBitmap: OFObject
|
||||||
|
@ -68,5 +81,17 @@ extern ogk_color_t OGK_COLOR_BLACK;
|
||||||
region: (of_rectangle_t)region
|
region: (of_rectangle_t)region
|
||||||
scale: (of_dimension_t)scale
|
scale: (of_dimension_t)scale
|
||||||
tint: (ogk_color_t)tint;
|
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;
|
- (ALLEGRO_BITMAP*)OGK_allegroBitmap;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -191,6 +191,41 @@ ogk_color_to_allegro(ogk_color_t color)
|
||||||
scale.height * al_get_bitmap_height(bitmap), 0);
|
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
|
- (ALLEGRO_BITMAP*)OGK_allegroBitmap
|
||||||
{
|
{
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
of_point_t position;
|
of_point_t position;
|
||||||
of_dimension_t scale;
|
of_dimension_t scale;
|
||||||
BOOL running;
|
BOOL running;
|
||||||
|
ogk_rotation_t rotation;
|
||||||
ogk_color_t tint;
|
ogk_color_t tint;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -51,6 +51,12 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
case OGK_KEY_N:
|
case OGK_KEY_N:
|
||||||
tint = ogk_color(1, 1, 1, 0);
|
tint = ogk_color(1, 1, 1, 0);
|
||||||
break;
|
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:
|
case OGK_KEY_Q:
|
||||||
running = NO;
|
running = NO;
|
||||||
break;
|
break;
|
||||||
|
@ -104,6 +110,7 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
[OGKBitmap clearToColor: OGK_COLOR_BLACK];
|
[OGKBitmap clearToColor: OGK_COLOR_BLACK];
|
||||||
[bitmap drawAtPosition: position
|
[bitmap drawAtPosition: position
|
||||||
scale: scale
|
scale: scale
|
||||||
|
rotation: rotation
|
||||||
tint: tint];
|
tint: tint];
|
||||||
[display update];
|
[display update];
|
||||||
}
|
}
|
||||||
|
@ -135,6 +142,8 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"];
|
bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"];
|
||||||
position = of_point(display.size.width / 2, display.size.height / 2);
|
position = of_point(display.size.width / 2, display.size.height / 2);
|
||||||
scale = of_dimension(1, 1);
|
scale = of_dimension(1, 1);
|
||||||
|
rotation = ogk_rotation(bitmap.size.width / 2, bitmap.size.height / 2,
|
||||||
|
0);
|
||||||
tint = ogk_color(1, 1, 1, 0);
|
tint = ogk_color(1, 1, 1, 0);
|
||||||
|
|
||||||
for (running = YES; running;) {
|
for (running = YES; running;) {
|
||||||
|
|
Reference in a new issue