IPHONE: Use Common::List to store the event queue.

This commit is contained in:
Johannes Schickel 2012-03-08 21:55:56 +01:00
parent 0a08b2461f
commit d27d8cec83
2 changed files with 31 additions and 122 deletions

View File

@ -34,10 +34,20 @@
#include "iphone_keyboard.h"
#include "iphone_common.h"
#include "common/list.h"
struct InternalEvent {
InternalEvent() : type(), value1(), value2() {}
InternalEvent(InputEvent t, int v1, int v2) : type(t), value1(v1), value2(v2) {}
InputEvent type;
int value1, value2;
};
@interface iPhoneView : UIView {
VideoContext _videoContext;
NSMutableArray *_events;
Common::List<InternalEvent> _events;
SoftKeyboard *_keyboardView;
EAGLContext *_context;
@ -94,8 +104,6 @@
- (void)updateMouseCursorScaling;
- (void)updateMouseCursor;
- (id)getEvent;
- (void)deviceOrientationChanged:(UIDeviceOrientation)orientation;
- (void)applicationSuspend;

View File

@ -66,21 +66,15 @@ void iPhone_updateScreen() {
}
bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) {
id event = [g_iPhoneViewInstance getEvent];
if (event == nil) {
Common::List<InternalEvent> &events = g_iPhoneViewInstance->_events;
if (events.empty())
return false;
}
id type = [event objectForKey:@"type"];
if (type == nil) {
printf("fetchEvent says: No type!\n");
return false;
}
*outEvent = [type intValue];
*outX = [[event objectForKey:@"x"] intValue];
*outY = [[event objectForKey:@"y"] intValue];
const InternalEvent &front = *events.begin();
*outEvent = front.type;
*outX = front.value1;
*outY = front.value2;
events.pop_front();
return true;
}
@ -575,23 +569,8 @@ const char *iPhone_getDocumentsDir() {
}
}
- (id)getEvent {
if (_events == nil || [_events count] == 0) {
return nil;
}
id event = [_events objectAtIndex: 0];
[_events removeObjectAtIndex: 0];
return event;
}
- (void)addEvent:(NSDictionary *)event {
if (_events == nil)
_events = [[NSMutableArray alloc] init];
[_events addObject: event];
- (void)addEvent:(InternalEvent)event {
_events.push_back(event);
}
/**
@ -664,14 +643,7 @@ const char *iPhone_getDocumentsDir() {
return;
}
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputOrientationChanged], @"type",
[NSNumber numberWithInt:orientation], @"x",
[NSNumber numberWithInt:0], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputOrientationChanged, orientation, 0)];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
@ -686,14 +658,7 @@ const char *iPhone_getDocumentsDir() {
return;
_firstTouch = touch;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseDown], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseDown, x, y)];
break;
}
@ -704,14 +669,7 @@ const char *iPhone_getDocumentsDir() {
return;
_secondTouch = touch;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseSecondDown], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseSecondDown, x, y)];
break;
}
}
@ -727,27 +685,13 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseDragged], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseDragged, x, y)];
} else if (touch == _secondTouch) {
CGPoint point = [touch locationInView:self];
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseSecondDragged], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseSecondDragged, x, y)];
}
}
}
@ -763,14 +707,7 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseUp], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseUp, x, y)];
break;
}
@ -780,14 +717,7 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseSecondUp], @"type",
[NSNumber numberWithInt:x], @"x",
[NSNumber numberWithInt:y], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputMouseSecondUp, x, y)];
break;
}
}
@ -797,14 +727,7 @@ const char *iPhone_getDocumentsDir() {
}
- (void)handleKeyPress:(unichar)c {
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputKeyPressed], @"type",
[NSNumber numberWithInt:c], @"x",
[NSNumber numberWithInt:0], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputKeyPressed, c, 0)];
}
- (BOOL)canHandleSwipes {
@ -814,38 +737,16 @@ const char *iPhone_getDocumentsDir() {
- (int)swipe:(int)num withEvent:(struct __GSEvent *)event {
//printf("swipe: %i\n", num);
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputSwipe], @"type",
[NSNumber numberWithInt:num], @"x",
[NSNumber numberWithInt:0], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputSwipe, num, 0)];
return 0;
}
- (void)applicationSuspend {
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputApplicationSuspended], @"type",
[NSNumber numberWithInt:0], @"x",
[NSNumber numberWithInt:0], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputApplicationSuspended, 0, 0)];
}
- (void)applicationResume {
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputApplicationResumed], @"type",
[NSNumber numberWithInt:0], @"x",
[NSNumber numberWithInt:0], @"y",
nil
]
];
[self addEvent:InternalEvent(kInputApplicationResumed, 0, 0)];
}
@end