Commit graph

164 commits

Author SHA1 Message Date
Ralph Sennhauser
a0bb103390
Unwrap SDL_Event
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled
Since C++11 a C typedef'ed union can be forward declared, so the wrapper
is no longer needed.

While at it switch signatures to refs and convert C style casts.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-05-20 19:44:52 +02:00
Vantha
5a92c22d90 Compute actual size of GUI objects lazily
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled
This shifts the responsibility of updating the actual size more towards
IGUIObject, and enables only ever doing it when the value is actually
needed. This allows us to remove the delay of size changed
notifications, since the value is now already recalculated as
infrequently as possible anyways.

All of that ensures that the actual size (returned by GetActualSize) is
always up-to-date e.g. when reading it from the parent, which was
previously broken.

Fixes #8200
2026-04-12 00:17:02 +02:00
Vantha
8a2a450686 Align text as usual if the scrollbar is invisible
Previously, while `scrollbar` was set to true, the text was always
vertically aligned to the top, no matter what its `text_valign` was, by
the scrolling logic. However, this was done even when the text's caption
was so short that no scrollbar was required in the first place (and not
rendered). Falling back to the specified `text_valign` value in that case
instead seems like the expected behavior.

On a few occasions in the GUI, the text was supposed to be aligned to
the top in either case, but still set `text_valign` to a different value
(for whatever reason), which didn't have any effect previously. But
now since it does, the values have to be corrected to specify what is
actually desired.
2026-04-06 21:39:18 +02:00
Vantha
01476b9836 Only render the minimap texture if it'll be displayed
This patch implements a way for minimap-type GUI objects to request the rendering
of the minimap texture each frame. If it wasn't requested the minimap
texture isn't rendered at all and the objects only request it while they are
being displayed. This saves unnecessary work and fixes a bug where the
minimap briefly showed the revealed map after a cinema path ended
playing, since it isn't updated every frame (only 2x per second).
2026-03-03 11:25:52 +01:00
Vantha
2e450f0f52 Remove inconsistent override in CDropdown.h
It was added in 670f1e5d42 and, while not illegal, was inconsistent with the
rest of the header file, which caused compiler warnings.
As a quick solution the override keyword is simply removed again.
In the long run, it would be good to still modernise the style of all files
in that directory (at once).
2025-12-29 13:46:47 +01:00
Vantha
670f1e5d42 Fix warnings on the charts tab of summary screen
Engine.GetTextWidth has been deprecated since e845da025a

Idea:
If you look at a dropdown as just a text field (its header) that can
change caption like any other, then getPreferredHeaderTextSize is the
equivalent to getPreferredTextSize (present on buttons and text fields).

Fixes #8493
2025-12-23 10:28:22 +01:00
Vantha
fbb6052c30 Fix oversight in 83f4d8789b 2025-12-23 10:28:22 +01:00
phosit
7ccea4ace9
Remove *WithReturn duplication
This has been introduced in 1ed64439ea.
2025-11-05 14:39:44 +01: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
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
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
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
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
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
93666d8628 Remove ignore_result
`std::ignore` serves the same purpose and is C++ standard.
2025-06-19 19:05:56 +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
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
phosit
1a8757660f Get config values without using return parameters
Many temporaries can be removed.
2025-04-09 12:51:21 +02:00
phosit
b41ca5ad78 Replace FALLTHROUGH by the standard attribute 2025-01-29 19:34:12 +01:00
phosit
473f8ca72e Remove FALLTHROUGH on empty cases
`#include "lib/code_annotation.h"` can be removed in some places.
2025-01-29 19:34:12 +01:00
trompetin17
8c250568e7
Add scrollpanel widget
This PR introduces a new ScrollPanel component with the following
capabilities:
- Scroll Orientation Support: Allows scrolling in horizontal, vertical,
  or both directions, providing flexibility for different use cases.
- Partial Object Rendering: Supports partial rendering of objects that
  are only partially visible within the scroll boundaries, improving
  visual accuracy and performance.
- Boundary-Constrained Mouse Interaction: Handles mouse events strictly
  within the panel's visible boundaries, preventing interaction with
  objects outside the scrollable area.
- Minimum Internal Size (min_width, min_height): Introduces support for
  virtual space management, allowing the panel to maintain a minimum
  internal size independent of its actual on-screen dimensions. Even
  when the panel is resized, this ensures that the content respects a
  defined virtual space (with min_width and min_height), effectively
  simulating a larger internal canvas. This is particularly useful for
  large content or scenarios where a more extensive scrollable area is
  required than the current visible panel.
