Commit Graph

98 Commits

Author SHA1 Message Date
Peter Nelson
e4cf6ca0ba
Fix: Mis-sized widgets due to missing widget fill. (#14370)
In most places where we calculate and set widget resize step we neglect
to set widget fill step to match. Initial widget sizing uses fill step
instead of resize step, which means the initial size may not be a
multiple of the resize step as intended. In particular this will cause
WWT_MATRIX to be misrendered.

Whether or not this matters depends on the widget type being resized and
the window layout, however for consistency always set fill step to the
same as resize step when calculating.
2025-06-17 17:40:11 +01:00
Peter Nelson
984d864c72 Codechange: Add OnClick handler for dropdown items.
This allows each dropdown item to indicate if something different should happen depending on where in the item was clicked.
2025-05-25 09:13:05 +01:00
Peter Nelson
7344dfe651 Change: Reflow Textfile window content incrementally.
This avoids a stall when reflowing a long text file with some truetype fonts.
2025-05-23 07:42:10 +01:00
Peter Nelson
46b745a06a Codechange: Use a helper method to test if text file window is wrapped. 2025-05-23 07:42:10 +01:00
Rubidium
f8aceb6c37 Codechange: use value initialisation over memset 2025-05-09 17:20:41 +02:00
frosch
61cec33be2 Codechange: Add 'const' to static variables, which are only initialised once. 2025-05-06 18:29:41 +02:00
Peter Nelson
ac76212b80 Fix: Closing the Game Options window closes all textfile windows.
Record the parent window that opens a textfile window so only child windows are closed instead of all.
2025-05-04 19:36:46 +01:00
Peter Nelson
8b14faaa40
Codechange: Add version of DrawStringMultiLine that performs clipping test. (#14189)
Normally DrawStringMultiLine does not perform any clipping, as the return value may be needed if it the text is not drawn.

In some specific cases the height is already known, so it is possible to test for clipping, which can cut down on layouting time for text which won't be visible.
2025-05-02 22:59:55 +01:00
Peter Nelson
3eba97f67c
Codechange: Scrollbar Count no longer needs to be clamped to uint16_t. (#14184) 2025-05-02 22:21:05 +01:00
Rubidium
29ceaf0a84 Codechange: use std::string_view over const char * 2025-04-27 18:04:04 +02:00
Rubidium
781187b8a6 Codechange: replace C-style strings with std::string_view related to strings functions 2025-04-27 17:57:42 +02:00
frosch
fa284af263 Codechange: Replace remaining Utf8Encode usages with StringBuilder. 2025-04-08 23:10:58 +02:00
Peter Nelson
5b9d171e63
Codechange: Use EnumBitSet for StringValidationSettings. (#13974) 2025-04-08 21:19:17 +01:00
Peter Nelson
89948b941b
Codechange: Use emplace_back instead of push_back. (#13855) 2025-03-20 17:39:10 +00:00
Rubidium
754311a779 Codechange: use std::move when appropriate 2025-03-13 13:00:24 +01:00
Peter Nelson
8ba86c54b1
Add: Show hyperlink destination tooltips in text window. (#13742) 2025-03-10 18:12:42 +00:00
Rubidium
2926dd2c2f Codefix: do not dereference the std::end() iterator 2025-03-09 23:33:25 +01:00
Rubidium
0b102db421 Codefix: initialise a few uninitialised variables 2025-03-08 18:01:25 +01:00
Peter Nelson
e2c1b9f03e
Codechange: Use only raw strings in drop down lists. (#13667)
Strings with parameters are now pre-formatted, avoiding global parameters.

Helper functions still allow StringID.
2025-02-27 21:11:16 +00:00
Peter Nelson
d30e8dd1c1 Codechange: Use EnumBitSet for WindowDefaultFlags. 2025-01-30 08:40:42 +00:00
Peter Nelson
afc0745aa2
Codechange: Specify underlying type for all enums excluding those exposed to scripts. (#13383) 2025-01-28 22:17:34 +00:00
Rubidium
7c1ddd74d5 Codefix: use SetToolTip(..) instead of SetStringTip(STR_NULL, ..) 2025-01-03 14:18:59 +01:00
Rubidium
e3a5f9b040 Codechange: replace SetDataTip(AWV_ with SetArrowWidgetTypeTip(AWV_ 2025-01-02 23:28:43 +01:00
Rubidium
4bf36e3fa6 Codechange: replace SetDataTip(STR_ with SetStringTip(STR_ 2025-01-02 23:28:43 +01:00
Peter Nelson
fa1849b855 Codechange: Use std::range::find_if where possible. 2024-11-24 10:36:03 +00:00
Peter Nelson
059a4b22f7 Codechange: Use projection-based std::range::find where possible.
This simplifies matching by class members and avoids wordy lambdas.
2024-11-24 10:36:03 +00:00
Peter Nelson
3cd1200668
Fix #12976: Incorrect widget rect scrolling for RTL languages. (#12978)
Industry directory, AS/GS and Textfile window did not consider RTL when applying horizontal scrolling.
2024-10-05 08:02:59 +01:00
Peter Nelson
908ee7292b
Codechange: Replace all FILE * with FileHandle RAII class. (#12718)
This removes the need to manually ensure all files are closed.
2024-09-16 08:45:26 +01:00
Peter Nelson
91fd082e93
Fix: Apply widget's internal padding to scrollbar capacity/position. (#12801)
For non-WWT_MATRIX widgets, scrollbars need to take account of the internal padding used for the widget.

This is not normally noticeable as framerect padding is only 2 extra pixels
2024-06-22 15:42:13 +00:00
Peter Nelson
55314513ce
Codechange: Pass NWidgetParts as span instead of begin/end pointers. (#12779) 2024-06-12 23:08:35 +01:00
Peter Nelson
4cf6d1dd79
Codechange: Pass WindowDesc by reference instead of pointer. (#12771)
WindowDesc as passed to Windows is not optional so don't allow to it to be nullptr.
2024-06-11 08:58:03 +01:00
Peter Nelson
3d4b98845a
Codechange: Remove initial colour from layouter cache. (#12728)
Initial colour is now always TC_INVALID, which is substituted with the desired colour when drawing the layout line.

This allows strings which differ only by initial colour to use the same layout cache entry, increasing the efficacy of the cache.
2024-05-28 19:33:44 +01:00
Rubidium
9fe9e4d398 Codechange: use vector instead of manual memory management for decompressing text files 2024-05-04 17:43:02 +02:00
Peter Nelson
a28ab8cac2
Codechange: Replace C-style casts to size_t with static_cast. (#12455)
* Codechange: Replace C-style casts to size_t with static_cast.

This touches only simple value-type casts.

* Codechange: Replace static_cast<size_t>(-1) with SIZE_MAX

Co-authored-by: Rubidium <rubidium@openttd.org>
2024-04-19 20:34:36 +01:00
Peter Nelson
de4e00c93f
Codechange: Pass by reference to UpdateWidgetSize. (#12457)
These parameters are always provided and not optional.
2024-04-09 08:34:45 +01:00
Peter Nelson
56cac21086 Codechange: Use functions to create common drop down list items. 2024-04-01 22:33:16 +01:00
Peter Nelson
d683ec0183
Codechange: Move dropdown and slider out of widgets directory. (#12403)
Also shuffle headers to place widget includes near end.

This leaves the widgets directory solely for defining Widget IDs.
2024-03-31 19:37:16 +01:00
Patric Stout
a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 2024-03-16 23:59:32 +01:00
Rubidium
86cb184eb4 Codechange: use std::source_location over __FILE__ and __LINE__ for WindowDesc 2024-03-10 10:14:20 +01:00
Peter Nelson
83d63464db
Fix #11966: Scrollbar may be incorrect on first opening of text file window. (#11981)
The scrollbar is set up before the true monospace is loaded, so reinitialise the window after loading.
2024-02-04 10:15:20 +00:00
Peter Nelson
fef0bfcfd3
Fix: TextfileWindow called virtual methods before constructor completed. (#11889)
SetStringParameters() was called during widget tree init in the constructor.

Calls within a constructor cannot call the derived classes methods. This would result in invalid data being passed to the string system, which could then crash.
2024-01-27 14:45:37 +00:00
Rubidium
2d77cf9c80 Codechange: replace StrStartsWith/StrEndsWith with starts_with and ends_with 2024-01-17 19:48:22 +01:00
Peter Nelson
7737aa6640 Codechange: Make all NWidgetPart arrays constexpr.
This ensures that the arrays are not created at runtime and prevents using non-constexpr values.
2024-01-16 21:57:05 +00:00
Patric Stout
6860a86d45
Codechange: remove all u8 prefix in favour of compile-time option (#11807) 2024-01-16 21:33:53 +00:00
Peter Nelson
a0dfb76e34 Codechange: Replace mishmash of types for widget index with WidgetID.
Indices were stored as int, but often passed around as uint/uint8_t and casts.

Now they should all use WidgetID.
2023-12-30 00:23:57 +00:00
Peter Nelson
fd84f73323
Fix #11643: Empty area at top of survey preview. (#11647)
Empty area at the top of some textfile windows due to calling
SetDisplayedPlane() after calling FinishInitNested(), and/or changing
the displayed plane and not calling ReInit() after.

This was previously hidden by CheckForMissingGlyphs() reinitialising
all windows anyway.
2023-12-30 00:19:27 +00:00
Peter Nelson
313ee13e5f Codechange: Add Rect version of FillDrawPixelInfo().
This simplifies most callers as they longer have to split out a rect.
2023-12-20 09:29:28 +00:00
rubidium42
27082f9efa Codechange: pass std::string references to OpenBrowser 2023-11-29 02:02:30 +01:00
Peter Nelson
e3622da408
Fix #11500: Rename Textfile GUI's LinkType to HyperlinkType. (#11502)
This disambiguates it with LinkType in league tables.
2023-11-27 10:06:46 +00:00
Peter Nelson
c18a1494b7
Codechange: Remove FONT_HEIGHT_... macros. (#11481)
These make it look like we're dealing with a constant, but actually each is a call to `GetCharacterHeight(...)`.
2023-11-21 19:04:24 +00:00