diff --git a/include/editor/GUI/item.cpp b/include/editor/GUI/item.cpp new file mode 100644 index 00000000..6ec3b680 --- /dev/null +++ b/include/editor/GUI/item.cpp @@ -0,0 +1,3 @@ +#include "item.hpp" + +float GUI::Item::SCALE = 1.0f; diff --git a/include/editor/GUI/item.hpp b/include/editor/GUI/item.hpp index b7267db0..a72395d4 100644 --- a/include/editor/GUI/item.hpp +++ b/include/editor/GUI/item.hpp @@ -34,7 +34,6 @@ struct Observer struct Item { - static constexpr float SCALE = 2.0f; // Attributes sf::Vector2f size; sf::Vector2f offset; @@ -228,7 +227,7 @@ struct Item void draw(sf::RenderTarget& target, const sf::Drawable& drawable, const sf::RenderStates& states) { sf::RenderStates default_states = states; - default_states.transform.scale(2.0f, 2.0f); + default_states.transform.scale(Conf::GUI_SCALE, Conf::GUI_SCALE); default_states.transform.translate(offset); target.draw(drawable, default_states); } diff --git a/include/editor/GUI/scene.hpp b/include/editor/GUI/scene.hpp index cc65ec12..ca812ae4 100644 --- a/include/editor/GUI/scene.hpp +++ b/include/editor/GUI/scene.hpp @@ -22,7 +22,7 @@ struct Scene Scene(sf::RenderWindow& window_) : window(window_) , event_manager(window_, false) - , root(toVector2f(window_.getSize()) / Item::SCALE) + , root(toVector2f(window_.getSize()) / Conf::GUI_SCALE) { initializeEventsCallbacks(); } @@ -49,7 +49,7 @@ struct Scene { const auto size = window.getSize(); const sf::Vector2f new_size{to(size.x), to(size.y)}; - root.setSize(new_size / Item::SCALE); + root.setSize(new_size / Conf::GUI_SCALE); window.setView(sf::View(new_size * 0.5f, new_size)); onSizeChange(); } @@ -73,7 +73,7 @@ struct Scene void dispatchClick(const sf::Event& e) { - root.defaultOnClick(mouse_position / Item::SCALE, e.mouseButton.button); + root.defaultOnClick(mouse_position / Conf::GUI_SCALE, e.mouseButton.button); } void unclick(const sf::Event& e) @@ -105,7 +105,7 @@ struct Scene void mouseMove(int32_t x, int32_t y) { - mouse_position = sf::Vector2f(to(x), to(y)) / Item::SCALE; + mouse_position = sf::Vector2f(to(x), to(y)) / Conf::GUI_SCALE; root.defaultOnMouseMove(mouse_position); } }; diff --git a/include/editor/editor_scene.hpp b/include/editor/editor_scene.hpp index b107adf6..60e6b78d 100644 --- a/include/editor/editor_scene.hpp +++ b/include/editor/editor_scene.hpp @@ -132,8 +132,8 @@ struct EditorScene : public GUI::Scene void onSizeChange() override { - renderer->setSize(root.size); - renderer->simulation.renderer.vp_handler.state.center = root.size; + renderer->size = root.size; + renderer->simulation.renderer.vp_handler.state.center = root.size * 0.5f * Conf::GUI_SCALE; // This is to update mouse_position simulation.renderer.vp_handler.wheelZoom(0); } diff --git a/include/editor/world_view.hpp b/include/editor/world_view.hpp index 6e8556fd..825a94d4 100644 --- a/include/editor/world_view.hpp +++ b/include/editor/world_view.hpp @@ -44,7 +44,7 @@ struct WorldView : GUI::Item { if (button == sf::Mouse::Left) { control_state.focus_requested = false; - simulation.renderer.vp_handler.click(relative_click_position * Item::SCALE); + simulation.renderer.vp_handler.click(relative_click_position * Conf::GUI_SCALE); } else if (button == sf::Mouse::Right) { action_button_click = true; control_state.executeViewAction(simulation.renderer.vp_handler.getMouseWorldPosition()); @@ -68,7 +68,7 @@ struct WorldView : GUI::Item void onMouseMove(sf::Vector2f new_mouse_position) override { - simulation.renderer.vp_handler.setMousePosition(new_mouse_position * Item::SCALE); + simulation.renderer.vp_handler.setMousePosition(new_mouse_position * Conf::GUI_SCALE); if (action_button_click) { control_state.executeViewAction(simulation.renderer.vp_handler.getMouseWorldPosition()); } diff --git a/include/simulation/config.hpp b/include/simulation/config.hpp index d29caefb..25095ca5 100644 --- a/include/simulation/config.hpp +++ b/include/simulation/config.hpp @@ -26,6 +26,7 @@ struct DefaultConf static constexpr uint32_t MAX_COLONIES_COUNT = 4; static sf::Color COLONY_COLORS[MAX_COLONIES_COUNT]; static uint32_t USE_FULLSCREEN; + static float GUI_SCALE; static void loadTextures() { @@ -65,6 +66,9 @@ struct DefaultConf DefaultConf::USE_FULLSCREEN = std::atoi(line_c); break; case 3: + DefaultConf::GUI_SCALE = std::atof(line_c); + break; + case 4: DefaultConf::ANTS_COUNT = std::atoi(line_c); break; default: @@ -118,6 +122,9 @@ sf::Color DefaultConf::COLONY_COLORS[MAX_COLONIES_COUNT] = {sf::Color::Red, s template uint32_t DefaultConf::USE_FULLSCREEN = 1; +template +float DefaultConf::GUI_SCALE = 1.0f; + using Conf = DefaultConf; diff --git a/src/main.cpp b/src/main.cpp index 8c00b143..faf70428 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ int main() Simulation simulation(window); // Create editor scene around it GUI::Scene::Ptr scene = create(window, simulation); + scene->resize(); // Main loop while (window.isOpen()) { // Update