Skip to content

Commit

Permalink
Fix some issues with scaling on linux
Browse files Browse the repository at this point in the history
Some things are still a bit wonky but it should be more usable now at least
  • Loading branch information
sirjuddington committed May 30, 2024
1 parent b38ded8 commit 25cbba8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Application/SLADEWxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ bool SLADEWxApp::OnInit()
// Init application
try
{
if (!app::init(args, ui_scale))
if (!app::init(args, 1.))
return false;
}
catch (const std::exception& ex)
Expand Down
2 changes: 1 addition & 1 deletion src/General/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void ui::init(double scale)
{
splash_window = std::make_unique<SplashWindow>();

#if wxCHECK_VERSION(3, 1, 4)
#ifdef __WXMSW__
scale = splash_window->GetDPIScaleFactor();
#endif

Expand Down
34 changes: 27 additions & 7 deletions src/UI/SToolBar/SToolBarButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ SToolBarButton::SToolBarButton(wxWindow* parent, const wxString& action, const w
Bind(wxEVT_LEFT_UP, &SToolBarButton::onMouseEvent, this);
Bind(wxEVT_KILL_FOCUS, &SToolBarButton::onFocus, this);
Bind(wxEVT_LEFT_DCLICK, &SToolBarButton::onMouseEvent, this);
Bind(wxEVT_MOTION, &SToolBarButton::onMouseEvent, this);
Bind(wxEVT_ERASE_BACKGROUND, &SToolBarButton::onEraseBackground, this);
}

Expand Down Expand Up @@ -215,16 +216,26 @@ void SToolBarButton::setMenu(wxMenu* menu, bool delete_existing)
// Checks if the mouseover state of the button needs updating.
// If it does, the button is refreshed and this returns true
// -----------------------------------------------------------------------------
bool SToolBarButton::updateState()
bool SToolBarButton::updateState(int mouse_event)
{
auto prev_state = state_;

if (IsShownOnScreen() && IsEnabled() && GetScreenRect().Contains(wxGetMousePosition()))
if (mouse_event == 1) // Enter or motion
state_ = State::MouseOver;
else if (mouse_event == 2) // Leave
state_ = State::Normal;
else if (IsShownOnScreen() && IsEnabled())
{
if (wxGetMouseState().LeftIsDown())
state_ = State::MouseDown;
else
state_ = State::MouseOver;
auto mousePos = ScreenToClient(wxGetMousePosition());
auto rect = wxRect(GetSize());

if (rect.Contains(mousePos))
{
if (wxGetMouseState().LeftIsDown())
state_ = State::MouseDown;
else
state_ = State::MouseOver;
}
}
else
state_ = State::Normal;
Expand Down Expand Up @@ -422,13 +433,16 @@ void SToolBarButton::onPaint(wxPaintEvent& e)
void SToolBarButton::onMouseEvent(wxMouseEvent& e)
{
auto parent_window = dynamic_cast<wxFrame*>(wxGetTopLevelParent(this));
int mouse_event = 0;

// Mouse enter
if (e.GetEventType() == wxEVT_ENTER_WINDOW)
{
// Set status bar help text
if (parent_window && parent_window->GetStatusBar())
parent_window->SetStatusText(help_text_);

mouse_event = 1;
}

// Mouse leave
Expand All @@ -437,6 +451,8 @@ void SToolBarButton::onMouseEvent(wxMouseEvent& e)
// Clear status bar help text
if (parent_window && parent_window->GetStatusBar())
parent_window->SetStatusText("");

mouse_event = 2;
}

// Left button down
Expand Down Expand Up @@ -464,7 +480,11 @@ void SToolBarButton::onMouseEvent(wxMouseEvent& e)
parent_window->SetStatusText("");
}

updateState();
// Motion
if (e.GetEventType() == wxEVT_MOTION)
mouse_event = 1;

updateState(mouse_event);

// e.Skip();
}
Expand Down
2 changes: 1 addition & 1 deletion src/UI/SToolBar/SToolBarButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SToolBarButton : public wxControl
void setChecked(bool checked);
void setMenu(wxMenu* menu, bool delete_existing = false);

bool updateState();
bool updateState(int mouse_event = 0);

static int pixelHeight();

Expand Down

0 comments on commit 25cbba8

Please sign in to comment.