InputAndroid.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <anki/input/Input.h>
  6. #include <anki/core/NativeWindowAndroid.h>
  7. #include <anki/util/Logger.h>
  8. #include <anki/core/App.h>
  9. namespace anki
  10. {
  11. static void handleAndroidEvents(android_app* app, int32_t cmd)
  12. {
  13. Input* input = (Input*)app->userData;
  14. ANKI_ASSERT(input != nullptr);
  15. switch(cmd)
  16. {
  17. case APP_CMD_TERM_WINDOW:
  18. case APP_CMD_LOST_FOCUS:
  19. ANKI_LOGI("New event 0x%x", cmd);
  20. input->addEvent(Input::WINDOW_CLOSED_EVENT);
  21. break;
  22. }
  23. }
  24. Input::~Input()
  25. {
  26. }
  27. void Input::handleEvents()
  28. {
  29. int ident;
  30. int outEvents;
  31. android_poll_source* source;
  32. zeroMemory(events);
  33. while((ident = ALooper_pollAll(0, NULL, &outEvents, (void**)&source)) >= 0)
  34. {
  35. if(source != NULL)
  36. {
  37. source->process(gAndroidApp, source);
  38. }
  39. }
  40. }
  41. void Input::init(NativeWindow* /*nativeWindow*/)
  42. {
  43. ANKI_ASSERT(gAndroidApp);
  44. gAndroidApp->userData = this;
  45. gAndroidApp->onAppCmd = handleAndroidEvents;
  46. }
  47. void Input::moveCursor(const Vec2& posNdc)
  48. {
  49. // do nothing
  50. }
  51. void Input::hideCursor(Bool hide)
  52. {
  53. // do nothing
  54. }
  55. } // end namespace anki