ObjGameKit  Check-in [f2278e46ca]

Overview
Comment:Add many new methods to OGKBitmap.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f2278e46ca619d270aa0e705a5cd83a72678a869e2dcd09b156a32c67cab9878
User & Date: js on 2012-08-28 17:50:05
Other Links: manifest | tags
Context
2012-08-28
19:43
Make scale relative instead of absolute. check-in: e3b3bcfe20 user: js tags: trunk
17:50
Add many new methods to OGKBitmap. check-in: f2278e46ca user: js tags: trunk
17:39
Add keycodes.h. check-in: 8bf981dfa3 user: js tags: trunk
Changes

Modified src/OGKBitmap.h from [13fb383bcb] to [a481d3b08b].

37
38
39
40
41
42
43


44
45
46
47

48



















49
50
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







>
>




>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
extern ogk_color_t OGK_COLOR_BLACK;

@interface OGKBitmap: OFObject
{
	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

Modified src/OGKBitmap.m from [ffce6aad92] to [0e51e0ab6e].

21
22
23
24
25
26
27






28
29
30
31
32
33
34
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

#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;








>
>
>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

#import "OGKBitmap.h"
#import "OGKDisplay.h"

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
{
	if (self != [OGKBitmap class])
		return;

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
		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);







|
<







49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
		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(ogk_color_to_allegro(color));

}

- initWithSize: (of_dimension_t)size
{
	self = [super init];

	bitmap = al_create_bitmap(size.width, size.height);
79
80
81
82
83
84
85
86

































87
88
89
90
91




























































92
93
94
95
96
}

- (void)dealloc
{
	if (bitmap != NULL && al_is_system_installed())
		al_destroy_bitmap(bitmap);
}


































- (void)drawAtPosition: (of_point_t)position
{
	al_draw_bitmap(bitmap, position.x, position.y, 0);
}





























































- (ALLEGRO_BITMAP*)OGK_allegroBitmap
{
	return bitmap;
}
@end








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
}

- (void)dealloc
{
	if (bitmap != NULL && al_is_system_installed())
		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;
}
@end

Modified src/OGKEvent.h from [876a2c81a5] to [5d7e7a26bf].

17
18
19
20
21
22
23


24
25
26
27
28
29
30
 *       be misrepresented as being the original software.
 *   3.) This notice may not be removed or altered from any source distribution.
 */

#include <allegro5/allegro.h>

#import <ObjFW/ObjFW.h>



@interface OGKEvent: OFObject
{
	ALLEGRO_EVENT event;
}

- (ALLEGRO_EVENT*)OGK_allegroEvent;







>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 *       be misrepresented as being the original software.
 *   3.) This notice may not be removed or altered from any source distribution.
 */

#include <allegro5/allegro.h>

#import <ObjFW/ObjFW.h>

#import "keycodes.h"

@interface OGKEvent: OFObject
{
	ALLEGRO_EVENT event;
}

- (ALLEGRO_EVENT*)OGK_allegroEvent;

Modified tests/TestMain.h from [150ee79de4] to [79738436b7].

26
27
28
29
30
31
32

33

34
35

@interface TestMain: OFObject <OFApplicationDelegate, OGKEventQueueDelegate>
{
	OGKDisplay *display;
	OGKEventQueue *eventQueue;
	OGKBitmap *bitmap;
	of_point_t position;

	BOOL running;

}
@end







>

>


26
27
28
29
30
31
32
33
34
35
36
37

@interface TestMain: OFObject <OFApplicationDelegate, OGKEventQueueDelegate>
{
	OGKDisplay *display;
	OGKEventQueue *eventQueue;
	OGKBitmap *bitmap;
	of_point_t position;
	of_dimension_t scale;
	BOOL running;
	ogk_color_t tint;
}
@end

Modified tests/TestMain.m from [e1d8f71724] to [2b37607de0].

33
34
35
36
37
38
39


















40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57


58
59
60
61
62
63
64
	running = NO;
}

- (void)keyWasPressed: (OGKKeyPressEvent*)event
	      display: (OGKDisplay*)display
{
	of_log(@"Pressed: %d", event.keycode);


















}

- (void)keyWasReleased: (OGKKeyReleaseEvent*)event
	       display: (OGKDisplay*)display
{
	of_log(@"Released: %d", event.keycode);
}

- (void)mouseWasMoved: (OGKMouseMovedEvent*)event
	      display: (OGKDisplay*)display
{
	of_log(@"Mouse moved: X=%.f(%.f) Y=%.f(%.f) WX=%.f(%.f) WY=%.f(%.f)",
	    event.cursor.x, event.deltaCursor.x,
	    event.cursor.y, event.deltaCursor.y,
	    event.wheel.x, event.deltaWheel.x,
	    event.wheel.y, event.deltaWheel.y);

	position = event.cursor;


}

- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event
		      display: (OGKDisplay*)display
{
	of_log(@"Mouse button was pressed: %d (X=%.f Y=%.f WX=%.f WY=%.f)",
	    event.button, event.cursor.x, event.cursor.y,







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


















>
>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
	running = NO;
}

- (void)keyWasPressed: (OGKKeyPressEvent*)event
	      display: (OGKDisplay*)display
{
	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
	       display: (OGKDisplay*)display
{
	of_log(@"Released: %d", event.keycode);
}

- (void)mouseWasMoved: (OGKMouseMovedEvent*)event
	      display: (OGKDisplay*)display
{
	of_log(@"Mouse moved: X=%.f(%.f) Y=%.f(%.f) WX=%.f(%.f) WY=%.f(%.f)",
	    event.cursor.x, event.deltaCursor.x,
	    event.cursor.y, event.deltaCursor.y,
	    event.wheel.x, event.deltaWheel.x,
	    event.wheel.y, event.deltaWheel.y);

	position = event.cursor;
	scale = of_dimension(bitmap.size.width + event.wheel.x,
	    bitmap.size.height + event.wheel.y);
}

- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event
		      display: (OGKDisplay*)display
{
	of_log(@"Mouse button was pressed: %d (X=%.f Y=%.f WX=%.f WY=%.f)",
	    event.button, event.cursor.x, event.cursor.y,
77
78
79
80
81
82
83
84


85
86
87
88
89
90
91
{
	[eventQueue handleEvents];
}

- (void)draw
{
	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: position];


	[display update];
}

- (void)applicationDidFinishLaunching
{
	ogk_display_flags_t flags =
	    OGK_DISPLAY_FLAGS_RESIZABLE |







|
>
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
	[eventQueue handleEvents];
}

- (void)draw
{
	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: position
			 scale: scale
			  tint: tint];
	[display update];
}

- (void)applicationDidFinishLaunching
{
	ogk_display_flags_t flags =
	    OGK_DISPLAY_FLAGS_RESIZABLE |
106
107
108
109
110
111
112



113
114
115
116
117
118
119
120
121
	eventQueue.delegate = self;

	[eventQueue registerDisplay: display];
	[eventQueue registerKeyboard];
	[eventQueue registerMouse];

	bitmap = [[OGKBitmap alloc] initWithFile: @"test.bmp"];




	for (running = YES; running;) {
		@autoreleasepool {
			[self handleEvents];
			[self draw];
		}
	}
}
@end







>
>
>









128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	eventQueue.delegate = self;

	[eventQueue registerDisplay: display];
	[eventQueue registerKeyboard];
	[eventQueue registerMouse];

	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;) {
		@autoreleasepool {
			[self handleEvents];
			[self draw];
		}
	}
}
@end