Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate RmlUi #1415

Merged
merged 121 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
39a7f0d
Add RmlUi to build system
p2004a Sep 27, 2023
a81fa62
render first light
loveridge Sep 30, 2023
abf0418
remove sdl2_image
loveridge Sep 30, 2023
05e9af6
VFS system integration
loveridge Oct 1, 2023
defcc76
rmlui lua and sdl integration
loveridge Oct 3, 2023
b6df62f
rmlui reload support and better luaui integration
loveridge Oct 6, 2023
6f3c228
delete extra file
loveridge Oct 6, 2023
38ff05a
Temporarily switch to RmlUi branch with tracy integration fixed
p2004a Oct 9, 2023
695339e
data model change detection bad edition
loveridge Oct 21, 2023
a1fc41b
fix for chobby support, better binds, translation table
loveridge Oct 22, 2023
d92bf53
key event handling, luaui reloading, rmlsol bug fixes
loveridge Nov 9, 2023
d798803
remove rml demo files
loveridge Nov 9, 2023
b5cf385
create contexts lua side
loveridge Nov 10, 2023
04140d8
clean up comments
loveridge Nov 10, 2023
40e1be0
allow multiple rmlui contexts
loveridge Nov 10, 2023
2a765f4
pull out inner loop of processevent calls
loveridge Nov 10, 2023
3b78d5e
add comment to make it clear certain events are not captured
loveridge Nov 10, 2023
cb1081b
Update RmlUi to latest git version
p2004a Nov 11, 2023
504dac3
headless building and lua support
loveridge Nov 12, 2023
cae1e20
add lunasvg submodule
loveridge Nov 12, 2023
7b6478c
update lunasvg version
loveridge Nov 12, 2023
0435f65
reset build option
loveridge Nov 12, 2023
6a12a91
didnt need to build lunasvg as a shared lib
loveridge Nov 15, 2023
81642f4
fix: uint is not standard and breaks mingw compile
p2004a Dec 16, 2023
55ce5d7
Rework RmlSolLua integration into build
p2004a Dec 16, 2023
29cf7e6
Fix RmlSolLua compilation under MSVC
p2004a Dec 16, 2023
cad5a8c
Document the mouse press check
sprunk Dec 30, 2023
796c401
Change size() < 1 to empty. Move setActive after processContext loop
loveridge Dec 30, 2023
efa116d
Deeper MouseHandler integration for processing mouse events
loveridge Jan 10, 2024
02433b0
Fix software rendered mouse cursor
loveridge Jan 14, 2024
be0f717
Missed half of the move of this comment
loveridge Jan 14, 2024
3dc0b2e
make lua binding for RemoveContext
ChrisFloofyKitsune Apr 6, 2024
1ea772a
do less bullying of the RmlSolLua lib
ChrisFloofyKitsune Jan 15, 2024
53dada4
attempt to add thread safety to RmlGui::data->context accesses
ChrisFloofyKitsune Jan 16, 2024
cfc9db6
have RmlGui store what cursor it would like (or "" to cede control of…
ChrisFloofyKitsune Jan 17, 2024
6cb2916
Platform_RTS ended up being disliked, so re-renamed stuff to "RmlSyst…
ChrisFloofyKitsune Jan 18, 2024
97ba381
check Rml input first
ChrisFloofyKitsune Jan 18, 2024
3047fa6
fix a singular character to be lowercase blargh
ChrisFloofyKitsune Jan 18, 2024
bb87676
fix spelling
loveridge Jan 18, 2024
6afd614
reference fix
loveridge Jan 18, 2024
b8735d9
use cbitmap texture binding
loveridge Jan 27, 2024
e6d8515
spaces to tabs with clang-format
loveridge Jan 27, 2024
b141e0e
mask lua macros
loveridge Jan 28, 2024
62e215d
Remove unused variable
loveridge Jan 28, 2024
6baa7c6
add an explicit removeLua call
loveridge Jan 28, 2024
cae6b32
accurate tracking of lua added items
loveridge Jan 29, 2024
e452e41
move general Rml::Context watching plugin outside of Lua init/destroy
ChrisFloofyKitsune Jan 29, 2024
5fb2725
left some mess in, sorry
ChrisFloofyKitsune Jan 29, 2024
8cb883c
Remove unnecessary includes
loveridge Jan 30, 2024
4d95ceb
create new <texture> element which hooks into the existing LuaOpenGL/…
ChrisFloofyKitsune Jan 27, 2024
8497288
what if we just kept the texture handle away from Rml
ChrisFloofyKitsune Jan 29, 2024
b7c986a
clearer and more readable element tag name
ChrisFloofyKitsune Jan 29, 2024
352a23c
misc changes
ChrisFloofyKitsune Jan 31, 2024
7233cab
copyright auto insert go brrr too hard
ChrisFloofyKitsune Jan 31, 2024
88fa05d
leave a note on the UI reload
ChrisFloofyKitsune Jan 31, 2024
ff7336e
move RmlSolLua out of the lib folder so that it can integrate more wi…
ChrisFloofyKitsune Feb 5, 2024
6d00b91
according to a tutorial, the proper implementation of the iterator co…
ChrisFloofyKitsune Feb 6, 2024
c9faa4c
minor cleanup
ChrisFloofyKitsune Feb 8, 2024
f3cee55
minor cleanup as I investigate how Data Models work
ChrisFloofyKitsune Feb 10, 2024
dee6542
use the configured lua_Number type instead of blindly assuming double
ChrisFloofyKitsune Feb 10, 2024
333e932
beginning refactor of RenderInterface
ChrisFloofyKitsune Feb 11, 2024
6c30f46
we can just use `glPush/PopAttrib()` here
ChrisFloofyKitsune Feb 11, 2024
483b060
narrow down to just the attrib bits needed
ChrisFloofyKitsune Feb 11, 2024
657c2ce
misc changes
ChrisFloofyKitsune Feb 12, 2024
0f3eb99
drop element render hook
ChrisFloofyKitsune Feb 12, 2024
1d44625
untested custom Rml Decorator: 'lua-render' (name not final)
ChrisFloofyKitsune Feb 13, 2024
736a077
rml lua-render decorator barely functional
ChrisFloofyKitsune Feb 14, 2024
9da07be
remove redundant Log binding from SolLua
ChrisFloofyKitsune Feb 16, 2024
ade6718
many changes
ChrisFloofyKitsune Jan 31, 2024
2ccc7aa
Actually add submodules
lhog Feb 19, 2024
801495f
Fix g++ compilation
lhog Feb 19, 2024
73d4fbf
just use one shader program, copy in documentation comments to make w…
ChrisFloofyKitsune Mar 16, 2024
9ed6508
SolLua binding "low hanging fruit" cleanup
ChrisFloofyKitsune Mar 16, 2024
9224db0
make all the RmlUi Lua bindings into a "RmlUi" namespace table to bet…
ChrisFloofyKitsune Mar 16, 2024
e396690
add Mouse Cursor Aliases feature
ChrisFloofyKitsune Mar 17, 2024
338d6c5
use <texture> instead of <lua-texture> as LuaTextureElement tag name
ChrisFloofyKitsune Mar 17, 2024
c59a3b3
add mouse cursor alias stuff to example rml_setup.lua
ChrisFloofyKitsune Mar 17, 2024
453ccf1
touch up rml_setup.lua
ChrisFloofyKitsune Mar 18, 2024
85a8ad8
without the render_interface being 100% finalized, it is too early fo…
ChrisFloofyKitsune Mar 16, 2024
e1f3f91
get rid of extraneous whitespace changes
ChrisFloofyKitsune Apr 7, 2024
2fb66e0
replace space indenting with tab indenting
ChrisFloofyKitsune Apr 7, 2024
3d4d03b
RmlGui::Initialize gets own globals + allow Reload to init
ChrisFloofyKitsune Apr 8, 2024
99fadbc
clean up/fixing of init/shutdown/Context removal
ChrisFloofyKitsune Apr 9, 2024
a13a6a9
tidy event handling + more
ChrisFloofyKitsune Apr 9, 2024
6cba4e7
Replace README.md with notice of where the code came from
ChrisFloofyKitsune Apr 12, 2024
830b1a5
Add MIT license info to almost all Rml/SolLua source files
ChrisFloofyKitsune Apr 12, 2024
999c028
add support for border-radius property to ElementLuaTexture.cpp
ChrisFloofyKitsune Apr 14, 2024
31f2b7d
recalc geometry when rect attribute is set to (blank)
ChrisFloofyKitsune Apr 14, 2024
1b8f9d6
create lua hook for the RmlUi debugger
ChrisFloofyKitsune Apr 14, 2024
b52f4bc
context ordering, rm PasThrPlugin, data > state
ChrisFloofyKitsune Apr 15, 2024
aa91c6d
fix debugger use-after-free crash
ChrisFloofyKitsune Apr 15, 2024
89ce466
remove contexts last in update
ChrisFloofyKitsune Apr 15, 2024
0732235
fix crash in StyleProxy iteration
ChrisFloofyKitsune Apr 20, 2024
9731e48
add returns from element hierarchy manip bindings
ChrisFloofyKitsune Apr 20, 2024
75bc81e
code style tidying
ChrisFloofyKitsune Apr 20, 2024
d25824c
allow nil and blank strings to clear a property
ChrisFloofyKitsune Apr 20, 2024
281402b
Fix whitespace
p2004a Jun 8, 2024
4e9c1be
Remove lua mask/restore macros as fix is on BAR105
p2004a Jun 8, 2024
eaa8b38
bump to rmlui repo latest
ChrisFloofyKitsune May 26, 2024
db448e7
use renamed RMLUI_ option
ChrisFloofyKitsune May 26, 2024
bcc6f4e
use new RmlUi target names
ChrisFloofyKitsune May 26, 2024
5254bc0
Create Uniform*v variants that take a "count" parameter
ChrisFloofyKitsune May 28, 2024
8ce219c
Initial update to RmlUi 6. Code is compiling.
ChrisFloofyKitsune May 28, 2024
05d788b
interface with Shader API correctly
ChrisFloofyKitsune May 28, 2024
80afcf0
better init logging
ChrisFloofyKitsune May 29, 2024
cce0619
update "is initialized" check
ChrisFloofyKitsune May 29, 2024
455a730
code/formatting cleanup
ChrisFloofyKitsune May 29, 2024
9fe2685
sidestep the RmlUi resource handling to render the texture and geomet…
ChrisFloofyKitsune May 30, 2024
0c35e5d
remove outdated comment
ChrisFloofyKitsune May 31, 2024
e8a4d45
fix use-after-free issue by removing debugger before shutting down lua
ChrisFloofyKitsune Apr 15, 2024
20ec89c
size of a non-table is 0 actually
ChrisFloofyKitsune Apr 19, 2024
07e7cf7
RmlUi log pretty useful actually
ChrisFloofyKitsune Jun 4, 2024
d5fb5ee
Don't deactivate the shader if TexturePostprocess is used
ChrisFloofyKitsune Jun 6, 2024
eb2de0d
ensure that RmlUi can be loaded after changing UI Size option
ChrisFloofyKitsune Jun 7, 2024
80079c0
bump RmlUi for flexbox gap feature
ChrisFloofyKitsune Jun 19, 2024
67952fa
inline rgba Colour binding macro
ChrisFloofyKitsune Jun 22, 2024
43fbd9d
remove outdated commented-out code
ChrisFloofyKitsune Jun 22, 2024
d23c965
update headless render interface stub
ChrisFloofyKitsune Jun 24, 2024
a8ff4b2
(whitespace) correct accidental tab
ChrisFloofyKitsune Jun 24, 2024
29bf3da
update RmlUi to official 6.0 release
ChrisFloofyKitsune Aug 30, 2024
6926f7e
update backend files with updates made to the originals
ChrisFloofyKitsune Aug 30, 2024
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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
[submodule "rts/lib/cereal"]
path = rts/lib/cereal
url = https://github.com/USCiLab/cereal.git
[submodule "rts/lib/RmlUi"]
path = rts/lib/RmlUi
url = https://github.com/mikke89/RmlUi.git
[submodule "rts/lib/lunasvg"]
path = rts/lib/lunasvg
url = https://github.com/sammycage/lunasvg.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ else()
set(JAVA_COMPILE_FLAG_CONDITIONAL "-g:lines,source")
endif()

# By default, the libraries that don't explicily specify SHARED/STATIC are build statically.
# See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries" OFF)

# Tell windows to pass arguments around in @response files
# (32k arg limit workaround)
Expand Down
3 changes: 2 additions & 1 deletion cont/LuaUI/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

Spring.SendCommands({"ctrlpanel " .. LUAUI_DIRNAME .. "ctrlpanel.txt"})

VFS.Include(LUAUI_DIRNAME .. 'utils.lua', utilFile)
VFS.Include(LUAUI_DIRNAME .. "rml_setup.lua", nil, VFS.ZIP)
VFS.Include(LUAUI_DIRNAME .. 'utils.lua', nil, VFS.ZIP)

include("setupdefs.lua")
include("savetable.lua")
Expand Down
27 changes: 27 additions & 0 deletions cont/LuaUI/rml_setup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- file: rml.lua
-- brief: RmlUi Setup
-- author: lov + ChrisFloofyKitsune
--
-- Copyright (C) 2024.
-- Licensed under the terms of the GNU GPL, v2 or later.

if (RmlGuard or not RmlUi) then
return
end
RmlGuard = true

-- Load fonts
RmlUi.LoadFontFace("Fonts/FreeMonoBold.ttf", true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if a game doesn't do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly do not know for this one, I'll try commenting it out and get back to you.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/fonts.html :

TrueType and OpenType fonts can be loaded into RmlUi by the application. RmlUi has no default font, so at least one font must be loaded before text can be rendered.

I have just tried commenting out the font loading in my own code, and:

  • Text is no longer rendered.
  • RmlUi logs warnings and complains about no font face being defined.
  • Buttons and the rest of the UI works, at least in my own project.
  • If you are running with the debugger (Rml::Debugger::Initialise()) , RmlUi loads its own "rmlui-debugger-font" to show debug text in the debug UI element inside your application window.

RmlUi describes "fallback fonts" in https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/fonts.html . So if the RmlUi integration code defines at least one fallback font, unless fonts can be unloaded, text will as far as I can tell always be rendered (except for the characters that the fallback font does not include). You can also define multiple fallback fonts.


-- Mouse Cursor Aliases
--[[
These let standard CSS cursor names be used when doing styling.
If a cursor set via RCSS does not have an alias, it is unchanged.
CSS cursor list: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
RmlUi documentation: https://mikke89.github.io/RmlUiDoc/pages/rcss/user_interface.html#cursor
]]

-- when "cursor: normal" is set via RCSS, "cursornormal" will be sent to the engine
RmlUi.SetMouseCursorAlias("default", 'cursornormal')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if a game doesn't do this?

Copy link
Member

@ChrisFloofyKitsune ChrisFloofyKitsune Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the .rcss files will have to specify the game specific cursor name to use

instead of

.example {
    cursor: default
}

they would have to put

.example {
    cursor: cursornormal
}

the latter of which makes css parsers/style checkers confused and css code in general less importable if it was developed elsewhere

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also comment says "cursor: normal", shouldn't it be "cursor: default"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of

.example {
    cursor: default
}

they would have to put

.example {
    cursor: cursornormal
}

what if they put default there regardless?

Or, say my widget wants the "wait" cursor (hourglass). since this file doesn't set it, will that fail?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as if any other part of the code that tries to use a cursor that's not registered with the engine-
it will default to "" in the MouseHandler code

void CMouseHandler::SetCursor(const std::string& cmdName, const bool forceRebind)
{
if ((activeCursorName == cmdName) && !forceRebind)
return;
const auto it = cursorCommandMap.find(activeCursorName = cmdName);
if (it != cursorCommandMap.end()) {
activeCursorIdx = it->second;
} else {
activeCursorIdx = cursorCommandMap[""];
}
if (!hardwareCursor || hideCursor)
return;
if ((hwHideCursor = !loadedCursors[activeCursorIdx].IsHWValid())) {
SDL_ShowCursor(SDL_DISABLE);
mouseInput->SetWMMouseCursor(nullptr);
} else {
loadedCursors[activeCursorIdx].BindHwCursor(); // calls SDL_ShowCursor(SDL_ENABLE);
}
}

which is assigned here in the init/reload code

AssignMouseCursor("", "cursornormal", mTopLeft, false);
AssignMouseCursor("Area attack", "cursorareaattack", mCenter, false);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if every command defaults to "" if missing, and "" command is assigned the "cursornormal" cursors in engine, then does RmlUi.SetMouseCursorAlias("default", 'cursornormal') actually do anything?

a rml widget will say .example { cursor: default }, this will fallback to "" because "default" is missing, and "" uses "cursornormal" anyway, no?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the worst case outcome of this? If the worst case outcome is fairly minor, it would be fine to improve this, but not something that should block the PR, in my perspective at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My aim is to

  • see if it would be possible to get rid of this file
  • become aware of the caveats etc for documentation purposes if not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the version of this file I have in my rmlui-example-widgets branch has a lot more going on
I stripped down that file to make this one

https://github.com/ChrisFloofyKitsune/Beyond-All-Reason/blob/rmlui-example-widgets/luaui/rml_setup.lua

in terms of useful stuff, 4 fonts are loaded and 5 cursor aliases are set there

-- for command cursors, use the command name
-- RmlUi.SetMouseCursorAlias("pointer", 'Move')
1 change: 1 addition & 0 deletions cont/LuaUI/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (System == nil) then
CMD = CMD,
CMDTYPE = CMDTYPE,
LOG = LOG,
RmlUi = RmlUi,

UnitDefs = UnitDefs,
UnitDefNames = UnitDefNames,
Expand Down
3 changes: 3 additions & 0 deletions rts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ add_subdirectory(Lua)
add_subdirectory(ExternalAI)
add_subdirectory(Rendering)
add_subdirectory(aGui)
add_subdirectory(Rml)
add_subdirectory(Menu)
add_subdirectory(Map)
add_subdirectory(Net)
Expand All @@ -152,6 +153,8 @@ make_global_var(engineSources
${sources_engine_Map}
${sources_engine_Rendering}
${sources_engine_aGui}
${sources_engine_Rml}
${sources_engine_RmlSolLua}
${sources_engine_Menu}
${sources_engine_System}
${sources_engine_ExternalAI}
Expand Down
16 changes: 16 additions & 0 deletions rts/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Rendering/GL/myGL.h"

#include <Rml/Backends/RmlUi_Backend.h>
#include <RmlUi/Core.h>
#include "Game.h"
#include "Camera.h"
#include "CameraHandler.h"
Expand Down Expand Up @@ -296,6 +298,7 @@ CGame::~CGame()
ENTER_SYNCED_CODE();
LOG("[Game::%s][1]", __func__);

RmlGui::Shutdown();
helper->Kill();
KillLua(true);
KillMisc();
Expand Down Expand Up @@ -828,6 +831,8 @@ void CGame::LoadInterface()
GameSetupDrawer::Disable();
GameSetupDrawer::Enable();
}

RmlGui::Initialize();
}

void CGame::LoadLua(bool dryRun, bool onlyUnsynced)
Expand Down Expand Up @@ -1105,6 +1110,9 @@ int CGame::KeyPressed(int keyCode, int scanCode, bool isRepeat)

lastActionList = keyBindings.GetActionList(curKeyCodeChain, curScanCodeChain);

if (RmlGui::ProcessKeyPressed(keyCode, scanCode, isRepeat))
return 0;

if (gameTextInput.ConsumePressedKey(keyCode, scanCode, lastActionList))
return 0;

Expand Down Expand Up @@ -1145,6 +1153,9 @@ int CGame::KeyPressed(int keyCode, int scanCode, bool isRepeat)
int CGame::KeyReleased(int keyCode, int scanCode)
{
RECOIL_DETAILED_TRACY_ZONE;
if (RmlGui::ProcessKeyReleased(keyCode, scanCode))
return 0;

if (gameTextInput.ConsumeReleasedKey(keyCode, scanCode))
return 0;

Expand Down Expand Up @@ -1180,6 +1191,9 @@ int CGame::KeyMapChanged()
int CGame::TextInput(const std::string& utf8Text)
{
RECOIL_DETAILED_TRACY_ZONE;
if (RmlGui::ProcessTextInput(utf8Text))
return 0;

if (eventHandler.TextInput(utf8Text))
return 0;

Expand Down Expand Up @@ -1473,6 +1487,7 @@ bool CGame::Draw() {
if (UpdateUnsynced(currentTimePreUpdate))
return false;

RmlGui::Update();
const spring_time currentTimePreDraw = spring_gettime();

SCOPED_SPECIAL_TIMER("Draw");
Expand Down Expand Up @@ -1560,6 +1575,7 @@ bool CGame::Draw() {
DrawInputReceivers();
DrawInputText();
DrawInterfaceWidgets();
RmlGui::RenderFrame();
mouse->DrawCursor();

eventHandler.DrawScreenPost();
Expand Down
2 changes: 2 additions & 0 deletions rts/Game/UI/GuiHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "GuiHandler.h"

#include <Rml/Backends/RmlUi_Backend.h>
#include "CommandColors.h"
#include "KeyBindings.h"
#include "KeyCodes.h"
Expand Down Expand Up @@ -174,6 +175,7 @@ bool CGuiHandler::EnableLuaUI(bool enableCommand)
}
}

RmlGui::Reload();
CLuaUI::ReloadHandler();

if (luaUI != nullptr) {
Expand Down
7 changes: 6 additions & 1 deletion rts/Game/UI/InputReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "InputReceiver.h"
#include "Lua/LuaInputReceiver.h"
#include "Rendering/GL/myGL.h"
#include "Rml/Backends/RmlUi_Backend.h"
#include "System/Rectangle.h"

#include "System/Misc/TracyDefs.h"
Expand Down Expand Up @@ -75,7 +76,11 @@ void CInputReceiver::DrawReceivers()
CInputReceiver* CInputReceiver::GetReceiverAt(int x, int y)
{
RECOIL_DETAILED_TRACY_ZONE;
// always ask Lua first
// check RmlUI first
if (RmlGui::IsMouseInteractingWith())
return RmlGui::GetInputReceiver();

// check lua second
if (luaInputReceiver != nullptr && luaInputReceiver->IsAbove(x, y))
return luaInputReceiver;

Expand Down
41 changes: 40 additions & 1 deletion rts/Game/UI/MouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "System/StringUtil.h"
#include "System/Input/KeyInput.h"
#include "System/Input/MouseInput.h"
#include "Rml/Backends/RmlUi_Backend.h"

#include "System/Misc/TracyDefs.h"

Expand Down Expand Up @@ -281,6 +282,13 @@ void CMouseHandler::MouseMove(int x, int y, int dx, int dy)
if (game != nullptr && !game->IsGameOver())
playerHandler.Player(gu->myPlayerNum)->currentStats.mousePixels += movedPixels;

/* Only want to give a mouse event to RmlUI if the mouse isn't currently performing a drag.
* Otherwise box selections get stuck when the mouse goes over an Rml element.
* Flags that ButtonPressed() checks are not set when clicking on Rml element. */
if (!ButtonPressed() && RmlGui::ProcessMouseMove(x, lasty, dx, dy, activeButtonIdx)) {
return;
}

if (activeReceiver != nullptr)
activeReceiver->MouseMove(x, lasty, dx, dy, activeButtonIdx);

Expand Down Expand Up @@ -309,7 +317,12 @@ void CMouseHandler::MousePress(int x, int y, int button)
if (game != nullptr && !game->IsGameOver())
playerHandler.Player(gu->myPlayerNum)->currentStats.mouseClicks++;

ButtonPressEvt& bp = buttons[activeButtonIdx = button];
if (RmlGui::ProcessMousePress(x, y, button)) {
return;
}

activeButtonIdx = button;
ButtonPressEvt& bp = buttons[activeButtonIdx];
bp.chorded = (buttons[SDL_BUTTON_LEFT].pressed || buttons[SDL_BUTTON_RIGHT].pressed);
bp.pressed = true;
bp.time = gu->gameTime;
Expand All @@ -319,6 +332,8 @@ void CMouseHandler::MousePress(int x, int y, int button)
bp.dir = (dir = GetCursorCameraDir(x, y));
bp.movement = 0;

pressedBitMask |= 1 << button;

if (activeReceiver != nullptr && activeReceiver->MousePress(x, y, button))
return;

Expand Down Expand Up @@ -379,6 +394,10 @@ bool CMouseHandler::GetSelectionBoxVertices(float3& bl, float3& br, float3& tl,
if (activeReceiver != nullptr)
return false;

if (RmlGui::IsMouseInteractingWith()) {
return false;
}

if (gu->fpsMode)
return false;

Expand Down Expand Up @@ -477,12 +496,17 @@ void CMouseHandler::MouseRelease(int x, int y, int button)
dir = GetCursorCameraDir(x, y);

buttons[button].pressed = false;
pressedBitMask &= ~(1 << button);

if (inMapDrawer != nullptr && inMapDrawer->IsDrawMode()) {
inMapDrawer->MouseRelease(x, y, button);
return;
}

if (RmlGui::ProcessMouseRelease(x, y, button)) {
return;
}

if (activeReceiver != nullptr) {
activeReceiver->MouseRelease(x, y, button);

Expand Down Expand Up @@ -557,10 +581,18 @@ void CMouseHandler::MouseRelease(int x, int y, int button)
}
}

bool CMouseHandler::ButtonPressed()
{
return pressedBitMask > 0;
}

void CMouseHandler::MouseWheel(float delta)
{
RECOIL_DETAILED_TRACY_ZONE;
if (RmlGui::ProcessMouseWheel(delta)) {
return;
}

if (eventHandler.MouseWheel(delta > 0.0f, delta))
return;

Expand Down Expand Up @@ -691,6 +723,13 @@ std::string CMouseHandler::GetCurrentTooltip() const
void CMouseHandler::Update()
{
RECOIL_DETAILED_TRACY_ZONE;
// Rml is very polite about asking for changes to the cursor
// so let's make sure it's not ignored!
if (RmlGui::IsMouseInteractingWith())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use brackets for multiline contents

// if the cursor string is empty, then Rml is cedeing control of it
if (auto& rmlCursor = RmlGui::GetMouseCursor(); !rmlCursor.empty())
queuedCursorName = rmlCursor;

SetCursor(queuedCursorName);

if (!hideCursor) {
Expand Down
3 changes: 3 additions & 0 deletions rts/Game/UI/MouseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class CMouseHandler

bool GetSelectionBoxVertices(float3& bl, float3& br, float3& tl, float3& tr) const;

bool ButtonPressed();

private:
int2 GetViewMouseCenter() const;
void SetCursor(const std::string& cmdName, const bool forceRebind = false);
Expand Down Expand Up @@ -116,6 +118,7 @@ class CMouseHandler
bool wasLocked = false;
bool offscreen = false;
bool mmbScroll = false;
uint32_t pressedBitMask = 0;

private:
bool hideCursor = true;
Expand Down
9 changes: 9 additions & 0 deletions rts/Lua/LuaHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Game/UI/KeySet.h"
#include "Game/UI/MiniMap.h"
#include "Rendering/GlobalRendering.h"
#include "Rml/Backends/RmlUi_Backend.h"
#include "Sim/Misc/GlobalSynced.h"
#include "Sim/Misc/TeamHandler.h"
#include "Sim/Projectiles/Projectile.h"
Expand Down Expand Up @@ -174,6 +175,10 @@ void CLuaHandle::KillLua(bool inFreeHandler)
if (inFreeHandler)
Shutdown();

if(rmlui) {
RmlGui::RemoveLua();
}

// 3. delete the lua_State
//
// must be done here: if called from a ctor, we want the
Expand Down Expand Up @@ -3921,6 +3926,10 @@ int CLuaHandle::CallOutUpdateCallIn(lua_State* L)
return 0;
}

void CLuaHandle::InitializeRmlUi()
{
rmlui = RmlGui::InitializeLua(L);
}

/******************************************************************************/
/******************************************************************************/
2 changes: 2 additions & 0 deletions rts/Lua/LuaHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class CLuaHandle : public CEventClient
void RunDrawCallIn(const LuaHashString& hs);

void DrawObjectsLua(std::initializer_list<bool> bools, const char* func);
void InitializeRmlUi();
protected:
bool rmlui = false;
bool userMode = false;
bool killMe = false; // set for handles that fail to RunCallIn

Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ CLuaUI::CLuaUI()
KillLua();
return;
}
InitializeRmlUi();

lua_settop(L, 0);
if (!LoadCode(L, std::move(code), file)) {
Expand Down
Loading
Loading