ObjGameKit  Check-in [e1d3ff7a4f]

Overview
Comment:New OGKDisplay methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e1d3ff7a4fbb44be4efb6dcce2ab4f088ef55977ac2afc3b15d37cce90fa7c96
User & Date: js on 2012-08-19 23:08:42
Other Links: manifest | tags
Context
2012-08-20
01:18
Pass the display on events. check-in: f309ba2b33 user: js tags: trunk
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
Changes

Modified src/OGKDisplay.h from [be99dd44f0] to [25cd74c4c2].

23
24
25
26
27
28
29



30

31
32

33
34
35
#import <ObjFW/ObjFW.h>

@interface OGKDisplay: OFObject
{
	ALLEGRO_DISPLAY *display;
}




- initWithSize: (of_dimension_t)size

    fullscreen: (BOOL)fullscreen
     resizable: (BOOL)resizable;

- (void)update;
- (ALLEGRO_DISPLAY*)OGK_allegroDisplay;
@end







>
>
>

>


>



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import <ObjFW/ObjFW.h>

@interface OGKDisplay: OFObject
{
	ALLEGRO_DISPLAY *display;
}

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

- 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

Modified src/OGKDisplay.m from [c89196f16c] to [3e2683ad84].

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

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

- initWithSize: (of_dimension_t)size

    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



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

	al_set_new_display_flags(flags);







>












>
>







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

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

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







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











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
111
112
113
}

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

- (void)setWindowTitle: (OFString*)title
{
	al_set_window_title(display,
	    [title cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);
}

- (void)setWindowPosition: (of_point_t)position
{
	al_set_window_position(display, position.x, position.y);
}

- (of_point_t)windowPosition
{
	int x, y;

	al_get_window_position(display, &x, &y);

	return of_point(x, y);
}

- (void)setSize: (of_dimension_t)size
{
	al_resize_display(display, size.width, size.height);
}

- (of_dimension_t)size
{
	return of_dimension(
	    al_get_display_width(display),
	    al_get_display_height(display));
}

- (void)update
{
	al_flip_display();
}

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

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

76
77
78
79
80
81
82

83
84








85
86
87
88
89
90
91
	[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];








>


>
>
>
>
>
>
>
>







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
	[bitmap drawAtPosition: of_point(160, 120)];
	[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);

	eventQueue = [[OGKEventQueue alloc] init];
	eventQueue.delegate = self;

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