Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
03b3104
Run menu in absolute cursor mode to match OS
beholdnec Dec 30, 2022
b9bb379
Switch away from relative mode in escape menu and PDA
beholdnec Dec 31, 2022
04c124d
Add new TFE_Input::setMouseCursorMode function
beholdnec Dec 31, 2022
e466986
Correctly position cursor in Agent and mission menu
beholdnec Jan 2, 2023
37fc784
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Jan 2, 2023
641d3c1
Fix OS cursor being shown when it shouldn't be visible
beholdnec Jan 2, 2023
acb372b
Fix cursor not being set to absolute mode in PDA
beholdnec Jan 2, 2023
80f763d
Attempt to warp cursor to center when opening menu (this doesn't work…
beholdnec Jan 3, 2023
7b6b876
Fix cursor positioning in escape menu (probably breaks in widescreen …
beholdnec Jan 4, 2023
417163c
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Jan 4, 2023
4f545da
Don't draw cursor when mouse leaves window
beholdnec Jan 4, 2023
8d6eed5
Use absolute mouse mode by default; Cursor can now leave window durin…
beholdnec Jan 4, 2023
a9afca7
Factor out display rect calculation to new function in render backend
beholdnec Jan 4, 2023
bbf32c7
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Jan 17, 2023
f295abc
Fix compile error
beholdnec Jan 17, 2023
4b5c581
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Jan 30, 2023
9dc3ec7
Fix compiler errors after merge
beholdnec Jan 30, 2023
9ede59c
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Feb 8, 2023
a668f4b
Merge remote-tracking branch 'origin/master' into absolute-menu-cursor
beholdnec Feb 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion TheForceEngine/TFE_DarkForces/GameUI/agentMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ namespace TFE_DarkForces
void agentMenu_blit()
{
setPalette();
menu_blitCursor(s_cursorPos.x, s_cursorPos.z, s_framebuffer);
if (TFE_Input::isMouseInWindow())
{
menu_blitCursor(s_cursorPos.x, s_cursorPos.z, s_framebuffer);
}
menu_blitToScreen(s_framebuffer);
}

Expand Down
59 changes: 32 additions & 27 deletions TheForceEngine/TFE_DarkForces/GameUI/escapeMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include <cstring>

#include <SDL.h>

#include "escapeMenu.h"
#include "delt.h"
#include "uiDraw.h"
#include <TFE_DarkForces/agent.h>
#include <TFE_DarkForces/util.h>
#include <TFE_DarkForces/hud.h>
#include <TFE_DarkForces/config.h>
#include <TFE_DarkForces/Landru/lrect.h>
#include <TFE_Game/reticle.h>
#include <TFE_Archive/archive.h>
#include <TFE_Settings/settings.h>
Expand All @@ -18,6 +21,7 @@
#include <TFE_Jedi/Level/rtexture.h>
#include <TFE_Jedi/Level/roffscreenBuffer.h>
#include <TFE_System/system.h>
#include <TFE_Ui/ui.h>

using namespace TFE_Jedi;
using namespace TFE_Input;
Expand Down Expand Up @@ -237,6 +241,8 @@ namespace TFE_DarkForces

void escapeMenu_open(u8* framebuffer, u8* palette)
{
TFE_Input::setMouseCursorMode(MCURSORMODE_ABSOLUTE);

// TFE
reticle_enable(false);

Expand All @@ -256,13 +262,20 @@ namespace TFE_DarkForces
s_emState.escMenuOpen = JFALSE;
}

void escapeMenu_close()
void escapeMenu_close(EscapeMenuAction action)
{
s_emState.escMenuOpen = JFALSE;
// Avoid sound pops due to buffered sound when returning to the Agent or Main menu.
if (!s_levelComplete || action != ESC_ABORT_OR_NEXT)
{
clearBufferedSound();
}
resumeLevelSound();

// TFE
reticle_enable(true);

TFE_Input::setMouseCursorMode(MCURSORMODE_RELATIVE);
}

JBool escapeMenu_isOpen()
Expand Down Expand Up @@ -375,7 +388,7 @@ namespace TFE_DarkForces
}

// Draw the mouse.
if (drawMouse)
if (drawMouse && TFE_Input::isMouseInWindow())
{
screenGPU_blitTextureScaled(&s_cursor.texture, nullptr, intToFixed16(s_emState.cursorPos.x), intToFixed16(s_emState.cursorPos.z), xScale, yScale, 31);
}
Expand Down Expand Up @@ -445,8 +458,11 @@ namespace TFE_DarkForces
blitDeltaFrame(&s_emState.confirmMenuFrames[s_emState.buttonPressed == CONFIRM_NO ? CONFIRM_QUIT_NOBTN_DOWN : CONFIRM_QUIT_NOBTN_UP], 0, 0, s_emState.framebuffer);
}

