screen_button.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* screen_button.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. OBJ_TYPE(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. int action_id;
  55. VisibilityMode visibility;
  56. void _input(const InputEvent &p_Event);
  57. bool _is_touch_inside(const InputEventScreenTouch &p_touch);
  58. void _press(int p_finger_pressed);
  59. void _release(bool p_exiting_tree = false);
  60. protected:
  61. void _notification(int p_what);
  62. static void _bind_methods();
  63. public:
  64. void set_texture(const Ref<Texture> &p_texture);
  65. Ref<Texture> get_texture() const;
  66. void set_texture_pressed(const Ref<Texture> &p_texture_pressed);
  67. Ref<Texture> get_texture_pressed() const;
  68. void set_bitmask(const Ref<BitMap> &p_bitmask);
  69. Ref<BitMap> get_bitmask() const;
  70. void set_shape(const Ref<Shape2D> &p_shape);
  71. Ref<Shape2D> get_shape() const;
  72. void set_shape_centered(bool p_shape_centered);
  73. bool is_shape_centered() const;
  74. void set_shape_visible(bool p_shape_visible);
  75. bool is_shape_visible() const;
  76. void set_action(const String &p_action);
  77. String get_action() const;
  78. void set_passby_press(bool p_enable);
  79. bool is_passby_press_enabled() const;
  80. void set_visibility_mode(VisibilityMode p_mode);
  81. VisibilityMode get_visibility_mode() const;
  82. bool is_pressed() const;
  83. Rect2 get_item_rect() const;
  84. TouchScreenButton();
  85. };
  86. VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);
  87. #endif // SCREEN_BUTTON_H