diff --git a/asloengine/animation.cpp b/asloengine/animation.cpp new file mode 100644 index 0000000..f6bfdaa --- /dev/null +++ b/asloengine/animation.cpp @@ -0,0 +1,94 @@ +#include "headers/animation.hpp" + +namespace asloengine +{ + + Animation::Animation(Function _function, float _start_value, float _end_value, float _duration) + { + + reset(_function, _start_value, _end_value, _duration); + + } + + void Animation::reset(Function _function, float _start_value, float _end_value, float _duration) + { + + function = _function; + start_value = _start_value; + current_value = _start_value; + end_value = _end_value; + time = 0; + duration = _duration; + + } + + float Animation::animate(float delta_time) + { + + time += delta_time; + + if (time > duration) + { + time = duration; + } + + switch (function) + { + + case LINEAR: + return calculate_linear(); + + case EASE_IN: + return calculate_ease_in(); + + case EASE_OUT: + return calculate_ease_out(); + + case EASE_IN_OUT: + return calculate_ease_in_out(); + + } + + return 0; + + } + + float Animation::calculate_linear() + { + + float value_difference = end_value - start_value; + float progress = time / duration; + + return start_value + value_difference * progress; + + } + + float Animation::calculate_ease_in() + { + + // TO-DO + return 0; + + } + + float Animation::calculate_ease_out() + { + + // TO-DO + return 0; + + } + + float Animation::calculate_ease_in_out() + { + + float value_difference = end_value - start_value; + float progress = time / duration; + + progress = pow(progress, 2) / (pow(progress, 2) + pow((1 - progress), 2)); + + return (start_value + value_difference * progress); + + } + +} \ No newline at end of file diff --git a/asloengine/builtin/headers/scene_default.hpp b/asloengine/builtin/headers/scene_default.hpp index 4664a3e..6d13b8a 100755 --- a/asloengine/builtin/headers/scene_default.hpp +++ b/asloengine/builtin/headers/scene_default.hpp @@ -8,6 +8,7 @@ #include "framerate_counter.hpp" #include "scroll_view.hpp" #include "grid_container.hpp" +#include "../../headers/animation.hpp" namespace asloengine { @@ -20,6 +21,7 @@ namespace asloengine sf::Texture button_texture; sf::Font button_font; + Animation *test_animation; void on_load() override; void on_update(float delta_time) override; diff --git a/asloengine/builtin/scene_default.cpp b/asloengine/builtin/scene_default.cpp index 3829182..6143a87 100755 --- a/asloengine/builtin/scene_default.cpp +++ b/asloengine/builtin/scene_default.cpp @@ -40,7 +40,7 @@ namespace asloengine toif->set_position(200, 300); InputField *if1 = new InputField("if_1", sf::Vector2f(200, 30), button_font, button_texture, 30, 20); - if1->set_position(100, 420); + if1->set_position(0, 420); if1->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus")); if1->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus")); //if1->signal_on_text_changed.connect_member(this, &SceneDefault::on_test); @@ -53,6 +53,8 @@ namespace asloengine //if2->set_position(20, 20); if2->signal_on_focus.connect_member(to1, &TextObject::set_text, sf::String("gained focus")); if2->signal_on_lost_focus.connect_member(to1, &TextObject::set_text, sf::String("lost focus")); + sf::Color *test_color = new sf::Color(192, 128, 96, 255); + if2->set_color(*test_color); /*sc1->objects.emplace_back(if2); @@ -73,10 +75,13 @@ namespace asloengine base_layer.emplace_back(container); + base_layer.emplace_back(if1); layers.emplace_back(base_layer); fixed_layers.emplace_back(gui_layer); + test_animation = new Animation(Animation::EASE_IN_OUT, 380, 200, 3); + } void SceneDefault::on_update(float delta_time) @@ -84,6 +89,10 @@ namespace asloengine //move_camera(sf::Vector2f(1, 2)); + float value = test_animation->animate(delta_time); + + layers[0][1]->set_position(value, 420); + } } \ No newline at end of file diff --git a/asloengine/core.cpp b/asloengine/core.cpp index c72e815..32ea6d4 100755 --- a/asloengine/core.cpp +++ b/asloengine/core.cpp @@ -42,6 +42,7 @@ namespace asloengine PROGRAM_INFO, sf::Style::Close); } + main_window->setPosition(_settings.window_position); main_window->setVerticalSyncEnabled(active_settings.vsync_enabled); main_window->setFramerateLimit(active_settings.max_framerate); diff --git a/asloengine/headers/animation.hpp b/asloengine/headers/animation.hpp new file mode 100644 index 0000000..c9eb0e1 --- /dev/null +++ b/asloengine/headers/animation.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include "helpers.hpp" + +namespace asloengine +{ + + class Animation + { + + public: + enum Function + { + LINEAR, EASE_IN, EASE_OUT, EASE_IN_OUT + }; + + Animation(Function _function, float _start_value, float _end_value, float _duration); + + void reset(Function _function, float _start_value, float _end_value, float _duration); + float animate(float delta_time); + + protected: + Function function; + float start_value; + float current_value; + float end_value; + float time; + float duration; + + float calculate_linear(); + float calculate_ease_in(); + float calculate_ease_out(); + float calculate_ease_in_out(); + + }; + +} \ No newline at end of file diff --git a/asloengine/headers/core.hpp b/asloengine/headers/core.hpp index 6104bc8..7fdc440 100755 --- a/asloengine/headers/core.hpp +++ b/asloengine/headers/core.hpp @@ -15,6 +15,7 @@ namespace asloengine uint resolution_y = 480; uint bit_depth = 24; uint max_framerate = 60; + sf::Vector2i window_position = sf::Vector2i(0, 0); bool vsync_enabled = true; bool fullscreen_enabled = false; }; diff --git a/asloengine/headers/spriteobject.hpp b/asloengine/headers/spriteobject.hpp index 38c42e5..257cce9 100755 --- a/asloengine/headers/spriteobject.hpp +++ b/asloengine/headers/spriteobject.hpp @@ -14,6 +14,8 @@ namespace asloengine virtual ~SpriteObject() override; void load_texture(sf::Texture& _texture); + void set_color(sf::Color& _color); + sf::Color get_color() const; virtual void draw() override; virtual void on_main_property_update() override; diff --git a/asloengine/spriteobject.cpp b/asloengine/spriteobject.cpp index 48c5fd7..68e3127 100755 --- a/asloengine/spriteobject.cpp +++ b/asloengine/spriteobject.cpp @@ -25,6 +25,20 @@ namespace asloengine } + void SpriteObject::set_color(sf::Color& _color) + { + + sprite.setColor(_color); + + } + + sf::Color SpriteObject::get_color() const + { + + return sprite.getColor(); + + } + void SpriteObject::draw() { diff --git a/log.txt b/log.txt index 5d3cb31..d5c158d 100644 --- a/log.txt +++ b/log.txt @@ -7,11 +7,13 @@ 6 - LOG: GameObject 'if_2' has been Started 7 - LOG: GameObject 'Login Button' has been Started 8 - LOG: GameObject 'Exit Button' has been Started -9 - LOG: Scene 'SceneDefault' has been Started -10 - LOG: GameObject 'Info Text' has been Destroyed -11 - LOG: GameObject 'if_2' has been Destroyed -12 - LOG: GameObject 'Login Button' has been Destroyed -13 - LOG: GameObject 'Exit Button' has been Destroyed -14 - LOG: GameObject 'cont1' has been Destroyed -15 - LOG: Scene 'SceneDefault' has been Destroyed -16 - LOG: END Main Game Loop +9 - LOG: GameObject 'if_1' has been Started +10 - LOG: Scene 'SceneDefault' has been Started +11 - LOG: GameObject 'Info Text' has been Destroyed +12 - LOG: GameObject 'if_2' has been Destroyed +13 - LOG: GameObject 'Login Button' has been Destroyed +14 - LOG: GameObject 'Exit Button' has been Destroyed +15 - LOG: GameObject 'cont1' has been Destroyed +16 - LOG: GameObject 'if_1' has been Destroyed +17 - LOG: Scene 'SceneDefault' has been Destroyed +18 - LOG: END Main Game Loop diff --git a/program.cpp b/program.cpp index d44cb54..5050c7b 100755 --- a/program.cpp +++ b/program.cpp @@ -9,6 +9,7 @@ int main() 480, // Resolution Y 24, // Bit Depth 60, // Max Framerate + sf::Vector2i(2000, 100), // Window Position true, // Vsync Enabled false // Fullscreen Enabled }; diff --git a/roadmap.txt b/roadmap.txt index 9a7077c..cf4c65b 100644 --- a/roadmap.txt +++ b/roadmap.txt @@ -1,2 +1,2 @@ -Color -Animations \ No newline at end of file +ease-in function for Animation +ease-out function for Animation \ No newline at end of file