// Draw the mouse.
blitDeltaFrame(&s_cursor, s_emState.cursorPos.x, s_emState.cursorPos.z, s_emState.framebuffer);
if (drawMouse && TFE_Input::isMouseInWindow())
{
// Draw the mouse.
blitDeltaFrame(&s_cursor, s_emState.cursorPos.x, s_emState.cursorPos.z, s_emState.framebuffer);
}
}
else
{
Expand Down Expand Up @@ -510,7 +526,7 @@ namespace TFE_DarkForces
}

// Draw the mouse.
if (drawMouse)
if (drawMouse && TFE_Input::isMouseInWindow())
{
blitDeltaFrameScaled(&s_cursor, s_emState.cursorPos.x, s_emState.cursorPos.z, xScale, yScale, s_emState.framebuffer);
}
Expand All @@ -524,16 +540,7 @@ namespace TFE_DarkForces
EscapeMenuAction action = escapeMenu_updateUI();
if (action != ESC_CONTINUE)
{
s_emState.escMenuOpen = JFALSE;
// Avoid sound pops due to buffered sound when returning to the Agent or Main menu.
if (!s_levelComplete || action != ESC_ABORT_OR_NEXT)
{
clearBufferedSound();
}
resumeLevelSound();

// TFE
reticle_enable(true);
escapeMenu_close(action);
}

escapeMenu_draw(JTRUE, JTRUE);
Expand Down Expand Up @@ -739,9 +746,12 @@ namespace TFE_DarkForces
DisplayInfo displayInfo;
TFE_RenderBackend::getDisplayInfo(&displayInfo);

s_emState.cursorPosAccum = { (s32)displayInfo.width >> 1, (s32)displayInfo.height >> 1 };
s_emState.cursorPosAccum = { (s32)displayInfo.width / 2, (s32)displayInfo.height / 2 };
s_emState.cursorPos.x = clamp(s_emState.cursorPosAccum.x * (s32)height / (s32)displayInfo.height, 0, (s32)width - 3);
s_emState.cursorPos.z = clamp(s_emState.cursorPosAccum.z * (s32)height / (s32)displayInfo.height, 0, (s32)height - 3);

// FIXME: this doesn't center the cursor correctly
SDL_WarpMouseInWindow(TFE_Ui::getSDLWindow(), s_emState.cursorPos.x, s_emState.cursorPos.z);
}

void escMenu_handleMousePosition()
Expand All @@ -758,19 +768,14 @@ namespace TFE_DarkForces
MonitorInfo monitorInfo;
TFE_RenderBackend::getCurrentMonitorInfo(&monitorInfo);

LRect displayRect = TFE_RenderBackend::calcDisplayRect();

s32 mx, my;
TFE_Input::getMousePos(&mx, &my);
s_emState.cursorPosAccum = { mx, my };

