529 changes: 209 additions & 320 deletions lib/sdl/main_sdl.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/widget/editbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void W_EDITBOX::run(W_CONTEXT *psContext)
/* If there is a mouse click outside of the edit box - stop editing */
int mx = psContext->mx;
int my = psContext->my;
if (mousePressed(MOUSE_LMB) && !geometry().contains(mx, my))
if (mouseDown(MOUSE_LMB) && !geometry().contains(mx, my))
{
StopTextInput();
screenPointer->setFocus(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/tip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void tipDisplay()
}
else if (newMX != mx ||
newMY != my ||
mousePressed(MOUSE_LMB))
mouseDown(MOUSE_LMB))
{
mx = newMX;
my = newMY;
Expand Down
27 changes: 14 additions & 13 deletions lib/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,28 +808,29 @@ WidgetTriggers const &widgRunScreen(W_SCREEN *psScreen)
lastReleasedKey_DEPRECATED = WKEY_NONE;
if (getWidgetsStatus())
{
MousePresses const &clicks = inputGetClicks();
for (MousePresses::const_iterator c = clicks.begin(); c != clicks.end(); ++c)
for (auto &event : inputGetEvents()) // Spaghetti code, should call inputGetEvents() once, and pass the Events down everywhere needed.
{
WIDGET_KEY wkey;
switch (c->key)
switch (event.button)
{
case MOUSE_LMB: wkey = WKEY_PRIMARY; break;
case MOUSE_RMB: wkey = WKEY_SECONDARY; break;
default: continue; // Who cares about other mouse buttons?
}
bool pressed;
switch (c->action)
sContext.mx = event.pos.x;
sContext.my = event.pos.y;
switch (event.action)
{
case MousePress::Press: pressed = true; break;
case MousePress::Release: pressed = false; break;
default: continue;
case Event::MousePress:
case Event::MouseDoubleClick:
psScreen->psForm->processClickRecursive(&sContext, wkey, true);
break;
case Event::MouseRelease:
lastReleasedKey_DEPRECATED = wkey;
psScreen->psForm->processClickRecursive(&sContext, wkey, false);
break;
default: break;
}
sContext.mx = c->pos.x;
sContext.my = c->pos.y;
psScreen->psForm->processClickRecursive(&sContext, wkey, pressed);

lastReleasedKey_DEPRECATED = wkey;
}
}

Expand Down
49 changes: 18 additions & 31 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,18 @@ void setConsolePermanence(bool state, bool bClearOld)
}

/** Check if mouse is over the Active console 'window' area */
bool mouseOverConsoleBox()
bool mouseOverConsoleBox(Event const &event)
{
int gotMessages = getNumberConsoleMessages();
if (gotMessages &&
((UDWORD)mouseX() > mainConsole.topX)
&& ((UDWORD)mouseY() > mainConsole.topY)
&& ((UDWORD)mouseX() < mainConsole.topX + mainConsole.width)
&& ((UDWORD)mouseY() < (mainConsole.topY + 4 + linePitch * gotMessages)))
{
return true;
}
return false;
return event.type() == Event::Mouse && gotMessages &&
event.pos.x > int(mainConsole.topX) &&
event.pos.y > int(mainConsole.topY) &&
event.pos.x < int(mainConsole.topX + mainConsole.width) &&
event.pos.y < int(mainConsole.topY + 4 + linePitch * gotMessages);
}

/** Check if mouse is over the History console 'window' area */
bool mouseOverHistoryConsoleBox()
bool mouseOverHistoryConsoleBox(Event const &event)
{
int nudgeright = 0;
if (isSecondaryWindowUp())
Expand All @@ -535,34 +531,25 @@ bool mouseOverHistoryConsoleBox()
}
#endif
// check to see if mouse is in the area when console is enabled
if (bConsoleDropped &&
((UDWORD)mouseX() > historyConsole.topX + nudgeright)
&& ((UDWORD)mouseY() > historyConsole.topY)
&& ((UDWORD)mouseX() < historyConsole.topX + historyConsole.width)
&& ((UDWORD)mouseY() < (historyConsole.topY + 4 + linePitch * NumDisplayLines)))
if (event.type() == Event::Mouse && bConsoleDropped &&
event.pos.x > int(historyConsole.topX + nudgeright) &&
event.pos.y > int(historyConsole.topY) &&
event.pos.x < int(historyConsole.topX + historyConsole.width) &&
event.pos.y < int(historyConsole.topY + 4 + linePitch * NumDisplayLines))
{
if (mousePressed(MOUSE_WUP))
if (event.mousePressed(MOUSE_WUP))
{
updatepos--;
}
else if (mousePressed(MOUSE_WDN))
else if (event.mousePressed(MOUSE_WDN))
{
updatepos++;
}
if (keyDown(KEY_LCTRL))
{
showBackgroundColor = true;
}
else
{
showBackgroundColor = false;
}
return (true);
}
else
{
return (false);
// Not sure this is the right place for this. Not sure what it was originally intended to do, but makes a background sometimes appear when pressing Ctrl.
showBackgroundColor = bool(event.flags & Event::Ctrl);
return true;
}
return false;
}

