ObjGameKit  Check-in [40c2d53ff0]

Overview
Comment:Use flags for -[OGKDisplay init...].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 40c2d53ff01f7539248bcdb02430bcdf58a73704c0e32a63e8e10cd84a536438
User & Date: js on 2012-08-26 10:09:26
Other Links: manifest | tags
Context
2012-08-26
12:17
Only call al_*_destroy if Allegro is initialized. check-in: 4719f25709 user: js tags: trunk
10:09
Use flags for -[OGKDisplay init...]. check-in: 40c2d53ff0 user: js tags: trunk
2012-08-20
01:18
Pass the display on events. check-in: f309ba2b33 user: js tags: trunk
Changes

Modified src/OGKDisplay.h from [1753a97d4c] to [5aa9048201].

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
 *       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 OGKDisplay: OFObject
{
	ALLEGRO_DISPLAY *display;
}

@property (assign) of_point_t windowPosition;
@property (assign) of_dimension_t size;

+ OGK_displayForAllegroDisplay: (ALLEGRO_DISPLAY*)display;
- initWithSize: (of_dimension_t)size
      position: (of_point_t)position
    fullscreen: (BOOL)fullscreen
     resizable: (BOOL)resizable;
- (void)setWindowTitle: (OFString*)title;
- (void)update;
- (ALLEGRO_DISPLAY*)OGK_allegroDisplay;
@end







>
>
>
>
>
>
>
>












|
<




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
 *       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 enum ogk_display_flags_t {
	OGK_DISPLAY_FLAGS_FULLSCREEN	= 0x01,
	OGK_DISPLAY_FLAGS_RESIZABLE	= 0x02,
	OGK_DISPLAY_FLAGS_OPENGL	= 0x04,
	OGK_DISPLAY_FLAGS_OPENGL_3	= 0x08,
	OGK_DISPLAY_FLAGS_OPENGL_3_ONLY	= 0x10
} ogk_display_flags_t;

@interface OGKDisplay: OFObject
{
	ALLEGRO_DISPLAY *display;
}

@property (assign) of_point_t windowPosition;
@property (assign) of_dimension_t size;

+ OGK_displayForAllegroDisplay: (ALLEGRO_DISPLAY*)display;
- initWithSize: (of_dimension_t)size
      position: (of_point_t)position
	 flags: (ogk_display_flags_t)flags;

- (void)setWindowTitle: (OFString*)title;
- (void)update;
- (ALLEGRO_DISPLAY*)OGK_allegroDisplay;
@end

Modified src/OGKDisplay.m from [fbfc273e25] to [c9b84695dd].

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
	[mutex lock];
	@try {
		ALLEGRO_DISPLAY **cArray = [allegroDisplays cArray];
		size_t i, count = [allegroDisplays count];

		for (i = 0; i < count; i++)
			if (cArray[i] == display)
				return [displays objectAtIndex: i];
	} @finally {
		[mutex unlock];
	}

	return nil;
}

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

	self = [super init];

#if 0
	/* TODO: Find a nice way to set these when requested */
	flags |= ALLEGRO_OPENGL_3_0;
	flags |= ALLEGRO_OPENGL_FORWARD_COMPATIBLE;
#endif

	al_set_new_window_position(position.x, position.y);

	if (fullscreen)
		flags |= ALLEGRO_FULLSCREEN;
	else if (resizable)
		flags |= ALLEGRO_RESIZABLE;







	al_set_new_display_flags(flags);
	display = al_create_display(size.width, size.height);

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

	[mutex lock];







|









|
<

|



<
<
<
<
<
<


|
|
|
|
>
>
>
>
>
>

|







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
	[mutex lock];
	@try {
		ALLEGRO_DISPLAY **cArray = [allegroDisplays cArray];
		size_t i, count = [allegroDisplays count];

		for (i = 0; i < count; i++)
			if (cArray[i] == display)
				return displays[i];
	} @finally {
		[mutex unlock];
	}

	return nil;
}

- initWithSize: (of_dimension_t)size
      position: (of_point_t)position
	 flags: (ogk_display_flags_t)flags

{
	int allegroFlags = 0;

	self = [super init];







	al_set_new_window_position(position.x, position.y);

	if (flags & OGK_DISPLAY_FLAGS_FULLSCREEN)
		allegroFlags |= ALLEGRO_FULLSCREEN;
	if (flags & OGK_DISPLAY_FLAGS_RESIZABLE)
		allegroFlags |= ALLEGRO_RESIZABLE;
	if (flags & OGK_DISPLAY_FLAGS_OPENGL)
		allegroFlags |= ALLEGRO_OPENGL;
	if (flags & OGK_DISPLAY_FLAGS_OPENGL_3)
		allegroFlags |= ALLEGRO_OPENGL_3_0;
	if (flags & OGK_DISPLAY_FLAGS_OPENGL_3_ONLY)
		allegroFlags |= ALLEGRO_OPENGL_FORWARD_COMPATIBLE;

	al_set_new_display_flags(allegroFlags);
	display = al_create_display(size.width, size.height);

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

	[mutex lock];

Modified test/TestMain.m from [003d86a89e] to [a7dbf6df22].

83
84
85
86
87
88
89


90
91
92
93
94
95
96
97
98
99
100
	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: position];
	[display update];
}

- (void)applicationDidFinishLaunching
{


	display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480)
					  position: of_point(200, 200)
					fullscreen: NO
					 resizable: NO];
	display.size = of_dimension(800, 600);
	display.windowPosition = of_point(100, 100);
	display.windowTitle = @"ObjGameKit test";

	of_log(@"Display is %.fx%.f at (%.f, %.f)",
	    display.size.width, display.size.height,
	    display.windowPosition.x, display.windowPosition.y);







>
>


|
<







83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
	[OGKBitmap clearToColor: OGK_COLOR_BLACK];
	[bitmap drawAtPosition: position];
	[display update];
}

- (void)applicationDidFinishLaunching
{
	ogk_display_flags_t flags = OGK_DISPLAY_FLAGS_RESIZABLE;

	display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480)
					  position: of_point(200, 200)
					     flags: flags];

	display.size = of_dimension(800, 600);
	display.windowPosition = of_point(100, 100);
	display.windowTitle = @"ObjGameKit test";

	of_log(@"Display is %.fx%.f at (%.f, %.f)",
	    display.size.width, display.size.height,
	    display.windowPosition.x, display.windowPosition.y);