touch_screen_button.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**************************************************************************/
  2. /* touch_screen_button.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TOUCH_SCREEN_BUTTON_H
  31. #define TOUCH_SCREEN_BUTTON_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/2d/rectangle_shape_2d.h"
  34. #include "scene/resources/bit_map.h"
  35. #include "scene/resources/texture.h"
  36. class TouchScreenButton : public Node2D {
  37. GDCLASS(TouchScreenButton, Node2D);
  38. public:
  39. enum VisibilityMode {
  40. VISIBILITY_ALWAYS,
  41. VISIBILITY_TOUCHSCREEN_ONLY
  42. };
  43. private:
  44. Ref<Texture2D> texture_normal;
  45. Ref<Texture2D> texture_pressed;
  46. Ref<BitMap> bitmask;
  47. Ref<Shape2D> shape;
  48. bool shape_centered = true;
  49. bool shape_visible = true;
  50. Ref<RectangleShape2D> unit_rect;
  51. StringName action;
  52. bool passby_press = false;
  53. int finger_pressed = -1;
  54. VisibilityMode visibility = VISIBILITY_ALWAYS;
  55. virtual void input(const Ref<InputEvent> &p_event) override;
  56. bool _is_point_inside(const Point2 &p_point);
  57. void _press(int p_finger_pressed);
  58. void _release(bool p_exiting_tree = false);
  59. protected:
  60. void _notification(int p_what);
  61. static void _bind_methods();
  62. #ifndef DISABLE_DEPRECATED
  63. bool _set(const StringName &p_name, const Variant &p_value);
  64. #endif // DISABLE_DEPRECATED
  65. public:
  66. #ifdef DEBUG_ENABLED
  67. virtual Rect2 _edit_get_rect() const override;
  68. virtual bool _edit_use_rect() const override;
  69. #endif // DEBUG_ENABLED
  70. void set_texture_normal(const Ref<Texture2D> &p_texture);
  71. Ref<Texture2D> get_texture_normal() const;
  72. void set_texture_pressed(const Ref<Texture2D> &p_texture_pressed);
  73. Ref<Texture2D> get_texture_pressed() const;
  74. void set_bitmask(const Ref<BitMap> &p_bitmask);
  75. Ref<BitMap> get_bitmask() const;
  76. void set_shape(const Ref<Shape2D> &p_shape);
  77. Ref<Shape2D> get_shape() const;
  78. void set_shape_centered(bool p_shape_centered);
  79. bool is_shape_centered() const;
  80. void set_shape_visible(bool p_shape_visible);
  81. bool is_shape_visible() const;
  82. void set_action(const String &p_action);
  83. String get_action() const;
  84. void set_passby_press(bool p_enable);
  85. bool is_passby_press_enabled() const;
  86. void set_visibility_mode(VisibilityMode p_mode);
  87. VisibilityMode get_visibility_mode() const;
  88. bool is_pressed() const;
  89. virtual Rect2 get_anchorable_rect() const override;
  90. TouchScreenButton();
  91. };
  92. VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);
  93. #endif // TOUCH_SCREEN_BUTTON_H