Debian Codegraph @

editor/animation/animation_bezier_editor.h

raw symbols SCIP
1 /**************************************************************************/
2 /* animation_bezier_editor.h */
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 #pragma once
32
33 #include "animation_track_editor.h"
34 #include "core/templates/hashfuncs.h"
35
36 class ViewPanner;
37
38 class AnimationBezierTrackEdit : public Control {
39 GDCLASS(AnimationBezierTrackEdit, Control);
40
41 enum {
42 MENU_KEY_INSERT,
43 MENU_KEY_DUPLICATE,
44 MENU_KEY_CUT,
45 MENU_KEY_COPY,
46 MENU_KEY_PASTE,
47 MENU_KEY_DELETE,
48 MENU_KEY_SET_HANDLE_FREE,
49 MENU_KEY_SET_HANDLE_LINEAR,
50 MENU_KEY_SET_HANDLE_BALANCED,
51 MENU_KEY_SET_HANDLE_MIRRORED,
52 MENU_KEY_SET_HANDLE_AUTO_BALANCED,
53 MENU_KEY_SET_HANDLE_AUTO_MIRRORED,
54 };
55
56 AnimationTimelineEdit *timeline = nullptr;
57 Node *root = nullptr;
58 Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
59 real_t play_position_pos = 0;
60
61 Ref<Animation> animation;
62 bool read_only = false;
63 int selected_track = -1;
64
65 Ref<Texture2D> bezier_icon;
66 Ref<Texture2D> bezier_handle_icon;
67 Ref<Texture2D> selected_icon;
68
69 RBMap<int, Rect2> subtracks;
70
71 enum {
72 REMOVE_ICON,
73 LOCK_ICON,
74 SOLO_ICON,
75 VISIBILITY_ICON
76 };
77
78 RBMap<String, RBMap<int, Rect2>> node_icons;
79 RBMap<int, RBMap<int, Rect2>> subtrack_icons;
80 HashSet<int> locked_tracks;
81 HashSet<int> hidden_tracks;
82 bool is_filtered = false;
83
84 float track_v_scroll = 0;
85 float track_v_scroll_max = 0;
86
87 float timeline_v_scroll = 0;
88 float timeline_v_zoom = 1;
89
90 PopupMenu *menu = nullptr;
91
92 void _zoom_changed();
93
94 void _update_locked_tracks_after(int p_track);
95 void _update_hidden_tracks_after(int p_track);
96 bool _lock_track(int p_track);
97 bool _unlock_track(int p_track);
98 bool _hide_track(int p_track);
99 bool _show_track(int p_track);
100
101 virtual void gui_input(const Ref<InputEvent> &p_event) override;
102 void _menu_selected(int p_index);
103
104 void _play_position_draw();
105 bool _is_track_displayed(int p_track_index);
106 bool _is_track_curves_displayed(int p_track_index);
107
108 typedef Pair<int, int> IntPair;
109
110 bool moving_selection_attempt = false;
111 bool moving_inserted_key = false;
112 Point2 moving_selection_mouse_begin;
113 IntPair select_single_attempt;
114 bool moving_selection = false;
115 int moving_selection_from_key = 0;
116 int moving_selection_from_track = 0;
117
118 Vector2 moving_selection_offset;
119
120 bool box_selecting_attempt = false;
121 bool box_selecting = false;
122 bool box_selecting_add = false;
123 Vector2 box_selection_from;
124 Vector2 box_selection_to;
125
126 Rect2 selection_rect;
127 Rect2 selection_handles_rect;
128
129 bool scaling_selection = false;
130 Vector2i scaling_selection_handles;
131 Vector2 scaling_selection_scale = Vector2(1, 1);
132 Vector2 scaling_selection_offset;
133 Point2 scaling_selection_pivot;
134
135 int moving_handle = 0; //0 no move -1 or +1 out, 2 both (drawing only)
136 int moving_handle_key = 0;
137 int moving_handle_track = 0;
138 Vector2 moving_handle_left;
139 Vector2 moving_handle_right;
140
141 struct PairHasher {
142 static _FORCE_INLINE_ uint32_t hash(const Pair<int, int> &p_value) {
143 int32_t hash = 23;
144 hash = hash * 31 * hash_one_uint64(p_value.first);
145 hash = hash * 31 * hash_one_uint64(p_value.second);
146 return hash;
147 }
148 };
149
150 HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_lefts;
151 HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_rights;
152
153 void _clear_selection();
154 void _clear_selection_for_anim(const Ref<Animation> &p_anim);
155 void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single);
156 bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);
157 void _change_selected_keys_handle_mode(Animation::HandleMode p_mode, bool p_auto = false);
158
159 Vector2 menu_insert_key;
160
161 struct AnimMoveRestore {
162 int track = 0;
163 double time = 0;
164 Variant key;
165 real_t transition = 0;
166 };
167
168 AnimationTrackEditor *editor = nullptr;
169
170 struct EditPoint {
171 Rect2 point_rect;
172 Rect2 in_rect;
173 Rect2 out_rect;
174 int track = 0;
175 int key = 0;
176 };
177
178 Vector<EditPoint> edit_points;
179
180 struct PairCompare {
181 bool operator()(const IntPair &lh, const IntPair &rh) {
182 if (lh.first == rh.first) {
183 return lh.second < rh.second;
184 } else {
185 return lh.first < rh.first;
186 }
187 }
188 };
189
190 typedef RBSet<IntPair, PairCompare> SelectionSet;
191
192 SelectionSet selection;
193
194 Ref<ViewPanner> panner;
195 void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
196 void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
197
198 void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);
199 void _draw_track(int p_track, const Color &p_color);
200
201 float _bezier_h_to_pixel(float p_h);
202 void _zoom_vertically(real_t p_minimum_value, real_t p_maximum_value);
203
204 protected:
205 static void _bind_methods();
206 void _notification(int p_what);
207
208 public:
209 static float get_bezier_key_value(Array p_bezier_key_array);
210
211 virtual String get_tooltip(const Point2 &p_pos) const override;
212
213 Ref<Animation> get_animation() const;
214
215 void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
216 virtual Size2 get_minimum_size() const override;
217 virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
218
219 void set_timeline(AnimationTimelineEdit *p_timeline);
220 void set_editor(AnimationTrackEditor *p_editor);
221 void set_root(Node *p_root);
222 void set_filtered(bool p_filtered);
223 void auto_fit_vertically();
224
225 void set_play_position(real_t p_pos);
226 void update_play_position();
227
228 void duplicate_selected_keys(real_t p_ofs, bool p_ofs_valid);
229 void copy_selected_keys(bool p_cut);
230 void paste_keys(real_t p_ofs, bool p_ofs_valid);
231 void delete_selection();
232
233 void _bezier_track_insert_key_at_anim(const Ref<Animation> &p_anim, int p_track, double p_time, real_t p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle, const Animation::HandleMode p_handle_mode, Animation::HandleSetMode p_handle_set_mode = Animation::HANDLE_SET_MODE_NONE);
234
235 AnimationBezierTrackEdit();
236 };