Path: blob/master/editor/animation/animation_bezier_editor.h
21733 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 = -1;6364Ref<Texture2D> bezier_icon;65Ref<Texture2D> bezier_handle_icon;66Ref<Texture2D> selected_icon;6768RBMap<int, Rect2> subtracks;6970enum {71REMOVE_ICON,72LOCK_ICON,73SOLO_ICON,74VISIBILITY_ICON75};7677RBMap<String, RBMap<int, Rect2>> node_icons;78RBMap<int, RBMap<int, Rect2>> subtrack_icons;79HashSet<int> locked_tracks;80HashSet<int> hidden_tracks;81bool is_filtered = false;8283float track_v_scroll = 0;84float track_v_scroll_max = 0;8586float timeline_v_scroll = 0;87float timeline_v_zoom = 1;8889PopupMenu *menu = nullptr;9091void _zoom_changed();9293void _update_locked_tracks_after(int p_track);94void _update_hidden_tracks_after(int p_track);95bool _lock_track(int p_track);96bool _unlock_track(int p_track);97bool _hide_track(int p_track);98bool _show_track(int p_track);99100virtual void gui_input(const Ref<InputEvent> &p_event) override;101void _menu_selected(int p_index);102103void _play_position_draw();104bool _is_track_displayed(int p_track_index);105bool _is_track_curves_displayed(int p_track_index);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;139140struct PairHasher {141static _FORCE_INLINE_ uint32_t hash(const Pair<int, int> &p_value) {142int32_t hash = 23;143hash = hash * 31 * hash_one_uint64(p_value.first);144hash = hash * 31 * hash_one_uint64(p_value.second);145return hash;146}147};148149HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_lefts;150HashMap<Pair<int, int>, Vector2, PairHasher> additional_moving_handle_rights;151152void _clear_selection();153void _clear_selection_for_anim(const Ref<Animation> &p_anim);154void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single);155bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);156void _change_selected_keys_handle_mode(Animation::HandleMode p_mode, bool p_auto = false);157158Vector2 menu_insert_key;159160struct AnimMoveRestore {161int track = 0;162double time = 0;163Variant key;164real_t transition = 0;165};166167AnimationTrackEditor *editor = nullptr;168169struct EditPoint {170Rect2 point_rect;171Rect2 in_rect;172Rect2 out_rect;173int track = 0;174int key = 0;175};176177Vector<EditPoint> edit_points;178179struct PairCompare {180bool operator()(const IntPair &lh, const IntPair &rh) {181if (lh.first == rh.first) {182return lh.second < rh.second;183} else {184return lh.first < rh.first;185}186}187};188189typedef RBSet<IntPair, PairCompare> SelectionSet;190191SelectionSet selection;192193Ref<ViewPanner> panner;194void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);195void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);196197void _draw_line_clipped(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, int p_clip_left, int p_clip_right);198void _draw_track(int p_track, const Color &p_color);199200float _bezier_h_to_pixel(float p_h);201void _zoom_vertically(real_t p_minimum_value, real_t p_maximum_value);202203protected:204static void _bind_methods();205void _notification(int p_what);206207public:208static float get_bezier_key_value(Array p_bezier_key_array);209210virtual String get_tooltip(const Point2 &p_pos) const override;211212Ref<Animation> get_animation() const;213214void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);215virtual Size2 get_minimum_size() const override;216virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;217218void set_timeline(AnimationTimelineEdit *p_timeline);219void set_editor(AnimationTrackEditor *p_editor);220void set_root(Node *p_root);221void set_filtered(bool p_filtered);222void auto_fit_vertically();223224void set_play_position(real_t p_pos);225void update_play_position();226227void duplicate_selected_keys(real_t p_ofs, bool p_ofs_valid);228void copy_selected_keys(bool p_cut);229void paste_keys(real_t p_ofs, bool p_ofs_valid);230void delete_selection();231232void _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);233234AnimationBezierTrackEdit();235};236237238