Path: blob/master/scene/2d/physics/touch_screen_button.h
9906 views
/**************************************************************************/1/* touch_screen_button.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/2d/node_2d.h"33#include "scene/resources/2d/rectangle_shape_2d.h"34#include "scene/resources/bit_map.h"35#include "scene/resources/texture.h"3637class TouchScreenButton : public Node2D {38GDCLASS(TouchScreenButton, Node2D);3940public:41enum VisibilityMode {42VISIBILITY_ALWAYS,43VISIBILITY_TOUCHSCREEN_ONLY44};4546private:47Ref<Texture2D> texture_normal;48Ref<Texture2D> texture_pressed;49Ref<BitMap> bitmask;50Ref<Shape2D> shape;51bool shape_centered = true;52bool shape_visible = true;5354Ref<RectangleShape2D> unit_rect;5556StringName action;57bool passby_press = false;58int finger_pressed = -1;5960VisibilityMode visibility = VISIBILITY_ALWAYS;6162virtual void input(const Ref<InputEvent> &p_event) override;6364bool _is_point_inside(const Point2 &p_point);6566void _press(int p_finger_pressed);67void _release(bool p_exiting_tree = false);6869protected:70void _notification(int p_what);71static void _bind_methods();72#ifndef DISABLE_DEPRECATED73bool _set(const StringName &p_name, const Variant &p_value);74#endif // DISABLE_DEPRECATED7576void _accessibility_action_click(const Variant &p_data);7778public:79#ifdef DEBUG_ENABLED80virtual Rect2 _edit_get_rect() const override;81virtual bool _edit_use_rect() const override;82#endif // DEBUG_ENABLED8384void set_texture_normal(const Ref<Texture2D> &p_texture);85Ref<Texture2D> get_texture_normal() const;8687void set_texture_pressed(const Ref<Texture2D> &p_texture_pressed);88Ref<Texture2D> get_texture_pressed() const;8990void set_bitmask(const Ref<BitMap> &p_bitmask);91Ref<BitMap> get_bitmask() const;9293void set_shape(const Ref<Shape2D> &p_shape);94Ref<Shape2D> get_shape() const;9596void set_shape_centered(bool p_shape_centered);97bool is_shape_centered() const;9899void set_shape_visible(bool p_shape_visible);100bool is_shape_visible() const;101102void set_action(const String &p_action);103String get_action() const;104105void set_passby_press(bool p_enable);106bool is_passby_press_enabled() const;107108void set_visibility_mode(VisibilityMode p_mode);109VisibilityMode get_visibility_mode() const;110111bool is_pressed() const;112113virtual Rect2 get_anchorable_rect() const override;114115TouchScreenButton();116};117118VARIANT_ENUM_CAST(TouchScreenButton::VisibilityMode);119120121