2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* screen_button.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "screen_button.h"
|
|
|
|
#include "input_map.h"
|
|
|
|
#include "os/input.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "os/os.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::set_texture(const Ref<Texture> &p_texture) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
texture = p_texture;
|
2014-02-10 02:10:30 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> TouchScreenButton::get_texture() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::set_texture_pressed(const Ref<Texture> &p_texture_pressed) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
texture_pressed = p_texture_pressed;
|
2014-02-10 02:10:30 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> TouchScreenButton::get_texture_pressed() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return texture_pressed;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::set_bitmask(const Ref<BitMap> &p_bitmask) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bitmask = p_bitmask;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<BitMap> TouchScreenButton::get_bitmask() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return bitmask;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
|
2017-01-25 17:06:06 +01:00
|
|
|
|
2017-04-03 14:23:52 +02:00
|
|
|
if (shape.is_valid())
|
|
|
|
shape->disconnect("changed", this, "update");
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
shape = p_shape;
|
2017-01-25 17:06:06 +01:00
|
|
|
|
2017-04-03 14:23:52 +02:00
|
|
|
if (shape.is_valid())
|
|
|
|
shape->connect("changed", this, "update");
|
|
|
|
|
2017-01-25 17:06:06 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Shape2D> TouchScreenButton::get_shape() const {
|
2017-01-25 17:06:06 +01:00
|
|
|
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::set_shape_centered(bool p_shape_centered) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
shape_centered = p_shape_centered;
|
2017-04-03 14:23:52 +02:00
|
|
|
update();
|
|
|
|
}
|
2017-01-25 17:06:06 +01:00
|
|
|
|
2017-04-03 14:23:52 +02:00
|
|
|
bool TouchScreenButton::is_shape_visible() const {
|
|
|
|
|
|
|
|
return shape_visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::set_shape_visible(bool p_shape_visible) {
|
|
|
|
|
|
|
|
shape_visible = p_shape_visible;
|
2017-01-25 17:06:06 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchScreenButton::is_shape_centered() const {
|
|
|
|
|
|
|
|
return shape_centered;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TouchScreenButton::_notification(int p_what) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
switch (p_what) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (finger_pressed != -1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (texture_pressed.is_valid())
|
2017-03-19 00:36:26 +01:00
|
|
|
draw_texture(texture_pressed, Point2());
|
2014-02-10 02:10:30 +01:00
|
|
|
else if (texture.is_valid())
|
2017-03-19 00:36:26 +01:00
|
|
|
draw_texture(texture, Point2());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (texture.is_valid())
|
2017-03-19 00:36:26 +01:00
|
|
|
draw_texture(texture, Point2());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 14:23:52 +02:00
|
|
|
if (!shape_visible)
|
|
|
|
return;
|
2017-01-25 17:06:06 +01:00
|
|
|
if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
|
|
|
|
return;
|
|
|
|
if (shape.is_valid()) {
|
2017-03-19 00:36:26 +01:00
|
|
|
Color draw_col = get_tree()->get_debug_collisions_color();
|
|
|
|
Vector2 pos = shape_centered ? get_item_rect().size * 0.5f : Vector2();
|
2017-01-25 17:06:06 +01:00
|
|
|
draw_set_transform_matrix(get_canvas_transform().translated(pos));
|
2017-03-19 00:36:26 +01:00
|
|
|
shape->draw(get_canvas_item(), draw_col);
|
2017-01-25 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
update();
|
2014-07-13 02:48:02 +02:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!get_tree()->is_editor_hint())
|
2017-03-09 01:25:42 +01:00
|
|
|
set_process_input(is_visible());
|
2014-07-13 02:48:02 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
|
|
|
|
action_id = InputMap::get_singleton()->get_action_id(action);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
action_id = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} break;
|
2015-12-27 23:06:30 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
if (is_pressed())
|
2017-02-04 16:57:11 +01:00
|
|
|
_release(true);
|
2015-12-27 23:06:30 +01:00
|
|
|
} break;
|
2017-03-09 01:25:42 +01:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
if (get_tree()->is_editor_hint())
|
|
|
|
break;
|
|
|
|
if (is_visible()) {
|
|
|
|
set_process_input(true);
|
|
|
|
} else {
|
|
|
|
set_process_input(false);
|
|
|
|
if (is_pressed())
|
|
|
|
_release();
|
|
|
|
}
|
|
|
|
} break;
|
2017-02-04 16:57:11 +01:00
|
|
|
case NOTIFICATION_PAUSED: {
|
2017-03-09 01:25:42 +01:00
|
|
|
if (is_pressed())
|
|
|
|
_release();
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool TouchScreenButton::is_pressed() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
return finger_pressed != -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::set_action(const String &p_action) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
action = p_action;
|
|
|
|
if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
|
|
|
|
action_id = InputMap::get_singleton()->get_action_id(action);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
action_id = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String TouchScreenButton::get_action() const {
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TouchScreenButton::_input(const InputEvent &p_event) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!get_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2014-08-14 15:31:38 +02:00
|
|
|
if (p_event.device != 0)
|
|
|
|
return;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (passby_press) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed == p_event.screen_touch.index) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-04 16:57:11 +01:00
|
|
|
_release();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if ((p_event.type == InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed) || p_event.type == InputEvent::SCREEN_DRAG) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (finger_pressed == -1 || p_event.screen_touch.index == finger_pressed) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool touched = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (bitmask.is_valid()) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (bitmask->get_bit(coord))
|
2017-03-19 00:36:26 +01:00
|
|
|
touched = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2014-07-13 04:08:50 +02:00
|
|
|
if (texture.is_valid())
|
2017-03-19 00:36:26 +01:00
|
|
|
touched = Rect2(Point2(), texture->get_size()).has_point(coord);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (touched) {
|
2017-03-19 00:36:26 +01:00
|
|
|
if (finger_pressed == -1) {
|
2017-02-04 16:57:11 +01:00
|
|
|
_press(p_event.screen_touch.index);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
if (finger_pressed != -1) {
|
2017-02-04 16:57:11 +01:00
|
|
|
_release();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::SCREEN_TOUCH) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (p_event.screen_touch.pressed) {
|
|
|
|
|
|
|
|
if (!is_visible())
|
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
const bool can_press = finger_pressed == -1;
|
2017-02-04 16:57:11 +01:00
|
|
|
if (!can_press)
|
2014-02-10 02:10:30 +01:00
|
|
|
return; //already fingering
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
|
2017-01-25 17:06:06 +01:00
|
|
|
Rect2 item_rect = get_item_rect();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool touched = false;
|
|
|
|
bool check_rect = true;
|
2017-01-25 17:06:06 +01:00
|
|
|
if (shape.is_valid()) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
check_rect = false;
|
|
|
|
Matrix32 xform = shape_centered ? Matrix32().translated(get_item_rect().size * 0.5f) : Matrix32();
|
|
|
|
touched = shape->collide(xform, unit_rect, Matrix32(0, coord + Vector2(0.5, 0.5)));
|
2017-01-25 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (bitmask.is_valid()) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
check_rect = false;
|
|
|
|
if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (bitmask->get_bit(coord))
|
2017-03-19 00:36:26 +01:00
|
|
|
touched = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-01-25 17:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!touched && check_rect) {
|
2014-05-20 15:05:18 +02:00
|
|
|
if (!texture.is_null())
|
2017-03-19 00:36:26 +01:00
|
|
|
touched = item_rect.has_point(coord);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (touched) {
|
2017-02-04 16:57:11 +01:00
|
|
|
_press(p_event.screen_touch.index);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.screen_touch.index == finger_pressed) {
|
2017-02-04 16:57:11 +01:00
|
|
|
_release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-04 16:57:11 +01:00
|
|
|
void TouchScreenButton::_press(int p_finger_pressed) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
finger_pressed = p_finger_pressed;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (action_id != -1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-04 16:57:11 +01:00
|
|
|
Input::get_singleton()->action_press(action);
|
|
|
|
InputEvent ie;
|
2017-03-19 00:36:26 +01:00
|
|
|
ie.type = InputEvent::ACTION;
|
|
|
|
ie.ID = 0;
|
|
|
|
ie.action.action = action_id;
|
|
|
|
ie.action.pressed = true;
|
2017-02-04 16:57:11 +01:00
|
|
|
get_tree()->input_event(ie);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-04 16:57:11 +01:00
|
|
|
emit_signal("pressed");
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::_release(bool p_exiting_tree) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
finger_pressed = -1;
|
2017-02-04 16:57:11 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (action_id != -1) {
|
2017-02-04 16:57:11 +01:00
|
|
|
|
|
|
|
Input::get_singleton()->action_release(action);
|
2017-02-22 01:36:31 +01:00
|
|
|
if (!p_exiting_tree) {
|
|
|
|
InputEvent ie;
|
2017-03-19 00:36:26 +01:00
|
|
|
ie.type = InputEvent::ACTION;
|
|
|
|
ie.ID = 0;
|
|
|
|
ie.action.action = action_id;
|
|
|
|
ie.action.pressed = false;
|
2017-02-22 01:36:31 +01:00
|
|
|
get_tree()->input_event(ie);
|
|
|
|
}
|
2017-02-04 16:57:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_exiting_tree) {
|
|
|
|
emit_signal("released");
|
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 TouchScreenButton::get_item_rect() const {
|
|
|
|
|
|
|
|
if (texture.is_null())
|
2017-03-19 00:36:26 +01:00
|
|
|
return Rect2(0, 0, 1, 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
//if (texture.is_null())
|
|
|
|
// return CanvasItem::get_item_rect();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
return Rect2(Size2(), texture->get_size());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::set_visibility_mode(VisibilityMode p_mode) {
|
2017-03-19 00:36:26 +01:00
|
|
|
visibility = p_mode;
|
2014-02-10 02:10:30 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchScreenButton::VisibilityMode TouchScreenButton::get_visibility_mode() const {
|
|
|
|
|
|
|
|
return visibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::set_passby_press(bool p_enable) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
passby_press = p_enable;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool TouchScreenButton::is_passby_press_enabled() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return passby_press;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenButton::_bind_methods() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_texture", "texture"), &TouchScreenButton::set_texture);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_texture"), &TouchScreenButton::get_texture);
|
2017-01-25 17:06:06 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_texture_pressed", "texture_pressed"), &TouchScreenButton::set_texture_pressed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_texture_pressed"), &TouchScreenButton::get_texture_pressed);
|
2017-01-25 17:06:06 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_bitmask", "bitmask"), &TouchScreenButton::set_bitmask);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_bitmask"), &TouchScreenButton::get_bitmask);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_shape", "shape"), &TouchScreenButton::set_shape);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_shape"), &TouchScreenButton::get_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_shape_centered", "bool"), &TouchScreenButton::set_shape_centered);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_shape_centered"), &TouchScreenButton::is_shape_centered);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-03 14:23:52 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_shape_visible", "bool"), &TouchScreenButton::set_shape_visible);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_shape_visible"), &TouchScreenButton::is_shape_visible);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_action", "action"), &TouchScreenButton::set_action);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_action"), &TouchScreenButton::get_action);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_visibility_mode", "mode"), &TouchScreenButton::set_visibility_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_visibility_mode"), &TouchScreenButton::get_visibility_mode);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_passby_press", "enabled"), &TouchScreenButton::set_passby_press);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_passby_press_enabled"), &TouchScreenButton::is_passby_press_enabled);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("is_pressed"), &TouchScreenButton::is_pressed);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_input"), &TouchScreenButton::_input);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"), _SCS("get_texture"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture_pressed"), _SCS("get_texture_pressed"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bitmask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), _SCS("set_bitmask"), _SCS("get_bitmask"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), _SCS("set_shape"), _SCS("get_shape"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_centered"), _SCS("set_shape_centered"), _SCS("is_shape_centered"));
|
2017-04-03 14:23:52 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_visible"), _SCS("set_shape_visible"), _SCS("is_shape_visible"));
|
2017-03-19 00:36:26 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "passby_press"), _SCS("set_passby_press"), _SCS("is_passby_press_enabled"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), _SCS("set_action"), _SCS("get_action"));
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_mode", PROPERTY_HINT_ENUM, "Always,TouchScreen Only"), _SCS("set_visibility_mode"), _SCS("get_visibility_mode"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("pressed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("released"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TouchScreenButton::TouchScreenButton() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
finger_pressed = -1;
|
|
|
|
action_id = -1;
|
|
|
|
passby_press = false;
|
|
|
|
visibility = VISIBILITY_ALWAYS;
|
|
|
|
shape_centered = true;
|
2017-04-03 14:23:52 +02:00
|
|
|
shape_visible = true;
|
2017-03-19 00:36:26 +01:00
|
|
|
unit_rect = Ref<RectangleShape2D>(memnew(RectangleShape2D));
|
|
|
|
unit_rect->set_extents(Vector2(0.5, 0.5));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|