Skip to content

Commit ed75cc4

Browse files
committed
Added ingameWindow dragging with middle mouse button
1 parent 6db0673 commit ed75cc4

11 files changed

Lines changed: 72 additions & 14 deletions

File tree

extras/videoDrivers/SDL2/VideoSDL2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ bool VideoSDL2::MessageLoop()
402402
mouse_xy.rdown = true;
403403
CallBack->Msg_RightDown(mouse_xy);
404404
}
405+
if(ev.button.button == SDL_BUTTON_MIDDLE)
406+
{
407+
mouse_xy.mdown = true;
408+
CallBack->Msg_MiddleDown(mouse_xy);
409+
}
405410
break;
406411
case SDL_MOUSEBUTTONUP:
407412
mouse_xy.pos = getGuiScale().screenToView(Position(ev.button.x, ev.button.y));
@@ -416,6 +421,11 @@ bool VideoSDL2::MessageLoop()
416421
mouse_xy.rdown = false;
417422
CallBack->Msg_RightUp(mouse_xy);
418423
}
424+
if(ev.button.button == SDL_BUTTON_MIDDLE)
425+
{
426+
mouse_xy.mdown = false;
427+
CallBack->Msg_MiddleUp(mouse_xy);
428+
}
419429
break;
420430
case SDL_MOUSEWHEEL:
421431
{

extras/videoDrivers/WinAPI/WinAPI.cpp

Lines changed: 10 additions & 2 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_l(false), mouse_r(false), mouse_m(false), mouse_z(0), screen(nullptr),
89+
screen_dc(nullptr), screen_rc(nullptr), isWindowResizable(false), isMinimized(true)
9090
{
9191
pVideoWinAPI = this;
9292
}
@@ -684,6 +684,14 @@ LRESULT CALLBACK VideoWinAPI::WindowProc(HWND window, UINT msg, WPARAM wParam, L
684684
pVideoWinAPI->mouse_xy.rdown = false;
685685
pVideoWinAPI->CallBack->Msg_RightUp(pVideoWinAPI->mouse_xy);
686686
break;
687+
case WM_MBUTTONDOWN:
688+
pVideoWinAPI->mouse_m = true;
689+
pVideoWinAPI->mouse_xy.mdown = true;
690+
pVideoWinAPI->CallBack->Msg_MiddleDown(pVideoWinAPI->mouse_xy);
691+
case WM_MBUTTONUP:
692+
pVideoWinAPI->mouse_m = false;
693+
pVideoWinAPI->mouse_xy.mdown = false;
694+
pVideoWinAPI->CallBack->Msg_MiddleUp(pVideoWinAPI->mouse_xy);
687695
case WM_MOUSEWHEEL:
688696
// Obtain scrolling distance. For every multiple of WHEEL_DELTA, we have to fire an event, because we treat
689697
// 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ 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.
87+
bool mouse_l; /// State of left mouse button
88+
bool mouse_r; /// State of right mouse button
89+
bool mouse_m; /// State of middle mouse button
8990
int mouse_z; /// Scrolling position for mousewheel.
9091
HWND screen; /// Fensterhandle.
9192
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ bool IngameWindow::Msg_LeftUp(const MouseCoords& mc)
263263
return false;
264264
}
265265

266+
bool IngameWindow::Msg_MiddleDown(const MouseCoords& mc)
267+
{
268+
isMoving = true;
269+
snapOffset_ = SnapOffset::all(0);
270+
lastMousePos = mc.pos;
271+
return true;
272+
}
273+
274+
bool IngameWindow::Msg_MiddleUp(const MouseCoords&)
275+
{
276+
isMoving = false;
277+
return false;
278+
}
279+
266280
bool IngameWindow::Msg_MouseMove(const MouseCoords& mc)
267281
{
268282
if(isMoving)

0 commit comments

Comments
 (0)