Skip to content

Commit

Permalink
Fix custom tab and dock art DPI scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
sirjuddington committed May 31, 2024
1 parent f90cc77 commit 660e573
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/MainEditor/UI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void MainWindow::setupLayout()
{
// Create the wxAUI manager & related things
aui_mgr_ = new wxAuiManager(this);
aui_mgr_->SetArtProvider(new SAuiDockArt());
aui_mgr_->SetArtProvider(new SAuiDockArt(this));
wxAuiPaneInfo p_inf;

// Set icon
Expand Down
2 changes: 1 addition & 1 deletion src/MapEditor/UI/MapEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void MapEditorWindow::setupLayout()
{
// Create the wxAUI manager & related things
auto m_mgr = new wxAuiManager(this);
m_mgr->SetArtProvider(new SAuiDockArt());
m_mgr->SetArtProvider(new SAuiDockArt(this));
wxAuiPaneInfo p_inf;

// Map canvas
Expand Down
2 changes: 1 addition & 1 deletion src/Scripting/UI/ScriptManagerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void ScriptManagerWindow::setupLayout()

// Create the wxAUI manager & related things
auto m_mgr = new wxAuiManager(this);
m_mgr->SetArtProvider(new SAuiDockArt());
m_mgr->SetArtProvider(new SAuiDockArt(this));
wxAuiPaneInfo p_inf;

// Set icon
Expand Down
5 changes: 2 additions & 3 deletions src/UI/Controls/STabCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
// -----------------------------------------------------------------------------
#include "Main.h"
#include "STabCtrl.h"
#include "General/UI.h"
#include "UI/SAuiTabArt.h"

using namespace slade;
Expand Down Expand Up @@ -75,8 +74,8 @@ STabCtrl::STabCtrl(wxWindow* parent, bool close_buttons, bool window_list, int h
wxAuiNotebook::Create(parent, -1, wxDefaultPosition, wxDefaultSize, style);

// Setup tabs
SetArtProvider(new SAuiTabArt(close_buttons, main_tabs));
wxAuiNotebook::SetTabCtrlHeight(ui::scalePx(height));
SetArtProvider(new SAuiTabArt(this, close_buttons, main_tabs));
wxAuiNotebook::SetTabCtrlHeight(FromDIP(height));
}

// -----------------------------------------------------------------------------
Expand Down
39 changes: 19 additions & 20 deletions src/UI/SAuiTabArt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
// -----------------------------------------------------------------------------
#include "Main.h"
#include "SAuiTabArt.h"
#include "General/UI.h"
#include "Graphics/Icons.h"
#include "Utility/Colour.h"
#include "WxUtils.h"
Expand Down Expand Up @@ -112,16 +111,16 @@ void IndentPressedBitmap(wxRect* rect, int button_state)
//
// -----------------------------------------------------------------------------

SAuiTabArt::SAuiTabArt(bool close_buttons, bool main_tabs) :
SAuiTabArt::SAuiTabArt(const wxWindow* window, bool close_buttons, bool main_tabs) :
close_buttons_{ close_buttons },
main_tabs_{ main_tabs },
padding_(tabs_condensed ? ui::scalePx(4) : ui::scalePx(8))
padding_(tabs_condensed ? window->FromDIP(4) : window->FromDIP(8))
{
m_normalFont = *wxNORMAL_FONT;
m_selectedFont = *wxNORMAL_FONT;

m_measuringFont = m_selectedFont;
m_fixedTabWidth = ui::scalePx(100);
m_fixedTabWidth = window->FromDIP(100);
m_tabCtrlHeight = 0;

wxColor baseColour = wxutil::systemPanelBGColour();
Expand Down Expand Up @@ -189,16 +188,16 @@ void SAuiTabArt::DrawBorder(wxDC& dc, wxWindow* wnd, const wxRect& rect)
dc.DrawLine(theRect.x, theRect.y, theRect.x + theRect.width, theRect.y);
}

void SAuiTabArt::DrawBackground(wxDC& dc, wxWindow* WXUNUSED(wnd), const wxRect& rect)
void SAuiTabArt::DrawBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect)
{
// draw background
wxColor top_color = main_tabs_ && global::win_version_major >= 10 ? col_w10_bg : m_baseColour;
wxColor bottom_color = main_tabs_ && global::win_version_major >= 10 ? col_w10_bg : m_baseColour;
wxRect r;

auto px1 = 1;
auto px2 = ui::scalePx(2);
auto px4 = ui::scalePx(4);
auto px1 = wnd->FromDIP(1);
auto px2 = wnd->FromDIP(2);
auto px4 = wnd->FromDIP(4);

if (m_flags & wxAUI_NB_BOTTOM)
r = wxRect(rect.x, rect.y, rect.width + px2, rect.height);
Expand Down Expand Up @@ -273,9 +272,9 @@ void SAuiTabArt::DrawTab(

// I know :P This stuff should probably be completely rewritten,
// but this will do for now
auto px2 = ui::scalePxU(2);
auto px3 = ui::scalePxU(3);
auto px4 = ui::scalePxU(4);
auto px2 = wnd->FromDIP(2);
auto px3 = wnd->FromDIP(3);
auto px4 = wnd->FromDIP(4);

wxCoord tab_height = m_tabCtrlHeight + px2;
wxCoord tab_width = tab_size.x;
Expand Down Expand Up @@ -526,10 +525,10 @@ wxSize SAuiTabArt::GetTabSize(

// add padding
tab_width += padding_ * 2;
tab_height += ui::scalePx(10);
tab_height += 10;

// minimum width
int min_width = tabs_condensed ? ui::scalePx(48) : ui::scalePx(64);
int min_width = tabs_condensed ? 48 : 64;
if (tab_width < min_width)
tab_width = min_width;

Expand All @@ -550,7 +549,7 @@ void SAuiTabArt::SetSelectedFont(const wxFont& font)
//
// -----------------------------------------------------------------------------

SAuiDockArt::SAuiDockArt()
SAuiDockArt::SAuiDockArt(const wxWindow* window)
{
caption_back_colour_ = wxutil::darkColour(wxutil::systemPanelBGColour(), 0.0f);

Expand All @@ -566,9 +565,9 @@ SAuiDockArt::SAuiDockArt()
if (global::win_version_major >= 10)
m_sashBrush = wxBrush(col_w10_bg);

m_captionSize = ui::scalePxU(19);
m_sashSize = ui::scalePxU(4);
m_buttonSize = ui::scalePx(16);
m_captionSize = window->FromDIP(19);
m_sashSize = window->FromDIP(4);
m_buttonSize = window->FromDIP(16);
}

SAuiDockArt::~SAuiDockArt() = default;
Expand All @@ -595,9 +594,9 @@ void SAuiDockArt::DrawCaption(wxDC& dc, wxWindow* window, const wxString& text,
// dc.SetPen(wxPen(sepCol));
// dc.DrawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1);

auto px2 = ui::scalePx(2);
auto px3 = ui::scalePx(3);
auto px5 = ui::scalePx(5);
auto px2 = window->FromDIP(2);
auto px3 = window->FromDIP(3);
auto px5 = window->FromDIP(5);

dc.SetBrush(wxBrush(sepCol));
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height + 1);
Expand Down
4 changes: 2 additions & 2 deletions src/UI/SAuiTabArt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace slade
class SAuiTabArt : public wxAuiGenericTabArt
{
public:
SAuiTabArt(bool close_buttons = false, bool main_tabs = false);
SAuiTabArt(const wxWindow* window, bool close_buttons = false, bool main_tabs = false);
~SAuiTabArt() override;

wxAuiTabArt* Clone() override;
Expand Down Expand Up @@ -88,7 +88,7 @@ class SAuiTabArt : public wxAuiGenericTabArt
class SAuiDockArt : public wxAuiDefaultDockArt
{
public:
SAuiDockArt();
SAuiDockArt(const wxWindow* window);
~SAuiDockArt() override;

void DrawCaption(wxDC& dc, wxWindow* window, const wxString& text, const wxRect& rect, wxAuiPaneInfo& pane)
Expand Down

0 comments on commit 660e573

Please sign in to comment.