-
Notifications
You must be signed in to change notification settings - Fork 120
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
Integrate RmlUi #1415
Changes from all commits
39a7f0d
a81fa62
abf0418
05e9af6
defcc76
b6df62f
6f3c228
38ff05a
695339e
a1fc41b
d92bf53
d798803
b5cf385
04140d8
40e1be0
2a765f4
3b78d5e
cb1081b
504dac3
cae1e20
7b6478c
0435f65
6a12a91
81642f4
55ce5d7
29cf7e6
cad5a8c
796c401
efa116d
02433b0
be0f717
3dc0b2e
1ea772a
53dada4
cfc9db6
6cb2916
97ba381
3047fa6
bb87676
6afd614
b8735d9
e6d8515
b141e0e
62e215d
6baa7c6
cae6b32
e452e41
5fb2725
8cb883c
4d95ceb
8497288
b7c986a
352a23c
7233cab
88fa05d
ff7336e
6d00b91
c9faa4c
f3cee55
dee6542
333e932
6c30f46
483b060
657c2ce
0f3eb99
1d44625
736a077
9da07be
ade6718
2ccc7aa
801495f
73d4fbf
9ed6508
9224db0
e396690
338d6c5
c59a3b3
453ccf1
85a8ad8
e1f3f91
2fb66e0
3d4d03b
99fadbc
a13a6a9
6cba4e7
830b1a5
999c028
31f2b7d
1b8f9d6
b52f4bc
aa91c6d
89ce466
0732235
9731e48
75bc81e
d25824c
281402b
4e9c1be
eaa8b38
db448e7
bcc6f4e
5254bc0
8ce219c
05d788b
80afcf0
cce0619
455a730
9fe2685
0c35e5d
e8a4d45
20ec89c
07e7cf7
d5fb5ee
eb2de0d
80079c0
67952fa
43fbd9d
d23c965
a8ff4b2
29bf3da
6926f7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- 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') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if a game doesn't do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also comment says "cursor: normal", shouldn't it be "cursor: default"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
what if they put Or, say my widget wants the "wait" cursor (hourglass). since this file doesn't set it, will that fail? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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- spring/rts/Game/UI/MouseHandler.cpp Lines 835 to 859 in fc1bb20
which is assigned here in the init/reload code spring/rts/Game/UI/MouseHandler.cpp Lines 160 to 163 in fc1bb20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if every command defaults to a rml widget will say There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My aim is to
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
|
@@ -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); | ||
|
||
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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); | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :
I have just tried commenting out the font loading in my own code, and:
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.