Skip to content

Commit 6b85405

Browse files
committed
Add scaling in conf
1 parent 3d04cd9 commit 6b85405

7 files changed

Lines changed: 20 additions & 10 deletions

File tree

include/editor/GUI/item.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "item.hpp"
2+
3+
float GUI::Item::SCALE = 1.0f;

include/editor/GUI/item.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct Observer
3434

3535
struct Item
3636
{
37-
static constexpr float SCALE = 2.0f;
3837
// Attributes
3938
sf::Vector2f size;
4039
sf::Vector2f offset;
@@ -228,7 +227,7 @@ struct Item
228227
void draw(sf::RenderTarget& target, const sf::Drawable& drawable, const sf::RenderStates& states)
229228
{
230229
sf::RenderStates default_states = states;
231-
default_states.transform.scale(2.0f, 2.0f);
230+
default_states.transform.scale(Conf::GUI_SCALE, Conf::GUI_SCALE);
232231
default_states.transform.translate(offset);
233232
target.draw(drawable, default_states);
234233
}

include/editor/GUI/scene.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Scene
2222
Scene(sf::RenderWindow& window_)
2323
: window(window_)
2424
, event_manager(window_, false)
25-
, root(toVector2f(window_.getSize()) / Item::SCALE)
25+
, root(toVector2f(window_.getSize()) / Conf::GUI_SCALE)
2626
{
2727
initializeEventsCallbacks();
2828
}
@@ -49,7 +49,7 @@ struct Scene
4949
{
5050
const auto size = window.getSize();
5151
const sf::Vector2f new_size{to<float>(size.x), to<float>(size.y)};
52-
root.setSize(new_size / Item::SCALE);
52+
root.setSize(new_size / Conf::GUI_SCALE);
5353
window.setView(sf::View(new_size * 0.5f, new_size));
5454
onSizeChange();
5555
}
@@ -73,7 +73,7 @@ struct Scene
7373

7474
void dispatchClick(const sf::Event& e)
7575
{
76-
root.defaultOnClick(mouse_position / Item::SCALE, e.mouseButton.button);
76+
root.defaultOnClick(mouse_position / Conf::GUI_SCALE, e.mouseButton.button);
7777
}
7878

7979
void unclick(const sf::Event& e)
@@ -105,7 +105,7 @@ struct Scene
105105

106106
void mouseMove(int32_t x, int32_t y)
107107
{
108-
mouse_position = sf::Vector2f(to<float>(x), to<float>(y)) / Item::SCALE;
108+
mouse_position = sf::Vector2f(to<float>(x), to<float>(y)) / Conf::GUI_SCALE;
109109
root.defaultOnMouseMove(mouse_position);
110110
}
111111
};

include/editor/editor_scene.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ struct EditorScene : public GUI::Scene
132132

133133
void onSizeChange() override
134134
{
135-
renderer->setSize(root.size);
136-
renderer->simulation.renderer.vp_handler.state.center = root.size;
135+
renderer->size = root.size;
136+
renderer->simulation.renderer.vp_handler.state.center = root.size * 0.5f * Conf::GUI_SCALE;
137137
// This is to update mouse_position
138138
simulation.renderer.vp_handler.wheelZoom(0);
139139
}

include/editor/world_view.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct WorldView : GUI::Item
4444
{
4545
if (button == sf::Mouse::Left) {
4646
control_state.focus_requested = false;
47-
simulation.renderer.vp_handler.click(relative_click_position * Item::SCALE);
47+
simulation.renderer.vp_handler.click(relative_click_position * Conf::GUI_SCALE);
4848
} else if (button == sf::Mouse::Right) {
4949
action_button_click = true;
5050
control_state.executeViewAction(simulation.renderer.vp_handler.getMouseWorldPosition());
@@ -68,7 +68,7 @@ struct WorldView : GUI::Item
6868

6969
void onMouseMove(sf::Vector2f new_mouse_position) override
7070
{
71-
simulation.renderer.vp_handler.setMousePosition(new_mouse_position * Item::SCALE);
71+
simulation.renderer.vp_handler.setMousePosition(new_mouse_position * Conf::GUI_SCALE);
7272
if (action_button_click) {
7373
control_state.executeViewAction(simulation.renderer.vp_handler.getMouseWorldPosition());
7474
}

include/simulation/config.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct DefaultConf
2626
static constexpr uint32_t MAX_COLONIES_COUNT = 4;
2727
static sf::Color COLONY_COLORS[MAX_COLONIES_COUNT];
2828
static uint32_t USE_FULLSCREEN;
29+
static float GUI_SCALE;
2930

3031
static void loadTextures()
3132
{
@@ -65,6 +66,9 @@ struct DefaultConf
6566
DefaultConf<T>::USE_FULLSCREEN = std::atoi(line_c);
6667
break;
6768
case 3:
69+
DefaultConf<T>::GUI_SCALE = std::atof(line_c);
70+
break;
71+
case 4:
6872
DefaultConf<T>::ANTS_COUNT = std::atoi(line_c);
6973
break;
7074
default:
@@ -118,6 +122,9 @@ sf::Color DefaultConf<T>::COLONY_COLORS[MAX_COLONIES_COUNT] = {sf::Color::Red, s
118122
template<typename T>
119123
uint32_t DefaultConf<T>::USE_FULLSCREEN = 1;
120124

125+
template<typename T>
126+
float DefaultConf<T>::GUI_SCALE = 1.0f;
127+
121128
using Conf = DefaultConf<int>;
122129

123130

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int main()
2424
Simulation simulation(window);
2525
// Create editor scene around it
2626
GUI::Scene::Ptr scene = create<edtr::EditorScene>(window, simulation);
27+
scene->resize();
2728
// Main loop
2829
while (window.isOpen()) {
2930
// Update

0 commit comments

Comments
 (0)