Merge lp:~widelands-dev/widelands/font_size-lua into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9126
Proposed branch: lp:~widelands-dev/widelands/font_size-lua
Merge into: lp:widelands
Diff against target: 7424 lines (+2687/-1172)
134 files modified
data/templates/default/init.lua (+600/-17)
src/CMakeLists.txt (+0/-1)
src/editor/tools/info_tool.cc (+20/-19)
src/editor/ui_menus/main_menu_load_or_save_map.cc (+1/-1)
src/editor/ui_menus/main_menu_map_options.cc (+4/-3)
src/editor/ui_menus/main_menu_random_map.cc (+7/-10)
src/editor/ui_menus/main_menu_save_map.cc (+1/-1)
src/editor/ui_menus/main_menu_save_map_make_directory.cc (+1/-1)
src/editor/ui_menus/player_menu.cc (+13/-8)
src/editor/ui_menus/tool_change_resources_options_menu.cc (+1/-1)
src/graphic/CMakeLists.txt (+5/-19)
src/graphic/align.cc (+48/-1)
src/graphic/align.h (+8/-0)
src/graphic/font_handler.cc (+1/-1)
src/graphic/graphic.cc (+0/-1)
src/graphic/panel_styles.cc (+0/-1)
src/graphic/rendertarget.cc (+1/-1)
src/graphic/style_manager.cc (+245/-49)
src/graphic/style_manager.h (+42/-7)
src/graphic/styles/CMakeLists.txt (+18/-0)
src/graphic/styles/building_statistics_style.h (+99/-0)
src/graphic/styles/button_style.h (+65/-0)
src/graphic/styles/font_style.cc (+130/-0)
src/graphic/styles/font_style.h (+97/-0)
src/graphic/styles/panel_styles.h (+29/-23)
src/graphic/styles/progress_bar_style.h (+69/-0)
src/graphic/styles/statistics_plot_style.h (+68/-0)
src/graphic/styles/table_style.h (+47/-0)
src/graphic/styles/text_panel_style.h (+61/-0)
src/graphic/styles/ware_info_style.h (+80/-0)
src/graphic/text/CMakeLists.txt (+0/-1)
src/graphic/text/font_set.cc (+1/-0)
src/graphic/text/font_set.h (+2/-2)
src/graphic/text/rendered_text.cc (+0/-1)
src/graphic/text/rt_render.cc (+20/-6)
src/graphic/text/rt_render.h (+2/-2)
src/graphic/text_constants.cc (+0/-1)
src/graphic/text_constants.h (+0/-50)
src/graphic/text_layout.cc (+127/-192)
src/graphic/text_layout.h (+37/-68)
src/graphic/wordwrap.cc (+25/-1)
src/graphic/wordwrap.h (+4/-4)
src/io/filesystem/filesystem.cc (+2/-2)
src/logic/map_objects/CMakeLists.txt (+0/-1)
src/logic/map_objects/immovable.cc (+1/-4)
src/logic/map_objects/map_object.cc (+10/-4)
src/logic/map_objects/tribes/building.cc (+5/-5)
src/logic/map_objects/tribes/constructionsite.cc (+1/-4)
src/logic/map_objects/tribes/dismantlesite.cc (+1/-4)
src/logic/map_objects/tribes/militarysite.cc (+3/-5)
src/logic/map_objects/tribes/productionsite.cc (+27/-35)
src/logic/map_objects/tribes/ship.cc (+3/-8)
src/logic/map_objects/tribes/worker.cc (+8/-7)
src/ui_basic/CMakeLists.txt (+0/-1)
src/ui_basic/button.cc (+12/-8)
src/ui_basic/button.h (+3/-3)
src/ui_basic/checkbox.cc (+1/-1)
src/ui_basic/dropdown.cc (+18/-10)
src/ui_basic/dropdown.h (+2/-1)
src/ui_basic/editbox.cc (+62/-49)
src/ui_basic/editbox.h (+6/-5)
src/ui_basic/fullscreen_window.cc (+3/-7)
src/ui_basic/fullscreen_window.h (+2/-3)
src/ui_basic/listselect.cc (+5/-5)
src/ui_basic/listselect.h (+3/-1)
src/ui_basic/messagebox.cc (+6/-3)
src/ui_basic/multilineeditbox.cc (+10/-10)
src/ui_basic/multilinetextarea.cc (+21/-11)
src/ui_basic/multilinetextarea.h (+9/-6)
src/ui_basic/panel.cc (+5/-6)
src/ui_basic/panel.h (+1/-1)
src/ui_basic/progressbar.cc (+6/-8)
src/ui_basic/progressbar.h (+2/-0)
src/ui_basic/progresswindow.cc (+6/-9)
src/ui_basic/progresswindow.h (+1/-0)
src/ui_basic/slider.cc (+9/-8)
src/ui_basic/slider.h (+6/-0)
src/ui_basic/spinbox.cc (+0/-1)
src/ui_basic/table.cc (+16/-9)
src/ui_basic/table.h (+21/-10)
src/ui_basic/tabpanel.cc (+1/-1)
src/ui_basic/textarea.cc (+42/-50)
src/ui_basic/textarea.h (+26/-22)
src/ui_basic/window.cc (+1/-1)
src/ui_fsmenu/CMakeLists.txt (+1/-5)
src/ui_fsmenu/about.cc (+1/-2)
src/ui_fsmenu/campaign_select.cc (+3/-6)
src/ui_fsmenu/campaigndetails.cc (+0/-1)
src/ui_fsmenu/internet_lobby.cc (+26/-23)
src/ui_fsmenu/internet_lobby.h (+0/-1)
src/ui_fsmenu/intro.cc (+5/-3)
src/ui_fsmenu/launch_game.cc (+3/-3)
src/ui_fsmenu/launch_mpg.cc (+19/-18)
src/ui_fsmenu/launch_mpg.h (+0/-2)
src/ui_fsmenu/launch_spg.cc (+19/-9)
src/ui_fsmenu/loadgame.cc (+5/-2)
src/ui_fsmenu/main.cc (+5/-1)
src/ui_fsmenu/mapselect.cc (+2/-2)
src/ui_fsmenu/multiplayer.cc (+4/-3)
src/ui_fsmenu/netsetup_lan.cc (+10/-14)
src/ui_fsmenu/options.cc (+3/-5)
src/ui_fsmenu/scenario_select.cc (+5/-6)
src/ui_fsmenu/scenariodetails.cc (+0/-1)
src/ui_fsmenu/singleplayer.cc (+2/-3)
src/wlapplication.cc (+0/-1)
src/wui/CMakeLists.txt (+4/-4)
src/wui/attack_box.cc (+15/-15)
src/wui/attack_box.h (+2/-4)
src/wui/building_statistics_menu.cc (+42/-57)
src/wui/building_statistics_menu.h (+4/-1)
src/wui/buildingwindow.cc (+4/-3)
src/wui/chat_msg_layout.cc (+28/-46)
src/wui/chat_overlay.cc (+6/-2)
src/wui/encyclopedia_window.cc (+1/-0)
src/wui/fieldaction.cc (+2/-5)
src/wui/game_chat_panel.cc (+3/-3)
src/wui/game_main_menu_save_game.cc (+1/-1)
src/wui/game_message_menu.cc (+1/-0)
src/wui/game_summary.cc (+1/-4)
src/wui/gamedetails.cc (+3/-3)
src/wui/helpwindow.cc (+1/-0)
src/wui/inputqueuedisplay.cc (+25/-15)
src/wui/interactive_base.cc (+4/-5)
src/wui/interactive_gamebase.cc (+4/-5)
src/wui/load_or_save_game.cc (+13/-12)
src/wui/login_box.cc (+7/-7)
src/wui/mapdetails.cc (+4/-3)
src/wui/multiplayersetupgroup.cc (+0/-1)
src/wui/multiplayersetupgroup.h (+0/-1)
src/wui/playerdescrgroup.cc (+0/-1)
src/wui/plot_area.cc (+29/-26)
src/wui/soldierlist.cc (+9/-6)
src/wui/sound_options.h (+1/-0)
src/wui/waresdisplay.cc (+14/-9)
To merge this branch: bzr merge lp:~widelands-dev/widelands/font_size-lua
Reviewer Review Type Date Requested Status
Toni Förster Approve
Review via email: mp+366938@code.launchpad.net

Commit message

Except for scenario and win condition messages, define all font styles via Lua. Reduce the number of construtors in TextArea.

Description of the change

The long-term goal is to allow user-defined styles.

To post a comment you must log in.
8420. By GunChleoc

Cleanup.

8421. By GunChleoc

Update documentation and fix codecheck.

8422. By GunChleoc

Fix shadow name.

8423. By GunChleoc

Merged trunk.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4882. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/528138938.
Appveyor build 4663. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_font_size_lua-4663.

Revision history for this message
kaputtnik (franku) wrote :
Download full text (3.3 KiB)

I get a crash when trying to open the buildings statistics menu:

Texture (21925, 7772) too big! Maximum size is 2048.
Fatal exception: Texture (21925, 7772) too big! Maximum size is 2048.
FATAL ERROR - game crashed. Attempting emergency save.

The crash does not appear in current trunk, so i guess it is in this branch.

Backtrace:
FATAL ERROR - game crashed. Attempting emergency save.
Game: Writing Preload Data ...
Thread 1 "widelands" received signal SIGSEGV, Segmentation fault.
Widelands::GamePreloadPacket::write (this=0x7fffffff9700, fs=..., game=...)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/game_io/game_preload_packet.cc:114
114 s.set_int("gametype", static_cast<int32_t>(game.game_controller()->get_game_type()));
(gdb) bt
#0 Widelands::GamePreloadPacket::write (this=0x7fffffff9700, fs=..., game=...)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/game_io/game_preload_packet.cc:114
#1 0x00005555565af007 in Widelands::GameSaver::save (this=0x7fffffff9800)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/game_io/game_saver.cc:51
#2 0x0000555556148385 in SaveHandler::<lambda(FileSystem&)>::operator()(FileSystem &) const (
    __closure=0x7fffffff9cb0, fs=...)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/logic/save_handler.cc:250
#3 0x0000555556148757 in std::_Function_handler<void(FileSystem&), SaveHandler::save_game(Widelands::Game&, const string&, std::__cxx11::string*)::<lambda(FileSystem&)> >::_M_invoke(const std::_Any_data &, FileSystem &) (
    __functor=..., __args#0=...) at /usr/include/c++/8.3.0/bits/std_function.h:297
#4 0x0000555556474f11 in std::function<void (FileSystem&)>::operator()(FileSystem&) const (this=0x7fffffff9cb0,
    __args#0=...) at /usr/include/c++/8.3.0/bits/std_function.h:687
#5 0x0000555556472a2d in GenericSaveHandler::save_file (this=0x7fffffff9cb0)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/logic/generic_save_handler.cc:108
#6 0x0000555556472f14 in GenericSaveHandler::save (this=0x7fffffff9cb0)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/logic/generic_save_handler.cc:166
#7 0x00005555561484be in SaveHandler::save_game (this=0x7fffffffa910, game=...,
    complete_filename="save/2019-05-10T22.59.49.wgf", error_str=0x7fffffff9e90)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/logic/save_handler.cc:253
#8 0x0000555555f7434e in WLApplication::emergency_save (game=...)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/wlapplication.cc:1482
#9 0x0000555555f73774 in WLApplication::load_game (this=0x555556d08150)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/wlapplication.cc:1384
#10 0x0000555555f722fe in WLApplication::mainmenu_singleplayer (this=0x555556d08150)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/wlapplication.cc:1207
#11 0x0000555555f71c2b in WLApplication::mainmenu (this=0x555556d08150)
    at /home/kaputtnik/Quellcode/widelands-repo/font_size-lua/src/wlapplication.cc:1109
#12 0x0000555555f6dfa7 in WLApplication::run (this=0x555556d08150)
    at /home/kaputtnik/Quellcode/widelands-r...

Read more...

Revision history for this message
kaputtnik (franku) wrote :
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks, I can reproduce this.

Revision history for this message
Toni Förster (stonerl) wrote :

I get 2 compile warnings:

src/graphic/text/rt_render.cc:63:6: warning: no previous prototype for function 'replace_entities' [-Wmissing-prototypes]
void replace_entities(std::string* text) {

src/wui/building_statistics_menu.cc:41:15: warning: unused variable 'kTabHeight' [-Wunused-const-variable]
constexpr int kTabHeight = 35 + 5 * (kBuildGridCellHeight + kLabelHeight + kLabelHeight);

8424. By GunChleoc

Fix crash in building statistics menu & clean up textarea.

8425. By GunChleoc

Merged trunk.

8426. By GunChleoc

FIxed compiler warnings.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Found the bug and fixed the compiler warnings :)

Revision history for this message
Toni Förster (stonerl) wrote :

Some problems in the lobby and multiplayer chat:

- The text in the input box is not centred
  (q,g, j and so on are cut off)
- Private messages double the prefix
- The @ in private message shouldn't be underlined
- There should either be no space before the @
  in private messages or an additional behind the @
  (as it is b20)
- If we have the space it should not be underlined
- The Username and the message look a little of
  (The message seems to be 2-4 pixels to high)

See this picture:

https://fosuta.org/pics/lua_chat.png

Revision history for this message
Toni Förster (stonerl) wrote :

=== modified file 'src/wui/game_chat_panel.cc'
--- src/wui/game_chat_panel.cc 2019-05-12 07:45:59 +0000
+++ src/wui/game_chat_panel.cc 2019-05-12 13:12:29 +0000
@@ -41,12 +41,12 @@
              0,
              0,
              w,
- h - 25,
+ h - 30,
              style,
              "",
              UI::Align::kLeft,
              UI::MultilineTextarea::ScrollMode::kScrollLogForced),
- editbox(this, 0, h - 20, w, style),
+ editbox(this, 0, h - 25, w, style),
      chat_message_counter(0),
      chat_sound(SoundHandler::register_fx(SoundType::kChat, "sound/lobby_chat")) {

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4953. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/531353166.
Appveyor build 4734. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_font_size_lua-4734.

8427. By GunChleoc

Merged trunk.

8428. By GunChleoc

Fix chat message layouting.

8429. By GunChleoc

Made editbox taller.

Revision history for this message
GunChleoc (gunchleoc) wrote :

- The text in the input box is not centred
  (q,g, j and so on are cut off)

Thanks for the fix. The whole alignment code in the editbox should be overhauled sometime.

- Private messages double the prefix

Fixed

- The @ in private message shouldn't be underlined

Fixed

- There should either be no space before the @
  in private messages or an additional behind the @
  (as it is b20)

I did that on purpose. Mentions on Twitter and lots of modern messageboards etc. are always "@username", never "@ username".
No space before the @ would make it too hard to read-

- If we have the space it should not be underlined

Fixed

- The Username and the message look a little of
  (The message seems to be 2-4 pixels to high)

That's https://bugs.launchpad.net/widelands/+bug/1827544 and out of scope for this branch

Revision history for this message
Toni Förster (stonerl) wrote :

On more question. We have 2 different fonts now. The one used in editboxes is completely different from the other font. Is this intentionally?

Revision history for this message
Toni Förster (stonerl) wrote :

And one more. This is the handling of direct messages. I know this is branch is about fonts but maybe we can address this here.

Do we need:

sender @recepiant: text

For direct messages? The name is already coloured green and the text italic. This differentiates the message more than enough from normal messages IMHO.

For the sender:

@recepiant: text

For the recipient:

sender: text

This should be sufficient, IMHO.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Good idea. I'd also like each player name to have the respective player's color, but this will need changing of the chat message protocol, because we only have 1 of the 2 player colors available there. So, not in this branch.

> On more question. We have 2 different fonts now. The one used in editboxes is completely different from the other font. Is this intentionally?

It's the same font. The only difference is that it's not bold. I think it looks better if we use bold fonts only for headings etc.

Revision history for this message
Toni Förster (stonerl) wrote :

In trunk admins are written in green in the client list. Did you remove this on purpose? If not, I'm going to post the patch the next comment,

Revision history for this message
Toni Förster (stonerl) wrote :

=== modified file 'src/ui_fsmenu/internet_lobby.cc'
--- src/ui_fsmenu/internet_lobby.cc 2019-05-13 06:04:34 +0000
+++ src/ui_fsmenu/internet_lobby.cc 2019-05-15 08:36:30 +0000
@@ -296,6 +296,8 @@
    case kClientSuperuser:
     pic = g_gr->images().get("images/wui/overlays/roadb_green.png");
     er.set_picture(0, pic);
+ er.set_color(RGBColor(0, 255, 0));
+ er.set_picture(0, pic);
     break;
    case kClientIRC:
     // No icon for IRC users

8430. By GunChleoc

Merged trunk.

8431. By GunChleoc

Add font style for superusers.

Revision history for this message
GunChleoc (gunchleoc) wrote :

That one fell victim to a merge conflict. I have added the style now :)

Revision history for this message
Toni Förster (stonerl) wrote :

LGTM :)

review: Approve
8432. By GunChleoc

Merged trunk.

8433. By GunChleoc

Add disabled style to textareas for login box.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks a lot for the review!

@bunnybot merge

8434. By GunChleoc

Fixed codecheck.

8435. By GunChleoc

