modalMenu.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include "util/string.h"
  19. class GUIModalMenu;
  20. class IMenuManager
  21. {
  22. public:
  23. // A GUIModalMenu calls these when this class is passed as a parameter
  24. virtual void createdMenu(gui::IGUIElement *menu) = 0;
  25. virtual void deletingMenu(gui::IGUIElement *menu) = 0;
  26. };
  27. // Remember to drop() the menu after creating, so that it can
  28. // remove itself when it wants to.
  29. class GUIModalMenu : public gui::IGUIElement
  30. {
  31. public:
  32. GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
  33. IMenuManager *menumgr);
  34. virtual ~GUIModalMenu();
  35. void allowFocusRemoval(bool allow);
  36. bool canTakeFocus(gui::IGUIElement *e);
  37. void draw();
  38. void quitMenu();
  39. void removeChildren();
  40. virtual void regenerateGui(v2u32 screensize) = 0;
  41. virtual void drawMenu() = 0;
  42. virtual bool preprocessEvent(const SEvent& event);
  43. virtual bool OnEvent(const SEvent& event) { return false; };
  44. virtual bool pausesGame() { return false; } // Used for pause menu
  45. #ifdef __ANDROID__
  46. virtual bool getAndroidUIInput() { return false; }
  47. bool hasAndroidUIInput();
  48. #endif
  49. protected:
  50. virtual std::wstring getLabelByID(s32 id) = 0;
  51. virtual std::string getNameByID(s32 id) = 0;
  52. v2s32 m_pointer;
  53. v2s32 m_old_pointer; // Mouse position after previous mouse event
  54. v2u32 m_screensize_old;
  55. float m_gui_scale;
  56. #ifdef __ANDROID__
  57. v2s32 m_down_pos;
  58. std::string m_jni_field_name;
  59. #endif
  60. #ifdef HAVE_TOUCHSCREENGUI
  61. bool m_touchscreen_visible = true;
  62. #endif
  63. private:
  64. IMenuManager *m_menumgr;
  65. // This might be necessary to expose to the implementation if it
  66. // wants to launch other menus
  67. bool m_allow_focus_removal = false;
  68. };