Skip to content

Commit 7a79bd2

Browse files
authored
Merge pull request #1893 from Farmer-Markus/master
Allow dragging ingameWindows with middle mouse button
2 parents 6e12273 + 8ffa8b4 commit 7a79bd2

11 files changed

Lines changed: 114 additions & 40 deletions

File tree

extras/videoDrivers/SDL2/VideoSDL2.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,29 +392,43 @@ bool VideoSDL2::MessageLoop()
392392
case SDL_MOUSEBUTTONDOWN:
393393
mouse_xy.pos = getGuiScale().screenToView(Position(ev.button.x, ev.button.y));
394394

395-
if(/*!mouse_xy.ldown && */ ev.button.button == SDL_BUTTON_LEFT)
395+
switch(ev.button.button)
396396
{
397-
mouse_xy.ldown = true;
398-
CallBack->Msg_LeftDown(mouse_xy);
399-
}
400-
if(/*!mouse_xy.rdown &&*/ ev.button.button == SDL_BUTTON_RIGHT)
401-
{
402-
mouse_xy.rdown = true;
403-
CallBack->Msg_RightDown(mouse_xy);
397+
case SDL_BUTTON_LEFT:
398+
mouse_xy.ldown = true;
399+
CallBack->Msg_LeftDown(mouse_xy);
400+
break;
401+
402+
case SDL_BUTTON_RIGHT:
403+
mouse_xy.rdown = true;
404+
CallBack->Msg_RightDown(mouse_xy);
405+
break;
406+
407+
case SDL_BUTTON_MIDDLE:
408+
mouse_xy.mdown = true;
409+
CallBack->Msg_MiddleDown(mouse_xy);
410+
break;
404411
}
405412
break;
406413
case SDL_MOUSEBUTTONUP:
407414
mouse_xy.pos = getGuiScale().screenToView(Position(ev.button.x, ev.button.y));
408415

409-
if(/*mouse_xy.ldown &&*/ ev.button.button == SDL_BUTTON_LEFT)
416+
switch(ev.button.button)
410417
{
411-
mouse_xy.ldown = false;
412-
CallBack->Msg_LeftUp(mouse_xy);
413-
}
414-
if(/*mouse_xy.rdown &&*/ ev.button.button == SDL_BUTTON_RIGHT)
415-
{
416-
mouse_xy.rdown = false;
417-
CallBack->Msg_RightUp(mouse_xy);
418+
case SDL_BUTTON_LEFT:
419+
mouse_xy.ldown = false;
420+
CallBack->Msg_LeftUp(mouse_xy);
421+
break;
422+
423+
case SDL_BUTTON_RIGHT:
424+
mouse_xy.rdown = false;
425+
CallBack->Msg_RightUp(mouse_xy);
426+
break;
427+
428+
case SDL_BUTTON_MIDDLE:
429+
mouse_xy.mdown = false;
430+
CallBack->Msg_MiddleUp(mouse_xy);
431+
break;
418432
}
419433
break;
420434
case SDL_MOUSEWHEEL:

extras/videoDrivers/WinAPI/WinAPI.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ const char* GetDriverName()
8585
* @param[in] CallBack DriverCallback für Rückmeldungen.
8686
*/
8787
VideoWinAPI::VideoWinAPI(VideoDriverLoaderInterface* CallBack)
88-
: VideoDriver(CallBack), mouse_l(false), mouse_r(false), mouse_z(0), screen(nullptr), screen_dc(nullptr),
89-
screen_rc(nullptr), isWindowResizable(false), isMinimized(true)
88+
: VideoDriver(CallBack), mouse_z(0), screen(nullptr), screen_dc(nullptr), screen_rc(nullptr),
89+
isWindowResizable(false), isMinimized(true)
9090
{
9191
pVideoWinAPI = this;
9292
}
@@ -665,25 +665,29 @@ LRESULT CALLBACK VideoWinAPI::WindowProc(HWND window, UINT msg, WPARAM wParam, L
665665
pVideoWinAPI->CallBack->Msg_MouseMove(pVideoWinAPI->mouse_xy);
666666
break;
667667
case WM_LBUTTONDOWN:
668-
pVideoWinAPI->mouse_l = true;
669668
pVideoWinAPI->mouse_xy.ldown = true;
670669
pVideoWinAPI->CallBack->Msg_LeftDown(pVideoWinAPI->mouse_xy);
671670
break;
672671
case WM_LBUTTONUP:
673-
pVideoWinAPI->mouse_l = false;
674672
pVideoWinAPI->mouse_xy.ldown = false;
675673
pVideoWinAPI->CallBack->Msg_LeftUp(pVideoWinAPI->mouse_xy);
676674
break;
677675
case WM_RBUTTONDOWN:
678-
pVideoWinAPI->mouse_r = true;
679676
pVideoWinAPI->mouse_xy.rdown = true;
680677
pVideoWinAPI->CallBack->Msg_RightDown(pVideoWinAPI->mouse_xy);
681678
break;
682679
case WM_RBUTTONUP:
683-
pVideoWinAPI->mouse_r = false;
684680
pVideoWinAPI->mouse_xy.rdown = false;
685681
pVideoWinAPI->CallBack->Msg_RightUp(pVideoWinAPI->mouse_xy);
686682
break;
683+
case WM_MBUTTONDOWN:
684+
pVideoWinAPI->mouse_xy.mdown = true;
685+
pVideoWinAPI->CallBack->Msg_MiddleDown(pVideoWinAPI->mouse_xy);
686+
break;
687+
case WM_MBUTTONUP:
688+
pVideoWinAPI->mouse_xy.mdown = false;
689+
pVideoWinAPI->CallBack->Msg_MiddleUp(pVideoWinAPI->mouse_xy);
690+
break;
687691
case WM_MOUSEWHEEL:
688692
// Obtain scrolling distance. For every multiple of WHEEL_DELTA, we have to fire an event, because we treat
689693
// the wheel like two buttons. One wheel "step" usually produces a mouse_z of +/- WHEEL_DELTA. But there

extras/videoDrivers/WinAPI/WinAPI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class VideoWinAPI final : public VideoDriver
8484
static LRESULT CALLBACK WindowProc(HWND window, UINT msg, WPARAM wParam, LPARAM lParam);
8585

8686
private:
87-
bool mouse_l; /// Status der Linken Maustaste.
88-
bool mouse_r; /// Status der Rechten Maustaste.
8987
int mouse_z; /// Scrolling position for mousewheel.
9088
HWND screen; /// Fensterhandle.
9189
HDC screen_dc; /// Zeichenkontext des Fensters.

libs/driver/include/driver/MouseCoords.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct MouseCoords
1616
Position pos = Position(0, 0);
1717
bool ldown = false; /// left button down
1818
bool rdown = false; /// right button down
19+
bool mdown = false; /// middle button down
1920
bool dbl_click = false; /// double-click (left button)
2021
unsigned num_tfingers = 0; /// Count of fingers currently on touchscreen
2122
};

libs/driver/include/driver/VideoDriver.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ class VideoDriver : public IVideoDriver
4949
VideoMode FindClosestVideoMode(const VideoMode& mode) const;
5050
void SetNewSize(VideoMode windowSize, Extent renderSize);
5151

52-
VideoDriverLoaderInterface* CallBack; /// Das DriverCallback für Rückmeldungen.
53-
bool initialized; /// Initialisierungsstatus.
54-
MouseCoords mouse_xy; /// Status der Maus.
55-
std::array<bool, 512> keyboard; /// Status der Tastatur;
56-
bool isFullscreen_; /// Vollbild an/aus?
52+
VideoDriverLoaderInterface* CallBack; /// DriverCallback to notify on player input
53+
bool initialized;
54+
MouseCoords mouse_xy; /// Mouse state
55+
std::array<bool, 512> keyboard; /// Keyboard state
56+
bool isFullscreen_;
57+
5758
private:
5859
// cached as possibly used often
5960
VideoMode windowSize_; ///< Size of the window or fullscreen resolution

libs/driver/include/driver/VideoDriverLoaderInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class BOOST_SYMBOL_VISIBLE VideoDriverLoaderInterface
1717
virtual void Msg_LeftUp(MouseCoords mc) = 0;
1818
virtual void Msg_RightDown(const MouseCoords& mc) = 0;
1919
virtual void Msg_RightUp(const MouseCoords& mc) = 0;
20+
virtual void Msg_MiddleDown(const MouseCoords& mc) = 0;
21+
virtual void Msg_MiddleUp(const MouseCoords& mc) = 0;
2022
virtual void Msg_WheelUp(const MouseCoords& mc) = 0;
2123
virtual void Msg_WheelDown(const MouseCoords& mc) = 0;
2224
virtual void Msg_MouseMove(const MouseCoords& mc) = 0;

libs/s25main/Window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ class Window
222222
virtual void Msg_PaintAfter();
223223
virtual bool Msg_LeftDown(const MouseCoords&) { return false; }
224224
virtual bool Msg_RightDown(const MouseCoords&) { return false; }
225+
virtual bool Msg_MiddleDown(const MouseCoords&) { return false; }
225226
virtual bool Msg_LeftUp(const MouseCoords&) { return false; }
226227
virtual bool Msg_RightUp(const MouseCoords&) { return false; }
228+
virtual bool Msg_MiddleUp(const MouseCoords&) { return false; }
227229
virtual bool Msg_WheelUp(const MouseCoords&) { return false; }
228230
virtual bool Msg_WheelDown(const MouseCoords&) { return false; }
229231
virtual bool Msg_MouseMove(const MouseCoords&) { return false; }

