/**************************************************************************/1/* marker_2d.cpp */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#include "marker_2d.h"3132void Marker2D::_draw_cross() {33const real_t extents = get_gizmo_extents();3435PackedVector2Array points = {36Point2(+extents, 0),37Point2(),38Point2(),39Point2(-extents, 0),40Point2(0, +extents),41Point2(),42Point2(),43Point2(0, -extents),44};4546// Use the axis color which is brighter for the positive axis.47// Use a darkened axis color for the negative axis.48// This makes it possible to see in which direction the Marker3D node is rotated49// (which can be important depending on how it's used).50// Axis colors are taken from `axis_x_color` and `axis_y_color` (defined in `editor/themes/editor_theme_manager.cpp`).51const Color color_x = Color(0.96, 0.20, 0.32);52const Color color_y = Color(0.53, 0.84, 0.01);53PackedColorArray colors = {54color_x,55color_x.darkened(0.5),56color_y,57color_y.darkened(0.5),58};5960draw_multiline_colors(points, colors);61}6263#ifdef DEBUG_ENABLED64Rect2 Marker2D::_edit_get_rect() const {65real_t extents = get_gizmo_extents();66return Rect2(Point2(-extents, -extents), Size2(extents * 2, extents * 2));67}6869bool Marker2D::_edit_use_rect() const {70return false;71}72#endif // DEBUG_ENABLED7374void Marker2D::_notification(int p_what) {75switch (p_what) {76case NOTIFICATION_ENTER_TREE: {77queue_redraw();78} break;7980case NOTIFICATION_DRAW: {81if (!is_inside_tree()) {82break;83}84if (Engine::get_singleton()->is_editor_hint()) {85_draw_cross();86}87} break;88}89}9091void Marker2D::set_gizmo_extents(real_t p_extents) {92gizmo_extents = p_extents;93queue_redraw();94}9596real_t Marker2D::get_gizmo_extents() const {97return gizmo_extents;98}99100void Marker2D::_bind_methods() {101ClassDB::bind_method(D_METHOD("set_gizmo_extents", "extents"), &Marker2D::set_gizmo_extents);102ClassDB::bind_method(D_METHOD("get_gizmo_extents"), &Marker2D::get_gizmo_extents);103104ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gizmo_extents", PROPERTY_HINT_RANGE, "0,1000,0.1,or_greater,suffix:px"), "set_gizmo_extents", "get_gizmo_extents");105}106107Marker2D::Marker2D() {108set_hide_clip_children(true);109}110111112