ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

events.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #if defined(__ANDROID__)
00024 
00025 // Allow use of stuff in <time.h>
00026 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
00027 
00028 // Disable printf override in common/forbidden.h to avoid
00029 // clashes with log.h from the Android SDK.
00030 // That header file uses
00031 //   __attribute__ ((format(printf, 3, 4)))
00032 // which gets messed up by our override mechanism; this could
00033 // be avoided by either changing the Android SDK to use the equally
00034 // legal and valid
00035 //   __attribute__ ((format(printf, 3, 4)))
00036 // or by refining our printf override to use a varadic macro
00037 // (which then wouldn't be portable, though).
00038 // Anyway, for now we just disable the printf override globally
00039 // for the Android port
00040 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
00041 
00042 #include "backends/platform/android/android.h"
00043 #include "backends/platform/android/events.h"
00044 #include "backends/platform/android/jni.h"
00045 
00046 #include "engines/engine.h"
00047 #include "gui/gui-manager.h"
00048 
00049 // floating point. use sparingly
00050 template<class T>
00051 static inline T scalef(T in, float numerator, float denominator) {
00052     return static_cast<float>(in) * numerator / denominator;
00053 }
00054 
00055 static const int kQueuedInputEventDelay = 50;
00056 
00057 void OSystem_Android::setupKeymapper() {
00058 #ifdef ENABLE_KEYMAPPER
00059     using namespace Common;
00060 
00061     Keymapper *mapper = getEventManager()->getKeymapper();
00062 
00063     HardwareInputSet *inputSet = new HardwareInputSet();
00064 
00065     keySet->addHardwareInput(
00066         new HardwareInput("n", KeyState(KEYCODE_n), "n (vk)"));
00067 
00068     mapper->registerHardwareInputSet(inputSet);
00069 
00070     Keymap *globalMap = new Keymap(kGlobalKeymapName);
00071     Action *act;
00072 
00073     act = new Action(globalMap, "VIRT", "Display keyboard");
00074     act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, KBD_CTRL));
00075 
00076     mapper->addGlobalKeymap(globalMap);
00077 
00078     mapper->pushKeymap(kGlobalKeymapName);
00079 #endif
00080 }
00081 
00082 void OSystem_Android::warpMouse(int x, int y) {
00083     ENTER("%d, %d", x, y);
00084 
00085     Common::Event e;
00086 
00087     e.type = Common::EVENT_MOUSEMOVE;
00088     e.mouse.x = x;
00089     e.mouse.y = y;
00090 
00091     clipMouse(e.mouse);
00092 
00093     pushEvent(e);
00094 }
00095 
00096 void OSystem_Android::clipMouse(Common::Point &p) {
00097     const GLESBaseTexture *tex;
00098 
00099     if (_show_overlay)
00100         tex = _overlay_texture;
00101     else
00102         tex = _game_texture;
00103 
00104     p.x = CLIP(p.x, int16(0), int16(tex->width() - 1));
00105     p.y = CLIP(p.y, int16(0), int16(tex->height() - 1));
00106 }
00107 
00108 void OSystem_Android::scaleMouse(Common::Point &p, int x, int y,
00109                                     bool deductDrawRect, bool touchpadMode) {
00110     const GLESBaseTexture *tex;
00111 
00112     if (_show_overlay)
00113         tex = _overlay_texture;
00114     else
00115         tex = _game_texture;
00116 
00117     const Common::Rect &r = tex->getDrawRect();
00118 
00119     if (touchpadMode) {
00120         x = x * 100 / _touchpad_scale;
00121         y = y * 100 / _touchpad_scale;
00122     }
00123 
00124     if (deductDrawRect) {
00125         x -= r.left;
00126         y -= r.top;
00127     }
00128 
00129     p.x = scalef(x, tex->width(), r.width());
00130     p.y = scalef(y, tex->height(), r.height());
00131 }
00132 
00133 void OSystem_Android::updateEventScale() {
00134     const GLESBaseTexture *tex;
00135 
00136     if (_show_overlay)
00137         tex = _overlay_texture;
00138     else
00139         tex = _game_texture;
00140 
00141     _eventScaleY = 100 * 480 / tex->height();
00142     _eventScaleX = 100 * 640 / tex->width();
00143 }
00144 
00145 void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
00146                                 int arg4, int arg5, int arg6) {
00147     Common::Event e;
00148 
00149     switch (type) {
00150     case JE_SYS_KEY:
00151         switch (arg1) {
00152         case JACTION_DOWN:
00153             e.type = Common::EVENT_KEYDOWN;
00154             break;
00155         case JACTION_UP:
00156             e.type = Common::EVENT_KEYUP;
00157             break;
00158         default:
00159             LOGE("unhandled jaction on system key: %d", arg1);
00160             return;
00161         }
00162 
00163         switch (arg2) {
00164 
00165         // special case. we'll only get it's up event
00166         case JKEYCODE_BACK:
00167             e.kbd.keycode = Common::KEYCODE_ESCAPE;
00168             e.kbd.ascii = Common::ASCII_ESCAPE;
00169 
00170             lockMutex(_event_queue_lock);
00171             e.type = Common::EVENT_KEYDOWN;
00172             _event_queue.push(e);
00173             e.type = Common::EVENT_KEYUP;
00174             _event_queue.push(e);
00175             unlockMutex(_event_queue_lock);
00176 
00177             return;
00178 
00179         // special case. we'll only get it's up event
00180         case JKEYCODE_MENU:
00181             e.type = Common::EVENT_MAINMENU;
00182 
00183             pushEvent(e);
00184 
00185             return;
00186 
00187         case JKEYCODE_MEDIA_PAUSE:
00188         case JKEYCODE_MEDIA_PLAY:
00189         case JKEYCODE_MEDIA_PLAY_PAUSE:
00190             if (arg1 == JACTION_DOWN) {
00191                 e.type = Common::EVENT_MAINMENU;
00192 
00193                 pushEvent(e);
00194             }
00195 
00196             return;
00197 
00198         case JKEYCODE_CAMERA:
00199         case JKEYCODE_SEARCH:
00200             if (arg1 == JACTION_DOWN)
00201                 e.type = Common::EVENT_RBUTTONDOWN;
00202             else
00203                 e.type = Common::EVENT_RBUTTONUP;
00204 
00205             e.mouse = getEventManager()->getMousePos();
00206 
00207             pushEvent(e);
00208 
00209             return;
00210 
00211         default:
00212             LOGW("unmapped system key: %d", arg2);
00213             return;
00214         }
00215 
00216         break;
00217 
00218     case JE_KEY:
00219         switch (arg1) {
00220         case JACTION_DOWN:
00221             e.type = Common::EVENT_KEYDOWN;
00222             break;
00223         case JACTION_UP:
00224             e.type = Common::EVENT_KEYUP;
00225             break;
00226         default:
00227             LOGE("unhandled jaction on key: %d", arg1);
00228             return;
00229         }
00230 
00231         if (arg2 < 1 || arg2 > ARRAYSIZE(jkeymap)) {
00232             if (arg3 < 1) {
00233                 LOGE("received invalid keycode: %d (%d)", arg2, arg3);
00234                 return;
00235             } else {
00236                 // lets bet on the ascii code
00237                 e.kbd.keycode = Common::KEYCODE_INVALID;
00238             }
00239         } else {
00240             e.kbd.keycode = jkeymap[arg2];
00241         }
00242 
00243         if (arg5 > 0)
00244             e.kbdRepeat = true;
00245 
00246         // map special keys to 'our' ascii codes
00247         switch (e.kbd.keycode) {
00248         case Common::KEYCODE_BACKSPACE:
00249             e.kbd.ascii = Common::ASCII_BACKSPACE;
00250             break;
00251         case Common::KEYCODE_TAB:
00252             e.kbd.ascii = Common::ASCII_TAB;
00253             break;
00254         case Common::KEYCODE_RETURN:
00255             e.kbd.ascii = Common::ASCII_RETURN;
00256             break;
00257         case Common::KEYCODE_ESCAPE:
00258             e.kbd.ascii = Common::ASCII_ESCAPE;
00259             break;
00260         case Common::KEYCODE_SPACE:
00261             e.kbd.ascii = Common::ASCII_SPACE;
00262             break;
00263         case Common::KEYCODE_F1:
00264             e.kbd.ascii = Common::ASCII_F1;
00265             break;
00266         case Common::KEYCODE_F2:
00267             e.kbd.ascii = Common::ASCII_F2;
00268             break;
00269         case Common::KEYCODE_F3:
00270             e.kbd.ascii = Common::ASCII_F3;
00271             break;
00272         case Common::KEYCODE_F4:
00273             e.kbd.ascii = Common::ASCII_F4;
00274             break;
00275         case Common::KEYCODE_F5:
00276             e.kbd.ascii = Common::ASCII_F5;
00277             break;
00278         case Common::KEYCODE_F6:
00279             e.kbd.ascii = Common::ASCII_F6;
00280             break;
00281         case Common::KEYCODE_F7:
00282             e.kbd.ascii = Common::ASCII_F7;
00283             break;
00284         case Common::KEYCODE_F8:
00285             e.kbd.ascii = Common::ASCII_F8;
00286             break;
00287         case Common::KEYCODE_F9:
00288             e.kbd.ascii = Common::ASCII_F9;
00289             break;
00290         case Common::KEYCODE_F10:
00291             e.kbd.ascii = Common::ASCII_F10;
00292             break;
00293         case Common::KEYCODE_F11:
00294             e.kbd.ascii = Common::ASCII_F11;
00295             break;
00296         case Common::KEYCODE_F12:
00297             e.kbd.ascii = Common::ASCII_F12;
00298             break;
00299         default:
00300             e.kbd.ascii = arg3;
00301             break;
00302         }
00303 
00304         if (arg4 & JMETA_SHIFT)
00305             e.kbd.flags |= Common::KBD_SHIFT;
00306         // JMETA_ALT is Fn on physical keyboards!
00307         // when mapping this to ALT - as we know it from PC keyboards - all
00308         // Fn combos will be broken (like Fn+q, which needs to end as 1 and
00309         // not ALT+1). Do not want.
00310         //if (arg4 & JMETA_ALT)
00311         //  e.kbd.flags |= Common::KBD_ALT;
00312         if (arg4 & (JMETA_SYM | JMETA_CTRL))
00313             e.kbd.flags |= Common::KBD_CTRL;
00314 
00315         pushEvent(e);
00316 
00317         return;
00318 
00319     case JE_DPAD:
00320         switch (arg2) {
00321         case JKEYCODE_DPAD_UP:
00322         case JKEYCODE_DPAD_DOWN:
00323         case JKEYCODE_DPAD_LEFT:
00324         case JKEYCODE_DPAD_RIGHT:
00325             if (!shouldGenerateMouseEvents()) {
00326                 switch (arg1) {
00327                 case JACTION_DOWN:
00328                     e.type = Common::EVENT_KEYDOWN;
00329                     break;
00330                 case JACTION_UP:
00331                     e.type = Common::EVENT_KEYUP;
00332                     break;
00333                 default:
00334                     LOGE("unhandled jaction on dpad key: %d", arg1);
00335                     return;
00336                 }
00337 
00338                 switch (arg2) {
00339                 case JKEYCODE_DPAD_UP:
00340                     e.kbd.keycode = Common::KEYCODE_UP;
00341                     break;
00342                 case JKEYCODE_DPAD_DOWN:
00343                     e.kbd.keycode = Common::KEYCODE_DOWN;
00344                     break;
00345                 case JKEYCODE_DPAD_LEFT:
00346                     e.kbd.keycode = Common::KEYCODE_LEFT;
00347                     break;
00348                 case JKEYCODE_DPAD_RIGHT:
00349                     e.kbd.keycode = Common::KEYCODE_RIGHT;
00350                     break;
00351                 }
00352 
00353                 pushEvent(e);
00354                 return;
00355             }
00356 
00357             if (arg1 != JACTION_DOWN)
00358                 return;
00359 
00360             e.type = Common::EVENT_MOUSEMOVE;
00361 
00362             e.mouse = getEventManager()->getMousePos();
00363 
00364             {
00365                 int16 *c;
00366                 int s;
00367 
00368                 if (arg2 == JKEYCODE_DPAD_UP || arg2 == JKEYCODE_DPAD_DOWN) {
00369                     c = &e.mouse.y;
00370                     s = _eventScaleY;
00371                 } else {
00372                     c = &e.mouse.x;
00373                     s = _eventScaleX;
00374                 }
00375 
00376                 // the longer the button held, the faster the pointer is
00377                 // TODO put these values in some option dlg?
00378                 int f = CLIP(arg4, 1, 8) * _dpad_scale * 100 / s;
00379 
00380                 if (arg2 == JKEYCODE_DPAD_UP || arg2 == JKEYCODE_DPAD_LEFT)
00381                     *c -= f;
00382                 else
00383                     *c += f;
00384             }
00385 
00386             clipMouse(e.mouse);
00387 
00388             pushEvent(e);
00389 
00390             return;
00391 
00392         case JKEYCODE_DPAD_CENTER:
00393             switch (arg1) {
00394             case JACTION_DOWN:
00395                 e.type = Common::EVENT_LBUTTONDOWN;
00396                 break;
00397             case JACTION_UP:
00398                 e.type = Common::EVENT_LBUTTONUP;
00399                 break;
00400             default:
00401                 LOGE("unhandled jaction on dpad key: %d", arg1);
00402                 return;
00403             }
00404 
00405             e.mouse = getEventManager()->getMousePos();
00406 
00407             pushEvent(e);
00408 
00409             return;
00410         }
00411 
00412     case JE_DOWN:
00413         _touch_pt_down = getEventManager()->getMousePos();
00414         _touch_pt_scroll.x = -1;
00415         _touch_pt_scroll.y = -1;
00416         break;
00417 
00418     case JE_SCROLL:
00419         if (!shouldGenerateMouseEvents())
00420             return;
00421 
00422         e.type = Common::EVENT_MOUSEMOVE;
00423 
00424         if (_touchpad_mode) {
00425             if (_touch_pt_scroll.x == -1 && _touch_pt_scroll.y == -1) {
00426                 _touch_pt_scroll.x = arg3;
00427                 _touch_pt_scroll.y = arg4;
00428                 return;
00429             }
00430 
00431             scaleMouse(e.mouse, arg3 - _touch_pt_scroll.x,
00432                         arg4 - _touch_pt_scroll.y, false, true);
00433             e.mouse += _touch_pt_down;
00434             clipMouse(e.mouse);
00435         } else {
00436             scaleMouse(e.mouse, arg3, arg4);
00437             clipMouse(e.mouse);
00438         }
00439 
00440         pushEvent(e);
00441 
00442         return;
00443 
00444     case JE_TAP:
00445         if (_fingersDown > 0) {
00446             _fingersDown = 0;
00447             return;
00448         }
00449 
00450         if (!shouldGenerateMouseEvents()) {
00451             keyPress(Common::KEYCODE_RETURN, KeyReceiver::PRESS);
00452             return;
00453         }
00454 
00455         e.type = Common::EVENT_MOUSEMOVE;
00456 
00457         if (_touchpad_mode) {
00458             e.mouse = getEventManager()->getMousePos();
00459         } else {
00460             scaleMouse(e.mouse, arg1, arg2);
00461             clipMouse(e.mouse);
00462         }
00463 
00464         {
00465             Common::EventType down, up;
00466 
00467             // TODO put these values in some option dlg?
00468             if (arg3 > 1000) {
00469                 down = Common::EVENT_MBUTTONDOWN;
00470                 up = Common::EVENT_MBUTTONUP;
00471             } else if (arg3 > 500) {
00472                 down = Common::EVENT_RBUTTONDOWN;
00473                 up = Common::EVENT_RBUTTONUP;
00474             } else {
00475                 down = Common::EVENT_LBUTTONDOWN;
00476                 up = Common::EVENT_LBUTTONUP;
00477             }
00478 
00479             lockMutex(_event_queue_lock);
00480 
00481             if (_queuedEventTime)
00482                 _event_queue.push(_queuedEvent);
00483 
00484             if (!_touchpad_mode)
00485                 _event_queue.push(e);
00486 
00487             e.type = down;
00488             _event_queue.push(e);
00489 
00490             e.type = up;
00491             _queuedEvent = e;
00492             _queuedEventTime = getMillis() + kQueuedInputEventDelay;
00493 
00494             unlockMutex(_event_queue_lock);
00495         }
00496 
00497         return;
00498 
00499     case JE_DOUBLE_TAP:
00500         if (!shouldGenerateMouseEvents()) {
00501             keyPress(Common::KEYCODE_u, KeyReceiver::PRESS);
00502         }
00503 
00504         e.type = Common::EVENT_MOUSEMOVE;
00505 
00506         if (_touchpad_mode) {
00507             e.mouse = getEventManager()->getMousePos();
00508         } else {
00509             scaleMouse(e.mouse, arg1, arg2);
00510             clipMouse(e.mouse);
00511         }
00512 
00513         {
00514             Common::EventType dptype = Common::EVENT_INVALID;
00515 
00516             switch (arg3) {
00517             case JACTION_DOWN:
00518                 dptype = Common::EVENT_LBUTTONDOWN;
00519                 _touch_pt_dt.x = -1;
00520                 _touch_pt_dt.y = -1;
00521                 break;
00522             case JACTION_UP:
00523                 dptype = Common::EVENT_LBUTTONUP;
00524                 break;
00525             // held and moved
00526             case JACTION_MULTIPLE:
00527                 if (_touch_pt_dt.x == -1 && _touch_pt_dt.y == -1) {
00528                     _touch_pt_dt.x = arg1;
00529                     _touch_pt_dt.y = arg2;
00530                     return;
00531                 }
00532 
00533                 dptype = Common::EVENT_MOUSEMOVE;
00534 
00535                 if (_touchpad_mode) {
00536                     scaleMouse(e.mouse, arg1 - _touch_pt_dt.x,
00537                                 arg2 - _touch_pt_dt.y, false, true);
00538                     e.mouse += _touch_pt_down;
00539 
00540                     clipMouse(e.mouse);
00541                 }
00542 
00543                 break;
00544             default:
00545                 LOGE("unhandled jaction on double tap: %d", arg3);
00546                 return;
00547             }
00548 
00549             lockMutex(_event_queue_lock);
00550             _event_queue.push(e);
00551             e.type = dptype;
00552             _event_queue.push(e);
00553             unlockMutex(_event_queue_lock);
00554         }
00555 
00556         return;
00557 
00558 
00559     case JE_TOUCH:
00560     case JE_MULTI:
00561         if (!shouldGenerateMouseEvents()) {
00562             _touchControls.update(arg1, arg2, arg3, arg4);
00563             return;
00564         }
00565         switch (arg2) {
00566         case JACTION_POINTER_DOWN:
00567             if (arg1 > _fingersDown)
00568                 _fingersDown = arg1;
00569 
00570             return;
00571 
00572         case JACTION_POINTER_UP:
00573             if (arg1 != _fingersDown)
00574                 return;
00575 
00576             {
00577                 Common::EventType up;
00578 
00579                 switch (_fingersDown) {
00580                 case 1:
00581                     e.type = Common::EVENT_RBUTTONDOWN;
00582                     up = Common::EVENT_RBUTTONUP;
00583                     break;
00584                 case 2:
00585                     e.type = Common::EVENT_MBUTTONDOWN;
00586                     up = Common::EVENT_MBUTTONUP;
00587                     break;
00588                 default:
00589                     LOGD("unmapped multi tap: %d", _fingersDown);
00590                     return;
00591                 }
00592 
00593                 e.mouse = getEventManager()->getMousePos();
00594 
00595                 lockMutex(_event_queue_lock);
00596 
00597                 if (_queuedEventTime)
00598                     _event_queue.push(_queuedEvent);
00599 
00600                 _event_queue.push(e);
00601 
00602                 e.type = up;
00603                 _queuedEvent = e;
00604                 _queuedEventTime = getMillis() + kQueuedInputEventDelay;
00605 
00606                 unlockMutex(_event_queue_lock);
00607                 return;
00608 
00609             default:
00610                 LOGE("unhandled jaction on multi tap: %d", arg2);
00611                 return;
00612             }
00613         }
00614 
00615         return;
00616 
00617     case JE_BALL:
00618         e.mouse = getEventManager()->getMousePos();
00619 
00620         switch (arg1) {
00621         case JACTION_DOWN:
00622             e.type = Common::EVENT_LBUTTONDOWN;
00623             break;
00624         case JACTION_UP:
00625             e.type = Common::EVENT_LBUTTONUP;
00626             break;
00627         case JACTION_MULTIPLE:
00628             e.type = Common::EVENT_MOUSEMOVE;
00629 
00630             // already multiplied by 100
00631             e.mouse.x += arg2 * _trackball_scale / _eventScaleX;
00632             e.mouse.y += arg3 * _trackball_scale / _eventScaleY;
00633 
00634             clipMouse(e.mouse);
00635 
00636             break;
00637         default:
00638             LOGE("unhandled jaction on system key: %d", arg1);
00639             return;
00640         }
00641 
00642         pushEvent(e);
00643 
00644         return;
00645 
00646     case JE_MOUSE_MOVE:
00647         e.type = Common::EVENT_MOUSEMOVE;
00648 
00649         scaleMouse(e.mouse, arg1, arg2);
00650         clipMouse(e.mouse);
00651 
00652         pushEvent(e);
00653 
00654         return;
00655 
00656     case JE_LMB_DOWN:
00657         e.type = Common::EVENT_LBUTTONDOWN;
00658 
00659         scaleMouse(e.mouse, arg1, arg2);
00660         clipMouse(e.mouse);
00661 
00662         pushEvent(e);
00663 
00664         return;
00665 
00666     case JE_LMB_UP:
00667         e.type = Common::EVENT_LBUTTONUP;
00668 
00669         scaleMouse(e.mouse, arg1, arg2);
00670         clipMouse(e.mouse);
00671 
00672         pushEvent(e);
00673 
00674         return;
00675 
00676     case JE_RMB_DOWN:
00677         e.type = Common::EVENT_RBUTTONDOWN;
00678 
00679         scaleMouse(e.mouse, arg1, arg2);
00680         clipMouse(e.mouse);
00681 
00682         pushEvent(e);
00683 
00684         return;
00685 
00686     case JE_RMB_UP:
00687         e.type = Common::EVENT_RBUTTONUP;
00688 
00689         scaleMouse(e.mouse, arg1, arg2);
00690         clipMouse(e.mouse);
00691 
00692         pushEvent(e);
00693 
00694         return;
00695 
00696     case JE_MMB_DOWN:
00697         e.type = Common::EVENT_MAINMENU;
00698 
00699         pushEvent(e);
00700 
00701         return;
00702 
00703     case JE_MMB_UP:
00704         // No action
00705 
00706         return;
00707 
00708     case JE_QUIT:
00709         e.type = Common::EVENT_QUIT;
00710 
00711         pushEvent(e);
00712 
00713         return;
00714 
00715     default:
00716         LOGE("unknown jevent type: %d", type);
00717 
00718         break;
00719     }
00720 }
00721 
00722 bool OSystem_Android::pollEvent(Common::Event &event) {
00723     //ENTER();
00724 
00725     if (pthread_self() == _main_thread) {
00726         if (_screen_changeid != JNI::surface_changeid) {
00727             if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
00728                 // surface changed
00729                 JNI::deinitSurface();
00730                 initSurface();
00731                 initViewport();
00732                 updateScreenRect();
00733                 updateEventScale();
00734 
00735                 // double buffered, flip twice
00736                 clearScreen(kClearUpdate, 2);
00737 
00738                 event.type = Common::EVENT_SCREEN_CHANGED;
00739 
00740                 return true;
00741             } else {
00742                 // surface lost
00743                 deinitSurface();
00744             }
00745         }
00746 
00747         if (JNI::pause) {
00748             deinitSurface();
00749 
00750             LOGD("main thread going to sleep");
00751             sem_wait(&JNI::pause_sem);
00752             LOGD("main thread woke up");
00753         }
00754     }
00755 
00756     lockMutex(_event_queue_lock);
00757 
00758     if (_queuedEventTime && (getMillis() > _queuedEventTime)) {
00759         event = _queuedEvent;
00760         _queuedEventTime = 0;
00761         unlockMutex(_event_queue_lock);
00762         return true;
00763     }
00764 
00765     if (_event_queue.empty()) {
00766         unlockMutex(_event_queue_lock);
00767         return false;
00768     }
00769 
00770     event = _event_queue.pop();
00771 
00772     unlockMutex(_event_queue_lock);
00773 
00774     if (event.type == Common::EVENT_MOUSEMOVE) {
00775         const Common::Point &m = getEventManager()->getMousePos();
00776 
00777         if (m != event.mouse)
00778             _force_redraw = true;
00779     }
00780 
00781     return true;
00782 }
00783 
00784 bool OSystem_Android::shouldGenerateMouseEvents() {
00785     // Engine doesn't support joystick -> emulate mouse events
00786     // TODO: Provide dedicated feature for handling touchscreen events
00787     if (g_engine && !g_engine->hasFeature(Engine::kSupportsJoystick)) {
00788         return true;
00789     }
00790 
00791     // Even if engine supports joystick, emulate mouse events if in GUI or in virtual keyboard
00792     if (g_gui.isActive() || g_engine->isPaused()) {
00793         return true;
00794     }
00795 
00796     return false;
00797 }
00798 
00799 void OSystem_Android::pushEvent(const Common::Event &event) {
00800     lockMutex(_event_queue_lock);
00801     _event_queue.push(event);
00802     unlockMutex(_event_queue_lock);
00803 }
00804 
00805 void OSystem_Android::keyPress(const Common::KeyCode keycode, const KeyReceiver::KeyPressType type) {
00806     Common::Event e;
00807     e.kbd.keycode = keycode;
00808     lockMutex(_event_queue_lock);
00809     if (type == KeyReceiver::DOWN || type == KeyReceiver::PRESS) {
00810         e.type = Common::EVENT_KEYDOWN;
00811         _event_queue.push(e);
00812     }
00813     if (type == KeyReceiver::UP || type == KeyReceiver::PRESS) {
00814         e.type = Common::EVENT_KEYUP;
00815         _event_queue.push(e);
00816     }
00817     unlockMutex(_event_queue_lock);
00818 }
00819 
00820 #endif


Generated on Sat May 25 2019 05:00:44 for ResidualVM by doxygen 1.7.1
curved edge   curved edge