Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/marker_2d.cpp
9902 views
1
/**************************************************************************/
2
/* marker_2d.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 "marker_2d.h"
32
33
void Marker2D::_draw_cross() {
34
const real_t extents = get_gizmo_extents();
35
36
PackedVector2Array points = {
37
Point2(+extents, 0),
38
Point2(),
39
Point2(),
40
Point2(-extents, 0),
41
Point2(0, +extents),
42
Point2(),
43
Point2(),
44
Point2(0, -extents),
45
};
46
47
// Use the axis color which is brighter for the positive axis.
48
// Use a darkened axis color for the negative axis.
49
// This makes it possible to see in which direction the Marker3D node is rotated
50
// (which can be important depending on how it's used).
51
// Axis colors are taken from `axis_x_color` and `axis_y_color` (defined in `editor/themes/editor_theme_manager.cpp`).
52
const Color color_x = Color(0.96, 0.20, 0.32);
53
const Color color_y = Color(0.53, 0.84, 0.01);
54
PackedColorArray colors = {
55
color_x,
56
color_x.darkened(0.5),
57
color_y,
58
color_y.darkened(0.5),
59
};
60
61
draw_multiline_colors(points, colors);
62
}
63
64
#ifdef DEBUG_ENABLED
65
Rect2 Marker2D::_edit_get_rect() const {
66
real_t extents = get_gizmo_extents();
67
return Rect2(Point2(-extents, -extents), Size2(extents * 2, extents * 2));
68
}
69
70
bool Marker2D::_edit_use_rect() const {
71
return false;
72
}
73
#endif // DEBUG_ENABLED
74
75
void Marker2D::_notification(int p_what) {
76
switch (p_what) {
77
case NOTIFICATION_ENTER_TREE: {
78
queue_redraw();
79
} break;
80
81
case NOTIFICATION_DRAW: {
82
if (!is_inside_tree()) {
83
break;
84
}
85
if (Engine::get_singleton()->is_editor_hint()) {
86
_draw_cross();
87
}
88
} break;
89
}
90
}
91
92
void Marker2D::set_gizmo_extents(real_t p_extents) {
93
gizmo_extents = p_extents;
94
queue_redraw();
95
}
96
97
real_t Marker2D::get_gizmo_extents() const {
98
return gizmo_extents;
99
}
100
101
void Marker2D::_bind_methods() {
102
ClassDB::bind_method(D_METHOD("set_gizmo_extents", "extents"), &Marker2D::set_gizmo_extents);
103
ClassDB::bind_method(D_METHOD("get_gizmo_extents"), &Marker2D::get_gizmo_extents);
104
105
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gizmo_extents", PROPERTY_HINT_RANGE, "0,1000,0.1,or_greater,suffix:px"), "set_gizmo_extents", "get_gizmo_extents");
106
}
107
108
Marker2D::Marker2D() {
109
set_hide_clip_children(true);
110
}
111
112