Add many new methods to OGKBitmap.
This commit is contained in:
parent
53b1823dc3
commit
89e736050e
5 changed files with 152 additions and 3 deletions
|
@ -41,10 +41,32 @@ extern ogk_color_t OGK_COLOR_BLACK;
|
|||
ALLEGRO_BITMAP *bitmap;
|
||||
}
|
||||
|
||||
@property (readonly) of_dimension_t size;
|
||||
|
||||
+ (void)setTarget: (id)target;
|
||||
+ (void)clearToColor: (ogk_color_t)color;
|
||||
- initWithSize: (of_dimension_t)size;
|
||||
- initWithFile: (OFString*)file;
|
||||
- (instancetype)subBitmapWithRegion: (of_rectangle_t)region;
|
||||
- (void)drawAtPosition: (of_point_t)position;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
scale: (of_dimension_t)scale;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region
|
||||
scale: (of_dimension_t)scale;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
tint: (ogk_color_t)tint;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
scale: (of_dimension_t)scale
|
||||
tint: (ogk_color_t)tint;
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
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;
|
||||
- (ALLEGRO_BITMAP*)OGK_allegroBitmap;
|
||||
@end
|
||||
|
|
102
src/OGKBitmap.m
102
src/OGKBitmap.m
|
@ -26,6 +26,12 @@
|
|||
|
||||
ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
||||
|
||||
static ALLEGRO_COLOR
|
||||
ogk_color_to_allegro(ogk_color_t color)
|
||||
{
|
||||
return al_map_rgba_f(color.red, color.green, color.blue, color.alpha);
|
||||
}
|
||||
|
||||
@implementation OGKBitmap
|
||||
+ (void)initialize
|
||||
{
|
||||
|
@ -47,8 +53,7 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
|||
|
||||
+ (void)clearToColor: (ogk_color_t)color
|
||||
{
|
||||
al_clear_to_color(
|
||||
al_map_rgb(color.red * 256, color.green * 256, color.blue * 256));
|
||||
al_clear_to_color(ogk_color_to_allegro(color));
|
||||
}
|
||||
|
||||
- initWithSize: (of_dimension_t)size
|
||||
|
@ -84,11 +89,104 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
|||
al_destroy_bitmap(bitmap);
|
||||
}
|
||||
|
||||
- copy
|
||||
{
|
||||
OGKBitmap *copy = [[[self class] alloc] init];
|
||||
|
||||
copy->bitmap = al_clone_bitmap(bitmap);
|
||||
|
||||
if (copy->bitmap == NULL)
|
||||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: [self class]];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (instancetype)subBitmapWithRegion: (of_rectangle_t)region
|
||||
{
|
||||
OGKBitmap *subBitmap = [[[self class] alloc] init];
|
||||
|
||||
subBitmap->bitmap = al_create_sub_bitmap(bitmap, region.origin.x,
|
||||
region.origin.y, region.size.width, region.size.height);
|
||||
|
||||
if (subBitmap->bitmap == NULL)
|
||||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: [self class]];
|
||||
|
||||
return subBitmap;
|
||||
}
|
||||
|
||||
- (of_dimension_t)size
|
||||
{
|
||||
return of_dimension(al_get_bitmap_width(bitmap),
|
||||
al_get_bitmap_height(bitmap));
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
{
|
||||
al_draw_bitmap(bitmap, position.x, position.y, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
scale: (of_dimension_t)scale
|
||||
{
|
||||
al_draw_scaled_bitmap(bitmap, 0, 0, al_get_bitmap_width(bitmap),
|
||||
al_get_bitmap_height(bitmap), position.x, position.y,
|
||||
scale.width, scale.height, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region
|
||||
{
|
||||
al_draw_bitmap_region(bitmap, region.origin.x, region.origin.y,
|
||||
region.size.width, region.size.height, position.x, position.y, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region
|
||||
scale: (of_dimension_t)scale
|
||||
{
|
||||
al_draw_scaled_bitmap(bitmap, region.origin.x, region.origin.y,
|
||||
region.size.width, region.size.height, position.x, position.y,
|
||||
scale.width, scale.height, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
tint: (ogk_color_t)tint
|
||||
{
|
||||
al_draw_tinted_bitmap(bitmap, ogk_color_to_allegro(tint),
|
||||
position.x, position.y, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
scale: (of_dimension_t)scale
|
||||
tint: (ogk_color_t)tint
|
||||
{
|
||||
al_draw_tinted_scaled_bitmap(bitmap, ogk_color_to_allegro(tint),
|
||||
0, 0, al_get_bitmap_width(bitmap), al_get_bitmap_height(bitmap),
|
||||
position.x, position.y, scale.width, scale.height, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region
|
||||
tint: (ogk_color_t)tint
|
||||
{
|
||||
al_draw_tinted_bitmap_region(bitmap, ogk_color_to_allegro(tint),
|
||||
region.origin.x, region.origin.y, region.size.width,
|
||||
region.size.height, position.x, position.y, 0);
|
||||
}
|
||||
|
||||
- (void)drawAtPosition: (of_point_t)position
|
||||
region: (of_rectangle_t)region
|
||||
scale: (of_dimension_t)scale
|
||||
tint: (ogk_color_t)tint
|
||||
{
|
||||
al_draw_tinted_scaled_bitmap(bitmap, ogk_color_to_allegro(tint),
|
||||
region.origin.x, region.origin.y, region.size.width,
|
||||
region.size.height, position.x, position.y, scale.width,
|
||||
scale.height, 0);
|
||||
}
|
||||
|
||||
- (ALLEGRO_BITMAP*)OGK_allegroBitmap
|
||||
{
|
||||
return bitmap;
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#import "keycodes.h"
|
||||
|
||||
@interface OGKEvent: OFObject
|
||||
{
|
||||
ALLEGRO_EVENT event;
|
||||
|
|
Reference in a new issue