ObjGameKit  Check-in [2a081e62c9]

Overview
Comment:Add OGKBitmap.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2a081e62c989e5268fe74b540716942382aa6b5fbbca45f3ca689f9d1da00682
User & Date: js on 2012-08-19 22:49:57
Other Links: manifest | tags
Context
2012-08-19
23:08
New OGKDisplay methods. check-in: e1d3ff7a4f user: js tags: trunk
22:49
Add OGKBitmap. check-in: 2a081e62c9 user: js tags: trunk
21:53
Initial import. check-in: c6c34e7b99 user: js tags: trunk
Changes

Modified src/Makefile from [a545af16af] to [ba2e7eda2e].



1
2
3
4

5
6
7
1
2
3
4
5

6
7
8
9
+
+



-
+



ALLEGRO_MODULES = allegro-5.0 allegro_main-5.0 allegro_image-5.0

all:
	@mkdir -p build
	@objfw-compile --lib 0.0 -o objgamekit --builddir build *.m \
		--arc `pkg-config --cflags --libs allegro-5.0 allegro_main-5.0`
		--arc `pkg-config --cflags --libs ${ALLEGRO_MODULES}`

clean:
	@rm -fr build libobjgamekit.* *~

Added src/OGKBitmap.h version [13fb383bcb].



















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2012 Jonathan Schleifer <js@webkeks.org>
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 *   1.) The origin of this software must not be misrepresented; you must not
 *       claim that you wrote the original software. If you use this software
 *       in a product, an acknowledgment in the product documentation would be
 *       appreciated but is not required.
 *   2.) Altered source versions must be plainly marked as such, and must not
 *       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>

typedef struct ogk_color_t {
	float red, green, blue, alpha;
} ogk_color_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;
}

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

Added src/OGKBitmap.m version [d4949e0576].




























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
85
86
87
88
89
90
91
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2012 Jonathan Schleifer <js@webkeks.org>
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 *   1.) The origin of this software must not be misrepresented; you must not
 *       claim that you wrote the original software. If you use this software
 *       in a product, an acknowledgment in the product documentation would be
 *       appreciated but is not required.
 *   2.) Altered source versions must be plainly marked as such, and must not
 *       be misrepresented as being the original software.
 *   3.) This notice may not be removed or altered from any source distribution.
 */

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

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL) ||
	    !al_init_image_addon())
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

+ (void)setTarget: (id)target
{
	if ([target isKindOfClass: [OGKDisplay class]])
		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);

	if (bitmap == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: [self class]];

	return self;
}

- initWithFile: (OFString*)path
{
	self = [super init];

	bitmap = al_load_bitmap(
	    [path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);

	if (bitmap == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: [self class]];

	return self;
}

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

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

Modified src/OGKDisplay.h from [575fe769bc] to [be99dd44f0].

23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
23
24
25
26
27
28
29



30
31
32
33
34
35







-
-
-



+


#import <ObjFW/ObjFW.h>

@interface OGKDisplay: OFObject
{
	ALLEGRO_DISPLAY *display;
}

+ displayWithSize: (of_dimension_t)size
       fullscreen: (BOOL)fullscreen
	resizable: (BOOL)resizable;
- initWithSize: (of_dimension_t)size
    fullscreen: (BOOL)fullscreen
     resizable: (BOOL)resizable;
- (void)update;
- (ALLEGRO_DISPLAY*)OGK_allegroDisplay;
@end

Modified src/OGKDisplay.m from [78f573a0bd] to [c89196f16c].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
27
28
29
30
31
32
33









34
35
36
37
38
39
40







-
-
-
-
-
-
-
-
-







		return;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}

+ displayWithSize: (of_dimension_t)size
       fullscreen: (BOOL)fullscreen
	resizable: (BOOL)resizable
{
	return [[self alloc] initWithSize: size
			       fullscreen: fullscreen
				resizable: resizable];
}

- initWithSize: (of_dimension_t)size
    fullscreen: (BOOL)fullscreen
     resizable: (BOOL)resizable
{
	int flags = 0;

	self = [super init];
70
71
72
73
74
75
76





77
78
79
80
81
82
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78







+
+
+
+
+






}

- (void)dealloc
{
	if (display != NULL)
		al_destroy_display(display);
}

- (void)update
{
	al_flip_display();
}

- (ALLEGRO_DISPLAY*)OGK_allegroDisplay
{
	return display;
}
@end

Modified test/Makefile from [ce0acc1603] to [c184791af8].



1
2
3
4

5
6
7
1
2
3
4
5

6
7
8
9
+
+



-
+



ALLEGRO_MODULES = allegro-5.0 allegro_main-5.0 allegro_image-5.0

all:
	@objfw-compile -o test --arc *.m \
		-I../src -L../src -lobjgamekit \
		`pkg-config --cflags --libs allegro-5.0 allegro_main-5.0`
		`pkg-config --cflags --libs ${ALLEGRO_MODULES}`

clean:
	@rm -f test *.o *~

Modified test/TestMain.h from [f8c1ad0d84] to [0399db4bce].

18
19
20
21
22
23
24

25
26
27
28
29

30
31
32
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+





+



 *   3.) This notice may not be removed or altered from any source distribution.
 */

#import <ObjFW/ObjFW.h>

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

@interface TestMain: OFObject <OFApplicationDelegate, OGKEventQueueDelegate>
{
	OGKDisplay *display;
	OGKEventQueue *eventQueue;
	OGKBitmap *bitmap;
	BOOL running;
}
@end

Modified test/TestMain.m from [e02b7cbb4f] to [1ce7f6f9e5].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+







 *       be misrepresented as being the original software.
 *   3.) This notice may not be removed or altered from any source distribution.
 */

#import "OGKDisplay.h"
#import "OGKEvent.h"
#import "OGKEventQueue.h"
#import "OGKBitmap.h"
#import "TestMain.h"

OF_APPLICATION_DELEGATE(TestMain)

@implementation TestMain
- (void)displayWasClosed: (OGKCloseEvent*)event
{
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
85
86
87
88
89
90
91
92
93
94
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
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







+
+
+
+
+
+
+
+
+
+
+
+













+
+


-
+
+














- (void)mouseButtonWasReleased: (OGKMouseButtonPressedEvent*)event
{
	of_log(@"Mouse button was released: %d (X=%.f Y=%.f WX=%.f WY=%.f)",
	    event.button, event.cursor.x, event.cursor.y,
	    event.wheel.x, event.wheel.y);
}

- (void)handleEvents
{
	[eventQueue handleNextEvent];
}

- (void)draw
{
	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: of_point(160, 120)];
	[display update];
}

- (void)applicationDidFinishLaunching
{
	display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480)
					fullscreen: NO
					 resizable: NO];
	eventQueue = [[OGKEventQueue alloc] init];
	eventQueue.delegate = self;

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

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

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

- (void)applicationWillTerminate
{
	/* Make sure they don't get deallocated after al_uninstall_system() */
	display = nil;
	eventQueue = nil;

	al_uninstall_system();
}
@end

Added test/test.bmp version [31b66dd80e].

cannot compute difference between binary files