2024-11-12 15:01:42 -05:00
trompetin17
ff28ac36a6
Tooltip set like ghost
Tooltip shouldnt receive any mouse event direct, there is a edge case
when you have a big tooltip and the object that need that tooltip is in
the bottom left, at this moment tooltip is in the same position of the
mouse, current code was returning the tooltip, and the code hide the
tooltip, and find again there is another object that needs the tooltip
and show again. To fix this is just than simple to set a tooltip like
ghost because shouldnt receive any mouse event.
2024-10-27 17:18:42 -05:00
Stan
a4d9993e86 Finish implementing property "textcolor_selected" for list GUI objects
Fixes #6920
Patch by: @Vantha
Differential Revision: https://code.wildfiregames.com/D5269
This was SVN commit r28135.
2024-07-03 08:32:52 +00:00
Stan
9af1433995 Rename the "color" property of COlist columns to "textcolor"
Patch by: @Vantha
Differential Revision: https://code.wildfiregames.com/D5278
This was SVN commit r28120.
2024-06-22 20:18:09 +00:00
vladislavbelov
ffc4a56b9f Revert non-ASCII characters from source and configuration files introduced in 157c6af18e.
Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185
This was SVN commit r27965.
2023-12-03 00:30:12 +00:00
phosit
3fff9df4a0 Return CTerrain and CUnitManager references from CWorld instead of pointers
Accepted By: @vladislavbelov
Comments By: @Stan
Differential Revision: https://code.wildfiregames.com/D4739
This was SVN commit r27861.
2023-09-26 20:10:40 +00:00
vladislavbelov
5ba7ec3bfa Removes scissor backend setup from GUI.
Differential Revision: https://code.wildfiregames.com/D5051
This was SVN commit r27798.
2023-08-15 17:29:45 +00:00
bb
157c6af18e Make the space in 0 A.D. non-breaking throughout the codebase.
Avoid cases of filenames
Update years in terms and other legal(ish) documents
Don't update years in license headers, since change is not meaningful

Will add linter rule in seperate commit

Happy recompiling everyone!

Original Patch By: Nescio
Comment By: Gallaecio
Differential Revision: D2620
This was SVN commit r27786.
2023-07-27 20:54:46 +00:00
vladislavbelov
7378692c89 Fixes CGUISimpleSetting warnings and allows it to be moved.
Differential Revision: https://code.wildfiregames.com/D5071
This was SVN commit r27763.
2023-07-18 20:01:22 +00:00
trompetin17
5e2ae82d9e Bug fix: Use sort order asc by default instead of desc
refs 9044735e87

This was SVN commit r27429.
2023-01-12 19:10:28 +00:00
vladislavbelov
7c84c23114 Adds Vulkan backend.
Comments By: phosit, Stan
Differential Revision: https://code.wildfiregames.com/D4876
This was SVN commit r27412.
2023-01-10 20:22:20 +00:00
trompetin17
9044735e87 Optional column "sort_order" attribute support olist GUI
Patch by: @Grapjas
Differential revision: D4859
Reviewed by: @trompetin17
This was SVN commit r27398.
2023-01-09 14:26:03 +00:00
trompetin17
c8e24927b2 Add support to change column heading text in olist GUI component
Patch by: @Grapjas
Reviewed by: @phosit @trompetin17
Differential Revision: https://code.wildfiregames.com/D4857
This was SVN commit r27384.
2023-01-07 15:02:12 +00:00
vladislavbelov
2ef801f5d0 Remove some unnecessary string copy related to substr.
Patch By: phosit
Differential Revision: https://code.wildfiregames.com/D4772
This was SVN commit r27271.
2022-12-04 19:56:12 +00:00
vladislavbelov
4d77de66d4 Removes GUI dependency from Canvas2D.
Initially the GetDefaultGuiMatrix function was added in 4113aa0a36 and
renamed in 04c63a4093.

This was SVN commit r27111.
2022-10-04 20:25:39 +00:00
vladislavbelov
75518d0e15 Removes drawing via IDeviceCommandContext from CMinimap.
Comments By: phosit
Differential Revision: https://code.wildfiregames.com/D4779
This was SVN commit r27109.
2022-10-04 19:32:42 +00:00
vladislavbelov
095838da0a Fixes A8 framebuffer format used for LOS interpolation and enables smooth LOS by default.
Tested By: Langbart, mastoras
Differential Revision: https://code.wildfiregames.com/D4654
This was SVN commit r26906.
2022-05-26 16:36:57 +00:00
vladislavbelov
a6f60afdc5 Adds instancing support to backend and enables it for minimap.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4650
This was SVN commit r26901.
2022-05-24 07:11:23 +00:00
vladislavbelov
1f8705d8f7 Avoids drawing text in GUI if it will be clipped.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4640
This was SVN commit r26870.
2022-05-10 16:32:25 +00:00
vladislavbelov
62e589ab76 Adds renderer backend interface and dummy backend.
Comments By: phosit, Stan
Tested By: Langbart, phosit
Differential Revision: https://code.wildfiregames.com/D4636
This was SVN commit r26858.
2022-05-08 22:02:46 +00:00
vladislavbelov
3ed4eaf247 Removes ogl_WarnIfError from regular renderer code.
This was SVN commit r26850.
2022-05-02 21:52:21 +00:00
vladislavbelov
04bd96cee0 Moves uniform and texture binding to CDeviceCommandContext.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4631
This was SVN commit r26848.
2022-05-02 20:57:22 +00:00