if (displayInfo.width >= displayInfo.height)
{
s_emState.cursorPos.x = clamp(s_emState.cursorPosAccum.x * (s32)height / (s32)displayInfo.height, 0, (s32)width - 3);
s_emState.cursorPos.z = clamp(s_emState.cursorPosAccum.z * (s32)height / (s32)displayInfo.height, 0, (s32)height - 3);
}
else
{
s_emState.cursorPos.x = clamp(s_emState.cursorPosAccum.x * (s32)width / (s32)displayInfo.width, 0, (s32)width - 3);
s_emState.cursorPos.z = clamp(s_emState.cursorPosAccum.z * (s32)width / (s32)displayInfo.width, 0, (s32)height - 3);
}
s_emState.cursorPos = {
interpolate(mx, displayRect.left, displayRect.right, 0, width),
interpolate(my, displayRect.top, displayRect.bottom, 0, height),
};
}
}
2 changes: 1 addition & 1 deletion TheForceEngine/TFE_DarkForces/GameUI/escapeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace TFE_DarkForces

// Opens the escape menu, which sets up the background.
void escapeMenu_open(u8* framebuffer, u8* palette);
void escapeMenu_close();
void escapeMenu_close(EscapeMenuAction action);
void escapeMenu_resetLevel();

// Returns JTRUE if the escape menu is open.
Expand Down
40 changes: 28 additions & 12 deletions TheForceEngine/TFE_DarkForces/GameUI/menu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <cstring>

#include <SDL.h>

#include "menu.h"
#include "delt.h"
#include "uiDraw.h"
Expand All @@ -17,6 +19,7 @@
#include <TFE_System/system.h>
#include <TFE_Jedi/Renderer/virtualFramebuffer.h>
#include <TFE_Jedi/Renderer/screenDraw.h>
#include <TFE_Ui/ui.h>

using namespace TFE_Jedi;

Expand Down Expand Up @@ -59,20 +62,16 @@ namespace TFE_DarkForces
s32 width = bounds.right - bounds.left;
s32 height = bounds.bottom - bounds.top;

LRect displayRect = TFE_RenderBackend::calcDisplayRect();

s32 mx, my;
TFE_Input::getMousePos(&mx, &my);
s_cursorPosAccum = { 12*mx/10, my }; // Account for 320x200 in 4:3 scaling.

if (displayInfo.width >= displayInfo.height)
{
s_cursorPos.x = clamp(s_cursorPosAccum.x * (s32)height / (s32)displayInfo.height, 0, (s32)width - 3);
s_cursorPos.z = clamp(s_cursorPosAccum.z * (s32)height / (s32)displayInfo.height, 0, (s32)height - 3);
}
else
{
s_cursorPos.x = clamp(s_cursorPosAccum.x * (s32)width / (s32)displayInfo.width, 0, (s32)width - 3);
s_cursorPos.z = clamp(s_cursorPosAccum.z * (s32)width / (s32)displayInfo.width, 0, (s32)height - 3);
}
s_cursorPosAccum = {
interpolate(mx, displayRect.left, displayRect.right, bounds.left, bounds.right),
interpolate(my, displayRect.top, displayRect.bottom, bounds.top, bounds.bottom),
};
s_cursorPos = s_cursorPosAccum;
}

void menu_resetCursor()
Expand All @@ -84,19 +83,36 @@ namespace TFE_DarkForces
DisplayInfo displayInfo;
TFE_RenderBackend::getDisplayInfo(&displayInfo);

s_cursorPosAccum = { (s32)displayInfo.width >> 1, (s32)displayInfo.height >> 1 };
s_cursorPosAccum = { (s32)displayInfo.width / 2, (s32)displayInfo.height / 2 };
s_cursorPos.x = clamp(s_cursorPosAccum.x * (s32)height / (s32)displayInfo.height, 0, (s32)width - 3);
s_cursorPos.z = clamp(s_cursorPosAccum.z * (s32)height / (s32)displayInfo.height, 0, (s32)height - 3);