/** Sets up how many lines are allowed and how many are visible */
Expand Down
5 changes: 3 additions & 2 deletions src/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ bool getConsoleDisplayStatus();
void setConsoleSizePos(UDWORD x, UDWORD y, UDWORD width);
void setConsolePermanence(bool state, bool bClearOld);
void clearActiveConsole();
bool mouseOverConsoleBox();
bool mouseOverHistoryConsoleBox();
struct Event;
bool mouseOverConsoleBox(Event const &event);
bool mouseOverHistoryConsoleBox(Event const &event);
int getNumberConsoleMessages();
void setConsoleLineInfo(UDWORD vis);
UDWORD getConsoleLineInfo();
Expand Down
372 changes: 201 additions & 171 deletions src/display.cpp

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
/* Initialise the display system */
bool dispInitialise();

void ProcessRadarInput();

void processInput();
/*don't want to do any of these whilst in the Intelligence Screen*/
CURSOR processMouseClickInput();
CURSOR processMostInput(bool shouldProcessRadar, bool shouldProcessMouseClick);

CURSOR scroll();
void resetScroll();
Expand Down Expand Up @@ -211,7 +207,9 @@ void setSensorAssigned();
void AddDerrickBurningMessage();

// check whether the queue order keys are pressed
bool ctrlShiftDown();
struct Event;
bool ctrlShiftDown(Event const &event);
bool ctrlShiftDown_DEPRECATED();

UDWORD getTargetType();

