| 1 | /**************************************************************************/ |
| 2 | /* reference_rect.cpp */ |
| 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 | #include "reference_rect.h" |
| 32 | |
| 33 | #include "core/config/engine.h" |
| 34 | |
| 35 | void ReferenceRect::_notification(int p_what) { |
| 36 | switch (p_what) { |
| 37 | case NOTIFICATION_DRAW: { |
| 38 | if (!is_inside_tree()) { |
| 39 | return; |
| 40 | } |
| 41 | if (Engine::get_singleton()->is_editor_hint() || !editor_only) { |
| 42 | draw_rect(Rect2(Point2(), get_size()), border_color, false, border_width); |
| 43 | } |
| 44 | } break; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void ReferenceRect::set_border_color(const Color &p_color) { |
| 49 | if (border_color == p_color) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | border_color = p_color; |
| 54 | queue_redraw(); |
| 55 | } |
| 56 | |
| 57 | Color ReferenceRect::get_border_color() const { |
| 58 | return border_color; |
| 59 | } |
| 60 | |
| 61 | void ReferenceRect::set_border_width(float p_width) { |
| 62 | float width_max = MAX(0.0, p_width); |
| 63 | if (border_width == width_max) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | border_width = width_max; |
| 68 | queue_redraw(); |
| 69 | } |
| 70 | |
| 71 | float ReferenceRect::get_border_width() const { |
| 72 | return border_width; |
| 73 | } |
| 74 | |
| 75 | void ReferenceRect::set_editor_only(const bool &p_enabled) { |
| 76 | if (editor_only == p_enabled) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | editor_only = p_enabled; |
| 81 | queue_redraw(); |
| 82 | } |
| 83 | |
| 84 | bool ReferenceRect::get_editor_only() const { |
| 85 | return editor_only; |
| 86 | } |
| 87 | |
| 88 | void ReferenceRect::_bind_methods() { |
| 89 | ClassDB::bind_method(D_METHOD("get_border_color" ), &ReferenceRect::get_border_color); |
| 90 | ClassDB::bind_method(D_METHOD("set_border_color" , "color" ), &ReferenceRect::set_border_color); |
| 91 | |
| 92 | ClassDB::bind_method(D_METHOD("get_border_width" ), &ReferenceRect::get_border_width); |
| 93 | ClassDB::bind_method(D_METHOD("set_border_width" , "width" ), &ReferenceRect::set_border_width); |
| 94 | |
| 95 | ClassDB::bind_method(D_METHOD("get_editor_only" ), &ReferenceRect::get_editor_only); |
| 96 | ClassDB::bind_method(D_METHOD("set_editor_only" , "enabled" ), &ReferenceRect::set_editor_only); |
| 97 | |
| 98 | ADD_PROPERTY(PropertyInfo(Variant::COLOR, "border_color" ), "set_border_color" , "get_border_color" ); |
| 99 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "border_width" , PROPERTY_HINT_RANGE, "0.0,5.0,0.1,or_greater,suffix:px" ), "set_border_width" , "get_border_width" ); |
| 100 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only" ), "set_editor_only" , "get_editor_only" ); |
| 101 | } |
| 102 | |