Skip to content

Commit 62e8eda

Browse files
FlamefireFlow86
authored andcommitted
Convert MouseCoord to plain struct
The only method `GetPos` is no longer required as the `pos` is already a `Point` instance.
1 parent 1f6b512 commit 62e8eda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+172
-153
lines changed
Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
1-
// Copyright (C) 2005 - 2021 Settlers Freaks (sfteam at siedler25.org)
1+
// Copyright (C) 2005 - 2025 Settlers Freaks (sfteam at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

55
#pragma once
66

77
#include "Point.h"
88

9-
///////////////////////////////////////////////////////////////////////////////
10-
/**
11-
* Mausstatusstruct
12-
*
13-
* @author OLiver
14-
*/
15-
class MouseCoords
9+
/// State of mouse buttons and position
10+
struct MouseCoords
1611
{
17-
public:
18-
MouseCoords() : pos(0, 0), ldown(false), rdown(false), dbl_click(false) {}
19-
MouseCoords(int x, int y, bool ldown = false, bool rdown = false, bool dbl_click = false)
20-
: pos(x, y), ldown(ldown), rdown(rdown), dbl_click(dbl_click)
21-
{}
22-
MouseCoords(Position pos, bool ldown = false, bool rdown = false, bool dbl_click = false)
23-
: pos(pos), ldown(ldown), rdown(rdown), dbl_click(dbl_click)
24-
{}
12+
MouseCoords() = default;
13+
MouseCoords(Position pos) : pos(pos) {}
14+
MouseCoords(int x, int y) : pos(x, y) {}
2515

26-
Position pos;
27-
bool ldown; /// Linke Maustaste gedrückt
28-
bool rdown; /// Rechte Maustaste gedrückt
29-
bool dbl_click; /// Linke Maustaste - Doppelklick
30-
31-
Position GetPos() const { return pos; }
16+
Position pos = Position(0, 0);
17+
bool ldown = false; /// left button down
18+
bool rdown = false; /// right button down
19+
bool dbl_click = false; /// double-click (left button)
3220
};
3321

34-
/// Maximale Zeitdifferenz in ms für einen Doppeklick
35-
const unsigned DOUBLE_CLICK_INTERVAL = 500;
22+
/// Maximum interval between two clicks to be considered a double-click (in milliseconds)
23+
constexpr unsigned DOUBLE_CLICK_INTERVAL = 500;

libs/s25main/Window.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
115115
// Use reverse iterator because the topmost (=last elements) should receive the messages first!
116116
for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
117117
{
118-
if(!lockedAreas_.empty() && IsInLockedRegion(mc.GetPos(), wnd))
118+
if(!lockedAreas_.empty() && IsInLockedRegion(mc.pos, wnd))
119119
continue;
120120

121121
if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(mc))
@@ -572,5 +572,5 @@ bool Window::IsMouseOver() const
572572

573573
bool Window::IsMouseOver(const MouseCoords& mousePos) const
574574
{
575-
return IsPointInRect(mousePos.GetPos(), GetBoundaryRect());
575+
return IsPointInRect(mousePos.pos, GetBoundaryRect());
576576
}

libs/s25main/Window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ctrlVarText;
4747
class glArchivItem_Bitmap;
4848
class glFont;
4949
class ITexture;
50-
class MouseCoords;
50+
struct MouseCoords;
5151
enum class GroupSelectType : unsigned;
5252
struct KeyEvent;
5353
struct ScreenResizeEvent;

libs/s25main/WindowManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void WindowManager::Msg_LeftDown(MouseCoords mc)
308308
return;
309309
}
310310

311-
IngameWindow* foundWindow = FindWindowAtPos(mc.GetPos());
311+
IngameWindow* foundWindow = FindWindowAtPos(mc.pos);
312312

313313
// Haben wir ein Fenster gefunden gehabt?
314314
if(foundWindow)
@@ -356,13 +356,13 @@ void WindowManager::Msg_LeftUp(MouseCoords mc)
356356

357357
// Ggf. Doppelklick untersuche
358358
unsigned time_now = VIDEODRIVER.GetTickCount();
359-
if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.GetPos() == lastLeftClickPos)
359+
if(time_now - lastLeftClickTime < DOUBLE_CLICK_INTERVAL && mc.pos == lastLeftClickPos)
360360
{
361361
mc.dbl_click = true;
362362
} else
363363
{
364364
// Werte wieder erneut speichern
365-
lastLeftClickPos = mc.GetPos();
365+
lastLeftClickPos = mc.pos;
366366
lastLeftClickTime = time_now;
367367
}
368368

@@ -410,7 +410,7 @@ void WindowManager::Msg_RightDown(const MouseCoords& mc)
410410
// Right-click closes (most) windows, so check that
411411
if(!windows.empty())
412412
{
413-
IngameWindow* foundWindow = FindWindowAtPos(mc.GetPos());
413+
IngameWindow* foundWindow = FindWindowAtPos(mc.pos);
414414
if(windows.back()->IsModal())
415415
{
416416
// We have a modal window -> Activate it
@@ -503,7 +503,7 @@ void WindowManager::Msg_WheelUp(const MouseCoords& mc)
503503
return;
504504
}
505505

506-
IngameWindow* foundWindow = FindWindowAtPos(mc.GetPos());
506+
IngameWindow* foundWindow = FindWindowAtPos(mc.pos);
507507

508508
if(foundWindow)
509509
{
@@ -550,7 +550,7 @@ void WindowManager::Msg_WheelDown(const MouseCoords& mc)
550550
activeWnd.RelayMouseMessage(&Window::Msg_WheelDown, mc);
551551
return;
552552
}
553-
IngameWindow* foundWindow = FindWindowAtPos(mc.GetPos());
553+
IngameWindow* foundWindow = FindWindowAtPos(mc.pos);
554554

555555
if(foundWindow)
556556
{

libs/s25main/WindowManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Window;
1717
class Desktop;
1818
class IngameWindow;
19-
class MouseCoords;
19+
struct MouseCoords;
2020
struct KeyEvent;
2121
class ctrlBaseTooltip;
2222

libs/s25main/controls/ctrlButton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <string>
1212

13-
class MouseCoords;
13+
struct MouseCoords;
1414

1515
/// Buttonklasse
1616
class ctrlButton : public Window, public ctrlBaseTooltip

libs/s25main/controls/ctrlChat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bool ctrlChat::Msg_LeftUp(const MouseCoords& mc)
235235

236236
bool ctrlChat::Msg_WheelUp(const MouseCoords& mc)
237237
{
238-
if(IsPointInRect(mc.GetPos(), Rect(GetDrawPos() + DrawPoint(2, 2), GetSize() - Extent(2, 4))))
238+
if(IsPointInRect(mc.pos, Rect(GetDrawPos() + DrawPoint(2, 2), GetSize() - Extent(2, 4))))
239239
{
240240
auto* scrollbar = GetCtrl<ctrlScrollBar>(0);
241241
scrollbar->Scroll(-3);
@@ -246,7 +246,7 @@ bool ctrlChat::Msg_WheelUp(const MouseCoords& mc)
246246

247247
bool ctrlChat::Msg_WheelDown(const MouseCoords& mc)
248248
{
249-
if(IsPointInRect(mc.GetPos(), Rect(GetDrawPos() + DrawPoint(2, 2), GetSize() - Extent(2, 4))))
249+
if(IsPointInRect(mc.pos, Rect(GetDrawPos() + DrawPoint(2, 2), GetSize() - Extent(2, 4))))
250250
{
251251
auto* scrollbar = GetCtrl<ctrlScrollBar>(0);
252252
scrollbar->Scroll(+3);

libs/s25main/controls/ctrlChat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Window.h"
88
#include "variant.h"
99
#include <vector>
10-
class MouseCoords;
10+
struct MouseCoords;
1111
class glFont;
1212

1313
/// ChatCtrl-Klasse für ein ChatCtrl.

libs/s25main/controls/ctrlCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ctrlCheck::ctrlCheck(Window* parent, unsigned id, const DrawPoint& pos, const Ex
1919

2020
bool ctrlCheck::Msg_LeftDown(const MouseCoords& mc)
2121
{
22-
if(!readonly && IsPointInRect(mc.GetPos(), GetDrawRect()))
22+
if(!readonly && IsPointInRect(mc.pos, GetDrawRect()))
2323
{
2424
check = !check;
2525
GetParent()->Msg_CheckboxChange(GetID(), check);
@@ -31,7 +31,7 @@ bool ctrlCheck::Msg_LeftDown(const MouseCoords& mc)
3131

3232
bool ctrlCheck::Msg_MouseMove(const MouseCoords& mc)
3333
{
34-
if(IsMouseOver(mc.GetPos()))
34+
if(IsMouseOver(mc.pos))
3535
{
3636
ShowTooltip();
3737
return true;

libs/s25main/controls/ctrlCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Window.h"
88
#include "ctrlBaseTooltip.h"
99
#include <string>
10-
class MouseCoords;
10+
struct MouseCoords;
1111
class glFont;
1212

1313
class ctrlCheck : public Window, public ctrlBaseTooltip

0 commit comments

Comments
 (0)