aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/iphone
diff options
context:
space:
mode:
authorTravis Howell2009-07-18 00:53:31 +0000
committerTravis Howell2009-07-18 00:53:31 +0000
commitaa98f944fe87e21870f375581541926913a4ac82 (patch)
treeb9b8d19a94f4683ad699c6b590e9e8583241c014 /backends/platform/iphone
parentcdf751accda346f5d96e3fdfa2fd4a1b92ed4d19 (diff)
parent025702ba4084dcad8dbe65c07a718f086320c19c (diff)
downloadscummvm-rg350-aa98f944fe87e21870f375581541926913a4ac82.tar.gz
scummvm-rg350-aa98f944fe87e21870f375581541926913a4ac82.tar.bz2
scummvm-rg350-aa98f944fe87e21870f375581541926913a4ac82.zip
Merged revisions 42463,42468-42484,42486-42488,42490-42495,42498-42507,42510-42513,42516-42518,42521-42525,42527-42531,42533,42536-42540,42543,42545,42548,42551-42552,42558-42561,42563-42565,42570,42572 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk ........ r42463 | drmccoy | 2009-07-14 09:42:37 +1000 (Tue, 14 Jul 2009) | 1 line Allow resource loading from EXT even if the TOT has none again ........ r42468 | fingolfin | 2009-07-14 18:36:06 +1000 (Tue, 14 Jul 2009) | 1 line TINSEL: Don't use ioFailed to check if a file was opened succesfuly ........ r42469 | drmccoy | 2009-07-14 18:57:55 +1000 (Tue, 14 Jul 2009) | 1 line Removing ioFailed() usage and fixing a leak in case of error ........ r42470 | joostp | 2009-07-14 19:44:56 +1000 (Tue, 14 Jul 2009) | 2 lines commit peres' patch for #2813472: BASS: "showgrid" enabled triggers an assert ........ r42471 | dreammaster | 2009-07-14 20:26:56 +1000 (Tue, 14 Jul 2009) | 1 line Bugfix for player being able to walk through some objects against room walls ........ r42472 | dreammaster | 2009-07-14 20:55:51 +1000 (Tue, 14 Jul 2009) | 1 line Bugfix to cursor updates - it previously required that both X and Y positions had changed before a cursor change could occur ........ r42473 | joostp | 2009-07-14 21:15:21 +1000 (Tue, 14 Jul 2009) | 2 lines add workaround for #2687172: BASS: Occasional loss of speech ........ r42474 | Kirben | 2009-07-14 22:34:42 +1000 (Tue, 14 Jul 2009) | 1 line Add workaround for bug #1538873 - SIMON1 (French): Text wrongly displayed. ........ r42475 | vinterstum | 2009-07-14 22:55:54 +1000 (Tue, 14 Jul 2009) | 1 line Updated xcode project ........ r42476 | strangerke | 2009-07-14 23:25:38 +1000 (Tue, 14 Jul 2009) | 1 line Add detection for Playtoons CK 3 (FR) ........ r42477 | buddha_ | 2009-07-14 23:48:31 +1000 (Tue, 14 Jul 2009) | 1 line Fix some typos and grammar in sword1's Sound::checkSpeechFileEndianness-function's comments. ........ r42478 | Kirben | 2009-07-14 23:50:17 +1000 (Tue, 14 Jul 2009) | 1 line Change key combination to dump all script, due to conflict. ........ r42479 | vinterstum | 2009-07-14 23:52:11 +1000 (Tue, 14 Jul 2009) | 1 line Split the iPhone OSystem class up into several files ........ r42480 | Kirben | 2009-07-14 23:53:54 +1000 (Tue, 14 Jul 2009) | 1 line Update workaround for bug #1538873, which effects the Polish version of Simon the Sorcerer 2 too. ........ r42481 | Kirben | 2009-07-14 23:55:10 +1000 (Tue, 14 Jul 2009) | 1 line Remove last ioFailed() usage in AGOS game engine. ........ r42482 | buddha_ | 2009-07-15 01:02:17 +1000 (Wed, 15 Jul 2009) | 1 line Partially fix automatic restarting of AGI games (Addresses bug #2798797 ('AGI: larry 1 doesn't restart after dying') but doesn't fully fix it. There seems to be more to the problem still. Automatic restarting after dying of an STD doesn't take away the STD-condition and Larry continues to die in a loop). ........ r42483 | strangerke | 2009-07-15 01:48:05 +1000 (Wed, 15 Jul 2009) | 1 line Add detection for Playtoons 4 EN_ANY as supplied by goodoldgeorg in bug #2820006 ........ r42484 | eriktorbjorn | 2009-07-15 02:45:18 +1000 (Wed, 15 Jul 2009) | 3 lines Got rid of ioFailed(). I haven't actually tested it, but we don't use the MPEG decoder at the moment, and it was only used in the BACKEND_8BIT case anyway. ........ r42486 | lordhoto | 2009-07-15 04:14:20 +1000 (Wed, 15 Jul 2009) | 1 line Got rid of ioFailed in font code, also added another check for err() when loading bdf fonts from text files. ........ r42487 | lordhoto | 2009-07-15 04:15:07 +1000 (Wed, 15 Jul 2009) | 1 line Fix possible memory leak. ........ r42488 | fingolfin | 2009-07-15 04:24:20 +1000 (Wed, 15 Jul 2009) | 1 line Got rid of some more ioFailed uses (also fixed a potential leak in graphics/font.cpp, and handle eos correctly in the FLAC code) ........ r42490 | lordhoto | 2009-07-15 05:32:25 +1000 (Wed, 15 Jul 2009) | 2 lines Replaced char usage by int8, since char is unsigned on Linux/PPC by default. ........ r42491 | fingolfin | 2009-07-15 07:46:23 +1000 (Wed, 15 Jul 2009) | 1 line AGOS: Cleanup PN code a bit, trying to make sense out of it ........ r42492 | fingolfin | 2009-07-15 07:50:22 +1000 (Wed, 15 Jul 2009) | 1 line AGOS: Fixed potential OOBA crash in AGOSEngine_PN::opn_opcode26 ........ r42493 | lordhoto | 2009-07-15 08:47:33 +1000 (Wed, 15 Jul 2009) | 1 line Fix graphics glitch in LoL PC98 intro. ........ r42494 | fingolfin | 2009-07-15 09:03:25 +1000 (Wed, 15 Jul 2009) | 1 line AGOS: Some more cleanup and added some comments to the PN code ........ r42495 | buddha_ | 2009-07-15 09:03:40 +1000 (Wed, 15 Jul 2009) | 1 line Remove ioFailed() usage from AGI engine. ........ r42498 | Kirben | 2009-07-15 12:06:26 +1000 (Wed, 15 Jul 2009) | 1 line Fix bug #2821215 - DIG: Skipping planetarium animation disables F5 menu. ........ r42499 | Kirben | 2009-07-15 15:00:59 +1000 (Wed, 15 Jul 2009) | 1 line Hack is no longer required, due to revision 42498. ........ r42500 | dreammaster | 2009-07-15 18:55:12 +1000 (Wed, 15 Jul 2009) | 1 line Created a system for inserting arbitrary code fragments into game scripts, and added an initial fragment to fix the bug of being stuck in the past in the DW1 SCN version ........ r42501 | fingolfin | 2009-07-15 20:04:50 +1000 (Wed, 15 Jul 2009) | 1 line Got rid of two more ioFailed uses ........ r42502 | buddha_ | 2009-07-15 23:04:17 +1000 (Wed, 15 Jul 2009) | 1 line Remove ioFailed() usage from Cine engine. ........ r42503 | buddha_ | 2009-07-15 23:10:29 +1000 (Wed, 15 Jul 2009) | 1 line Fix some typos in TransactionError-enumeration's comments. ........ r42504 | Kirben | 2009-07-15 23:19:49 +1000 (Wed, 15 Jul 2009) | 1 line Fix recent PN regression in vc32_saveScreen(). ........ r42505 | Kirben | 2009-07-15 23:53:18 +1000 (Wed, 15 Jul 2009) | 1 line Add Discworld 1/2. ........ r42506 | Kirben | 2009-07-15 23:58:23 +1000 (Wed, 15 Jul 2009) | 1 line Add Cruise for a Corpse and games from MADE engine. ........ r42507 | lordhoto | 2009-07-16 01:51:47 +1000 (Thu, 16 Jul 2009) | 1 line Bugfix: Disallow GMM Save/Load while in kyragem scene. ........ r42510 | lordhoto | 2009-07-16 03:07:45 +1000 (Thu, 16 Jul 2009) | 1 line Fix "search" filter being settings lost in launcher, when using the "Edit Game..." menu for example. ........ r42511 | lordhoto | 2009-07-16 03:23:27 +1000 (Thu, 16 Jul 2009) | 1 line Fix bug, which caused the ListWidget to draw a widget background around the selected item, when the ListWidget had no focus. ........ r42512 | lordhoto | 2009-07-16 04:05:37 +1000 (Thu, 16 Jul 2009) | 1 line For a smoother user experience, use different colors for inverted text of the ListWidget, depending on whether the widget has focus or not. ........ r42513 | lordhoto | 2009-07-16 04:08:54 +1000 (Thu, 16 Jul 2009) | 1 line Fix formatting of some switch statements. ........ r42516 | robinwatts | 2009-07-16 06:51:31 +1000 (Thu, 16 Jul 2009) | 4 lines New ARM code blending Smartphone landscale scaler for WinCE port. Seems to work in my mockup - I don't have a smartphone resolution device to test it. ........ r42517 | lordhoto | 2009-07-16 08:19:16 +1000 (Thu, 16 Jul 2009) | 1 line Fix ugly spacing between tabs in classic theme (as reported by sunmax on -devel). ........ r42518 | lordhoto | 2009-07-16 08:19:31 +1000 (Thu, 16 Jul 2009) | 1 line Slightly brighten up the active tab color in the modern theme. ........ r42521 | dreammaster | 2009-07-16 12:27:26 +1000 (Thu, 16 Jul 2009) | 1 line Game script fix for bug #2525010 - in the GRA version, the luggage blocked Rincewind's exit from the Inn, leaving him in a non-walkable area ........ r42522 | dreammaster | 2009-07-16 14:06:35 +1000 (Thu, 16 Jul 2009) | 1 line Added no blocking fix for Present Outside Inn scene as well ........ r42523 | thebluegr | 2009-07-16 18:13:08 +1000 (Thu, 16 Jul 2009) | 1 line Added a detection entry for Pepper's Adventures in Time, and fixed an issue with _gfxop_set_pic(), which was causing crashes in that game ........ r42524 | thebluegr | 2009-07-16 18:17:38 +1000 (Thu, 16 Jul 2009) | 1 line Added the French version of KQ5 floppy (bug report #2812611) ........ r42525 | thebluegr | 2009-07-16 18:21:06 +1000 (Thu, 16 Jul 2009) | 1 line Added missing information for the newly-added version of Pepper ........ r42527 | dreammaster | 2009-07-16 19:31:31 +1000 (Thu, 16 Jul 2009) | 1 line Added game script fix for bug #2680397 - game hang when using the brochure on the Beekeeper ........ r42528 | dreammaster | 2009-07-16 19:53:19 +1000 (Thu, 16 Jul 2009) | 1 line Prior script fix also fixes bug #2820788, with stealing wizard's mallets ........ r42529 | tanoku | 2009-07-16 21:37:36 +1000 (Thu, 16 Jul 2009) | 2 lines Fixed issue with beveled shapes being drawn outside their shapes. Possible regressions. ........ r42530 | lordhoto | 2009-07-16 21:41:45 +1000 (Thu, 16 Jul 2009) | 1 line Formatting. ........ r42531 | lordhoto | 2009-07-16 21:42:07 +1000 (Thu, 16 Jul 2009) | 1 line Update classic and builtin theme after r42529. ........ r42533 | thebluegr | 2009-07-16 22:43:42 +1000 (Thu, 16 Jul 2009) | 1 line Added a proper fix for Pepper (the previous one caused regressions in KQ6) ........ r42536 | eriktorbjorn | 2009-07-17 03:26:44 +1000 (Fri, 17 Jul 2009) | 2 lines Fixed GCC warning. ........ r42537 | tanoku | 2009-07-17 03:29:31 +1000 (Fri, 17 Jul 2009) | 2 lines Fixed bug 2820514 ("Help dialog causes crash") ........ r42538 | lordhoto | 2009-07-17 03:39:16 +1000 (Fri, 17 Jul 2009) | 1 line Formatting fixes. ........ r42539 | lordhoto | 2009-07-17 03:44:05 +1000 (Fri, 17 Jul 2009) | 1 line This commit is just for DrMcCoy. (forgot to fix two usages of whitespaces instead of tabs for indentation -.-) ........ r42540 | tanoku | 2009-07-17 03:51:12 +1000 (Fri, 17 Jul 2009) | 2 lines Fixed bug: In-game console doesn't stay centered when switching resolutions on the fly. ........ r42543 | lordhoto | 2009-07-17 07:47:57 +1000 (Fri, 17 Jul 2009) | 1 line Fix bug in "KyraEngine_v2::runSceneScript6", fixes text line Zanthia says, when picking up the spellbook page in the town. ........ r42545 | Kirben | 2009-07-17 10:10:10 +1000 (Fri, 17 Jul 2009) | 1 line Fix using subtitles only setting in The Dig. ........ r42548 | Kirben | 2009-07-17 10:25:27 +1000 (Fri, 17 Jul 2009) | 1 line Fix bug #2821986 - COMI: setting to 'subtitles only' does not disable speech. ........ r42551 | drmccoy | 2009-07-17 10:55:42 +1000 (Fri, 17 Jul 2009) | 1 line Added some more debug warnings when resources can't be loaded ........ r42552 | drmccoy | 2009-07-17 10:55:56 +1000 (Fri, 17 Jul 2009) | 1 line Making TOTResourceItem::size unsigned, fixing a graphics bug that crept in ........ r42558 | dreammaster | 2009-07-17 15:10:24 +1000 (Fri, 17 Jul 2009) | 1 line Added an explicit break out of the event processing loop for mouse buttons and/or key-presses - this should allow stylus-based systems to properly process 'mouse down' events before the 'mouse up' is processed ........ r42559 | Kirben | 2009-07-17 16:26:37 +1000 (Fri, 17 Jul 2009) | 1 line Fix input glitch regression, after pausing in PN. ........ r42560 | Kirben | 2009-07-17 19:56:03 +1000 (Fri, 17 Jul 2009) | 1 line Fix bug #2822956 - ELVIRA2: Crash at the beginning (regression). ........ r42561 | Kirben | 2009-07-17 20:48:30 +1000 (Fri, 17 Jul 2009) | 1 line Correct error in saveBackGround. ........ r42563 | lordhoto | 2009-07-17 23:35:56 +1000 (Fri, 17 Jul 2009) | 1 line Replace LGPL header by GPL header. ........ r42564 | lordhoto | 2009-07-17 23:50:59 +1000 (Fri, 17 Jul 2009) | 3 lines - Moved SoundAdlibPC definition to new header file sound_adlib.h - Made the future versions of sound.h GPL only - sound_adlib.h is dual licensed under GPL and LGPL (so AdPlug can still benefit from future changes) ........ r42565 | lordhoto | 2009-07-18 00:05:22 +1000 (Sat, 18 Jul 2009) | 1 line Cleanup. ........ r42570 | drmccoy | 2009-07-18 05:22:12 +1000 (Sat, 18 Jul 2009) | 1 line Adding a workaround for the vanishing Coh Cott bug (#1972466), which is actually an error in that video file ........ r42572 | drmccoy | 2009-07-18 06:03:41 +1000 (Sat, 18 Jul 2009) | 1 line /Finally/ fixing the longstanding flicker bug in Woodruff. I was completely mistaken about its cause, too ........ svn-id: r42576
Diffstat (limited to 'backends/platform/iphone')
-rw-r--r--backends/platform/iphone/module.mk5
-rw-r--r--backends/platform/iphone/osys_events.cpp514
-rw-r--r--backends/platform/iphone/osys_iphone.cpp1303
-rw-r--r--backends/platform/iphone/osys_main.cpp296
-rw-r--r--backends/platform/iphone/osys_main.h (renamed from backends/platform/iphone/osys_iphone.h)0
-rw-r--r--backends/platform/iphone/osys_sound.cpp111
-rw-r--r--backends/platform/iphone/osys_video.cpp463
7 files changed, 1388 insertions, 1304 deletions
diff --git a/backends/platform/iphone/module.mk b/backends/platform/iphone/module.mk
index a3c9a012fe..28bc8d3ac7 100644
--- a/backends/platform/iphone/module.mk
+++ b/backends/platform/iphone/module.mk
@@ -1,7 +1,10 @@
MODULE := backends/platform/iphone
MODULE_OBJS := \
- osys_iphone.o \
+ osys_main.o \
+ osys_events.o \
+ osys_sound.o \
+ osys_video.o \
iphone_main.o \
iphone_video.o \
iphone_keyboard.o \
diff --git a/backends/platform/iphone/osys_events.cpp b/backends/platform/iphone/osys_events.cpp
new file mode 100644
index 0000000000..a190f68189
--- /dev/null
+++ b/backends/platform/iphone/osys_events.cpp
@@ -0,0 +1,514 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "gui/message.h"
+
+#include "osys_main.h"
+
+
+bool OSystem_IPHONE::pollEvent(Common::Event &event) {
+ //printf("pollEvent()\n");
+
+ long curTime = getMillis();
+
+ if (_timerCallback && (curTime >= _timerCallbackNext)) {
+ _timerCallback(_timerCallbackTimer);
+ _timerCallbackNext = curTime + _timerCallbackTimer;
+ }
+
+ if (_needEventRestPeriod) {
+ // Workaround: Some engines can't handle mouse-down and mouse-up events
+ // appearing right after each other, without a call returning no input in between.
+ _needEventRestPeriod = false;
+ return false;
+ }
+
+ if (_queuedInputEvent.type != (Common::EventType)0) {
+ event = _queuedInputEvent;
+ _queuedInputEvent.type = (Common::EventType)0;
+ return true;
+ }
+
+ int eventType;
+ float xUnit, yUnit;
+
+ if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) {
+ int x = 0;
+ int y = 0;
+ switch (_screenOrientation) {
+ case kScreenOrientationPortrait:
+ x = (int)(xUnit * _screenWidth);
+ y = (int)(yUnit * _screenHeight);
+ break;
+ case kScreenOrientationLandscape:
+ x = (int)(yUnit * _screenWidth);
+ y = (int)((1.0 - xUnit) * _screenHeight);
+ break;
+ case kScreenOrientationFlippedLandscape:
+ x = (int)((1.0 - yUnit) * _screenWidth);
+ y = (int)(xUnit * _screenHeight);
+ break;
+ }
+
+ switch ((InputEvent)eventType) {
+ case kInputMouseDown:
+ if (!handleEvent_mouseDown(event, x, y))
+ return false;
+ break;
+
+ case kInputMouseUp:
+ if (!handleEvent_mouseUp(event, x, y))
+ return false;
+ break;
+
+ case kInputMouseDragged:
+ if (!handleEvent_mouseDragged(event, x, y))
+ return false;
+ break;
+ case kInputMouseSecondDragged:
+ if (!handleEvent_mouseSecondDragged(event, x, y))
+ return false;
+ break;
+ case kInputMouseSecondDown:
+ _secondaryTapped = true;
+ if (!handleEvent_secondMouseDown(event, x, y))
+ return false;
+ break;
+ case kInputMouseSecondUp:
+ _secondaryTapped = false;
+ if (!handleEvent_secondMouseUp(event, x, y))
+ return false;
+ break;
+ case kInputOrientationChanged:
+ handleEvent_orientationChanged((int)xUnit);
+ return false;
+ break;
+
+ case kInputApplicationSuspended:
+ suspendLoop();
+ return false;
+ break;
+
+ case kInputKeyPressed:
+ handleEvent_keyPressed(event, (int)xUnit);
+ break;
+
+ case kInputSwipe:
+ if (!handleEvent_swipe(event, (int)xUnit))
+ return false;
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+ }
+ return false;
+}
+
+bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) {
+ //printf("Mouse down at (%u, %u)\n", x, y);
+
+ // Workaround: kInputMouseSecondToggled isn't always sent when the
+ // secondary finger is lifted. Need to make sure we get out of that mode.
+ _secondaryTapped = false;
+
+ if (_touchpadModeEnabled) {
+ _lastPadX = x;
+ _lastPadY = y;
+ } else
+ warpMouse(x, y);
+
+ if (_mouseClickAndDragEnabled) {
+ event.type = Common::EVENT_LBUTTONDOWN;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+ return true;
+ } else {
+ _lastMouseDown = getMillis();
+ }
+ return false;
+}
+
+bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) {
+ //printf("Mouse up at (%u, %u)\n", x, y);
+
+ if (_secondaryTapped) {
+ _secondaryTapped = false;
+ if (!handleEvent_secondMouseUp(event, x, y))
+ return false;
+ }
+ else if (_mouseClickAndDragEnabled) {
+ event.type = Common::EVENT_LBUTTONUP;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+ } else {
+ if (getMillis() - _lastMouseDown < 250) {
+ event.type = Common::EVENT_LBUTTONDOWN;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+
+ _queuedInputEvent.type = Common::EVENT_LBUTTONUP;
+ _queuedInputEvent.mouse.x = _mouseX;
+ _queuedInputEvent.mouse.y = _mouseY;
+ _lastMouseTap = getMillis();
+ _needEventRestPeriod = true;
+ } else
+ return false;
+ }
+
+ return true;
+}
+
+bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, int y) {
+ _lastSecondaryDown = getMillis();
+ _gestureStartX = x;
+ _gestureStartY = y;
+
+ if (_mouseClickAndDragEnabled) {
+ event.type = Common::EVENT_LBUTTONUP;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+
+ _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN;
+ _queuedInputEvent.mouse.x = _mouseX;
+ _queuedInputEvent.mouse.y = _mouseY;
+ }
+ else
+ return false;
+
+ return true;
+}
+
+bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int y) {
+ int curTime = getMillis();
+
+ if (curTime - _lastSecondaryDown < 400 ) {
+ //printf("Right tap!\n");
+ if (curTime - _lastSecondaryTap < 400 && !_overlayVisible) {
+ //printf("Right escape!\n");
+ event.type = Common::EVENT_KEYDOWN;
+ _queuedInputEvent.type = Common::EVENT_KEYUP;
+
+ event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+ event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
+ event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE;
+ _needEventRestPeriod = true;
+ _lastSecondaryTap = 0;
+ } else if (!_mouseClickAndDragEnabled) {
+ //printf("Rightclick!\n");
+ event.type = Common::EVENT_RBUTTONDOWN;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+ _queuedInputEvent.type = Common::EVENT_RBUTTONUP;
+ _queuedInputEvent.mouse.x = _mouseX;
+ _queuedInputEvent.mouse.y = _mouseY;
+ _lastSecondaryTap = curTime;
+ _needEventRestPeriod = true;
+ } else {
+ //printf("Right nothing!\n");
+ return false;
+ }
+ }
+ if (_mouseClickAndDragEnabled) {
+ event.type = Common::EVENT_RBUTTONUP;
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+ }
+
+ return true;
+}
+
+bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y) {
+ if (_lastDragPosX == x && _lastDragPosY == y)
+ return false;
+
+ _lastDragPosX = x;
+ _lastDragPosY = y;
+
+ //printf("Mouse dragged at (%u, %u)\n", x, y);
+ int mouseNewPosX;
+ int mouseNewPosY;
+ if (_touchpadModeEnabled ) {
+ int deltaX = _lastPadX - x;
+ int deltaY = _lastPadY - y;
+ _lastPadX = x;
+ _lastPadY = y;
+
+ mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
+ mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
+
+ if (mouseNewPosX < 0)
+ mouseNewPosX = 0;
+ else if (mouseNewPosX > _screenWidth)
+ mouseNewPosX = _screenWidth;
+
+ if (mouseNewPosY < 0)
+ mouseNewPosY = 0;
+ else if (mouseNewPosY > _screenHeight)
+ mouseNewPosY = _screenHeight;
+
+ } else {
+ mouseNewPosX = x;
+ mouseNewPosY = y;
+ }
+
+ event.type = Common::EVENT_MOUSEMOVE;
+ event.mouse.x = mouseNewPosX;
+ event.mouse.y = mouseNewPosY;
+ warpMouse(mouseNewPosX, mouseNewPosY);
+
+ return true;
+}
+
+bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x, int y) {
+ if (_gestureStartX == -1 || _gestureStartY == -1) {
+ return false;
+ }
+
+ static const int kNeededLength = 100;
+ static const int kMaxDeviation = 20;
+
+ int vecX = (x - _gestureStartX);
+ int vecY = (y - _gestureStartY);
+
+ int absX = abs(vecX);
+ int absY = abs(vecY);
+
+ //printf("(%d, %d)\n", vecX, vecY);
+
+ if (absX >= kNeededLength || absY >= kNeededLength) { // Long enough gesture to react upon.
+ _gestureStartX = -1;
+ _gestureStartY = -1;
+
+ if (absX < kMaxDeviation && vecY >= kNeededLength) {
+ // Swipe down
+ event.type = Common::EVENT_KEYDOWN;
+ _queuedInputEvent.type = Common::EVENT_KEYUP;
+
+ event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+ event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
+ event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
+ _needEventRestPeriod = true;
+ return true;
+ }
+
+ if (absX < kMaxDeviation && -vecY >= kNeededLength) {
+ // Swipe up
+ _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
+ const char *dialogMsg;
+ if (_mouseClickAndDragEnabled) {
+ _touchpadModeEnabled = false;
+ dialogMsg = "Mouse-click-and-drag mode enabled.";
+ } else
+ dialogMsg = "Mouse-click-and-drag mode disabled.";
+ GUI::TimedMessageDialog dialog(dialogMsg, 1500);
+ dialog.runModal();
+ return false;
+ }
+
+ if (absY < kMaxDeviation && vecX >= kNeededLength) {
+ // Swipe right
+ _touchpadModeEnabled = !_touchpadModeEnabled;
+ const char *dialogMsg;
+ if (_touchpadModeEnabled)
+ dialogMsg = "Touchpad mode enabled.";
+ else
+ dialogMsg = "Touchpad mode disabled.";
+ GUI::TimedMessageDialog dialog(dialogMsg, 1500);
+ dialog.runModal();
+ return false;
+
+ }
+
+ if (absY < kMaxDeviation && -vecX >= kNeededLength) {
+ // Swipe left
+ return false;
+ }
+ }
+
+ return false;
+}
+
+void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) {
+ //printf("Orientation: %i\n", orientation);
+
+ ScreenOrientation newOrientation;
+ switch (orientation) {
+ case 1:
+ newOrientation = kScreenOrientationPortrait;
+ break;
+ case 3:
+ newOrientation = kScreenOrientationLandscape;
+ break;
+ case 4:
+ newOrientation = kScreenOrientationFlippedLandscape;
+ break;
+ default:
+ return;
+ }
+
+
+ if (_screenOrientation != newOrientation) {
+ _screenOrientation = newOrientation;
+ iPhone_initSurface(_screenWidth, _screenHeight);
+
+ dirtyFullScreen();
+ if (_overlayVisible)
+ dirtyFullOverlayScreen();
+ updateScreen();
+ }
+}
+
+void OSystem_IPHONE::handleEvent_keyPressed(Common::Event &event, int keyPressed) {
+ int ascii = keyPressed;
+ //printf("key: %i\n", keyPressed);
+
+ // We remap some of the iPhone keyboard keys.
+ // The first ten here are the row of symbols below the numeric keys.
+ switch (keyPressed) {
+ case 45:
+ keyPressed = Common::KEYCODE_F1;
+ ascii = Common::ASCII_F1;
+ break;
+ case 47:
+ keyPressed = Common::KEYCODE_F2;
+ ascii = Common::ASCII_F2;
+ break;
+ case 58:
+ keyPressed = Common::KEYCODE_F3;
+ ascii = Common::ASCII_F3;
+ break;
+ case 59:
+ keyPressed = Common::KEYCODE_F4;
+ ascii = Common::ASCII_F4;
+ break;
+ case 40:
+ keyPressed = Common::KEYCODE_F5;
+ ascii = Common::ASCII_F5;
+ break;
+ case 41:
+ keyPressed = Common::KEYCODE_F6;
+ ascii = Common::ASCII_F6;
+ break;
+ case 36:
+ keyPressed = Common::KEYCODE_F7;
+ ascii = Common::ASCII_F7;
+ break;
+ case 38:
+ keyPressed = Common::KEYCODE_F8;
+ ascii = Common::ASCII_F8;
+ break;
+ case 64:
+ keyPressed = Common::KEYCODE_F9;
+ ascii = Common::ASCII_F9;
+ break;
+ case 34:
+ keyPressed = Common::KEYCODE_F10;
+ ascii = Common::ASCII_F10;
+ break;
+ case 10:
+ keyPressed = Common::KEYCODE_RETURN;
+ ascii = Common::ASCII_RETURN;
+ break;
+ }
+ event.type = Common::EVENT_KEYDOWN;
+ _queuedInputEvent.type = Common::EVENT_KEYUP;
+
+ event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+ event.kbd.keycode = _queuedInputEvent.kbd.keycode = (Common::KeyCode)keyPressed;
+ event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii;
+ _needEventRestPeriod = true;
+}
+
+bool OSystem_IPHONE::handleEvent_swipe(Common::Event &event, int direction) {
+ Common::KeyCode keycode = Common::KEYCODE_INVALID;
+ switch (_screenOrientation) {
+ case kScreenOrientationPortrait:
+ switch ((UIViewSwipeDirection)direction) {
+ case kUIViewSwipeUp:
+ keycode = Common::KEYCODE_UP;
+ break;
+ case kUIViewSwipeDown:
+ keycode = Common::KEYCODE_DOWN;
+ break;
+ case kUIViewSwipeLeft:
+ keycode = Common::KEYCODE_LEFT;
+ break;
+ case kUIViewSwipeRight:
+ keycode = Common::KEYCODE_RIGHT;
+ break;
+ default:
+ return false;
+ }
+ break;
+ case kScreenOrientationLandscape:
+ switch ((UIViewSwipeDirection)direction) {
+ case kUIViewSwipeUp:
+ keycode = Common::KEYCODE_LEFT;
+ break;
+ case kUIViewSwipeDown:
+ keycode = Common::KEYCODE_RIGHT;
+ break;
+ case kUIViewSwipeLeft:
+ keycode = Common::KEYCODE_DOWN;
+ break;
+ case kUIViewSwipeRight:
+ keycode = Common::KEYCODE_UP;
+ break;
+ default:
+ return false;
+ }
+ break;
+ case kScreenOrientationFlippedLandscape:
+ switch ((UIViewSwipeDirection)direction) {
+ case kUIViewSwipeUp:
+ keycode = Common::KEYCODE_RIGHT;
+ break;
+ case kUIViewSwipeDown:
+ keycode = Common::KEYCODE_LEFT;
+ break;
+ case kUIViewSwipeLeft:
+ keycode = Common::KEYCODE_UP;
+ break;
+ case kUIViewSwipeRight:
+ keycode = Common::KEYCODE_DOWN;
+ break;
+ default:
+ return false;
+ }
+ break;
+ }
+
+ event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode;
+ event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0;
+ event.type = Common::EVENT_KEYDOWN;
+ _queuedInputEvent.type = Common::EVENT_KEYUP;
+ event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+ _needEventRestPeriod = true;
+
+ return true;
+}
diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp
deleted file mode 100644
index 7f30c0caaf..0000000000
--- a/backends/platform/iphone/osys_iphone.cpp
+++ /dev/null
@@ -1,1303 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include <unistd.h>
-#include <pthread.h>
-
-#include <sys/time.h>
-
-#include "common/scummsys.h"
-#include "common/util.h"
-#include "common/rect.h"
-#include "common/file.h"
-#include "common/fs.h"
-
-#include "base/main.h"
-
-#include "backends/saves/default/default-saves.h"
-#include "backends/timer/default/default-timer.h"
-#include "sound/mixer.h"
-#include "sound/mixer_intern.h"
-#include "gui/message.h"
-
-#include "osys_iphone.h"
-
-
-const OSystem::GraphicsMode OSystem_IPHONE::s_supportedGraphicsModes[] = {
- {0, 0, 0}
-};
-
-AQCallbackStruct OSystem_IPHONE::s_AudioQueue;
-SoundProc OSystem_IPHONE::s_soundCallback = NULL;
-void *OSystem_IPHONE::s_soundParam = NULL;
-
-OSystem_IPHONE::OSystem_IPHONE() :
- _savefile(NULL), _mixer(NULL), _timer(NULL), _offscreen(NULL),
- _overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL),
- _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0),
- _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape),
- _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(true),
- _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false),
- _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0)
-
-{
- _queuedInputEvent.type = (Common::EventType)0;
- _lastDrawnMouseRect = Common::Rect(0, 0, 0, 0);
-
- _fsFactory = new POSIXFilesystemFactory();
-}
-
-OSystem_IPHONE::~OSystem_IPHONE() {
- AudioQueueDispose(s_AudioQueue.queue, true);
-
- delete _fsFactory;
- delete _savefile;
- delete _mixer;
- delete _timer;
- delete _offscreen;
- delete _fullscreen;
-}
-
-int OSystem_IPHONE::timerHandler(int t) {
- DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
- tm->handler();
- return t;
-}
-
-void OSystem_IPHONE::initBackend() {
-#ifdef IPHONE_OFFICIAL
- _savefile = new DefaultSaveFileManager(iPhone_getDocumentsDir());
-#else
- _savefile = new DefaultSaveFileManager(SCUMMVM_SAVE_PATH);
-#endif
-
- _timer = new DefaultTimerManager();
-
- gettimeofday(&_startTime, NULL);
-
- setupMixer();
-
- setTimerCallback(&OSystem_IPHONE::timerHandler, 10);
-
- OSystem::initBackend();
-}
-
-bool OSystem_IPHONE::hasFeature(Feature f) {
- return false;
-}
-
-void OSystem_IPHONE::setFeatureState(Feature f, bool enable) {
-}
-
-bool OSystem_IPHONE::getFeatureState(Feature f) {
- return false;
-}
-
-const OSystem::GraphicsMode* OSystem_IPHONE::getSupportedGraphicsModes() const {
- return s_supportedGraphicsModes;
-}
-
-
-int OSystem_IPHONE::getDefaultGraphicsMode() const {
- return -1;
-}
-
-bool OSystem_IPHONE::setGraphicsMode(const char *mode) {
- return true;
-}
-
-bool OSystem_IPHONE::setGraphicsMode(int mode) {
- return true;
-}
-
-int OSystem_IPHONE::getGraphicsMode() const {
- return -1;
-}
-
-void OSystem_IPHONE::initSize(uint width, uint height) {
- //printf("initSize(%i, %i)\n", width, height);
-
- _screenWidth = width;
- _screenHeight = height;
-
- free(_offscreen);
-
- _offscreen = (byte *)malloc(width * height);
- bzero(_offscreen, width * height);
-
- free(_overlayBuffer);
-
- int fullSize = _screenWidth * _screenHeight * sizeof(OverlayColor);
- _overlayBuffer = (OverlayColor *)malloc(fullSize);
- clearOverlay();
-
- free(_fullscreen);
-
- _fullscreen = (uint16 *)malloc(fullSize);
- bzero(_fullscreen, fullSize);
-
- iPhone_initSurface(width, height);
-
- _fullScreenIsDirty = false;
- dirtyFullScreen();
- _mouseVisible = false;
- _screenChangeCount++;
- updateScreen();
-}
-
-int16 OSystem_IPHONE::getHeight() {
- return _screenHeight;
-}
-
-int16 OSystem_IPHONE::getWidth() {
- return _screenWidth;
-}
-
-void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) {
- //printf("setPalette()\n");
- const byte *b = colors;
-
- for (uint i = start; i < start + num; ++i) {
- _palette[i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(b[0], b[1], b[2]);
- b += 4;
- }
-
- dirtyFullScreen();
-}
-
-void OSystem_IPHONE::grabPalette(byte *colors, uint start, uint num) {
- //printf("grabPalette()\n");
-}
-
-void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
- //printf("copyRectToScreen(%i, %i, %i, %i)\n", x, y, w, h);
- //Clip the coordinates
- if (x < 0) {
- w += x;
- buf -= x;
- x = 0;
- }
-
- if (y < 0) {
- h += y;
- buf -= y * pitch;
- y = 0;
- }
-
- if (w > _screenWidth - x) {
- w = _screenWidth - x;
- }
-
- if (h > _screenHeight - y) {
- h = _screenHeight - y;
- }
-
- if (w <= 0 || h <= 0)
- return;
-
- if (!_fullScreenIsDirty) {
- _dirtyRects.push_back(Common::Rect(x, y, x + w, y + h));
- }
-
-
- byte *dst = _offscreen + y * _screenWidth + x;
- if (_screenWidth == pitch && pitch == w)
- memcpy(dst, buf, h * w);
- else {
- do {
- memcpy(dst, buf, w);
- buf += pitch;
- dst += _screenWidth;
- } while (--h);
- }
-}
-
-void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) {
- if (x < 0) {
- w += x;
- x = 0;
- }
-
- if (y < 0) {
- h += y;
- y = 0;
- }
-
- if (w > _screenWidth - x)
- w = _screenWidth - x;
-
- if (h > _screenHeight - y)
- h = _screenHeight - y;
-
- if (w < 0) {
- w = 0;
- }
-
- if (h < 0) {
- h = 0;
- }
-}
-
-void OSystem_IPHONE::updateScreen() {
- //printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size());
-
- if (_dirtyRects.size() == 0 && _dirtyOverlayRects.size() == 0 && !_mouseDirty)
- return;
-
- internUpdateScreen();
- _fullScreenIsDirty = false;
- _fullScreenOverlayIsDirty = false;
-
- iPhone_updateScreen();
-}
-
-void OSystem_IPHONE::internUpdateScreen() {
- int16 mouseX = _mouseX - _mouseHotspotX;
- int16 mouseY = _mouseY - _mouseHotspotY;
- int16 mouseWidth = _mouseWidth;
- int16 mouseHeight = _mouseHeight;
-
- clipRectToScreen(mouseX, mouseY, mouseWidth, mouseHeight);
-
- Common::Rect mouseRect(mouseX, mouseY, mouseX + mouseWidth, mouseY + mouseHeight);
-
- if (_mouseDirty) {
- if (!_fullScreenIsDirty) {
- _dirtyRects.push_back(_lastDrawnMouseRect);
- _dirtyRects.push_back(mouseRect);
- }
- if (!_fullScreenOverlayIsDirty && _overlayVisible) {
- _dirtyOverlayRects.push_back(_lastDrawnMouseRect);
- _dirtyOverlayRects.push_back(mouseRect);
- }
- _mouseDirty = false;
- _lastDrawnMouseRect = mouseRect;
- }
-
- while (_dirtyRects.size()) {
- Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1);
-
- //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
-
- drawDirtyRect(dirtyRect);
-
- if (_overlayVisible)
- drawDirtyOverlayRect(dirtyRect);
-
- drawMouseCursorOnRectUpdate(dirtyRect, mouseRect);
- updateHardwareSurfaceForRect(dirtyRect);
- }
-
- if (_overlayVisible) {
- while (_dirtyOverlayRects.size()) {
- Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1);
-
- //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
-
- drawDirtyOverlayRect(dirtyRect);
- drawMouseCursorOnRectUpdate(dirtyRect, mouseRect);
- updateHardwareSurfaceForRect(dirtyRect);
- }
- }
-}
-
-void OSystem_IPHONE::drawDirtyRect(const Common::Rect& dirtyRect) {
- int h = dirtyRect.bottom - dirtyRect.top;
- int w = dirtyRect.right - dirtyRect.left;
-
- byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
- uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
- for (int y = h; y > 0; y--) {
- for (int x = w; x > 0; x--)
- *dst++ = _palette[*src++];
-
- dst += _screenWidth - w;
- src += _screenWidth - w;
- }
-}
-
-void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect& dirtyRect) {
- int h = dirtyRect.bottom - dirtyRect.top;
-
- uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left];
- uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
- int x = (dirtyRect.right - dirtyRect.left) * 2;
- for (int y = h; y > 0; y--) {
- memcpy(dst, src, x);
- src += _screenWidth;
- dst += _screenWidth;
- }
-}
-
-void OSystem_IPHONE::drawMouseCursorOnRectUpdate(const Common::Rect& updatedRect, const Common::Rect& mouseRect) {
- //draw mouse on top
- if (_mouseVisible && (updatedRect.intersects(mouseRect))) {
- int srcX = 0;
- int srcY = 0;
- int left = _mouseX - _mouseHotspotX;
- if (left < 0) {
- srcX -= left;
- left = 0;
- }
- int top = _mouseY - _mouseHotspotY;
- if (top < 0) {
- srcY -= top;
- top = 0;
- }
- //int right = left + _mouseWidth;
- int bottom = top + _mouseHeight;
- if (bottom > _screenWidth)
- bottom = _screenWidth;
- int displayWidth = _mouseWidth;
- if (_mouseWidth + left > _screenWidth)
- displayWidth = _screenWidth - left;
- int displayHeight = _mouseHeight;
- if (_mouseHeight + top > _screenHeight)
- displayHeight = _screenHeight - top;
- byte *src = &_mouseBuf[srcY * _mouseWidth + srcX];
- uint16 *dst = &_fullscreen[top * _screenWidth + left];
- for (int y = displayHeight; y > srcY; y--) {
- for (int x = displayWidth; x > srcX; x--) {
- if (*src != _mouseKeyColour)
- *dst = _palette[*src];
- dst++;
- src++;
- }
- dst += _screenWidth - displayWidth + srcX;
- src += _mouseWidth - displayWidth + srcX;
- }
- }
-}
-
-void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect& updatedRect) {
- iPhone_updateScreenRect(_fullscreen, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom );
-}
-
-Graphics::Surface *OSystem_IPHONE::lockScreen() {
- //printf("lockScreen()\n");
-
- _framebuffer.pixels = _offscreen;
- _framebuffer.w = _screenWidth;
- _framebuffer.h = _screenHeight;
- _framebuffer.pitch = _screenWidth;
- _framebuffer.bytesPerPixel = 1;
-
- return &_framebuffer;
-}
-
-void OSystem_IPHONE::unlockScreen() {
- //printf("unlockScreen()\n");
- dirtyFullScreen();
-}
-
-void OSystem_IPHONE::setShakePos(int shakeOffset) {
- //printf("setShakePos(%i)\n", shakeOffset);
-}
-
-void OSystem_IPHONE::showOverlay() {
- //printf("showOverlay()\n");
- _overlayVisible = true;
- dirtyFullOverlayScreen();
-}
-
-void OSystem_IPHONE::hideOverlay() {
- //printf("hideOverlay()\n");
- _overlayVisible = false;
- _dirtyOverlayRects.clear();
- dirtyFullScreen();
-}
-
-void OSystem_IPHONE::clearOverlay() {
- //printf("clearOverlay()\n");
- bzero(_overlayBuffer, _screenWidth * _screenHeight * sizeof(OverlayColor));
- dirtyFullOverlayScreen();
-}
-
-void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) {
- //printf("grabOverlay()\n");
- int h = _screenHeight;
- OverlayColor *src = _overlayBuffer;
-
- do {
- memcpy(buf, src, _screenWidth * sizeof(OverlayColor));
- src += _screenWidth;
- buf += pitch;
- } while (--h);
-}
-
-void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
- //printf("copyRectToOverlay(buf, pitch=%i, x=%i, y=%i, w=%i, h=%i)\n", pitch, x, y, w, h);
-
- //Clip the coordinates
- if (x < 0) {
- w += x;
- buf -= x;
- x = 0;
- }
-
- if (y < 0) {
- h += y;
- buf -= y * pitch;
- y = 0;
- }
-
- if (w > _screenWidth - x)
- w = _screenWidth - x;
-
- if (h > _screenHeight - y)
- h = _screenHeight - y;
-
- if (w <= 0 || h <= 0)
- return;
-
- if (!_fullScreenOverlayIsDirty) {
- _dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h));
- }
-
- OverlayColor *dst = _overlayBuffer + (y * _screenWidth + x);
- if (_screenWidth == pitch && pitch == w)
- memcpy(dst, buf, h * w * sizeof(OverlayColor));
- else {
- do {
- memcpy(dst, buf, w * sizeof(OverlayColor));
- buf += pitch;
- dst += _screenWidth;
- } while (--h);
- }
-}
-
-int16 OSystem_IPHONE::getOverlayHeight() {
- return _screenHeight;
-}
-
-int16 OSystem_IPHONE::getOverlayWidth() {
- return _screenWidth;
-}
-
-bool OSystem_IPHONE::showMouse(bool visible) {
- bool last = _mouseVisible;
- _mouseVisible = visible;
- _mouseDirty = true;
-
- return last;
-}
-
-void OSystem_IPHONE::warpMouse(int x, int y) {
- //printf("warpMouse()\n");
-
- _mouseX = x;
- _mouseY = y;
- _mouseDirty = true;
-}
-
-void OSystem_IPHONE::dirtyFullScreen() {
- if (!_fullScreenIsDirty) {
- _dirtyRects.clear();
- _dirtyRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight));
- _fullScreenIsDirty = true;
- }
-}
-
-void OSystem_IPHONE::dirtyFullOverlayScreen() {
- if (!_fullScreenOverlayIsDirty) {
- _dirtyOverlayRects.clear();
- _dirtyOverlayRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight));
- _fullScreenOverlayIsDirty = true;
- }
-}
-
-void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) {
- //printf("setMouseCursor(%i, %i)\n", hotspotX, hotspotY);
-
- if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) {
- free(_mouseBuf);
- _mouseBuf = NULL;
- }
-
- if (_mouseBuf == NULL)
- _mouseBuf = (byte *)malloc(w * h);
-
- _mouseWidth = w;
- _mouseHeight = h;
-
- _mouseHotspotX = hotspotX;
- _mouseHotspotY = hotspotY;
-
- _mouseKeyColour = keycolor;
-
- memcpy(_mouseBuf, buf, w * h);
-
- _mouseDirty = true;
-}
-
-bool OSystem_IPHONE::pollEvent(Common::Event &event) {
- //printf("pollEvent()\n");
-
- long curTime = getMillis();
-
- if (_timerCallback && (curTime >= _timerCallbackNext)) {
- _timerCallback(_timerCallbackTimer);
- _timerCallbackNext = curTime + _timerCallbackTimer;
- }
-
- if (_needEventRestPeriod) {
- // Workaround: Some engines can't handle mouse-down and mouse-up events
- // appearing right after each other, without a call returning no input in between.
- _needEventRestPeriod = false;
- return false;
- }
-
- if (_queuedInputEvent.type != (Common::EventType)0) {
- event = _queuedInputEvent;
- _queuedInputEvent.type = (Common::EventType)0;
- return true;
- }
-
- int eventType;
- float xUnit, yUnit;
-
- if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) {
- int x = 0;
- int y = 0;
- switch (_screenOrientation) {
- case kScreenOrientationPortrait:
- x = (int)(xUnit * _screenWidth);
- y = (int)(yUnit * _screenHeight);
- break;
- case kScreenOrientationLandscape:
- x = (int)(yUnit * _screenWidth);
- y = (int)((1.0 - xUnit) * _screenHeight);
- break;
- case kScreenOrientationFlippedLandscape:
- x = (int)((1.0 - yUnit) * _screenWidth);
- y = (int)(xUnit * _screenHeight);
- break;
- }
-
- switch ((InputEvent)eventType) {
- case kInputMouseDown:
- if (!handleEvent_mouseDown(event, x, y))
- return false;
- break;
-
- case kInputMouseUp:
- if (!handleEvent_mouseUp(event, x, y))
- return false;
- break;
-
- case kInputMouseDragged:
- if (!handleEvent_mouseDragged(event, x, y))
- return false;
- break;
- case kInputMouseSecondDragged:
- if (!handleEvent_mouseSecondDragged(event, x, y))
- return false;
- break;
- case kInputMouseSecondDown:
- _secondaryTapped = true;
- if (!handleEvent_secondMouseDown(event, x, y))
- return false;
- break;
- case kInputMouseSecondUp:
- _secondaryTapped = false;
- if (!handleEvent_secondMouseUp(event, x, y))
- return false;
- break;
- case kInputOrientationChanged:
- handleEvent_orientationChanged((int)xUnit);
- return false;
- break;
-
- case kInputApplicationSuspended:
- suspendLoop();
- return false;
- break;
-
- case kInputKeyPressed:
- handleEvent_keyPressed(event, (int)xUnit);
- break;
-
- case kInputSwipe:
- if (!handleEvent_swipe(event, (int)xUnit))
- return false;
- break;
-
- default:
- break;
- }
-
- return true;
- }
- return false;
-}
-
-bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) {
- //printf("Mouse down at (%u, %u)\n", x, y);
-
- // Workaround: kInputMouseSecondToggled isn't always sent when the
- // secondary finger is lifted. Need to make sure we get out of that mode.
- _secondaryTapped = false;
-
- if (_touchpadModeEnabled) {
- _lastPadX = x;
- _lastPadY = y;
- } else
- warpMouse(x, y);
-
- if (_mouseClickAndDragEnabled) {
- event.type = Common::EVENT_LBUTTONDOWN;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
- return true;
- } else {
- _lastMouseDown = getMillis();
- }
- return false;
-}
-
-bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) {
- //printf("Mouse up at (%u, %u)\n", x, y);
-
- if (_secondaryTapped) {
- _secondaryTapped = false;
- if (!handleEvent_secondMouseUp(event, x, y))
- return false;
- }
- else if (_mouseClickAndDragEnabled) {
- event.type = Common::EVENT_LBUTTONUP;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
- } else {
- if (getMillis() - _lastMouseDown < 250) {
- event.type = Common::EVENT_LBUTTONDOWN;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
-
- _queuedInputEvent.type = Common::EVENT_LBUTTONUP;
- _queuedInputEvent.mouse.x = _mouseX;
- _queuedInputEvent.mouse.y = _mouseY;
- _lastMouseTap = getMillis();
- _needEventRestPeriod = true;
- } else
- return false;
- }
-
- return true;
-}
-
-bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, int y) {
- _lastSecondaryDown = getMillis();
- _gestureStartX = x;
- _gestureStartY = y;
-
- if (_mouseClickAndDragEnabled) {
- event.type = Common::EVENT_LBUTTONUP;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
-
- _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN;
- _queuedInputEvent.mouse.x = _mouseX;
- _queuedInputEvent.mouse.y = _mouseY;
- }
- else
- return false;
-
- return true;
-}
-
-bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int y) {
- int curTime = getMillis();
-
- if (curTime - _lastSecondaryDown < 400 ) {
- //printf("Right tap!\n");
- if (curTime - _lastSecondaryTap < 400 && !_overlayVisible) {
- //printf("Right escape!\n");
- event.type = Common::EVENT_KEYDOWN;
- _queuedInputEvent.type = Common::EVENT_KEYUP;
-
- event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
- event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
- event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE;
- _needEventRestPeriod = true;
- _lastSecondaryTap = 0;
- } else if (!_mouseClickAndDragEnabled) {
- //printf("Rightclick!\n");
- event.type = Common::EVENT_RBUTTONDOWN;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
- _queuedInputEvent.type = Common::EVENT_RBUTTONUP;
- _queuedInputEvent.mouse.x = _mouseX;
- _queuedInputEvent.mouse.y = _mouseY;
- _lastSecondaryTap = curTime;
- _needEventRestPeriod = true;
- } else {
- //printf("Right nothing!\n");
- return false;
- }
- }
- if (_mouseClickAndDragEnabled) {
- event.type = Common::EVENT_RBUTTONUP;
- event.mouse.x = _mouseX;
- event.mouse.y = _mouseY;
- }
-
- return true;
-}
-
-bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y) {
- if (_lastDragPosX == x && _lastDragPosY == y)
- return false;
-
- _lastDragPosX = x;
- _lastDragPosY = y;
-
- //printf("Mouse dragged at (%u, %u)\n", x, y);
- int mouseNewPosX;
- int mouseNewPosY;
- if (_touchpadModeEnabled ) {
- int deltaX = _lastPadX - x;
- int deltaY = _lastPadY - y;
- _lastPadX = x;
- _lastPadY = y;
-
- mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
- mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
-
- if (mouseNewPosX < 0)
- mouseNewPosX = 0;
- else if (mouseNewPosX > _screenWidth)
- mouseNewPosX = _screenWidth;
-
- if (mouseNewPosY < 0)
- mouseNewPosY = 0;
- else if (mouseNewPosY > _screenHeight)
- mouseNewPosY = _screenHeight;
-
- } else {
- mouseNewPosX = x;
- mouseNewPosY = y;
- }
-
- event.type = Common::EVENT_MOUSEMOVE;
- event.mouse.x = mouseNewPosX;
- event.mouse.y = mouseNewPosY;
- warpMouse(mouseNewPosX, mouseNewPosY);
-
- return true;
-}
-
-bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x, int y) {
- if (_gestureStartX == -1 || _gestureStartY == -1) {
- return false;
- }
-
- static const int kNeededLength = 100;
- static const int kMaxDeviation = 20;
-
- int vecX = (x - _gestureStartX);
- int vecY = (y - _gestureStartY);
-
- int absX = abs(vecX);
- int absY = abs(vecY);
-
- //printf("(%d, %d)\n", vecX, vecY);
-
- if (absX >= kNeededLength || absY >= kNeededLength) { // Long enough gesture to react upon.
- _gestureStartX = -1;
- _gestureStartY = -1;
-
- if (absX < kMaxDeviation && vecY >= kNeededLength) {
- // Swipe down
- event.type = Common::EVENT_KEYDOWN;
- _queuedInputEvent.type = Common::EVENT_KEYUP;
-
- event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
- event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
- _needEventRestPeriod = true;
- return true;
- }
-
- if (absX < kMaxDeviation && -vecY >= kNeededLength) {
- // Swipe up
- _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
- const char *dialogMsg;
- if (_mouseClickAndDragEnabled) {
- _touchpadModeEnabled = false;
- dialogMsg = "Mouse-click-and-drag mode enabled.";
- } else
- dialogMsg = "Mouse-click-and-drag mode disabled.";
- GUI::TimedMessageDialog dialog(dialogMsg, 1500);
- dialog.runModal();
- return false;
- }
-
- if (absY < kMaxDeviation && vecX >= kNeededLength) {
- // Swipe right
- _touchpadModeEnabled = !_touchpadModeEnabled;
- const char *dialogMsg;
- if (_touchpadModeEnabled)
- dialogMsg = "Touchpad mode enabled.";
- else
- dialogMsg = "Touchpad mode disabled.";
- GUI::TimedMessageDialog dialog(dialogMsg, 1500);
- dialog.runModal();
- return false;
-
- }
-
- if (absY < kMaxDeviation && -vecX >= kNeededLength) {
- // Swipe left
- return false;
- }
- }
-
- return false;
-}
-
-void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) {
- //printf("Orientation: %i\n", orientation);
-
- ScreenOrientation newOrientation;
- switch (orientation) {
- case 1:
- newOrientation = kScreenOrientationPortrait;
- break;
- case 3:
- newOrientation = kScreenOrientationLandscape;
- break;
- case 4:
- newOrientation = kScreenOrientationFlippedLandscape;
- break;
- default:
- return;
- }
-
-
- if (_screenOrientation != newOrientation) {
- _screenOrientation = newOrientation;
- iPhone_initSurface(_screenWidth, _screenHeight);
-
- dirtyFullScreen();
- if (_overlayVisible)
- dirtyFullOverlayScreen();
- updateScreen();
- }
-}
-
-void OSystem_IPHONE::handleEvent_keyPressed(Common::Event &event, int keyPressed) {
- int ascii = keyPressed;
- //printf("key: %i\n", keyPressed);
-
- // We remap some of the iPhone keyboard keys.
- // The first ten here are the row of symbols below the numeric keys.
- switch (keyPressed) {
- case 45:
- keyPressed = Common::KEYCODE_F1;
- ascii = Common::ASCII_F1;
- break;
- case 47:
- keyPressed = Common::KEYCODE_F2;
- ascii = Common::ASCII_F2;
- break;
- case 58:
- keyPressed = Common::KEYCODE_F3;
- ascii = Common::ASCII_F3;
- break;
- case 59:
- keyPressed = Common::KEYCODE_F4;
- ascii = Common::ASCII_F4;
- break;
- case 40:
- keyPressed = Common::KEYCODE_F5;
- ascii = Common::ASCII_F5;
- break;
- case 41:
- keyPressed = Common::KEYCODE_F6;
- ascii = Common::ASCII_F6;
- break;
- case 36:
- keyPressed = Common::KEYCODE_F7;
- ascii = Common::ASCII_F7;
- break;
- case 38:
- keyPressed = Common::KEYCODE_F8;
- ascii = Common::ASCII_F8;
- break;
- case 64:
- keyPressed = Common::KEYCODE_F9;
- ascii = Common::ASCII_F9;
- break;
- case 34:
- keyPressed = Common::KEYCODE_F10;
- ascii = Common::ASCII_F10;
- break;
- case 10:
- keyPressed = Common::KEYCODE_RETURN;
- ascii = Common::ASCII_RETURN;
- break;
- }
- event.type = Common::EVENT_KEYDOWN;
- _queuedInputEvent.type = Common::EVENT_KEYUP;
-
- event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
- event.kbd.keycode = _queuedInputEvent.kbd.keycode = (Common::KeyCode)keyPressed;
- event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii;
- _needEventRestPeriod = true;
-}
-
-bool OSystem_IPHONE::handleEvent_swipe(Common::Event &event, int direction) {
- Common::KeyCode keycode = Common::KEYCODE_INVALID;
- switch (_screenOrientation) {
- case kScreenOrientationPortrait:
- switch ((UIViewSwipeDirection)direction) {
- case kUIViewSwipeUp:
- keycode = Common::KEYCODE_UP;
- break;
- case kUIViewSwipeDown:
- keycode = Common::KEYCODE_DOWN;
- break;
- case kUIViewSwipeLeft:
- keycode = Common::KEYCODE_LEFT;
- break;
- case kUIViewSwipeRight:
- keycode = Common::KEYCODE_RIGHT;
- break;
- default:
- return false;
- }
- break;
- case kScreenOrientationLandscape:
- switch ((UIViewSwipeDirection)direction) {
- case kUIViewSwipeUp:
- keycode = Common::KEYCODE_LEFT;
- break;
- case kUIViewSwipeDown:
- keycode = Common::KEYCODE_RIGHT;
- break;
- case kUIViewSwipeLeft:
- keycode = Common::KEYCODE_DOWN;
- break;
- case kUIViewSwipeRight:
- keycode = Common::KEYCODE_UP;
- break;
- default:
- return false;
- }
- break;
- case kScreenOrientationFlippedLandscape:
- switch ((UIViewSwipeDirection)direction) {
- case kUIViewSwipeUp:
- keycode = Common::KEYCODE_RIGHT;
- break;
- case kUIViewSwipeDown:
- keycode = Common::KEYCODE_LEFT;
- break;
- case kUIViewSwipeLeft:
- keycode = Common::KEYCODE_UP;
- break;
- case kUIViewSwipeRight:
- keycode = Common::KEYCODE_DOWN;
- break;
- default:
- return false;
- }
- break;
- }
-
- event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode;
- event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0;
- event.type = Common::EVENT_KEYDOWN;
- _queuedInputEvent.type = Common::EVENT_KEYUP;
- event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
- _needEventRestPeriod = true;
-
- return true;
-}
-
-void OSystem_IPHONE::suspendLoop() {
- bool done = false;
- int eventType;
- float xUnit, yUnit;
- uint32 startTime = getMillis();
-
- stopSoundsystem();
-
- while (!done) {
- if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit))
- if ((InputEvent)eventType == kInputApplicationResumed)
- done = true;
- usleep(100000);
- }
-
- startSoundsystem();
-
- _timeSuspended += getMillis() - startTime;
-}
-
-uint32 OSystem_IPHONE::getMillis() {
- //printf("getMillis()\n");
-
- struct timeval currentTime;
- gettimeofday(&currentTime, NULL);
- return (uint32)(((currentTime.tv_sec - _startTime.tv_sec) * 1000) +
- ((currentTime.tv_usec - _startTime.tv_usec) / 1000)) - _timeSuspended;
-}
-
-void OSystem_IPHONE::delayMillis(uint msecs) {
- //printf("delayMillis(%d)\n", msecs);
- usleep(msecs * 1000);
-}
-
-OSystem::MutexRef OSystem_IPHONE::createMutex(void) {
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-
- pthread_mutex_t *mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
- if (pthread_mutex_init(mutex, &attr) != 0) {
- printf("pthread_mutex_init() failed!\n");
- free(mutex);
- return NULL;
- }
-
- return (MutexRef)mutex;
-}
-
-void OSystem_IPHONE::lockMutex(MutexRef mutex) {
- if (pthread_mutex_lock((pthread_mutex_t *) mutex) != 0) {
- printf("pthread_mutex_lock() failed!\n");
- }
-}
-
-void OSystem_IPHONE::unlockMutex(MutexRef mutex) {
- if (pthread_mutex_unlock((pthread_mutex_t *) mutex) != 0) {
- printf("pthread_mutex_unlock() failed!\n");
- }
-}
-
-void OSystem_IPHONE::deleteMutex(MutexRef mutex) {
- if (pthread_mutex_destroy((pthread_mutex_t *) mutex) != 0) {
- printf("pthread_mutex_destroy() failed!\n");
- } else {
- free(mutex);
- }
-}
-
-void OSystem_IPHONE::AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB) {
- //printf("AQBufferCallback()\n");
- if (s_AudioQueue.frameCount > 0 && s_soundCallback != NULL) {
- outQB->mAudioDataByteSize = 4 * s_AudioQueue.frameCount;
- s_soundCallback(s_soundParam, (byte *)outQB->mAudioData, outQB->mAudioDataByteSize);
- AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
- } 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) {
- this_->_mixer->mixCallback(samples, len);
- }
-}
-
-void OSystem_IPHONE::setupMixer() {
- //printf("setSoundCallback()\n");
- _mixer = new Audio::MixerImpl(this);
-
- s_soundCallback = mixCallback;
- s_soundParam = this;
-
- startSoundsystem();
-}
-
-void OSystem_IPHONE::startSoundsystem() {
- s_AudioQueue.dataFormat.mSampleRate = AUDIO_SAMPLE_RATE;
- s_AudioQueue.dataFormat.mFormatID = kAudioFormatLinearPCM;
- s_AudioQueue.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
- s_AudioQueue.dataFormat.mBytesPerPacket = 4;
- s_AudioQueue.dataFormat.mFramesPerPacket = 1;
- s_AudioQueue.dataFormat.mBytesPerFrame = 4;
- s_AudioQueue.dataFormat.mChannelsPerFrame = 2;
- s_AudioQueue.dataFormat.mBitsPerChannel = 16;
- s_AudioQueue.frameCount = WAVE_BUFFER_SIZE;
-
- if (AudioQueueNewOutput(&s_AudioQueue.dataFormat, AQBufferCallback, &s_AudioQueue, 0, kCFRunLoopCommonModes, 0, &s_AudioQueue.queue)) {
- printf("Couldn't set the AudioQueue callback!\n");
- _mixer->setReady(false);
- return;
- }
-
- uint32 bufferBytes = s_AudioQueue.frameCount * s_AudioQueue.dataFormat.mBytesPerFrame;
-
- for (int i = 0; i < AUDIO_BUFFERS; i++) {
- if (AudioQueueAllocateBuffer(s_AudioQueue.queue, bufferBytes, &s_AudioQueue.buffers[i])) {
- printf("Error allocating AudioQueue buffer!\n");
- _mixer->setReady(false);
- return;
- }
-
- AQBufferCallback(&s_AudioQueue, s_AudioQueue.queue, s_AudioQueue.buffers[i]);
- }
-
- AudioQueueSetParameter(s_AudioQueue.queue, kAudioQueueParam_Volume, 1.0);
- if (AudioQueueStart(s_AudioQueue.queue, NULL)) {
- printf("Error starting the AudioQueue!\n");
- _mixer->setReady(false);
- return;
- }
-
- _mixer->setOutputRate(AUDIO_SAMPLE_RATE);
- _mixer->setReady(true);
-}
-
-void OSystem_IPHONE::stopSoundsystem() {
- AudioQueueStop(s_AudioQueue.queue, true);
-
- for (int i = 0; i < AUDIO_BUFFERS; i++) {
- AudioQueueFreeBuffer(s_AudioQueue.queue, s_AudioQueue.buffers[i]);
- }
-
- AudioQueueDispose(s_AudioQueue.queue, true);
- _mixer->setReady(false);
-}
-
-int OSystem_IPHONE::getOutputSampleRate() const {
- return AUDIO_SAMPLE_RATE;
-}
-
-void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) {
- //printf("setTimerCallback()\n");
-
- if (callback != NULL) {
- _timerCallbackTimer = interval;
- _timerCallbackNext = getMillis() + interval;
- _timerCallback = callback;
- } else
- _timerCallback = NULL;
-}
-
-void OSystem_IPHONE::quit() {
-}
-
-void OSystem_IPHONE::getTimeAndDate(struct tm &t) const {
- time_t curTime = time(0);
- t = *localtime(&curTime);
-}
-
-Common::SaveFileManager *OSystem_IPHONE::getSavefileManager() {
- assert(_savefile);
- return _savefile;
-}
-
-Audio::Mixer *OSystem_IPHONE::getMixer() {
- assert(_mixer);
- return _mixer;
-}
-
-Common::TimerManager *OSystem_IPHONE::getTimerManager() {
- assert(_timer);
- return _timer;
-}
-
-OSystem *OSystem_IPHONE_create() {
- return new OSystem_IPHONE();
-}
-
-Common::SeekableReadStream *OSystem_IPHONE::createConfigReadStream() {
-#ifdef IPHONE_OFFICIAL
- char buf[256];
- strncpy(buf, iPhone_getDocumentsDir(), 256);
- strncat(buf, "/Preferences", 256 - strlen(buf) );
- Common::FSNode file(buf);
-#else
- Common::FSNode file(SCUMMVM_PREFS_PATH);
-#endif
- return file.createReadStream();
-}
-
-Common::WriteStream *OSystem_IPHONE::createConfigWriteStream() {
-#ifdef IPHONE_OFFICIAL
- char buf[256];
- strncpy(buf, iPhone_getDocumentsDir(), 256);
- strncat(buf, "/Preferences", 256 - strlen(buf) );
- Common::FSNode file(buf);
-#else
- Common::FSNode file(SCUMMVM_PREFS_PATH);
-#endif
- return file.createWriteStream();
-}
-
-void OSystem_IPHONE::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
- // Get URL of the Resource directory of the .app bundle
- CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
- if (fileUrl) {
- // Try to convert the URL to an absolute path
- UInt8 buf[MAXPATHLEN];
- if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
- // Success: Add it to the search path
- Common::String bundlePath((const char *)buf);
- s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority);
- }
- CFRelease(fileUrl);
- }
-}
-
-void iphone_main(int argc, char *argv[]) {
-
- //OSystem_IPHONE::migrateApp();
-
- FILE *newfp = fopen("/var/mobile/.scummvm.log", "a");
- if (newfp != NULL) {
- fclose(stdout);
- fclose(stderr);
- *stdout = *newfp;
- *stderr = *newfp;
- setbuf(stdout, NULL);
- setbuf(stderr, NULL);
-
- //extern int gDebugLevel;
- //gDebugLevel = 10;
- }
-
-#ifdef IPHONE_OFFICIAL
- chdir( iPhone_getDocumentsDir() );
-#else
- system("mkdir " SCUMMVM_ROOT_PATH);
- system("mkdir " SCUMMVM_SAVE_PATH);
-
- chdir("/var/mobile/");
-#endif
-
- g_system = OSystem_IPHONE_create();
- assert(g_system);
-
- // Invoke the actual ScummVM main entry point:
- scummvm_main(argc, argv);
- g_system->quit(); // TODO: Consider removing / replacing this!
-}
diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp
new file mode 100644
index 0000000000..eb2ecf8769
--- /dev/null
+++ b/backends/platform/iphone/osys_main.cpp
@@ -0,0 +1,296 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <unistd.h>
+#include <pthread.h>
+
+#include <sys/time.h>
+
+#include "common/scummsys.h"
+#include "common/util.h"
+#include "common/rect.h"
+#include "common/file.h"
+#include "common/fs.h"
+
+#include "base/main.h"
+
+#include "backends/saves/default/default-saves.h"
+#include "backends/timer/default/default-timer.h"
+#include "sound/mixer.h"
+#include "sound/mixer_intern.h"
+
+#include "osys_main.h"
+
+
+const OSystem::GraphicsMode OSystem_IPHONE::s_supportedGraphicsModes[] = {
+ {0, 0, 0}
+};
+
+AQCallbackStruct OSystem_IPHONE::s_AudioQueue;
+SoundProc OSystem_IPHONE::s_soundCallback = NULL;
+void *OSystem_IPHONE::s_soundParam = NULL;
+
+OSystem_IPHONE::OSystem_IPHONE() :
+ _savefile(NULL), _mixer(NULL), _timer(NULL), _offscreen(NULL),
+ _overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL),
+ _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0),
+ _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape),
+ _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(true),
+ _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false),
+ _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0)
+
+{
+ _queuedInputEvent.type = (Common::EventType)0;
+ _lastDrawnMouseRect = Common::Rect(0, 0, 0, 0);
+
+ _fsFactory = new POSIXFilesystemFactory();
+}
+
+OSystem_IPHONE::~OSystem_IPHONE() {
+ AudioQueueDispose(s_AudioQueue.queue, true);
+
+ delete _fsFactory;
+ delete _savefile;
+ delete _mixer;
+ delete _timer;
+ delete _offscreen;
+ delete _fullscreen;
+}
+
+int OSystem_IPHONE::timerHandler(int t) {
+ DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
+ tm->handler();
+ return t;
+}
+
+void OSystem_IPHONE::initBackend() {
+#ifdef IPHONE_OFFICIAL
+ _savefile = new DefaultSaveFileManager(iPhone_getDocumentsDir());
+#else
+ _savefile = new DefaultSaveFileManager(SCUMMVM_SAVE_PATH);
+#endif
+
+ _timer = new DefaultTimerManager();
+
+ gettimeofday(&_startTime, NULL);
+
+ setupMixer();
+
+ setTimerCallback(&OSystem_IPHONE::timerHandler, 10);
+
+ OSystem::initBackend();
+}
+
+bool OSystem_IPHONE::hasFeature(Feature f) {
+ return false;
+}
+
+void OSystem_IPHONE::setFeatureState(Feature f, bool enable) {
+}
+
+bool OSystem_IPHONE::getFeatureState(Feature f) {
+ return false;
+}
+
+void OSystem_IPHONE::suspendLoop() {
+ bool done = false;
+ int eventType;
+ float xUnit, yUnit;
+ uint32 startTime = getMillis();
+
+ stopSoundsystem();
+
+ while (!done) {
+ if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit))
+ if ((InputEvent)eventType == kInputApplicationResumed)
+ done = true;
+ usleep(100000);
+ }
+
+ startSoundsystem();
+
+ _timeSuspended += getMillis() - startTime;
+}
+
+uint32 OSystem_IPHONE::getMillis() {
+ //printf("getMillis()\n");
+
+ struct timeval currentTime;
+ gettimeofday(&currentTime, NULL);
+ return (uint32)(((currentTime.tv_sec - _startTime.tv_sec) * 1000) +
+ ((currentTime.tv_usec - _startTime.tv_usec) / 1000)) - _timeSuspended;
+}
+
+void OSystem_IPHONE::delayMillis(uint msecs) {
+ //printf("delayMillis(%d)\n", msecs);
+ usleep(msecs * 1000);
+}
+
+OSystem::MutexRef OSystem_IPHONE::createMutex(void) {
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+
+ pthread_mutex_t *mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
+ if (pthread_mutex_init(mutex, &attr) != 0) {
+ printf("pthread_mutex_init() failed!\n");
+ free(mutex);
+ return NULL;
+ }
+
+ return (MutexRef)mutex;
+}
+
+void OSystem_IPHONE::lockMutex(MutexRef mutex) {
+ if (pthread_mutex_lock((pthread_mutex_t *) mutex) != 0) {
+ printf("pthread_mutex_lock() failed!\n");
+ }
+}
+
+void OSystem_IPHONE::unlockMutex(MutexRef mutex) {
+ if (pthread_mutex_unlock((pthread_mutex_t *) mutex) != 0) {
+ printf("pthread_mutex_unlock() failed!\n");
+ }
+}
+
+void OSystem_IPHONE::deleteMutex(MutexRef mutex) {
+ if (pthread_mutex_destroy((pthread_mutex_t *) mutex) != 0) {
+ printf("pthread_mutex_destroy() failed!\n");
+ } else {
+ free(mutex);
+ }
+}
+
+
+void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) {
+ //printf("setTimerCallback()\n");
+
+ if (callback != NULL) {
+ _timerCallbackTimer = interval;
+ _timerCallbackNext = getMillis() + interval;
+ _timerCallback = callback;
+ } else
+ _timerCallback = NULL;
+}
+
+void OSystem_IPHONE::quit() {
+}
+
+void OSystem_IPHONE::getTimeAndDate(struct tm &t) const {
+ time_t curTime = time(0);
+ t = *localtime(&curTime);
+}
+
+Common::SaveFileManager *OSystem_IPHONE::getSavefileManager() {
+ assert(_savefile);
+ return _savefile;
+}
+
+Audio::Mixer *OSystem_IPHONE::getMixer() {
+ assert(_mixer);
+ return _mixer;
+}
+
+Common::TimerManager *OSystem_IPHONE::getTimerManager() {
+ assert(_timer);
+ return _timer;
+}
+
+OSystem *OSystem_IPHONE_create() {
+ return new OSystem_IPHONE();
+}
+
+Common::SeekableReadStream *OSystem_IPHONE::createConfigReadStream() {
+#ifdef IPHONE_OFFICIAL
+ char buf[256];
+ strncpy(buf, iPhone_getDocumentsDir(), 256);
+ strncat(buf, "/Preferences", 256 - strlen(buf) );
+ Common::FSNode file(buf);
+#else
+ Common::FSNode file(SCUMMVM_PREFS_PATH);
+#endif
+ return file.createReadStream();
+}
+
+Common::WriteStream *OSystem_IPHONE::createConfigWriteStream() {
+#ifdef IPHONE_OFFICIAL
+ char buf[256];
+ strncpy(buf, iPhone_getDocumentsDir(), 256);
+ strncat(buf, "/Preferences", 256 - strlen(buf) );
+ Common::FSNode file(buf);
+#else
+ Common::FSNode file(SCUMMVM_PREFS_PATH);
+#endif
+ return file.createWriteStream();
+}
+
+void OSystem_IPHONE::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
+ // Get URL of the Resource directory of the .app bundle
+ CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
+ if (fileUrl) {
+ // Try to convert the URL to an absolute path
+ UInt8 buf[MAXPATHLEN];
+ if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
+ // Success: Add it to the search path
+ Common::String bundlePath((const char *)buf);
+ s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority);
+ }
+ CFRelease(fileUrl);
+ }
+}
+
+void iphone_main(int argc, char *argv[]) {
+
+ //OSystem_IPHONE::migrateApp();
+
+ FILE *newfp = fopen("/var/mobile/.scummvm.log", "a");
+ if (newfp != NULL) {
+ fclose(stdout);
+ fclose(stderr);
+ *stdout = *newfp;
+ *stderr = *newfp;
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
+
+ //extern int gDebugLevel;
+ //gDebugLevel = 10;
+ }
+
+#ifdef IPHONE_OFFICIAL
+ chdir( iPhone_getDocumentsDir() );
+#else
+ system("mkdir " SCUMMVM_ROOT_PATH);
+ system("mkdir " SCUMMVM_SAVE_PATH);
+
+ chdir("/var/mobile/");
+#endif
+
+ g_system = OSystem_IPHONE_create();
+ assert(g_system);
+
+ // Invoke the actual ScummVM main entry point:
+ scummvm_main(argc, argv);
+ g_system->quit(); // TODO: Consider removing / replacing this!
+}
diff --git a/backends/platform/iphone/osys_iphone.h b/backends/platform/iphone/osys_main.h
index 705f89319a..705f89319a 100644
--- a/backends/platform/iphone/osys_iphone.h
+++ b/backends/platform/iphone/osys_main.h
diff --git a/backends/platform/iphone/osys_sound.cpp b/backends/platform/iphone/osys_sound.cpp
new file mode 100644
index 0000000000..60b8d04a9b
--- /dev/null
+++ b/backends/platform/iphone/osys_sound.cpp
@@ -0,0 +1,111 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "osys_main.h"
+
+void OSystem_IPHONE::AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB) {
+ //printf("AQBufferCallback()\n");
+ if (s_AudioQueue.frameCount > 0 && s_soundCallback != NULL) {
+ outQB->mAudioDataByteSize = 4 * s_AudioQueue.frameCount;
+ s_soundCallback(s_soundParam, (byte *)outQB->mAudioData, outQB->mAudioDataByteSize);
+ AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
+ } 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) {
+ this_->_mixer->mixCallback(samples, len);
+ }
+}
+
+void OSystem_IPHONE::setupMixer() {
+ //printf("setSoundCallback()\n");
+ _mixer = new Audio::MixerImpl(this);
+
+ s_soundCallback = mixCallback;
+ s_soundParam = this;
+
+ startSoundsystem();
+}
+
+void OSystem_IPHONE::startSoundsystem() {
+ s_AudioQueue.dataFormat.mSampleRate = AUDIO_SAMPLE_RATE;
+ s_AudioQueue.dataFormat.mFormatID = kAudioFormatLinearPCM;
+ s_AudioQueue.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+ s_AudioQueue.dataFormat.mBytesPerPacket = 4;
+ s_AudioQueue.dataFormat.mFramesPerPacket = 1;
+ s_AudioQueue.dataFormat.mBytesPerFrame = 4;
+ s_AudioQueue.dataFormat.mChannelsPerFrame = 2;
+ s_AudioQueue.dataFormat.mBitsPerChannel = 16;
+ s_AudioQueue.frameCount = WAVE_BUFFER_SIZE;
+
+ if (AudioQueueNewOutput(&s_AudioQueue.dataFormat, AQBufferCallback, &s_AudioQueue, 0, kCFRunLoopCommonModes, 0, &s_AudioQueue.queue)) {
+ printf("Couldn't set the AudioQueue callback!\n");
+ _mixer->setReady(false);
+ return;
+ }
+
+ uint32 bufferBytes = s_AudioQueue.frameCount * s_AudioQueue.dataFormat.mBytesPerFrame;
+
+ for (int i = 0; i < AUDIO_BUFFERS; i++) {
+ if (AudioQueueAllocateBuffer(s_AudioQueue.queue, bufferBytes, &s_AudioQueue.buffers[i])) {
+ printf("Error allocating AudioQueue buffer!\n");
+ _mixer->setReady(false);
+ return;
+ }
+
+ AQBufferCallback(&s_AudioQueue, s_AudioQueue.queue, s_AudioQueue.buffers[i]);
+ }
+
+ AudioQueueSetParameter(s_AudioQueue.queue, kAudioQueueParam_Volume, 1.0);
+ if (AudioQueueStart(s_AudioQueue.queue, NULL)) {
+ printf("Error starting the AudioQueue!\n");
+ _mixer->setReady(false);
+ return;
+ }
+
+ _mixer->setOutputRate(AUDIO_SAMPLE_RATE);
+ _mixer->setReady(true);
+}
+
+void OSystem_IPHONE::stopSoundsystem() {
+ AudioQueueStop(s_AudioQueue.queue, true);
+
+ for (int i = 0; i < AUDIO_BUFFERS; i++) {
+ AudioQueueFreeBuffer(s_AudioQueue.queue, s_AudioQueue.buffers[i]);
+ }
+
+ AudioQueueDispose(s_AudioQueue.queue, true);
+ _mixer->setReady(false);
+}
+
+int OSystem_IPHONE::getOutputSampleRate() const {
+ return AUDIO_SAMPLE_RATE;
+}
diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.cpp
new file mode 100644
index 0000000000..641c341f50
--- /dev/null
+++ b/backends/platform/iphone/osys_video.cpp
@@ -0,0 +1,463 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "osys_main.h"
+
+const OSystem::GraphicsMode* OSystem_IPHONE::getSupportedGraphicsModes() const {
+ return s_supportedGraphicsModes;
+}
+
+
+int OSystem_IPHONE::getDefaultGraphicsMode() const {
+ return -1;
+}
+
+bool OSystem_IPHONE::setGraphicsMode(const char *mode) {
+ return true;
+}
+
+bool OSystem_IPHONE::setGraphicsMode(int mode) {
+ return true;
+}
+
+int OSystem_IPHONE::getGraphicsMode() const {
+ return -1;
+}
+
+void OSystem_IPHONE::initSize(uint width, uint height) {
+ //printf("initSize(%i, %i)\n", width, height);
+
+ _screenWidth = width;
+ _screenHeight = height;
+
+ free(_offscreen);
+
+ _offscreen = (byte *)malloc(width * height);
+ bzero(_offscreen, width * height);
+
+ free(_overlayBuffer);
+
+ int fullSize = _screenWidth * _screenHeight * sizeof(OverlayColor);
+ _overlayBuffer = (OverlayColor *)malloc(fullSize);
+ clearOverlay();
+
+ free(_fullscreen);
+
+ _fullscreen = (uint16 *)malloc(fullSize);
+ bzero(_fullscreen, fullSize);
+
+ iPhone_initSurface(width, height);
+
+ _fullScreenIsDirty = false;
+ dirtyFullScreen();
+ _mouseVisible = false;
+ _screenChangeCount++;
+ updateScreen();
+}
+
+int16 OSystem_IPHONE::getHeight() {
+ return _screenHeight;
+}
+
+int16 OSystem_IPHONE::getWidth() {
+ return _screenWidth;
+}
+
+void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) {
+ //printf("setPalette()\n");
+ const byte *b = colors;
+
+ for (uint i = start; i < start + num; ++i) {
+ _palette[i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(b[0], b[1], b[2]);
+ b += 4;
+ }
+
+ dirtyFullScreen();
+}
+
+void OSystem_IPHONE::grabPalette(byte *colors, uint start, uint num) {
+ //printf("grabPalette()\n");
+}
+
+void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
+ //printf("copyRectToScreen(%i, %i, %i, %i)\n", x, y, w, h);
+ //Clip the coordinates
+ if (x < 0) {
+ w += x;
+ buf -= x;
+ x = 0;
+ }
+
+ if (y < 0) {
+ h += y;
+ buf -= y * pitch;
+ y = 0;
+ }
+
+ if (w > _screenWidth - x) {
+ w = _screenWidth - x;
+ }
+
+ if (h > _screenHeight - y) {
+ h = _screenHeight - y;
+ }
+
+ if (w <= 0 || h <= 0)
+ return;
+
+ if (!_fullScreenIsDirty) {
+ _dirtyRects.push_back(Common::Rect(x, y, x + w, y + h));
+ }
+
+
+ byte *dst = _offscreen + y * _screenWidth + x;
+ if (_screenWidth == pitch && pitch == w)
+ memcpy(dst, buf, h * w);
+ else {
+ do {
+ memcpy(dst, buf, w);
+ buf += pitch;
+ dst += _screenWidth;
+ } while (--h);
+ }
+}
+
+void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) {
+ if (x < 0) {
+ w += x;
+ x = 0;
+ }
+
+ if (y < 0) {
+ h += y;
+ y = 0;
+ }
+
+ if (w > _screenWidth - x)
+ w = _screenWidth - x;
+
+ if (h > _screenHeight - y)
+ h = _screenHeight - y;
+
+ if (w < 0) {
+ w = 0;
+ }
+
+ if (h < 0) {
+ h = 0;
+ }
+}
+
+void OSystem_IPHONE::updateScreen() {
+ //printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size());
+
+ if (_dirtyRects.size() == 0 && _dirtyOverlayRects.size() == 0 && !_mouseDirty)
+ return;
+
+ internUpdateScreen();
+ _fullScreenIsDirty = false;
+ _fullScreenOverlayIsDirty = false;
+
+ iPhone_updateScreen();
+}
+
+void OSystem_IPHONE::internUpdateScreen() {
+ int16 mouseX = _mouseX - _mouseHotspotX;
+ int16 mouseY = _mouseY - _mouseHotspotY;
+ int16 mouseWidth = _mouseWidth;
+ int16 mouseHeight = _mouseHeight;
+
+ clipRectToScreen(mouseX, mouseY, mouseWidth, mouseHeight);
+
+ Common::Rect mouseRect(mouseX, mouseY, mouseX + mouseWidth, mouseY + mouseHeight);
+
+ if (_mouseDirty) {
+ if (!_fullScreenIsDirty) {
+ _dirtyRects.push_back(_lastDrawnMouseRect);
+ _dirtyRects.push_back(mouseRect);
+ }
+ if (!_fullScreenOverlayIsDirty && _overlayVisible) {
+ _dirtyOverlayRects.push_back(_lastDrawnMouseRect);
+ _dirtyOverlayRects.push_back(mouseRect);
+ }
+ _mouseDirty = false;
+ _lastDrawnMouseRect = mouseRect;
+ }
+
+ while (_dirtyRects.size()) {
+ Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1);
+
+ //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
+
+ drawDirtyRect(dirtyRect);
+
+ if (_overlayVisible)
+ drawDirtyOverlayRect(dirtyRect);
+
+ drawMouseCursorOnRectUpdate(dirtyRect, mouseRect);
+ updateHardwareSurfaceForRect(dirtyRect);
+ }
+
+ if (_overlayVisible) {
+ while (_dirtyOverlayRects.size()) {
+ Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1);
+
+ //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
+
+ drawDirtyOverlayRect(dirtyRect);
+ drawMouseCursorOnRectUpdate(dirtyRect, mouseRect);
+ updateHardwareSurfaceForRect(dirtyRect);
+ }
+ }
+}
+
+void OSystem_IPHONE::drawDirtyRect(const Common::Rect& dirtyRect) {
+ int h = dirtyRect.bottom - dirtyRect.top;
+ int w = dirtyRect.right - dirtyRect.left;
+
+ byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
+ uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
+ for (int y = h; y > 0; y--) {
+ for (int x = w; x > 0; x--)
+ *dst++ = _palette[*src++];
+
+ dst += _screenWidth - w;
+ src += _screenWidth - w;
+ }
+}
+
+void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect& dirtyRect) {
+ int h = dirtyRect.bottom - dirtyRect.top;
+
+ uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left];
+ uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left];
+ int x = (dirtyRect.right - dirtyRect.left) * 2;
+ for (int y = h; y > 0; y--) {
+ memcpy(dst, src, x);
+ src += _screenWidth;
+ dst += _screenWidth;
+ }
+}
+
+void OSystem_IPHONE::drawMouseCursorOnRectUpdate(const Common::Rect& updatedRect, const Common::Rect& mouseRect) {
+ //draw mouse on top
+ if (_mouseVisible && (updatedRect.intersects(mouseRect))) {
+ int srcX = 0;
+ int srcY = 0;
+ int left = _mouseX - _mouseHotspotX;
+ if (left < 0) {
+ srcX -= left;
+ left = 0;
+ }
+ int top = _mouseY - _mouseHotspotY;
+ if (top < 0) {
+ srcY -= top;
+ top = 0;
+ }
+ //int right = left + _mouseWidth;
+ int bottom = top + _mouseHeight;
+ if (bottom > _screenWidth)
+ bottom = _screenWidth;
+ int displayWidth = _mouseWidth;
+ if (_mouseWidth + left > _screenWidth)
+ displayWidth = _screenWidth - left;
+ int displayHeight = _mouseHeight;
+ if (_mouseHeight + top > _screenHeight)
+ displayHeight = _screenHeight - top;
+ byte *src = &_mouseBuf[srcY * _mouseWidth + srcX];
+ uint16 *dst = &_fullscreen[top * _screenWidth + left];
+ for (int y = displayHeight; y > srcY; y--) {
+ for (int x = displayWidth; x > srcX; x--) {
+ if (*src != _mouseKeyColour)
+ *dst = _palette[*src];
+ dst++;
+ src++;
+ }
+ dst += _screenWidth - displayWidth + srcX;
+ src += _mouseWidth - displayWidth + srcX;
+ }
+ }
+}
+
+void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect& updatedRect) {
+ iPhone_updateScreenRect(_fullscreen, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom );
+}
+
+Graphics::Surface *OSystem_IPHONE::lockScreen() {
+ //printf("lockScreen()\n");
+
+ _framebuffer.pixels = _offscreen;
+ _framebuffer.w = _screenWidth;
+ _framebuffer.h = _screenHeight;
+ _framebuffer.pitch = _screenWidth;
+ _framebuffer.bytesPerPixel = 1;
+
+ return &_framebuffer;
+}
+
+void OSystem_IPHONE::unlockScreen() {
+ //printf("unlockScreen()\n");
+ dirtyFullScreen();
+}
+
+void OSystem_IPHONE::setShakePos(int shakeOffset) {
+ //printf("setShakePos(%i)\n", shakeOffset);
+}
+
+void OSystem_IPHONE::showOverlay() {
+ //printf("showOverlay()\n");
+ _overlayVisible = true;
+ dirtyFullOverlayScreen();
+}
+
+void OSystem_IPHONE::hideOverlay() {
+ //printf("hideOverlay()\n");
+ _overlayVisible = false;
+ _dirtyOverlayRects.clear();
+ dirtyFullScreen();
+}
+
+void OSystem_IPHONE::clearOverlay() {
+ //printf("clearOverlay()\n");
+ bzero(_overlayBuffer, _screenWidth * _screenHeight * sizeof(OverlayColor));
+ dirtyFullOverlayScreen();
+}
+
+void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) {
+ //printf("grabOverlay()\n");
+ int h = _screenHeight;
+ OverlayColor *src = _overlayBuffer;
+
+ do {
+ memcpy(buf, src, _screenWidth * sizeof(OverlayColor));
+ src += _screenWidth;
+ buf += pitch;
+ } while (--h);
+}
+
+void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
+ //printf("copyRectToOverlay(buf, pitch=%i, x=%i, y=%i, w=%i, h=%i)\n", pitch, x, y, w, h);
+
+ //Clip the coordinates
+ if (x < 0) {
+ w += x;
+ buf -= x;
+ x = 0;
+ }
+
+ if (y < 0) {
+ h += y;
+ buf -= y * pitch;
+ y = 0;
+ }
+
+ if (w > _screenWidth - x)
+ w = _screenWidth - x;
+
+ if (h > _screenHeight - y)
+ h = _screenHeight - y;
+
+ if (w <= 0 || h <= 0)
+ return;
+
+ if (!_fullScreenOverlayIsDirty) {
+ _dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h));
+ }
+
+ OverlayColor *dst = _overlayBuffer + (y * _screenWidth + x);
+ if (_screenWidth == pitch && pitch == w)
+ memcpy(dst, buf, h * w * sizeof(OverlayColor));
+ else {
+ do {
+ memcpy(dst, buf, w * sizeof(OverlayColor));
+ buf += pitch;
+ dst += _screenWidth;
+ } while (--h);
+ }
+}
+
+int16 OSystem_IPHONE::getOverlayHeight() {
+ return _screenHeight;
+}
+
+int16 OSystem_IPHONE::getOverlayWidth() {
+ return _screenWidth;
+}
+
+bool OSystem_IPHONE::showMouse(bool visible) {
+ bool last = _mouseVisible;
+ _mouseVisible = visible;
+ _mouseDirty = true;
+
+ return last;
+}
+
+void OSystem_IPHONE::warpMouse(int x, int y) {
+ //printf("warpMouse()\n");
+
+ _mouseX = x;
+ _mouseY = y;
+ _mouseDirty = true;
+}
+
+void OSystem_IPHONE::dirtyFullScreen() {
+ if (!_fullScreenIsDirty) {
+ _dirtyRects.clear();
+ _dirtyRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight));
+ _fullScreenIsDirty = true;
+ }
+}
+
+void OSystem_IPHONE::dirtyFullOverlayScreen() {
+ if (!_fullScreenOverlayIsDirty) {
+ _dirtyOverlayRects.clear();
+ _dirtyOverlayRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight));
+ _fullScreenOverlayIsDirty = true;
+ }
+}
+
+void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) {
+ //printf("setMouseCursor(%i, %i)\n", hotspotX, hotspotY);
+
+ if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) {
+ free(_mouseBuf);
+ _mouseBuf = NULL;
+ }
+
+ if (_mouseBuf == NULL)
+ _mouseBuf = (byte *)malloc(w * h);
+
+ _mouseWidth = w;
+ _mouseHeight = h;
+
+ _mouseHotspotX = hotspotX;
+ _mouseHotspotY = hotspotY;
+
+ _mouseKeyColour = keycolor;
+
+ memcpy(_mouseBuf, buf, w * h);
+
+ _mouseDirty = true;
+}