Added AsloEngine 0.9.0 to Repository
This commit is contained in:
parent
d017dd84b3
commit
881e6c70f2
60 changed files with 2648 additions and 0 deletions
BIN
asloengine/builtin/assets/fonts/arcon_regular.otf
Executable file
BIN
asloengine/builtin/assets/fonts/arcon_regular.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_black.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_black.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_bold.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_bold.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_extra_bold.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_extra_bold.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_extra_light.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_extra_light.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_light.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_light.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_medium.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_medium.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_regular.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_regular.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_semi_bold.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_semi_bold.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/argentum_sans_thin.otf
Executable file
BIN
asloengine/builtin/assets/fonts/argentum_sans_thin.otf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/fonts/nasalization_regular.ttf
Executable file
BIN
asloengine/builtin/assets/fonts/nasalization_regular.ttf
Executable file
Binary file not shown.
BIN
asloengine/builtin/assets/textures/texture_default_button.png
Executable file
BIN
asloengine/builtin/assets/textures/texture_default_button.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
10
asloengine/builtin/builtin.hpp
Executable file
10
asloengine/builtin/builtin.hpp
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "headers/scene_default.hpp"
|
||||
|
||||
#include "headers/text_only_button.hpp"
|
||||
#include "headers/button.hpp"
|
||||
#include "headers/text_only_input_field.hpp"
|
||||
#include "headers/input_field.hpp"
|
||||
#include "headers/framerate_counter.hpp"
|
||||
#include "headers/scroll_view.hpp"
|
||||
49
asloengine/builtin/button.cpp
Executable file
49
asloengine/builtin/button.cpp
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#include "headers/button.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
Button::Button(sf::String _name, sf::String _text, sf::Font& _font, sf::Texture& _texture, uint _text_size)
|
||||
: text_vertical_offset(3.5), TextOnlyButton(_name, _text, _font, _text_size), SpriteObject(_name, _texture), GameObject(_name) {}
|
||||
|
||||
Button::~Button() {}
|
||||
|
||||
void Button::draw()
|
||||
{
|
||||
|
||||
SpriteObject::draw();
|
||||
TextOnlyButton::draw();
|
||||
|
||||
}
|
||||
|
||||
void Button::on_main_property_update()
|
||||
{
|
||||
|
||||
SpriteObject::on_main_property_update();
|
||||
|
||||
sf::FloatRect sprite_bounds = sprite.getLocalBounds();
|
||||
sf::FloatRect text_bounds = text->getLocalBounds();
|
||||
|
||||
sf::Vector2f offset(0, -text_bounds.height / text_vertical_offset);
|
||||
sf::Vector2f position_correction = calculate_child_position_centered(
|
||||
sprite_bounds, text_bounds, offset, scale, rotation
|
||||
);
|
||||
|
||||
text->setPosition(position.x + position_correction.x, position.y + position_correction.y);
|
||||
text->setScale(scale);
|
||||
text->setOrigin(origin);
|
||||
text->setRotation(rotation);
|
||||
|
||||
sprite_bounds = sprite.getGlobalBounds();
|
||||
update_clickable(sprite_bounds);
|
||||
|
||||
}
|
||||
|
||||
void Button::on_start()
|
||||
{
|
||||
|
||||
set_clickable(sprite.getGlobalBounds(), render_window);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
89
asloengine/builtin/framerate_counter.cpp
Executable file
89
asloengine/builtin/framerate_counter.cpp
Executable file
|
|
@ -0,0 +1,89 @@
|
|||
#include "headers/framerate_counter.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
FramerateCounter::FramerateCounter(sf::String _name, uint _update_interval)
|
||||
: GameObject(_name)
|
||||
{
|
||||
|
||||
set_update_interval(_update_interval);
|
||||
|
||||
prefix = "";
|
||||
postfix = "";
|
||||
|
||||
}
|
||||
|
||||
FramerateCounter::FramerateCounter(sf::String _name, std::shared_ptr<sf::Text> _target_text, uint _update_interval)
|
||||
: GameObject(_name), target_text(_target_text)
|
||||
{
|
||||
|
||||
set_update_interval(_update_interval);
|
||||
|
||||
prefix = "";
|
||||
postfix = "";
|
||||
|
||||
}
|
||||
|
||||
FramerateCounter::~FramerateCounter()
|
||||
{
|
||||
|
||||
if (values)
|
||||
{
|
||||
delete[] values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FramerateCounter::set_update_interval(uint _update_interval)
|
||||
{
|
||||
|
||||
if (_update_interval < 1)
|
||||
{
|
||||
_update_interval = 1;
|
||||
}
|
||||
|
||||
update_interval = _update_interval;
|
||||
|
||||
values = new float[_update_interval];
|
||||
for (uint i; i < _update_interval; i++)
|
||||
{
|
||||
values[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint FramerateCounter::get_update_interval() const
|
||||
{
|
||||
|
||||
return update_interval;
|
||||
|
||||
}
|
||||
|
||||
void FramerateCounter::on_start()
|
||||
{
|
||||
|
||||
counter = 0;
|
||||
|
||||
}
|
||||
|
||||
void FramerateCounter::on_update(float delta_time)
|
||||
{
|
||||
|
||||
if (counter == update_interval)
|
||||
{
|
||||
counter = 0;
|
||||
sf::String output_string = prefix + fmt::format("{:.1f}", (calculate_average(values, update_interval))) + postfix;
|
||||
if (target_text)
|
||||
{
|
||||
target_text->setString(output_string);
|
||||
}
|
||||
signal_on_counter_updated(output_string);
|
||||
}
|
||||
|
||||
values[counter] = (1 / delta_time);
|
||||
counter++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
124
asloengine/builtin/grid_container.cpp
Executable file
124
asloengine/builtin/grid_container.cpp
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
#include "headers/grid_container.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
GridContainer::GridContainer(sf::String _name, sf::Vector2u _grid_size, sf::Vector2f _cell_size)
|
||||
: grid_size(_grid_size), cell_size(_cell_size), GameObject(_name) {}
|
||||
|
||||
GridContainer::~GridContainer() {}
|
||||
|
||||
void GridContainer::update_positions()
|
||||
{
|
||||
|
||||
sf::Vector2f grid_anchor_position = get_position() - (get_origin() * to_vector2f(grid_size) * cell_size);
|
||||
|
||||
for (int x = 0; x < grid_size.x; x++)
|
||||
{
|
||||
for (int y = 0; y < grid_size.y; y++)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int x = 0;
|
||||
unsigned int y = 0;
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
|
||||
if (x >= grid_size.x)
|
||||
{
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y >= grid_size.y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sf::Vector2f tmp_vec = grid_anchor_position + sf::Vector2f(x * cell_size.x, y * cell_size.y);
|
||||
object->set_position(tmp_vec);
|
||||
|
||||
x++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::add_object(GameObject *object)
|
||||
{
|
||||
|
||||
objects.emplace_back(object);
|
||||
|
||||
update_positions();
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::remove_object(int index)
|
||||
{
|
||||
|
||||
objects.erase(objects.begin() + index);
|
||||
|
||||
update_positions();
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::draw()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_start()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->start(render_window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_update(float delta_time)
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->update(delta_time);
|
||||
if (!object->alive)
|
||||
{
|
||||
needs_clean = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::clean()
|
||||
{
|
||||
|
||||
for (int i = 0; i < objects.size(); i++)
|
||||
{
|
||||
objects.erase(objects.begin() + i);
|
||||
}
|
||||
|
||||
needs_clean = false;
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::on_destroy()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
24
asloengine/builtin/headers/button.hpp
Executable file
24
asloengine/builtin/headers/button.hpp
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "text_only_button.hpp"
|
||||
#include "../../headers/spriteobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class Button : public TextOnlyButton, public SpriteObject
|
||||
{
|
||||
|
||||
public:
|
||||
float text_vertical_offset;
|
||||
|
||||
Button(sf::String _name, sf::String _text, sf::Font& _font, sf::Texture& _texture, uint _text_size = 30);
|
||||
~Button();
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
virtual void on_start() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
34
asloengine/builtin/headers/framerate_counter.hpp
Executable file
34
asloengine/builtin/headers/framerate_counter.hpp
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../headers/gameobject.hpp"
|
||||
#include "fmt/format.h"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class FramerateCounter : public GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
std::string prefix;
|
||||
std::string postfix;
|
||||
std::shared_ptr<sf::Text> target_text;
|
||||
aslosignals::TypeSignal<sf::String> signal_on_counter_updated;
|
||||
|
||||
FramerateCounter(sf::String _name, uint _update_interval = 5);
|
||||
FramerateCounter(sf::String _name, std::shared_ptr<sf::Text> _target_text, uint _update_interval = 5);
|
||||
~FramerateCounter();
|
||||
|
||||
virtual void set_update_interval(uint _update_interval);
|
||||
virtual uint get_update_interval() const;
|
||||
virtual void on_start() override;
|
||||
virtual void on_update(float delta_time) override;
|
||||
|
||||
protected:
|
||||
uint counter;
|
||||
uint update_interval;
|
||||
float *values;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
32
asloengine/builtin/headers/grid_container.hpp
Executable file
32
asloengine/builtin/headers/grid_container.hpp
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../headers/gameobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class GridContainer : public GameObject
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<GameObject *> objects;
|
||||
bool needs_clean = false;
|
||||
sf::Vector2u grid_size;
|
||||
sf::Vector2f cell_size;
|
||||
|
||||
GridContainer(sf::String _name, sf::Vector2u _grid_size = sf::Vector2u(0, 0), sf::Vector2f _cell_size = sf::Vector2f(0, 0));
|
||||
virtual ~GridContainer() override;
|
||||
|
||||
virtual void update_positions();
|
||||
virtual void add_object(GameObject *object);
|
||||
virtual void remove_object(int index);
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_start() override;
|
||||
virtual void on_update(float delta_time) override;
|
||||
virtual void clean();
|
||||
virtual void on_destroy() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
24
asloengine/builtin/headers/input_field.hpp
Executable file
24
asloengine/builtin/headers/input_field.hpp
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "text_only_input_field.hpp"
|
||||
#include "../../headers/spriteobject.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class InputField : public TextOnlyInputField, public SpriteObject
|
||||
{
|
||||
|
||||
public:
|
||||
float text_vertical_offset;
|
||||
|
||||
InputField(sf::String _name, sf::Vector2f _size, sf::Font& _font, sf::Texture& _texture, uint _text_size = 30, int _max_length = 999, sf::String _default_text = "");
|
||||
~InputField();
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
virtual void on_start() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
29
asloengine/builtin/headers/scene_default.hpp
Executable file
29
asloengine/builtin/headers/scene_default.hpp
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../headers/scene.hpp"
|
||||
#include "text_only_button.hpp"
|
||||
#include "button.hpp"
|
||||
#include "text_only_input_field.hpp"
|
||||
#include "input_field.hpp"
|
||||
#include "framerate_counter.hpp"
|
||||
#include "scroll_view.hpp"
|
||||
#include "grid_container.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class SceneDefault : public Scene
|
||||
{
|
||||
|
||||
public:
|
||||
SceneDefault();
|
||||
|
||||
sf::Texture button_texture;
|
||||
sf::Font button_font;
|
||||
|
||||
void on_load() override;
|
||||
void on_update(float delta_time) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
38
asloengine/builtin/headers/scroll_view.hpp
Executable file
38
asloengine/builtin/headers/scroll_view.hpp
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../../headers/gameobject.hpp"
|
||||
#include "../../headers/clickable.hpp"
|
||||
#include "../../headers/mouse.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class ScrollView : public GameObject, public virtual Clickable
|
||||
{
|
||||
|
||||
public:
|
||||
std::vector<GameObject *> objects;
|
||||
bool needs_clean = false;
|
||||
sf::Vector2f size;
|
||||
float scroll_amount;
|
||||
float max_scroll_amount;
|
||||
float scroll_speed;
|
||||
|
||||
ScrollView(sf::String _name, sf::Vector2f _size, float _max_scroll_amount, float _scroll_speed = 25);
|
||||
virtual ~ScrollView() override;
|
||||
|
||||
virtual void set_rotation(float _rotation);
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_start() override;
|
||||
virtual void on_update(float delta_time) override;
|
||||
virtual void clean();
|
||||
virtual void on_destroy() override;
|
||||
|
||||
protected:
|
||||
virtual sf::View change_view();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
25
asloengine/builtin/headers/text_only_button.hpp
Executable file
25
asloengine/builtin/headers/text_only_button.hpp
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../headers/textobject.hpp"
|
||||
#include "../../headers/clickable.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class TextOnlyButton : public TextObject, public Clickable
|
||||
{
|
||||
|
||||
public:
|
||||
aslosignals::Signal signal_on_clicked;
|
||||
|
||||
TextOnlyButton(sf::String _name, sf::String _text, sf::Font& _font, uint _text_size = 30);
|
||||
virtual ~TextOnlyButton() override;
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
virtual void on_start() override;
|
||||
virtual void on_update(float delta_time) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
33
asloengine/builtin/headers/text_only_input_field.hpp
Executable file
33
asloengine/builtin/headers/text_only_input_field.hpp
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../headers/textobject.hpp"
|
||||
#include "../../headers/clickable.hpp"
|
||||
#include "../../headers/keyboard.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
class TextOnlyInputField : public TextObject, public Clickable
|
||||
{
|
||||
|
||||
public:
|
||||
sf::Vector2f size;
|
||||
int max_length;
|
||||
bool crop = true;
|
||||
bool editable = true;
|
||||
bool editing = false;
|
||||
aslosignals::TypeSignal<sf::String, sf::Uint32> signal_on_text_changed;
|
||||
aslosignals::Signal signal_on_focus;
|
||||
aslosignals::Signal signal_on_lost_focus;
|
||||
|
||||
TextOnlyInputField(sf::String _name, sf::Vector2f _size, sf::Font& _font, uint _text_size = 30, int _max_length = 999, sf::String _default_text = "");
|
||||
virtual ~TextOnlyInputField() override;
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void on_main_property_update() override;
|
||||
virtual void on_start() override;
|
||||
virtual void on_update(float delta_time) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
52
asloengine/builtin/input_field.cpp
Executable file
52
asloengine/builtin/input_field.cpp
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#include "headers/input_field.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
InputField::InputField(sf::String _name, sf::Vector2f _size, sf::Font& _font, sf::Texture& _texture, uint _text_size, int _max_length, sf::String _default_text)
|
||||
: text_vertical_offset(3.5), TextOnlyInputField(_name, _size, _font, _text_size, _max_length, _default_text), SpriteObject(_name, _texture), GameObject(_name) {}
|
||||
|
||||
InputField::~InputField() {}
|
||||
|
||||
void InputField::draw()
|
||||
{
|
||||
|
||||
SpriteObject::draw();
|
||||
//sf::FloatRect sprite_bounds = sprite.getLocalBounds();
|
||||
//sf::View default_view = crop ? set_crop(position.x + (sprite_bounds.width - size.x) / 2, position.y, size.x, size.y * 1.5) : render_window->getView();
|
||||
TextObject::draw();
|
||||
//render_window->setView(default_view);
|
||||
|
||||
}
|
||||
|
||||
void InputField::on_main_property_update()
|
||||
{
|
||||
|
||||
SpriteObject::on_main_property_update();
|
||||
|
||||
sf::FloatRect sprite_bounds = sprite.getLocalBounds();
|
||||
sf::FloatRect text_bounds = text->getLocalBounds();
|
||||
|
||||
sf::Vector2f offset(0, -text_bounds.height / text_vertical_offset);
|
||||
sf::Vector2f position_correction = calculate_child_position_centered(
|
||||
sprite_bounds, text_bounds, offset, scale, rotation
|
||||
);
|
||||
|
||||
text->setPosition(position.x + position_correction.x, position.y + position_correction.y);
|
||||
text->setScale(scale);
|
||||
text->setOrigin(origin);
|
||||
text->setRotation(rotation);
|
||||
|
||||
sprite_bounds = sprite.getGlobalBounds();
|
||||
update_clickable(sprite_bounds);
|
||||
|
||||
}
|
||||
|
||||
void InputField::on_start()
|
||||
{
|
||||
|
||||
set_clickable(sprite.getGlobalBounds(), render_window);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
86
asloengine/builtin/scene_default.cpp
Executable file
86
asloengine/builtin/scene_default.cpp
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
#include "headers/scene_default.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
SceneDefault::SceneDefault()
|
||||
: Scene("SceneDefault") {}
|
||||
|
||||
void SceneDefault::on_load()
|
||||
{
|
||||
|
||||
Layer base_layer;
|
||||
Layer gui_layer;
|
||||
|
||||
button_texture = sf::Texture();
|
||||
button_texture.loadFromFile("asloengine/builtin/assets/textures/texture_default_button.png");
|
||||
|
||||
button_font = sf::Font();
|
||||
button_font.loadFromFile("asloengine/builtin/assets/fonts/nasalization_regular.ttf");
|
||||
|
||||
Button *btn1 = new Button("Login Button", "Login", button_font, button_texture);
|
||||
//btn1->set_position(100, 50);
|
||||
|
||||
TextOnlyButton *tbtn1 = new TextOnlyButton("Exit Button", "Exit Game", button_font);
|
||||
//tbtn1->set_position(100, 125);
|
||||
|
||||
TextObject *to1 = new TextObject("Info Text", "Aslo Engine v0.9.0 by Aslan2142", button_font);
|
||||
//to1->set_position(630, 0);
|
||||
//to1->set_origin(1, 0);
|
||||
btn1->signal_on_clicked.connect_member(to1, &TextObject::set_text, sf::String("lulz"));
|
||||
|
||||
FramerateCounter *fctr1 = new FramerateCounter("fctr1", 5);
|
||||
fctr1->signal_on_counter_updated.connect_member(to1, &TextObject::set_text);
|
||||
fctr1->postfix = " FPS";
|
||||
|
||||
TextOnlyInputField *toif = new TextOnlyInputField("toif1", sf::Vector2f(100, 30), button_font, 30, 10, "input");
|
||||
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->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);
|
||||
|
||||
ScrollView *sc1 = new ScrollView("scroll1", sf::Vector2f(160, 160), 200);
|
||||
sc1->set_position(640, 480);
|
||||
sc1->set_origin(1, 1);
|
||||
|
||||
InputField *if2 = new InputField("if_2", sf::Vector2f(200, 30), button_font, button_texture, 30, 20);
|
||||
//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"));
|
||||
|
||||
/*sc1->objects.emplace_back(if2);
|
||||
|
||||
base_layer.emplace_back(fctr1);
|
||||
base_layer.emplace_back(btn1);
|
||||
base_layer.emplace_back(tbtn1);
|
||||
base_layer.emplace_back(to1);
|
||||
base_layer.emplace_back(if1);
|
||||
gui_layer.emplace_back(toif);
|
||||
gui_layer.emplace_back(sc1);*/
|
||||
|
||||
GridContainer *container = new GridContainer("cont1", sf::Vector2u(2, 2), sf::Vector2f(200, 150));
|
||||
container->set_position(100, 200);
|
||||
container->add_object(to1);
|
||||
container->add_object(if2);
|
||||
container->add_object(btn1);
|
||||
container->add_object(tbtn1);
|
||||
|
||||
|
||||
base_layer.emplace_back(container);
|
||||
|
||||
layers.emplace_back(base_layer);
|
||||
fixed_layers.emplace_back(gui_layer);
|
||||
|
||||
}
|
||||
|
||||
void SceneDefault::on_update(float delta_time)
|
||||
{
|
||||
|
||||
move_camera(sf::Vector2f(1, 2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
114
asloengine/builtin/scroll_view.cpp
Executable file
114
asloengine/builtin/scroll_view.cpp
Executable file
|
|
@ -0,0 +1,114 @@
|
|||
#include "headers/scroll_view.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
ScrollView::ScrollView(sf::String _name, sf::Vector2f _size, float _max_scroll_amount, float _scroll_speed)
|
||||
: size(_size), max_scroll_amount(_max_scroll_amount), scroll_speed(_scroll_speed), GameObject(_name), Clickable(sf::Mouse::Left) {}
|
||||
|
||||
ScrollView::~ScrollView() {}
|
||||
|
||||
void ScrollView::set_rotation(float _rotation) {}
|
||||
|
||||
void ScrollView::draw()
|
||||
{
|
||||
|
||||
sf::View default_view = change_view();
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->draw();
|
||||
}
|
||||
|
||||
render_window->setView(default_view);
|
||||
|
||||
}
|
||||
|
||||
void ScrollView::on_start()
|
||||
{
|
||||
|
||||
set_clickable(sf::FloatRect(get_position().x - origin.x * size.x, get_position().y - origin.y * size.y, size.x, size.y), render_window);
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->start(render_window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScrollView::on_update(float delta_time)
|
||||
{
|
||||
|
||||
if (is_mouse_in())
|
||||
{
|
||||
scroll_amount -= Mouse::mouse_wheel_delta * scroll_speed;
|
||||
scroll_amount = clamp(scroll_amount, 0, max_scroll_amount);
|
||||
}
|
||||
|
||||
sf::View default_view = change_view();
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->update(delta_time);
|
||||
if (!object->alive)
|
||||
{
|
||||
needs_clean = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needs_clean)
|
||||
{
|
||||
clean();
|
||||
}
|
||||
|
||||
render_window->setView(default_view);
|
||||
|
||||
}
|
||||
|
||||
void ScrollView::clean()
|
||||
{
|
||||
|
||||
for (int i = 0; i < objects.size(); i++)
|
||||
{
|
||||
objects.erase(objects.begin() + i);
|
||||
}
|
||||
|
||||
needs_clean = false;
|
||||
|
||||
}
|
||||
|
||||
void ScrollView::on_destroy()
|
||||
{
|
||||
|
||||
for (GameObject *const& object : objects)
|
||||
{
|
||||
object->destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sf::View ScrollView::change_view()
|
||||
{
|
||||
|
||||
sf::View default_view = render_window->getView();
|
||||
sf::View view = default_view;
|
||||
sf::Vector2u window_size = render_window->getSize();
|
||||
|
||||
sf::Vector2f camera_center = default_view.getCenter() - default_view.getSize() / 2;
|
||||
|
||||
view.reset(sf::FloatRect(0, 0 + scroll_amount, size.x, size.y));
|
||||
|
||||
view.setViewport(sf::FloatRect(
|
||||
(position.x - camera_center.x - size.x * origin.x) / window_size.x,
|
||||
(position.y - camera_center.y - size.y * origin.y) / window_size.y,
|
||||
size.x / window_size.x,
|
||||
size.y / window_size.y
|
||||
));
|
||||
|
||||
render_window->setView(view);
|
||||
|
||||
return default_view;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
44
asloengine/builtin/text_only_button.cpp
Executable file
44
asloengine/builtin/text_only_button.cpp
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#include "headers/text_only_button.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
TextOnlyButton::TextOnlyButton(sf::String _name, sf::String _text, sf::Font& _font, uint _text_size)
|
||||
: TextObject(_name, _text, _font, _text_size), GameObject(_name), Clickable(sf::Mouse::Left) {}
|
||||
|
||||
TextOnlyButton::~TextOnlyButton() {}
|
||||
|
||||
void TextOnlyButton::draw()
|
||||
{
|
||||
|
||||
TextObject::draw();
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyButton::on_main_property_update()
|
||||
{
|
||||
|
||||
TextObject::on_main_property_update();
|
||||
|
||||
update_clickable(text->getGlobalBounds());
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyButton::on_start()
|
||||
{
|
||||
|
||||
set_clickable(text->getGlobalBounds(), render_window);
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyButton::on_update(float delta_time)
|
||||
{
|
||||
|
||||
if (clicked_press_and_release())
|
||||
{
|
||||
signal_on_clicked();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
78
asloengine/builtin/text_only_input_field.cpp
Executable file
78
asloengine/builtin/text_only_input_field.cpp
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
#include "headers/text_only_input_field.hpp"
|
||||
|
||||
namespace asloengine
|
||||
{
|
||||
|
||||
TextOnlyInputField::TextOnlyInputField(sf::String _name, sf::Vector2f _size, sf::Font& _font, uint _text_size, int _max_length, sf::String _default_text)
|
||||
: size(_size), max_length(_max_length), TextObject(_name, _default_text, _font, _text_size), GameObject(_name), Clickable(sf::Mouse::Left) {}
|
||||
|
||||
TextOnlyInputField::~TextOnlyInputField() {}
|
||||
|
||||
void TextOnlyInputField::draw()
|
||||
{
|
||||
|
||||
//sf::View default_view = crop ? set_crop(position.x, position.y, size.x, size.y * 1.5) : render_window->getView();
|
||||
TextObject::draw();
|
||||
//render_window->setView(default_view);
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyInputField::on_main_property_update()
|
||||
{
|
||||
|
||||
TextObject::on_main_property_update();
|
||||
|
||||
update_clickable(sf::FloatRect(position, size));
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyInputField::on_start()
|
||||
{
|
||||
|
||||
set_clickable(sf::FloatRect(position, size), render_window);
|
||||
|
||||
}
|
||||
|
||||
void TextOnlyInputField::on_update(float delta_time)
|
||||
{
|
||||
|
||||
if (editable)
|
||||
{
|
||||
|
||||
if (get_click_action() == ClickAction::Pressed)
|
||||
{
|
||||
if (is_mouse_in())
|
||||
{
|
||||
if (!editing)
|
||||
{
|
||||
signal_on_focus();
|
||||
}
|
||||
editing = true;
|
||||
} else {
|
||||
if (editing)
|
||||
{
|
||||
signal_on_lost_focus();
|
||||
}
|
||||
editing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (editing && Keyboard::entered_text != 0)
|
||||
{
|
||||
if (Keyboard::entered_text == 8 || Keyboard::entered_text == 127)
|
||||
{
|
||||
sf::String tmp_text = get_text();
|
||||
set_text(tmp_text.substring(0, tmp_text.getSize() - 1));
|
||||
signal_on_text_changed(get_text(), Keyboard::entered_text);
|
||||
} else if (get_text_length() < max_length) {
|
||||
set_text(get_text() + sf::String(Keyboard::entered_text));
|
||||
signal_on_text_changed(get_text(), Keyboard::entered_text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue