mirror of https://github.com/OpenTTD/OpenTTD
Merge f1e310727a
into 3518d7e0f1
commit
febc1bb480
|
@ -332,7 +332,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
|
||||||
|
|
||||||
FixTitleGameZoom();
|
FixTitleGameZoom();
|
||||||
_pause_mode = PM_UNPAUSED;
|
_pause_mode = PM_UNPAUSED;
|
||||||
_cursor.fix_at = false;
|
VideoDriver::GetInstance()->FixMousePointer(false);
|
||||||
|
|
||||||
CheckForMissingGlyphs();
|
CheckForMissingGlyphs();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "core/backup_type.hpp"
|
#include "core/backup_type.hpp"
|
||||||
|
#include "video/video_driver.hpp"
|
||||||
#include "clear_map.h"
|
#include "clear_map.h"
|
||||||
#include "industry.h"
|
#include "industry.h"
|
||||||
#include "station_map.h"
|
#include "station_map.h"
|
||||||
|
@ -1866,7 +1867,9 @@ public:
|
||||||
|
|
||||||
void OnScroll(Point delta) override
|
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)? */
|
/* While tile is at (delta.x, delta.y)? */
|
||||||
int sub;
|
int sub;
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
void ClearSystemSprites() override;
|
void ClearSystemSprites() override;
|
||||||
void PopulateSystemSprites() override;
|
void PopulateSystemSprites() override;
|
||||||
|
|
||||||
|
void FixMousePointer(bool fix_at) override;
|
||||||
void EditBoxLostFocus() override;
|
void EditBoxLostFocus() override;
|
||||||
|
|
||||||
std::vector<int> GetListOfMonitorRefreshRates() override;
|
std::vector<int> GetListOfMonitorRefreshRates() override;
|
||||||
|
|
|
@ -240,6 +240,15 @@ bool VideoDriver_Cocoa::AfterBlitterChange()
|
||||||
return true;
|
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.
|
* An edit box lost the input focus. Abort character compositing if necessary.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -674,15 +674,6 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
||||||
HandleMouseEvents();
|
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
|
- (BOOL)emulateRightButton:(NSEvent *)event
|
||||||
{
|
{
|
||||||
uint32_t keymask = 0;
|
uint32_t keymask = 0;
|
||||||
|
@ -708,7 +699,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
||||||
[ self rightMouseDown:event ];
|
[ self rightMouseDown:event ];
|
||||||
} else {
|
} else {
|
||||||
_left_button_down = true;
|
_left_button_down = true;
|
||||||
[ self internalMouseButtonEvent ];
|
HandleMouseEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- (void)mouseUp:(NSEvent *)event
|
- (void)mouseUp:(NSEvent *)event
|
||||||
|
@ -719,7 +710,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
||||||
} else {
|
} else {
|
||||||
_left_button_down = false;
|
_left_button_down = false;
|
||||||
_left_button_clicked = 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_down = true;
|
||||||
_right_button_clicked = true;
|
_right_button_clicked = true;
|
||||||
[ self internalMouseButtonEvent ];
|
HandleMouseEvents();
|
||||||
}
|
}
|
||||||
- (void)rightMouseUp:(NSEvent *)event
|
- (void)rightMouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
_right_button_down = false;
|
_right_button_down = false;
|
||||||
[ self internalMouseButtonEvent ];
|
HandleMouseEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrollWheel:(NSEvent *)event
|
- (void)scrollWheel:(NSEvent *)event
|
||||||
|
|
|
@ -205,6 +205,20 @@ bool VideoDriver_SDL_Base::ClaimMousePointer()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoDriver_SDL_Base::FixMousePointer(bool fix_at)
|
||||||
|
{
|
||||||
|
if (_cursor.fix_at == fix_at) return;
|
||||||
|
|
||||||
|
this->VideoDriver::FixMousePointer(fix_at);
|
||||||
|
|
||||||
|
SDL_SetRelativeMouseMode(fix_at ? SDL_TRUE : SDL_FALSE);
|
||||||
|
|
||||||
|
if (!fix_at) {
|
||||||
|
/* Move cursor back to where it was before being fixed. */
|
||||||
|
SDL_WarpMouseInWindow(this->sdl_window, _cursor.pos.x, _cursor.pos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called to indicate that an edit box has gained focus, text input mode should be enabled.
|
* This is called to indicate that an edit box has gained focus, text input mode should be enabled.
|
||||||
*/
|
*/
|
||||||
|
@ -385,21 +399,23 @@ bool VideoDriver_SDL_Base::PollEvent()
|
||||||
|
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case SDL_MOUSEMOTION: {
|
case SDL_MOUSEMOTION: {
|
||||||
int32_t x = ev.motion.x;
|
|
||||||
int32_t y = ev.motion.y;
|
|
||||||
|
|
||||||
if (_cursor.fix_at) {
|
if (_cursor.fix_at) {
|
||||||
|
/* Use relative motion events. */
|
||||||
|
int32_t x = ev.motion.xrel;
|
||||||
|
int32_t y = ev.motion.yrel;
|
||||||
|
|
||||||
/* Get all queued mouse events now in case we have to warp the cursor. In the
|
/* Get all queued mouse events now in case we have to warp the cursor. In the
|
||||||
* end, we only care about the current mouse position and not bygone events. */
|
* end, we only care about the current mouse position and not bygone events. */
|
||||||
while (SDL_PeepEvents(&ev, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)) {
|
while (SDL_PeepEvents(&ev, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)) {
|
||||||
x = ev.motion.x;
|
x += ev.motion.xrel;
|
||||||
y = ev.motion.y;
|
y += ev.motion.yrel;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cursor.UpdateCursorPosition(x, y)) {
|
_cursor.UpdateCursorPositionRelative(x, y);
|
||||||
SDL_WarpMouseInWindow(this->sdl_window, _cursor.pos.x, _cursor.pos.y);
|
} else {
|
||||||
|
_cursor.UpdateCursorPosition(ev.motion.x, ev.motion.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleMouseEvents();
|
HandleMouseEvents();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -560,12 +576,10 @@ std::optional<std::string_view> VideoDriver_SDL_Base::Start(const StringList &pa
|
||||||
if (error) return error;
|
if (error) return error;
|
||||||
|
|
||||||
#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
|
#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
|
||||||
if (GetDriverParamBool(param, "no_mouse_capture")) {
|
|
||||||
/* By default SDL captures the mouse, while a button is pressed.
|
/* By default SDL captures the mouse, while a button is pressed.
|
||||||
* This is annoying during debugging, when OpenTTD is suspended while the button was pressed.
|
* This is annoying during debugging, when OpenTTD is suspended while the button was pressed.
|
||||||
*/
|
*/
|
||||||
if (!SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0")) return SDL_GetError();
|
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SDL_HINT_APP_NAME
|
#ifdef SDL_HINT_APP_NAME
|
||||||
|
|
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
bool ClaimMousePointer() override;
|
bool ClaimMousePointer() override;
|
||||||
|
|
||||||
|
void FixMousePointer(bool fix_at) override;
|
||||||
|
|
||||||
void EditBoxGainedFocus() override;
|
void EditBoxGainedFocus() override;
|
||||||
|
|
||||||
void EditBoxLostFocus() override;
|
void EditBoxLostFocus() override;
|
||||||
|
|
|
@ -87,6 +87,11 @@ public:
|
||||||
return true;
|
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.
|
* Get whether the mouse cursor is drawn by the video driver.
|
||||||
* @return True if cursor drawing is done by the video driver.
|
* @return True if cursor drawing is done by the video driver.
|
||||||
|
|
|
@ -2363,7 +2363,7 @@ static EventState HandleViewportScroll()
|
||||||
if (_last_scroll_window == nullptr) _last_scroll_window = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
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))) {
|
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;
|
_scrolling_viewport = false;
|
||||||
_last_scroll_window = nullptr;
|
_last_scroll_window = nullptr;
|
||||||
return ES_NOT_HANDLED;
|
return ES_NOT_HANDLED;
|
||||||
|
@ -2818,7 +2818,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||||
if (vp != nullptr) {
|
if (vp != nullptr) {
|
||||||
if (scrollwheel_scrolling && !w->flags.Test(WindowFlag::DisableVpScroll)) {
|
if (scrollwheel_scrolling && !w->flags.Test(WindowFlag::DisableVpScroll)) {
|
||||||
_scrolling_viewport = true;
|
_scrolling_viewport = true;
|
||||||
_cursor.fix_at = true;
|
VideoDriver::GetInstance()->FixMousePointer(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2829,7 +2829,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||||
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
||||||
_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
|
_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
|
||||||
_scrolling_viewport = true;
|
_scrolling_viewport = true;
|
||||||
_cursor.fix_at = false;
|
VideoDriver::GetInstance()->FixMousePointer(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2838,8 +2838,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||||
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
||||||
_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
|
_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
|
||||||
_scrolling_viewport = true;
|
_scrolling_viewport = true;
|
||||||
_cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
|
VideoDriver::GetInstance()->FixMousePointer(_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
|
||||||
_settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED);
|
|
||||||
DispatchRightClickEvent(w, x - w->left, y - w->top);
|
DispatchRightClickEvent(w, x - w->left, y - w->top);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue