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;
|
ALLEGRO_BITMAP *bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property (readonly) of_dimension_t size;
|
||||||
|
|
||||||
+ (void)setTarget: (id)target;
|
+ (void)setTarget: (id)target;
|
||||||
+ (void)clearToColor: (ogk_color_t)color;
|
+ (void)clearToColor: (ogk_color_t)color;
|
||||||
- initWithSize: (of_dimension_t)size;
|
- initWithSize: (of_dimension_t)size;
|
||||||
- initWithFile: (OFString*)file;
|
- initWithFile: (OFString*)file;
|
||||||
|
- (instancetype)subBitmapWithRegion: (of_rectangle_t)region;
|
||||||
- (void)drawAtPosition: (of_point_t)position;
|
- (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;
|
- (ALLEGRO_BITMAP*)OGK_allegroBitmap;
|
||||||
@end
|
@end
|
||||||
|
|
102
src/OGKBitmap.m
102
src/OGKBitmap.m
|
@ -26,6 +26,12 @@
|
||||||
|
|
||||||
ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
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
|
@implementation OGKBitmap
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
{
|
{
|
||||||
|
@ -47,8 +53,7 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
||||||
|
|
||||||
+ (void)clearToColor: (ogk_color_t)color
|
+ (void)clearToColor: (ogk_color_t)color
|
||||||
{
|
{
|
||||||
al_clear_to_color(
|
al_clear_to_color(ogk_color_to_allegro(color));
|
||||||
al_map_rgb(color.red * 256, color.green * 256, color.blue * 256));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithSize: (of_dimension_t)size
|
- initWithSize: (of_dimension_t)size
|
||||||
|
@ -84,11 +89,104 @@ ogk_color_t OGK_COLOR_BLACK = { 0, 0, 0, 1 };
|
||||||
al_destroy_bitmap(bitmap);
|
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
|
- (void)drawAtPosition: (of_point_t)position
|
||||||
{
|
{
|
||||||
al_draw_bitmap(bitmap, position.x, position.y, 0);
|
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
|
- (ALLEGRO_BITMAP*)OGK_allegroBitmap
|
||||||
{
|
{
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#import <ObjFW/ObjFW.h>
|
#import <ObjFW/ObjFW.h>
|
||||||
|
|
||||||
|
#import "keycodes.h"
|
||||||
|
|
||||||
@interface OGKEvent: OFObject
|
@interface OGKEvent: OFObject
|
||||||
{
|
{
|
||||||
ALLEGRO_EVENT event;
|
ALLEGRO_EVENT event;
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
OGKEventQueue *eventQueue;
|
OGKEventQueue *eventQueue;
|
||||||
OGKBitmap *bitmap;
|
OGKBitmap *bitmap;
|
||||||
of_point_t position;
|
of_point_t position;
|
||||||
|
of_dimension_t scale;
|
||||||
BOOL running;
|
BOOL running;
|
||||||
|
ogk_color_t tint;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -37,6 +37,24 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
display: (OGKDisplay*)display
|
display: (OGKDisplay*)display
|
||||||
{
|
{
|
||||||
of_log(@"Pressed: %d", event.keycode);
|
of_log(@"Pressed: %d", event.keycode);
|
||||||
|
|
||||||
|
switch (event.keycode) {
|
||||||
|
case OGK_KEY_R:
|
||||||
|
tint = ogk_color(1, 0.5, 0.5, 0);
|
||||||
|
break;
|
||||||
|
case OGK_KEY_G:
|
||||||
|
tint = ogk_color(0.5, 1, 0.5, 0);
|
||||||
|
break;
|
||||||
|
case OGK_KEY_B:
|
||||||
|
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_Q:
|
||||||
|
running = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)keyWasReleased: (OGKKeyReleaseEvent*)event
|
- (void)keyWasReleased: (OGKKeyReleaseEvent*)event
|
||||||
|
@ -55,6 +73,8 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
event.wheel.y, event.deltaWheel.y);
|
event.wheel.y, event.deltaWheel.y);
|
||||||
|
|
||||||
position = event.cursor;
|
position = event.cursor;
|
||||||
|
scale = of_dimension(bitmap.size.width + event.wheel.x,
|
||||||
|
bitmap.size.height + event.wheel.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event
|
- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event
|
||||||
|
@ -81,7 +101,9 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
- (void)draw
|
- (void)draw
|
||||||
{
|
{
|
||||||
[OGKBitmap clearToColor: OGK_COLOR_BLACK];
|
[OGKBitmap clearToColor: OGK_COLOR_BLACK];
|
||||||
[bitmap drawAtPosition: position];
|
[bitmap drawAtPosition: position
|
||||||
|
scale: scale
|
||||||
|
tint: tint];
|
||||||
[display update];
|
[display update];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +132,9 @@ OF_APPLICATION_DELEGATE(TestMain)
|
||||||
[eventQueue registerMouse];
|
[eventQueue registerMouse];
|
||||||
|
|
||||||
bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"];
|
bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"];
|
||||||
|
position = of_point(display.size.width / 2, display.size.height / 2);
|
||||||
|
scale = bitmap.size;
|
||||||
|
tint = ogk_color(1, 1, 1, 0);
|
||||||
|
|
||||||
for (running = YES; running;) {
|
for (running = YES; running;) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
|
Reference in a new issue