21#ifndef GF_ACTIVITIES_H
22#define GF_ACTIVITIES_H
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
64 m_tween.setOrigin(origin);
73 return m_tween.getOrigin();
82 m_tween.setTarget(target);
91 return m_tween.getTarget();
100 m_tween.setDuration(duration);
109 return m_tween.getDuration();
147 m_tween.setOrigin(origin);
157 return m_tween.getOrigin();
166 m_tween.setTarget(target);
176 return m_tween.getTarget();
185 m_tween.setDuration(duration);
194 return m_tween.getDuration();
233 m_tween.setOrigin(origin);
242 return m_tween.getOrigin();
251 m_tween.setTarget(target);
260 return m_tween.getTarget();
269 m_tween.setDuration(duration);
278 return m_tween.getDuration();
314 m_tween.setOrigin(origin);
323 return m_tween.getOrigin();
332 m_tween.setTarget(target);
341 return m_tween.getTarget();
350 m_tween.setDuration(duration);
359 return m_tween.getDuration();
387 std::function<void()> m_callback;
441 std::size_t m_current;
442 std::vector<Ref<Activity>> m_activities;
509 std::vector<Ref<Activity>> m_activities;
555 return MoveToActivity(origin, target, position, duration, easing);
592#ifndef DOXYGEN_SHOULD_SKIP_THIS
595 template<
typename Tuple, std::
size_t I>
596 Activity& activityTupleGet(Tuple& tuple) {
597 return std::get<I>(tuple);
600 template<
typename Tuple,
typename Indices = std::make_index_sequence<std::tuple_size_v<Tuple>>>
601 struct ActivityTupleGetters;
603 template<
typename Tuple, std::size_t ... Indices>
604 struct ActivityTupleGetters<Tuple, std::index_sequence<Indices...>>
606 using Getter = Activity& (*)(Tuple&);
607 static inline constexpr Getter table[std::tuple_size_v<Tuple>] = { &activityTupleGet<Tuple, Indices>... };
610 template<
typename Tuple>
611 Activity& activityTupleGetIth(Tuple& tuple, std::size_t i) {
612 assert(i < std::tuple_size_v<Tuple>);
613 return ActivityTupleGetters<Tuple>::table[i](tuple);
621 template<
typename... Args>
631 , m_activities(std::forward<Args>(activities)...)
636 if (m_current ==
sizeof... (Args)) {
640 Activity& currentActivity = activityTupleGetIth(m_activities, m_current);
641 auto status = currentActivity.
run(time);
653 for (std::size_t i = 0; i <
sizeof ... (Args); ++i) {
654 activityTupleGetIth(m_activities, i).restart();
659 std::size_t m_current;
660 std::tuple<Args...> m_activities;
668 template<
typename... Args>
676 template<
typename Other>
686 : m_activity(std::move(activity))
693 if (m_count > 0 && m_repeat == m_count) {
697 auto status = m_activity.run(time);
700 m_activity.restart();
709 m_activity.restart();
724 template<
typename Other>
732 template<
typename... Args>
744 , m_activities(std::forward<Args>(activities)...)
753 std::size_t finished = 0;
755 for (std::size_t i = 0; i <
sizeof ... (Args); ++i) {
756 auto status = activityTupleGetIth(m_activities, i).run(time);
771 if (finished ==
sizeof ... (Args)) {
783 for (std::size_t i = 0; i <
sizeof ... (Args); ++i) {
784 activityTupleGetIth(m_activities, i).restart();
792 std::tuple<Args...> m_activities;
800 template<
typename... Args>
810 template<
typename... Args>
825 template<
typename Other>
827 : m_activity(std::make_unique<
Other>(std::move(other)))
832 return m_activity->run(time);
836 m_activity->restart();
840 std::unique_ptr<Activity> m_activity;
845#ifndef DOXYGEN_SHOULD_SKIP_THIS
A game activity.
Definition: Activity.h:62
virtual ActivityStatus run(Time time)=0
Run the activity.
An activity for calling a function once.
Definition: Activities.h:374
CallbackActivity(std::function< void()> callback)
Constructor.
ActivityStatus run(Time time) override
Run the activity.
void restart() override
Restart the activity.
An activity for a change of color.
Definition: Activities.h:295
Color4f getOrigin() const noexcept
Get the origin of the activity.
Definition: Activities.h:322
void setDuration(Time duration)
Change the duration of the activity.
Definition: Activities.h:349
ColorActivity(Color4f origin, Color4f target, Color4f &color, Time duration, Easing easing=Ease::linear)
Constructor.
void restart() override
Restart the activity.
void setTarget(Color4f target)
Change the target of the activity.
Definition: Activities.h:331
Time getDuration() const noexcept
Get the duration of the activity.
Definition: Activities.h:358
ActivityStatus run(Time time) override
Run the activity.
void setOrigin(Color4f origin)
Change the origin of the activity.
Definition: Activities.h:313
Color4f getTarget() const noexcept
Get the target of the activity.
Definition: Activities.h:340
An activity to wait for a predefined duration.
Definition: Activities.h:396
ActivityStatus run(Time time) override
Run the activity.
DelayActivity(Time duration)
Constructor.
void restart() override
Restart the activity.
static float linear(float t)
Linear easing.
An activity for a change of position.
Definition: Activities.h:214
Vector2f getTarget() const noexcept
Get the target of the activity.
Definition: Activities.h:259
MoveToActivity(Vector2f origin, Vector2f target, Vector2f &position, Time duration, Easing easing=Ease::linear)
Constructor.
void setDuration(Time duration)
Change the duration of the activity.
Definition: Activities.h:268
void setTarget(Vector2f target)
Change the target of the activity.
Definition: Activities.h:250
void restart() override
Restart the activity.
Time getDuration() const noexcept
Get the duration of the activity.
Definition: Activities.h:277
ActivityStatus run(Time time) override
Run the activity.
Vector2f getOrigin() const noexcept
Get the origin of the activity.
Definition: Activities.h:241
void setOrigin(Vector2f origin)
Change the origin of the activity.
Definition: Activities.h:232
An activity to run several activities in parallel.
Definition: Activities.h:481
void addActivity(Activity &activity)
Add an activity to the set.
void clear()
Remove all the activities.
ActivityStatus run(Time time) override
Run the activity.
ParallelActivity(ActivityFinish finish=ActivityFinish::Any)
Constructor.
void restart() override
Restart the activity.
A reference wrapper.
Definition: Ref.h:39
An activity to run an activity several times.
Definition: Activities.h:450
RepeatActivity(Activity &activity, int repeat=0)
Constructor.
ActivityStatus run(Time time) override
Run the activity.
void restart() override
Restart the activity.
An activity for a change of angle.
Definition: Activities.h:128
float getTarget() const noexcept
Get the target of the activity.
Definition: Activities.h:175
void setOrigin(float origin)
Change the origin of the activity.
Definition: Activities.h:146
RotateToActivity(float origin, float target, float &angle, Time duration, Easing easing=Ease::linear)
Constructor.
float getOrigin() const noexcept
Get the origin of the activity.
Definition: Activities.h:156
void setTarget(float target)
Change the target of the activity.
Definition: Activities.h:165
void restart() override
Restart the activity.
Time getDuration() const noexcept
Get the duration of the activity.
Definition: Activities.h:193
void setDuration(Time duration)
Change the duration of the activity.
Definition: Activities.h:184
ActivityStatus run(Time time) override
Run the activity.
An activity to run several activities sequentially.
Definition: Activities.h:418
SequenceActivity()
Constructor.
void restart() override
Restart the activity.
void addActivity(Activity &activity)
Add an activity to the sequence.
ActivityStatus run(Time time) override
Run the activity.
void clear()
Remove all the activities.
Represents a time value.
Definition: Time.h:65
An activity for a simple float value.
Definition: Activities.h:45
ValueActivity(float origin, float target, float &value, Time duration, Easing easing=Ease::linear)
Constructor.
void setOrigin(float origin)
Change the origin of the activity.
Definition: Activities.h:63
void setDuration(Time duration)
Change the duration of the activity.
Definition: Activities.h:99
float getTarget() const noexcept
Get the target of the activity.
Definition: Activities.h:90
Time getDuration() const noexcept
Get the duration of the activity.
Definition: Activities.h:108
void setTarget(float target)
Change the target of the activity.
Definition: Activities.h:81
float getOrigin() const noexcept
Get the origin of the activity.
Definition: Activities.h:72
void restart() override
Restart the activity.
ActivityStatus run(Time time) override
Run the activity.
An activity that can hold any other activity.
Definition: Activities.h:818
AnyActivity(Other other)
Constructor.
Definition: Activities.h:826
ActivityStatus run(Time time) override
Run the activity.
Definition: Activities.h:831
void restart() override
Restart the activity.
Definition: Activities.h:835
A gf::ParallelActivity that holds its activities.
Definition: Activities.h:733
void restart() override
Restart the activity.
Definition: Activities.h:780
ParallelActivityEx(ActivityFinish finish, Args... activities)
Constructor.
Definition: Activities.h:741
ActivityStatus run(Time time) override
Run the activity.
Definition: Activities.h:748
A gf::RepeatActivity that holds its activity.
Definition: Activities.h:677
ActivityStatus run(Time time) override
Run the activity.
Definition: Activities.h:692
RepeatActivityEx(Other activity, int repeat)
Constructor.
Definition: Activities.h:685
void restart() override
Restart the activity.
Definition: Activities.h:707
A gf::SequenceActivity that holds its activities.
Definition: Activities.h:622
ActivityStatus run(Time time) override
Run the activity.
Definition: Activities.h:635
SequenceActivityEx(Args... activities)
Constructor.
Definition: Activities.h:629
void restart() override
Restart the activity.
Definition: Activities.h:650
float(*)(float) Easing
An easing function.
Definition: Easings.h:48
ActivityStatus
Status of an activity.
Definition: Activity.h:38
@ Running
The activity is still running.
@ Finished
The activity is finished.
GF_CORE_API float angle(Direction direction)
Get an angle from a direction.
constexpr AllType All
Constant to represent "all".
Definition: Types.h:61
constexpr AnyType Any
Constant to represent "any".
Definition: Types.h:77
@ Other
Another unknown button (may happen with touchpads)
ColorActivity color(Color4f origin, Color4f target, Color4f &color, Time duration, Easing easing=Ease::linear)
Create a gf::ColorActivity.
Definition: Activities.h:568
ParallelActivityEx< Args... > parallelAll(Args... activities)
Create a gf::ParallelActivityEx.
Definition: Activities.h:811
RepeatActivityEx< Other > repeat(Other activity, int repeat=0)
Definition: Activities.h:725
MoveToActivity moveTo(Vector2f origin, Vector2f target, Vector2f &position, Time duration, Easing easing=Ease::linear)
Create a gf::MoveToActivity.
Definition: Activities.h:554
RotateToActivity rotateTo(float origin, float target, float &angle, Time duration, Easing easing=Ease::linear)
Create a gf::RotateToActivity.
Definition: Activities.h:540
DelayActivity delay(Time duration)
Create a gf::DelayActivity.
Definition: Activities.h:588
ParallelActivityEx< Args... > parallelAny(Args... activities)
Create a gf::ParallelActivityEx.
Definition: Activities.h:801
SequenceActivityEx< Args... > sequence(Args... activities)
Definition: Activities.h:669
ValueActivity value(float origin, float target, float &value, Time duration, Easing easing=Ease::linear)
Create a gf::ValueActivity.
Definition: Activities.h:526
CallbackActivity call(std::function< void()> callback)
Create a gf::CallbackActivity.
Definition: Activities.h:578
The namespace for gf classes.
ActivityFinish
The type of finish for the activity.
Definition: Activities.h:472
@ All
If all of the activities ends.
@ Any
If any of the activities ends.
A 4D vector.
Definition: Vector.h:852