diff options
| -rw-r--r-- | editor/imgui-scenery.cpp | 2 | ||||
| -rw-r--r-- | editor/imgui-tiles.cpp | 8 | ||||
| -rw-r--r-- | editor/imgui.cpp | 14 | ||||
| -rw-r--r-- | floormat/events.hpp | 2 | ||||
| -rw-r--r-- | floormat/main.hpp | 5 | ||||
| -rw-r--r-- | floormat/settings.hpp | 2 | ||||
| -rw-r--r-- | main/draw.cpp | 27 | ||||
| -rw-r--r-- | main/events.cpp | 15 | ||||
| -rw-r--r-- | main/main-impl.cpp | 4 | ||||
| -rw-r--r-- | main/main-impl.hpp | 2 | ||||
| -rw-r--r-- | main/setup.cpp | 3 | 
11 files changed, 43 insertions, 41 deletions
| diff --git a/editor/imgui-scenery.cpp b/editor/imgui-scenery.cpp index f7577a04..85e7516f 100644 --- a/editor/imgui-scenery.cpp +++ b/editor/imgui-scenery.cpp @@ -19,7 +19,7 @@ void app::draw_editor_scenery_pane(scenery_editor& ed)      constexpr int ncolumns = 4;      const auto size = ImGui::GetWindowSize();      auto b2 = imgui::begin_table("scenery-table", ncolumns, flags, size); -    const auto row_height = ImGui::GetCurrentContext()->FontSize + 10*dpi; +    const auto row_height = ImGui::GetCurrentContext()->FontSize + 10*dpi[1];      constexpr auto thumbnail_width = 50;      const auto colwidth_type = ImGui::CalcTextSize("generic").x;      const auto colwidth_group = ImGui::CalcTextSize("MMMMMMMMMMMMMMM").x; diff --git a/editor/imgui-tiles.cpp b/editor/imgui-tiles.cpp index 79bf2166..9d84027f 100644 --- a/editor/imgui-tiles.cpp +++ b/editor/imgui-tiles.cpp @@ -17,7 +17,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st      constexpr Color4 color_perm_selected{1, 1, 1, .7f},                       color_selected{1, 0.843f, 0, .8f},                       color_hover{0, .8f, 1, .7f}; -    const float window_width = ImGui::GetWindowWidth() - 32 * dpi; +    const float window_width = ImGui::GetWindowWidth() - 32 * dpi[0];      char buf[128];      const auto& style = ImGui::GetStyle();      const auto N = atlas->num_tiles(); @@ -36,7 +36,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st              text(" (selected)");          }          const auto len = snformat(buf, "{:d}"_cf, N); -        ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi); +        ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi[0]);          text({buf, len});      };      if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); @@ -44,7 +44,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st      {          do_caption();          [[maybe_unused]] const raii_wrapper vars[] = { -            push_style_var(ImGuiStyleVar_FramePadding, {2*dpi, 2*dpi}), +            push_style_var(ImGuiStyleVar_FramePadding, {2*dpi[0], 2*dpi[1]}),              push_style_color(ImGuiCol_ButtonHovered, color_hover),          };          const bool perm_selected = ed.is_permutation_selected(atlas); @@ -65,7 +65,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st              snformat(buf, "##item_{}"_cf, i);              const auto uv = atlas->texcoords_for_id(i);              constexpr ImVec2 size_2 = { TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f }; -            ImGui::ImageButton(buf, (void*)&atlas->texture(), ImVec2(size_2.x * dpi, size_2.y * dpi), +            ImGui::ImageButton(buf, (void*)&atlas->texture(), ImVec2(size_2.x * dpi[0], size_2.y * dpi[1]),                                 { uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] });              if (ImGui::IsItemClicked(ImGuiMouseButton_Left))                  ed.select_tile(atlas, i); diff --git a/editor/imgui.cpp b/editor/imgui.cpp index e1b39d07..59196e6f 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -26,7 +26,7 @@ float app::draw_main_menu()      float main_menu_height = 0;      if (auto b = begin_main_menu())      { -        ImGui::SetWindowFontScale(M->dpi_scale()); +        ImGui::SetWindowFontScale(M->dpi_scale().min());          if (auto b = begin_menu("File"))          {  #if 0 @@ -77,7 +77,7 @@ float app::draw_main_menu()  void app::draw_ui()  { -    const auto dpi = M->dpi_scale(); +    const auto dpi = M->dpi_scale().min();      [[maybe_unused]] const auto style_ = style_saver{};      auto& style = ImGui::GetStyle();      auto& ctx = *ImGui::GetCurrentContext(); @@ -107,7 +107,7 @@ void app::draw_fps()      const ImVec2 size = ImGui::CalcTextSize(buf);      ImDrawList& draw = *ImGui::GetForegroundDrawList();      draw.AddText(nullptr, ImGui::GetCurrentContext()->FontSize, -                 {M->window_size()[0] - size.x - 3.5f*dpi, 3*dpi}, ImGui::ColorConvertFloat4ToU32({0, 1, 0, 1}), buf); +                 {M->window_size()[0] - size.x - 3.5f*dpi[0], 3*dpi[1]}, ImGui::ColorConvertFloat4ToU32({0, 1, 0, 1}), buf);  }  void app::draw_tile_under_cursor() @@ -126,7 +126,7 @@ void app::draw_tile_under_cursor()      ImDrawList& draw = *ImGui::GetForegroundDrawList();      draw.AddText(nullptr, ImGui::GetCurrentContext()->FontSize, -                 {window_size[0]*.5f - size.x/2, 3*dpi}, (unsigned)-1, buf); +                 {window_size[0]*.5f - size.x/2, 3*dpi[1]}, (unsigned)-1, buf);  }  void app::draw_editor_pane(float main_menu_height) @@ -143,9 +143,9 @@ void app::draw_editor_pane(float main_menu_height)          active ? M->start_text_input() : M->stop_text_input();      [[maybe_unused]] const raii_wrapper vars[] = { -        push_style_var(ImGuiStyleVar_WindowPadding, {8*dpi, 8*dpi}), +        push_style_var(ImGuiStyleVar_WindowPadding, {8*dpi[0], 8*dpi[1]}),          push_style_var(ImGuiStyleVar_WindowBorderSize, 0), -        push_style_var(ImGuiStyleVar_FramePadding, {4*dpi, 4*dpi}), +        push_style_var(ImGuiStyleVar_FramePadding, {4*dpi[0], 4*dpi[1]}),          push_style_color(ImGuiCol_WindowBg, {0, 0, 0, .5}),          push_style_color(ImGuiCol_FrameBg, {0, 0, 0, 0}),      }; @@ -158,7 +158,7 @@ void app::draw_editor_pane(float main_menu_height)          ImGui::SetNextWindowPos({0, main_menu_height+style.WindowPadding.y});          ImGui::SetNextFrameWantCaptureKeyboard(false); -        ImGui::SetNextWindowSize({425 * dpi, window_size[1] - main_menu_height - style.WindowPadding.y}); +        ImGui::SetNextWindowSize({425 * dpi[0], window_size[1] - main_menu_height - style.WindowPadding.y});          if (const auto flags = ImGuiWindowFlags_(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);              auto b = begin_window({}, flags))          { diff --git a/floormat/events.hpp b/floormat/events.hpp index a70832fd..44e54a05 100644 --- a/floormat/events.hpp +++ b/floormat/events.hpp @@ -20,7 +20,7 @@ struct mouse_button_event final {  };  struct mouse_move_event final { -    Vector2i position, relative_position; +    Vector2i position;      mouse_button buttons = mouse_button_none;      int mods = 0;  }; diff --git a/floormat/main.hpp b/floormat/main.hpp index af388de4..6c933037 100644 --- a/floormat/main.hpp +++ b/floormat/main.hpp @@ -60,12 +60,13 @@ struct floormat_main      virtual struct world& world() noexcept = 0;      virtual SDL_Window* window() noexcept = 0; -    float dpi_scale() const noexcept { return _dpi_scale; } +    Vector2 dpi_scale() const noexcept { return _dpi_scale; }      [[nodiscard]] static floormat_main* create(floormat_app& app, fm_settings&& options);  protected: -    float _frame_time1 = 0, _frame_time2 = 0, _dpi_scale = 1; +    float _frame_time1 = 0, _frame_time2 = 0; +    Vector2 _dpi_scale{1, 1}, _virtual_scale{1, 1};  };  } // namespace floormat diff --git a/floormat/settings.hpp b/floormat/settings.hpp index f90e1c97..aed65dea 100644 --- a/floormat/settings.hpp +++ b/floormat/settings.hpp @@ -17,7 +17,7 @@ struct fm_settings      fm_DECLARE_DEPRECATED_COPY_ASSIGNMENT(fm_settings);      fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(fm_settings); -    Magnum::Math::Vector2<int> resolution{1536, 1152}; +    Magnum::Math::Vector2<int> resolution{1024, 720};      Corrade::Containers::String title{"Test"};      Corrade::Containers::String disabled_extensions; // TODO      bool vsync = true; diff --git a/main/draw.cpp b/main/draw.cpp index 2f9bc737..9da9fbd7 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -12,11 +12,13 @@  namespace floormat { -void main_impl::recalc_viewport(Vector2i size) noexcept +void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept  { +    _dpi_scale = dpiScaling(); +    _virtual_scale = Vector2(fb_size) / Vector2(win_size);      update_window_state(); -    _shader.set_scale(Vector2{size}); -    GL::defaultFramebuffer.setViewport({{}, size }); +    _shader.set_scale(Vector2{fb_size}); +    GL::defaultFramebuffer.setViewport({{}, fb_size });      // -- state ---      using R = GL::Renderer; @@ -28,17 +30,17 @@ void main_impl::recalc_viewport(Vector2i size) noexcept      GL::Renderer::enable(R::Feature::ScissorTest);      GL::Renderer::enable(R::Feature::DepthClamp);      GL::Renderer::setDepthFunction(R::DepthFunction::Greater); -    GL::Renderer::setScissor({{}, size}); +    GL::Renderer::setScissor({{}, fb_size});      // -- user-- -    app.on_viewport_event(size); +    app.on_viewport_event(fb_size);  }  global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept  {      constexpr Vector2d pixel_size(TILE_SIZE2);      constexpr Vector2d half{.5, .5}; -    const Vector2d px = position - Vector2d{windowSize()}*.5 - _shader.camera_offset(); +    const Vector2d px = position - Vector2d{framebufferSize()}*.5 - _shader.camera_offset();      const Vector2d vec = tile_shader::unproject(px*.5) / pixel_size + half;      const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]);      return { x, y }; @@ -49,7 +51,7 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds      using limits = std::numeric_limits<std::int16_t>;      auto x0 = limits::max(), x1 = limits::min(), y0 = limits::max(), y1 = limits::min(); -    for (const auto win = Vector2d(windowSize()); +    for (const auto win = Vector2d(framebufferSize());          auto p : {pixel_to_tile(Vector2d{0, 0}).chunk(),                    pixel_to_tile(Vector2d{win[0]-1, 0}).chunk(),                    pixel_to_tile(Vector2d{0, win[1]-1}).chunk(), @@ -66,7 +68,7 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds  void main_impl::draw_world() noexcept  {      const auto [minx, maxx, miny, maxy] = get_draw_bounds(); -    const auto sz = windowSize(); +    const auto sz = framebufferSize();      for (std::int16_t y = miny; y <= maxy; y++)          for (std::int16_t x = minx; x <= maxx; x++) @@ -99,7 +101,7 @@ void main_impl::draw_world() noexcept  void main_impl::draw_anim() noexcept  { -    const auto sz = windowSize(); +    const auto sz = framebufferSize();      const auto [minx, maxx, miny, maxy] = get_draw_bounds();      _clickable_scenery.clear(); @@ -178,10 +180,11 @@ void main_impl::do_update()  void main_impl::drawEvent()  { -    _dpi_scale = 1; +#ifndef __linux__      if (int index = SDL_GetWindowDisplayIndex(window()); index >= 0) -        if (float dpi = 96; !SDL_GetDisplayDPI(index, &dpi, nullptr, nullptr)) -            _dpi_scale = dpi / 96; +        if (float hdpi = 96, vdpi = 96; !SDL_GetDisplayDPI(index, nullptr, &hdpi, &vdpi)) +            _dpi_scale = { hdpi / 96, vdpi / 96 }; +#endif      _shader.set_tint({1, 1, 1, 1}); diff --git a/main/events.cpp b/main/events.cpp index 922b2d23..11076b54 100644 --- a/main/events.cpp +++ b/main/events.cpp @@ -9,14 +9,13 @@ namespace floormat {  void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)  { -    fm_assert(event.framebufferSize() == event.windowSize()); -    recalc_viewport(event.windowSize()); -    app.on_viewport_event(event.windowSize()); +    recalc_viewport(event.framebufferSize(), event.windowSize()); +    app.on_viewport_event(event.framebufferSize());  }  void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)  { -    app.on_mouse_up_down({event.position(), +    app.on_mouse_up_down({event.position() * _virtual_scale,                            (SDL_Keymod)(std::uint16_t)event.modifiers(),                            mouse_button(SDL_BUTTON((std::uint8_t)event.button())),                            std::uint8_t(std::min(255, event.clickCount()))}, @@ -25,7 +24,7 @@ void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)  void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)  { -    app.on_mouse_up_down({event.position(), +    app.on_mouse_up_down({event.position() * _virtual_scale,                            (SDL_Keymod)(std::uint16_t)event.modifiers(),                            mouse_button(SDL_BUTTON((std::uint8_t)event.button())),                            std::uint8_t(std::min(255, event.clickCount()))}, @@ -34,14 +33,14 @@ void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)  void main_impl::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)  { -    app.on_mouse_move({event.position(), event.relativePosition(), -                       (mouse_button)(std::uint8_t)(std::uint32_t)event.buttons(), +    app.on_mouse_move({event.position() * _virtual_scale, +                       (mouse_button)(std::uint8_t)std::uint32_t{event.buttons()},                         (SDL_Keymod)(std::uint16_t)event.modifiers()});  }  void main_impl::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)  { -    app.on_mouse_scroll({event.offset(), event.position(), +    app.on_mouse_scroll({event.offset(), event.position() * _virtual_scale,                           (SDL_Keymod)(std::uint16_t)event.modifiers()});  } diff --git a/main/main-impl.cpp b/main/main-impl.cpp index 0790a0d2..1da2d4ee 100644 --- a/main/main-impl.cpp +++ b/main/main-impl.cpp @@ -13,7 +13,7 @@ struct world& main_impl::world() noexcept { return _world; }  SDL_Window* main_impl::window() noexcept { return Sdl2Application::window(); }  fm_settings& main_impl::settings() noexcept { return s; }  const fm_settings& main_impl::settings() const noexcept { return s; } -Vector2i main_impl::window_size() const noexcept { return windowSize(); } +Vector2i main_impl::window_size() const noexcept { return framebufferSize(); }  tile_shader& main_impl::shader() noexcept { return _shader; }  const tile_shader& main_impl::shader() const noexcept { return _shader; }  bool main_impl::is_text_input_active() const noexcept { return const_cast<main_impl&>(*this).isTextInputActive(); } @@ -22,7 +22,7 @@ void main_impl::stop_text_input() noexcept { stopTextInput(); }  int main_impl::exec()  { -    recalc_viewport(windowSize()); +    recalc_viewport(framebufferSize(), windowSize());      return Sdl2Application::exec();  } diff --git a/main/main-impl.hpp b/main/main-impl.hpp index cc17f9bc..74ed8222 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -86,7 +86,7 @@ private:          bool do_sleep = false;      } dt_expected; -    void recalc_viewport(Vector2i size) noexcept; +    void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept;      void draw_world() noexcept;      void draw_anim() noexcept; diff --git a/main/setup.cpp b/main/setup.cpp index 72bf3550..38df0ccf 100644 --- a/main/setup.cpp +++ b/main/setup.cpp @@ -20,7 +20,6 @@ main_impl::main_impl(floormat_app& app, fm_settings&& se, int& fake_argc) noexce      else          (void)setSwapInterval(0);      set_fp_mask(); -    fm_assert(framebufferSize() == windowSize());      _clickable_scenery.reserve(128);      timeline.start();  } @@ -58,7 +57,7 @@ auto main_impl::make_conf(const fm_settings& s) -> Configuration      }      return Configuration{}          .setTitle(s.title) -        .setSize(s.resolution, Vector2(1, 1)) +        .setSize(s.resolution, Configuration::DpiScalingPolicy::Virtual)          .setWindowFlags(make_window_flags(s));  } | 
