Commit graph

1220 commits

Author SHA1 Message Date
Itms
9150c20818
Remove ScriptTypes and ScriptExtraHeaders headers
The first header was used to include the SpiderMonkey JS API at once,
with safeguards and preprocessor defines. Nowadays, SpiderMonkey
provides modular headers allowing us to include what we use, refs #8086.

Some defines have to be moved to compiler options but it is apparently
a mistake from the SM developers:
https://bugzilla.mozilla.org/show_bug.cgi?id=1987876
2025-09-14 13:17:18 +02:00
trompetin17
423ba82837
Fix text right alignment with GUI Scale
Now that size uses float when emulating positioning, it was getting a
different value, like 0.008. This commit fixed that issue by using
std::floor to remove small noise.

Symmetrical for LEFT with std::ceil.
2025-09-13 10:01:51 -05:00
Vantha
83f4d8789b Lift window width constraint of .getPreferredTextSize
The method's point is to calculate a text's height and width if it was written
in a single line -- no matter how long the caption, even if it's wider
than the window.
2025-08-24 11:03:34 +02:00
Ralph Sennhauser
5b5f678e3f
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Add markers to precompiled.h header includes to avoid
include-what-you-use wanting them to be removed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-14 20:15:30 +02:00
Vantha
2026a5fece Clean up Engine.GetGUIObjectByName calls
GetGUIObjectByName was previously made stricter, logging an
error if it doesn't find the target object.
This commit deals with the resulting error-causing (invalid) calls,
by deleting them if they're unnecessary or converting them to the new
TryGetGUIObjectByName (which doesn't log any errors).
2025-08-14 10:22:56 +02:00
Vantha
6515c3fb1f Show an error when Engine.GetGUIObjectByName fails
It previously failed silently and just returned undefined which would often
only cause errors later on. Printing an error as soon as that happens helps
with debugging, by directly catching typos, for example.

For cases where the queried object may not exist, a new Engine function
called TryGetGUIObjectByName is introduced. It doesn't log any errors
and behaves exactly as GetGUIObjectByName used to.
2025-08-14 10:22:56 +02:00
Itms
cea708ac91 Cleanup of IGUIObject classes
- Explicitly delete move constructor and move assignment operator to
  avoid risk of memory leaks
- Remove unused class and typo
- Use same invocation of ScriptInterface as elsewhere
2025-08-11 18:38:01 +02:00
Itms
74bbdca25f Remove default dtors of IGUIObject derived classes 2025-08-11 18:38:01 +02:00
Ralph Sennhauser
fbc74482db
Fix some includes in atlas
Make include-what-you-use happy with some files in source/tools/atlas
and fix what needs to be fixed.

Drop the wxWidgets specific handling of precompiled headers in some
places, it isn't consistently used which it would have to to have meaning
and was mostly for early VS implementation of precompiled headers and a
lot of time has gone by since.

Drop Borland C++ compiler specific quirk, that compiler was
discontinued long ago and doesn't support modern C++.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-09 18:28:46 +02:00
trompetin17
690838e3dc
Add [locale] inline tag for per-locale fonts
New `[locale='xx']...[/locale]` markup lets GUI text sections render
with a locale-specific font (e.g. CJK) while the rest of the caption
keeps the current game font.

guiObject.caption = "Hello [locale='ja']世界[/locale], how do you
[locale='zh']感覺[/locale]" This is ideal for language pickers and
similar UI where you want the language name shown in its own script.

This commit unlocks richer, self-explanatory international UI while
keeping the legacy text behaviour unchanged.
2025-08-04 09:35:41 -05:00
phosit
eee48b74dd Store IGUIObjects in std::unique_ptr in CGUI
The object are automatically deleted. The destructor can now be
defaulted.
2025-08-03 16:55:43 +02:00
phosit
6eac128f12 Pass IGUIObject as reference
Where nullptr isn't allowed references should be used.
2025-08-03 16:55:43 +02:00
phosit
f2dfb94b88 Return void from CGUI::Xeromyces_ReadObject
The returned value was never used.
Now all CGUI::Xeromyces_Read* functions return void.
2025-08-03 16:55:43 +02:00
phosit
f721f56ad4 Replace TIMER with PROFILE2
`TIMER` messages where printed to stdout which lead to noise.

Refs: #1003
2025-07-29 18:19:49 +02:00
Itms
8ccba254fe Remove modmod dependency in test_CGUIText.h
The test loading the `mod` mod uses the bold variant that is present in
`_test.minimal`. Removing the need for the `mod` mod allows packagers to
build and run tests from the `unix-build` tarball without needing the
`unix-data` one.

The setup for this test suite defines the italic variant of the sans
serif font, but this variant is not present in `_test.minimal` and is
not used in any test, so remove that as well.
2025-07-23 12:20:19 +02:00
Itms
2d6d510ffa
Hide compiler warnings from external includes 2025-07-23 10:21:26 +02:00
trompetin17
4fd3533f37
Fix wrapping by passing window width to text size
Why
Passing 0 as the width to `CGUIText` meant "no wrapping".
Buttons and text objects therefore treated every caption as a
single unbroken line, ignoring embedded new-line characters and
overflowing their allotted space.

What
`GetPreferredTextSize` in both `CButton` and `CText` now forwards
`m_pGUI.GetWindowSize().Width` instead of 0.
With a real width the underlying `CGUIText::GetSize()` can measure
the caption using normal word-wrap rules, restoring correct
multi-line behaviour and preventing layout glitches.

Fixes: #8193
2025-07-14 15:02:13 -05:00
trompetin17
0f156e3544
GUIProxy: Support property introspection for debugging
This commit enables proper property enumeration and inspection for GUI
proxy objects in debugging sessions using the SpiderMonkey Debugger API.

Interface (IGUIProxyObject):
- Added a pure virtual method getPropsNames() to expose cached property
  names from the GUI object implementation.

Proxy handler (JSI_GUIProxy):
- Implemented ownPropertyKeys() to enumerate all visible properties of
  the proxy, including: -- Built-in GUI fields: "name", "parent",
  "children". -- Dynamic settings stored in m_Settings. -- Script event
  handlers prefixed with "on" from m_ScriptHandlers. -- Function
  properties returned by getPropsNames().
- Implemented getOwnPropertyDescriptor() to synthesize descriptors for
  debugger queries: -- Returns undefined if the property is not defined.
  -- Returns a read-only enumerable descriptor otherwise.
- Both methods are marked final and override SpiderMonkey's
  BaseProxyHandler.

Why:
- SpiderMonkey’s Debugger API requires ownPropertyKeys and
  getOwnPropertyDescriptor for proxy objects to be introspectable in dev
  tools like VS Code.
- Without these, properties of GUI objects are hidden during debugging.
- This change improves the developer experience by making all meaningful
  GUI object fields visible and explorable at runtime.
2025-07-11 11:06:06 -05:00
phosit
9822a22573 Replace ScriptException::Raise in Engine functions
Now exceptions can be thrown. The function throwing exceptions becomes
cleaner and doesn't require a `ScriptRequest` anymore.
2025-07-08 19:11:49 +02:00
Ralph Sennhauser
5e4b49f65f
Fix some includes in source/renderer
Make include-what-you-use happy with some files in source/renderer and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-07 17:45:54 +02:00
Ralph Sennhauser
461ff6c20c
Fix most headers in gui
Make include-what-you-use happy with most of the files in source/gui and
fix what needs to be fixed after including missing compile flags.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-05 12:42:34 +02:00
Ralph Sennhauser
8227e76845
Restore includes for suppressing warnings on vs2017
Commit d888b10931 remove those headers which have the side effect of
suppressing some warnings on Windows using vs2017. Keep those headers
around for till vs2019+.

Add additional suppressions where needed for spidermonkey headers.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-02 17:40:27 +02:00
Ralph Sennhauser
61326cfca6
Fix some headers in gui
Make include-what-you-use happy with a part of the files in source/gui
and fix what needs to be fixed after including missing compile flags.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-02 13:20:13 +02:00
Ralph Sennhauser
758d901883
more objecttype 2025-06-30 21:18:16 +02:00
Ralph Sennhauser
af582b09aa
fixup! Fix headers for gui/ObjectTypes 2025-06-30 21:09:46 +02:00
Ralph Sennhauser
00f9d887b1
fixup! Fix headers for gui/ObjectTypes 2025-06-30 21:07:53 +02:00
Ralph Sennhauser
49863da3b4
Fix headers for gui/ObjectTypes
Make include-what-you-use happy with files in source/gui/ObjectTypes and
fix what needs to be fixed after.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-30 20:38:16 +02:00
Ralph Sennhauser
d888b10931
Fix headers for gui/ObjectBases
Make include-what-you-use happy with files in source/gui/ObjectBases and
fix what needs to be fixed after.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-30 19:56:41 +02:00
trompetin17
571b536e1f
Log GUISize/GetTextSize deprecations once
Replace repeated LOGWARNING calls with ONCE(LOGWARNING) in
JSInterface_CGUISize.cpp and JSInterface_Main.cpp.

Why – The old behaviour printed a warning every time the deprecated
API was used, cluttering the log and annoying modders. We still want to
nudge them toward the new APIs (object.size = {...} and
guiObject.GetPreferedTextSize/getTextSize), but a single reminder is
enough.

What changed

CGUISimpleSetting<CGUISize>::DoFromJSVal now wraps the deprecation
message in ONCE(...).

Engine.GetTextSize warning is likewise wrapped.

Impact – Functionality is unchanged; only the frequency of the
warnings is throttled to one per session, making the transition less
intrusive and more user-friendly.
2025-06-29 09:12:21 -05:00
trompetin17
19e82ebceb
Add getPreferredTextSize to calculate unconstrained text width
Introduces (CButton|CText).getPreferredTextSize, a new method for estimating
the natural width of a caption if the object had no width constraints.

Unlike .getTextSize, which reports the size after applying current
layout constraints (e.g., fixed width or anchors), getPreferredTextSize
answers the question: "How wide would this object need to be to display
the caption on a single line?"

This is particularly useful for modders and layout logic that wants to
dynamically size elements *before* assigning a fixed width or anchoring.
2025-06-26 16:58:32 -05:00
phosit
891908b801 Remove UNUSED
The `UNUSED` macro is used to mark a variable as unused but with a name.
Those usages are replaced with comments so that `UNUSED` can be removed.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-26 17:25:05 +02:00
phosit
77b1addb45 Enable modules in the GUI
Doesn't actually change a GUI-page to use modules. Adopting a GUI-page
now only requires JS and XML changes.

Ref: #8081
2025-06-26 10:50:21 +02:00
phosit
93666d8628 Remove ignore_result
`std::ignore` serves the same purpose and is C++ standard.
2025-06-19 19:05:56 +02:00
Ralph Sennhauser
0108ff51f4
Fix no-pch build after b34f4b79aa
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-18 21:12:33 +02:00
phosit
d9795d29fe Remove the name of some unused arguments
Remove some usage of the `UNUSED` macro. Remove only those cases where
the names can be deduced from their type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-18 12:49:59 +02:00
trompetin17
b34f4b79aa
Allow setting CGUISize properties directly
Previously, modifying individual CGUISize properties (left, top, right,
bottom) via JavaScript had no effect unless the entire size object was
copied, modified, and reassigned—resulting in verbose and error-prone
code.

This update introduces proper JavaScript property accessors, enabling
direct reading and writing of CGUISize members. The result is a more
intuitive and scriptable API.

Key Changes:
- Implemented JavaScript get/set accessors for each CGUISize property,
  directly interacting with the native object.
- Retained support for string assignments to CGUISize
- Maintained the GUISize JS object for backward compatibility, also
  marked as deprecated.
- Improved CGUISimpleSetting<CGUISize> to allow partial updates via
  direct property access.
- allow assigning size from object with pixel and percent values

You can now assign size using an object with properties like:
size = {
  left: number, right: number, top: number, bottom: number,
  rleft: number, rright: number, rtop: number, rbottom: number
}

- One or more properties can be specified, the missing properties with
  fill as zero.
- Assignment triggers an immediate update event.

Delayed Setting Notifications:
- Introduced a mechanism for delayed setting notifications, currently
  only used in CGUISimpleSetting<CGUISize>, to avoid redundant
  recalculations.
- Ensured that getComputedSize triggers any pending delayed
  notifications before returning the size.

This change significantly enhances the developer experience and brings
the behavior in line with typical expectations for direct property
manipulation in JavaScript.
2025-06-17 12:57:33 -05:00
Ralph Sennhauser
58219b974c
Fix trailing whitespace and add pre-commit hook
Some have their editor configured to remove trailing whitespace and
editing such a file would "fix" it, adding an unrelated change.

Fix whitespace violations excluding third party libs and generated files
like glad or patches.

Enable pre-commit hook trailing-whitespace to enforce it in the future.

Fixes: #8016
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-15 20:08:48 +02:00
trompetin17
dfb4598186
Align font height, capHeight to FreeType metrics
Previously, `height` was derived from a manually chosen glyph (typically
"I", Standard Cap Height) using FontBuilder, and `lineSpacing` was used
inconsistently for layout logic as a height.

Now, with the FreeType-based system:
- `height` uses `face->size->metrics.height`, which includes the
  recommended line height with internal leading/line gap as defined by
  the font designer.
- `lineSpacing` was removed
- `GetCapHeight` uses the standard cap height + ascender to have a
  visual virtual alignment

This change standardizes font metric usage:
- Use `height` for vertical layout and line progression.
- Use `GetCapheight` in layout engines like `CGUIText` or `CGUIString`,

This ensures better alignment across fonts and consistent spacing in
multiline text rendering.

Fixes: #7962
2025-06-11 08:10:18 -05:00
trompetin17
bdd94bd264
Add font engine aware of Gui.scale
This commit enhances text rendering by leveraging FreeType and a dynamic
font atlas. Previously, GUI scaling relied on bitmap fonts, which led to
blurry and distorted text when scaling up. Now, we scale the font size
directly using FreeType, resulting in much sharper and more readable
text at any GUI scale.

Key improvements:
- Replaced bitmap font scaling with true font size scaling via FreeType.
- Reduced glyph cache dependency on fixed positions, relying on shader
  scaling instead.
- Switched to float-based glyph positioning for more accurate rendering
  and scaling.

These changes ensure clean and consistent text appearance across
different GUI scales.
2025-05-26 13:12:47 -05:00
trompetin17
734386ce9f
Use freetype for font rendering
Replace premade bitmap fonts with FreeType2 and dynamic texture atlas.

Switched from static, premade bitmap fonts to runtime-generated glyphs using FreeType2.
Glyphs are rendered on demand into a dynamic texture atlas, improving scalability,
font quality, and support for internationalization.

Currently using RGBA format for compatibility across all render
paths while initial support for R8_UNORM is being added.
This prepares for future optimizations in VRAM and performance

Includes groundwork for gamma-corrected blending and future swizzling support.
2025-05-16 14:57:59 -05:00
Vladislav Belov
0bf3ff5ad6
Reduce allocations for GUI and Hotkeys.
It allows to reduce the number of allocations per-frame for GUI and
during initialization for Hotkeys.
2025-04-24 15:11:22 +02:00
Lancelot de Ferrière
af32d386b9 Stop running shrinking gcs & simplify GC logic.
Shrinking GCs dump the JITted code, which leads to redundant recompilations, lowers performance, and makes profiling JS more difficult.
They may still happen if the runtime is at risk of OOM.
2025-04-22 17:03:29 +02:00
Vladislav Belov
0b33921c06
Removes GL code from the common GPU profiler. 2025-04-16 22:38:34 +02:00
phosit
1a8757660f Get config values without using return parameters
Many temporaries can be removed.
2025-04-09 12:51:21 +02:00
Ralph Sennhauser
933f49722e
Use js compiler option for strict-mode
The context option enabling strict mode was removed in sm-117 [1]
requiring to use the compiler option for the same purpose instead.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1621603

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-04-01 21:15:33 +02:00
phosit
2d206708cd Start Atlas by closing the root page
Theere is now an  `Engine.startAtlas` property that will start Atlas
when it's returned from the root page. The `Engine.RestartInAtlas`
function is removed.
2025-03-26 13:07:57 +01:00
phosit
df5fee6103 Rename PushGuiPage to OpenChildPage
There is no `PopGuiPage` anymore. For symmetry there should also be no
`PushGuiPage`.
2025-03-09 10:39:20 +01:00
phosit
d0ab2cb783 Remove Engine.PopGuiPage
Remove the old now unused interface.
2025-03-09 10:39:20 +01:00
phosit
4f62e9f6f0 Change the GuiManager tests to use promises
Adopt the new interface by the tests: as an example and to show that
it's sound.
2025-03-09 10:39:20 +01:00
phosit
d3bc5bc802 Enable page-inits to return a Promise
Allows to return the page-completion-value instead of passing it to an
`Engine` function.

Closes: #7000
2025-03-09 10:39:20 +01:00