Path: blob/master/editor/animation/animation_bezier_editor.h
9896 views
/**************************************************************************/1/* animation_bezier_editor.h */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#pragma once3132#include "animation_track_editor.h"33#include "core/templates/hashfuncs.h"3435class ViewPanner;3637class AnimationBezierTrackEdit : public Control {38GDCLASS(AnimationBezierTrackEdit, Control);3940enum {41MENU_KEY_INSERT,42MENU_KEY_DUPLICATE,43MENU_KEY_CUT,44MENU_KEY_COPY,45MENU_KEY_PASTE,46MENU_KEY_DELETE,47MENU_KEY_SET_HANDLE_FREE,48MENU_KEY_SET_HANDLE_LINEAR,49MENU_KEY_SET_HANDLE_BALANCED,50MENU_KEY_SET_HANDLE_MIRRORED,51MENU_KEY_SET_HANDLE_AUTO_BALANCED,52MENU_KEY_SET_HANDLE_AUTO_MIRRORED,53};5455AnimationTimelineEdit *timeline = nullptr;56Node *root = nullptr;57Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster58real_t play_position_pos = 0;5960Ref<Animation> animation;61bool read_only = false;62int selected_track = 0;6364Vector<Rect2> view_rects;6566Ref<Texture2D> bezier_icon;67Ref<Texture2D> bezier_handle_icon;68Ref<Texture2D> selected_icon;6970RBMap<int, Rect2> subtracks;7172enum {73REMOVE_ICON,74LOCK_ICON,75SOLO_ICON,76VISIBILITY_ICON77};7879RBMap<int, RBMap<int, Rect2>> subtrack_icons;80HashSet<int> locked_tracks;81HashSet<int> hidden_tracks;82int solo_track = -1;83bool is_filtered = false;8485float track_v_scroll = 0;86float track_v_scroll_max = 0;8788float timeline_v_scroll = 0;89float timeline_v_zoom = 1;9091PopupMenu *menu = nullptr;9293void _zoom_changed();9495void _update_locked_tracks_after(int p_track);96void _update_hidden_tracks_after(int p_track);9798virtual void gui_input(const Ref<InputEvent> &p_event) override;99void _menu_selected(int p_index);100101void _play_position_draw();102bool _is_track_displayed(int p_track_index);103bool _is_track_curves_displayed(int p_track_index);104105Vector2 insert_at_pos;106107typedef Pair<int, int> IntPair;108109bool moving_selection_attempt = false;110bool moving_inserted_key = false;111Point2 moving_selection_mouse_begin;112IntPair select_single_attempt;113bool moving_selection = false;114int moving_selection_from_key = 0;115int moving_selection_from_track = 0;116117Vector2 moving_selection_offset;118119bool box_selecting_attempt = false;120bool box_selecting = false;121bool box_selecting_add = false;122Vector2 box_selection_from;123Vector2 box_selection_to;124125Rect2 selection_rect;126Rect2 selection_handles_rect;127128bool scaling_selection = false;129Vector2i scaling_selection_handles;130Vector2 scaling_selection_scale = Vector2(1, 1);131Vector2 scaling_selection_offset;132Point2 scaling_selection_pivot;133134int moving_handle = 0; //0 no move -1 or +1 out, 2 both (drawing only)135int moving_handle_key = 0;136int moving_handle_track = 0;137Vector2 moving_handle_left;138Vector2 moving_handle_right;139int moving_handle_mode = 0; // value from Animation::HandleMode140141struct PairHasher {142static _FORCE_INLINE_ uint32_t hash(const Pair<int, int> &p_value) {143int32_t hash = 23;144hash = hash * 31 * hash_one_uint64(p_value.first);145hash = hash * 31 * hash_one_uint64(p_value.second);146return hash;147}148};149150HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_lefts;151HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_rights;152153void _clear_selection();154void _clear_selection_for_anim(const Ref<Animation> &p_anim);155void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single);156bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);157void _change_selected_keys_handle_mode(Animation::HandleMode p_mode, bool p_auto = false);158159Vector2 menu_insert_key;160161struct AnimMoveRestore {162int track = 0;163double time = 0;164Variant key;165real_t transition = 0;166};167168AnimationTrackEditor *editor = nullptr;169170struct EditPoint {171Rect2 point_rect;172Rect2 in_rect;173Rect2 out_rect;174int track = 0;175int key = 0;176};177178Vector<EditPoint> edit_points;179180struct PairCompare {181bool operator()(const IntPair &lh, const IntPair &rh) {182if (lh.first == rh.first) {183return lh.second < rh.second;184} else {185return lh.first < rh.first;186}187}188};189190typedef RBSet<IntPair, PairCompare> SelectionSet;191192SelectionSet selection;193194Ref<ViewPanner> panner;195void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);196void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);197198void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);199void _draw_track(int p_track, const Color &p_color);200201float _bezier_h_to_pixel(float p_h);202void _zoom_vertically(real_t p_minimum_value, real_t p_maximum_value);203204protected:205static void _bind_methods();206void _notification(int p_what);207208public:209static float get_bezier_key_value(Array p_bezier_key_array);210211virtual String get_tooltip(const Point2 &p_pos) const override;212213Ref<Animation> get_animation() const;214215void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);216virtual Size2 get_minimum_size() const override;217virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;218219void set_timeline(AnimationTimelineEdit *p_timeline);220void set_editor(AnimationTrackEditor *p_editor);221void set_root(Node *p_root);222void set_filtered(bool p_filtered);223void auto_fit_vertically();224225void set_play_position(real_t p_pos);226void update_play_position();227228void duplicate_selected_keys(real_t p_ofs, bool p_ofs_valid);229void copy_selected_keys(bool p_cut);230void paste_keys(real_t p_ofs, bool p_ofs_valid);231void delete_selection();232233void _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);234235AnimationBezierTrackEdit();236};237238239