Skip to content

Commit 6efcb95

Browse files
committed
Integrate the mouse button mapping patch
- Sets final and override qualifiers on the event class - Uses a private and constant button identifier, as it can only be set at construction time. - Deletes the default constructor - Uses the MouseButtonId enum names instead of raw integers
1 parent fb37a0c commit 6efcb95

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

src/gui/sdl_mapper.cpp

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,21 +1704,25 @@ class CKeyEvent final : public CTriggeredEvent {
17041704

17051705
KBD_KEYS key;
17061706
};
1707-
/*
1708-
class CMouseButtonEvent : public CTriggeredEvent {
1707+
1708+
class CMouseButtonEvent final : public CTriggeredEvent {
17091709
public:
1710-
CMouseButtonEvent(char const * const _entry,Bit8u _button) : CTriggeredEvent(_entry) {
1711-
button=_button;
1712-
}
1713-
void Active(bool yesno) {
1714-
if (yesno)
1715-
Mouse_ButtonPressed(button);
1716-
else
1717-
Mouse_ButtonReleased(button);
1710+
CMouseButtonEvent() = delete;
1711+
1712+
CMouseButtonEvent(const char* const entry, const MouseButtonId id)
1713+
: CTriggeredEvent(entry),
1714+
button_id(id)
1715+
{}
1716+
1717+
void Active(const bool pressed) override
1718+
{
1719+
MOUSE_EventButton(button_id, pressed);
17181720
}
1719-
Bit8u button;
1721+
1722+
private:
1723+
const MouseButtonId button_id = MouseButtonId::None;
17201724
};
1721-
*/
1725+
17221726
class CJAxisEvent final : public CContinuousEvent {
17231727
public:
17241728
CJAxisEvent(const char* const entry, Bitu s, Bitu a, bool p,
@@ -2033,16 +2037,18 @@ static CKeyEvent* AddKeyButtonEvent(int32_t x, int32_t y, int32_t dx,
20332037
new CEventButton(x,y,dx,dy,title,event);
20342038
return event;
20352039
}
2036-
/*
2037-
static CMouseButtonEvent * AddMouseButtonEvent(Bitu x,Bitu y,Bitu dx,Bitu dy,char const * const title,char const * const entry,Bit8u button) {
2038-
char buf[64];
2039-
strcpy(buf,"mouse_");
2040-
strcat(buf,entry);
2041-
CMouseButtonEvent * event=new CMouseButtonEvent(buf,button);
2042-
new CEventButton(x,y,dx,dy,title,event);
2040+
2041+
static CMouseButtonEvent* AddMouseButtonEvent(const int32_t x, const int32_t y,
2042+
const int32_t dx, const int32_t dy,
2043+
const char* const title,
2044+
const char* const entry,
2045+
const MouseButtonId button_id)
2046+
{
2047+
auto event = new CMouseButtonEvent(entry, button_id);
2048+
new CEventButton(x, y, dx, dy, title, event);
20432049
return event;
20442050
}
2045-
*/
2051+
20462052
static CJAxisEvent* AddJAxisButton(int32_t x, int32_t y, int32_t dx, int32_t dy,
20472053
const char* const title, Bitu stick, Bitu axis,
20482054
bool positive, CJAxisEvent* opposite_axis)
@@ -2269,17 +2275,36 @@ static void CreateLayout() {
22692275
#undef XO
22702276
#undef YO
22712277

2272-
#if 0
22732278
#define XO 5
22742279
#define YO 8
22752280
/* Mouse Buttons */
2276-
new CTextButton(PX(XO+0),PY(YO-1),3*BW,20,"Mouse");
2277-
AddMouseButtonEvent(PX(XO+0),PY(YO),BW,BH,"L","left",0);
2278-
AddMouseButtonEvent(PX(XO+1),PY(YO),BW,BH,"M","middle",2);
2279-
AddMouseButtonEvent(PX(XO+2),PY(YO),BW,BH,"R","right",1);
2281+
new CTextButton(pos_x(XO + 0), pos_y(YO - 1), 3 * button_width, 20, "Mouse");
2282+
2283+
AddMouseButtonEvent(pos_x(XO + 0),
2284+
pos_y(YO),
2285+
button_width,
2286+
button_height,
2287+
"L",
2288+
"mouse_left",
2289+
MouseButtonId::Left);
2290+
2291+
AddMouseButtonEvent(pos_x(XO + 1),
2292+
pos_y(YO),
2293+
button_width,
2294+
button_height,
2295+
"M",
2296+
"mouse_middle",
2297+
MouseButtonId::Middle);
2298+
2299+
AddMouseButtonEvent(pos_x(XO + 2),
2300+
pos_y(YO),
2301+
button_width,
2302+
button_height,
2303+
"R",
2304+
"mouse_right",
2305+
MouseButtonId::Right);
22802306
#undef XO
22812307
#undef YO
2282-
#endif
22832308

22842309
#define XO 10
22852310
#define YO 8

0 commit comments

Comments
 (0)