Skip to content

Commit 1dcdc99

Browse files
committed
Correct mouse interactions for game controller
1 parent 07a7ac2 commit 1dcdc99

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

Source/control.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ void DrawInfoBox()
11581158
} else {
11591159
if (pcursitem != -1)
11601160
GetItemStr(pcursitem);
1161-
if (pcursobj != -1)
1161+
else if (pcursobj != -1)
11621162
GetObjectStr(pcursobj);
11631163
if (pcursmonst != -1) {
11641164
if (leveltype != DTYPE_TOWN) {
@@ -1171,7 +1171,7 @@ void DrawInfoBox()
11711171
} else {
11721172
PrintMonstHistory(monster[pcursmonst].MType->mtype);
11731173
}
1174-
} else {
1174+
} else if (pcursitem == -1) {
11751175
strcpy(infostr, towner[pcursmonst]._tName);
11761176
}
11771177
}

SourceS/miniwin/misc.h

+1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ constexpr auto DVL_WM_PAINT = 0x000F;
513513
constexpr auto DVL_WM_CLOSE = 0x0010;
514514
constexpr auto DVL_WM_QUERYENDSESSION = 0x0011;
515515
constexpr auto DVL_WM_ERASEBKGND = 0x0014;
516+
constexpr auto DVL_WM_MOUSEHOVER = 0x02A1;
516517
constexpr auto DVL_WM_QUERYNEWPALETTE = 0x030F;
517518
constexpr auto DVL_WM_PALETTECHANGED = 0x0311;
518519

SourceX/controls/plrctrls.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -503,21 +503,21 @@ void plrctrls_after_check_curs_move()
503503
// check for monsters first, then items, then towners.
504504
if (sgbControllerActive) {
505505
// Clear focuse set by cursor
506-
if (!invflag) {
507-
*infostr = '\0';
508-
ClearPanel();
509-
}
510506
pcursplr = -1;
511507
pcursmonst = -1;
512508
pcursitem = -1;
513509
pcursobj = -1;
510+
if (!invflag) {
511+
*infostr = '\0';
512+
ClearPanel();
514513

515-
// TODO target players if !FriendlyMode
516-
if (leveltype != DTYPE_TOWN)
517-
CheckMonstersNearby();
518-
else
519-
CheckTownersNearby();
520-
CheckItemsNearby();
514+
// TODO target players if !FriendlyMode
515+
if (leveltype != DTYPE_TOWN)
516+
CheckMonstersNearby();
517+
else
518+
CheckTownersNearby();
519+
CheckItemsNearby();
520+
}
521521
}
522522
}
523523

SourceX/miniwin/misc_msg.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ namespace dvl {
1919
static std::deque<MSG> message_queue;
2020

2121
bool mouseWarping = false;
22+
int mouseWarpingX;
23+
int mouseWarpingY;
2224

2325
void SetCursorPos(int X, int Y)
2426
{
27+
mouseWarpingX = X;
28+
mouseWarpingY = Y;
29+
2530
#ifndef USE_SDL1
2631
if (renderer) {
2732
SDL_Rect view;
@@ -37,7 +42,7 @@ void SetCursorPos(int X, int Y)
3742
#endif
3843

3944
mouseWarping = true;
40-
SDL_WarpMouseInWindow(nullptr, X, Y);
45+
SDL_WarpMouseInWindow(window, X, Y);
4146
}
4247

4348
// Moves the mouse to the first attribute "+" button.
@@ -293,8 +298,6 @@ void SetMouseLMBMessage(const SDL_Event &event, LPMSG lpMsg)
293298
// Moves the mouse to the first inventory slot.
294299
void FocusOnInventory()
295300
{
296-
if (!invflag)
297-
return;
298301
SetCursorPos(InvRect[25].X + (INV_SLOT_SIZE_PX / 2), InvRect[25].Y - (INV_SLOT_SIZE_PX / 2));
299302
}
300303

@@ -552,6 +555,16 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
552555
case SDL_WINDOWEVENT:
553556
if (e.window.event == SDL_WINDOWEVENT_CLOSE) {
554557
lpMsg->message = DVL_WM_QUERYENDSESSION;
558+
} else if (e.window.event == SDL_WINDOWEVENT_ENTER) {
559+
lpMsg->message = DVL_WM_MOUSEHOVER;
560+
// Bug in SDL, SDL_WarpMouseInWindow doesn't emit SDL_MOUSEMOTION
561+
// and SDL_GetMouseState gives previous location if mouse was
562+
// outside window (observed on Ubuntu 19.04)
563+
if (mouseWarping) {
564+
MouseX = mouseWarpingX;
565+
MouseY = mouseWarpingY;
566+
mouseWarping = false;
567+
}
555568
} else {
556569
return false_avail();
557570
}

0 commit comments

Comments
 (0)