2018-08-29 20:38:13 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* animation_bezier_editor.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
#ifndef ANIMATION_BEZIER_EDITOR_H
|
|
|
|
#define ANIMATION_BEZIER_EDITOR_H
|
|
|
|
|
|
|
|
#include "animation_track_editor.h"
|
2022-08-22 10:45:30 +00:00
|
|
|
#include "core/templates/hashfuncs.h"
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2022-01-13 16:19:15 +00:00
|
|
|
class ViewPanner;
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
class AnimationBezierTrackEdit : public Control {
|
2019-03-19 18:35:57 +00:00
|
|
|
GDCLASS(AnimationBezierTrackEdit, Control);
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MENU_KEY_INSERT,
|
|
|
|
MENU_KEY_DUPLICATE,
|
2024-02-14 23:44:40 +00:00
|
|
|
MENU_KEY_CUT,
|
2024-02-06 17:57:10 +00:00
|
|
|
MENU_KEY_COPY,
|
|
|
|
MENU_KEY_PASTE,
|
2021-09-03 14:02:53 +00:00
|
|
|
MENU_KEY_DELETE,
|
|
|
|
MENU_KEY_SET_HANDLE_FREE,
|
2022-08-22 10:45:30 +00:00
|
|
|
MENU_KEY_SET_HANDLE_LINEAR,
|
2021-09-03 14:02:53 +00:00
|
|
|
MENU_KEY_SET_HANDLE_BALANCED,
|
2022-08-22 10:45:30 +00:00
|
|
|
MENU_KEY_SET_HANDLE_MIRRORED,
|
|
|
|
MENU_KEY_SET_HANDLE_AUTO_BALANCED,
|
|
|
|
MENU_KEY_SET_HANDLE_AUTO_MIRRORED,
|
2018-06-07 15:46:14 +00:00
|
|
|
};
|
|
|
|
|
2021-08-26 12:44:01 +00:00
|
|
|
AnimationTimelineEdit *timeline = nullptr;
|
|
|
|
Node *root = nullptr;
|
2022-04-04 13:06:57 +00:00
|
|
|
Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
|
2022-08-22 10:45:30 +00:00
|
|
|
real_t play_position_pos = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Ref<Animation> animation;
|
2022-05-04 00:17:08 +00:00
|
|
|
bool read_only = false;
|
2022-05-02 14:28:25 +00:00
|
|
|
int selected_track = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Vector<Rect2> view_rects;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> bezier_icon;
|
|
|
|
Ref<Texture2D> bezier_handle_icon;
|
|
|
|
Ref<Texture2D> selected_icon;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
RBMap<int, Rect2> subtracks;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2021-11-09 15:05:28 +00:00
|
|
|
enum {
|
|
|
|
REMOVE_ICON,
|
|
|
|
LOCK_ICON,
|
|
|
|
SOLO_ICON,
|
|
|
|
VISIBILITY_ICON
|
|
|
|
};
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
RBMap<int, RBMap<int, Rect2>> subtrack_icons;
|
2022-05-19 15:00:06 +00:00
|
|
|
HashSet<int> locked_tracks;
|
|
|
|
HashSet<int> hidden_tracks;
|
2021-11-09 15:05:28 +00:00
|
|
|
int solo_track = -1;
|
|
|
|
bool is_filtered = false;
|
|
|
|
|
2023-10-22 12:51:12 +00:00
|
|
|
float track_v_scroll = 0;
|
|
|
|
float track_v_scroll_max = 0;
|
|
|
|
|
|
|
|
float timeline_v_scroll = 0;
|
|
|
|
float timeline_v_zoom = 1;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2021-08-26 12:44:01 +00:00
|
|
|
PopupMenu *menu = nullptr;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
void _zoom_changed();
|
|
|
|
|
2021-11-09 15:05:28 +00:00
|
|
|
void _update_locked_tracks_after(int p_track);
|
|
|
|
void _update_hidden_tracks_after(int p_track);
|
|
|
|
|
2021-08-22 15:37:22 +00:00
|
|
|
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
2018-06-07 15:46:14 +00:00
|
|
|
void _menu_selected(int p_index);
|
|
|
|
|
|
|
|
void _play_position_draw();
|
2024-01-11 14:58:32 +00:00
|
|
|
bool _is_track_displayed(int p_track_index);
|
|
|
|
bool _is_track_curves_displayed(int p_track_index);
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Vector2 insert_at_pos;
|
|
|
|
|
2021-11-09 15:05:28 +00:00
|
|
|
typedef Pair<int, int> IntPair;
|
|
|
|
|
2021-08-26 12:44:01 +00:00
|
|
|
bool moving_selection_attempt = false;
|
2024-02-18 13:04:26 +00:00
|
|
|
float moving_selection_mouse_begin_x = 0.0;
|
2021-11-09 15:05:28 +00:00
|
|
|
IntPair select_single_attempt;
|
2021-08-26 12:44:01 +00:00
|
|
|
bool moving_selection = false;
|
2022-05-02 14:28:25 +00:00
|
|
|
int moving_selection_from_key = 0;
|
|
|
|
int moving_selection_from_track = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Vector2 moving_selection_offset;
|
|
|
|
|
2021-08-26 12:44:01 +00:00
|
|
|
bool box_selecting_attempt = false;
|
|
|
|
bool box_selecting = false;
|
|
|
|
bool box_selecting_add = false;
|
2018-06-07 15:46:14 +00:00
|
|
|
Vector2 box_selection_from;
|
|
|
|
Vector2 box_selection_to;
|
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
int moving_handle = 0; //0 no move -1 or +1 out, 2 both (drawing only)
|
2021-08-26 12:44:01 +00:00
|
|
|
int moving_handle_key = 0;
|
2021-11-09 15:05:28 +00:00
|
|
|
int moving_handle_track = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
Vector2 moving_handle_left;
|
|
|
|
Vector2 moving_handle_right;
|
2022-05-02 14:28:25 +00:00
|
|
|
int moving_handle_mode = 0; // value from Animation::HandleMode
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
struct PairHasher {
|
|
|
|
static _FORCE_INLINE_ uint32_t hash(const Pair<int, int> &p_value) {
|
|
|
|
int32_t hash = 23;
|
|
|
|
hash = hash * 31 * hash_one_uint64(p_value.first);
|
|
|
|
hash = hash * 31 * hash_one_uint64(p_value.second);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_lefts;
|
|
|
|
HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_rights;
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
void _clear_selection();
|
|
|
|
void _clear_selection_for_anim(const Ref<Animation> &p_anim);
|
2022-08-22 10:45:30 +00:00
|
|
|
void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos);
|
2024-02-06 17:57:10 +00:00
|
|
|
bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);
|
2022-08-22 10:45:30 +00:00
|
|
|
void _change_selected_keys_handle_mode(Animation::HandleMode p_mode, bool p_auto = false);
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Vector2 menu_insert_key;
|
|
|
|
|
|
|
|
struct AnimMoveRestore {
|
2020-11-24 09:12:55 +00:00
|
|
|
int track = 0;
|
2022-08-22 10:45:30 +00:00
|
|
|
double time = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
Variant key;
|
2022-08-22 10:45:30 +00:00
|
|
|
real_t transition = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
};
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
AnimationTrackEditor *editor = nullptr;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
struct EditPoint {
|
|
|
|
Rect2 point_rect;
|
|
|
|
Rect2 in_rect;
|
|
|
|
Rect2 out_rect;
|
2022-05-02 14:28:25 +00:00
|
|
|
int track = 0;
|
|
|
|
int key = 0;
|
2018-06-07 15:46:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<EditPoint> edit_points;
|
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
struct PairCompare {
|
2021-11-09 15:05:28 +00:00
|
|
|
bool operator()(const IntPair &lh, const IntPair &rh) {
|
|
|
|
if (lh.first == rh.first) {
|
|
|
|
return lh.second < rh.second;
|
|
|
|
} else {
|
|
|
|
return lh.first < rh.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
typedef RBSet<IntPair, PairCompare> SelectionSet;
|
2021-11-09 15:05:28 +00:00
|
|
|
|
|
|
|
SelectionSet selection;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2022-01-13 16:19:15 +00:00
|
|
|
Ref<ViewPanner> panner;
|
2023-01-19 16:50:51 +00:00
|
|
|
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
|
|
|
|
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);
|
|
|
|
void _draw_track(int p_track, const Color &p_color);
|
|
|
|
|
|
|
|
float _bezier_h_to_pixel(float p_h);
|
2024-01-11 14:58:32 +00:00
|
|
|
void _zoom_vertically(real_t p_minimum_value, real_t p_maximum_value);
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2024-02-06 17:57:10 +00:00
|
|
|
static Array make_default_bezier_key(float p_value);
|
|
|
|
static float get_bezier_key_value(Array p_bezier_key_array);
|
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual String get_tooltip(const Point2 &p_pos) const override;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
Ref<Animation> get_animation() const;
|
|
|
|
|
2022-05-04 00:17:08 +00:00
|
|
|
void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Size2 get_minimum_size() const override;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
|
|
|
void set_timeline(AnimationTimelineEdit *p_timeline);
|
|
|
|
void set_editor(AnimationTrackEditor *p_editor);
|
|
|
|
void set_root(Node *p_root);
|
2021-11-09 15:05:28 +00:00
|
|
|
void set_filtered(bool p_filtered);
|
2024-01-11 14:58:32 +00:00
|
|
|
void auto_fit_vertically();
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
void set_play_position(real_t p_pos);
|
2018-06-07 15:46:14 +00:00
|
|
|
void update_play_position();
|
|
|
|
|
2024-02-16 15:48:19 +00:00
|
|
|
void duplicate_selected_keys(real_t p_ofs, bool p_ofs_valid);
|
2024-02-14 23:44:40 +00:00
|
|
|
void copy_selected_keys(bool p_cut);
|
2024-02-16 15:48:19 +00:00
|
|
|
void paste_keys(real_t p_ofs, bool p_ofs_valid);
|
2018-06-07 15:46:14 +00:00
|
|
|
void delete_selection();
|
|
|
|
|
2022-08-22 10:45:30 +00:00
|
|
|
void _bezier_track_insert_key(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);
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
AnimationBezierTrackEdit();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ANIMATION_BEZIER_EDITOR_H
|