libs/s25main/WindowManager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ void WindowManager::Msg_RightUp(const MouseCoords& mc)
346346
RelayMouseMessage(&Window::Msg_RightUp, mc);
347347
}
348348

349+
void WindowManager::Msg_MiddleDown(const MouseCoords& mc)
350+
{
351+
Window* activeWindow = findAndActivateWindow(mc.pos);
352+
353+
if(activeWindow)
354+
RelayMouseMessage(&Window::Msg_MiddleDown, mc, activeWindow);
355+
}
356+
357+
void WindowManager::Msg_MiddleUp(const MouseCoords& mc)
358+
{
359+
RelayMouseMessage(&Window::Msg_MiddleUp, mc);
360+
}
361+
349362
void WindowManager::Msg_WheelUp(const MouseCoords& mc)
350363
{
351364
RelayMouseMessage(&Window::Msg_WheelUp, mc, findAndActivateWindow(mc.pos));

libs/s25main/WindowManager.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ class WindowManager : public Singleton<WindowManager>, public VideoDriverLoaderI
8787
void CloseNow(IngameWindow* window);
8888
/// merkt einen Desktop zum Wechsel vor.
8989
Desktop* Switch(std::unique_ptr<Desktop> desktop);
90-
/// Verarbeitung des Drückens der Linken Maustaste.
90+
/// Process press of left mouse button
9191
void Msg_LeftDown(MouseCoords mc) override;
92-
/// Verarbeitung des Loslassens der Linken Maustaste.
92+
/// Process release of left mouse button
9393
void Msg_LeftUp(MouseCoords mc) override;
94-
/// Verarbeitung des Drückens der Rechten Maustaste.
95-
void Msg_RightUp(const MouseCoords& mc) override;
96-
/// Verarbeitung des Loslassens der Rechten Maustaste.
94+
/// Process press of right mouse button
9795
void Msg_RightDown(const MouseCoords& mc) override;
96+
/// Process release of right mouse button
97+
void Msg_RightUp(const MouseCoords& mc) override;
98+
/// Process press of middle mouse button
99+
void Msg_MiddleDown(const MouseCoords& mc) override;
100+
/// Process release of middle mouse button
101+
void Msg_MiddleUp(const MouseCoords& mc) override;
98102
/// Verarbeitung des Drückens des Rad hoch.
99103
void Msg_WheelUp(const MouseCoords& mc) override;
100104
/// Verarbeitung Rad runter.

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "IngameWindow.h"
66
#include "CollisionDetection.h"
77
#include "Loader.h"
8+
#include "Point.h"
89
#include "RTTR_Assert.h"
910
#include "Settings.h"
1011
#include "WindowManager.h"
@@ -199,10 +200,7 @@ bool IngameWindow::Msg_LeftDown(const MouseCoords& mc)
199200
buttonStates_[btn] = ButtonState::Pressed;
200201
if(btn == IwButton::Title)
201202
{
202-
// start moving
203-
isMoving = true;
204-
snapOffset_ = SnapOffset::all(0);
205-
lastMousePos = mc.pos;
203+
StartDragging(mc.pos);
206204
return true;
207205
}
208206
}
@@ -212,7 +210,8 @@ bool IngameWindow::Msg_LeftDown(const MouseCoords& mc)
212210

213211
bool IngameWindow::Msg_LeftUp(const MouseCoords& mc)
214212
{
215-
isMoving = false;
213+
// If we handled the msg event. Don't return yet in case touch dblclick triggered dragging
214+
const bool handled = StopDragging();
216215

217216
for(const auto btn : helpers::enumRange<IwButton>())
218217
{
@@ -260,7 +259,18 @@ bool IngameWindow::Msg_LeftUp(const MouseCoords& mc)
260259
Close();
261260
return true;
262261
}
263-
return false;
262+
return handled;
263+
}
264+
265+
bool IngameWindow::Msg_MiddleDown(const MouseCoords& mc)
266+
{
267+
StartDragging(mc.pos);
268+
return true;
269+
}
270+
271+
bool IngameWindow::Msg_MiddleUp(const MouseCoords&)
272+
{
273+
return StopDragging();
264274
}
265275

266276
bool IngameWindow::Msg_MouseMove(const MouseCoords& mc)
@@ -493,3 +503,20 @@ Rect IngameWindow::GetButtonBounds(IwButton btn) const
493503
}
494504
return Rect(pos, size);
495505
}
506+
507+
void IngameWindow::StartDragging(const Position& pos)
508+
{
509+
isMoving = true;
510+
snapOffset_ = SnapOffset::all(0);
511+
lastMousePos = pos;
512+
}
513+
514+
bool IngameWindow::StopDragging()
515+
{
516+
if(isMoving)
517+
{
518+
isMoving = false;
519+
return true;
520+
}
521+
return false;
522+
}

0 commit comments

Comments
 (0)