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