summaryrefslogtreecommitdiff
path: root/scene/2d/touch_screen_button.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-14 23:09:03 +0200
committerGitHub <noreply@github.com>2020-05-14 23:09:03 +0200
commit00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch)
tree2b1c31f45add24085b64425ce440f577424c16a1 /scene/2d/touch_screen_button.cpp
parent5046f666a1181675b39f156c38346525dc1c444e (diff)
parent0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff)
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'scene/2d/touch_screen_button.cpp')
-rw-r--r--scene/2d/touch_screen_button.cpp105
1 files changed, 43 insertions, 62 deletions
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 590cc1e6c4..4597300db8 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -36,104 +36,96 @@
#include "scene/main/window.h"
#
void TouchScreenButton::set_texture(const Ref<Texture2D> &p_texture) {
-
texture = p_texture;
update();
}
Ref<Texture2D> TouchScreenButton::get_texture() const {
-
return texture;
}
void TouchScreenButton::set_texture_pressed(const Ref<Texture2D> &p_texture_pressed) {
-
texture_pressed = p_texture_pressed;
update();
}
Ref<Texture2D> TouchScreenButton::get_texture_pressed() const {
-
return texture_pressed;
}
void TouchScreenButton::set_bitmask(const Ref<BitMap> &p_bitmask) {
-
bitmask = p_bitmask;
}
Ref<BitMap> TouchScreenButton::get_bitmask() const {
-
return bitmask;
}
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
-
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update));
+ }
shape = p_shape;
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update));
+ }
update();
}
Ref<Shape2D> TouchScreenButton::get_shape() const {
-
return shape;
}
void TouchScreenButton::set_shape_centered(bool p_shape_centered) {
-
shape_centered = p_shape_centered;
update();
}
bool TouchScreenButton::is_shape_visible() const {
-
return shape_visible;
}
void TouchScreenButton::set_shape_visible(bool p_shape_visible) {
-
shape_visible = p_shape_visible;
update();
}
bool TouchScreenButton::is_shape_centered() const {
-
return shape_centered;
}
void TouchScreenButton::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_DRAW: {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
+ }
+ if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
+ }
if (finger_pressed != -1) {
-
- if (texture_pressed.is_valid())
+ if (texture_pressed.is_valid()) {
draw_texture(texture_pressed, Point2());
- else if (texture.is_valid())
+ } else if (texture.is_valid()) {
draw_texture(texture, Point2());
+ }
} else {
- if (texture.is_valid())
+ if (texture.is_valid()) {
draw_texture(texture, Point2());
+ }
}
- if (!shape_visible)
+ if (!shape_visible) {
return;
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
+ }
+ if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
return;
+ }
if (shape.is_valid()) {
Color draw_col = get_tree()->get_debug_collisions_color();
@@ -145,80 +137,79 @@ void TouchScreenButton::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
-
- if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
+ if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
+ }
update();
- if (!Engine::get_singleton()->is_editor_hint())
+ if (!Engine::get_singleton()->is_editor_hint()) {
set_process_input(is_visible_in_tree());
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
- if (is_pressed())
+ if (is_pressed()) {
_release(true);
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
break;
+ }
if (is_visible_in_tree()) {
set_process_input(true);
} else {
set_process_input(false);
- if (is_pressed())
+ if (is_pressed()) {
_release();
+ }
}
} break;
case NOTIFICATION_PAUSED: {
- if (is_pressed())
+ if (is_pressed()) {
_release();
+ }
} break;
}
}
bool TouchScreenButton::is_pressed() const {
-
return finger_pressed != -1;
}
void TouchScreenButton::set_action(const String &p_action) {
-
action = p_action;
}
String TouchScreenButton::get_action() const {
-
return action;
}
void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
-
- if (!get_tree())
+ if (!get_tree()) {
return;
+ }
- if (p_event->get_device() != 0)
+ if (p_event->get_device() != 0) {
return;
+ }
ERR_FAIL_COND(!is_visible_in_tree());
const InputEventScreenTouch *st = Object::cast_to<InputEventScreenTouch>(*p_event);
if (passby_press) {
-
const InputEventScreenDrag *sd = Object::cast_to<InputEventScreenDrag>(*p_event);
if (st && !st->is_pressed() && finger_pressed == st->get_index()) {
-
_release();
}
if ((st && st->is_pressed()) || sd) {
-
int index = st ? st->get_index() : sd->get_index();
Point2 coord = st ? st->get_position() : sd->get_position();
if (finger_pressed == -1 || index == finger_pressed) {
-
if (_is_point_inside(coord)) {
if (finger_pressed == -1) {
_press(index);
@@ -232,14 +223,12 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
}
} else {
-
if (st) {
-
if (st->is_pressed()) {
-
const bool can_press = finger_pressed == -1;
- if (!can_press)
+ if (!can_press) {
return; //already fingering
+ }
if (_is_point_inside(st->get_position())) {
_press(st->get_index());
@@ -268,29 +257,27 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) {
}
if (bitmask.is_valid()) {
-
check_rect = false;
if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
-
- if (bitmask->get_bit(coord))
+ if (bitmask->get_bit(coord)) {
touched = true;
+ }
}
}
if (!touched && check_rect) {
- if (texture.is_valid())
+ if (texture.is_valid()) {
touched = Rect2(Size2(), texture->get_size()).has_point(coord);
+ }
}
return touched;
}
void TouchScreenButton::_press(int p_finger_pressed) {
-
finger_pressed = p_finger_pressed;
if (action != StringName()) {
-
Input::get_singleton()->action_press(action);
Ref<InputEventAction> iea;
iea.instance();
@@ -304,14 +291,11 @@ void TouchScreenButton::_press(int p_finger_pressed) {
}
void TouchScreenButton::_release(bool p_exiting_tree) {
-
finger_pressed = -1;
if (action != StringName()) {
-
Input::get_singleton()->action_release(action);
if (!p_exiting_tree) {
-
Ref<InputEventAction> iea;
iea.instance();
iea->set_action(action);
@@ -328,8 +312,9 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
#ifdef TOOLS_ENABLED
Rect2 TouchScreenButton::_edit_get_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return CanvasItem::_edit_get_rect();
+ }
return Rect2(Size2(), texture->get_size());
}
@@ -340,8 +325,9 @@ bool TouchScreenButton::_edit_use_rect() const {
#endif
Rect2 TouchScreenButton::get_anchorable_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return CanvasItem::get_anchorable_rect();
+ }
return Rect2(Size2(), texture->get_size());
}
@@ -352,22 +338,18 @@ void TouchScreenButton::set_visibility_mode(VisibilityMode p_mode) {
}
TouchScreenButton::VisibilityMode TouchScreenButton::get_visibility_mode() const {
-
return visibility;
}
void TouchScreenButton::set_passby_press(bool p_enable) {
-
passby_press = p_enable;
}
bool TouchScreenButton::is_passby_press_enabled() const {
-
return passby_press;
}
void TouchScreenButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TouchScreenButton::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &TouchScreenButton::get_texture);
@@ -417,7 +399,6 @@ void TouchScreenButton::_bind_methods() {
}
TouchScreenButton::TouchScreenButton() {
-
finger_pressed = -1;
passby_press = false;
visibility = VISIBILITY_ALWAYS;