screen_button.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*************************************************************************/
  2. /* screen_button.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  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 SCREEN_BUTTON_H
  31. #define SCREEN_BUTTON_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/bit_mask.h"
  34. #include "scene/resources/rectangle_shape_2d.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<Texture> texture;
  45. Ref<Texture> texture_pressed;
  46. Ref<BitMap> bitmask;
  47. Ref<Shape2D> shape;
  48. bool shape_centered;
  49. bool shape_visible;
  50. Ref<RectangleShape2D> unit_rect;
  51. StringName action;
  52. bool passby_press;
  53. int finger_pressed;
  54. VisibilityMode visibility;
  55. void _input(const Ref<InputEvent> &p_event);
  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. public:
  63. void set_texture(const Ref<Texture> &p_texture);
  64. Ref<Texture> get_texture() const;
  65. void set_texture_pressed(const Ref<Texture> &p_texture_pressed);
  66. Ref<Texture> get_texture_pressed() const;
  67. void set_bitmask(const Ref<BitMap> &p_bitmask);
  68. Ref<BitMap> get_bitmask() const;
  69. void set_shape(const Ref<Shape2D> &p_shape);
  70. Ref<Shape2D> get_shape() const;
  71. void set_shape_centered(bool p_shape_centered);
  72. bool is_shape_centered() const;
  73. void set_shape_visible(bool p_shape_visible);
  74. bool is_shape_visible() const;
  75. void set_action(const String &p_action);
  76. String get_action() const;
  77. void set_passby_press(bool p_enable);
  78. bool is_passby_press_enabled() const;
  79. void set_visibility_mode(VisibilityMode p_mode);
  80. VisibilityMode get_visibility_mode() const;
  81. bool is_pressed() const;
  82. Rect2 get_item_rect() const;
  83. TouchScreenButton();
  84. };
  85. VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);
  86. #endif // SCREEN_BUTTON_H