Skip to content

Commit

Permalink
Fix wx UI scaling problems (Closes #1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Oct 23, 2023
1 parent 489362b commit 1fc8637
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 232 deletions.
8 changes: 4 additions & 4 deletions apps/RawLogViewer/main_timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void xRawLogViewerFrame::rebuildBottomTimeLine()
auto& tl = m_timeline;
tl.clearStats();

const auto clsz = m_glTimeLine->GetClientSize();
const auto clsz = mrpt::gui::GetScaledClientSize(m_glTimeLine);

auto px2x = [clsz](int u) { return -1.0 + (2.0 / clsz.GetWidth()) * u; };
auto px2y = [clsz](int v) { return +1.0 - (2.0 / clsz.GetHeight()) * v; };
Expand Down Expand Up @@ -365,7 +365,7 @@ void xRawLogViewerFrame::bottomTimeLineUpdateCursorFromTreeScrollPos()
return;
}

const auto clsz = m_glTimeLine->GetClientSize();
const auto clsz = mrpt::gui::GetScaledClientSize(m_glTimeLine);

auto px2x = [clsz](int u) { return -1.0 + (2.0 / clsz.GetWidth()) * u; };
auto px2y = [clsz](int v) { return +1.0 - (2.0 / clsz.GetHeight()) * v; };
Expand Down Expand Up @@ -557,7 +557,7 @@ void xRawLogViewerFrame::OnTimeLineMouseWheel(wxMouseEvent& e)
mrpt::keep_max(xFocus, -1.0);
mrpt::keep_min(xFocus, 1.0);

const auto clsz = m_glTimeLine->GetClientSize();
const auto clsz = mrpt::gui::GetScaledClientSize(m_glTimeLine);

auto px2x = [clsz](int u) {
return -1.0 + (2.0 / clsz.GetWidth()) * u;
Expand Down Expand Up @@ -613,7 +613,7 @@ std::optional<std::pair<double, size_t>>
const std::optional<std::string>& forceThisSensorLabel,
const mrpt::optional_ref<std::string>& outSelectedSensorLabel) const
{
const auto clsz = m_glTimeLine->GetClientSize();
const auto clsz = mrpt::gui::GetScaledClientSize(m_glTimeLine);

auto& tl = m_timeline;

Expand Down
3 changes: 2 additions & 1 deletion apps/camera-calib/CDlgCalibWizardOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ void CDlgCalibWizardOnline::OntimCaptureTrigger(wxTimerEvent& event)

// Resize the display area, if needed:
if (std::abs(
(int)(this->m_realtimeview->GetClientSize().GetWidth()) -
(int)(mrpt::gui::GetScaledClientSize(m_realtimeview)
.GetWidth()) -
int(img_to_show.getWidth())) > 30)
{
this->m_realtimeview->SetSize(
Expand Down
3 changes: 2 additions & 1 deletion apps/camera-calib/CDlgPoseEst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ void CDlgPoseEst::OntimCaptureTrigger(wxTimerEvent& event)

// Resize the display area, if needed:
if (std::abs(
(int)(this->m_realtimeview->GetClientSize().GetWidth()) -
(int)(mrpt::gui::GetScaledClientSize(m_realtimeview)
.GetWidth()) -
int(img_to_show.getWidth())) > 30)
{
this->m_realtimeview->SetSize(
Expand Down
6 changes: 5 additions & 1 deletion doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
\page changelog Change Log

# Version 2.11.2: UNRELEASED
(none yet)
- Changes in libraries:
- \ref mrpt_gui_grp
- New function mrpt::gui::GetScaledClientSize().
- BUG FIXES:
- Fix wrong rendering of all wxWidgets-based OpenGL windows when using Ubuntu's display settings to change UI to a size different than 100% (Fixes [issue #1114](https://github.com/MRPT/mrpt/issues/1114)).

# Version 2.11.1: Released Oct 23rd, 2023
- Changes in libraries:
Expand Down
6 changes: 5 additions & 1 deletion libs/gui/include/mrpt/gui/WxUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ namespace gui
/** \addtogroup mrpt_gui_wxutils Utilities for MRPT-wxWidgets interfacing (in
#include <mrpt/gui/WxUtils.h>)
* \ingroup mrpt_gui_grp
* @{ */
#if MRPT_HAS_WXWIDGETS

/** Returns the size of a window, including the optional magnification scale set
* by users in Display->Appearance.
*/
wxSize GetScaledClientSize(const wxWindow* w);

#ifndef WX_START_TRY

#define WX_START_TRY \
Expand Down
11 changes: 5 additions & 6 deletions libs/gui/src/CWxGLCanvasBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mrpt/core/lock_helper.h>
#include <mrpt/gui/CWxGLCanvasBase.h>
#include <mrpt/gui/WxSubsystem.h>
#include <mrpt/gui/WxUtils.h>
#include <mrpt/system/CTicTac.h>

#if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
Expand Down Expand Up @@ -223,9 +224,8 @@ void CWxGLCanvasBase::Render()

lck.unlock();

int width, height;
GetClientSize(&width, &height);
double At = renderCanvas(width, height);
const auto sz = mrpt::gui::GetScaledClientSize(this);
double At = renderCanvas(sz.GetWidth(), sz.GetHeight());

OnPostRenderSwapBuffers(At, dc);
}
Expand All @@ -241,8 +241,7 @@ void CWxGLCanvasBase::OnSize(wxSizeEvent& event)
if (!m_parent->IsShown()) return;

// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
int w, h;
GetClientSize(&w, &h);
const auto sz = mrpt::gui::GetScaledClientSize(this);

if (this->IsShownOnScreen())
{
Expand All @@ -256,7 +255,7 @@ void CWxGLCanvasBase::OnSize(wxSizeEvent& event)
SetCurrent(*m_gl_context);
}

resizeViewport(w, h);
resizeViewport(sz.GetWidth(), sz.GetHeight());
}
}

Expand Down
9 changes: 9 additions & 0 deletions libs/gui/src/WxUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "gui-precomp.h" // Precompiled headers
//
#include <mrpt/core/round.h>
#include <mrpt/gui/WxUtils.h>
#include <mrpt/img/CImage.h>
#include <mrpt/system/filesystem.h>
Expand Down Expand Up @@ -933,4 +934,12 @@ mrptKeyModifier mrpt::gui::keyEventToMrptKeyModifier(const wxKeyEvent& ev)
return mrptKeyModifier(mod);
}

wxSize mrpt::gui::GetScaledClientSize(const wxWindow* w)
{
int width, height;
w->GetClientSize(&width, &height);
const double s = w->GetContentScaleFactor();
return wxSize(mrpt::round(s * width), mrpt::round(s * height));
}

#endif // MRPT_HAS_WXWIDGETS
Loading

0 comments on commit 1fc8637

Please sign in to comment.