1
0
Fork 0

Codechange: Call VideoDriver to change mouse position fix state.

This avoids the video driver needing to check if the state has changed.
pull/13287/head
Peter Nelson 2025-01-06 17:30:17 +00:00
parent 1bf45cd6ef
commit 23ea9f138a
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
7 changed files with 28 additions and 20 deletions

View File

@ -332,7 +332,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
FixTitleGameZoom();
_pause_mode = PM_UNPAUSED;
_cursor.fix_at = false;
VideoDriver::GetInstance()->FixMousePointer(false);
CheckForMissingGlyphs();

View File

@ -9,6 +9,7 @@
#include "stdafx.h"
#include "core/backup_type.hpp"
#include "video/video_driver.hpp"
#include "clear_map.h"
#include "industry.h"
#include "station_map.h"
@ -1866,7 +1867,9 @@ public:
void OnScroll(Point delta) override
{
if (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED) _cursor.fix_at = true;
if (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED) {
VideoDriver::GetInstance()->FixMousePointer(true);
}
/* While tile is at (delta.x, delta.y)? */
int sub;

View File

@ -49,6 +49,7 @@ public:
void ClearSystemSprites() override;
void PopulateSystemSprites() override;
void FixMousePointer(bool fix_at) override;
void EditBoxLostFocus() override;
std::vector<int> GetListOfMonitorRefreshRates() override;

View File

@ -240,6 +240,15 @@ bool VideoDriver_Cocoa::AfterBlitterChange()
return true;
}
void VideoDriver_Cocoa::FixMousePointer(bool fix_at)
{
if (_cursor.fix_at == fix_at) return;
this->VideoDriver::FixMousePointer(fix_at);
CGAssociateMouseAndMouseCursorPosition(!_cursor.fix_at);
}
/**
* An edit box lost the input focus. Abort character compositing if necessary.
*/

View File

@ -674,15 +674,6 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
HandleMouseEvents();
}
- (void)internalMouseButtonEvent
{
bool cur_fix = _cursor.fix_at;
HandleMouseEvents();
/* Cursor fix mode was changed, synchronize with OS. */
if (cur_fix != _cursor.fix_at) CGAssociateMouseAndMouseCursorPosition(!_cursor.fix_at);
}
- (BOOL)emulateRightButton:(NSEvent *)event
{
uint32_t keymask = 0;
@ -708,7 +699,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
[ self rightMouseDown:event ];
} else {
_left_button_down = true;
[ self internalMouseButtonEvent ];
HandleMouseEvents();
}
}
- (void)mouseUp:(NSEvent *)event
@ -719,7 +710,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
} else {
_left_button_down = false;
_left_button_clicked = false;
[ self internalMouseButtonEvent ];
HandleMouseEvents();
}
}
@ -731,12 +722,12 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
{
_right_button_down = true;
_right_button_clicked = true;
[ self internalMouseButtonEvent ];
HandleMouseEvents();
}
- (void)rightMouseUp:(NSEvent *)event
{
_right_button_down = false;
[ self internalMouseButtonEvent ];
HandleMouseEvents();
}
- (void)scrollWheel:(NSEvent *)event

View File

@ -87,6 +87,11 @@ public:
return true;
}
/**
* Fix the mouse position position.
*/
virtual void FixMousePointer(bool fix_at) { _cursor.fix_at = fix_at; }
/**
* Get whether the mouse cursor is drawn by the video driver.
* @return True if cursor drawing is done by the video driver.

View File

@ -2365,7 +2365,7 @@ static EventState HandleViewportScroll()
if (_last_scroll_window == nullptr) _last_scroll_window = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
if (_last_scroll_window == nullptr || !((_settings_client.gui.scroll_mode != VSM_MAP_LMB && _right_button_down) || scrollwheel_scrolling || (_settings_client.gui.scroll_mode == VSM_MAP_LMB && _left_button_down))) {
_cursor.fix_at = false;
VideoDriver::GetInstance()->FixMousePointer(false);
_scrolling_viewport = false;
_last_scroll_window = nullptr;
return ES_NOT_HANDLED;
@ -2820,7 +2820,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
if (vp != nullptr) {
if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
_scrolling_viewport = true;
_cursor.fix_at = true;
VideoDriver::GetInstance()->FixMousePointer(true);
return;
}
@ -2831,7 +2831,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
_scrolling_viewport = true;
_cursor.fix_at = false;
VideoDriver::GetInstance()->FixMousePointer(false);
return;
}
break;
@ -2840,8 +2840,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
_scrolling_viewport = true;
_cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
_settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
VideoDriver::GetInstance()->FixMousePointer(_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
DispatchRightClickEvent(w, x - w->left, y - w->top);
return;
}