Skip to content
0.2.0-dev Download ZIP
119 lines ·4.3 KB Raw
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#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
38class TouchScreenButton : public Node2D {
39 GDCLASS(TouchScreenButton, Node2D);
40
41public:
42 enum VisibilityMode {
43 VISIBILITY_ALWAYS,
44 VISIBILITY_TOUCHSCREEN_ONLY
45 };
46
47private:
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
70protected:
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 // DISABLE_DEPRECATED
76
77 void _accessibility_action_click(const Variant &p_data);
78
79public:
80#ifdef DEBUG_ENABLED
81 virtual Rect2 _edit_get_rect() const override;
82 virtual bool _edit_use_rect() const override;
83#endif // DEBUG_ENABLED
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
119VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);