LRect bounds;
lcanvas_getBounds(&bounds);

LRect displayRect = TFE_RenderBackend::calcDisplayRect();
SDL_WarpMouseInWindow(TFE_Ui::getSDLWindow(),
interpolate(s_cursorPos.x, bounds.left, bounds.right, displayRect.left, displayRect.right),
interpolate(s_cursorPos.z, bounds.top, bounds.bottom, displayRect.top, displayRect.bottom)
);
}

u8* menu_startupDisplay()
{
TFE_Input::setMouseCursorMode(MCURSORMODE_ABSOLUTE);
vfb_setResolution(320, 200);
return vfb_getCpuBuffer();
}

void menu_blitCursor(s32 x, s32 y, u8* framebuffer)
{
LRect bounds;
lcanvas_getBounds(&bounds);
if (x < bounds.left || x > bounds.right || y < bounds.top || y > bounds.bottom)
{
return;
}

blitDeltaFrame(&s_cursor, x, y, framebuffer);
}

Expand Down
5 changes: 4 additions & 1 deletion TheForceEngine/TFE_DarkForces/GameUI/missionBriefing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ namespace TFE_DarkForces
lactorDelt_draw(s_briefActor, &rect, &s_missionTextRect, x, y, JTRUE);
lcanvas_clearClipRect();

menu_blitCursor(s_cursorPos.x, s_cursorPos.z, s_framebuffer);
if (TFE_Input::isMouseInWindow())
{
menu_blitCursor(s_cursorPos.x, s_cursorPos.z, s_framebuffer);
}
menu_blitToScreen();
return JTRUE;
}
Expand Down
9 changes: 8 additions & 1 deletion TheForceEngine/TFE_DarkForces/GameUI/pda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ namespace TFE_DarkForces
///////////////////////////////////////////
void pda_start(const char* levelName)
{
TFE_Input::setMouseCursorMode(MCURSORMODE_ABSOLUTE);

// TFE
reticle_enable(false);
s_mouseAccum = { 0 };
Expand Down Expand Up @@ -243,6 +245,8 @@ namespace TFE_DarkForces
TFE_Jedi::renderer_setType(RendererType(graphics->rendererIndex));
TFE_Jedi::renderer_setLimits();
}

TFE_Input::setMouseCursorMode(MCURSORMODE_RELATIVE);
}

void pda_update()
Expand Down Expand Up @@ -316,7 +320,10 @@ namespace TFE_DarkForces
// Doing that we need to restore the transparent color before blitting the mouse cursor, otherwise its black edges will
// show up incorrectly.
screenDraw_setTransColor(0);
menu_blitCursorScaled(s_cursorPos.x, s_cursorPos.z, vfb_getCpuBuffer());
if (TFE_Input::isMouseInWindow())
{
menu_blitCursorScaled(s_cursorPos.x, s_cursorPos.z, vfb_getCpuBuffer());
}
vfb_swap();
}

Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Landru/lrect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace TFE_DarkForces
LEXTENT
};

// A rectangle. The top left is inclusive and the bottom right is exclusive.
struct LRect
{
s16 top;
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/darkForcesMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ namespace TFE_DarkForces
} break;
case GMODE_MISSION:
{
TFE_Input::setMouseCursorMode(MCURSORMODE_RELATIVE);

sound_levelStart();

bitmap_setAllocator(s_levelRegion);
Expand Down
4 changes: 2 additions & 2 deletions TheForceEngine/TFE_DarkForces/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace TFE_DarkForces
// Close the console so the cheat can be executed.
TFE_FrontEndUI::toggleConsole();
mission_pause(JFALSE);
TFE_Input::enableRelativeMode(true);
TFE_Input::setMouseCursorMode(MCURSORMODE_RELATIVE);
}