Expand Down
8 changes: 4 additions & 4 deletions src/edit3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bool process3DBuilding()
//if not trying to build ignore
if (buildState == BUILD3D_NONE)
{
if (quickQueueMode && !ctrlShiftDown())
if (quickQueueMode && !ctrlShiftDown_DEPRECATED())
{
quickQueueMode = false;
intDemolishCancel();
Expand Down Expand Up @@ -214,7 +214,7 @@ bool process3DBuilding()
buildState = BUILD3D_NONE;
return true;
}
if (quickQueueMode && !ctrlShiftDown())
if (quickQueueMode && !ctrlShiftDown_DEPRECATED())
{
buildState = BUILD3D_NONE;
quickQueueMode = false;
Expand All @@ -235,7 +235,7 @@ bool found3DBuilding(UDWORD *x, UDWORD *y)
*x = sBuildDetails.x;
*y = sBuildDetails.y;

if (ctrlShiftDown())
if (ctrlShiftDown_DEPRECATED())
{
quickQueueMode = true;
init3DBuilding(sBuildDetails.psStats, sBuildDetails.CallBack, sBuildDetails.UserData);
Expand Down Expand Up @@ -272,7 +272,7 @@ bool found3DBuildLocTwo(UDWORD *px1, UDWORD *py1, UDWORD *px2, UDWORD *py2)
*px2 = wallDrag.x2;
*py2 = wallDrag.y2;

if (ctrlShiftDown())
if (ctrlShiftDown_DEPRECATED())
{
quickQueueMode = true;
init3DBuilding(sBuildDetails.psStats, sBuildDetails.CallBack, sBuildDetails.UserData);
Expand Down
14 changes: 3 additions & 11 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4876,23 +4876,15 @@ BASE_OBJECT *getCurrentSelected()
}

// Checks if a coordinate is over the build menu
bool CoordInBuild(int x, int y)
bool coordInBuild(Vector2i pos)
{
// This measurement is valid for the menu, so the buildmenu_height
// value is used to "nudge" it all upwards from the command menu.
// FIXME: hardcoded value (?)
const int buildmenu_height = 300;
Vector2f pos;
pos -= Vector2i(RET_X, RET_Y - buildmenu_height); // guesstimation

pos.x = x - RET_X;
pos.y = y - RET_Y + buildmenu_height; // guesstimation

if ((pos.x < 0 || pos.y < 0 || pos.x >= RET_FORMWIDTH || pos.y >= buildmenu_height) || !SecondaryWindowUp)
{
return false;
}

return true;
return pos.x >= 0 && pos.y >= 0 && pos.x < RET_FORMWIDTH && pos.y < buildmenu_height && SecondaryWindowUp;
}

// Our chat dialog for global & team communication
Expand Down
4 changes: 2 additions & 2 deletions src/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ extern iIMDShape *pNewDesignIMD;
/* Initialise the in game interface */
bool intInitialise();

// Check of coordinate is in the build menu
bool CoordInBuild(int x, int y);
// Check if coordinate is in the build menu
bool coordInBuild(Vector2i pos);

/* Shut down the in game interface */
void interfaceShutDown();
Expand Down
4 changes: 2 additions & 2 deletions src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2668,11 +2668,11 @@ void kf_AddHelpBlip()
debug(LOG_WZ, "Adding beacon='%s'", sCurrentConsoleText);

/* check if clicked on radar */
x = mouseX();
x = mouseX(); // If mouse moved between pressing Alt+H and processing the event, these coords may be wrong.
y = mouseY();
if (radarOnScreen && radarPermitted)
{
if (CoordInRadar(x, y))
if (coordInRadar({x, y}))
{
mOverR = true;
CalcRadarPosition(x, y, &worldX, &worldY);
Expand Down
193 changes: 51 additions & 142 deletions src/keymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "keyedit.h"

static UDWORD asciiKeyCodeToTable(KEY_CODE code);
static KEY_CODE getQwertyKey();

// ----------------------------------------------------------------------------------
KEY_MAPPING *keyGetMappingFromFunction(void (*function)())
Expand Down Expand Up @@ -74,7 +73,7 @@ static bool bWantDebugMappings[MAX_PLAYERS] = {false};
std::list<KEY_MAPPING> keyMappings;

/* Last meta and sub key that were recorded */
static KEY_CODE lastMetaKey, lastSubKey;
static KEY_CODE lastSubKey;

// ----------------------------------------------------------------------------------
// Adding a mapped function ? add a save pointer! Thank AlexL.
Expand Down Expand Up @@ -537,45 +536,35 @@ static bool keyRemoveMappingPt(KEY_MAPPING *psToRemove)

// ----------------------------------------------------------------------------------
/* Allows _new_ mappings to be made at runtime */
static bool checkQwertyKeys()
static void checkQwertyKeys(Event const &event)
{
KEY_CODE qKey;
UDWORD tableEntry;
bool aquired = false;

/* Are we trying to make a new map marker? */
if (keyDown(KEY_LALT))
/* Did we press a key */
if (event.action == Event::KeyPress && (event.flags & Event::Alt) && (event.key >= KEY_A && event.key <= KEY_Z))
{
/* Did we press a key */
qKey = getQwertyKey();
if (qKey)
unsigned tableEntry = asciiKeyCodeToTable(event.key);
/* We're assigning something to the key */
debug(LOG_NEVER, "Assigning keymapping to tableEntry: %i", tableEntry);
if (qwertyKeyMappings[tableEntry].psMapping)
{
tableEntry = asciiKeyCodeToTable(qKey);
/* We're assigning something to the key */
debug(LOG_NEVER, "Assigning keymapping to tableEntry: %i", tableEntry);
if (qwertyKeyMappings[tableEntry].psMapping)
{
/* Get rid of the old mapping on this key if there was one */
keyRemoveMappingPt(qwertyKeyMappings[tableEntry].psMapping);
}
/* Now add the new one for this location */
qwertyKeyMappings[tableEntry].psMapping =
keyAddMapping(KEYMAP_ALWAYS, KEY_LSHIFT, qKey, KEYMAP_PRESSED, kf_JumpToMapMarker, "Jump to new map marker");
aquired = true;

/* Store away the position and view angle */
qwertyKeyMappings[tableEntry].xPos = player.p.x;
qwertyKeyMappings[tableEntry].yPos = player.p.z;
qwertyKeyMappings[tableEntry].spin = player.r.y;
/* Get rid of the old mapping on this key if there was one */
keyRemoveMappingPt(qwertyKeyMappings[tableEntry].psMapping);
}
/* Now add the new one for this location */
qwertyKeyMappings[tableEntry].psMapping =
keyAddMapping(KEYMAP_ALWAYS, KEY_LSHIFT, event.key, KEYMAP_PRESSED, kf_JumpToMapMarker, "Jump to new map marker");

/* Store away the position and view angle */
qwertyKeyMappings[tableEntry].xPos = player.p.x;
qwertyKeyMappings[tableEntry].yPos = player.p.z;
qwertyKeyMappings[tableEntry].spin = player.r.y;
}
return aquired;
}


// ----------------------------------------------------------------------------------
/* Manages update of all the active function mappings */
void keyProcessMappings(bool bExclude)
void keyProcessMappings(Event const &event, bool bExclude)
{
/* Bomb out if there are none */
if (keyMappings.empty())
Expand All @@ -584,12 +573,7 @@ void keyProcessMappings(bool bExclude)
}

/* Jump out if we've got a new mapping */
(void) checkQwertyKeys();

/* Check for the meta keys */
bool bMetaKeyDown = keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL) || keyDown(KEY_LALT)
|| keyDown(KEY_RALT) || keyDown(KEY_LSHIFT) || keyDown(KEY_RSHIFT)
|| keyDown(KEY_LMETA) || keyDown(KEY_RMETA);
checkQwertyKeys(event);

/* Run through all our mappings */
for (auto keyToProcess = keyMappings.begin(); keyToProcess != keyMappings.end(); ++keyToProcess)
Expand All @@ -610,14 +594,29 @@ void keyProcessMappings(bool bExclude)
continue;
}

if (keyToProcess->metaKeyCode == KEY_IGNORE && !bMetaKeyDown &&
!(keyToProcess->status == KEYMAP__DEBUG && !getDebugMappingStatus()))
if (keyToProcess->status == KEYMAP__DEBUG && !getDebugMappingStatus())
{
continue;
}

unsigned mask = 0;
switch (keyToProcess->metaKeyCode)
{
default:
case KEY_IGNORE: break;
case KEY_LCTRL: case KEY_RCTRL: mask |= Event::Ctrl; break;
case KEY_LALT: case KEY_RALT: mask |= Event::Alt; break;
case KEY_LSHIFT: case KEY_RSHIFT: mask |= Event::Shift; break;
case KEY_LMETA: case KEY_RMETA: mask |= Event::Meta; break;
}

if ((event.flags & mask) || (!event.flags && !mask))
{
switch (keyToProcess->action)
{
case KEYMAP_PRESSED:
/* Were the right keys pressed? */
if (keyPressed(keyToProcess->subKeyCode))
if (event.keyPressed(keyToProcess->subKeyCode))
{
lastSubKey = keyToProcess->subKeyCode;
/* Jump to the associated function call */
Expand All @@ -626,7 +625,7 @@ void keyProcessMappings(bool bExclude)
break;
case KEYMAP_DOWN:
/* Is the key Down? */
if (keyDown(keyToProcess->subKeyCode))
if (event.action == Event::FrameNew && keyDown(keyToProcess->subKeyCode))
{
lastSubKey = keyToProcess->subKeyCode;
/* Jump to the associated function call */
Expand All @@ -636,7 +635,7 @@ void keyProcessMappings(bool bExclude)
break;
case KEYMAP_RELEASED:
/* Has the key been released? */
if (keyReleased(keyToProcess->subKeyCode))
if (event.keyReleased(keyToProcess->subKeyCode))
{
lastSubKey = keyToProcess->subKeyCode;
/* Jump to the associated function call */
Expand All @@ -650,88 +649,19 @@ void keyProcessMappings(bool bExclude)
break;
}
}
/* Process the combi ones */
if ((keyToProcess->metaKeyCode != KEY_IGNORE && bMetaKeyDown) &&
!(keyToProcess->status == KEYMAP__DEBUG && !getDebugMappingStatus()))
{
/* It's a combo keypress - one held down and the other pressed */
if (keyDown(keyToProcess->metaKeyCode) && keyPressed(keyToProcess->subKeyCode))
{
lastMetaKey = keyToProcess->metaKeyCode;
lastSubKey = keyToProcess->subKeyCode;
keyToProcess->function();
}
else if (keyToProcess->altMetaKeyCode != KEY_IGNORE)
{
if (keyDown(keyToProcess->altMetaKeyCode) && keyPressed(keyToProcess->subKeyCode))
{
lastMetaKey = keyToProcess->metaKeyCode;
lastSubKey = keyToProcess->subKeyCode;
keyToProcess->function();
}
}
}
}

/* Script callback - find out what meta key was pressed */
int pressedMetaKey = KEY_IGNORE;

/* getLastMetaKey() can't be used here, have to do manually */
if (keyDown(KEY_LCTRL))
{
pressedMetaKey = KEY_LCTRL;
}
else if (keyDown(KEY_RCTRL))
{
pressedMetaKey = KEY_RCTRL;
}
else if (keyDown(KEY_LALT))
{
pressedMetaKey = KEY_LALT;
}
else if (keyDown(KEY_RALT))
{
pressedMetaKey = KEY_RALT;
}
else if (keyDown(KEY_LSHIFT))
{
pressedMetaKey = KEY_LSHIFT;
}
else if (keyDown(KEY_RSHIFT))
{
pressedMetaKey = KEY_RSHIFT;
}
else if (keyDown(KEY_LMETA))
{
pressedMetaKey = KEY_LMETA;
}
else if (keyDown(KEY_RMETA))
{
pressedMetaKey = KEY_RMETA;
}

/* Find out what keys were pressed */
for (int i = 0; i < KEY_MAXSCAN; i++)
{
/* Skip meta keys */
switch (i)
{
case KEY_LCTRL:
case KEY_RCTRL:
case KEY_LALT:
case KEY_RALT:
case KEY_LSHIFT:
case KEY_RSHIFT:
case KEY_LMETA:
case KEY_RMETA:
continue;
break;
}
/* Script callback - find out what meta key was pressed */
int pressedMetaKey =
event.flags & Event::Ctrl? KEY_LCTRL :
event.flags & Event::Alt? KEY_LALT :
event.flags & Event::Shift? KEY_LSHIFT :
event.flags & Event::Meta? KEY_LMETA : KEY_IGNORE;

/* Let scripts process this key if it's pressed */
if (keyPressed((KEY_CODE)i))
/* Find out what keys were pressed */
if (event.action == Event::KeyPress && !event.keySpecial())
{
triggerEventKeyPressed(pressedMetaKey, i);
/* Let scripts process this key if it's pressed */
triggerEventKeyPressed(pressedMetaKey, event.key);
}
}
}
Expand Down Expand Up @@ -779,13 +709,6 @@ KEY_CODE getLastSubKey()
return lastSubKey;
}

// ----------------------------------------------------------------------------------
/* Returns the key code of the last meta key pressed - allows called functions to have a simple stack */
KEY_CODE getLastMetaKey()
{
return lastMetaKey;
}


static const KEY_CODE qwertyCodes[26] =
{
Expand All @@ -800,20 +723,6 @@ static const KEY_CODE qwertyCodes[26] =
// +---+ +---+ +---+ +---+ +---+ +---+ +---+
};

/* Returns the key code of the first ascii key that its finds has been PRESSED */
static KEY_CODE getQwertyKey()
{
for (KEY_CODE code : qwertyCodes)
{
if (keyPressed(code))
{
return code; // Top-, middle- or bottom-row key pressed.
}
}

return (KEY_CODE)0; // no ascii key pressed
}

// ----------------------------------------------------------------------------------
/* Returns the number (0 to 26) of a key on the keyboard
from it's keycode. Q is zero, through to M being 25
Expand All @@ -829,7 +738,7 @@ UDWORD asciiKeyCodeToTable(KEY_CODE code)
}
}

ASSERT(false, "only pass nonzero key codes from getQwertyKey to this function");
ASSERT(false, "only pass nonzero key codes from KEY_A to KEY_Z to this function");
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions src/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ struct KEY_MAPPING
KEY_MAPPING *keyAddMapping(KEY_STATUS status, KEY_CODE metaCode, KEY_CODE subcode, KEY_ACTION action, void (*pKeyMapFunc)(), const char *name);
KEY_MAPPING *keyGetMappingFromFunction(void (*function)());
KEY_MAPPING *keyFindMapping(KEY_CODE metaCode, KEY_CODE subCode);
void keyProcessMappings(bool bExclude);
void keyProcessMappings(Event const &event, bool bExclude);
void keyInitMappings(bool bForceDefaults);
KEY_CODE getLastSubKey();
KEY_CODE getLastMetaKey();
void processDebugMappings(unsigned player, bool val);
bool getDebugMappingStatus();
bool getWantedDebugMappingStatus(unsigned player);
Expand Down
30 changes: 13 additions & 17 deletions src/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static GAMECODE renderLoop()
{
if (dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING
&& (intRetVal == INT_INTERCEPT
|| (radarOnScreen && CoordInRadar(mouseX(), mouseY()) && radarPermitted)))
|| (radarOnScreen && coordInRadar({mouseX(), mouseY()}) && radarPermitted)))
{
// Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor()
wzSetCursor(CURSOR_DEFAULT);
Expand Down Expand Up @@ -301,20 +301,13 @@ static GAMECODE renderLoop()
{
if (!gameUpdatePaused())
{
if (dragBox3D.status != DRAG_DRAGGING
bool shouldProcessRadar = dragBox3D.status != DRAG_DRAGGING
&& wallDrag.status != DRAG_DRAGGING
&& intRetVal != INT_INTERCEPT)
{
ProcessRadarInput();
}
processInput();

//no key clicks or in Intelligence Screen
if (!isMouseOverRadar() && intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp)
{
CURSOR cursor2 = processMouseClickInput();
cursor = cursor2 == CURSOR_DEFAULT? cursor : cursor2;
}
&& intRetVal != INT_INTERCEPT;
// Is shouldProcessMouseClick named correctly?
bool shouldProcessMouseClick = intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp;
auto cursor2 = processMostInput(shouldProcessRadar, shouldProcessMouseClick);
cursor = cursor2 == CURSOR_DEFAULT? cursor : cursor2;
displayWorld();
}
wzPerfBegin(PERF_GUI, "User interface");
Expand Down Expand Up @@ -344,10 +337,13 @@ static GAMECODE renderLoop()
if (!quitting)
{
/* Check for toggling display mode */
if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN))
for (auto &event : inputGetEvents())
{
war_setFullscreen(!war_getFullscreen());
wzToggleFullscreen();
if (event.keyPressed(KEY_RETURN) && (event.flags & Event::Alt))
{
war_setFullscreen(!war_getFullscreen());
wzToggleFullscreen();
}
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,24 +633,18 @@ static void DrawRadarExtras(const glm::mat4 &modelViewProjectionMatrix)
RenderWindowFrame(FRAME_RADAR, -1, -1, radarWidth + 2, radarHeight + 2, modelViewProjectionMatrix);
}

/** Does a screen coordinate lie within the radar area? */
bool CoordInRadar(int x, int y)
/// Does a screen coordinate lie within the radar area?
bool coordInRadar(Vector2i pos_)
{
Vector2f pos;
pos.x = x - radarCenterX;
pos.y = y - radarCenterY;
Vector2f pos = pos_ - Vector2i(radarCenterX, radarCenterY);
if (rotateRadar)
{
pos = Vector2f_Rotate2f(pos, -player.r.y);
}
pos.x += radarWidth / 2.0;
pos.y += radarHeight / 2.0;

if (pos.x < 0 || pos.y < 0 || pos.x >= radarWidth || pos.y >= radarHeight)
{
return false;
}
return true;
return pos.x >= 0 && pos.y >= 0 && pos.x < radarWidth && pos.y < radarHeight;
}

void radarColour(UDWORD tileNumber, uint8_t r, uint8_t g, uint8_t b)
Expand Down
2 changes: 1 addition & 1 deletion src/radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void drawRadar(); ///< Draw the minimap on the screen.
void CalcRadarPosition(int mX, int mY, int *PosX, int *PosY); ///< Given a position within the radar, returns a world coordinate.
void SetRadarZoom(uint8_t ZoomLevel); ///< Set current zoom level. 1.0 is 1:1 resolution.
uint8_t GetRadarZoom(); ///< Get current zoom level.
bool CoordInRadar(int x, int y); ///< Is screen coordinate inside minimap?
bool coordInRadar(Vector2i pos); ///< Is screen coordinate inside minimap?

/** Different mini-map draw modes. */
enum RADAR_DRAW_MODE
Expand Down