From c2baff8cd6ea14e0450797856bd4c5808b397d87 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 26 Aug 2012 12:09:26 +0200 Subject: [PATCH] Use flags for -[OGKDisplay init...]. --- src/OGKDisplay.h | 11 +++++++++-- src/OGKDisplay.m | 29 ++++++++++++++--------------- test/TestMain.m | 5 +++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/OGKDisplay.h b/src/OGKDisplay.h index f6d24c8..bd76ddb 100644 --- a/src/OGKDisplay.h +++ b/src/OGKDisplay.h @@ -22,6 +22,14 @@ #import +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; @@ -33,8 +41,7 @@ + OGK_displayForAllegroDisplay: (ALLEGRO_DISPLAY*)display; - initWithSize: (of_dimension_t)size position: (of_point_t)position - fullscreen: (BOOL)fullscreen - resizable: (BOOL)resizable; + flags: (ogk_display_flags_t)flags; - (void)setWindowTitle: (OFString*)title; - (void)update; - (ALLEGRO_DISPLAY*)OGK_allegroDisplay; diff --git a/src/OGKDisplay.m b/src/OGKDisplay.m index b348e4b..ee97c0d 100644 --- a/src/OGKDisplay.m +++ b/src/OGKDisplay.m @@ -49,7 +49,7 @@ static OFDataArray *allegroDisplays = nil; for (i = 0; i < count; i++) if (cArray[i] == display) - return [displays objectAtIndex: i]; + return displays[i]; } @finally { [mutex unlock]; } @@ -59,27 +59,26 @@ static OFDataArray *allegroDisplays = nil; - initWithSize: (of_dimension_t)size position: (of_point_t)position - fullscreen: (BOOL)fullscreen - resizable: (BOOL)resizable + flags: (ogk_display_flags_t)flags { - int flags = 0; + int allegroFlags = 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; + 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(flags); + al_set_new_display_flags(allegroFlags); display = al_create_display(size.width, size.height); if (display == NULL) diff --git a/test/TestMain.m b/test/TestMain.m index 3aa5dbf..0641a34 100644 --- a/test/TestMain.m +++ b/test/TestMain.m @@ -87,10 +87,11 @@ OF_APPLICATION_DELEGATE(TestMain) - (void)applicationDidFinishLaunching { + ogk_display_flags_t flags = OGK_DISPLAY_FLAGS_RESIZABLE; + display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480) position: of_point(200, 200) - fullscreen: NO - resizable: NO]; + flags: flags]; display.size = of_dimension(800, 600); display.windowPosition = of_point(100, 100); display.windowTitle = @"ObjGameKit test";