Merged trunk.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5055. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/537329044.
Appveyor build 4835. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_font_size_lua-4835.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/templates/default/init.lua'
2--- data/templates/default/init.lua 2017-06-14 06:40:42 +0000
3+++ data/templates/default/init.lua 2019-05-26 02:00:17 +0000
4@@ -1,7 +1,15 @@
5 -- This script defines a GUI style for Widelands. At the moment, we only
6 -- support the default template.
7--- So far, only background textures and colors can be defined, and they all have
8--- the format { image = filename, color = {r, g, b } }.
9+
10+-- Background textures and colors have the format { image = filename, color = {r, g, b } }.
11+
12+-- Required parameters for font styles are:
13+-- * face: string
14+-- * color: table with r, g, b values as int
15+-- * size: positive int
16+-- Optional bools are: bold, italic, underline, shadow
17+
18+-- Some elements carry custom parameters like e.g. "margin" that should be expanded upon in the future.
19
20 dirname = path.dirname(__file__)
21
22@@ -17,43 +25,222 @@
23 local wui_green = {3, 15, 0}
24 local wui_brown = {32, 19, 8}
25
26+local fs_font_color = {255, 255, 0}
27+local fs_font_face = "sans"
28+local fs_font_size = 14
29+
30+local wui_font_color = {255, 255, 0}
31+local wui_font_face = "sans"
32+local wui_font_size = 14
33+
34+local default_ui_font = {
35+ color = fs_font_color,
36+ face = fs_font_face,
37+ size = fs_font_size,
38+ bold = true,
39+ shadow = true
40+}
41+
42+local default_button_fonts = {
43+ enabled = default_ui_font,
44+ disabled = {
45+ color = {127, 127, 127},
46+ face = fs_font_face,
47+ size = fs_font_size,
48+ bold = true,
49+ shadow = true
50+ },
51+}
52+
53+local productivity_colors = {
54+ low = {187, 0, 0},
55+ medium = {255, 225, 30},
56+ high = {0, 187, 0},
57+}
58+
59 -- These are the style definitions to be returned.
60 -- Note: you have to keep all the keys intact, or Widelands will not be happy.
61 return {
62- -- Button backgrounds
63+ -- Automatic resizing of fonts to make them fit onto buttons etc.
64+ -- won't go below this size
65+ minimum_font_size = 10,
66+ minimap_icon_frame = fs_font_color,
67+
68+ -- Buttons
69 buttons = {
70 -- Buttons used in Fullscreen menus
71 fsmenu = {
72 -- Main menu ("Single Player", "Watch Replay", ...)
73- menu = { image = fs_button, color = fs_blue },
74+ menu = {
75+ enabled = {
76+ font = default_button_fonts["enabled"],
77+ background = {
78+ image = fs_button,
79+ color = fs_blue,
80+ }
81+ },
82+ disabled = {
83+ font = default_button_fonts["disabled"],
84+ background = {
85+ image = fs_button,
86+ color = fs_blue,
87+ }
88+ }
89+ },
90 -- Primary user selection ("OK", ...)
91- primary = { image = fs_button, color = fs_green },
92+ primary = {
93+ enabled = {
94+ font = default_button_fonts["enabled"],
95+ background = {
96+ image = fs_button,
97+ color = fs_green,
98+ }
99+ },
100+ disabled = {
101+ font = default_button_fonts["disabled"],
102+ background = {
103+ image = fs_button,
104+ color = fs_green,
105+ }
106+ }
107+ },
108 -- Secondary user selection ("Cancel", "Delete", selection buttons, ...)
109- secondary = { image = fs_button, color = fs_brown },
110+ secondary = {
111+ enabled = {
112+ font = default_button_fonts["enabled"],
113+ background = {
114+ image = fs_button,
115+ color = fs_brown,
116+ }
117+ },
118+ disabled = {
119+ font = default_button_fonts["disabled"],
120+ background = {
121+ image = fs_button,
122+ color = fs_brown,
123+ }
124+ }
125+ },
126 },
127 -- Buttons used in-game and in the editor
128 wui = {
129 -- Main menu ("Exit Game"), Building Windows, selection buttons, ...
130- menu = { image = wui_button, color = wui_light },
131+ menu = {
132+ enabled = {
133+ font = default_button_fonts["enabled"],
134+ background = {
135+ image = wui_button,
136+ color = wui_light,
137+ }
138+ },
139+ disabled = {
140+ font = default_button_fonts["disabled"],
141+ background = {
142+ image = wui_button,
143+ color = wui_light,
144+ }
145+ }
146+ },
147 -- Primary user selection ("OK", attack, ...)
148- primary = { image = wui_button, color = wui_green },
149+ primary = {
150+ enabled = {
151+ font = default_button_fonts["enabled"],
152+ background = {
153+ image = wui_button,
154+ color = wui_green,
155+ }
156+ },
157+ disabled = {
158+ font = default_button_fonts["disabled"],
159+ background = {
160+ image = wui_button,
161+ color = wui_green,
162+ }
163+ }
164+ },
165 -- Secondary user selection ("Cancel", "Delete", ...)
166- secondary = { image = wui_button, color = wui_brown },
167+ secondary = {
168+ enabled = {
169+ font = default_button_fonts["enabled"],
170+ background = {
171+ image = wui_button,
172+ color = wui_brown,
173+ }
174+ },
175+ disabled = {
176+ font = default_button_fonts["disabled"],
177+ background = {
178+ image = wui_button,
179+ color = wui_brown,
180+ }
181+ }
182+ },
183 -- Building buttons on fieldaction and building statistics need to be
184 -- transparent in order to match the background of the tab panel.
185- building_stats = { image = "", color = {0, 0, 0} },
186+ building_stats = {
187+ enabled = {
188+ font = default_button_fonts["enabled"],
189+ background = {
190+ image = "",
191+ color = {0, 0, 0},
192+ }
193+ },
194+ disabled = {
195+ font = default_button_fonts["disabled"],
196+ background = {
197+ image = "",
198+ color = {0, 0, 0},
199+ }
200+ }
201+ },
202 }
203 },
204 -- Slider cursors (Sound control, attack, statistics, ...)
205 sliders = {
206 fsmenu = {
207- menu = { image = fs_button, color = fs_blue },
208+ menu = {
209+ background = {
210+ image = fs_button,
211+ color = fs_blue,
212+ },
213+ font = {
214+ color = fs_font_color,
215+ face = "condensed",
216+ size = 11,
217+ bold = true,
218+ shadow = true
219+ }
220+ }
221 },
222 wui = {
223 -- Sound Options, Statistics
224- light = { image = wui_button, color = wui_brown },
225+ light = {
226+ background = {
227+ image = wui_button,
228+ color = wui_brown,
229+ },
230+ font = {
231+ color = fs_font_color,
232+ face = "condensed",
233+ size = 11,
234+ bold = true,
235+ shadow = true
236+ }
237+ },
238 -- Fieldaction (attack)
239- dark = { image = wui_button, color = wui_green },
240+ dark = {
241+ background = {
242+ image = wui_button,
243+ color = wui_green,
244+ },
245+ font = {
246+ color = fs_font_color,
247+ face = "condensed",
248+ size = 11,
249+ bold = true,
250+ shadow = true
251+ }
252+ },
253 }
254 },
255 -- Background for tab panels
256@@ -74,11 +261,31 @@
257 -- Used both for one-line and multiline edit boxes
258 editboxes = {
259 fsmenu = {
260- menu = { image = fs_button, color = fs_green },
261+ background = {
262+ image = fs_button,
263+ color = fs_green,
264+ margin = 4
265+ },
266+ font = {
267+ color = fs_font_color,
268+ face = fs_font_face,
269+ size = fs_font_size,
270+ shadow = true
271+ },
272 },
273 wui = {
274- menu = { image = wui_button, color = wui_brown },
275- }
276+ background = {
277+ image = wui_button,
278+ color = wui_brown,
279+ margin = 2,
280+ },
281+ font = {
282+ color = wui_font_color,
283+ face = wui_font_face,
284+ size = wui_font_size,
285+ shadow = true
286+ },
287+ },
288 },
289 -- Background for dropdown menus
290 dropdowns = {
291@@ -97,5 +304,381 @@
292 wui = {
293 menu = { image = wui_button, color = wui_brown },
294 }
295- }
296+ },
297+
298+ -- In-game statistics plots
299+ statistics_plot = {
300+ fonts = {
301+ x_tick = {
302+ color = { 255, 0, 0 },
303+ face = "condensed",
304+ size = 13,
305+ },
306+ y_min_value = {
307+ color = { 125, 0, 0 },
308+ face = "condensed",
309+ size = 13,
310+ },
311+ y_max_value = {
312+ color = { 60, 125, 0 },
313+ face = "condensed",
314+ size = 13,
315+ },
316+ },
317+ colors = {
318+ axis_line = { 0, 0, 0 },
319+ zero_line = { 255, 255, 255 },
320+ }
321+ },
322+
323+ -- Map census and statistics, and building statistics window
324+ building_statistics = {
325+ census_font = {
326+ color = wui_font_color, -- Default color
327+ face = "condensed",
328+ size = wui_font_size,
329+ bold = true,
330+ shadow = true
331+ },
332+ statistics_font = {
333+ color = wui_font_color, -- Default color
334+ face = "condensed",
335+ size = wui_font_size,
336+ bold = true,
337+ shadow = true
338+ },
339+ -- Building statistics window
340+ statistics_window = {
341+ fonts = {
342+ button_font = {
343+ color = wui_font_color, -- Default color
344+ face = "condensed",
345+ size = 12, -- Do not make this bigger - the UI element size is still hard-coded.
346+ bold = true,
347+ shadow = true
348+ },
349+ details_font = {
350+ color = wui_font_color, -- Default color
351+ face = "sans",
352+ size = 12, -- Do not make this bigger - the UI element size is still hard-coded.
353+ bold = true,
354+ shadow = true
355+ },
356+ },
357+ editbox_margin = 0
358+ },
359+ colors = {
360+ construction = { 163, 144, 19 },
361+ neutral = { 255, 250, 170 },
362+ low = productivity_colors["low"],
363+ medium = productivity_colors["medium"],
364+ high = productivity_colors["high"],
365+ }
366+ },
367+
368+ progressbar = {
369+ fsmenu = {
370+ font = {
371+ color = { 128, 128, 255 },
372+ face = fs_font_face,
373+ size = fs_font_size,
374+ bold = true,
375+ shadow = true
376+ },
377+ background_colors = {
378+ low = { 64, 64, 0 }, -- Unused
379+ medium = { 64, 64, 0 },
380+ high = { 64, 64, 0 }, -- Unused
381+ }
382+ },
383+ wui = {
384+ font = {
385+ color = {255, 250, 170},
386+ face = wui_font_face,
387+ size = wui_font_size,
388+ bold = true,
389+ shadow = true
390+ },
391+ background_colors = {
392+ low = productivity_colors["low"],
393+ medium = productivity_colors["medium"],
394+ high = productivity_colors["high"],
395+ }
396+ }
397+ },
398+
399+ tables = {
400+ fsmenu = {
401+ enabled = {
402+ color = fs_font_color,
403+ face = fs_font_face,
404+ size = fs_font_size,
405+ bold = true,
406+ shadow = true
407+ },
408+ disabled = {
409+ color = {127, 127, 127},
410+ face = fs_font_face,
411+ size = fs_font_size,
412+ bold = true,
413+ shadow = true
414+ }
415+ },
416+ wui = {
417+ enabled = {
418+ color = fs_font_color,
419+ face = fs_font_face,
420+ size = fs_font_size,
421+ bold = true,
422+ shadow = true
423+ },
424+ disabled = {
425+ color = {127, 127, 127},
426+ face = fs_font_face,
427+ size = fs_font_size,
428+ bold = true,
429+ shadow = true
430+ }
431+ },
432+ },
433+
434+ wareinfo = {
435+ -- TODO(GunChleoc): This design is ugly.
436+ -- Group stuff more logically once everything has been styled.
437+ normal = {
438+ fonts = {
439+ header = {
440+ color = wui_font_color,
441+ face = "sans",
442+ size = 11,
443+ },
444+ info = {
445+ color = wui_font_color,
446+ face = "condensed",
447+ size = 10,
448+ },
449+ },
450+ colors = {
451+ icon_frame = { 69, 69, 69 },
452+ icon_background = { 69, 69, 69 },
453+ info_background = { 0, 0, 0 },
454+ },
455+ icon_background_image = "images/wui/ware_list_bg.png",
456+ },
457+ highlight = {
458+ fonts = {
459+ header = {
460+ color = wui_font_color,
461+ face = "sans",
462+ size = 11,
463+ },
464+ info = {
465+ color = wui_font_color,
466+ face = "condensed",
467+ size = 10,
468+ },
469+ },
470+ colors = {
471+ icon_frame = {255, 255, 0},
472+ icon_background = {69, 69, 69},
473+ info_background = {0, 0, 0},
474+ },
475+ icon_background_image = "images/wui/ware_list_bg_selected.png",
476+ }
477+ },
478+
479+ -- Font styles. Required parameters are:
480+ -- * face: string
481+ -- * color: table with r, g, b values as int
482+ -- * size: positive int
483+ -- Optional bools are: bold, italic, underline, shadow
484+ fonts = {
485+ -- Basic chat message text color
486+ chat_message = {
487+ color = wui_font_color,
488+ face = "serif",
489+ size = fs_font_size,
490+ shadow = true,
491+ },
492+ -- Basic chat message text color
493+ chat_timestamp = {
494+ color = { 51, 255, 51 },
495+ face = "serif",
496+ size = 9,
497+ shadow = true,
498+ },
499+ -- Chat for private messages
500+ chat_whisper = {
501+ color = { 238, 238, 238 },
502+ face = "serif",
503+ size = fs_font_size,
504+ italic = true,
505+ shadow = true,
506+ },
507+ -- Chat playername highlight
508+ chat_playername = {
509+ color = { 255, 255, 255 },
510+ face = "serif",
511+ size = fs_font_size,
512+ bold = true,
513+ shadow = true,
514+ },
515+ -- Chat log messages color. Also doubles as spectator playercolor for chat messages.
516+ chat_server = {
517+ color = { 221, 221, 221 },
518+ face = "serif",
519+ size = fs_font_size,
520+ bold = true,
521+ shadow = true,
522+ },
523+ -- Intro screen
524+ fsmenu_intro = {
525+ color = { 192, 192, 128 },
526+ face = fs_font_face,
527+ size = 16,
528+ bold = true,
529+ shadow = true
530+ },
531+ -- Displayed in the loading screens
532+ fsmenu_gametip = {
533+ color = { 33, 33, 27 },
534+ face = "serif",
535+ size = 16,
536+ },
537+ -- Game and Map info panels
538+ fsmenu_info_panel_heading = {
539+ color = { 255, 255, 0 },
540+ face = fs_font_face,
541+ size = fs_font_size,
542+ bold = true,
543+ shadow = true
544+ },
545+ fsmenu_info_panel_paragraph = {
546+ color = { 209, 209, 209 },
547+ face = fs_font_face,
548+ size = fs_font_size,
549+ shadow = true
550+ },
551+ -- Internet lobby and launch game
552+ fsmenu_game_setup_headings = {
553+ color = { 0, 255, 0 },
554+ face = fs_font_face,
555+ size = fs_font_size,
556+ bold = true,
557+ shadow = true
558+ },
559+ fsmenu_game_setup_mapname = {
560+ color = { 255, 255, 127 },
561+ face = fs_font_face,
562+ size = fs_font_size,
563+ bold = true,
564+ shadow = true
565+ },
566+ -- List admin in the internet lobby
567+ fsmenu_game_setup_superuser = {
568+ color = { 0, 255, 0 },
569+ face = fs_font_face,
570+ size = fs_font_size,
571+ bold = true,
572+ shadow = true
573+ },
574+ -- List IRC clients in the internet lobby
575+ fsmenu_game_setup_irc_client = {
576+ color = { 221, 221, 221 },
577+ face = fs_font_face,
578+ size = fs_font_size,
579+ bold = true,
580+ shadow = true
581+ },
582+ -- Page titles. Also used in game summary TODO(GunChleoc): Refactor game summary
583+ fsmenu_title = {
584+ color = fs_font_color,
585+ face = fs_font_face,
586+ size = 22,
587+ bold = true,
588+ shadow = true
589+ },
590+ -- Make font a bit smaller so the link will fit at 800x600 resolution.
591+ fsmenu_translation_info = {
592+ color = fs_font_color,
593+ face = fs_font_face,
594+ size = fs_font_size - 2,
595+ bold = true,
596+ shadow = true
597+ },
598+
599+ -- Textarea default style, also used for sliders, checkboxes, both in fsmenu and wui ...
600+ label = default_ui_font,
601+ tooltip = {
602+ color = fs_font_color,
603+ face = fs_font_face,
604+ size = 14,
605+ bold = false,
606+ },
607+ tooltip_header = {
608+ color = fs_font_color,
609+ face = fs_font_face,
610+ size = 16,
611+ bold = true,
612+ },
613+ warning = {
614+ color = {255, 22, 22},
615+ face = fs_font_face,
616+ size = fs_font_size,
617+ bold = true,
618+ shadow = true
619+ },
620+ disabled = {
621+ color = {127, 127, 127},
622+ face = fs_font_face,
623+ size = fs_font_size,
624+ bold = true,
625+ shadow = true
626+ },
627+
628+ wui_attack_box_slider_label = {
629+ color = wui_font_color,
630+ face = wui_font_face,
631+ size = 10,
632+ bold = true,
633+ shadow = true
634+ },
635+ wui_info_panel_heading = {
636+ color = { 209, 209, 209 },
637+ face = wui_font_face,
638+ size = wui_font_size,
639+ bold = true,
640+ },
641+ wui_info_panel_paragraph = {
642+ color = { 255, 255, 0 },
643+ face = wui_font_face,
644+ size = wui_font_size,
645+ },
646+ -- Messages
647+ wui_message_heading = {
648+ color = { 209, 209, 209 },
649+ face = wui_font_face,
650+ size = 18,
651+ bold = true,
652+ },
653+ wui_message_paragraph = {
654+ color = { 255, 255, 0 },
655+ face = wui_font_face,
656+ size = 12,
657+ },
658+ wui_window_title = {
659+ color = fs_font_color,
660+ face = wui_font_face,
661+ size = 13,
662+ bold=true,
663+ shadow=true,
664+ },
665+ wui_game_speed_and_coordinates = {
666+ color = wui_font_color,
667+ face = "condensed",
668+ size = wui_font_size,
669+ bold = true,
670+ shadow = true
671+ },
672+ },
673 }
674
675=== modified file 'src/CMakeLists.txt'
676--- src/CMakeLists.txt 2019-05-05 18:53:14 +0000
677+++ src/CMakeLists.txt 2019-05-26 02:00:17 +0000
678@@ -107,7 +107,6 @@
679 graphic
680 graphic_fonthandler
681 graphic_text
682- graphic_text_constants
683 helper
684 io_filesystem
685 logic
686
687=== modified file 'src/editor/tools/info_tool.cc'
688--- src/editor/tools/info_tool.cc 2019-04-09 16:43:49 +0000
689+++ src/editor/tools/info_tool.cc 2019-05-26 02:00:17 +0000
690@@ -39,7 +39,8 @@
691 EditorActionArgs* /* args */,
692 Widelands::Map* map) {
693
694- static constexpr int kListFontsize = UI_FONT_SIZE_MESSAGE;
695+ constexpr UI::FontStyle font_style = UI::FontStyle::kWuiInfoPanelParagraph;
696+
697 parent.stop_painting();
698
699 UI::Window* const w =
700@@ -53,7 +54,7 @@
701 std::string buf = as_heading(_("Node"), UI::PanelStyle::kWui, true);
702 buf += as_listitem(
703 (boost::format(_("Coordinates: (%1$i, %2$i)")) % center.node.x % center.node.y).str(),
704- kListFontsize);
705+ font_style);
706
707 std::vector<std::string> caps_strings;
708 Widelands::NodeCaps const caps = f.nodecaps();
709@@ -100,15 +101,15 @@
710 buf += as_listitem((boost::format(_("Caps: %s")) %
711 i18n::localize_list(caps_strings, i18n::ConcatenateWith::COMMA))
712 .str(),
713- kListFontsize);
714+ font_style);
715
716 if (f.get_owned_by() > 0) {
717 buf += as_listitem(
718 (boost::format(_("Owned by: Player %u")) % static_cast<unsigned int>(f.get_owned_by()))
719 .str(),
720- kListFontsize);
721+ font_style);
722 } else {
723- buf += as_listitem(_("Owned by: —"), kListFontsize);
724+ buf += as_listitem(_("Owned by: —"), font_style);
725 }
726
727 // *** Terrain info
728@@ -119,7 +120,7 @@
729 center.triangle.t == Widelands::TriangleIndex::D ? tf.terrain_d() : tf.terrain_r());
730
731 buf += as_listitem(
732- (boost::format(pgettext("terrain_name", "Name: %s")) % ter.descname()).str(), kListFontsize);
733+ (boost::format(pgettext("terrain_name", "Name: %s")) % ter.descname()).str(), font_style);
734
735 std::vector<std::string> terrain_is_strings;
736 for (const Widelands::TerrainDescription::Type& terrain_type : ter.get_types()) {
737@@ -132,10 +133,10 @@
738 (boost::format(_("Is: %s")) %
739 i18n::localize_list(terrain_is_strings, i18n::ConcatenateWith::AMPERSAND))
740 .str(),
741- kListFontsize);
742+ font_style);
743 buf += as_listitem(
744 (boost::format(_("Editor Category: %s")) % ter.editor_category()->descname()).str(),
745- kListFontsize);
746+ font_style);
747
748 // *** Map Object info
749 const Widelands::BaseImmovable* immovable = f.get_immovable();
750@@ -146,7 +147,7 @@
751 if (immovable) {
752 buf +=
753 as_listitem((boost::format(_("Immovable: %s")) % immovable->descr().descname()).str(),
754- kListFontsize);
755+ font_style);
756 }
757
758 if (bob) {
759@@ -179,19 +180,19 @@
760 buf += as_listitem((boost::format(_("Animals: %s")) %
761 i18n::localize_list(critternames, i18n::ConcatenateWith::COMMA))
762 .str(),
763- kListFontsize);
764+ font_style);
765 }
766 if (!workernames.empty()) {
767 buf += as_listitem((boost::format(_("Workers: %s")) %
768 i18n::localize_list(workernames, i18n::ConcatenateWith::COMMA))
769 .str(),
770- kListFontsize);
771+ font_style);
772 }
773 if (!shipnames.empty()) {
774 buf += as_listitem((boost::format(_("Ships: %s")) %
775 i18n::localize_list(shipnames, i18n::ConcatenateWith::COMMA))
776 .str(),
777- kListFontsize);
778+ font_style);
779 }
780 }
781 }
782@@ -204,28 +205,28 @@
783 (boost::format(pgettext("resources", "%1%x %2%")) % static_cast<unsigned int>(ramount) %
784 world.get_resource(f.get_resources())->descname())
785 .str(),
786- kListFontsize);
787+ font_style);
788 }
789
790 // *** Map info
791 buf += as_heading(_("Map"), UI::PanelStyle::kWui);
792 buf += as_listitem(
793- (boost::format(pgettext("map_name", "Name: %s")) % map->get_name()).str(), kListFontsize);
794+ (boost::format(pgettext("map_name", "Name: %s")) % map->get_name()).str(), font_style);
795 buf += as_listitem(
796 (boost::format(_("Size: %1% x %2%")) % map->get_width() % map->get_height()).str(),
797- kListFontsize);
798+ font_style);
799
800 if (map->get_nrplayers() > 0) {
801 buf += as_listitem(
802 (boost::format(_("Players: %u")) % static_cast<unsigned int>(map->get_nrplayers())).str(),
803- kListFontsize);
804+ font_style);
805 } else {
806- buf += as_listitem(_("Players: –"), kListFontsize);
807+ buf += as_listitem(_("Players: –"), font_style);
808 }
809
810- buf += as_listitem((boost::format(_("Author: %s")) % map->get_author()).str(), kListFontsize);
811+ buf += as_listitem((boost::format(_("Author: %s")) % map->get_author()).str(), font_style);
812 buf += as_listitem(
813- (boost::format(_("Description: %s")) % map->get_description()).str(), kListFontsize);
814+ (boost::format(_("Description: %s")) % map->get_description()).str(), font_style);
815
816 multiline_textarea->set_text(as_richtext(buf));
817
818
819=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc'
820--- src/editor/ui_menus/main_menu_load_or_save_map.cc 2019-04-18 16:50:35 +0000
821+++ src/editor/ui_menus/main_menu_load_or_save_map.cc 2019-05-26 02:00:17 +0000
822@@ -55,7 +55,7 @@
823 get_inner_w() - right_column_x_ - padding_,
824 tableh_,
825 UI::PanelStyle::kWui),
826- directory_info_(this, padding_, get_inner_h() - 2 * buth_ - 4 * padding_),
827+ directory_info_(this, padding_, get_inner_h() - 2 * buth_ - 4 * padding_, 0, 0),
828 ok_(this,
829 "ok",
830 UI::g_fh->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ :
831
832=== modified file 'src/editor/ui_menus/main_menu_map_options.cc'
833--- src/editor/ui_menus/main_menu_map_options.cc 2019-02-23 11:00:49 +0000
834+++ src/editor/ui_menus/main_menu_map_options.cc 2019-05-26 02:00:17 +0000
835@@ -28,6 +28,7 @@
836 #include "editor/editorinteractive.h"
837 #include "graphic/font_handler.h"
838 #include "graphic/graphic.h"
839+#include "graphic/text_layout.h"
840 #include "logic/map.h"
841 #include "ui_basic/editbox.h"
842 #include "ui_basic/multilineeditbox.h"
843@@ -45,7 +46,7 @@
844 : UI::Window(&parent, "map_options", 0, 0, 350, parent.get_inner_h() - 80, _("Map Options")),
845 padding_(4),
846 indent_(10),
847- labelh_(text_height() + 4),
848+ labelh_(text_height(UI::FontStyle::kLabel) + 4),
849 checkbox_space_(25),
850 butw_((get_inner_w() - 3 * padding_) / 2),
851 max_w_(get_inner_w() - 2 * padding_),
852@@ -72,8 +73,8 @@
853 tags_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),
854 teams_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),
855
856- name_(&main_box_, 0, 0, max_w_, 0, 2, UI::PanelStyle::kWui),
857- author_(&main_box_, 0, 0, max_w_, 0, 2, UI::PanelStyle::kWui),
858+ name_(&main_box_, 0, 0, max_w_, UI::PanelStyle::kWui),
859+ author_(&main_box_, 0, 0, max_w_, UI::PanelStyle::kWui),
860 size_(&main_box_, 0, 0, max_w_ - indent_, labelh_, ""),
861
862 teams_list_(
863
864=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
865--- src/editor/ui_menus/main_menu_random_map.cc 2019-04-24 07:09:29 +0000
866+++ src/editor/ui_menus/main_menu_random_map.cc 2019-05-26 02:00:17 +0000
867@@ -32,6 +32,7 @@
868 #include "editor/editorinteractive.h"
869 #include "editor/map_generator.h"
870 #include "graphic/font_handler.h"
871+#include "graphic/text_layout.h"
872 #include "logic/editor_game_base.h"
873 #include "logic/map.h"
874 #include "logic/map_objects/world/world.h"
875@@ -51,7 +52,7 @@
876 // UI elements
877 margin_(4),
878 box_width_(get_inner_w() - 2 * margin_),
879- label_height_(text_height() + 2),
880+ label_height_(text_height(UI::FontStyle::kLabel) + 2),
881 box_(this, margin_, margin_, UI::Box::Vertical, 0, 0, margin_),
882 // Size
883 width_(&box_,
884@@ -108,8 +109,8 @@
885 resource_amount_(2),
886 world_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
887 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
888- world_label_(&world_box_, 0, 0, _("Climate:")),
889- resources_label_(&resources_box_, 0, 0, _("Resources:")),
890+ world_label_(&world_box_, 0, 0, 0, 0, _("Climate:")),
891+ resources_label_(&resources_box_, 0, 0, 0, 0, _("Resources:")),
892 world_(&world_box_,
893 "world",
894 0,
895@@ -171,7 +172,7 @@
896 UI::SpinBox::Type::kSmall,
897 5),
898 mountains_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
899- mountains_label_(&mountains_box_, 0, 0, _("Mountains:")),
900+ mountains_label_(&mountains_box_, 0, 0, 0, 0, _("Mountains:")),
901 mountains_(&mountains_box_,
902 0,
903 0,
904@@ -182,22 +183,18 @@
905 island_mode_(&box_, Vector2i::zero(), _("Island mode")),
906 // Geeky stuff
907 map_number_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
908- map_number_label_(&map_number_box_, 0, 0, _("Random number:")),
909+ map_number_label_(&map_number_box_, 0, 0, 0, 0, _("Random number:")),
910 map_number_edit_(&map_number_box_,
911 0,
912 0,
913 box_width_ - 2 * margin_ - map_number_label_.get_w(),
914- 0,
915- 2,
916 UI::PanelStyle::kWui),
917 map_id_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
918- map_id_label_(&map_id_box_, 0, 0, _("Map ID:")),
919+ map_id_label_(&map_id_box_, 0, 0, 0, 0, _("Map ID:")),
920 map_id_edit_(&map_id_box_,
921 0,
922 0,
923 box_width_ - 2 * margin_ - map_id_label_.get_w(),
924- 0,
925- 2,
926 UI::PanelStyle::kWui),
927 // Buttons
928 button_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
929
930=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
931--- src/editor/ui_menus/main_menu_save_map.cc 2019-03-18 21:10:56 +0000
932+++ src/editor/ui_menus/main_menu_save_map.cc 2019-05-26 02:00:17 +0000
933@@ -83,7 +83,7 @@
934
935 editbox_ = new UI::EditBox(
936 this, editbox_label_.get_x() + editbox_label_.get_w() + padding_, editbox_label_.get_y(),
937- tablew_ - editbox_label_.get_w() - padding_ + 1, buth_, 2, UI::PanelStyle::kWui);
938+ tablew_ - editbox_label_.get_w() - padding_ + 1, UI::PanelStyle::kWui);
939 editbox_->set_text(parent.egbase().map().get_name());
940
941 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));
942
943=== modified file 'src/editor/ui_menus/main_menu_save_map_make_directory.cc'
944--- src/editor/ui_menus/main_menu_save_map_make_directory.cc 2019-02-23 11:00:49 +0000
945+++ src/editor/ui_menus/main_menu_save_map_make_directory.cc 2019-05-26 02:00:17 +0000
946@@ -41,7 +41,7 @@
947 get_inner_h() - 3 * padding_ - buth_,
948 padding_ / 2),
949 label_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, buth_, _("Enter Directory Name:")),
950- edit_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, 0, 4, UI::PanelStyle::kWui),
951+ edit_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, UI::PanelStyle::kWui),
952 ok_button_(this,
953 "ok",
954 UI::g_fh->fontset()->is_rtl() ? padding_ : get_inner_w() - butw_ - padding_,
955
956=== modified file 'src/editor/ui_menus/player_menu.cc'
957--- src/editor/ui_menus/player_menu.cc 2019-02-27 19:00:36 +0000
958+++ src/editor/ui_menus/player_menu.cc 2019-05-26 02:00:17 +0000
959@@ -160,13 +160,11 @@
960 UI::Box* row = new UI::Box(&box_, 0, 0, UI::Box::Horizontal);
961
962 // Name
963- UI::EditBox* plr_name = new UI::EditBox(row, 0, 0, 0, 0, kMargin, UI::PanelStyle::kWui);
964+ UI::EditBox* plr_name = new UI::EditBox(row, 0, 0, 0, UI::PanelStyle::kWui);
965 if (map_has_player) {
966 plr_name->set_text(map.get_scenario_player_name(p));
967 }
968 plr_name->changed.connect(boost::bind(&EditorPlayerMenu::name_changed, this, p - 1));
969- row->add(plr_name, UI::Box::Resizing::kFillSpace);
970- row->add_space(kMargin);
971
972 // Tribe
973 UI::Dropdown<std::string>* plr_tribe =
974@@ -189,8 +187,6 @@
975 "");
976 plr_tribe->selected.connect(
977 boost::bind(&EditorPlayerMenu::player_tribe_clicked, boost::ref(*this), p - 1));
978- row->add(plr_tribe);
979- row->add_space(kMargin);
980
981 // Starting position
982 const Image* player_image =
983@@ -204,8 +200,17 @@
984 player_image, _("Set this player’s starting position"));
985 plr_position->sigclicked.connect(
986 boost::bind(&EditorPlayerMenu::set_starting_pos_clicked, boost::ref(*this), p));
987+
988+ // Add the elements to the row
989+ row->add(plr_name, UI::Box::Resizing::kFillSpace);
990+ row->add_space(kMargin);
991+
992+ row->add(plr_tribe);
993+ row->add_space(kMargin);
994+
995 row->add(plr_position);
996
997+ // Add the row itself
998 box_.add(row, UI::Box::Resizing::kFullSize);
999 box_.add_space(kMargin);
1000 row->set_visible(map_has_player);
1001@@ -227,7 +232,7 @@
1002 assert(!rows_.empty());
1003 const Widelands::PlayerNumber nr_players = eia().egbase().map().get_nrplayers();
1004 box_.set_size(310, no_of_players_.get_h() + kMargin +
1005- nr_players * (rows_.front()->tribe->get_h() + kMargin));
1006+ nr_players * (rows_.front()->name->get_h() + kMargin));
1007 set_inner_size(box_.get_w() + 2 * kMargin, box_.get_h() + 2 * kMargin);
1008 }
1009
1010@@ -319,10 +324,10 @@
1011 // Signal player position states via button states
1012 iterate_player_numbers(pn, map->get_nrplayers()) {
1013 if (pn == row) {
1014- rows_.at(pn - 1)->position->set_background_style(UI::ButtonStyle::kWuiPrimary);
1015+ rows_.at(pn - 1)->position->set_style(UI::ButtonStyle::kWuiPrimary);
1016 rows_.at(pn - 1)->position->set_perm_pressed(true);
1017 } else {
1018- rows_.at(pn - 1)->position->set_background_style(UI::ButtonStyle::kWuiSecondary);
1019+ rows_.at(pn - 1)->position->set_style(UI::ButtonStyle::kWuiSecondary);
1020 rows_.at(pn - 1)->position->set_perm_pressed(map->get_starting_pos(pn) !=
1021 Widelands::Coords::null());
1022 }
1023
1024=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
1025--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2019-02-27 19:00:36 +0000
1026+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2019-05-26 02:00:17 +0000
1027@@ -73,7 +73,7 @@
1028 UI::SpinBox::Units::kNone,
1029 UI::SpinBox::Type::kSmall),
1030 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, 1),
1031- cur_selection_(&box_, 0, 0, "", UI::Align::kCenter) {
1032+ cur_selection_(&box_, 0, 0, 0, 0, "", UI::Align::kCenter) {
1033 // Configure spin boxes
1034 change_by_.set_tooltip(
1035 /** TRANSLATORS: Editor change rseources access keys. **/
1036
1037=== modified file 'src/graphic/CMakeLists.txt'
1038--- src/graphic/CMakeLists.txt 2019-05-11 10:22:57 +0000
1039+++ src/graphic/CMakeLists.txt 2019-05-26 02:00:17 +0000
1040@@ -1,3 +1,4 @@
1041+add_subdirectory(styles)
1042 add_subdirectory(text)
1043
1044 # TODO(sirver): Separate this directory into a base directory and one
1045@@ -5,20 +6,12 @@
1046
1047 # Align and color
1048
1049-
1050-wl_library(graphic_styles
1051- SRCS
1052- panel_styles.cc
1053- panel_styles.h
1054- DEPENDS
1055- graphic_color
1056- graphic_surface
1057-)
1058-
1059 wl_library(graphic_align
1060 SRCS
1061 align.h
1062 align.cc
1063+ DEPENDS
1064+ base_geometry
1065 )
1066
1067 wl_library(graphic_color
1068@@ -269,12 +262,6 @@
1069 graphic_text
1070 )
1071
1072-wl_library(graphic_text_constants
1073- SRCS
1074- text_constants.h
1075- text_constants.cc
1076-)
1077-
1078 wl_library(graphic_text_layout
1079 SRCS
1080 text_layout.cc
1081@@ -284,8 +271,8 @@
1082 graphic_align
1083 graphic_color
1084 graphic_surface
1085+ graphic_styles
1086 graphic_text
1087- graphic_text_constants
1088 graphic_fonthandler
1089 graphic_styles
1090 )
1091@@ -304,7 +291,6 @@
1092 graphic_color
1093 graphic_fonthandler
1094 graphic_text
1095- graphic_text_constants
1096 graphic_text_layout
1097 )
1098
1099@@ -343,7 +329,6 @@
1100 graphic_render_queue
1101 graphic_styles
1102 graphic_surface
1103- graphic_text_layout
1104 io_filesystem
1105 io_stream
1106 logic_constants
1107@@ -355,3 +340,4 @@
1108 scripting_lua_table
1109 sound
1110 )
1111+
1112
1113=== modified file 'src/graphic/align.cc'
1114--- src/graphic/align.cc 2019-02-23 11:00:49 +0000
1115+++ src/graphic/align.cc 2019-05-26 02:00:17 +0000
1116@@ -19,4 +19,51 @@
1117
1118 #include "graphic/align.h"
1119
1120-// Dummy
1121+namespace UI {
1122+
1123+/**
1124+ * Align pt horizontally to match align based on width w.
1125+ *
1126+ * When correcting for align, we never move from pixel boundaries to
1127+ * sub-pixels, because this might lead from pixel-perfect rendering to
1128+ * subsampled rendering - this can lead to blurry texts. That is why we
1129+ * never do float divisions in this function.
1130+ */
1131+void correct_for_align(Align align, uint32_t w, Vector2i* pt) {
1132+ if (align == Align::kCenter) {
1133+ pt->x -= w / 2;
1134+ } else if (align == Align::kRight) {
1135+ pt->x -= w;
1136+ }
1137+}
1138+
1139+/**
1140+ * Adjust the y coordinate in 'point 'pt' to vertically center an element with height 'h'.
1141+ */
1142+void center_vertically(uint32_t h, Vector2i* pt) {
1143+ pt->y -= h / 2;
1144+}
1145+
1146+
1147+/**
1148+ * This mirrors the horizontal alignment for RTL languages.
1149+ *
1150+ * Do not store this value as it is based on the global font setting.
1151+ */
1152+Align mirror_alignment(Align alignment, bool is_rtl) {
1153+ if (is_rtl) {
1154+ switch (alignment) {
1155+ case Align::kLeft:
1156+ alignment = Align::kRight;
1157+ break;
1158+ case Align::kRight:
1159+ alignment = Align::kLeft;
1160+ break;
1161+ case Align::kCenter:
1162+ break;
1163+ }
1164+ }
1165+ return alignment;
1166+}
1167+
1168+} // namespace UI
1169
1170=== modified file 'src/graphic/align.h'
1171--- src/graphic/align.h 2019-02-23 11:00:49 +0000
1172+++ src/graphic/align.h 2019-05-26 02:00:17 +0000
1173@@ -20,6 +20,10 @@
1174 #ifndef WL_GRAPHIC_ALIGN_H
1175 #define WL_GRAPHIC_ALIGN_H
1176
1177+#include <string>
1178+
1179+#include "base/vector.h"
1180+
1181 namespace UI {
1182
1183 // TODO(GunChleoc): Step 1: Clean up superfluous usages of kLeft/kTop, especially with dalls to
1184@@ -33,5 +37,9 @@
1185 kTop = kLeft,
1186 kBottom = kRight,
1187 };
1188+
1189+void center_vertically(uint32_t h, Vector2i* pt);
1190+void correct_for_align(Align, uint32_t w, Vector2i* pt);
1191+Align mirror_alignment(Align alignment, bool is_rtl);
1192 } // namespace UI
1193 #endif // end of include guard: WL_GRAPHIC_ALIGN_H
1194
1195=== modified file 'src/graphic/font_handler.cc'
1196--- src/graphic/font_handler.cc 2019-02-23 11:00:49 +0000
1197+++ src/graphic/font_handler.cc 2019-05-26 02:00:17 +0000
1198@@ -87,7 +87,7 @@
1199 const std::string hash = boost::lexical_cast<std::string>(w) + text;
1200 std::shared_ptr<const RenderedText> rendered_text = render_cache_->get(hash);
1201 if (rendered_text == nullptr) {
1202- rendered_text = render_cache_->insert(hash, rt_renderer_->render(text, w));
1203+ rendered_text = render_cache_->insert(hash, rt_renderer_->render(text, w, fontset()->is_rtl()));
1204 }
1205 return rendered_text;
1206 }
1207
1208=== modified file 'src/graphic/graphic.cc'
1209--- src/graphic/graphic.cc 2019-02-28 08:02:18 +0000
1210+++ src/graphic/graphic.cc 2019-05-26 02:00:17 +0000
1211@@ -35,7 +35,6 @@
1212 #include "graphic/render_queue.h"
1213 #include "graphic/rendertarget.h"
1214 #include "graphic/screen.h"
1215-#include "graphic/text_layout.h"
1216 #include "graphic/texture.h"
1217 #include "io/filesystem/layered_filesystem.h"
1218 #include "io/streamwrite.h"
1219
1220=== removed file 'src/graphic/panel_styles.cc'
1221--- src/graphic/panel_styles.cc 2017-06-12 11:07:47 +0000
1222+++ src/graphic/panel_styles.cc 1970-01-01 00:00:00 +0000
1223@@ -1,1 +0,0 @@
1224-// Dummy to make CMake happy
1225
1226=== modified file 'src/graphic/rendertarget.cc'
1227--- src/graphic/rendertarget.cc 2019-04-24 06:32:02 +0000
1228+++ src/graphic/rendertarget.cc 2019-05-26 02:00:17 +0000
1229@@ -20,10 +20,10 @@
1230 #include "graphic/rendertarget.h"
1231
1232 #include "base/macros.h"
1233+#include "graphic/align.h"
1234 #include "graphic/animation.h"
1235 #include "graphic/graphic.h"
1236 #include "graphic/surface.h"
1237-#include "graphic/text_layout.h"
1238
1239 /**
1240 * Build a render target for the given surface.
1241
1242=== modified file 'src/graphic/style_manager.cc'
1243--- src/graphic/style_manager.cc 2019-02-23 11:00:49 +0000
1244+++ src/graphic/style_manager.cc 2019-05-26 02:00:17 +0000
1245@@ -21,21 +21,55 @@
1246
1247 #include <memory>
1248
1249+#include <boost/format.hpp>
1250+
1251 #include "base/scoped_timer.h"
1252 #include "base/wexception.h"
1253 #include "graphic/graphic.h"
1254 #include "scripting/lua_interface.h"
1255
1256 namespace {
1257-// Read image filename and RGB color from LuaTable
1258-UI::PanelStyleInfo* read_style(const LuaTable& table) {
1259+// Read RGB color from LuaTable
1260+RGBColor read_rgb_color(const LuaTable& table) {
1261+ std::vector<int> rgbcolor = table.array_entries<int>();
1262+ if (rgbcolor.size() != 3) {
1263+ throw wexception("Expected 3 entries for RGB color, but got %" PRIuS ".", rgbcolor.size());
1264+ }
1265+ return RGBColor(rgbcolor[0], rgbcolor[1], rgbcolor[2]);
1266+}
1267+
1268+// Read font style from LuaTable
1269+UI::FontStyleInfo* read_font_style(const LuaTable& parent_table, const std::string& table_key) {
1270+ std::unique_ptr<LuaTable> style_table = parent_table.get_table(table_key);
1271+ const int size = style_table->get_int("size");
1272+ if (size < 1) {
1273+ throw wexception("Font size %d too small for %s, must be at least 1!", size, table_key.c_str());
1274+ }
1275+ return new UI::FontStyleInfo(
1276+ style_table->get_string("face"),
1277+ read_rgb_color(*style_table->get_table("color")),
1278+ size,
1279+ style_table->has_key<std::string>("bold") ? style_table->get_bool("bold") : false,
1280+ style_table->has_key<std::string>("italic") ? style_table->get_bool("italic") : false,
1281+ style_table->has_key<std::string>("underline") ? style_table->get_bool("underline") : false,
1282+ style_table->has_key<std::string>("shadow") ? style_table->get_bool("shadow") : false);
1283+}
1284+
1285+// Read image filename and RGBA color from LuaTable
1286+UI::PanelStyleInfo* read_panel_style(const LuaTable& table) {
1287 const std::string image = table.get_string("image");
1288 std::vector<int> rgbcolor = table.get_table("color")->array_entries<int>();
1289 if (rgbcolor.size() != 3) {
1290 throw wexception("Expected 3 entries for RGB color, but got %" PRIuS ".", rgbcolor.size());
1291 }
1292 return new UI::PanelStyleInfo(image.empty() ? nullptr : g_gr->images().get(image),
1293- RGBAColor(rgbcolor[0], rgbcolor[1], rgbcolor[2], 0));
1294+ RGBAColor(rgbcolor[0], rgbcolor[1], rgbcolor[2], 0),
1295+ table.has_key<std::string>("margin") ? table.get_int("margin") : 0);
1296+}
1297+
1298+// Read text panel style from LuaTable
1299+UI::TextPanelStyleInfo* read_text_panel_style(const LuaTable& table) {
1300+ return new UI::TextPanelStyleInfo(read_font_style(table, "font"), read_panel_style(*table.get_table("background")));
1301 }
1302
1303 // Stupid completeness check - enum classes weren't meant for iterating, so we just compare the size
1304@@ -59,45 +93,34 @@
1305 dropdownstyles_.clear();
1306 scrollbarstyles_.clear();
1307
1308- log("Style Manager: Loading %sinit.lua ... ", kTemplateDir.c_str());
1309-
1310 LuaInterface lua;
1311 std::unique_ptr<LuaTable> table(lua.run_script(kTemplateDir + "init.lua"));
1312
1313- log("took %ums\n", timer.ms_since_last_query());
1314- log("Style Manager: Reading button styles ... ");
1315-
1316 // Buttons
1317 std::unique_ptr<LuaTable> element_table = table->get_table("buttons");
1318 std::unique_ptr<LuaTable> style_table = element_table->get_table("fsmenu");
1319- add_button_style(UI::ButtonStyle::kFsMenuMenu, *style_table->get_table("menu").get());
1320- add_button_style(UI::ButtonStyle::kFsMenuPrimary, *style_table->get_table("primary").get());
1321- add_button_style(UI::ButtonStyle::kFsMenuSecondary, *style_table->get_table("secondary").get());
1322+ add_button_style(UI::ButtonStyle::kFsMenuMenu, *style_table->get_table("menu"));
1323+ add_button_style(UI::ButtonStyle::kFsMenuPrimary, *style_table->get_table("primary"));
1324+ add_button_style(UI::ButtonStyle::kFsMenuSecondary, *style_table->get_table("secondary"));
1325 style_table = element_table->get_table("wui");
1326- add_button_style(UI::ButtonStyle::kWuiMenu, *style_table->get_table("menu").get());
1327- add_button_style(UI::ButtonStyle::kWuiPrimary, *style_table->get_table("primary").get());
1328- add_button_style(UI::ButtonStyle::kWuiSecondary, *style_table->get_table("secondary").get());
1329+ add_button_style(UI::ButtonStyle::kWuiMenu, *style_table->get_table("menu"));
1330+ add_button_style(UI::ButtonStyle::kWuiPrimary, *style_table->get_table("primary"));
1331+ add_button_style(UI::ButtonStyle::kWuiSecondary, *style_table->get_table("secondary"));
1332 add_button_style(
1333- UI::ButtonStyle::kWuiBuildingStats, *style_table->get_table("building_stats").get());
1334+ UI::ButtonStyle::kWuiBuildingStats, *style_table->get_table("building_stats"));
1335 check_completeness(
1336 "buttons", buttonstyles_.size(), static_cast<size_t>(UI::ButtonStyle::kWuiBuildingStats));
1337
1338- log("took %ums\n", timer.ms_since_last_query());
1339- log("Style Manager: Reading slider styles ... ");
1340-
1341 // Sliders
1342 element_table = table->get_table("sliders");
1343 style_table = element_table->get_table("fsmenu");
1344- add_slider_style(UI::SliderStyle::kFsMenu, *style_table->get_table("menu").get());
1345+ add_slider_style(UI::SliderStyle::kFsMenu, *style_table->get_table("menu"));
1346 style_table = element_table->get_table("wui");
1347- add_slider_style(UI::SliderStyle::kWuiLight, *style_table->get_table("light").get());
1348- add_slider_style(UI::SliderStyle::kWuiDark, *style_table->get_table("dark").get());
1349+ add_slider_style(UI::SliderStyle::kWuiLight, *style_table->get_table("light"));
1350+ add_slider_style(UI::SliderStyle::kWuiDark, *style_table->get_table("dark"));
1351 check_completeness(
1352 "sliders", sliderstyles_.size(), static_cast<size_t>(UI::SliderStyle::kWuiDark));
1353
1354- log("took %ums\n", timer.ms_since_last_query());
1355- log("Style Manager: Reading tabpanel styles ... ");
1356-
1357 // Tabpanels
1358 element_table = table->get_table("tabpanels");
1359 style_table = element_table->get_table("fsmenu");
1360@@ -108,21 +131,13 @@
1361 check_completeness(
1362 "tabpanels", tabpanelstyles_.size(), static_cast<size_t>(UI::TabPanelStyle::kWuiDark));
1363
1364- log("took %ums\n", timer.ms_since_last_query());
1365- log("Style Manager: Reading editbox styles ... ");
1366-
1367 // Editboxes
1368 element_table = table->get_table("editboxes");
1369- style_table = element_table->get_table("fsmenu");
1370- add_style(UI::PanelStyle::kFsMenu, *style_table->get_table("menu").get(), &editboxstyles_);
1371- style_table = element_table->get_table("wui");
1372- add_style(UI::PanelStyle::kWui, *style_table->get_table("menu").get(), &editboxstyles_);
1373+ add_editbox_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
1374+ add_editbox_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
1375 check_completeness(
1376 "editboxes", editboxstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
1377
1378- log("took %ums\n", timer.ms_since_last_query());
1379- log("Style Manager: Reading dropdown styles ... ");
1380-
1381 // Dropdowns
1382 element_table = table->get_table("dropdowns");
1383 style_table = element_table->get_table("fsmenu");
1384@@ -132,9 +147,6 @@
1385 check_completeness(
1386 "dropdowns", dropdownstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
1387
1388- log("took %ums\n", timer.ms_since_last_query());
1389- log("Style Manager: Reading scrollbar styles ... ");
1390-
1391 // Scrollbars
1392 element_table = table->get_table("scrollbars");
1393 style_table = element_table->get_table("fsmenu");
1394@@ -144,18 +156,81 @@
1395 check_completeness(
1396 "scrollbars", scrollbarstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
1397
1398- log("took %ums\n", timer.ms_since_last_query());
1399+ // Building statistics etc. for map objects
1400+ set_building_statistics_style(*table->get_table("building_statistics"));
1401+
1402+ // Progress bars
1403+ element_table = table->get_table("progressbar");
1404+ add_progressbar_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
1405+ add_progressbar_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
1406+ check_completeness(
1407+ "progressbars", progressbar_styles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
1408+
1409+ // Table and listselect
1410+ element_table = table->get_table("tables");
1411+ add_table_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
1412+ add_table_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
1413+ check_completeness(
1414+ "tables", table_styles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
1415+
1416+ // Statistics plot
1417+ set_statistics_plot_style(*table->get_table("statistics_plot"));
1418+
1419+ // Ware info in warehouses, construction actions etc.
1420+ element_table = table->get_table("wareinfo");
1421+ add_ware_info_style(UI::WareInfoStyle::kNormal, *element_table->get_table("normal"));
1422+ add_ware_info_style(UI::WareInfoStyle::kHighlight, *element_table->get_table("highlight"));
1423+ check_completeness(
1424+ "wareinfos", ware_info_styles_.size(), static_cast<size_t>(UI::WareInfoStyle::kHighlight));
1425+
1426+ // Special elements
1427+ minimum_font_size_ = table->get_int("minimum_font_size");
1428+ if (minimum_font_size_ < 1) {
1429+ throw wexception("Font size too small for minimum_font_size, must be at least 1!");
1430+ }
1431+ minimap_icon_frame_ = read_rgb_color(*table->get_table("minimap_icon_frame"));
1432+
1433+ // Fonts
1434+ element_table = table->get_table("fonts");
1435+ add_font_style(UI::FontStyle::kChatMessage, *element_table, "chat_message");
1436+ add_font_style(UI::FontStyle::kChatPlayername, *element_table, "chat_playername");
1437+ add_font_style(UI::FontStyle::kChatServer, *element_table, "chat_server");
1438+ add_font_style(UI::FontStyle::kChatTimestamp, *element_table, "chat_timestamp");
1439+ add_font_style(UI::FontStyle::kChatWhisper, *element_table, "chat_whisper");
1440+ add_font_style(UI::FontStyle::kFsGameSetupHeadings, *element_table, "fsmenu_game_setup_headings");
1441+ add_font_style(UI::FontStyle::kFsGameSetupSuperuser, *element_table, "fsmenu_game_setup_superuser");
1442+ add_font_style(UI::FontStyle::kFsGameSetupIrcClient, *element_table, "fsmenu_game_setup_irc_client");
1443+ add_font_style(UI::FontStyle::kFsGameSetupMapname, *element_table, "fsmenu_game_setup_mapname");
1444+ add_font_style(UI::FontStyle::kFsMenuGameTip, *element_table, "fsmenu_gametip");
1445+ add_font_style(UI::FontStyle::kFsMenuInfoPanelHeading, *element_table, "fsmenu_info_panel_heading");
1446+ add_font_style(UI::FontStyle::kFsMenuInfoPanelParagraph, *element_table, "fsmenu_info_panel_paragraph");
1447+ add_font_style(UI::FontStyle::kFsMenuIntro, *element_table, "fsmenu_intro");
1448+ add_font_style(UI::FontStyle::kFsMenuTitle, *element_table, "fsmenu_title");
1449+ add_font_style(UI::FontStyle::kFsMenuTranslationInfo, *element_table, "fsmenu_translation_info");
1450+ add_font_style(UI::FontStyle::kDisabled, *element_table, "disabled");
1451+ add_font_style(UI::FontStyle::kLabel, *element_table, "label");
1452+ add_font_style(UI::FontStyle::kTooltipHeader, *element_table, "tooltip_header");
1453+ add_font_style(UI::FontStyle::kTooltip, *element_table, "tooltip");
1454+ add_font_style(UI::FontStyle::kWarning, *element_table, "warning");
1455+ add_font_style(UI::FontStyle::kWuiAttackBoxSliderLabel, *element_table, "wui_attack_box_slider_label");
1456+ add_font_style(UI::FontStyle::kWuiGameSpeedAndCoordinates, *element_table, "wui_game_speed_and_coordinates");
1457+ add_font_style(UI::FontStyle::kWuiInfoPanelHeading, *element_table, "wui_info_panel_heading");
1458+ add_font_style(UI::FontStyle::kWuiInfoPanelParagraph, *element_table, "wui_info_panel_paragraph");
1459+ add_font_style(UI::FontStyle::kWuiMessageHeading, *element_table, "wui_message_heading");
1460+ add_font_style(UI::FontStyle::kWuiMessageParagraph, *element_table, "wui_message_paragraph");
1461+ add_font_style(UI::FontStyle::kWuiWindowTitle, *element_table, "wui_window_title");
1462+ check_completeness("fonts", fontstyles_.size(), static_cast<size_t>(UI::FontStyle::kWuiWindowTitle));
1463 }
1464
1465 // Return functions for the styles
1466-const UI::PanelStyleInfo* StyleManager::button_style(UI::ButtonStyle style) const {
1467+const UI::ButtonStyleInfo& StyleManager::button_style(UI::ButtonStyle style) const {
1468 assert(buttonstyles_.count(style) == 1);
1469- return buttonstyles_.at(style).get();
1470+ return *buttonstyles_.at(style);
1471 }
1472
1473-const UI::PanelStyleInfo* StyleManager::slider_style(UI::SliderStyle style) const {
1474+const UI::TextPanelStyleInfo& StyleManager::slider_style(UI::SliderStyle style) const {
1475 assert(sliderstyles_.count(style) == 1);
1476- return sliderstyles_.at(style).get();
1477+ return *sliderstyles_.at(style);
1478 }
1479
1480 const UI::PanelStyleInfo* StyleManager::tabpanel_style(UI::TabPanelStyle style) const {
1481@@ -163,9 +238,9 @@
1482 return tabpanelstyles_.at(style).get();
1483 }
1484
1485-const UI::PanelStyleInfo* StyleManager::editbox_style(UI::PanelStyle style) const {
1486+const UI::TextPanelStyleInfo& StyleManager::editbox_style(UI::PanelStyle style) const {
1487 assert(editboxstyles_.count(style) == 1);
1488- return editboxstyles_.at(style).get();
1489+ return *editboxstyles_.at(style);
1490 }
1491
1492 const UI::PanelStyleInfo* StyleManager::dropdown_style(UI::PanelStyle style) const {
1493@@ -178,22 +253,143 @@
1494 return scrollbarstyles_.at(style).get();
1495 }
1496
1497+const UI::BuildingStatisticsStyleInfo& StyleManager::building_statistics_style() const {
1498+ return *building_statistics_style_;
1499+}
1500+
1501+const UI::ProgressbarStyleInfo& StyleManager::progressbar_style(UI::PanelStyle style) const {
1502+ assert(progressbar_styles_.count(style) == 1);
1503+ return *progressbar_styles_.at(style);
1504+}
1505+
1506+const UI::StatisticsPlotStyleInfo& StyleManager::statistics_plot_style() const {
1507+ return *statistics_plot_style_;
1508+}
1509+
1510+const UI::TableStyleInfo& StyleManager::table_style(UI::PanelStyle style) const {
1511+ assert(table_styles_.count(style) == 1);
1512+ return *table_styles_.at(style);
1513+}
1514+
1515+const UI::WareInfoStyleInfo& StyleManager::ware_info_style(UI::WareInfoStyle style) const {
1516+ assert(ware_info_styles_.count(style) == 1);
1517+ return *ware_info_styles_.at(style);
1518+}
1519+
1520+const UI::FontStyleInfo& StyleManager::font_style(UI::FontStyle style) const {
1521+ assert(fontstyles_.count(style) == 1);
1522+ return *fontstyles_.at(style);
1523+}
1524+
1525+int StyleManager::minimum_font_size() const {
1526+ return minimum_font_size_;
1527+}
1528+
1529+const RGBColor& StyleManager::minimap_icon_frame() const {
1530+ return minimap_icon_frame_;
1531+}
1532+
1533+std::string StyleManager::color_tag(const std::string& text, const RGBColor& color) {
1534+ static boost::format f("<font color=%s>%s</font>");
1535+ f % color.hex_value();
1536+ f % text;
1537+ return f.str();
1538+}
1539+
1540 // Fill the maps
1541 void StyleManager::add_button_style(UI::ButtonStyle style, const LuaTable& table) {
1542 buttonstyles_.insert(
1543- std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));
1544+ std::make_pair(
1545+ style,
1546+ std::unique_ptr<const UI::ButtonStyleInfo>(
1547+ new UI::ButtonStyleInfo(
1548+ read_text_panel_style(*table.get_table("enabled")),
1549+ read_text_panel_style(*table.get_table("disabled"))))));
1550 }
1551
1552 void StyleManager::add_slider_style(UI::SliderStyle style, const LuaTable& table) {
1553 sliderstyles_.insert(
1554- std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));
1555-}
1556+ std::make_pair(style, std::unique_ptr<UI::TextPanelStyleInfo>(read_text_panel_style(table))));
1557+}
1558+
1559+void StyleManager::add_editbox_style(UI::PanelStyle style, const LuaTable& table) {
1560+ editboxstyles_.insert(
1561+ std::make_pair(style, std::unique_ptr<UI::TextPanelStyleInfo>(read_text_panel_style(table))));
1562+}
1563+
1564
1565 void StyleManager::add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table) {
1566 tabpanelstyles_.insert(
1567- std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));
1568+ std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_panel_style(table))));
1569+}
1570+
1571+void StyleManager::add_progressbar_style(UI::PanelStyle style, const LuaTable& table) {
1572+ std::unique_ptr<LuaTable> color_table = table.get_table("background_colors");
1573+ progressbar_styles_.insert(std::make_pair(
1574+ style,
1575+ std::unique_ptr<const UI::ProgressbarStyleInfo>(
1576+ new UI::ProgressbarStyleInfo(
1577+ read_font_style(table, "font"),
1578+ read_rgb_color(*color_table->get_table("low")),
1579+ read_rgb_color(*color_table->get_table("medium")),
1580+ read_rgb_color(*color_table->get_table("high"))))));
1581+}
1582+
1583+void StyleManager::add_table_style(UI::PanelStyle style, const LuaTable& table) {
1584+ table_styles_.insert(std::make_pair(style,
1585+ std::unique_ptr<const UI::TableStyleInfo>(
1586+ new UI::TableStyleInfo(
1587+ read_font_style(table, "enabled"),
1588+ read_font_style(table, "disabled")))));
1589+}
1590+
1591+void StyleManager::set_statistics_plot_style(const LuaTable& table) {
1592+ std::unique_ptr<LuaTable> fonts_table = table.get_table("fonts");
1593+ std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
1594+ statistics_plot_style_.reset(new UI::StatisticsPlotStyleInfo(
1595+ read_font_style(*fonts_table, "x_tick"),
1596+ read_font_style(*fonts_table, "y_min_value"),
1597+ read_font_style(*fonts_table, "y_max_value"),
1598+ read_rgb_color(*colors_table->get_table("axis_line")),
1599+ read_rgb_color(*colors_table->get_table("zero_line"))));
1600+}
1601+
1602+void StyleManager::set_building_statistics_style(const LuaTable& table) {
1603+ std::unique_ptr<LuaTable> window_table = table.get_table("statistics_window");
1604+ std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
1605+ std::unique_ptr<LuaTable> fonts_table = window_table->get_table("fonts");
1606+ building_statistics_style_.reset(new UI::BuildingStatisticsStyleInfo(
1607+ read_font_style(*fonts_table, "button_font"),
1608+ read_font_style(*fonts_table, "details_font"),
1609+ window_table->get_int("editbox_margin"),
1610+ read_font_style(table, "census_font"),
1611+ read_font_style(table, "statistics_font"),
1612+ read_rgb_color(*colors_table->get_table("construction")),
1613+ read_rgb_color(*colors_table->get_table("neutral")),
1614+ read_rgb_color(*colors_table->get_table("low")),
1615+ read_rgb_color(*colors_table->get_table("medium")),
1616+ read_rgb_color(*colors_table->get_table("high"))));
1617+}
1618+
1619+void StyleManager::add_ware_info_style(UI::WareInfoStyle style, const LuaTable& table) {
1620+ std::unique_ptr<LuaTable> fonts_table = table.get_table("fonts");
1621+ std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
1622+ ware_info_styles_.insert(
1623+ std::make_pair(style,
1624+ std::unique_ptr<const UI::WareInfoStyleInfo>(
1625+ new UI::WareInfoStyleInfo(
1626+ read_font_style(*fonts_table, "header"),
1627+ read_font_style(*fonts_table, "info"),
1628+ g_gr->images().get(table.get_string("icon_background_image")),
1629+ read_rgb_color(*colors_table->get_table("icon_frame")),
1630+ read_rgb_color(*colors_table->get_table("icon_background")),
1631+ read_rgb_color(*colors_table->get_table("info_background"))))));
1632 }
1633
1634 void StyleManager::add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map) {
1635- map->insert(std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));
1636+ map->insert(std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_panel_style(table))));
1637+}
1638+
1639+void StyleManager::add_font_style(UI::FontStyle font_key, const LuaTable& table, const std::string& table_key) {
1640+ fontstyles_.emplace(std::make_pair(font_key, std::unique_ptr<UI::FontStyleInfo>(read_font_style(table, table_key))));
1641 }
1642
1643=== modified file 'src/graphic/style_manager.h'
1644--- src/graphic/style_manager.h 2019-02-23 11:00:49 +0000
1645+++ src/graphic/style_manager.h 2019-05-26 02:00:17 +0000
1646@@ -23,7 +23,15 @@
1647 #include <map>
1648 #include <memory>
1649
1650-#include "graphic/panel_styles.h"
1651+#include "graphic/styles/building_statistics_style.h"
1652+#include "graphic/styles/button_style.h"
1653+#include "graphic/styles/font_style.h"
1654+#include "graphic/styles/panel_styles.h"
1655+#include "graphic/styles/progress_bar_style.h"
1656+#include "graphic/styles/statistics_plot_style.h"
1657+#include "graphic/styles/table_style.h"
1658+#include "graphic/styles/text_panel_style.h"
1659+#include "graphic/styles/ware_info_style.h"
1660 #include "scripting/lua_table.h"
1661
1662 static const std::string kTemplateDir = "templates/default/";
1663@@ -36,27 +44,54 @@
1664 // Late initialization, because Graphics needs to load the image files first.
1665 void init();
1666
1667- const UI::PanelStyleInfo* button_style(UI::ButtonStyle) const;
1668- const UI::PanelStyleInfo* slider_style(UI::SliderStyle) const;
1669+ const UI::BuildingStatisticsStyleInfo& building_statistics_style() const;
1670+ const UI::ButtonStyleInfo& button_style(UI::ButtonStyle) const;
1671+ const UI::TextPanelStyleInfo& slider_style(UI::SliderStyle) const;
1672 const UI::PanelStyleInfo* tabpanel_style(UI::TabPanelStyle) const;
1673- const UI::PanelStyleInfo* editbox_style(UI::PanelStyle) const;
1674+ const UI::TextPanelStyleInfo& editbox_style(UI::PanelStyle) const;
1675 const UI::PanelStyleInfo* dropdown_style(UI::PanelStyle) const;
1676 const UI::PanelStyleInfo* scrollbar_style(UI::PanelStyle) const;
1677+ const UI::ProgressbarStyleInfo& progressbar_style(UI::PanelStyle) const;
1678+ const UI::StatisticsPlotStyleInfo& statistics_plot_style() const;
1679+ const UI::TableStyleInfo& table_style(UI::PanelStyle) const;
1680+ const UI::WareInfoStyleInfo& ware_info_style(UI::WareInfoStyle) const;
1681+ const UI::FontStyleInfo& font_style(UI::FontStyle style) const;
1682+
1683+ // Special elements
1684+ int minimum_font_size() const;
1685+ const RGBColor& minimap_icon_frame() const;
1686+ static std::string color_tag(const std::string& text, const RGBColor& color);
1687
1688 private:
1689 using PanelStyleMap = std::map<UI::PanelStyle, std::unique_ptr<const UI::PanelStyleInfo>>;
1690 void add_button_style(UI::ButtonStyle style, const LuaTable& table);
1691 void add_slider_style(UI::SliderStyle style, const LuaTable& table);
1692+ void add_editbox_style(UI::PanelStyle style, const LuaTable& table);
1693 void add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table);
1694+ void add_progressbar_style(UI::PanelStyle style, const LuaTable& table);
1695+ void add_table_style(UI::PanelStyle style, const LuaTable& table);
1696+ void set_statistics_plot_style(const LuaTable& table);
1697+ void set_building_statistics_style(const LuaTable& table);
1698+ void add_ware_info_style(UI::WareInfoStyle style, const LuaTable& table);
1699 void add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map);
1700+ void add_font_style(UI::FontStyle font, const LuaTable& table, const std::string& key);
1701
1702- std::map<UI::ButtonStyle, std::unique_ptr<const UI::PanelStyleInfo>> buttonstyles_;
1703- std::map<UI::SliderStyle, std::unique_ptr<const UI::PanelStyleInfo>> sliderstyles_;
1704+ std::map<UI::ButtonStyle, std::unique_ptr<const UI::ButtonStyleInfo>> buttonstyles_;
1705+ std::map<UI::PanelStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> editboxstyles_;
1706+ std::map<UI::SliderStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> sliderstyles_;
1707 std::map<UI::TabPanelStyle, std::unique_ptr<const UI::PanelStyleInfo>> tabpanelstyles_;
1708- PanelStyleMap editboxstyles_;
1709 PanelStyleMap dropdownstyles_;
1710 PanelStyleMap scrollbarstyles_;
1711
1712+ int minimum_font_size_;
1713+ RGBColor minimap_icon_frame_;
1714+ std::map<UI::FontStyle, std::unique_ptr<const UI::FontStyleInfo>> fontstyles_;
1715+ std::unique_ptr<const UI::BuildingStatisticsStyleInfo> building_statistics_style_;
1716+ std::map<UI::PanelStyle, std::unique_ptr<const UI::ProgressbarStyleInfo>> progressbar_styles_;
1717+ std::unique_ptr<const UI::StatisticsPlotStyleInfo> statistics_plot_style_;
1718+ std::map<UI::PanelStyle, std::unique_ptr<const UI::TableStyleInfo>> table_styles_;
1719+ std::map<UI::WareInfoStyle, std::unique_ptr<const UI::WareInfoStyleInfo>> ware_info_styles_;
1720+
1721 DISALLOW_COPY_AND_ASSIGN(StyleManager);
1722 };
1723
1724
1725=== added directory 'src/graphic/styles'
1726=== added file 'src/graphic/styles/CMakeLists.txt'
1727--- src/graphic/styles/CMakeLists.txt 1970-01-01 00:00:00 +0000
1728+++ src/graphic/styles/CMakeLists.txt 2019-05-26 02:00:17 +0000
1729@@ -0,0 +1,18 @@
1730+wl_library(graphic_styles
1731+ SRCS
1732+ building_statistics_style.h
1733+ button_style.h
1734+ font_style.cc
1735+ font_style.h
1736+ panel_styles.h
1737+ progress_bar_style.h
1738+ text_panel_style.h
1739+ statistics_plot_style.h
1740+ table_style.h
1741+ ware_info_style.h
1742+ DEPENDS
1743+ base_exceptions
1744+ base_log
1745+ graphic_color
1746+ graphic_surface
1747+)
1748
1749=== added file 'src/graphic/styles/building_statistics_style.h'
1750--- src/graphic/styles/building_statistics_style.h 1970-01-01 00:00:00 +0000
1751+++ src/graphic/styles/building_statistics_style.h 2019-05-26 02:00:17 +0000
1752@@ -0,0 +1,99 @@
1753+/*
1754+ * Copyright (C) 2018 by the Widelands Development Team
1755+ *
1756+ * This program is free software; you can redistribute it and/or
1757+ * modify it under the terms of the GNU General Public License
1758+ * as published by the Free Software Foundation; either version 2
1759+ * of the License, or (at your option) any later version.
1760+ *
1761+ * This program is distributed in the hope that it will be useful,
1762+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1763+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1764+ * GNU General Public License for more details.
1765+ *
1766+ * You should have received a copy of the GNU General Public License
1767+ * along with this program; if not, write to the Free Software
1768+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1769+ *
1770+ */
1771+
1772+#ifndef WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
1773+#define WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
1774+
1775+#include <memory>
1776+
1777+#include "graphic/color.h"
1778+#include "graphic/styles/font_style.h"
1779+
1780+namespace UI {
1781+
1782+struct BuildingStatisticsStyleInfo {
1783+ explicit BuildingStatisticsStyleInfo(UI::FontStyleInfo* init_building_statistics_button_font,
1784+ UI::FontStyleInfo* init_building_statistics_details_font,
1785+ int init_editbox_margin,
1786+ UI::FontStyleInfo* init_census,
1787+ UI::FontStyleInfo* init_statistics,
1788+ const RGBColor& init_construction_color,
1789+ const RGBColor& init_neutral_color,
1790+ const RGBColor& init_low_color,
1791+ const RGBColor& init_medium_color,
1792+ const RGBColor& init_high_color) :
1793+ building_statistics_button_font_(init_building_statistics_button_font),
1794+ building_statistics_details_font_(init_building_statistics_details_font),
1795+ editbox_margin_(init_editbox_margin),
1796+ census_font_(init_census),
1797+ statistics_font_(init_statistics),
1798+ construction_color_(init_construction_color),
1799+ neutral_color_(init_neutral_color),
1800+ low_color_(init_low_color),
1801+ medium_color_(init_medium_color),
1802+ high_color_(init_high_color) {}
1803+
1804+ const UI::FontStyleInfo& building_statistics_button_font() const {
1805+ return *building_statistics_button_font_.get();
1806+ }
1807+ const UI::FontStyleInfo& building_statistics_details_font() const {
1808+ return *building_statistics_details_font_.get();
1809+ }
1810+ int editbox_margin() const {
1811+ return editbox_margin_;
1812+ }
1813+
1814+ const UI::FontStyleInfo& census_font() const {
1815+ return *census_font_.get();
1816+ }
1817+ const UI::FontStyleInfo& statistics_font() const {
1818+ return *statistics_font_.get();
1819+ }
1820+ const RGBColor& construction_color() const {
1821+ return construction_color_;
1822+ }
1823+ const RGBColor& neutral_color() const {
1824+ return neutral_color_;
1825+ }
1826+ const RGBColor& low_color() const {
1827+ return low_color_;
1828+ }
1829+ const RGBColor& medium_color() const {
1830+ return medium_color_;
1831+ }
1832+ const RGBColor& high_color() const {
1833+ return high_color_;
1834+ }
1835+
1836+private:
1837+ std::unique_ptr<const UI::FontStyleInfo> building_statistics_button_font_;
1838+ std::unique_ptr<const UI::FontStyleInfo> building_statistics_details_font_;
1839+ int editbox_margin_;
1840+ std::unique_ptr<const UI::FontStyleInfo> census_font_;
1841+ std::unique_ptr<const UI::FontStyleInfo> statistics_font_;
1842+ const RGBColor construction_color_;
1843+ const RGBColor neutral_color_;
1844+ const RGBColor low_color_;
1845+ const RGBColor medium_color_;
1846+ const RGBColor high_color_;
1847+};
1848+
1849+} // namespace UI
1850+
1851+#endif // end of include guard: WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
1852
1853=== added file 'src/graphic/styles/button_style.h'
1854--- src/graphic/styles/button_style.h 1970-01-01 00:00:00 +0000
1855+++ src/graphic/styles/button_style.h 2019-05-26 02:00:17 +0000
1856@@ -0,0 +1,65 @@
1857+/*
1858+ * Copyright (C) 2018 by the Widelands Development Team
1859+ *
1860+ * This program is free software; you can redistribute it and/or
1861+ * modify it under the terms of the GNU General Public License
1862+ * as published by the Free Software Foundation; either version 2
1863+ * of the License, or (at your option) any later version.
1864+ *
1865+ * This program is distributed in the hope that it will be useful,
1866+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1867+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1868+ * GNU General Public License for more details.
1869+ *
1870+ * You should have received a copy of the GNU General Public License
1871+ * along with this program; if not, write to the Free Software
1872+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1873+ *
1874+ */
1875+
1876+#ifndef WL_GRAPHIC_STYLES_BUTTON_STYLE_H
1877+#define WL_GRAPHIC_STYLES_BUTTON_STYLE_H
1878+
1879+#include <memory>
1880+
1881+#include "graphic/styles/font_style.h"
1882+#include "graphic/styles/panel_styles.h"
1883+#include "graphic/styles/text_panel_style.h"
1884+
1885+namespace UI {
1886+
1887+enum class ButtonStyle {
1888+ kFsMenuMenu,
1889+ kFsMenuPrimary,
1890+ kFsMenuSecondary,
1891+ kWuiMenu,
1892+ kWuiPrimary,
1893+ kWuiSecondary,
1894+ kWuiBuildingStats
1895+};
1896+
1897+struct ButtonStyleInfo {
1898+ ButtonStyleInfo(const UI::TextPanelStyleInfo* init_enabled, const UI::TextPanelStyleInfo* init_disabled) :
1899+ enabled_(init_enabled),
1900+ disabled_(init_disabled) {
1901+ }
1902+ ButtonStyleInfo(const ButtonStyleInfo& other) :
1903+ enabled_(new UI::TextPanelStyleInfo(other.enabled())),
1904+ disabled_(new UI::TextPanelStyleInfo(other.disabled())) {
1905+ }
1906+
1907+ const UI::TextPanelStyleInfo& enabled() const {
1908+ return *enabled_.get();
1909+ }
1910+ const UI::TextPanelStyleInfo& disabled() const {
1911+ return *disabled_.get();
1912+ }
1913+
1914+private:
1915+ std::unique_ptr<const UI::TextPanelStyleInfo> enabled_;
1916+ std::unique_ptr<const UI::TextPanelStyleInfo> disabled_;
1917+};
1918+
1919+} // namespace UI
1920+
1921+#endif // end of include guard: WL_GRAPHIC_STYLES_BUTTON_STYLE_H
1922
1923=== added file 'src/graphic/styles/font_style.cc'
1924--- src/graphic/styles/font_style.cc 1970-01-01 00:00:00 +0000
1925+++ src/graphic/styles/font_style.cc 2019-05-26 02:00:17 +0000
1926@@ -0,0 +1,130 @@
1927+/*
1928+ * Copyright (C) 2018 by the Widelands Development Team
1929+ *
1930+ * This program is free software; you can redistribute it and/or
1931+ * modify it under the terms of the GNU General Public License
1932+ * as published by the Free Software Foundation; either version 2
1933+ * of the License, or (at your option) any later version.
1934+ *
1935+ * This program is distributed in the hope that it will be useful,
1936+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1937+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1938+ * GNU General Public License for more details.
1939+ *
1940+ * You should have received a copy of the GNU General Public License
1941+ * along with this program; if not, write to the Free Software
1942+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1943+ *
1944+ */
1945+
1946+#include "graphic/styles/font_style.h"
1947+
1948+#include <boost/format.hpp>
1949+
1950+#include "base/log.h"
1951+#include "base/wexception.h"
1952+
1953+namespace UI {
1954+
1955+FontStyleInfo::FontStyleInfo(const std::string& init_face, const RGBColor& init_color, int init_size,
1956+ bool init_bold, bool init_italic, bool init_underline, bool init_shadow) :
1957+ face_(string_to_face(init_face)),
1958+ color_(init_color),
1959+ size_(init_size),
1960+ bold_(init_bold),
1961+ italic_(init_italic),
1962+ underline_(init_underline),
1963+ shadow_(init_shadow) {
1964+}
1965+
1966+FontStyleInfo::FontStyleInfo(const FontStyleInfo& other) :
1967+ face_(other.face()),
1968+ color_(other.color()),
1969+ size_(other.size()),
1970+ bold_(other.bold()),
1971+ italic_(other.italic()),
1972+ underline_(other.underline()),
1973+ shadow_(other.shadow())
1974+{}
1975+
1976+const std::string FontStyleInfo::face_to_string() const {
1977+ switch (face_) {
1978+ case Face::kSans:
1979+ return "sans";
1980+ case Face::kSerif:
1981+ return "serif";
1982+ case Face::kCondensed:
1983+ return "condensed";
1984+ }
1985+ return "sans";
1986+}
1987+
1988+FontStyleInfo::Face FontStyleInfo::string_to_face(const std::string& init_face) {
1989+ FontStyleInfo::Face result;
1990+ if (init_face == "sans") {
1991+ result = Face::kSans;
1992+ } else if (init_face == "serif") {
1993+ result = Face::kSerif;
1994+ } else if (init_face == "condensed") {
1995+ result = Face::kCondensed;
1996+ } else {
1997+ throw wexception("Unknown font face '%s', expected 'sans', 'serif' or 'condensed'", init_face.c_str());
1998+ }
1999+ return result;
2000+}
2001+
2002+std::string FontStyleInfo::as_font_tag(const std::string& text) const {
2003+ static boost::format f("<font face=%s size=%d color=%s%s>%s</font>");
2004+ std::string optionals = "";
2005+ if (bold_) {
2006+ optionals += " bold=1";
2007+ }
2008+ if (italic_) {
2009+ optionals += " italic=1";
2010+ }
2011+ if (shadow_) {
2012+ optionals += " shadow=1";
2013+ }
2014+ if (underline_) {
2015+ optionals += " underline=1";
2016+ }
2017+ f % face_to_string();
2018+ f % size_;
2019+ f % color_.hex_value();
2020+ f % optionals;
2021+ f % text;
2022+ return f.str();
2023+}
2024+
2025+FontStyleInfo::Face FontStyleInfo::face() const {
2026+ return face_;
2027+}
2028+void FontStyleInfo::make_condensed() {
2029+ face_ = Face::kCondensed;
2030+}
2031+const RGBColor& FontStyleInfo::color() const {
2032+ return color_;
2033+}
2034+void FontStyleInfo::set_color(const RGBColor& new_color) {
2035+ color_ = new_color;
2036+}
2037+int FontStyleInfo::size() const {
2038+ return size_;
2039+}
2040+void FontStyleInfo::set_size(int new_size) {
2041+ size_ = new_size;
2042+}
2043+bool FontStyleInfo::bold() const {
2044+ return bold_;
2045+}
2046+bool FontStyleInfo::italic() const {
2047+ return italic_;
2048+}
2049+bool FontStyleInfo::underline() const {
2050+ return underline_;
2051+}
2052+bool FontStyleInfo::shadow() const {
2053+ return shadow_;
2054+}
2055+
2056+} // namespace UI
2057
2058=== added file 'src/graphic/styles/font_style.h'
2059--- src/graphic/styles/font_style.h 1970-01-01 00:00:00 +0000
2060+++ src/graphic/styles/font_style.h 2019-05-26 02:00:17 +0000
2061@@ -0,0 +1,97 @@
2062+/*
2063+ * Copyright (C) 2018 by the Widelands Development Team
2064+ *
2065+ * This program is free software; you can redistribute it and/or
2066+ * modify it under the terms of the GNU General Public License
2067+ * as published by the Free Software Foundation; either version 2
2068+ * of the License, or (at your option) any later version.
2069+ *
2070+ * This program is distributed in the hope that it will be useful,
2071+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2072+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2073+ * GNU General Public License for more details.
2074+ *
2075+ * You should have received a copy of the GNU General Public License
2076+ * along with this program; if not, write to the Free Software
2077+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2078+ *
2079+ */
2080+
2081+#ifndef WL_GRAPHIC_STYLES_FONT_STYLE_H
2082+#define WL_GRAPHIC_STYLES_FONT_STYLE_H
2083+
2084+#include <string>
2085+
2086+#include "graphic/color.h"
2087+
2088+namespace UI {
2089+enum class FontStyle {
2090+ kChatMessage,
2091+ kChatPlayername,
2092+ kChatServer,
2093+ kChatTimestamp,
2094+ kChatWhisper,
2095+ kFsGameSetupHeadings,
2096+ kFsGameSetupIrcClient,
2097+ kFsGameSetupSuperuser,
2098+ kFsGameSetupMapname,
2099+ kFsMenuGameTip,
2100+ kFsMenuInfoPanelHeading,
2101+ kFsMenuInfoPanelParagraph,
2102+ kFsMenuIntro,
2103+ kFsMenuTitle,
2104+ kFsMenuTranslationInfo,
2105+ kDisabled,
2106+ kLabel,
2107+ kTooltipHeader,
2108+ kTooltip,
2109+ kWarning,
2110+ kWuiAttackBoxSliderLabel,
2111+ kWuiGameSpeedAndCoordinates,
2112+ kWuiInfoPanelHeading,
2113+ kWuiInfoPanelParagraph,
2114+ kWuiMessageHeading,
2115+ kWuiMessageParagraph,
2116+ kWuiWindowTitle
2117+};
2118+
2119+struct FontStyleInfo {
2120+ enum class Face { kSans, kSerif, kCondensed };
2121+
2122+ explicit FontStyleInfo(const std::string& init_face, const RGBColor& init_color, int init_size,
2123+ bool init_bold, bool init_italic, bool init_underline, bool init_shadow);
2124+ explicit FontStyleInfo(const FontStyleInfo& other);
2125+ FontStyleInfo& operator=(const FontStyleInfo& other) = default;
2126+
2127+ std::string as_font_tag(const std::string& text) const;
2128+
2129+ Face face() const;
2130+ void make_condensed();
2131+
2132+ const RGBColor& color() const;
2133+ void set_color(const RGBColor& new_color);
2134+
2135+ int size() const;
2136+ void set_size(int new_size);
2137+
2138+ bool bold() const;
2139+ bool italic() const;
2140+ bool underline() const;
2141+ bool shadow() const;
2142+
2143+private:
2144+ static Face string_to_face(const std::string& face_);
2145+ const std::string face_to_string() const;
2146+
2147+ Face face_;
2148+ RGBColor color_;
2149+ int size_;
2150+ const bool bold_;
2151+ const bool italic_;
2152+ const bool underline_;
2153+ const bool shadow_;
2154+};
2155+
2156+} // namespace UI
2157+
2158+#endif // end of include guard: WL_GRAPHIC_STYLES_FONT_STYLE_H
2159
2160=== renamed file 'src/graphic/panel_styles.h' => 'src/graphic/styles/panel_styles.h'
2161--- src/graphic/panel_styles.h 2019-02-23 11:00:49 +0000
2162+++ src/graphic/styles/panel_styles.h 2019-05-26 02:00:17 +0000
2163@@ -17,41 +17,47 @@
2164 *
2165 */
2166
2167-#ifndef WL_GRAPHIC_PANEL_STYLES_H
2168-#define WL_GRAPHIC_PANEL_STYLES_H
2169+#ifndef WL_GRAPHIC_STYLES_PANEL_STYLES_H
2170+#define WL_GRAPHIC_STYLES_PANEL_STYLES_H
2171+
2172+#include <map>
2173+#include <memory>
2174
2175 #include "graphic/color.h"
2176+#include "graphic/styles/font_style.h"
2177 #include "graphic/image.h"
2178
2179 namespace UI {
2180
2181-// Buttons
2182-enum class ButtonStyle {
2183- kFsMenuMenu,
2184- kFsMenuPrimary,
2185- kFsMenuSecondary,
2186- kWuiMenu,
2187- kWuiPrimary,
2188- kWuiSecondary,
2189- kWuiBuildingStats
2190-};
2191-enum class SliderStyle { kFsMenu, kWuiLight, kWuiDark };
2192-
2193 // Backgrounds
2194 enum class PanelStyle { kFsMenu, kWui };
2195 enum class TabPanelStyle { kFsMenu, kWuiLight, kWuiDark };
2196
2197 struct PanelStyleInfo {
2198- PanelStyleInfo(const Image* init_image, const RGBAColor& init_color)
2199- : image(init_image), color(init_color) {
2200- }
2201- PanelStyleInfo() : PanelStyleInfo(nullptr, RGBAColor(0, 0, 0, 0)) {
2202- }
2203-
2204- const Image* image;
2205- const RGBAColor color;
2206+ PanelStyleInfo(const Image* init_image, const RGBAColor& init_color, int init_margin)
2207+ : margin_(init_margin), image_(init_image), color_(init_color) {
2208+ }
2209+ PanelStyleInfo(const PanelStyleInfo& other)
2210+ : image_(other.image()), color_(other.color()) {
2211+ }
2212+
2213+ const RGBAColor& color() const {
2214+ return color_;
2215+ }
2216+ const Image* image() const {
2217+ return image_;
2218+ }
2219+
2220+ int margin() const {
2221+ return margin_;
2222+ }
2223+
2224+private:
2225+ int margin_;
2226+ const Image* image_;
2227+ RGBAColor color_;
2228 };
2229
2230 } // namespace UI
2231
2232-#endif // end of include guard: WL_GRAPHIC_PANEL_STYLES_H
2233+#endif // end of include guard: WL_GRAPHIC_STYLES_PANEL_STYLES_H
2234
2235=== added file 'src/graphic/styles/progress_bar_style.h'
2236--- src/graphic/styles/progress_bar_style.h 1970-01-01 00:00:00 +0000
2237+++ src/graphic/styles/progress_bar_style.h 2019-05-26 02:00:17 +0000
2238@@ -0,0 +1,69 @@
2239+/*
2240+ * Copyright (C) 2018 by the Widelands Development Team
2241+ *
2242+ * This program is free software; you can redistribute it and/or
2243+ * modify it under the terms of the GNU General Public License
2244+ * as published by the Free Software Foundation; either version 2
2245+ * of the License, or (at your option) any later version.
2246+ *
2247+ * This program is distributed in the hope that it will be useful,
2248+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2249+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2250+ * GNU General Public License for more details.
2251+ *
2252+ * You should have received a copy of the GNU General Public License
2253+ * along with this program; if not, write to the Free Software
2254+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2255+ *
2256+ */
2257+
2258+#ifndef WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
2259+#define WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
2260+
2261+#include <memory>
2262+
2263+#include "graphic/color.h"
2264+#include "graphic/styles/font_style.h"
2265+
2266+namespace UI {
2267+
2268+struct ProgressbarStyleInfo {
2269+ explicit ProgressbarStyleInfo(UI::FontStyleInfo* init_font,
2270+ const RGBColor& init_low_color,
2271+ const RGBColor& init_medium_color,
2272+ const RGBColor& init_high_color) :
2273+ font_(init_font),
2274+ low_color_(init_low_color),
2275+ medium_color_(init_medium_color),
2276+ high_color_(init_high_color) {}
2277+ explicit ProgressbarStyleInfo(const ProgressbarStyleInfo& other):
2278+ font_(new UI::FontStyleInfo(other.font())),
2279+ low_color_(other.low_color()),
2280+ medium_color_(other.medium_color()),
2281+ high_color_(other.high_color())
2282+ {
2283+ }
2284+
2285+ const UI::FontStyleInfo& font() const {
2286+ return *font_.get();
2287+ }
2288+ const RGBColor& low_color() const {
2289+ return low_color_;
2290+ }
2291+ const RGBColor& medium_color() const {
2292+ return medium_color_;
2293+ }
2294+ const RGBColor& high_color() const {
2295+ return high_color_;
2296+ }
2297+
2298+private:
2299+ std::unique_ptr<const UI::FontStyleInfo> font_;
2300+ const RGBColor low_color_;
2301+ const RGBColor medium_color_;
2302+ const RGBColor high_color_;
2303+};
2304+
2305+} // namespace UI
2306+
2307+#endif // end of include guard: WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
2308
2309=== added file 'src/graphic/styles/statistics_plot_style.h'
2310--- src/graphic/styles/statistics_plot_style.h 1970-01-01 00:00:00 +0000
2311+++ src/graphic/styles/statistics_plot_style.h 2019-05-26 02:00:17 +0000
2312@@ -0,0 +1,68 @@
2313+/*
2314+ * Copyright (C) 2018 by the Widelands Development Team
2315+ *
2316+ * This program is free software; you can redistribute it and/or
2317+ * modify it under the terms of the GNU General Public License
2318+ * as published by the Free Software Foundation; either version 2
2319+ * of the License, or (at your option) any later version.
2320+ *
2321+ * This program is distributed in the hope that it will be useful,
2322+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2323+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2324+ * GNU General Public License for more details.
2325+ *
2326+ * You should have received a copy of the GNU General Public License
2327+ * along with this program; if not, write to the Free Software
2328+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2329+ *
2330+ */
2331+
2332+#ifndef WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
2333+#define WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
2334+
2335+#include <memory>
2336+
2337+#include "graphic/color.h"
2338+#include "graphic/styles/font_style.h"
2339+
2340+namespace UI {
2341+
2342+struct StatisticsPlotStyleInfo {
2343+ explicit StatisticsPlotStyleInfo(UI::FontStyleInfo* init_x_tick_font,
2344+ UI::FontStyleInfo* init_y_min_value_font,
2345+ UI::FontStyleInfo* init_y_max_value_font,
2346+ const RGBColor& init_axis_line_color,
2347+ const RGBColor& init_zero_line_color) :
2348+ x_tick_font_(init_x_tick_font),
2349+ y_min_value_font_(init_y_min_value_font),
2350+ y_max_value_font_(init_y_max_value_font),
2351+ axis_line_color_(init_axis_line_color),
2352+ zero_line_color_(init_zero_line_color) {}
2353+
2354+ const UI::FontStyleInfo& x_tick_font() const {
2355+ return *x_tick_font_.get();
2356+ }
2357+ const UI::FontStyleInfo& y_min_value_font() const {
2358+ return *y_min_value_font_.get();
2359+ }
2360+ const UI::FontStyleInfo& y_max_value_font() const {
2361+ return *y_max_value_font_.get();
2362+ }
2363+ const RGBColor& axis_line_color() const {
2364+ return axis_line_color_;
2365+ }
2366+ const RGBColor& zero_line_color() const {
2367+ return zero_line_color_;
2368+ }
2369+
2370+private:
2371+ std::unique_ptr<const UI::FontStyleInfo> x_tick_font_;
2372+ std::unique_ptr<const UI::FontStyleInfo> y_min_value_font_;
2373+ std::unique_ptr<const UI::FontStyleInfo> y_max_value_font_;
2374+ const RGBColor axis_line_color_;
2375+ const RGBColor zero_line_color_;
2376+};
2377+
2378+} // namespace UI
2379+
2380+#endif // end of include guard: WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
2381
2382=== added file 'src/graphic/styles/table_style.h'
2383--- src/graphic/styles/table_style.h 1970-01-01 00:00:00 +0000
2384+++ src/graphic/styles/table_style.h 2019-05-26 02:00:17 +0000
2385@@ -0,0 +1,47 @@
2386+/*
2387+ * Copyright (C) 2018 by the Widelands Development Team
2388+ *
2389+ * This program is free software; you can redistribute it and/or
2390+ * modify it under the terms of the GNU General Public License
2391+ * as published by the Free Software Foundation; either version 2
2392+ * of the License, or (at your option) any later version.
2393+ *
2394+ * This program is distributed in the hope that it will be useful,
2395+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2396+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2397+ * GNU General Public License for more details.
2398+ *
2399+ * You should have received a copy of the GNU General Public License
2400+ * along with this program; if not, write to the Free Software
2401+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2402+ *
2403+ */
2404+
2405+#ifndef WL_GRAPHIC_STYLES_TABLE_STYLE_H
2406+#define WL_GRAPHIC_STYLES_TABLE_STYLE_H
2407+
2408+#include <memory>
2409+
2410+#include "graphic/styles/font_style.h"
2411+
2412+namespace UI {
2413+
2414+struct TableStyleInfo {
2415+ explicit TableStyleInfo(UI::FontStyleInfo* init_enabled, UI::FontStyleInfo* init_disabled) :
2416+ enabled_(init_enabled), disabled_(init_disabled) {}
2417+
2418+ const UI::FontStyleInfo& enabled() const {
2419+ return *enabled_.get();
2420+ }
2421+ const UI::FontStyleInfo& disabled() const {
2422+ return *disabled_.get();
2423+ }
2424+
2425+private:
2426+ std::unique_ptr<const UI::FontStyleInfo> enabled_;
2427+ std::unique_ptr<const UI::FontStyleInfo> disabled_;
2428+};
2429+
2430+} // namespace UI
2431+
2432+#endif // end of include guard: WL_GRAPHIC_STYLES_TABLE_STYLE_H
2433
2434=== added file 'src/graphic/styles/text_panel_style.h'
2435--- src/graphic/styles/text_panel_style.h 1970-01-01 00:00:00 +0000
2436+++ src/graphic/styles/text_panel_style.h 2019-05-26 02:00:17 +0000
2437@@ -0,0 +1,61 @@
2438+/*
2439+ * Copyright (C) 2018 by the Widelands Development Team
2440+ *
2441+ * This program is free software; you can redistribute it and/or
2442+ * modify it under the terms of the GNU General Public License
2443+ * as published by the Free Software Foundation; either version 2
2444+ * of the License, or (at your option) any later version.
2445+ *
2446+ * This program is distributed in the hope that it will be useful,
2447+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2448+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2449+ * GNU General Public License for more details.
2450+ *
2451+ * You should have received a copy of the GNU General Public License
2452+ * along with this program; if not, write to the Free Software
2453+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2454+ *
2455+ */
2456+
2457+#ifndef WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
2458+#define WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
2459+
2460+#include <memory>
2461+
2462+#include "graphic/styles/font_style.h"
2463+#include "graphic/styles/panel_styles.h"
2464+
2465+namespace UI {
2466+
2467+enum class SliderStyle { kFsMenu, kWuiLight, kWuiDark };
2468+
2469+struct TextPanelStyleInfo {
2470+ explicit TextPanelStyleInfo(const UI::FontStyleInfo* init_font, const UI::PanelStyleInfo* init_background) :
2471+ background_(init_background),
2472+ font_(init_font) {
2473+ }
2474+ explicit TextPanelStyleInfo(const TextPanelStyleInfo& other) :
2475+ background_(new UI::PanelStyleInfo(other.background())),
2476+ font_(new UI::FontStyleInfo(other.font())) {
2477+ }
2478+ TextPanelStyleInfo& operator=(const TextPanelStyleInfo& other) = default;
2479+
2480+ const UI::FontStyleInfo& font() const {
2481+ return *font_.get();
2482+ }
2483+ void set_font(const UI::FontStyleInfo& new_font) {
2484+ font_.reset(new UI::FontStyleInfo(new_font));
2485+ }
2486+
2487+ const UI::PanelStyleInfo& background() const {
2488+ return *background_.get();
2489+ }
2490+
2491+private:
2492+ std::unique_ptr<const UI::PanelStyleInfo> background_;
2493+ std::unique_ptr<const UI::FontStyleInfo> font_;
2494+};
2495+
2496+} // namespace UI
2497+
2498+#endif // end of include guard: WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
2499
2500=== added file 'src/graphic/styles/ware_info_style.h'
2501--- src/graphic/styles/ware_info_style.h 1970-01-01 00:00:00 +0000
2502+++ src/graphic/styles/ware_info_style.h 2019-05-26 02:00:17 +0000
2503@@ -0,0 +1,80 @@
2504+/*
2505+ * Copyright (C) 2018 by the Widelands Development Team
2506+ *
2507+ * This program is free software; you can redistribute it and/or
2508+ * modify it under the terms of the GNU General Public License
2509+ * as published by the Free Software Foundation; either version 2
2510+ * of the License, or (at your option) any later version.
2511+ *
2512+ * This program is distributed in the hope that it will be useful,
2513+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2514+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2515+ * GNU General Public License for more details.
2516+ *
2517+ * You should have received a copy of the GNU General Public License
2518+ * along with this program; if not, write to the Free Software
2519+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2520+ *
2521+ */
2522+
2523+#ifndef WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
2524+#define WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
2525+
2526+#include <memory>
2527+
2528+#include "graphic/color.h"
2529+#include "graphic/styles/font_style.h"
2530+#include "graphic/image.h"
2531+
2532+namespace UI {
2533+
2534+enum class WareInfoStyle {
2535+ kNormal,
2536+ kHighlight
2537+};
2538+
2539+struct WareInfoStyleInfo {
2540+ explicit WareInfoStyleInfo(UI::FontStyleInfo* init_header_font,
2541+ UI::FontStyleInfo* init_info_font,
2542+ const Image* init_icon_background_image,
2543+ const RGBColor& init_icon_frame,
2544+ const RGBColor& init_icon_background,
2545+ const RGBColor& init_info_background) :
2546+ header_font_(init_header_font),
2547+ info_font_(init_info_font),
2548+ icon_background_image_(init_icon_background_image),
2549+ icon_frame_(init_icon_frame),
2550+ icon_background_(init_icon_background),
2551+ info_background_(init_info_background) {}
2552+
2553+ const UI::FontStyleInfo& header_font() const {
2554+ return *header_font_.get();
2555+ }
2556+ const UI::FontStyleInfo& info_font() const {
2557+ return *info_font_.get();
2558+ }
2559+ const Image* icon_background_image() const {
2560+ return icon_background_image_;
2561+ }
2562+ const RGBColor& icon_frame() const {
2563+ return icon_frame_;
2564+ }
2565+ const RGBColor& icon_background() const {
2566+ return icon_background_;
2567+ }
2568+ const RGBColor& info_background() const {
2569+ return info_background_;
2570+ }
2571+
2572+private:
2573+ std::unique_ptr<const UI::FontStyleInfo> header_font_;
2574+ std::unique_ptr<const UI::FontStyleInfo> info_font_;
2575+ const Image* icon_background_image_;
2576+ const RGBColor icon_frame_;
2577+ const RGBColor icon_background_;
2578+ const RGBColor info_background_;
2579+};
2580+
2581+} // namespace UI
2582+
2583+#endif // end of include guard: WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
2584
2585=== modified file 'src/graphic/text/CMakeLists.txt'
2586--- src/graphic/text/CMakeLists.txt 2018-03-02 06:01:51 +0000
2587+++ src/graphic/text/CMakeLists.txt 2019-05-26 02:00:17 +0000
2588@@ -41,7 +41,6 @@
2589 graphic_playercolor
2590 graphic_sdl_utils
2591 graphic_surface
2592- graphic_text_layout
2593 io_fileread
2594 io_filesystem
2595 scripting_lua_interface
2596
2597=== modified file 'src/graphic/text/font_set.cc'
2598--- src/graphic/text/font_set.cc 2019-02-23 11:00:49 +0000
2599+++ src/graphic/text/font_set.cc 2019-05-26 02:00:17 +0000
2600@@ -27,6 +27,7 @@
2601
2602 #include "base/i18n.h"
2603 #include "base/log.h"
2604+#include "graphic/text/bidi.h"
2605 #include "io/filesystem/layered_filesystem.h"
2606 #include "scripting/lua_interface.h"
2607 #include "scripting/lua_table.h"
2608
2609=== modified file 'src/graphic/text/font_set.h'
2610--- src/graphic/text/font_set.h 2019-02-23 11:00:49 +0000
2611+++ src/graphic/text/font_set.h 2019-05-26 02:00:17 +0000
2612@@ -25,6 +25,7 @@
2613 #include <string>
2614
2615 #include "base/macros.h"
2616+#include "graphic/align.h"
2617 #include "scripting/lua_table.h"
2618
2619 namespace UI {
2620@@ -32,8 +33,6 @@
2621 // Contains font information for a locale
2622 struct FontSet {
2623
2624- enum class Face { kSans, kSerif, kCondensed };
2625-
2626 static constexpr const char* kFallbackFont = "DejaVu/DejaVuSans.ttf";
2627
2628 /// Create a fontset from i18n/fonts.lua
2629@@ -62,6 +61,7 @@
2630 // Returns true iff the fontset's script is written from right to left.
2631 bool is_rtl() const;
2632
2633+
2634 private:
2635 /// Parses font information for the given fontset name from Lua.
2636 /// The fontset definitions are in i18n/fonts.lua
2637
2638=== modified file 'src/graphic/text/rendered_text.cc'
2639--- src/graphic/text/rendered_text.cc 2019-02-23 11:00:49 +0000
2640+++ src/graphic/text/rendered_text.cc 2019-05-26 02:00:17 +0000
2641@@ -22,7 +22,6 @@
2642 #include <memory>
2643
2644 #include "graphic/graphic.h"
2645-#include "graphic/text_layout.h"
2646
2647 namespace UI {
2648 // RenderedRect
2649
2650=== modified file 'src/graphic/text/rt_render.cc'
2651--- src/graphic/text/rt_render.cc 2019-05-04 09:59:51 +0000
2652+++ src/graphic/text/rt_render.cc 2019-05-26 02:00:17 +0000
2653@@ -48,11 +48,23 @@
2654 #include "graphic/text/rt_parse.h"
2655 #include "graphic/text/sdl_ttf_font.h"
2656 #include "graphic/text/textstream.h"
2657-#include "graphic/text_layout.h"
2658 #include "graphic/texture.h"
2659 #include "io/filesystem/filesystem_exceptions.h"
2660 #include "io/filesystem/layered_filesystem.h"
2661
2662+namespace {
2663+/**
2664+ * This function replaces some HTML entities in strings, e.g. &nbsp;.
2665+ * It is used by the renderer after the tags have been parsed.
2666+ */
2667+void replace_entities(std::string* text) {
2668+ boost::replace_all(*text, "&gt;", ">");
2669+ boost::replace_all(*text, "&lt;", "<");
2670+ boost::replace_all(*text, "&nbsp;", " ");
2671+ boost::replace_all(*text, "&amp;", "&"); // Must be performed last
2672+}
2673+} // namespace
2674+
2675 namespace RT {
2676
2677 static const uint16_t INFINITE_WIDTH = 65535; // 2^16-1
2678@@ -93,6 +105,7 @@
2679 uint8_t spacing;
2680 UI::Align halign;
2681 UI::Align valign;
2682+ const bool is_rtl;
2683 std::string reference;
2684 };
2685
2686@@ -975,7 +988,7 @@
2687 : RenderNode(ns),
2688 image_(image),
2689 filename_(""),
2690- scale_(1.0f),
2691+ scale_(1.0),
2692 color_(RGBColor(0, 0, 0)),
2693 use_playercolor_(false) {
2694 check_size();
2695@@ -1234,7 +1247,7 @@
2696 nodestyle_.halign = UI::Align::kLeft;
2697 }
2698 }
2699- nodestyle_.halign = mirror_alignment(nodestyle_.halign);
2700+ nodestyle_.halign = mirror_alignment(nodestyle_.halign, nodestyle_.is_rtl);
2701 if (a.has("valign")) {
2702 const std::string align = a["valign"].get_string();
2703 if (align == "bottom") {
2704@@ -1715,7 +1728,7 @@
2705 }
2706
2707 std::shared_ptr<RenderNode>
2708-Renderer::layout(const std::string& text, uint16_t width, const TagSet& allowed_tags) {
2709+Renderer::layout(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags) {
2710 std::unique_ptr<Tag> rt(parser_->parse(text, allowed_tags));
2711
2712 if (!width) {
2713@@ -1735,6 +1748,7 @@
2714 0,
2715 UI::Align::kLeft,
2716 UI::Align::kTop,
2717+ is_rtl,
2718 ""};
2719
2720 RTTagHandler rtrn(
2721@@ -1749,8 +1763,8 @@
2722 }
2723
2724 std::shared_ptr<const UI::RenderedText>
2725-Renderer::render(const std::string& text, uint16_t width, const TagSet& allowed_tags) {
2726- std::shared_ptr<RenderNode> node(layout(text, width, allowed_tags));
2727+Renderer::render(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags) {
2728+ std::shared_ptr<RenderNode> node(layout(text, width, is_rtl, allowed_tags));
2729 return std::shared_ptr<const UI::RenderedText>(node->render(texture_cache_));
2730 }
2731 } // namespace RT
2732
2733=== modified file 'src/graphic/text/rt_render.h'
2734--- src/graphic/text/rt_render.h 2019-02-23 11:00:49 +0000
2735+++ src/graphic/text/rt_render.h 2019-05-26 02:00:17 +0000
2736@@ -70,11 +70,11 @@
2737 // Render the given string in the given width. Restricts the allowed tags to
2738 // the ones in TagSet.
2739 std::shared_ptr<const UI::RenderedText>
2740- render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());
2741+ render(const std::string&, uint16_t width, bool is_rtl, const TagSet& tagset = TagSet());
2742
2743 private:
2744 std::shared_ptr<RenderNode>
2745- layout(const std::string& text, uint16_t width, const TagSet& allowed_tags);
2746+ layout(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags);
2747
2748 std::unique_ptr<FontCache> font_cache_;
2749 std::unique_ptr<Parser> parser_;
2750
2751=== removed file 'src/graphic/text_constants.cc'
2752--- src/graphic/text_constants.cc 2017-03-04 12:37:17 +0000
2753+++ src/graphic/text_constants.cc 1970-01-01 00:00:00 +0000
2754@@ -1,1 +0,0 @@
2755-// Dummy to make CMake happy
2756
2757=== removed file 'src/graphic/text_constants.h'
2758--- src/graphic/text_constants.h 2019-02-23 11:00:49 +0000
2759+++ src/graphic/text_constants.h 1970-01-01 00:00:00 +0000
2760@@ -1,50 +0,0 @@
2761-/*
2762- * Copyright (C) 2006-2019 by the Widelands Development Team
2763- *
2764- * This program is free software; you can redistribute it and/or
2765- * modify it under the terms of the GNU General Public License
2766- * as published by the Free Software Foundation; either version 2
2767- * of the License, or (at your option) any later version.
2768- *
2769- * This program is distributed in the hope that it will be useful,
2770- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2771- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2772- * GNU General Public License for more details.
2773- *
2774- * You should have received a copy of the GNU General Public License
2775- * along with this program; if not, write to the Free Software
2776- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2777- *
2778- */
2779-
2780-#ifndef WL_GRAPHIC_TEXT_CONSTANTS_H
2781-#define WL_GRAPHIC_TEXT_CONSTANTS_H
2782-
2783-// Basic constants for often used text attributes.
2784-
2785-/// Font Sizes
2786-#define UI_FONT_SIZE_BIG 22
2787-#define UI_FONT_SIZE_SMALL 14
2788-#define UI_FONT_SIZE_MESSAGE 12
2789-#define UI_FONT_SIZE_ULTRASMALL 10
2790-constexpr int kMinimumFontSize = 6;
2791-constexpr int kLineMargin = 1;
2792-
2793-/// Font colors
2794-
2795-/// Global UI font color
2796-#define UI_FONT_CLR_FG RGBColor(255, 255, 0)
2797-#define UI_FONT_CLR_DISABLED RGBColor(127, 127, 127)
2798-#define UI_FONT_CLR_WARNING RGBColor(255, 22, 22)
2799-
2800-/// Tooltip font color
2801-#define UI_FONT_TOOLTIP_CLR RGBColor(255, 255, 0)
2802-
2803-/// Colors for good/ok/bad
2804-#define UI_FONT_CLR_BRIGHT RGBColor(255, 250, 170)
2805-#define UI_FONT_CLR_DARK RGBColor(163, 144, 19)
2806-#define UI_FONT_CLR_BAD RGBColor(187, 0, 0)
2807-#define UI_FONT_CLR_OK RGBColor(255, 225, 30)
2808-#define UI_FONT_CLR_GOOD RGBColor(0, 187, 0)
2809-
2810-#endif // end of include guard: WL_GRAPHIC_TEXT_CONSTANTS_H
2811
2812=== modified file 'src/graphic/text_layout.cc'
2813--- src/graphic/text_layout.cc 2019-04-18 16:50:35 +0000
2814+++ src/graphic/text_layout.cc 2019-05-26 02:00:17 +0000
2815@@ -19,18 +19,14 @@
2816
2817 #include "graphic/text_layout.h"
2818
2819-#include <map>
2820-
2821-#include <SDL_ttf.h>
2822 #include <boost/algorithm/string.hpp>
2823 #include <boost/format.hpp>
2824
2825 #include "graphic/font_handler.h"
2826 #include "graphic/graphic.h"
2827 #include "graphic/image.h"
2828-#include "graphic/text/bidi.h"
2829+#include "graphic/style_manager.h"
2830 #include "graphic/text/font_set.h"
2831-#include "graphic/text_constants.h"
2832
2833 namespace {
2834 bool is_paragraph(const std::string& text) {
2835@@ -40,70 +36,8 @@
2836 bool is_div(const std::string& text) {
2837 return boost::starts_with(text, "<div");
2838 }
2839-} // namespace
2840-
2841-void replace_entities(std::string* text) {
2842- boost::replace_all(*text, "&gt;", ">");
2843- boost::replace_all(*text, "&lt;", "<");
2844- boost::replace_all(*text, "&nbsp;", " ");
2845- boost::replace_all(*text, "&amp;", "&"); // Must be performed last
2846-}
2847-
2848-int text_width(const std::string& text, int ptsize) {
2849- return UI::g_fh
2850- ->render(as_editorfont(
2851- text.substr(0, g_gr->max_texture_size_for_font_rendering() / text_height() - 1),
2852- ptsize - UI::g_fh->fontset()->size_offset()))
2853- ->width();
2854-}
2855-
2856-int text_height(int ptsize, UI::FontSet::Face face) {
2857- return UI::g_fh
2858- ->render(as_aligned(UI::g_fh->fontset()->representative_character(), UI::Align::kLeft,
2859- ptsize - UI::g_fh->fontset()->size_offset(), RGBColor(0, 0, 0), face))
2860- ->height();
2861-}
2862-
2863-std::string richtext_escape(const std::string& given_text) {
2864- std::string text = given_text;
2865- boost::replace_all(text, "&", "&amp;"); // Must be performed first
2866- boost::replace_all(text, ">", "&gt;");
2867- boost::replace_all(text, "<", "&lt;");
2868- return text;
2869-}
2870-
2871-std::string as_game_tip(const std::string& txt) {
2872- static boost::format f(
2873- "<rt><p align=center><font color=21211b face=serif size=16>%s</font></p></rt>");
2874- f % txt;
2875- return f.str();
2876-}
2877-
2878-std::string
2879-as_uifont(const std::string& txt, int size, const RGBColor& clr, UI::FontSet::Face face) {
2880- return as_aligned(txt, UI::Align::kLeft, size, clr, face);
2881-}
2882-
2883-std::string
2884-as_condensed(const std::string& text, UI::Align align, int ptsize, const RGBColor& clr) {
2885- return as_aligned(text, align, ptsize, clr, UI::FontSet::Face::kCondensed);
2886-}
2887-
2888-std::string as_editorfont(const std::string& text, int ptsize, const RGBColor& clr) {
2889- // UI Text is always bold due to historic reasons
2890- static boost::format f(
2891- "<rt keep_spaces=1><p><font face=sans size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
2892- f % ptsize;
2893- f % clr.hex_value();
2894- f % richtext_escape(text);
2895- return f.str();
2896-}
2897-
2898-std::string as_aligned(const std::string& txt,
2899- UI::Align align,
2900- int ptsize,
2901- const RGBColor& clr,
2902- UI::FontSet::Face face) {
2903+
2904+std::string as_richtext_paragraph(const std::string& text, UI::Align align) {
2905 std::string alignment = "left";
2906 switch (align) {
2907 case UI::Align::kCenter:
2908@@ -117,38 +51,48 @@
2909 break;
2910 }
2911
2912- std::string font_face = "sans";
2913-
2914- switch (face) {
2915- case UI::FontSet::Face::kCondensed:
2916- font_face = "condensed";
2917- break;
2918- case UI::FontSet::Face::kSerif:
2919- font_face = "serif";
2920- break;
2921- case UI::FontSet::Face::kSans:
2922- font_face = "sans";
2923- break;
2924- }
2925-
2926- // UI Text is always bold due to historic reasons
2927- static boost::format f(
2928- "<rt><p align=%s><font face=%s size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
2929+ static boost::format f("<rt><p align=%s>%s</p></rt>");
2930 f % alignment;
2931- f % font_face;
2932- f % ptsize;
2933- f % clr.hex_value();
2934- f % txt;
2935+ f % text;
2936 return f.str();
2937 }
2938+} // namespace
2939+
2940+int text_width(const std::string& text, const UI::FontStyleInfo& style, float scale) {
2941+ UI::FontStyleInfo info(style);
2942+ info.set_size(info.size() * scale - UI::g_fh->fontset()->size_offset());
2943+ return UI::g_fh
2944+ ->render(as_editor_richtext_paragraph(text, info))->width();
2945+}
2946+
2947+int text_height(const UI::FontStyleInfo& style, float scale) {
2948+ UI::FontStyleInfo info(style);
2949+ info.set_size(info.size() * scale - UI::g_fh->fontset()->size_offset());
2950+ return UI::g_fh
2951+ ->render(as_richtext_paragraph(UI::g_fh->fontset()->representative_character(), info))
2952+ ->height();
2953+}
2954+
2955+int text_height(UI::FontStyle style, float scale) {
2956+ return text_height(g_gr->styles().font_style(style), scale);
2957+}
2958+
2959+std::string richtext_escape(const std::string& given_text) {
2960+ std::string text = given_text;
2961+ boost::replace_all(text, "&", "&amp;"); // Must be performed first
2962+ boost::replace_all(text, ">", "&gt;");
2963+ boost::replace_all(text, "<", "&lt;");
2964+ return text;
2965+}
2966
2967 /// Bullet list item
2968-std::string as_listitem(const std::string& txt, int ptsize, const RGBColor& clr) {
2969+std::string as_listitem(const std::string& txt, UI::FontStyle style) {
2970 static boost::format f("<div width=100%%><div><p><font size=%d "
2971 "color=%s>•</font></p></div><div><p><space gap=6></p></div><div "
2972 "width=*><p><font size=%d color=%s>%s<vspace "
2973 "gap=6></font></p></div></div>");
2974- f % ptsize % clr.hex_value() % ptsize % clr.hex_value() % txt;
2975+ const UI::FontStyleInfo& font_style = g_gr->styles().font_style(style);
2976+ f % font_style.size() % font_style.color().hex_value() % font_style.size() % font_style.color().hex_value() % txt;
2977 return f.str();
2978 }
2979
2980@@ -158,33 +102,83 @@
2981 return f.str();
2982 }
2983
2984-std::string as_tooltip(const std::string& txt) {
2985- static boost::format f("<rt><p><font face=sans size=%i bold=1 color=%s>%s</font></p></rt>");
2986-
2987- f % UI_FONT_SIZE_SMALL;
2988- f % UI_FONT_TOOLTIP_CLR.hex_value();
2989- f % txt;
2990- return f.str();
2991-}
2992-
2993-std::string as_waresinfo(const std::string& txt) {
2994- static boost::format f("<rt><p><font face=condensed size=10 bold=0 color=%s>%s</font></p></rt>");
2995- f % UI_FONT_TOOLTIP_CLR.hex_value();
2996- f % txt;
2997- return f.str();
2998+std::string as_richtext_paragraph(const std::string& text, UI::FontStyle style, UI::Align align) {
2999+ return as_richtext_paragraph(text, g_gr->styles().font_style(style), align);
3000+}
3001+
3002+std::string as_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style, UI::Align align) {
3003+ return as_richtext_paragraph(style.as_font_tag(text), align);
3004+}
3005+
3006+std::string as_editor_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style) {
3007+ static boost::format f("<rt keep_spaces=1><p>%s</p></rt>");
3008+ f % style.as_font_tag(text);
3009+ return f.str();
3010+}
3011+
3012+std::string as_game_tip(const std::string& txt) {
3013+ static boost::format f("<rt><p align=center>%s</p></rt>");
3014+ f % g_gr->styles().font_style(UI::FontStyle::kFsMenuGameTip).as_font_tag(txt);
3015+ return f.str();
3016+}
3017+
3018+std::string as_mapobject_message(const std::string& image, int width, const std::string& txt, const RGBColor* player_color) {
3019+ assert(!image.empty());
3020+ assert(!txt.empty());
3021+ const std::string image_type = g_gr->images().has(image) ? "src" : "object";
3022+ static boost::format f_color("<div padding_r=10><p><img width=%d %s=%s color=%s></p></div>"
3023+ "<div width=*><p>%s</p></div>");
3024+ static boost::format f_nocolor("<div padding_r=10><p><img width=%d %s=%s></p></div>"
3025+ "<div width=*><p>%s</p></div>");
3026+ if (player_color != nullptr) {
3027+ f_color % width;
3028+ f_color % image_type;
3029+ f_color % image;
3030+ f_color % player_color->hex_value();
3031+ f_color % g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(txt);
3032+ return f_color.str();
3033+ } else {
3034+ f_nocolor % width;
3035+ f_nocolor % image_type;
3036+ f_nocolor % image;
3037+ f_nocolor % g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(txt);
3038+ return f_nocolor.str();
3039+ }
3040 }
3041
3042 std::string as_message(const std::string& heading, const std::string& body) {
3043 return (
3044 (boost::format(
3045- "<rt><p><font size=18 bold=1 color=D1D1D1>%s<br></font></p><vspace gap=6>%s</rt>") %
3046- heading %
3047+ "<rt><p>%s<br></p><vspace gap=6>%s</rt>") %
3048+ g_gr->styles().font_style(UI::FontStyle::kWuiMessageHeading).as_font_tag(heading) %
3049 (is_paragraph(body) || is_div(body) ?
3050 body :
3051- (boost::format("<p><font size=%d>%s</font></p>") % UI_FONT_SIZE_MESSAGE % body).str()))
3052+ (boost::format("<p>%s</p>") %
3053+ g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(body))
3054+ .str()))
3055 .str());
3056 }
3057
3058+std::shared_ptr<const UI::RenderedText> autofit_text(const std::string& text,
3059+ const UI::FontStyleInfo& font_info,
3060+ int width) {
3061+ std::shared_ptr<const UI::RenderedText> rendered_text =
3062+ UI::g_fh->render(as_richtext_paragraph(text, font_info));
3063+
3064+ // Autoshrink if it doesn't fit
3065+ if (width > 0 && rendered_text->width() > width) {
3066+ const int minimum_size = g_gr->styles().minimum_font_size();
3067+ // We take a copy, because we are changing values during the autofit.
3068+ UI::FontStyleInfo temp_font_info(font_info);
3069+ temp_font_info.make_condensed();
3070+ while (rendered_text->width() > width && temp_font_info.size() >= minimum_size) {
3071+ rendered_text = UI::g_fh->render(as_richtext_paragraph(text, temp_font_info));
3072+ temp_font_info.set_size(temp_font_info.size() - 1);
3073+ }
3074+ }
3075+ return rendered_text;
3076+}
3077+
3078 std::string as_heading_with_content(const std::string& header,
3079 const std::string& content,
3080 UI::PanelStyle style,
3081@@ -192,18 +186,16 @@
3082 bool noescape) {
3083 switch (style) {
3084 case UI::PanelStyle::kFsMenu:
3085- return (boost::format(
3086- "<p><font size=%i bold=1 shadow=1>%s%s <font color=D1D1D1>%s</font></font></p>") %
3087- UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=9>") %
3088- (noescape ? header : richtext_escape(header)) %
3089- (noescape ? content : richtext_escape(content)))
3090+ return (boost::format("<p>%s%s %s</p>") %
3091+ (is_first ? "" : "<vspace gap=9>") %
3092+ g_gr->styles().font_style(UI::FontStyle::kFsMenuInfoPanelHeading).as_font_tag(noescape ? header : richtext_escape(header)) %
3093+ g_gr->styles().font_style(UI::FontStyle::kFsMenuInfoPanelParagraph).as_font_tag(noescape ? content : richtext_escape(content)))
3094 .str();
3095 case UI::PanelStyle::kWui:
3096- return (boost::format(
3097- "<p><font size=%i>%s<font bold=1 color=D1D1D1>%s</font> %s</font></p>") %
3098- UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=6>") %
3099- (noescape ? header : richtext_escape(header)) %
3100- (noescape ? content : richtext_escape(content)))
3101+ return (boost::format("<p>%s%s %s</p>") %
3102+ (is_first ? "" : "<vspace gap=6>") %
3103+ g_gr->styles().font_style(UI::FontStyle::kWuiInfoPanelHeading).as_font_tag(noescape ? header : richtext_escape(header)) %
3104+ g_gr->styles().font_style(UI::FontStyle::kWuiInfoPanelParagraph).as_font_tag(noescape ? content : richtext_escape(content)))
3105 .str();
3106 }
3107 NEVER_HERE();
3108@@ -212,12 +204,16 @@
3109 std::string as_heading(const std::string& txt, UI::PanelStyle style, bool is_first) {
3110 switch (style) {
3111 case UI::PanelStyle::kFsMenu:
3112- return (boost::format("<p><font size=%i bold=1 shadow=1>%s%s</font></p>") %
3113- UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=9>") % richtext_escape(txt))
3114+ return (boost::format("<p>%s%s</p>") % (is_first ? "" : "<vspace gap=9>") %
3115+ g_gr->styles()
3116+ .font_style(UI::FontStyle::kFsMenuInfoPanelHeading)
3117+ .as_font_tag(richtext_escape(txt)))
3118 .str();
3119 case UI::PanelStyle::kWui:
3120- return (boost::format("<p><font size=%i bold=1 color=D1D1D1>%s%s</font></p>") %
3121- UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=6>") % richtext_escape(txt))
3122+ return (boost::format("<p>%s%s</p>") % (is_first ? "" : "<vspace gap=6>") %
3123+ g_gr->styles()
3124+ .font_style(UI::FontStyle::kWuiInfoPanelHeading)
3125+ .as_font_tag(richtext_escape(txt)))
3126 .str();
3127 }
3128 NEVER_HERE();
3129@@ -226,78 +222,17 @@
3130 std::string as_content(const std::string& txt, UI::PanelStyle style) {
3131 switch (style) {
3132 case UI::PanelStyle::kFsMenu:
3133- return (boost::format("<p><font size=%i color=D1D1D1 shadow=1><vspace gap=2>%s</font></p>") %
3134- UI_FONT_SIZE_SMALL % richtext_escape(txt))
3135+ return (boost::format("<p><vspace gap=2>%s</p>") %
3136+ g_gr->styles()
3137+ .font_style(UI::FontStyle::kFsMenuInfoPanelParagraph)
3138+ .as_font_tag(richtext_escape(txt)))
3139 .str();
3140 case UI::PanelStyle::kWui:
3141- return (boost::format("<p><font size=%i><vspace gap=2>%s</font></p>") %
3142- (UI_FONT_SIZE_SMALL - 2) % richtext_escape(txt))
3143+ return (boost::format("<p><vspace gap=2>%s</p>") %
3144+ g_gr->styles()
3145+ .font_style(UI::FontStyle::kWuiInfoPanelParagraph)
3146+ .as_font_tag(richtext_escape(txt)))
3147 .str();
3148 }
3149 NEVER_HERE();
3150 }
3151-
3152-std::shared_ptr<const UI::RenderedText>
3153-autofit_ui_text(const std::string& text, int width, RGBColor color, int fontsize) {
3154- std::shared_ptr<const UI::RenderedText> result =
3155- UI::g_fh->render(as_uifont(richtext_escape(text), fontsize, color));
3156- if (width > 0) { // Autofit
3157- for (; result->width() > width && fontsize >= kMinimumFontSize; --fontsize) {
3158- result = UI::g_fh->render(
3159- as_condensed(richtext_escape(text), UI::Align::kLeft, fontsize, color));
3160- }
3161- }
3162- return result;
3163-}
3164-
3165-namespace UI {
3166-
3167-/**
3168- * This mirrors the horizontal alignment for RTL languages.
3169- *
3170- * Do not store this value as it is based on the global font setting.
3171- *
3172- * If 'checkme' is not empty, mirror the alignment if the first 20 characters contain an RTL
3173- * character. Otherwise, mirror if the current fontset is RTL.
3174- */
3175-Align mirror_alignment(Align alignment, const std::string& checkme) {
3176- bool do_swap_alignment = checkme.empty() ? UI::g_fh->fontset()->is_rtl() :
3177- i18n::has_rtl_character(checkme.c_str(), 20);
3178- if (do_swap_alignment) {
3179- switch (alignment) {
3180- case Align::kLeft:
3181- alignment = Align::kRight;
3182- break;
3183- case Align::kRight:
3184- alignment = Align::kLeft;
3185- break;
3186- case Align::kCenter:
3187- break;
3188- }
3189- }
3190- return alignment;
3191-}
3192-
3193-/**
3194- * Align pt horizontally to match align based on width w.
3195- *
3196- * When correcting for align, we never move from pixel boundaries to
3197- * sub-pixels, because this might lead from pixel-perfect rendering to
3198- * subsampled rendering - this can lead to blurry texts. That is why we
3199- * never do float divisions in this function.
3200- */
3201-void correct_for_align(Align align, uint32_t w, Vector2i* pt) {
3202-
3203- if (align == Align::kCenter)
3204- pt->x -= w / 2;
3205- else if (align == Align::kRight)
3206- pt->x -= w;
3207-}
3208-
3209-/**
3210- * Adjust the y coordinate in 'point 'pt' to vertically center an element with height 'h'.
3211- */
3212-void center_vertically(uint32_t h, Vector2i* pt) {
3213- pt->y -= h / 2;
3214-}
3215-} // namespace UI
3216
3217=== modified file 'src/graphic/text_layout.h'
3218--- src/graphic/text_layout.h 2019-04-18 16:50:35 +0000
3219+++ src/graphic/text_layout.h 2019-05-26 02:00:17 +0000
3220@@ -23,30 +23,26 @@
3221 #include <string>
3222
3223 #include "graphic/align.h"
3224+#include "graphic/styles/font_style.h"
3225+#include "graphic/styles/panel_styles.h"
3226+#include "graphic/text/rendered_text.h"
3227 #include "graphic/color.h"
3228 #include "graphic/font_handler.h"
3229 #include "graphic/image.h"
3230-#include "graphic/panel_styles.h"
3231 #include "graphic/text/font_set.h"
3232-#include "graphic/text_constants.h"
3233-
3234-/**
3235- * This function replaces some HTML entities in strings, e.g. %nbsp;.
3236- * It is used by the renderers after the tags have been parsed.
3237- */
3238-void replace_entities(std::string* text);
3239-
3240-/**
3241- * Returns the exact width of the text rendered as editorfont for the given font size.
3242- * This function is inefficient; only call when we need the exact width.
3243- */
3244-int text_width(const std::string& text, int ptsize = UI_FONT_SIZE_SMALL);
3245-
3246-/**
3247- * Returns the exact height of the text rendered for the given font size and face.
3248- * This function is inefficient; only call when we need the exact height.
3249- */
3250-int text_height(int ptsize = UI_FONT_SIZE_SMALL, UI::FontSet::Face face = UI::FontSet::Face::kSans);
3251+
3252+/**
3253+ * Returns the exact width of the text rendered as editorfont for the given font size.
3254+ * This function is inefficient; only call when we need the exact width.
3255+ */
3256+int text_width(const std::string& text, const UI::FontStyleInfo& style, float scale = 1.0f);
3257+
3258+/**
3259+ * Returns the exact height of the text rendered for the given font size and face.
3260+ * This function is inefficient; only call when we need the exact height.
3261+ */
3262+int text_height(const UI::FontStyleInfo& style, float scale = 1.0f);
3263+int text_height(UI::FontStyle style, float scale = 1.0f);
3264
3265 /**
3266 * Checks it the given string is RichText or not. Does not do validity checking.
3267@@ -60,42 +56,35 @@
3268 */
3269 std::string richtext_escape(const std::string& given_text);
3270
3271+std::string as_richtext(const std::string&);
3272+
3273 /**
3274 * Convenience functions to convert simple text into a valid block
3275 * of rich text which can be rendered.
3276 */
3277-std::string as_uifont(const std::string&,
3278- int ptsize = UI_FONT_SIZE_SMALL,
3279- const RGBColor& clr = UI_FONT_CLR_FG,
3280- UI::FontSet::Face face = UI::FontSet::Face::kSans);
3281-
3282-// Same as as_aligned, but with the condensed font preselected.
3283-std::string as_condensed(const std::string& text,
3284- UI::Align align = UI::Align::kLeft,
3285- int ptsize = UI_FONT_SIZE_SMALL,
3286- const RGBColor& clr = UI_FONT_CLR_FG);
3287-
3288-std::string as_editorfont(const std::string& text,
3289- int ptsize = UI_FONT_SIZE_SMALL,
3290- const RGBColor& clr = UI_FONT_CLR_FG);
3291-
3292-std::string as_aligned(const std::string& txt,
3293- UI::Align align,
3294- int ptsize = UI_FONT_SIZE_SMALL,
3295- const RGBColor& clr = UI_FONT_CLR_FG,
3296- UI::FontSet::Face face = UI::FontSet::Face::kSans);
3297-
3298-std::string as_listitem(const std::string&,
3299- int ptsize = UI_FONT_SIZE_SMALL,
3300- const RGBColor& clr = UI_FONT_CLR_FG);
3301-
3302-std::string as_richtext(const std::string&);
3303-std::string as_tooltip(const std::string&);
3304-std::string as_waresinfo(const std::string&);
3305+std::string as_richtext_paragraph(const std::string& text, UI::FontStyle style, UI::Align align = UI::Align::kLeft);
3306+std::string as_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style, UI::Align align = UI::Align::kLeft);
3307+std::string as_editor_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style);
3308+
3309+std::string as_listitem(const std::string&, UI::FontStyle style);
3310+
3311 std::string as_game_tip(const std::string&);
3312+/// Format message to player. 'image' is either an image filename or a map object name.
3313+std::string as_mapobject_message(const std::string& image, int width, const std::string& txt, const RGBColor* player_color = nullptr);
3314 std::string as_message(const std::string& heading, const std::string& body);
3315
3316 /**
3317+
3318+ * Render 'text' with the given font style. If 'width' > 0 and the rendered image is too
3319+ * wide, it will first use the condensed font face and then make the text
3320+ * smaller until it fits 'width'. The resulting font size will not go below
3321+ * 'StyleManager::minimum_font_size()'.
3322+ */
3323+std::shared_ptr<const UI::RenderedText> autofit_text(const std::string& text,
3324+ const UI::FontStyleInfo& font_info,
3325+ int width);
3326+
3327+/**
3328 * 'is_first' omits the vertical gap before the line.
3329 * 'noescape' is needed for error message formatting and does not call richtext_escape. */
3330 std::string as_heading_with_content(const std::string& header,
3331@@ -112,24 +101,4 @@
3332 /// Paragraph in menu info texts
3333 std::string as_content(const std::string& txt, UI::PanelStyle style);
3334
3335-/**
3336- * Render 'text' as ui_font. If 'width' > 0 and the rendered image is too
3337- * wide, it will first use the condensed font face and then make the text
3338- * smaller until it fits 'width'. The resulting font size will not go below
3339- * 'kMinimumFontSize'.
3340- */
3341-std::shared_ptr<const UI::RenderedText> autofit_ui_text(const std::string& text,
3342- int width = 0,
3343- RGBColor color = UI_FONT_CLR_FG,
3344- int fontsize = UI_FONT_SIZE_SMALL);
3345-
3346-namespace UI {
3347-
3348-Align mirror_alignment(Align alignment, const std::string& checkme = "");
3349-
3350-void center_vertically(uint32_t h, Vector2i* pt);
3351-void correct_for_align(Align, uint32_t w, Vector2i* pt);
3352-
3353-} // namespace UI
3354-
3355 #endif // end of include guard: WL_GRAPHIC_TEXT_LAYOUT_H
3356
3357=== modified file 'src/graphic/wordwrap.cc'
3358--- src/graphic/wordwrap.cc 2019-02-23 11:00:49 +0000
3359+++ src/graphic/wordwrap.cc 2019-05-26 02:00:17 +0000
3360@@ -36,6 +36,30 @@
3361 #include "graphic/text/font_io.h"
3362 #include "graphic/text_layout.h"
3363
3364+namespace {
3365+std::string as_editorfont(const std::string& text, int ptsize, const RGBColor& clr) {
3366+ // UI Text is always bold due to historic reasons
3367+ static boost::format f(
3368+ "<rt keep_spaces=1><p><font face=sans size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
3369+ f % ptsize;
3370+ f % clr.hex_value();
3371+ f % richtext_escape(text);
3372+ return f.str();
3373+}
3374+
3375+int text_width(const std::string& text, int ptsize) {
3376+ RGBColor color(0, 0, 0);
3377+ return UI::g_fh->render(as_editorfont(text, ptsize - UI::g_fh->fontset()->size_offset(), color))
3378+ ->width();
3379+}
3380+
3381+int text_height(int ptsize) {
3382+ RGBColor font_color(0, 0, 0);
3383+ const UI::FontStyleInfo font_info("sans", font_color, ptsize, false, false, false, false);
3384+ return UI::g_fh->render(as_richtext_paragraph(UI::g_fh->fontset()->representative_character(), font_info))->height();
3385+}
3386+} // namespace
3387+
3388 namespace UI {
3389
3390 WordWrap::WordWrap(int fontsize, const RGBColor& color, uint32_t gwrapwidth)
3391@@ -299,7 +323,7 @@
3392
3393 ++where.y;
3394
3395- Align alignment = mirror_alignment(align);
3396+ Align alignment = mirror_alignment(align, g_fh->fontset()->is_rtl());
3397
3398 const int fontheight = text_height(fontsize_);
3399 for (uint32_t line = 0; line < lines_.size(); ++line, where.y += fontheight) {
3400
3401=== modified file 'src/graphic/wordwrap.h'
3402--- src/graphic/wordwrap.h 2019-02-23 11:00:49 +0000
3403+++ src/graphic/wordwrap.h 2019-05-26 02:00:17 +0000
3404@@ -27,8 +27,8 @@
3405 #include "base/vector.h"
3406 #include "graphic/align.h"
3407 #include "graphic/color.h"
3408+#include "graphic/graphic.h"
3409 #include "graphic/text/sdl_ttf_font.h"
3410-#include "graphic/text_constants.h"
3411
3412 class RenderTarget;
3413
3414@@ -38,9 +38,9 @@
3415 * Helper struct that provides word wrapping and related functionality.
3416 */
3417 struct WordWrap {
3418- WordWrap(int fontsize = UI_FONT_SIZE_SMALL,
3419- const RGBColor& color = UI_FONT_CLR_FG,
3420- uint32_t wrapwidth = std::numeric_limits<uint32_t>::max());
3421+ static constexpr int kLineMargin = 1;
3422+
3423+ explicit WordWrap(int fontsize, const RGBColor& color, uint32_t wrapwidth);
3424
3425 void set_wrapwidth(uint32_t wrapwidth);
3426
3427
3428=== modified file 'src/io/filesystem/filesystem.cc'
3429--- src/io/filesystem/filesystem.cc 2019-02-23 11:00:49 +0000
3430+++ src/io/filesystem/filesystem.cc 2019-05-26 02:00:17 +0000
3431@@ -205,7 +205,7 @@
3432 (boost::format(pgettext("illegal_filename_characters", "%s at the start of the filename")) %
3433 richtext_escape(i18n::localize_list(starting_characters, i18n::ConcatenateWith::OR)))
3434 .str(),
3435- UI_FONT_SIZE_MESSAGE));
3436+ UI::FontStyle::kWuiMessageParagraph));
3437
3438 const std::string illegal(as_listitem(
3439 /** TRANSLATORS: Tooltip entry for characters in illegal filenames.
3440@@ -213,7 +213,7 @@
3441 (boost::format(pgettext("illegal_filename_characters", "%s anywhere in the filename")) %
3442 richtext_escape(i18n::localize_list(illegal_filename_characters, i18n::ConcatenateWith::OR)))
3443 .str(),
3444- UI_FONT_SIZE_MESSAGE));
3445+ UI::FontStyle::kWuiMessageParagraph));
3446
3447 return (boost::format("%s%s%s") %
3448 /** TRANSLATORS: Tooltip header for characters in illegal filenames.
3449
3450=== modified file 'src/logic/map_objects/CMakeLists.txt'
3451--- src/logic/map_objects/CMakeLists.txt 2019-05-05 18:53:14 +0000
3452+++ src/logic/map_objects/CMakeLists.txt 2019-05-26 02:00:17 +0000
3453@@ -125,7 +125,6 @@
3454 graphic_fonthandler
3455 graphic_image_io
3456 graphic_surface
3457- graphic_text_constants
3458 graphic_text_layout
3459 helper
3460 io_fileread
3461
3462=== modified file 'src/logic/map_objects/immovable.cc'
3463--- src/logic/map_objects/immovable.cc 2019-05-19 12:25:24 +0000
3464+++ src/logic/map_objects/immovable.cc 2019-05-26 02:00:17 +0000
3465@@ -32,7 +32,6 @@
3466 #include "config.h"
3467 #include "graphic/graphic.h"
3468 #include "graphic/rendertarget.h"
3469-#include "graphic/text_constants.h"
3470 #include "helper.h"
3471 #include "io/fileread.h"
3472 #include "io/filewrite.h"
3473@@ -526,9 +525,7 @@
3474
3475 // Additionally, if statistics are enabled, draw a progression string
3476 do_draw_info(draw_text, descr().descname(),
3477- (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
3478- (boost::format(_("%i%% built")) % (100 * done / total)).str())
3479- .str(),
3480+ g_gr->styles().color_tag((boost::format(_("%i%% built")) % (100 * done / total)).str(), g_gr->styles().building_statistics_style().construction_color()),
3481 point_on_dst, scale, dst);
3482 }
3483
3484
3485=== modified file 'src/logic/map_objects/map_object.cc'
3486--- src/logic/map_objects/map_object.cc 2019-05-18 20:43:25 +0000
3487+++ src/logic/map_objects/map_object.cc 2019-05-26 02:00:17 +0000
3488@@ -32,6 +32,7 @@
3489 #include "graphic/font_handler.h"
3490 #include "graphic/graphic.h"
3491 #include "graphic/rendertarget.h"
3492+#include "graphic/style_manager.h"
3493 #include "graphic/text_layout.h"
3494 #include "io/fileread.h"
3495 #include "io/filewrite.h"
3496@@ -485,20 +486,25 @@
3497 if (scale < 1.f) {
3498 return;
3499 }
3500- const int font_size = scale * UI_FONT_SIZE_SMALL;
3501+
3502+ UI::FontStyleInfo census_font(g_gr->styles().building_statistics_style().census_font());
3503+ census_font.set_size(scale * census_font.size());
3504
3505 // We always render this so we can have a stable position for the statistics string.
3506 std::shared_ptr<const UI::RenderedText> rendered_census =
3507- UI::g_fh->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);
3508+ UI::g_fh->render(as_richtext_paragraph(census, census_font, UI::Align::kCenter), 120 * scale);
3509 Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;
3510 if ((draw_text & TextToDraw::kCensus) != TextToDraw::kNone) {
3511 rendered_census->draw(*dst, position, UI::Align::kCenter);
3512 }
3513
3514 if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone && !statictics.empty()) {
3515+ UI::FontStyleInfo statistics_font(g_gr->styles().building_statistics_style().statistics_font());
3516+ statistics_font.set_size(scale * statistics_font.size());
3517+
3518 std::shared_ptr<const UI::RenderedText> rendered_statistics =
3519- UI::g_fh->render(as_condensed(statictics, UI::Align::kCenter, font_size));
3520- position.y += rendered_census->height() + text_height(font_size) / 4;
3521+ UI::g_fh->render(as_richtext_paragraph(statictics, statistics_font, UI::Align::kCenter));
3522+ position.y += rendered_census->height() + text_height(statistics_font) / 4;
3523 rendered_statistics->draw(*dst, position, UI::Align::kCenter);
3524 }
3525 }
3526
3527=== modified file 'src/logic/map_objects/tribes/building.cc'
3528--- src/logic/map_objects/tribes/building.cc 2019-05-11 13:48:12 +0000
3529+++ src/logic/map_objects/tribes/building.cc 2019-05-26 02:00:17 +0000
3530@@ -33,7 +33,7 @@
3531 #include "economy/input_queue.h"
3532 #include "economy/request.h"
3533 #include "graphic/rendertarget.h"
3534-#include "graphic/text_constants.h"
3535+#include "graphic/text_layout.h"
3536 #include "io/filesystem/filesystem.h"
3537 #include "io/filesystem/layered_filesystem.h"
3538 #include "logic/game.h"
3539@@ -774,10 +774,10 @@
3540 uint32_t throttle_time,
3541 uint32_t throttle_radius) {
3542 const std::string rt_description =
3543- (boost::format("<div padding_r=10><p><img object=%s color=%s></p></div>"
3544- "<div width=*><p><font size=%d>%s</font></p></div>") %
3545- descr().name() % owner().get_playercolor().hex_value() % UI_FONT_SIZE_MESSAGE % description)
3546- .str();
3547+ as_mapobject_message(descr().name(),
3548+ descr().representative_image()->width(),
3549+ description,
3550+ &owner().get_playercolor());
3551
3552 std::unique_ptr<Message> msg(new Message(msgtype, game.get_gametime(), title, icon_filename,
3553 heading, rt_description, get_position(),
3554
3555=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
3556--- src/logic/map_objects/tribes/constructionsite.cc 2019-05-18 20:43:25 +0000
3557+++ src/logic/map_objects/tribes/constructionsite.cc 2019-05-26 02:00:17 +0000
3558@@ -30,7 +30,6 @@
3559 #include "graphic/animation.h"
3560 #include "graphic/graphic.h"
3561 #include "graphic/rendertarget.h"
3562-#include "graphic/text_constants.h"
3563 #include "logic/editor_game_base.h"
3564 #include "logic/game.h"
3565 #include "logic/map_objects/tribes/tribe_descr.h"
3566@@ -110,9 +109,7 @@
3567
3568 void ConstructionSite::update_statistics_string(std::string* s) {
3569 unsigned int percent = (get_built_per64k() * 100) >> 16;
3570- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
3571- (boost::format(_("%i%% built")) % percent))
3572- .str();
3573+ *s = g_gr->styles().color_tag((boost::format(_("%i%% built")) % percent).str(), g_gr->styles().building_statistics_style().construction_color());
3574 }
3575
3576 /*
3577
3578=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
3579--- src/logic/map_objects/tribes/dismantlesite.cc 2019-05-18 20:43:25 +0000
3580+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-05-26 02:00:17 +0000
3581@@ -29,7 +29,6 @@
3582 #include "economy/wares_queue.h"
3583 #include "graphic/animation.h"
3584 #include "graphic/rendertarget.h"
3585-#include "graphic/text_constants.h"
3586 #include "logic/editor_game_base.h"
3587 #include "logic/game.h"
3588 #include "logic/map_objects/tribes/tribe_descr.h"
3589@@ -103,9 +102,7 @@
3590 */
3591 void DismantleSite::update_statistics_string(std::string* s) {
3592 unsigned int percent = (get_built_per64k() * 100) >> 16;
3593- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
3594- (boost::format(_("%u%% dismantled")) % percent))
3595- .str();
3596+ *s = g_gr->styles().color_tag((boost::format(_("%u%% dismantled")) % percent).str(), g_gr->styles().building_statistics_style().construction_color());
3597 }
3598
3599 /*
3600
3601=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
3602--- src/logic/map_objects/tribes/militarysite.cc 2019-05-18 20:43:25 +0000
3603+++ src/logic/map_objects/tribes/militarysite.cc 2019-05-26 02:00:17 +0000
3604@@ -30,7 +30,6 @@
3605 #include "base/macros.h"
3606 #include "economy/flag.h"
3607 #include "economy/request.h"
3608-#include "graphic/text_constants.h"
3609 #include "logic/editor_game_base.h"
3610 #include "logic/game.h"
3611 #include "logic/map_objects/findbob.h"
3612@@ -396,10 +395,9 @@
3613 .str();
3614 }
3615 }
3616- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %
3617- // Line break to make Codecheck happy.
3618- *s)
3619- .str();
3620+ *s = g_gr->styles().color_tag(
3621+ // Line break to make Codecheck happy.
3622+ *s, g_gr->styles().building_statistics_style().medium_color());
3623 }
3624
3625 bool MilitarySite::init(EditorGameBase& egbase) {
3626
3627=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
3628--- src/logic/map_objects/tribes/productionsite.cc 2019-05-22 15:46:08 +0000
3629+++ src/logic/map_objects/tribes/productionsite.cc 2019-05-26 02:00:17 +0000
3630@@ -32,7 +32,6 @@
3631 #include "economy/ware_instance.h"
3632 #include "economy/wares_queue.h"
3633 #include "economy/workers_queue.h"
3634-#include "graphic/text_constants.h"
3635 #include "logic/editor_game_base.h"
3636 #include "logic/game.h"
3637 #include "logic/game_data_error.h"
3638@@ -296,28 +295,23 @@
3639 nr_workers += working_positions_[--i].worker ? 1 : 0;
3640
3641 if (nr_workers == 0) {
3642- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BAD.hex_value() %
3643- _("(not occupied)"))
3644- .str();
3645+ *s = g_gr->styles().color_tag(_("(not occupied)"), g_gr->styles().building_statistics_style().low_color());
3646 return;
3647 }
3648
3649 if (uint32_t const nr_requests = nr_working_positions - nr_workers) {
3650- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BAD.hex_value() %
3651+ *s = g_gr->styles().color_tag(
3652 (nr_requests == 1 ?
3653 /** TRANSLATORS: Productivity label on a building if there is 1 worker missing */
3654 _("Worker missing") :
3655 /** TRANSLATORS: Productivity label on a building if there is more than 1 worker
3656 missing. If you need plural forms here, please let us know. */
3657- _("Workers missing")))
3658- .str();
3659+ _("Workers missing")), g_gr->styles().building_statistics_style().low_color());
3660 return;
3661 }
3662
3663 if (is_stopped_) {
3664- *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BRIGHT.hex_value() %
3665- _("(stopped)"))
3666- .str();
3667+ *s = g_gr->styles().color_tag(_("(stopped)"), g_gr->styles().building_statistics_style().neutral_color());
3668 return;
3669 }
3670 *s = statistics_string_on_changed_statistics_;
3671@@ -407,34 +401,32 @@
3672
3673 const unsigned int lastPercOk = (lastOk * 100) / (STATISTICS_VECTOR_LENGTH / 2);
3674
3675- std::string color;
3676- if (percOk < 33)
3677- color = UI_FONT_CLR_BAD.hex_value();
3678- else if (percOk < 66)
3679- color = UI_FONT_CLR_OK.hex_value();
3680- else
3681- color = UI_FONT_CLR_GOOD.hex_value();
3682 const std::string perc_str =
3683- (boost::format("<font color=%s>%s</font>") % color % (boost::format(_("%i%%")) % percOk))
3684- .str();
3685-
3686- std::string trend;
3687- if (lastPercOk > percOk) {
3688- trend_ = Trend::kRising;
3689- color = UI_FONT_CLR_GOOD.hex_value();
3690- trend = "+";
3691- } else if (lastPercOk < percOk) {
3692- trend_ = Trend::kFalling;
3693- color = UI_FONT_CLR_BAD.hex_value();
3694- trend = "-";
3695- } else {
3696- trend_ = Trend::kUnchanged;
3697- color = UI_FONT_CLR_BRIGHT.hex_value();
3698- trend = "=";
3699- }
3700- const std::string trend_str = (boost::format("<font color=%s>%s</font>") % color % trend).str();
3701+ g_gr->styles().color_tag((boost::format(_("%i%%")) % percOk).str(),
3702+ (percOk < 33) ? g_gr->styles().building_statistics_style().low_color() :
3703+ (percOk < 66) ?
3704+ g_gr->styles().building_statistics_style().medium_color() :
3705+ g_gr->styles().building_statistics_style().high_color());
3706
3707 if (0 < percOk && percOk < 100) {
3708+ RGBColor color = g_gr->styles().building_statistics_style().high_color();
3709+ std::string trend;
3710+ if (lastPercOk > percOk) {
3711+ trend_ = Trend::kRising;
3712+ color = g_gr->styles().building_statistics_style().high_color();
3713+ trend = "+";
3714+ } else if (lastPercOk < percOk) {
3715+ trend_ = Trend::kFalling;
3716+ color = g_gr->styles().building_statistics_style().low_color();
3717+ trend = "-";
3718+ } else {
3719+ trend_ = Trend::kUnchanged;
3720+ color = g_gr->styles().building_statistics_style().neutral_color();
3721+ trend = "=";
3722+ }
3723+
3724+ const std::string trend_str = g_gr->styles().color_tag((boost::format(_("%i%%")) % trend).str(), color);
3725+
3726 // TODO(GunChleoc): We might need to reverse the order here for RTL languages
3727 statistics_string_on_changed_statistics_ =
3728 (boost::format("%s\u2009%s") % perc_str % trend_str).str();
3729
3730=== modified file 'src/logic/map_objects/tribes/ship.cc'
3731--- src/logic/map_objects/tribes/ship.cc 2019-05-11 13:48:12 +0000
3732+++ src/logic/map_objects/tribes/ship.cc 2019-05-26 02:00:17 +0000
3733@@ -31,7 +31,7 @@
3734 #include "economy/portdock.h"
3735 #include "economy/wares_queue.h"
3736 #include "graphic/rendertarget.h"
3737-#include "graphic/text_constants.h"
3738+#include "graphic/text_layout.h"
3739 #include "io/fileread.h"
3740 #include "io/filewrite.h"
3741 #include "logic/game.h"
3742@@ -1061,9 +1061,7 @@
3743 case (ShipStates::kSinkAnimation):
3744 break;
3745 }
3746- statistics_string = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %
3747- statistics_string)
3748- .str();
3749+ statistics_string = g_gr->styles().color_tag(statistics_string, g_gr->styles().building_statistics_style().medium_color());
3750 }
3751
3752 do_draw_info(draw_text, shipname_, statistics_string, calc_drawpos(egbase, point_on_dst, scale),
3753@@ -1128,10 +1126,7 @@
3754 const std::string& description,
3755 const std::string& picture) {
3756 const std::string rt_description =
3757- (boost::format("<div padding_r=10><p><img src=%s></p></div>"
3758- "<div width=*><p><font size=%d>%s</font></p></div>") %
3759- picture % UI_FONT_SIZE_MESSAGE % description)
3760- .str();
3761+ as_mapobject_message(picture, g_gr->images().get(picture)->width(), description);
3762
3763 get_owner()->add_message(game, std::unique_ptr<Message>(new Message(
3764 Message::Type::kSeafaring, game.get_gametime(), title, picture,
3765
3766=== modified file 'src/logic/map_objects/tribes/worker.cc'
3767--- src/logic/map_objects/tribes/worker.cc 2019-05-25 10:47:18 +0000
3768+++ src/logic/map_objects/tribes/worker.cc 2019-05-26 02:00:17 +0000
3769@@ -33,8 +33,9 @@
3770 #include "economy/portdock.h"
3771 #include "economy/road.h"
3772 #include "economy/transfer.h"
3773+#include "graphic/graphic.h"
3774 #include "graphic/rendertarget.h"
3775-#include "graphic/text_constants.h"
3776+#include "graphic/text_layout.h"
3777 #include "helper.h"
3778 #include "io/fileread.h"
3779 #include "io/filewrite.h"
3780@@ -972,12 +973,12 @@
3781 MapObjectDescr::OwnerType::kTribe, get_owner());
3782
3783 // Geologist also sends a message notifying the player
3784+ // TODO(GunChleoc): We keep formatting this even when timeout has not elapsed
3785 if (rdescr && rdescr->detectable() && position.field->get_resources_amount()) {
3786- const std::string message =
3787- (boost::format("<div padding_r=10><p><img object=%s></p></div>"
3788- "<div width=*><p><font size=%d>%s</font></p></div>") %
3789- ri.descr().name() % UI_FONT_SIZE_MESSAGE % _("A geologist found resources."))
3790- .str();
3791+ const std::string rt_description =
3792+ as_mapobject_message(ri.descr().name(),
3793+ g_gr->images().get(rdescr->representative_image())->width(),
3794+ _("A geologist found resources."));
3795
3796 // We should add a message to the player's message queue - but only,
3797 // if there is not already a similar one in list.
3798@@ -985,7 +986,7 @@
3799 game,
3800 std::unique_ptr<Message>(new Message(Message::Type::kGeologists, game.get_gametime(),
3801 rdescr->descname(), rdescr->representative_image(),
3802- ri.descr().descname(), message, position, serial_,
3803+ ri.descr().descname(), rt_description, position, serial_,
3804 rdescr->name())),
3805 rdescr->timeout_ms(), rdescr->timeout_radius());
3806 }
3807
3808=== modified file 'src/ui_basic/CMakeLists.txt'
3809--- src/ui_basic/CMakeLists.txt 2019-04-09 04:51:44 +0000
3810+++ src/ui_basic/CMakeLists.txt 2019-05-26 02:00:17 +0000
3811@@ -67,7 +67,6 @@
3812 graphic_styles
3813 graphic_surface
3814 graphic_text
3815- graphic_text_constants
3816 graphic_text_layout
3817 graphic_wordwrap
3818 io_filesystem
3819
3820=== modified file 'src/ui_basic/button.cc'
3821--- src/ui_basic/button.cc 2019-02-23 11:00:49 +0000
3822+++ src/ui_basic/button.cc 2019-05-26 02:00:17 +0000
3823@@ -24,7 +24,6 @@
3824 #include "graphic/image.h"
3825 #include "graphic/rendertarget.h"
3826 #include "graphic/style_manager.h"
3827-#include "graphic/text_constants.h"
3828 #include "graphic/text_layout.h"
3829 #include "ui_basic/mouse_constants.h"
3830
3831@@ -58,7 +57,7 @@
3832 time_nextact_(0),
3833 title_(title_text),
3834 title_image_(title_image),
3835- background_style_(g_gr->styles().button_style(init_style)) {
3836+ style_(&g_gr->styles().button_style(init_style)) {
3837 set_thinks(false);
3838 // Don't allow focus
3839 assert(!get_can_focus());
3840@@ -89,7 +88,7 @@
3841 UI::Button::ImageMode::kShrink) {
3842 // Automatically resize for font height and give it a margin.
3843 if (h < 1) {
3844- int new_height = text_height() + 4;
3845+ const int new_height = text_height(g_gr->styles().button_style(init_style).enabled().font()) + 4;
3846 set_desired_size(w, new_height);
3847 set_size(w, new_height);
3848 }
3849@@ -170,8 +169,10 @@
3850 const bool is_monochrome =
3851 !enabled_ && static_cast<int>(disable_style_ & ButtonDisableStyle::kMonochrome);
3852
3853+ const UI::TextPanelStyleInfo& style_to_use = is_monochrome ? style_->disabled() : style_->enabled();
3854+
3855 // Draw the background
3856- draw_background(dst, *background_style_);
3857+ draw_background(dst, style_to_use.background());
3858
3859 if (is_flat && highlighted_)
3860 dst.brighten_rect(Recti(0, 0, get_w(), get_h()), MOUSE_OVER_BRIGHT_FACTOR);
3861@@ -216,8 +217,11 @@
3862 } else if (title_.length()) {
3863 // Otherwise draw title string centered
3864 std::shared_ptr<const UI::RenderedText> rendered_text =
3865- autofit_ui_text(title_, get_inner_w() - 2 * kButtonImageMargin,
3866- is_monochrome ? UI_FONT_CLR_DISABLED : UI_FONT_CLR_FG);
3867+ autofit_text(
3868+ richtext_escape(title_),
3869+ style_to_use.font(),
3870+ get_inner_w() - 2 * kButtonImageMargin);
3871+
3872 // Blit on pixel boundary (not float), so that the text is blitted pixel perfect.
3873 rendered_text->draw(dst, Vector2i((get_w() - rendered_text->width()) / 2,
3874 (get_h() - rendered_text->height()) / 2));
3875@@ -363,8 +367,8 @@
3876 UI::Button::VisualState::kRaised);
3877 }
3878
3879-void Button::set_background_style(UI::ButtonStyle bstyle) {
3880- background_style_ = g_gr->styles().button_style(bstyle);
3881+void Button::set_style(UI::ButtonStyle bstyle) {
3882+ style_ = &g_gr->styles().button_style(bstyle);
3883 }
3884
3885 void Button::toggle() {
3886
3887=== modified file 'src/ui_basic/button.h'
3888--- src/ui_basic/button.h 2019-02-23 11:00:49 +0000
3889+++ src/ui_basic/button.h 2019-05-26 02:00:17 +0000
3890@@ -25,7 +25,7 @@
3891 #include <boost/signals2.hpp>
3892
3893 #include "graphic/color.h"
3894-#include "graphic/text_layout.h"
3895+#include "graphic/styles/button_style.h"
3896 #include "ui_basic/panel.h"
3897
3898 namespace UI {
3899@@ -146,7 +146,7 @@
3900 void set_perm_pressed(bool pressed);
3901
3902 /// Change the background style of the button.
3903- void set_background_style(UI::ButtonStyle bstyle);
3904+ void set_style(UI::ButtonStyle bstyle);
3905
3906 /// Convenience function. Toggles between raised and permpressed style
3907 void toggle();
3908@@ -172,7 +172,7 @@
3909 std::string title_; // title string used when title_image_ == nullptr
3910 const Image* title_image_; // custom icon on the button
3911
3912- const UI::PanelStyleInfo* background_style_; // Background color and texture. Not owned.
3913+ const UI::ButtonStyleInfo* style_; // Background color and texture. Not owned.
3914 };
3915
3916 } // namespace UI
3917
3918=== modified file 'src/ui_basic/checkbox.cc'
3919--- src/ui_basic/checkbox.cc 2019-02-23 11:00:49 +0000
3920+++ src/ui_basic/checkbox.cc 2019-05-26 02:00:17 +0000
3921@@ -80,7 +80,7 @@
3922 }
3923 rendered_text_ = label_text_.empty() ?
3924 nullptr :
3925- UI::g_fh->render(as_uifont(label_text_), text_width(get_w(), pic_width));
3926+ UI::g_fh->render(as_richtext_paragraph(label_text_, UI::FontStyle::kLabel), text_width(get_w(), pic_width));
3927 if (rendered_text_.get()) {
3928 w = std::max(rendered_text_->width() + kPadding + pic_width, w);
3929 h = std::max(rendered_text_->height(), h);
3930
3931=== modified file 'src/ui_basic/dropdown.cc'
3932--- src/ui_basic/dropdown.cc 2019-02-23 11:00:49 +0000
3933+++ src/ui_basic/dropdown.cc 2019-05-26 02:00:17 +0000
3934@@ -29,18 +29,25 @@
3935 #include "graphic/font_handler.h"
3936 #include "graphic/graphic.h"
3937 #include "graphic/rendertarget.h"
3938+#include "graphic/text_layout.h"
3939 #include "ui_basic/mouse_constants.h"
3940 #include "ui_basic/tabpanel.h"
3941 #include "ui_basic/window.h"
3942
3943 namespace {
3944-
3945-int base_height(int button_dimension) {
3946- return std::max(
3947+int base_height(int button_dimension, UI::PanelStyle style) {
3948+ int result = std::max(
3949 button_dimension,
3950- UI::g_fh->render(as_uifont(UI::g_fh->fontset()->representative_character()))->height() + 2);
3951-}
3952-
3953+ text_height(g_gr->styles().table_style(style).enabled()) + 2);
3954+ return result;
3955+}
3956+
3957+
3958+/*
3959+int BaseDropdown::base_height(int button_dimension) const {
3960+ return std::max(button_dimension, text_height(g_gr->styles().table_style(UI::PanelStyle::kWui).enabled()) + 2);
3961+}
3962+*/
3963 } // namespace
3964
3965 namespace UI {
3966@@ -61,13 +68,14 @@
3967 y,
3968 type == DropdownType::kPictorial ? button_dimension : w,
3969 // Height only to fit the button, so we can use this in Box layout.
3970- base_height(button_dimension)),
3971+ base_height(button_dimension, style)),
3972 id_(next_id_++),
3973 max_list_height_(h - 2 * get_h()),
3974 list_width_(w),
3975 list_offset_x_(0),
3976 list_offset_y_(0),
3977 button_dimension_(button_dimension),
3978+ base_height_(base_height(button_dimension, style)),
3979 mouse_tolerance_(50),
3980 button_box_(this, 0, 0, UI::Box::Horizontal, w, h),
3981 push_button_(type == DropdownType::kTextual ?
3982@@ -154,16 +162,16 @@
3983 }
3984
3985 void BaseDropdown::set_height(int height) {
3986- max_list_height_ = height - base_height(button_dimension_);
3987+ max_list_height_ = height - base_height_;
3988 layout();
3989 }
3990
3991 void BaseDropdown::set_max_items(int items) {
3992- set_height(list_->get_lineheight() * items + base_height(button_dimension_));
3993+ set_height(list_->get_lineheight() * items + base_height_);
3994 }
3995
3996 void BaseDropdown::layout() {
3997- const int base_h = base_height(button_dimension_);
3998+ const int base_h = base_height_;
3999 const int w = type_ == DropdownType::kPictorial ? button_dimension_ : get_w();
4000 button_box_.set_size(w, base_h);
4001 display_button_.set_desired_size(
4002
4003=== modified file 'src/ui_basic/dropdown.h'
4004--- src/ui_basic/dropdown.h 2019-02-23 11:00:49 +0000
4005+++ src/ui_basic/dropdown.h 2019-05-26 02:00:17 +0000
4006@@ -179,7 +179,8 @@
4007 int list_width_;
4008 int list_offset_x_;
4009 int list_offset_y_;
4010- int button_dimension_;
4011+ const int button_dimension_;
4012+ const int base_height_;
4013 const int mouse_tolerance_; // Allow mouse outside the panel a bit before autocollapse
4014 UI::Box button_box_;
4015 UI::Button* push_button_; // Only used in textual dropdowns
4016
4017=== modified file 'src/ui_basic/editbox.cc'
4018--- src/ui_basic/editbox.cc 2019-05-25 08:25:55 +0000
4019+++ src/ui_basic/editbox.cc 2019-05-26 02:00:17 +0000
4020@@ -34,7 +34,6 @@
4021 #include "graphic/text/bidi.h"
4022 #include "graphic/text/font_set.h"
4023 #include "graphic/text/rt_errors.h"
4024-#include "graphic/text_constants.h"
4025 #include "graphic/text_layout.h"
4026 #include "ui_basic/mouse_constants.h"
4027
4028@@ -43,23 +42,30 @@
4029 namespace {
4030
4031 constexpr int kMarginX = 4;
4032+constexpr int kLineMargin = 1;
4033
4034 } // namespace
4035
4036 namespace UI {
4037
4038 struct EditBoxImpl {
4039- /**
4040- * Font used for rendering text.
4041- */
4042- /*@{*/
4043- std::string fontname;
4044- uint32_t fontsize;
4045- /*@}*/
4046+ explicit EditBoxImpl(const UI::TextPanelStyleInfo& init_style) :
4047+ background_style(&init_style.background()), font_style(&init_style.font()),
4048+ margin(init_style.background().margin()), font_scale(1.0f) {
4049+ }
4050
4051 /// Background color and texture
4052 const UI::PanelStyleInfo* background_style;
4053
4054+ /// Font style
4055+ const UI::FontStyleInfo* font_style;
4056+
4057+ /// Margin around the test
4058+ int margin;
4059+
4060+ /// Scale for font size
4061+ float font_scale;
4062+
4063 /// Maximum number of characters in the input
4064 uint32_t maxLength;
4065
4066@@ -80,22 +86,17 @@
4067 int32_t x,
4068 int32_t y,
4069 uint32_t w,
4070- uint32_t h,
4071- int margin_y,
4072- UI::PanelStyle style,
4073- int font_size)
4074- : Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),
4075- m_(new EditBoxImpl),
4076+ UI::PanelStyle style)
4077+ : Panel(parent, x, y, w,
4078+ text_height(g_gr->styles().editbox_style(style).font())
4079+ + 2 * g_gr->styles().editbox_style(style).background().margin()),
4080+ m_(new EditBoxImpl(g_gr->styles().editbox_style(style))),
4081 history_active_(false),
4082 history_position_(-1),
4083 password_(false),
4084 warning_(false) {
4085 set_thinks(false);
4086
4087- m_->background_style = g_gr->styles().editbox_style(style);
4088- m_->fontname = UI::g_fh->fontset()->sans();
4089- m_->fontsize = font_size;
4090-
4091 // Set alignment to the UI language's principal writing direction
4092 m_->align = UI::g_fh->fontset()->is_rtl() ? UI::Align::kRight : UI::Align::kLeft;
4093 m_->caret = 0;
4094@@ -103,6 +104,7 @@
4095 // yes, use *signed* max as maximum length; just a small safe-guard.
4096 set_max_length(std::numeric_limits<int32_t>::max());
4097
4098+ set_thinks(false);
4099 set_handle_mouse(true);
4100 set_can_focus(true);
4101 set_handle_textinput();
4102@@ -148,9 +150,9 @@
4103 * If the current string is longer than the new maximum length,
4104 * its end is cut off to fit into the maximum length.
4105 */
4106-void EditBox::set_max_length(uint32_t const n) {
4107+void EditBox::set_max_length(int const n) {
4108 m_->maxLength =
4109- std::min(g_gr->max_texture_size_for_font_rendering() / text_height(), static_cast<int>(n));
4110+ std::min(g_gr->max_texture_size_for_font_rendering() / text_height(*m_->font_style), n);
4111
4112 if (m_->text.size() > m_->maxLength) {
4113 m_->text.erase(m_->text.begin() + m_->maxLength, m_->text.end());
4114@@ -161,6 +163,22 @@
4115 }
4116 }
4117
4118+void EditBox::set_font_scale(float scale) {
4119+ m_->font_scale = scale;
4120+}
4121+
4122+void EditBox::set_font_style(const UI::FontStyleInfo& style) {
4123+ m_->font_style = &style;
4124+ const int new_height = text_height(style) + 2 * m_->margin;
4125+ set_size(get_w(), new_height);
4126+ set_desired_size(get_w(), new_height);
4127+}
4128+
4129+void EditBox::set_font_style_and_margin(const UI::FontStyleInfo& style, int margin) {
4130+ m_->margin = margin;
4131+ set_font_style(style);
4132+}
4133+
4134 /**
4135 * The mouse was clicked on this editbox
4136 */
4137@@ -389,12 +407,13 @@
4138 }
4139
4140 const int max_width = get_w() - 2 * kMarginX;
4141-
4142+ FontStyleInfo scaled_style(*m_->font_style);
4143+ scaled_style.set_size(scaled_style.size() * m_->font_scale);
4144 std::shared_ptr<const UI::RenderedText> rendered_text =
4145- UI::g_fh->render(as_editorfont(m_->text, m_->fontsize));
4146+ UI::g_fh->render(as_editor_richtext_paragraph(password_ ? text_to_asterisk() : m_->text, scaled_style));
4147
4148 const int linewidth = rendered_text->width();
4149- const int lineheight = m_->text.empty() ? text_height(m_->fontsize) : rendered_text->height();
4150+ const int lineheight = m_->text.empty() ? text_height(scaled_style) : rendered_text->height();
4151
4152 Vector2i point(kMarginX, get_h() / 2);
4153 if (m_->align == UI::Align::kRight) {
4154@@ -403,33 +422,27 @@
4155 UI::center_vertically(lineheight, &point);
4156
4157 // Crop to max_width while blitting
4158- if (!password_) {
4159- if (max_width < linewidth) {
4160- // Fix positioning for BiDi languages.
4161- if (UI::g_fh->fontset()->is_rtl()) {
4162- point.x = 0.f;
4163- }
4164- // We want this always on, e.g. for mixed language savegame filenames
4165- if (i18n::has_rtl_character(m_->text.c_str(), 100)) { // Restrict check for efficiency
4166+ if (max_width < linewidth) {
4167+ // Fix positioning for BiDi languages.
4168+ if (UI::g_fh->fontset()->is_rtl()) {
4169+ point.x = 0.f;
4170+ }
4171+ // We want this always on, e.g. for mixed language savegame filenames
4172+ if (i18n::has_rtl_character(m_->text.c_str(), 100)) { // Restrict check for efficiency
4173+ // TODO(GunChleoc): Arabic: Fix scrolloffset
4174+ rendered_text->draw(dst, point, Recti(linewidth - max_width, 0, linewidth, lineheight));
4175+ } else {
4176+ if (m_->align == UI::Align::kRight) {
4177 // TODO(GunChleoc): Arabic: Fix scrolloffset
4178- rendered_text->draw(dst, point, Recti(linewidth - max_width, 0, linewidth, lineheight));
4179+ rendered_text->draw(
4180+ dst, point,
4181+ Recti(point.x + m_->scrolloffset + kMarginX, 0, max_width, lineheight));
4182 } else {
4183- if (m_->align == UI::Align::kRight) {
4184- // TODO(GunChleoc): Arabic: Fix scrolloffset
4185- rendered_text->draw(
4186- dst, point,
4187- Recti(point.x + m_->scrolloffset + kMarginX, 0, max_width, lineheight));
4188- } else {
4189- rendered_text->draw(dst, point, Recti(-m_->scrolloffset, 0, max_width, lineheight));
4190- }
4191+ rendered_text->draw(dst, point, Recti(-m_->scrolloffset, 0, max_width, lineheight));
4192 }
4193- } else {
4194- rendered_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
4195 }
4196 } else {
4197- std::shared_ptr<const UI::RenderedText> password_text =
4198- UI::g_fh->render(as_editorfont(text_to_asterisk(), m_->fontsize));
4199- password_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
4200+ rendered_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
4201 }
4202
4203 if (has_focus()) {
4204@@ -443,9 +456,9 @@
4205 }
4206
4207 // TODO(GunChleoc): Arabic: Fix cursor position for BIDI text.
4208- int caret_x = text_width(line_to_caret, m_->fontsize);
4209+ int caret_x = text_width(line_to_caret, *m_->font_style, m_->font_scale);
4210
4211- const uint16_t fontheight = text_height(m_->fontsize);
4212+ const uint16_t fontheight = text_height(*m_->font_style, m_->font_scale);
4213
4214 const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png");
4215 Vector2i caretpt = Vector2i::zero();
4216@@ -461,8 +474,8 @@
4217 void EditBox::check_caret() {
4218 std::string leftstr(m_->text, 0, m_->caret);
4219 std::string rightstr(m_->text, m_->caret, std::string::npos);
4220- int32_t leftw = text_width(leftstr, m_->fontsize);
4221- int32_t rightw = text_width(rightstr, m_->fontsize);
4222+ int32_t leftw = text_width(leftstr, *m_->font_style, m_->font_scale);
4223+ int32_t rightw = text_width(rightstr, *m_->font_style, m_->font_scale);
4224
4225 int32_t caretpos = 0;
4226
4227
4228=== modified file 'src/ui_basic/editbox.h'
4229--- src/ui_basic/editbox.h 2019-05-15 09:58:33 +0000
4230+++ src/ui_basic/editbox.h 2019-05-26 02:00:17 +0000
4231@@ -26,6 +26,7 @@
4232 #include <boost/signals2.hpp>
4233
4234 #include "graphic/align.h"
4235+#include "graphic/style_manager.h"
4236 #include "ui_basic/button.h"
4237
4238 #define CHAT_HISTORY_SIZE 5
4239@@ -48,10 +49,7 @@
4240 int32_t x,
4241 int32_t y,
4242 uint32_t w,
4243- uint32_t h,
4244- int margin_y,
4245- UI::PanelStyle style,
4246- int font_size = UI_FONT_SIZE_SMALL);
4247+ UI::PanelStyle style);
4248 ~EditBox() override;
4249
4250 boost::signals2::signal<void()> changed;
4251@@ -60,7 +58,10 @@
4252
4253 const std::string& text() const;
4254 void set_text(const std::string&);
4255- void set_max_length(uint32_t);
4256+ void set_max_length(int);
4257+ void set_font_scale(float scale);
4258+ void set_font_style(const UI::FontStyleInfo& style);
4259+ void set_font_style_and_margin(const UI::FontStyleInfo& style, int margin);
4260
4261 void activate_history(bool activate) {
4262 history_active_ = activate;
4263
4264=== modified file 'src/ui_basic/fullscreen_window.cc'
4265--- src/ui_basic/fullscreen_window.cc 2019-02-23 11:00:49 +0000
4266+++ src/ui_basic/fullscreen_window.cc 2019-05-26 02:00:17 +0000
4267@@ -22,9 +22,9 @@
4268 #include <cstdio>
4269 #include <memory>
4270
4271+#include "base/log.h"
4272 #include "graphic/rendertarget.h"
4273 #include "graphic/style_manager.h"
4274-#include "graphic/text_constants.h"
4275
4276 /*
4277 ==============================================================================
4278@@ -177,12 +177,8 @@
4279 }
4280 }
4281
4282-int FullscreenWindow::fs_small() {
4283- return UI_FONT_SIZE_SMALL * get_h() / 600;
4284-}
4285-
4286-int FullscreenWindow::fs_big() {
4287- return UI_FONT_SIZE_BIG * get_h() / 600;
4288+float FullscreenWindow::scale_factor() const {
4289+ return std::max(1.0f, get_h() / 600.0f);
4290 }
4291
4292 } // namespace UI
4293
4294=== modified file 'src/ui_basic/fullscreen_window.h'
4295--- src/ui_basic/fullscreen_window.h 2019-02-23 11:00:49 +0000
4296+++ src/ui_basic/fullscreen_window.h 2019-05-26 02:00:17 +0000
4297@@ -71,9 +71,8 @@
4298 FullscreenWindow();
4299 ~FullscreenWindow() override;
4300
4301- /// \return the size for texts fitting to current resolution
4302- int fs_small();
4303- int fs_big();
4304+ /// \return the font size scale factor for fitting texts to current resolution
4305+ float scale_factor() const;
4306
4307 protected:
4308 void draw(RenderTarget&) override;
4309
4310=== modified file 'src/ui_basic/listselect.cc'
4311--- src/ui_basic/listselect.cc 2019-02-23 11:00:49 +0000
4312+++ src/ui_basic/listselect.cc 2019-05-26 02:00:17 +0000
4313@@ -30,7 +30,6 @@
4314 #include "graphic/rendertarget.h"
4315 #include "graphic/style_manager.h"
4316 #include "graphic/text/bidi.h"
4317-#include "graphic/text_constants.h"
4318 #include "graphic/text_layout.h"
4319 #include "ui_basic/mouse_constants.h"
4320
4321@@ -54,16 +53,17 @@
4322 UI::PanelStyle style,
4323 const ListselectLayout selection_mode)
4324 : Panel(parent, x, y, w, h),
4325- lineheight_(text_height() + kMargin),
4326 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style),
4327 scrollpos_(0),
4328 selection_(no_selection_index()),
4329 last_click_time_(-10000),
4330 last_selection_(no_selection_index()),
4331 selection_mode_(selection_mode),
4332+ font_style_(&g_gr->styles().table_style(style).enabled()),
4333 background_style_(selection_mode == ListselectLayout::kDropdown ?
4334 g_gr->styles().dropdown_style(style) :
4335- nullptr) {
4336+ nullptr),
4337+ lineheight_(text_height(*font_style_) + kMargin) {
4338 set_thinks(false);
4339
4340 scrollbar_.moved.connect(boost::bind(&BaseListselect::set_scrollpos, this, _1));
4341@@ -297,7 +297,7 @@
4342 for (size_t i = 0; i < entry_records_.size(); ++i) {
4343 const EntryRecord& er = *entry_records_[i];
4344 std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(
4345- as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
4346+ as_richtext_paragraph(richtext_escape(er.name), *font_style_));
4347 int picw = max_pic_width_ ? max_pic_width_ + 10 : 0;
4348 int difference = rendered_text->width() + picw + 8 - get_eff_w();
4349 if (difference > 0) {
4350@@ -342,7 +342,7 @@
4351
4352 const EntryRecord& er = *entry_records_[idx];
4353 std::shared_ptr<const UI::RenderedText> rendered_text =
4354- UI::g_fh->render(as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
4355+ UI::g_fh->render(as_richtext_paragraph(richtext_escape(er.name), *font_style_));
4356
4357 int lineheight = std::max(get_lineheight(), rendered_text->height());
4358
4359
4360=== modified file 'src/ui_basic/listselect.h'
4361--- src/ui_basic/listselect.h 2019-02-23 11:00:49 +0000
4362+++ src/ui_basic/listselect.h 2019-05-26 02:00:17 +0000
4363@@ -26,6 +26,7 @@
4364 #include <boost/signals2.hpp>
4365
4366 #include "graphic/color.h"
4367+#include "graphic/styles/font_style.h"
4368 #include "ui_basic/panel.h"
4369 #include "ui_basic/scrollbar.h"
4370
4371@@ -139,7 +140,6 @@
4372 using EntryRecordDeque = std::deque<EntryRecord*>;
4373
4374 int max_pic_width_;
4375- int lineheight_;
4376 EntryRecordDeque entry_records_;
4377 Scrollbar scrollbar_;
4378 uint32_t scrollpos_; // in pixels
4379@@ -148,7 +148,9 @@
4380 uint32_t last_selection_; // for double clicks
4381 ListselectLayout selection_mode_;
4382 const Image* check_pic_;
4383+ const FontStyleInfo* font_style_;
4384 const UI::PanelStyleInfo* background_style_; // Background color and texture. Not owned.
4385+ int lineheight_;
4386 std::string current_tooltip_;
4387 };
4388
4389
4390=== modified file 'src/ui_basic/messagebox.cc'
4391--- src/ui_basic/messagebox.cc 2019-02-23 11:00:49 +0000
4392+++ src/ui_basic/messagebox.cc 2019-05-26 02:00:17 +0000
4393@@ -22,6 +22,7 @@
4394 #include "base/i18n.h"
4395 #include "graphic/font_handler.h"
4396 #include "graphic/graphic.h"
4397+#include "graphic/text_layout.h"
4398 #include "ui_basic/window.h"
4399
4400 namespace UI {
4401@@ -44,19 +45,21 @@
4402 // Make sure that there is space for buttons + message, but not too tall
4403 const int maxheight = std::min(260, std::max(outerheight * 2 / 3, 200));
4404
4405+ const UI::FontStyle font_style = UI::FontStyle::kLabel;
4406+
4407 const int margin = 5;
4408 int width, height = 0;
4409 {
4410 std::shared_ptr<const UI::RenderedText> temp_rendered_text =
4411- g_fh->render(as_uifont(text), maxwidth);
4412+ g_fh->render(as_richtext_paragraph(text, font_style), maxwidth);
4413 width = temp_rendered_text->width();
4414 height = temp_rendered_text->height();
4415 }
4416
4417 // Stupid heuristic to avoid excessively long lines
4418- if (height < 2 * UI_FONT_SIZE_SMALL) {
4419+ if (height < 2 * text_height(font_style)) {
4420 std::shared_ptr<const UI::RenderedText> temp_rendered_text =
4421- g_fh->render(as_uifont(text), maxwidth / 2);
4422+ g_fh->render(as_richtext_paragraph(text, font_style), maxwidth / 2);
4423 width = temp_rendered_text->width();
4424 height = temp_rendered_text->height();
4425 }
4426
4427=== modified file 'src/ui_basic/multilineeditbox.cc'
4428--- src/ui_basic/multilineeditbox.cc 2019-02-23 11:00:49 +0000
4429+++ src/ui_basic/multilineeditbox.cc 2019-05-26 02:00:17 +0000
4430@@ -41,8 +41,8 @@
4431 /// The text in the edit box
4432 std::string text;
4433
4434- /// Background color and texture
4435- const UI::PanelStyleInfo* background_style;
4436+ /// Background color and texture + font style
4437+ const UI::TextPanelStyleInfo& style;
4438
4439 /// Position of the cursor inside the text.
4440 /// 0 indicates that the cursor is before the first character,
4441@@ -60,7 +60,7 @@
4442 WordWrap ww;
4443 /*@}*/
4444
4445- Data(MultilineEditbox&, const UI::PanelStyleInfo* style);
4446+ Data(MultilineEditbox&, const TextPanelStyleInfo& style);
4447 void refresh_ww();
4448
4449 void update();
4450@@ -81,7 +81,7 @@
4451
4452 /**
4453 * Initialize an editbox that supports multiline strings.
4454- */
4455+*/
4456 MultilineEditbox::MultilineEditbox(
4457 Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, UI::PanelStyle style)
4458 : Panel(parent, x, y, w, h), d_(new Data(*this, g_gr->styles().editbox_style(style))) {
4459@@ -91,17 +91,18 @@
4460 set_handle_textinput();
4461 }
4462
4463-MultilineEditbox::Data::Data(MultilineEditbox& o, const UI::PanelStyleInfo* style)
4464+MultilineEditbox::Data::Data(MultilineEditbox& o, const UI::TextPanelStyleInfo& init_style)
4465 : scrollbar(
4466 &o, o.get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, o.get_h(), UI::PanelStyle::kWui),
4467- background_style(style),
4468+ style(init_style),
4469 cursor_pos(0),
4470- lineheight(text_height()),
4471+ lineheight(text_height(style.font())),
4472 maxbytes(std::min(g_gr->max_texture_size_for_font_rendering() *
4473 g_gr->max_texture_size_for_font_rendering() /
4474- (text_height() * text_height()),
4475+ (text_height(style.font()) * text_height(style.font())),
4476 std::numeric_limits<int32_t>::max())),
4477 ww_valid(false),
4478+ ww(style.font().size(), style.font().color(), o.get_w()),
4479 owner(o) {
4480 scrollbar.moved.connect(boost::bind(&MultilineEditbox::scrollpos_changed, &o, _1));
4481
4482@@ -413,7 +414,7 @@
4483 * Redraw the Editbox
4484 */
4485 void MultilineEditbox::draw(RenderTarget& dst) {
4486- draw_background(dst, *d_->background_style);
4487+ draw_background(dst, d_->style.background());
4488
4489 // Draw border.
4490 if (get_w() >= 4 && get_h() >= 4) {
4491@@ -437,7 +438,6 @@
4492 d_->refresh_ww();
4493
4494 d_->ww.set_draw_caret(has_focus());
4495-
4496 d_->ww.draw(dst, Vector2i(0, -int32_t(d_->scrollbar.get_scrollpos())), UI::Align::kLeft,
4497 has_focus() ? d_->cursor_pos : std::numeric_limits<uint32_t>::max());
4498 }
4499
4500=== modified file 'src/ui_basic/multilinetextarea.cc'
4501--- src/ui_basic/multilinetextarea.cc 2019-02-23 11:00:49 +0000
4502+++ src/ui_basic/multilinetextarea.cc 2019-05-26 02:00:17 +0000
4503@@ -23,9 +23,10 @@
4504 #include <boost/bind.hpp>
4505
4506 #include "graphic/font_handler.h"
4507+#include "graphic/graphic.h"
4508 #include "graphic/rendertarget.h"
4509+#include "graphic/text/bidi.h"
4510 #include "graphic/text/font_set.h"
4511-#include "graphic/text_constants.h"
4512 #include "graphic/text_layout.h"
4513
4514 namespace UI {
4515@@ -44,19 +45,30 @@
4516 MultilineTextarea::ScrollMode scroll_mode)
4517 : Panel(parent, x, y, w, h),
4518 text_(text),
4519- color_(UI_FONT_CLR_FG),
4520+ style_(&g_gr->styles().font_style(FontStyle::kLabel)),
4521+ font_scale_(1.0f),
4522 align_(align),
4523 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style, false) {
4524 set_thinks(false);
4525
4526 scrollbar_.moved.connect(boost::bind(&MultilineTextarea::scrollpos_changed, this, _1));
4527
4528- scrollbar_.set_singlestepsize(text_height());
4529+ scrollbar_.set_singlestepsize(text_height(*style_, font_scale_));
4530 scrollbar_.set_steps(1);
4531 set_scrollmode(scroll_mode);
4532 assert(scrollmode_ == MultilineTextarea::ScrollMode::kNoScrolling || Scrollbar::kSize <= w);
4533 }
4534
4535+void MultilineTextarea::set_style(const UI::FontStyleInfo& style) {
4536+ style_ = &style;
4537+ recompute();
4538+}
4539+void MultilineTextarea::set_font_scale(float scale) {
4540+ font_scale_ = scale;
4541+ scrollbar_.set_singlestepsize(text_height(*style_, font_scale_));
4542+ recompute();
4543+}
4544+
4545 /**
4546 * Replace the current text with a new one.
4547 * Fix up scrolling state if necessary.
4548@@ -66,11 +78,6 @@
4549 recompute();
4550 }
4551
4552-void MultilineTextarea::set_color(RGBColor fg) {
4553- color_ = fg;
4554- recompute();
4555-}
4556-
4557 /**
4558 * Recompute the text rendering or rich-text layouting,
4559 * and adjust scrollbar settings accordingly.
4560@@ -129,7 +136,7 @@
4561 // Take care of the scrollbar
4562 scrollbar_.set_pos(Vector2i(get_w() - Scrollbar::kSize, 0));
4563 scrollbar_.set_size(Scrollbar::kSize, get_h());
4564- scrollbar_.set_pagesize(get_h() - 2 * UI_FONT_SIZE_BIG);
4565+ scrollbar_.set_pagesize(get_h() - 2 * style_->size() * font_scale_);
4566 }
4567
4568 /**
4569@@ -140,7 +147,7 @@
4570 return;
4571 }
4572 int anchor = 0;
4573- Align alignment = mirror_alignment(align_, text_);
4574+ Align alignment = mirror_alignment(align_, i18n::has_rtl_character(text_.c_str(), 20));
4575 switch (alignment) {
4576 // TODO(Arty): We might want to revisit this after the font renderer can handle long strings
4577 // without whitespaces differently.
4578@@ -192,7 +199,10 @@
4579 // TODO(GunChleoc): Revisit this once the old font renderer is completely gone.
4580 boost::replace_all(temp, "\n\n", "<br>&nbsp;<br>");
4581 boost::replace_all(temp, "\n", "<br>");
4582- return as_aligned(temp, align_, UI_FONT_SIZE_SMALL, color_);
4583+
4584+ FontStyleInfo scaled_style(*style_);
4585+ scaled_style.set_size(std::max(g_gr->styles().minimum_font_size(), static_cast<int>(std::ceil(scaled_style.size() * font_scale_))));
4586+ return as_richtext_paragraph(temp, scaled_style, align_);
4587 }
4588
4589 } // namespace UI
4590
4591=== modified file 'src/ui_basic/multilinetextarea.h'
4592--- src/ui_basic/multilinetextarea.h 2019-02-23 11:00:49 +0000
4593+++ src/ui_basic/multilinetextarea.h 2019-05-26 02:00:17 +0000
4594@@ -23,13 +23,12 @@
4595 #include <memory>
4596
4597 #include "graphic/align.h"
4598-#include "graphic/color.h"
4599+#include "graphic/styles/panel_styles.h"
4600 #include "graphic/text_layout.h"
4601 #include "ui_basic/panel.h"
4602 #include "ui_basic/scrollbar.h"
4603
4604 namespace UI {
4605-struct Scrollbar;
4606
4607 /**
4608 * This defines an area, where a text can easily be printed.
4609@@ -65,7 +64,8 @@
4610 return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();
4611 }
4612
4613- void set_color(RGBColor fg);
4614+ void set_style(const FontStyleInfo& style);
4615+ void set_font_scale(float scale);
4616
4617 // Drawing and event handlers
4618 void draw(RenderTarget&) override;
4619@@ -88,10 +88,13 @@
4620 * turns '\\n' into '<br>' tags as needed, then creates the richtext style wrappers.
4621 */
4622 std::string make_richtext();
4623-
4624 std::string text_;
4625- std::shared_ptr<const UI::RenderedText> rendered_text_;
4626- RGBColor color_;
4627+
4628+ std::shared_ptr<const UI::RenderedText> rendered_text_;
4629+
4630+ const FontStyleInfo* style_;
4631+ float font_scale_;
4632+
4633 const Align align_;
4634
4635 Scrollbar scrollbar_;
4636
4637=== modified file 'src/ui_basic/panel.cc'
4638--- src/ui_basic/panel.cc 2019-04-24 06:01:37 +0000
4639+++ src/ui_basic/panel.cc 2019-05-26 02:00:17 +0000
4640@@ -24,7 +24,6 @@
4641 #include "graphic/graphic.h"
4642 #include "graphic/rendertarget.h"
4643 #include "graphic/text/font_set.h"
4644-#include "graphic/text_constants.h"
4645 #include "graphic/text_layout.h"
4646 #include "profile/profile.h"
4647 #include "sound/sound_handler.h"
4648@@ -458,12 +457,12 @@
4649 draw_background(dst, Recti(0, 0, get_w(), get_h()), info);
4650 }
4651 void Panel::draw_background(RenderTarget& dst, Recti rect, const UI::PanelStyleInfo& info) {
4652- if (info.image != nullptr) {
4653+ if (info.image() != nullptr) {
4654 dst.fill_rect(rect, RGBAColor(0, 0, 0, 255));
4655- dst.tile(rect, info.image, Vector2i(get_x(), get_y()));
4656+ dst.tile(rect, info.image(), Vector2i(get_x(), get_y()));
4657 }
4658- if (info.color != RGBAColor(0, 0, 0, 0)) {
4659- dst.fill_rect(rect, info.color, BlendMode::UseAlpha);
4660+ if (info.color() != RGBAColor(0, 0, 0, 0)) {
4661+ dst.fill_rect(rect, info.color(), BlendMode::UseAlpha);
4662 }
4663 }
4664
4665@@ -1082,7 +1081,7 @@
4666 RenderTarget& dst = *g_gr->get_render_target();
4667 std::string text_to_render = text;
4668 if (!is_richtext(text_to_render)) {
4669- text_to_render = as_tooltip(text_to_render);
4670+ text_to_render = as_richtext_paragraph(text_to_render, UI::FontStyle::kTooltip);
4671 }
4672
4673 constexpr uint32_t kTipWidthMax = 360;
4674
4675=== modified file 'src/ui_basic/panel.h'
4676--- src/ui_basic/panel.h 2019-05-05 11:20:18 +0000
4677+++ src/ui_basic/panel.h 2019-05-26 02:00:17 +0000
4678@@ -33,7 +33,7 @@
4679 #include "base/vector.h"
4680 #include "graphic/align.h"
4681 #include "graphic/font_handler.h"
4682-#include "graphic/panel_styles.h"
4683+#include "graphic/styles/panel_styles.h"
4684 #include "sound/constants.h"
4685
4686 class RenderTarget;
4687
4688=== modified file 'src/ui_basic/progressbar.cc'
4689--- src/ui_basic/progressbar.cc 2019-02-23 11:00:49 +0000
4690+++ src/ui_basic/progressbar.cc 2019-05-26 02:00:17 +0000
4691@@ -24,6 +24,7 @@
4692 #include <boost/format.hpp>
4693
4694 #include "graphic/font_handler.h"
4695+#include "graphic/graphic.h"
4696 #include "graphic/rendertarget.h"
4697 #include "graphic/text_layout.h"
4698
4699@@ -37,7 +38,7 @@
4700 int32_t const w,
4701 int32_t const h,
4702 uint32_t const orientation)
4703- : Panel(parent, x, y, w, h), orientation_(orientation), state_(0), total_(100) {
4704+ : Panel(parent, x, y, w, h), orientation_(orientation), state_(0), total_(100), style_(g_gr->styles().progressbar_style(UI::PanelStyle::kWui)) {
4705 }
4706
4707 /**
4708@@ -66,9 +67,9 @@
4709 assert(0 <= fraction);
4710 assert(fraction <= 1);
4711
4712- const RGBColor color = fraction <= 0.33f ?
4713- RGBColor(255, 0, 0) :
4714- fraction <= 0.67f ? RGBColor(255, 255, 0) : RGBColor(0, 255, 0);
4715+ const RGBColor& color = fraction <= 0.33f ? style_.low_color() : fraction <= 0.67f ?
4716+ style_.medium_color() :
4717+ style_.high_color();
4718
4719 // Draw the actual bar
4720 if (orientation_ == Horizontal) {
4721@@ -85,11 +86,8 @@
4722 }
4723
4724 // Print the state in percent without decimal points.
4725- const std::string progress_text = (boost::format("<font color=%s>%u%%</font>") %
4726- UI_FONT_CLR_BRIGHT.hex_value() % floorf(fraction * 100.f))
4727- .str();
4728 std::shared_ptr<const UI::RenderedText> rendered_text =
4729- UI::g_fh->render(as_uifont(progress_text));
4730+ UI::g_fh->render(as_richtext_paragraph((boost::format("%u%%") % floorf(fraction * 100.f)).str(), style_.font()));
4731 Vector2i pos(get_w() / 2, get_h() / 2);
4732 UI::center_vertically(rendered_text->height(), &pos);
4733 rendered_text->draw(dst, pos, UI::Align::kCenter);
4734
4735=== modified file 'src/ui_basic/progressbar.h'
4736--- src/ui_basic/progressbar.h 2019-02-23 11:00:49 +0000
4737+++ src/ui_basic/progressbar.h 2019-05-26 02:00:17 +0000
4738@@ -20,6 +20,7 @@
4739 #ifndef WL_UI_BASIC_PROGRESSBAR_H
4740 #define WL_UI_BASIC_PROGRESSBAR_H
4741
4742+#include "graphic/style_manager.h"
4743 #include "ui_basic/panel.h"
4744
4745 namespace UI {
4746@@ -58,6 +59,7 @@
4747 uint32_t orientation_;
4748 uint32_t state_; ///< state_ is [0..total_]
4749 uint32_t total_; ///< maximum progress
4750+ const UI::ProgressbarStyleInfo& style_;
4751 };
4752 } // namespace UI
4753
4754
4755=== modified file 'src/ui_basic/progresswindow.cc'
4756--- src/ui_basic/progresswindow.cc 2019-02-23 11:00:49 +0000
4757+++ src/ui_basic/progresswindow.cc 2019-05-26 02:00:17 +0000
4758@@ -28,14 +28,10 @@
4759 #include "graphic/graphic.h"
4760 #include "graphic/rendertarget.h"
4761 #include "graphic/text/font_set.h"
4762-#include "graphic/text_constants.h"
4763 #include "graphic/text_layout.h"
4764 #include "io/filesystem/layered_filesystem.h"
4765
4766 namespace {
4767-
4768-#define PROGRESS_FONT_COLOR_FG RGBColor(128, 128, 255)
4769-#define PROGRESS_FONT_COLOR_BG RGBColor(64, 64, 0)
4770 #define PROGRESS_STATUS_RECT_PADDING 2
4771 #define PROGRESS_STATUS_BORDER_X 2
4772 #define PROGRESS_STATUS_BORDER_Y 2
4773@@ -46,7 +42,7 @@
4774 namespace UI {
4775
4776 ProgressWindow::ProgressWindow(const std::string& background)
4777- : UI::FullscreenWindow(), label_center_(Vector2i::zero()) {
4778+ : UI::FullscreenWindow(), label_center_(Vector2i::zero()), style_(g_gr->styles().progressbar_style(UI::PanelStyle::kFsMenu)) {
4779 set_background(background);
4780 step(_("Loading…"));
4781 }
4782@@ -63,7 +59,7 @@
4783 label_center_.x = get_w() / 2;
4784 label_center_.y = get_h() * PROGRESS_LABEL_POSITION_Y / 100;
4785
4786- const uint32_t h = text_height();
4787+ const uint32_t h = text_height(style_.font());
4788
4789 label_rectangle_.x = get_w() / 4;
4790 label_rectangle_.w = get_w() / 2;
4791@@ -76,7 +72,9 @@
4792 border_rect.w += 2 * PROGRESS_STATUS_BORDER_X;
4793 border_rect.h += 2 * PROGRESS_STATUS_BORDER_Y;
4794
4795- rt.draw_rect(border_rect, PROGRESS_FONT_COLOR_FG);
4796+ rt.draw_rect(border_rect, style_.font().color());
4797+ // TODO(GunChleoc): this should depend on actual progress. Add a total steps variable and reuse the Progressbar class.
4798+ rt.fill_rect(label_rectangle_, style_.medium_color());
4799 }
4800
4801 /// Set a picture to render in the background
4802@@ -97,9 +95,8 @@
4803 // always repaint the background first
4804 draw(rt);
4805
4806- rt.fill_rect(label_rectangle_, PROGRESS_FONT_COLOR_BG);
4807 std::shared_ptr<const UI::RenderedText> rendered_text =
4808- UI::g_fh->render(as_uifont(description, UI_FONT_SIZE_SMALL, PROGRESS_FONT_COLOR_FG));
4809+ UI::g_fh->render(as_richtext_paragraph(description, style_.font()));
4810 UI::center_vertically(rendered_text->height(), &label_center_);
4811 rendered_text->draw(rt, label_center_, UI::Align::kCenter);
4812
4813
4814=== modified file 'src/ui_basic/progresswindow.h'
4815--- src/ui_basic/progresswindow.h 2019-02-23 11:00:49 +0000
4816+++ src/ui_basic/progresswindow.h 2019-05-26 02:00:17 +0000
4817@@ -67,6 +67,7 @@
4818 Recti label_rectangle_;
4819 VisualizationArray visualizations_;
4820 std::string background_;
4821+ const UI::ProgressbarStyleInfo& style_;
4822
4823 void draw(RenderTarget&) override;
4824 void update(bool repaint);
4825
4826=== modified file 'src/ui_basic/slider.cc'
4827--- src/ui_basic/slider.cc 2019-03-16 07:46:10 +0000
4828+++ src/ui_basic/slider.cc 2019-05-26 02:00:17 +0000
4829@@ -72,7 +72,7 @@
4830 highlighted_(false),
4831 pressed_(false),
4832 enabled_(enabled),
4833- cursor_style_(g_gr->styles().slider_style(style)),
4834+ cursor_style_(&g_gr->styles().slider_style(style).background()),
4835 x_gap_(x_gap),
4836 y_gap_(y_gap),
4837 bar_size_(bar_size),
4838@@ -487,22 +487,23 @@
4839 const uint32_t w,
4840 const uint32_t h,
4841 const std::vector<std::string>& labels_in,
4842- uint32_t value_,
4843- SliderStyle style,
4844+ uint32_t init_value,
4845+ SliderStyle init_style,
4846 const std::string& tooltip_text,
4847 const uint32_t cursor_size,
4848 const bool enabled)
4849 : Panel(parent, x, y, w, h, tooltip_text),
4850+ style(g_gr->styles().slider_style(init_style)),
4851 slider(this,
4852 // here, we take into account the h_gap introduced by HorizontalSlider
4853 w / (2 * labels_in.size()) - cursor_size / 2,
4854 0,
4855 w - (w / labels_in.size()) + cursor_size,
4856- h - text_height(UI_FONT_SIZE_SMALL - 2, UI::FontSet::Face::kCondensed) - 2,
4857+ h - text_height(style.font()) - 2,
4858 0,
4859 labels_in.size() - 1,
4860- value_,
4861- style,
4862+ init_value,
4863+ init_style,
4864 tooltip_text,
4865 cursor_size,
4866 enabled),
4867@@ -524,7 +525,7 @@
4868
4869 for (uint32_t i = 0; i < labels.size(); i++) {
4870 std::shared_ptr<const UI::RenderedText> rendered_text =
4871- UI::g_fh->render(as_condensed(labels[i], UI::Align::kCenter, UI_FONT_SIZE_SMALL - 2));
4872+ UI::g_fh->render(as_richtext_paragraph(labels[i], style.font()));
4873 rendered_text->draw(
4874 dst, Vector2i(gap_1 + i * gap_n, get_h() - rendered_text->height()), UI::Align::kCenter);
4875 }
4876@@ -542,7 +543,7 @@
4877 assert(labels.size());
4878 slider.set_pos(Vector2i(w / (2 * labels.size()) - slider.cursor_size_ / 2, 0));
4879 slider.set_size(w - (w / labels.size()) + slider.cursor_size_,
4880- h - text_height(UI_FONT_SIZE_SMALL - 2, UI::FontSet::Face::kCondensed) + 2);
4881+ h - text_height(style.font()) + 2);
4882 Panel::layout();
4883 }
4884 } // namespace UI
4885
4886=== modified file 'src/ui_basic/slider.h'
4887--- src/ui_basic/slider.h 2019-03-16 07:28:07 +0000
4888+++ src/ui_basic/slider.h 2019-05-26 02:00:17 +0000
4889@@ -21,6 +21,7 @@
4890
4891 #include <boost/signals2.hpp>
4892
4893+#include "graphic/styles/text_panel_style.h"
4894 #include "ui_basic/panel.h"
4895
4896 namespace UI {
4897@@ -236,6 +237,11 @@
4898 void draw(RenderTarget& dst) override;
4899 void layout() override;
4900
4901+private:
4902+ // We need the style to initialize the slider, so it has to come first.
4903+ const UI::TextPanelStyleInfo& style;
4904+
4905+protected:
4906 HorizontalSlider slider;
4907
4908 private:
4909
4910=== modified file 'src/ui_basic/spinbox.cc'
4911--- src/ui_basic/spinbox.cc 2019-02-23 11:00:49 +0000
4912+++ src/ui_basic/spinbox.cc 2019-05-26 02:00:17 +0000
4913@@ -31,7 +31,6 @@
4914 #include "graphic/font_handler.h"
4915 #include "graphic/graphic.h"
4916 #include "graphic/text/font_set.h"
4917-#include "graphic/text_constants.h"
4918 #include "ui_basic/button.h"
4919 #include "ui_basic/multilinetextarea.h"
4920 #include "ui_basic/textarea.h"
4921
4922=== modified file 'src/ui_basic/table.cc'
4923--- src/ui_basic/table.cc 2019-04-18 16:50:35 +0000
4924+++ src/ui_basic/table.cc 2019-05-26 02:00:17 +0000
4925@@ -22,14 +22,13 @@
4926 #include <boost/bind.hpp>
4927
4928 #include "graphic/font_handler.h"
4929+#include "graphic/graphic.h"
4930 #include "graphic/rendertarget.h"
4931 #include "graphic/text/bidi.h"
4932 #include "graphic/text/font_set.h"
4933-#include "graphic/text_constants.h"
4934 #include "graphic/text_layout.h"
4935 #include "graphic/texture.h"
4936 #include "ui_basic/mouse_constants.h"
4937-#include "ui_basic/scrollbar.h"
4938
4939 namespace UI {
4940
4941@@ -49,8 +48,9 @@
4942 TableRows rowtype)
4943 : Panel(parent, x, y, w, h),
4944 total_width_(0),
4945- headerheight_(text_height() + 4),
4946- lineheight_(text_height()),
4947+ lineheight_(text_height(g_gr->styles().table_style(style).enabled())),
4948+ headerheight_(lineheight_ + 4),
4949+ style_(style),
4950 button_style_(style == UI::PanelStyle::kFsMenu ? UI::ButtonStyle::kFsMenuMenu :
4951 UI::ButtonStyle::kWuiSecondary),
4952 scrollbar_(nullptr),
4953@@ -239,7 +239,7 @@
4954 for (uint32_t i = 0, curx = 0; i < nr_columns; ++i) {
4955 const Column& column = columns_[i];
4956 const int curw = column.width;
4957- Align alignment = mirror_alignment(column.alignment);
4958+ Align alignment = mirror_alignment(column.alignment, g_fh->fontset()->is_rtl());
4959
4960 const Image* entry_picture = er.get_picture(i);
4961 const std::string& entry_string = er.get_string(i);
4962@@ -300,12 +300,19 @@
4963 curx += curw;
4964 continue;
4965 }
4966- std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(
4967- as_uifont(richtext_escape(entry_string), UI_FONT_SIZE_SMALL, er.get_color()));
4968+
4969+ const UI::FontStyleInfo& font_style =
4970+ er.font_style() != nullptr ?
4971+ *er.font_style() :
4972+ er.is_disabled() ?
4973+ g_gr->styles().table_style(style_).disabled() :
4974+ g_gr->styles().table_style(style_).enabled();
4975+ std::shared_ptr<const UI::RenderedText> rendered_text =
4976+ UI::g_fh->render(as_richtext_paragraph(richtext_escape(entry_string), font_style));
4977
4978 // Fix text alignment for BiDi languages if the entry contains an RTL character. We want
4979 // this always on, e.g. for mixed language savegame filenames.
4980- alignment = mirror_alignment(column.alignment, entry_string);
4981+ alignment = mirror_alignment(column.alignment, i18n::has_rtl_character(entry_string.c_str(), 20));
4982
4983 // Position the text according to alignment
4984 switch (alignment) {
4985@@ -718,7 +725,7 @@
4986 return ea.get_string(column) < eb.get_string(column);
4987 }
4988
4989-Table<void*>::EntryRecord::EntryRecord(void* const e) : entry_(e), clr(UI_FONT_CLR_FG) {
4990+Table<void*>::EntryRecord::EntryRecord(void* const e) : entry_(e), font_style_(nullptr), disabled_(false) {
4991 }
4992
4993 void Table<void*>::EntryRecord::set_picture(uint8_t const col,
4994
4995=== modified file 'src/ui_basic/table.h'
4996--- src/ui_basic/table.h 2019-04-18 16:50:35 +0000
4997+++ src/ui_basic/table.h 2019-05-26 02:00:17 +0000
4998@@ -29,12 +29,12 @@
4999
5000 #include "graphic/align.h"
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to status/vote changes: