2014-08-20 06:01:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* tween.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 14:50:53 +01:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-08-20 06:01:41 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef TWEEN_H
|
|
|
|
#define TWEEN_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
|
|
|
|
|
|
|
|
|
|
|
class Tween : public Node {
|
|
|
|
|
|
|
|
OBJ_TYPE( Tween, Node );
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum TweenProcessMode {
|
|
|
|
TWEEN_PROCESS_FIXED,
|
|
|
|
TWEEN_PROCESS_IDLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TransitionType {
|
|
|
|
TRANS_LINEAR,
|
|
|
|
TRANS_SINE,
|
|
|
|
TRANS_QUINT,
|
|
|
|
TRANS_QUART,
|
|
|
|
TRANS_QUAD,
|
|
|
|
TRANS_EXPO,
|
|
|
|
TRANS_ELASTIC,
|
|
|
|
TRANS_CUBIC,
|
|
|
|
TRANS_CIRC,
|
|
|
|
TRANS_BOUNCE,
|
|
|
|
TRANS_BACK,
|
2014-12-19 10:13:20 +01:00
|
|
|
|
|
|
|
TRANS_COUNT,
|
2014-08-20 06:01:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EaseType {
|
|
|
|
EASE_IN,
|
|
|
|
EASE_OUT,
|
|
|
|
EASE_IN_OUT,
|
2014-12-19 10:13:20 +01:00
|
|
|
EASE_OUT_IN,
|
|
|
|
|
|
|
|
EASE_COUNT,
|
2014-08-20 06:01:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2014-08-22 05:24:53 +02:00
|
|
|
enum InterpolateType {
|
|
|
|
|
|
|
|
INTER_PROPERTY,
|
|
|
|
INTER_METHOD,
|
2014-08-25 07:36:56 +02:00
|
|
|
FOLLOW_PROPERTY,
|
|
|
|
FOLLOW_METHOD,
|
|
|
|
TARGETING_PROPERTY,
|
|
|
|
TARGETING_METHOD,
|
2014-08-22 05:24:53 +02:00
|
|
|
INTER_CALLBACK,
|
|
|
|
};
|
2014-08-20 06:01:41 +02:00
|
|
|
|
|
|
|
struct InterpolateData {
|
|
|
|
bool active;
|
2014-08-22 05:24:53 +02:00
|
|
|
InterpolateType type;
|
2014-08-21 09:34:16 +02:00
|
|
|
bool finish;
|
2015-01-07 12:46:01 +01:00
|
|
|
bool call_deferred;
|
2014-08-20 06:01:41 +02:00
|
|
|
real_t elapsed;
|
2014-12-19 10:13:20 +01:00
|
|
|
ObjectID id;
|
2014-08-25 07:36:56 +02:00
|
|
|
StringName key;
|
2014-08-20 06:01:41 +02:00
|
|
|
Variant initial_val;
|
|
|
|
Variant delta_val;
|
|
|
|
Variant final_val;
|
2014-12-19 10:13:20 +01:00
|
|
|
ObjectID target_id;
|
2014-08-25 07:36:56 +02:00
|
|
|
StringName target_key;
|
2014-08-20 06:01:41 +02:00
|
|
|
real_t times_in_sec;
|
|
|
|
TransitionType trans_type;
|
|
|
|
EaseType ease_type;
|
2014-08-21 09:34:16 +02:00
|
|
|
real_t delay;
|
2015-01-07 12:46:01 +01:00
|
|
|
int args;
|
|
|
|
Variant arg[5];
|
2014-08-20 06:01:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
String autoplay;
|
|
|
|
TweenProcessMode tween_process_mode;
|
|
|
|
bool processing;
|
|
|
|
bool active;
|
2014-08-20 10:39:28 +02:00
|
|
|
bool repeat;
|
2014-08-20 06:01:41 +02:00
|
|
|
float speed_scale;
|
2014-12-19 10:13:20 +01:00
|
|
|
mutable int pending_update;
|
2014-08-20 06:01:41 +02:00
|
|
|
|
|
|
|
List<InterpolateData> interpolates;
|
|
|
|
|
2015-05-05 05:12:17 +02:00
|
|
|
struct PendingCommand {
|
|
|
|
StringName key;
|
|
|
|
int args;
|
|
|
|
Variant arg[10];
|
|
|
|
};
|
|
|
|
List<PendingCommand> pending_commands;
|
|
|
|
|
|
|
|
void _add_pending_command(StringName p_key
|
|
|
|
,const Variant& p_arg1=Variant()
|
|
|
|
,const Variant& p_arg2=Variant()
|
|
|
|
,const Variant& p_arg3=Variant()
|
|
|
|
,const Variant& p_arg4=Variant()
|
|
|
|
,const Variant& p_arg5=Variant()
|
|
|
|
,const Variant& p_arg6=Variant()
|
|
|
|
,const Variant& p_arg7=Variant()
|
|
|
|
,const Variant& p_arg8=Variant()
|
|
|
|
,const Variant& p_arg9=Variant()
|
|
|
|
,const Variant& p_arg10=Variant()
|
|
|
|
);
|
|
|
|
void _process_pending_commands();
|
|
|
|
|
2014-08-20 06:01:41 +02:00
|
|
|
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
|
|
|
|
static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
|
|
|
|
|
|
|
|
real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
|
2014-08-25 07:36:56 +02:00
|
|
|
Variant& _get_delta_val(InterpolateData& p_data);
|
|
|
|
Variant& _get_initial_val(InterpolateData& p_data);
|
2014-08-20 06:01:41 +02:00
|
|
|
Variant _run_equation(InterpolateData& p_data);
|
2014-08-25 07:36:56 +02:00
|
|
|
bool _calc_delta_val(const Variant& p_initial_val, const Variant& p_final_val, Variant& p_delta_val);
|
2014-08-20 06:01:41 +02:00
|
|
|
bool _apply_tween_value(InterpolateData& p_data, Variant& value);
|
|
|
|
|
|
|
|
void _tween_process(float p_delta);
|
|
|
|
void _set_process(bool p_process,bool p_force=false);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
bool _set(const StringName& p_name, const Variant& p_value);
|
|
|
|
bool _get(const StringName& p_name,Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool is_active() const;
|
|
|
|
void set_active(bool p_active);
|
|
|
|
|
2014-08-20 10:39:28 +02:00
|
|
|
bool is_repeat() const;
|
|
|
|
void set_repeat(bool p_repeat);
|
|
|
|
|
2014-08-20 06:01:41 +02:00
|
|
|
void set_tween_process_mode(TweenProcessMode p_mode);
|
|
|
|
TweenProcessMode get_tween_process_mode() const;
|
|
|
|
|
|
|
|
void set_speed(float p_speed);
|
|
|
|
float get_speed() const;
|
|
|
|
|
|
|
|
bool start();
|
2014-12-19 10:13:20 +01:00
|
|
|
bool reset(Object *p_node, String p_key);
|
2014-08-20 06:01:41 +02:00
|
|
|
bool reset_all();
|
2014-12-19 10:13:20 +01:00
|
|
|
bool stop(Object *p_node, String p_key);
|
2014-08-20 06:01:41 +02:00
|
|
|
bool stop_all();
|
2014-12-19 10:13:20 +01:00
|
|
|
bool resume(Object *p_node, String p_key);
|
2014-08-20 06:01:41 +02:00
|
|
|
bool resume_all();
|
2014-12-19 10:13:20 +01:00
|
|
|
bool remove(Object *p_node, String p_key);
|
2014-08-20 06:19:22 +02:00
|
|
|
bool remove_all();
|
2014-08-20 06:01:41 +02:00
|
|
|
|
2014-08-20 10:39:28 +02:00
|
|
|
bool seek(real_t p_time);
|
2014-08-22 08:25:41 +02:00
|
|
|
real_t tell() const;
|
|
|
|
real_t get_runtime() const;
|
2014-08-20 10:39:28 +02:00
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool interpolate_property(Object *p_node
|
2014-08-20 06:01:41 +02:00
|
|
|
, String p_property
|
|
|
|
, Variant p_initial_val
|
|
|
|
, Variant p_final_val
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
2014-08-21 09:34:16 +02:00
|
|
|
, real_t p_delay = 0
|
2014-08-20 06:01:41 +02:00
|
|
|
);
|
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool interpolate_method(Object *p_node
|
2014-08-20 06:01:41 +02:00
|
|
|
, String p_method
|
|
|
|
, Variant p_initial_val
|
|
|
|
, Variant p_final_val
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
2014-08-21 09:34:16 +02:00
|
|
|
, real_t p_delay = 0
|
2014-08-20 06:01:41 +02:00
|
|
|
);
|
|
|
|
|
2015-01-07 12:46:01 +01:00
|
|
|
bool interpolate_callback(Object *p_object
|
2014-08-22 05:24:53 +02:00
|
|
|
, real_t p_times_in_sec
|
2014-12-19 10:13:20 +01:00
|
|
|
, String p_callback
|
2015-01-07 12:46:01 +01:00
|
|
|
, VARIANT_ARG_DECLARE
|
|
|
|
);
|
|
|
|
|
|
|
|
bool interpolate_deferred_callback(Object *p_object
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, String p_callback
|
|
|
|
, VARIANT_ARG_DECLARE
|
2014-08-25 07:36:56 +02:00
|
|
|
);
|
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool follow_property(Object *p_node
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_property
|
|
|
|
, Variant p_initial_val
|
2014-12-19 10:13:20 +01:00
|
|
|
, Object *p_target
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_target_property
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
|
|
|
, real_t p_delay = 0
|
|
|
|
);
|
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool follow_method(Object *p_node
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_method
|
|
|
|
, Variant p_initial_val
|
2014-12-19 10:13:20 +01:00
|
|
|
, Object *p_target
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_target_method
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
|
|
|
, real_t p_delay = 0
|
|
|
|
);
|
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool targeting_property(Object *p_node
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_property
|
2014-12-19 10:13:20 +01:00
|
|
|
, Object *p_initial
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_initial_property
|
|
|
|
, Variant p_final_val
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
|
|
|
, real_t p_delay = 0
|
|
|
|
);
|
|
|
|
|
2014-12-19 10:13:20 +01:00
|
|
|
bool targeting_method(Object *p_node
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_method
|
2014-12-19 10:13:20 +01:00
|
|
|
, Object *p_initial
|
2014-08-25 07:36:56 +02:00
|
|
|
, String p_initial_method
|
|
|
|
, Variant p_final_val
|
|
|
|
, real_t p_times_in_sec
|
|
|
|
, TransitionType p_trans_type
|
|
|
|
, EaseType p_ease_type
|
|
|
|
, real_t p_delay = 0
|
2014-08-22 05:24:53 +02:00
|
|
|
);
|
|
|
|
|
2014-08-20 06:01:41 +02:00
|
|
|
Tween();
|
|
|
|
~Tween();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST( Tween::TweenProcessMode );
|
|
|
|
VARIANT_ENUM_CAST( Tween::TransitionType );
|
|
|
|
VARIANT_ENUM_CAST( Tween::EaseType );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|