| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
#include "scene/resources/2d/rectangle_shape_2d.h" |
| 35 |
#include "scene/resources/bit_map.h" |
| 36 |
#include "scene/resources/texture.h" |
| 37 |
|
| 38 |
class TouchScreenButton : public Node2D { |
| 39 |
GDCLASS(TouchScreenButton, Node2D); |
| 40 |
|
| 41 |
public: |
| 42 |
enum VisibilityMode { |
| 43 |
VISIBILITY_ALWAYS, |
| 44 |
VISIBILITY_TOUCHSCREEN_ONLY |
| 45 |
}; |
| 46 |
|
| 47 |
private: |
| 48 |
Ref<Texture2D> texture_normal; |
| 49 |
Ref<Texture2D> texture_pressed; |
| 50 |
Ref<BitMap> bitmask; |
| 51 |
Ref<Shape2D> shape; |
| 52 |
bool shape_centered = true; |
| 53 |
bool shape_visible = true; |
| 54 |
|
| 55 |
Ref<RectangleShape2D> unit_rect; |
| 56 |
|
| 57 |
StringName action; |
| 58 |
bool passby_press = false; |
| 59 |
int finger_pressed = -1; |
| 60 |
|
| 61 |
VisibilityMode visibility = VISIBILITY_ALWAYS; |
| 62 |
|
| 63 |
virtual void input(const Ref<InputEvent> &p_event) override; |
| 64 |
|
| 65 |
bool _is_point_inside(const Point2 &p_point); |
| 66 |
|
| 67 |
void _press(int p_finger_pressed); |
| 68 |
void _release(bool p_exiting_tree = false); |
| 69 |
|
| 70 |
protected: |
| 71 |
void _notification(int p_what); |
| 72 |
static void _bind_methods(); |
| 73 |
#ifndef DISABLE_DEPRECATED |
| 74 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 75 |
#endif |
| 76 |
|
| 77 |
void _accessibility_action_click(const Variant &p_data); |
| 78 |
|
| 79 |
public: |
| 80 |
#ifdef DEBUG_ENABLED |
| 81 |
virtual Rect2 _edit_get_rect() const override; |
| 82 |
virtual bool _edit_use_rect() const override; |
| 83 |
#endif |
| 84 |
|
| 85 |
void set_texture_normal(const Ref<Texture2D> &p_texture); |
| 86 |
Ref<Texture2D> get_texture_normal() const; |
| 87 |
|
| 88 |
void set_texture_pressed(const Ref<Texture2D> &p_texture_pressed); |
| 89 |
Ref<Texture2D> get_texture_pressed() const; |
| 90 |
|
| 91 |
void set_bitmask(const Ref<BitMap> &p_bitmask); |
| 92 |
Ref<BitMap> get_bitmask() const; |
| 93 |
|
| 94 |
void set_shape(const Ref<Shape2D> &p_shape); |
| 95 |
Ref<Shape2D> get_shape() const; |
| 96 |
|
| 97 |
void set_shape_centered(bool p_shape_centered); |
| 98 |
bool is_shape_centered() const; |
| 99 |
|
| 100 |
void set_shape_visible(bool p_shape_visible); |
| 101 |
bool is_shape_visible() const; |
| 102 |
|
| 103 |
void set_action(const String &p_action); |
| 104 |
String get_action() const; |
| 105 |
|
| 106 |
void set_passby_press(bool p_enable); |
| 107 |
bool is_passby_press_enabled() const; |
| 108 |
|
| 109 |
void set_visibility_mode(VisibilityMode p_mode); |
| 110 |
VisibilityMode get_visibility_mode() const; |
| 111 |
|
| 112 |
bool is_pressed() const; |
| 113 |
|
| 114 |
virtual Rect2 get_anchorable_rect() const override; |
| 115 |
|
| 116 |
TouchScreenButton(); |
| 117 |
}; |
| 118 |
|
| 119 |
VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode); |