aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorOystein Eftevaag2009-06-18 18:57:17 +0000
committerOystein Eftevaag2009-06-18 18:57:17 +0000
commit224e9840e18e3260ccbeb73496d2fb7b7e69e703 (patch)
tree4280862c6ad9820adb8246571dc470a95584afa4 /backends
parent0324f20e392a7a536471fc44fad2a3e081c3ef12 (diff)
downloadscummvm-rg350-224e9840e18e3260ccbeb73496d2fb7b7e69e703.tar.gz
scummvm-rg350-224e9840e18e3260ccbeb73496d2fb7b7e69e703.tar.bz2
scummvm-rg350-224e9840e18e3260ccbeb73496d2fb7b7e69e703.zip
Improved the iphone swipe input handling
svn-id: r41641
Diffstat (limited to 'backends')
-rw-r--r--backends/platform/iphone/iphone_video.m41
-rw-r--r--backends/platform/iphone/osys_iphone.cpp40
2 files changed, 45 insertions, 36 deletions
diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m
index 0392172aa2..61770a16c2 100644
--- a/backends/platform/iphone/iphone_video.m
+++ b/backends/platform/iphone/iphone_video.m
@@ -36,6 +36,9 @@ static int _textureHeight = 0;
NSLock* _lock = nil;
static int _needsScreenUpdate = 0;
+static UITouch* _firstTouch = NULL;
+static UITouch* _secondTouch = NULL;
+
// static long lastTick = 0;
// static int frames = 0;
@@ -47,14 +50,14 @@ void iPhone_updateScreen() {
}
void iPhone_updateScreenRect(unsigned short* screen, int x1, int y1, int x2, int y2) {
- [_lock lock];
+ //[_lock lock];
int y;
for (y = y1; y < y2; ++y) {
memcpy(&_textureBuffer[(y * _textureWidth + x1 )* 2], &screen[y * _width + x1], (x2 - x1) * 2);
}
- [_lock unlock];
+ //[_lock unlock];
}
@@ -192,12 +195,12 @@ uint getSizeNextPOT(uint size) {
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
- [_lock lock];
+ //[_lock lock];
// Unfortunately we have to update the whole texture every frame, since glTexSubImage2D is actually slower in all cases
// due to the iPhone internals having to convert the whole texture back from its internal format when used.
// In the future we could use several tiled textures instead.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _textureWidth, _textureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _textureBuffer);
- [_lock unlock];
+ //[_lock unlock];
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
@@ -280,7 +283,7 @@ uint getSizeNextPOT(uint size) {
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
// The color buffer is triple-buffered, so we clear it multiple times right away to avid doing any glClears later.
- int clearCount = 3;
+ int clearCount = 5;
while (clearCount-- > 0) {
glClear(GL_COLOR_BUFFER_BIT);
[_context presentRenderbuffer:GL_RENDERBUFFER_OES];
@@ -366,7 +369,6 @@ uint getSizeNextPOT(uint size) {
];
}
-
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
@@ -374,11 +376,12 @@ uint getSizeNextPOT(uint size) {
switch ([allTouches count]) {
case 1:
{
- UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
+ UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
if (!getLocalMouseCoords(&point))
return;
+ _firstTouch = touch;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseDown], @"type",
@@ -391,11 +394,12 @@ uint getSizeNextPOT(uint size) {
}
case 2:
{
- UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
+ UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
if (!getLocalMouseCoords(&point))
return;
+ _secondTouch = touch;
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseSecondDown], @"type",
@@ -413,14 +417,13 @@ uint getSizeNextPOT(uint size) {
{
NSSet *allTouches = [event allTouches];
- switch ([allTouches count]) {
- case 1:
- {
- UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
+ for (UITouch* touch in touches) {
+ if (touch == _firstTouch) {
+
CGPoint point = [touch locationInView:self];
if (!getLocalMouseCoords(&point))
return;
-
+
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseDragged], @"type",
@@ -429,15 +432,13 @@ uint getSizeNextPOT(uint size) {
nil
]
];
- break;
- }
- case 2:
- {
- UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
+
+ } else if (touch == _secondTouch) {
+
CGPoint point = [touch locationInView:self];
if (!getLocalMouseCoords(&point))
return;
-
+
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kInputMouseSecondDragged], @"type",
@@ -446,7 +447,7 @@ uint getSizeNextPOT(uint size) {
nil
]
];
- break;
+
}
}
}
diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp
index b72e8b65d5..4b5201d560 100644
--- a/backends/platform/iphone/osys_iphone.cpp
+++ b/backends/platform/iphone/osys_iphone.cpp
@@ -813,22 +813,22 @@ bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x,
return false;
}
+ static const int kNeededLength = 100;
+ static const int kMaxDeviation = 20;
+
int vecX = (x - _gestureStartX);
int vecY = (y - _gestureStartY);
- int lengthSq = vecX * vecX + vecY * vecY;
- //printf("Lengthsq: %u\n", lengthSq);
+
+ int absX = abs(vecX);
+ int absY = abs(vecY);
+
+ //printf("(%d, %d)\n", vecX, vecY);
- if (lengthSq > 15000) { // Long enough gesture to react upon.
+ if (absX >= kNeededLength || absY >= kNeededLength) { // Long enough gesture to react upon.
_gestureStartX = -1;
_gestureStartY = -1;
- float vecLength = sqrt(lengthSq);
- float vecXNorm = vecX / vecLength;
- float vecYNorm = vecY / vecLength;
-
- //printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
-
- if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
+ if (absX < kMaxDeviation && vecY >= kNeededLength) {
// Swipe down
event.type = Common::EVENT_KEYDOWN;
_queuedInputEvent.type = Common::EVENT_KEYUP;
@@ -837,7 +837,10 @@ bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x,
event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
_needEventRestPeriod = true;
- } else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
+ return true;
+ }
+
+ if (absX < kMaxDeviation && -vecY >= kNeededLength) {
// Swipe up
_mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
const char *dialogMsg;
@@ -849,8 +852,9 @@ bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x,
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
dialog.runModal();
return false;
-
- } else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
+ }
+
+ if (absY < kMaxDeviation && vecX >= kNeededLength) {
// Swipe right
_touchpadModeEnabled = !_touchpadModeEnabled;
const char *dialogMsg;
@@ -862,7 +866,9 @@ bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x,
dialog.runModal();
return false;
- } else if (vecXNorm < -0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
+ }
+
+ if (absY < kMaxDeviation && -vecX >= kNeededLength) {
// Swipe left
return false;
}
@@ -1106,16 +1112,18 @@ void OSystem_IPHONE::AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBuf
outQB->mAudioDataByteSize = 4 * s_AudioQueue.frameCount;
s_soundCallback(s_soundParam, (byte *)outQB->mAudioData, outQB->mAudioDataByteSize);
AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
- } else
+ } else {
AudioQueueStop(s_AudioQueue.queue, false);
+ }
}
void OSystem_IPHONE::mixCallback(void *sys, byte *samples, int len) {
OSystem_IPHONE *this_ = (OSystem_IPHONE *)sys;
assert(this_);
- if (this_->_mixer)
+ if (this_->_mixer) {
this_->_mixer->mixCallback(samples, len);
+ }
}
void OSystem_IPHONE::setupMixer() {