#define CHEAT_CMD(c) \
Expand All @@ -152,7 +152,7 @@ namespace TFE_DarkForces
s_queuedCheatID = CHEAT_##c ; \
TFE_FrontEndUI::toggleConsole(); \
mission_pause(JFALSE); \
TFE_Input::enableRelativeMode(true); \
TFE_Input:setMouseCursorMode(MCURSORMODE_RELATIVE); \
}
CHEAT_CMD(LACDS);
CHEAT_CMD(LANTFH);
Expand Down
18 changes: 8 additions & 10 deletions TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace TFE_FrontEndUI
static bool s_bindingPopupOpen = false;

static bool s_consoleActive = false;
static bool s_relativeMode;
static MouseCursorMode s_oldMouseCursorMode = MCURSORMODE_OS;
static bool s_canSave = false;
static bool s_drawNoGameDataMsg = false;

Expand Down Expand Up @@ -272,7 +272,7 @@ namespace TFE_FrontEndUI
s_appState = APP_STATE_MENU;
s_menuRetState = APP_STATE_MENU;
s_subUI = FEUI_NONE;
s_relativeMode = false;
s_oldMouseCursorMode = MCURSORMODE_OS;
s_drawNoGameDataMsg = false;
char fontpath[TFE_MAX_PATH];

Expand Down Expand Up @@ -361,8 +361,8 @@ namespace TFE_FrontEndUI
{
s_appState = APP_STATE_MENU;
s_subUI = FEUI_CONFIG;
s_relativeMode = TFE_Input::relativeModeEnabled();
TFE_Input::enableRelativeMode(false);
s_oldMouseCursorMode = TFE_Input::getMouseCursorMode();
TFE_Input::setMouseCursorMode(MCURSORMODE_OS);
pickCurrentResolution();
}

Expand All @@ -382,7 +382,7 @@ namespace TFE_FrontEndUI
s_drawNoGameDataMsg = false;
s_appState = s_menuRetState;
TFE_Settings::writeToDisk();
TFE_Input::enableRelativeMode(s_relativeMode);
TFE_Input::setMouseCursorMode(s_oldMouseCursorMode);
inputMapping_serialize();

return s_appState;
Expand Down Expand Up @@ -460,8 +460,7 @@ namespace TFE_FrontEndUI
s_drawNoGameDataMsg = false;
s_appState = APP_STATE_EXIT_TO_MENU;
s_selectedModCmd[0] = 0;
s_relativeMode = false;
TFE_Input::enableRelativeMode(s_relativeMode);
TFE_Input::setMouseCursorMode(MCURSORMODE_OS);

if (TFE_Settings::getSystemSettings()->returnToModLoader && s_modLoaded)
{
Expand Down Expand Up @@ -550,7 +549,6 @@ namespace TFE_FrontEndUI
if (s_subUI == FEUI_NONE)
{
s_menuRetState = APP_STATE_MENU;
s_relativeMode = false;

const f32 windowPadding = 16.0f; // required padding so that a window completely holds a control without clipping.

Expand Down Expand Up @@ -848,7 +846,7 @@ namespace TFE_FrontEndUI
s_drawNoGameDataMsg = false;
s_appState = s_menuRetState;
TFE_Settings::writeToDisk();
TFE_Input::enableRelativeMode(s_relativeMode);
TFE_Input::setMouseCursorMode(s_oldMouseCursorMode);
inputMapping_serialize();
}
if (s_menuRetState != APP_STATE_MENU && ImGui::Button("Exit to Menu", sideBarButtonSize))
Expand Down Expand Up @@ -1228,7 +1226,7 @@ namespace TFE_FrontEndUI
s_subUI = FEUI_NONE;
s_appState = s_menuRetState;
s_drawNoGameDataMsg = false;
TFE_Input::enableRelativeMode(s_relativeMode);
TFE_Input::setMouseCursorMode(s_oldMouseCursorMode);
}

void configSaveLoadBegin(bool save)
Expand Down
Loading