Skip to content

Commit

Permalink
feat(sfml): add window_resized event tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 7, 2019
1 parent 8cfe31a commit 71d4507
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion modules/sfml/antara/gaming/sfml/graphic.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
******************************************************************************/

#include <iostream>
#include <entt/entity/helper.hpp>
#include "antara/gaming/ecs/component.position.hpp"
#include "antara/gaming/ecs/component.layer.hpp"
#include "antara/gaming/sfml/graphic.system.hpp"
Expand All @@ -24,6 +24,7 @@ namespace antara::gaming::sfml
{
graphic_system::graphic_system(entt::registry &registry) noexcept : system(registry)
{
this->dispatcher_.sink<entt::tag<"window_resized"_hs>>().connect<&graphic_system::on_window_resized_event>(*this);
refresh_render_texture();
}

Expand Down Expand Up @@ -138,4 +139,9 @@ namespace antara::gaming::sfml
{
draw_all_layers(std::make_index_sequence<ecs::component::max_layer>{});
}

void graphic_system::on_window_resized_event(const entt::tag<"window_resized"_hs> &) noexcept
{
refresh_render_texture();
}
}
3 changes: 3 additions & 0 deletions modules/sfml/antara/gaming/sfml/graphic.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <entt/entity/helper.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/Sprite.hpp>
Expand Down Expand Up @@ -49,6 +50,8 @@ namespace antara::gaming::sfml
//! Public getter
sf::RenderWindow &get_window() noexcept;

void on_window_resized_event(const entt::tag<"window_resized"_hs> &evt) noexcept;

private:
config::game_cfg &game_cfg_{entity_registry_.ctx<config::game_cfg>()};
config::window_cfg &window_cfg_{game_cfg_.win_cfg};
Expand Down
3 changes: 2 additions & 1 deletion modules/sfml/antara/gaming/sfml/input.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
******************************************************************************/

#include <SFML/Window/Event.hpp>
#include <entt/entity/helper.hpp>
#include "antara/gaming/config/config.game.hpp"
#include "antara/gaming/event/quit.game.hpp"
#include "antara/gaming/event/mouse.button.pressed.hpp"
Expand Down Expand Up @@ -44,7 +45,7 @@ namespace antara::gaming::sfml
auto &window_component = this->entity_registry_.ctx<config::game_cfg>().win_cfg;
window_component.width = evt.size.width;
window_component.height = evt.size.height;
this->dispatcher_.trigger<event::window_resized>();
this->dispatcher_.trigger<entt::tag<"window_resized"_hs>>();
}
break;
case sf::Event::LostFocus:
Expand Down

0 comments on commit 71d4507

Please sign in to comment.