Skip to content

Commit 0867f3f

Browse files
committed
fix hidpi bug
1 parent db92302 commit 0867f3f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

include/gf2/graphics/Scene.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace gf {
2929
void set_surface_size(Vec2I size);
3030
Vec2I surface_size() const;
3131

32+
void set_window_size(Vec2I size);
33+
Vec2I window_size() const;
34+
3235
void set_clear_color(Color color);
3336
Color clear_color() const;
3437

@@ -81,6 +84,7 @@ namespace gf {
8184
SceneVisibility m_visibility = SceneVisibility::Shown;
8285

8386
Vec2I m_surface_size = { 1, 1 };
87+
Vec2I m_window_size = { 1, 1 };
8488
Color m_clear_color = Black;
8589
};
8690

library/graphics/Scene.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ namespace gf {
2424
return m_surface_size;
2525
}
2626

27+
void BasicScene::set_window_size(Vec2I size)
28+
{
29+
m_window_size = size;
30+
}
31+
32+
Vec2I BasicScene::window_size() const
33+
{
34+
return m_window_size;
35+
}
36+
2737
void BasicScene::set_clear_color(Color color)
2838
{
2939
m_clear_color = gf::srgb_to_linear(color);
@@ -214,12 +224,12 @@ namespace gf {
214224

215225
Vec2F Scene::position_to_world_location(Vec2I position)
216226
{
217-
return m_world_camera.position_to_location(position, surface_size());
227+
return m_world_camera.position_to_location(position, window_size());
218228
}
219229

220230
Vec2I Scene::world_location_to_position(Vec2F location)
221231
{
222-
return m_world_camera.location_to_position(location, surface_size());
232+
return m_world_camera.location_to_position(location, window_size());
223233
}
224234

225235
void Scene::update_entities(Time time)

library/graphics/SceneManager.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,14 @@ namespace gf {
381381
while (!m_curr_scenes.empty() && !window()->should_close()) {
382382
std::vector<BasicScene*> scenes = m_curr_scenes; // make a copy to avoid iterator invalidation
383383
m_scenes_changed = false;
384+
384385
auto surface_size = window()->surface_size();
386+
auto window_size = window()->size();
385387

386-
std::for_each(scenes.begin(), scenes.end(), [surface_size](auto* scene) { scene->set_surface_size(surface_size); });
388+
std::for_each(scenes.begin(), scenes.end(), [surface_size, window_size](auto* scene) {
389+
scene->set_surface_size(surface_size);
390+
scene->set_window_size(window_size);
391+
});
387392

388393
auto* current_scene = scenes.back();
389394
current_scene->show();
@@ -398,6 +403,11 @@ namespace gf {
398403
window()->close();
399404
break;
400405

406+
case EventType::WindowResized:
407+
window_size = event->from<EventType::WindowResized>().size;
408+
std::for_each(scenes.begin(), scenes.end(), [window_size](auto* scene) { scene->set_window_size(window_size); });
409+
break;
410+
401411
case EventType::WindowPixelSizeChanged:
402412
surface_size = event->from<EventType::WindowPixelSizeChanged>().size;
403413
render_manager()->update_surface_size(surface_size);

0 commit comments

Comments
 (0)