Pass the display on events.
This commit is contained in:
parent
7e755a78c9
commit
b72b6c8ac7
6 changed files with 128 additions and 27 deletions
|
@ -30,6 +30,7 @@
|
|||
@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
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
|
||||
#import "OGKDisplay.h"
|
||||
|
||||
static OFMutex *mutex = nil;
|
||||
static OFMutableArray *displays = nil;
|
||||
static OFDataArray *allegroDisplays = nil;
|
||||
|
||||
@implementation OGKDisplay
|
||||
+ (void)initialize
|
||||
{
|
||||
|
@ -29,6 +33,28 @@
|
|||
if (!al_install_system(ALLEGRO_VERSION_INT, NULL))
|
||||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: self];
|
||||
|
||||
mutex = [[OFMutex alloc] init];
|
||||
displays = [[OFMutableArray alloc] init];
|
||||
allegroDisplays = [[OFDataArray alloc]
|
||||
initWithItemSize: sizeof(ALLEGRO_DISPLAY*)];
|
||||
}
|
||||
|
||||
+ OGK_displayForAllegroDisplay: (ALLEGRO_DISPLAY*)display
|
||||
{
|
||||
[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
|
||||
|
@ -60,11 +86,29 @@
|
|||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: [self class]];
|
||||
|
||||
[mutex lock];
|
||||
@try {
|
||||
[allegroDisplays addItem: &display];
|
||||
[displays addObject: self];
|
||||
} @finally {
|
||||
[mutex unlock];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[mutex lock];
|
||||
@try {
|
||||
size_t index = [displays indexOfObject: self];
|
||||
|
||||
[allegroDisplays removeItemAtIndex: index];
|
||||
[displays removeObjectAtIndex: index];
|
||||
} @finally {
|
||||
[mutex unlock];
|
||||
}
|
||||
|
||||
if (display != NULL)
|
||||
al_destroy_display(display);
|
||||
}
|
||||
|
|
|
@ -27,13 +27,18 @@
|
|||
|
||||
@protocol OGKEventQueueDelegate <OFObject>
|
||||
@optional
|
||||
- (void)displayWasClosed: (OGKCloseEvent*)event;
|
||||
// FIXME: Those need to get the OGKDisplay passed!
|
||||
- (void)keyWasPressed: (OGKKeyPressEvent*)event;
|
||||
- (void)keyWasReleased: (OGKKeyReleaseEvent*)event;
|
||||
- (void)mouseWasMoved: (OGKMouseMovedEvent*)event;
|
||||
- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event;
|
||||
- (void)mouseButtonWasReleased: (OGKMouseButtonReleasedEvent*)event;
|
||||
- (void)display: (OGKDisplay*)display
|
||||
wasClosed: (OGKCloseEvent*)event;
|
||||
- (void)keyWasPressed: (OGKKeyPressEvent*)event
|
||||
display: (OGKDisplay*)display;
|
||||
- (void)keyWasReleased: (OGKKeyReleaseEvent*)event
|
||||
display: (OGKDisplay*)display;
|
||||
- (void)mouseWasMoved: (OGKMouseMovedEvent*)event
|
||||
display: (OGKDisplay*)display;
|
||||
- (void)mouseButtonWasPressed: (OGKMouseButtonPressedEvent*)event
|
||||
display: (OGKDisplay*)display;
|
||||
- (void)mouseButtonWasReleased: (OGKMouseButtonReleasedEvent*)event
|
||||
display: (OGKDisplay*)display;
|
||||
@end
|
||||
|
||||
@interface OGKEventQueue: OFObject
|
||||
|
|
|
@ -63,36 +63,64 @@ static int mouse_retain_count = 0;
|
|||
object_setClass(event, [OGKCloseEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(displayWasClosed:)])
|
||||
[delegate displayWasClosed:
|
||||
(OGKCloseEvent*)event];
|
||||
@selector(display:wasClosed:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->display.source];
|
||||
OGKCloseEvent *closeEvent =
|
||||
(OGKCloseEvent*)event;
|
||||
|
||||
[delegate display: display
|
||||
wasClosed: closeEvent];
|
||||
}
|
||||
|
||||
break;
|
||||
case ALLEGRO_EVENT_KEY_DOWN:
|
||||
object_setClass(event, [OGKKeyPressEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(keyWasPressed:)])
|
||||
[delegate keyWasPressed:
|
||||
(OGKKeyPressEvent*)event];
|
||||
@selector(keyWasPressed:display:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->keyboard.display];
|
||||
OGKKeyPressEvent *keyPressEvent =
|
||||
(OGKKeyPressEvent*)event;
|
||||
|
||||
[delegate keyWasPressed: keyPressEvent
|
||||
display: display];
|
||||
}
|
||||
|
||||
break;
|
||||
case ALLEGRO_EVENT_KEY_UP:
|
||||
object_setClass(event, [OGKKeyReleaseEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(keyWasReleased:)])
|
||||
[delegate keyWasReleased:
|
||||
(OGKKeyReleaseEvent*)event];
|
||||
@selector(keyWasReleased:display:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->keyboard.display];
|
||||
OGKKeyReleaseEvent *keyReleaseEvent =
|
||||
(OGKKeyReleaseEvent*)event;
|
||||
|
||||
[delegate keyWasReleased: keyReleaseEvent
|
||||
display: display];
|
||||
}
|
||||
|
||||
break;
|
||||
case ALLEGRO_EVENT_MOUSE_AXES:
|
||||
object_setClass(event, [OGKMouseMovedEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(mouseWasMoved:)])
|
||||
[delegate mouseWasMoved:
|
||||
(OGKMouseMovedEvent*)event];
|
||||
@selector(mouseWasMoved:display:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->mouse.display];
|
||||
OGKMouseMovedEvent *mouseMovedEvent =
|
||||
(OGKMouseMovedEvent*)event;
|
||||
|
||||
[delegate mouseWasMoved: mouseMovedEvent
|
||||
display: display];
|
||||
}
|
||||
|
||||
break;
|
||||
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
|
||||
|
@ -100,9 +128,16 @@ static int mouse_retain_count = 0;
|
|||
[OGKMouseButtonPressedEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(mouseButtonWasPressed:)])
|
||||
[delegate mouseButtonWasPressed:
|
||||
(OGKMouseButtonPressedEvent*)event];
|
||||
@selector(mouseButtonWasPressed:display:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->mouse.display];
|
||||
OGKMouseButtonPressedEvent *pressedEvent =
|
||||
(OGKMouseButtonPressedEvent*)event;
|
||||
|
||||
[delegate mouseButtonWasPressed: pressedEvent
|
||||
display: display];
|
||||
}
|
||||
|
||||
break;
|
||||
case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
|
||||
|
@ -110,9 +145,16 @@ static int mouse_retain_count = 0;
|
|||
[OGKMouseButtonReleasedEvent class]);
|
||||
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(mouseButtonWasReleased:)])
|
||||
[delegate mouseButtonWasReleased:
|
||||
(OGKMouseButtonReleasedEvent*)event];
|
||||
@selector(mouseButtonWasReleased:display:)]) {
|
||||
OGKDisplay *display = [OGKDisplay
|
||||
OGK_displayForAllegroDisplay:
|
||||
allegroEvent->mouse.display];
|
||||
OGKMouseButtonReleasedEvent *releasedEvent =
|
||||
(OGKMouseButtonReleasedEvent*)event;
|
||||
|
||||
[delegate mouseButtonWasReleased: releasedEvent
|
||||
display: display];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
Reference in a new issue