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.
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);

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.

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

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
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks a lot for the review!

@bunnybot merge

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
=== modified file 'data/templates/default/init.lua'
--- data/templates/default/init.lua 2017-06-14 06:40:42 +0000
+++ data/templates/default/init.lua 2019-05-26 02:00:17 +0000
@@ -1,7 +1,15 @@
1-- This script defines a GUI style for Widelands. At the moment, we only1-- This script defines a GUI style for Widelands. At the moment, we only
2-- support the default template.2-- support the default template.
3-- So far, only background textures and colors can be defined, and they all have3
4-- the format { image = filename, color = {r, g, b } }.4-- Background textures and colors have the format { image = filename, color = {r, g, b } }.
5
6-- Required parameters for font styles are:
7-- * face: string
8-- * color: table with r, g, b values as int
9-- * size: positive int
10-- Optional bools are: bold, italic, underline, shadow
11
12-- Some elements carry custom parameters like e.g. "margin" that should be expanded upon in the future.
513
6dirname = path.dirname(__file__)14dirname = path.dirname(__file__)
715
@@ -17,43 +25,222 @@
17local wui_green = {3, 15, 0}25local wui_green = {3, 15, 0}
18local wui_brown = {32, 19, 8}26local wui_brown = {32, 19, 8}
1927
28local fs_font_color = {255, 255, 0}
29local fs_font_face = "sans"
30local fs_font_size = 14
31
32local wui_font_color = {255, 255, 0}
33local wui_font_face = "sans"
34local wui_font_size = 14
35
36local default_ui_font = {
37 color = fs_font_color,
38 face = fs_font_face,
39 size = fs_font_size,
40 bold = true,
41 shadow = true
42}
43
44local default_button_fonts = {
45 enabled = default_ui_font,
46 disabled = {
47 color = {127, 127, 127},
48 face = fs_font_face,
49 size = fs_font_size,
50 bold = true,
51 shadow = true
52 },
53}
54
55local productivity_colors = {
56 low = {187, 0, 0},
57 medium = {255, 225, 30},
58 high = {0, 187, 0},
59}
60
20-- These are the style definitions to be returned.61-- These are the style definitions to be returned.
21-- Note: you have to keep all the keys intact, or Widelands will not be happy.62-- Note: you have to keep all the keys intact, or Widelands will not be happy.
22return {63return {
23 -- Button backgrounds64 -- Automatic resizing of fonts to make them fit onto buttons etc.
65 -- won't go below this size
66 minimum_font_size = 10,
67 minimap_icon_frame = fs_font_color,
68
69 -- Buttons
24 buttons = {70 buttons = {
25 -- Buttons used in Fullscreen menus71 -- Buttons used in Fullscreen menus
26 fsmenu = {72 fsmenu = {
27 -- Main menu ("Single Player", "Watch Replay", ...)73 -- Main menu ("Single Player", "Watch Replay", ...)
28 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 },
29 -- Primary user selection ("OK", ...)90 -- Primary user selection ("OK", ...)
30 primary = { image = fs_button, color = fs_green },91 primary = {
92 enabled = {
93 font = default_button_fonts["enabled"],
94 background = {
95 image = fs_button,
96 color = fs_green,
97 }
98 },
99 disabled = {
100 font = default_button_fonts["disabled"],
101 background = {
102 image = fs_button,
103 color = fs_green,
104 }
105 }
106 },
31 -- Secondary user selection ("Cancel", "Delete", selection buttons, ...)107 -- Secondary user selection ("Cancel", "Delete", selection buttons, ...)
32 secondary = { image = fs_button, color = fs_brown },108 secondary = {
109 enabled = {
110 font = default_button_fonts["enabled"],
111 background = {
112 image = fs_button,
113 color = fs_brown,
114 }
115 },
116 disabled = {
117 font = default_button_fonts["disabled"],
118 background = {
119 image = fs_button,
120 color = fs_brown,
121 }
122 }
123 },
33 },124 },
34 -- Buttons used in-game and in the editor125 -- Buttons used in-game and in the editor
35 wui = {126 wui = {
36 -- Main menu ("Exit Game"), Building Windows, selection buttons, ...127 -- Main menu ("Exit Game"), Building Windows, selection buttons, ...
37 menu = { image = wui_button, color = wui_light },128 menu = {
129 enabled = {
130 font = default_button_fonts["enabled"],
131 background = {
132 image = wui_button,
133 color = wui_light,
134 }
135 },
136 disabled = {
137 font = default_button_fonts["disabled"],
138 background = {
139 image = wui_button,
140 color = wui_light,
141 }
142 }
143 },
38 -- Primary user selection ("OK", attack, ...)144 -- Primary user selection ("OK", attack, ...)
39 primary = { image = wui_button, color = wui_green },145 primary = {
146 enabled = {
147 font = default_button_fonts["enabled"],
148 background = {
149 image = wui_button,
150 color = wui_green,
151 }
152 },
153 disabled = {
154 font = default_button_fonts["disabled"],
155 background = {
156 image = wui_button,
157 color = wui_green,
158 }
159 }
160 },
40 -- Secondary user selection ("Cancel", "Delete", ...)161 -- Secondary user selection ("Cancel", "Delete", ...)
41 secondary = { image = wui_button, color = wui_brown },162 secondary = {
163 enabled = {
164 font = default_button_fonts["enabled"],
165 background = {
166 image = wui_button,
167 color = wui_brown,
168 }
169 },
170 disabled = {
171 font = default_button_fonts["disabled"],
172 background = {
173 image = wui_button,
174 color = wui_brown,
175 }
176 }
177 },
42 -- Building buttons on fieldaction and building statistics need to be178 -- Building buttons on fieldaction and building statistics need to be
43 -- transparent in order to match the background of the tab panel.179 -- transparent in order to match the background of the tab panel.
44 building_stats = { image = "", color = {0, 0, 0} },180 building_stats = {
181 enabled = {
182 font = default_button_fonts["enabled"],
183 background = {
184 image = "",
185 color = {0, 0, 0},
186 }
187 },
188 disabled = {
189 font = default_button_fonts["disabled"],
190 background = {
191 image = "",
192 color = {0, 0, 0},
193 }
194 }
195 },
45 }196 }
46 },197 },
47 -- Slider cursors (Sound control, attack, statistics, ...)198 -- Slider cursors (Sound control, attack, statistics, ...)
48 sliders = {199 sliders = {
49 fsmenu = {200 fsmenu = {
50 menu = { image = fs_button, color = fs_blue },201 menu = {
202 background = {
203 image = fs_button,
204 color = fs_blue,
205 },
206 font = {
207 color = fs_font_color,
208 face = "condensed",
209 size = 11,
210 bold = true,
211 shadow = true
212 }
213 }
51 },214 },
52 wui = {215 wui = {
53 -- Sound Options, Statistics216 -- Sound Options, Statistics
54 light = { image = wui_button, color = wui_brown },217 light = {
218 background = {
219 image = wui_button,
220 color = wui_brown,
221 },
222 font = {
223 color = fs_font_color,
224 face = "condensed",
225 size = 11,
226 bold = true,
227 shadow = true
228 }
229 },
55 -- Fieldaction (attack)230 -- Fieldaction (attack)
56 dark = { image = wui_button, color = wui_green },231 dark = {
232 background = {
233 image = wui_button,
234 color = wui_green,
235 },
236 font = {
237 color = fs_font_color,
238 face = "condensed",
239 size = 11,
240 bold = true,
241 shadow = true
242 }
243 },
57 }244 }
58 },245 },
59 -- Background for tab panels246 -- Background for tab panels
@@ -74,11 +261,31 @@
74 -- Used both for one-line and multiline edit boxes261 -- Used both for one-line and multiline edit boxes
75 editboxes = {262 editboxes = {
76 fsmenu = {263 fsmenu = {
77 menu = { image = fs_button, color = fs_green },264 background = {
265 image = fs_button,
266 color = fs_green,
267 margin = 4
268 },
269 font = {
270 color = fs_font_color,
271 face = fs_font_face,
272 size = fs_font_size,
273 shadow = true
274 },
78 },275 },
79 wui = {276 wui = {
80 menu = { image = wui_button, color = wui_brown },277 background = {
81 }278 image = wui_button,
279 color = wui_brown,
280 margin = 2,
281 },
282 font = {
283 color = wui_font_color,
284 face = wui_font_face,
285 size = wui_font_size,
286 shadow = true
287 },
288 },
82 },289 },
83 -- Background for dropdown menus290 -- Background for dropdown menus
84 dropdowns = {291 dropdowns = {
@@ -97,5 +304,381 @@
97 wui = {304 wui = {
98 menu = { image = wui_button, color = wui_brown },305 menu = { image = wui_button, color = wui_brown },
99 }306 }
100 }307 },
308
309 -- In-game statistics plots
310 statistics_plot = {
311 fonts = {
312 x_tick = {
313 color = { 255, 0, 0 },
314 face = "condensed",
315 size = 13,
316 },
317 y_min_value = {
318 color = { 125, 0, 0 },
319 face = "condensed",
320 size = 13,
321 },
322 y_max_value = {
323 color = { 60, 125, 0 },
324 face = "condensed",
325 size = 13,
326 },
327 },
328 colors = {
329 axis_line = { 0, 0, 0 },
330 zero_line = { 255, 255, 255 },
331 }
332 },
333
334 -- Map census and statistics, and building statistics window
335 building_statistics = {
336 census_font = {
337 color = wui_font_color, -- Default color
338 face = "condensed",
339 size = wui_font_size,
340 bold = true,
341 shadow = true
342 },
343 statistics_font = {
344 color = wui_font_color, -- Default color
345 face = "condensed",
346 size = wui_font_size,
347 bold = true,
348 shadow = true
349 },
350 -- Building statistics window
351 statistics_window = {
352 fonts = {
353 button_font = {
354 color = wui_font_color, -- Default color
355 face = "condensed",
356 size = 12, -- Do not make this bigger - the UI element size is still hard-coded.
357 bold = true,
358 shadow = true
359 },
360 details_font = {
361 color = wui_font_color, -- Default color
362 face = "sans",
363 size = 12, -- Do not make this bigger - the UI element size is still hard-coded.
364 bold = true,
365 shadow = true
366 },
367 },
368 editbox_margin = 0
369 },
370 colors = {
371 construction = { 163, 144, 19 },
372 neutral = { 255, 250, 170 },
373 low = productivity_colors["low"],
374 medium = productivity_colors["medium"],
375 high = productivity_colors["high"],
376 }
377 },
378
379 progressbar = {
380 fsmenu = {
381 font = {
382 color = { 128, 128, 255 },
383 face = fs_font_face,
384 size = fs_font_size,
385 bold = true,
386 shadow = true
387 },
388 background_colors = {
389 low = { 64, 64, 0 }, -- Unused
390 medium = { 64, 64, 0 },
391 high = { 64, 64, 0 }, -- Unused
392 }
393 },
394 wui = {
395 font = {
396 color = {255, 250, 170},
397 face = wui_font_face,
398 size = wui_font_size,
399 bold = true,
400 shadow = true
401 },
402 background_colors = {
403 low = productivity_colors["low"],
404 medium = productivity_colors["medium"],
405 high = productivity_colors["high"],
406 }
407 }
408 },
409
410 tables = {
411 fsmenu = {
412 enabled = {
413 color = fs_font_color,
414 face = fs_font_face,
415 size = fs_font_size,
416 bold = true,
417 shadow = true
418 },
419 disabled = {
420 color = {127, 127, 127},
421 face = fs_font_face,
422 size = fs_font_size,
423 bold = true,
424 shadow = true
425 }
426 },
427 wui = {
428 enabled = {
429 color = fs_font_color,
430 face = fs_font_face,
431 size = fs_font_size,
432 bold = true,
433 shadow = true
434 },
435 disabled = {
436 color = {127, 127, 127},
437 face = fs_font_face,
438 size = fs_font_size,
439 bold = true,
440 shadow = true
441 }
442 },
443 },
444
445 wareinfo = {
446 -- TODO(GunChleoc): This design is ugly.
447 -- Group stuff more logically once everything has been styled.
448 normal = {
449 fonts = {
450 header = {
451 color = wui_font_color,
452 face = "sans",
453 size = 11,
454 },
455 info = {
456 color = wui_font_color,
457 face = "condensed",
458 size = 10,
459 },
460 },
461 colors = {
462 icon_frame = { 69, 69, 69 },
463 icon_background = { 69, 69, 69 },
464 info_background = { 0, 0, 0 },
465 },
466 icon_background_image = "images/wui/ware_list_bg.png",
467 },
468 highlight = {
469 fonts = {
470 header = {
471 color = wui_font_color,
472 face = "sans",
473 size = 11,
474 },
475 info = {
476 color = wui_font_color,
477 face = "condensed",
478 size = 10,
479 },
480 },
481 colors = {
482 icon_frame = {255, 255, 0},
483 icon_background = {69, 69, 69},
484 info_background = {0, 0, 0},
485 },
486 icon_background_image = "images/wui/ware_list_bg_selected.png",
487 }
488 },
489
490 -- Font styles. Required parameters are:
491 -- * face: string
492 -- * color: table with r, g, b values as int
493 -- * size: positive int
494 -- Optional bools are: bold, italic, underline, shadow
495 fonts = {
496 -- Basic chat message text color
497 chat_message = {
498 color = wui_font_color,
499 face = "serif",
500 size = fs_font_size,
501 shadow = true,
502 },
503 -- Basic chat message text color
504 chat_timestamp = {
505 color = { 51, 255, 51 },
506 face = "serif",
507 size = 9,
508 shadow = true,
509 },
510 -- Chat for private messages
511 chat_whisper = {
512 color = { 238, 238, 238 },
513 face = "serif",
514 size = fs_font_size,
515 italic = true,
516 shadow = true,
517 },
518 -- Chat playername highlight
519 chat_playername = {
520 color = { 255, 255, 255 },
521 face = "serif",
522 size = fs_font_size,
523 bold = true,
524 shadow = true,
525 },
526 -- Chat log messages color. Also doubles as spectator playercolor for chat messages.
527 chat_server = {
528 color = { 221, 221, 221 },
529 face = "serif",
530 size = fs_font_size,
531 bold = true,
532 shadow = true,
533 },
534 -- Intro screen
535 fsmenu_intro = {
536 color = { 192, 192, 128 },
537 face = fs_font_face,
538 size = 16,
539 bold = true,
540 shadow = true
541 },
542 -- Displayed in the loading screens
543 fsmenu_gametip = {
544 color = { 33, 33, 27 },
545 face = "serif",
546 size = 16,
547 },
548 -- Game and Map info panels
549 fsmenu_info_panel_heading = {
550 color = { 255, 255, 0 },
551 face = fs_font_face,
552 size = fs_font_size,
553 bold = true,
554 shadow = true
555 },
556 fsmenu_info_panel_paragraph = {
557 color = { 209, 209, 209 },
558 face = fs_font_face,
559 size = fs_font_size,
560 shadow = true
561 },
562 -- Internet lobby and launch game
563 fsmenu_game_setup_headings = {
564 color = { 0, 255, 0 },
565 face = fs_font_face,
566 size = fs_font_size,
567 bold = true,
568 shadow = true
569 },
570 fsmenu_game_setup_mapname = {
571 color = { 255, 255, 127 },
572 face = fs_font_face,
573 size = fs_font_size,
574 bold = true,
575 shadow = true
576 },
577 -- List admin in the internet lobby
578 fsmenu_game_setup_superuser = {
579 color = { 0, 255, 0 },
580 face = fs_font_face,
581 size = fs_font_size,
582 bold = true,
583 shadow = true
584 },
585 -- List IRC clients in the internet lobby
586 fsmenu_game_setup_irc_client = {
587 color = { 221, 221, 221 },
588 face = fs_font_face,
589 size = fs_font_size,
590 bold = true,
591 shadow = true
592 },
593 -- Page titles. Also used in game summary TODO(GunChleoc): Refactor game summary
594 fsmenu_title = {
595 color = fs_font_color,
596 face = fs_font_face,
597 size = 22,
598 bold = true,
599 shadow = true
600 },
601 -- Make font a bit smaller so the link will fit at 800x600 resolution.
602 fsmenu_translation_info = {
603 color = fs_font_color,
604 face = fs_font_face,
605 size = fs_font_size - 2,
606 bold = true,
607 shadow = true
608 },
609
610 -- Textarea default style, also used for sliders, checkboxes, both in fsmenu and wui ...
611 label = default_ui_font,
612 tooltip = {
613 color = fs_font_color,
614 face = fs_font_face,
615 size = 14,
616 bold = false,
617 },
618 tooltip_header = {
619 color = fs_font_color,
620 face = fs_font_face,
621 size = 16,
622 bold = true,
623 },
624 warning = {
625 color = {255, 22, 22},
626 face = fs_font_face,
627 size = fs_font_size,
628 bold = true,
629 shadow = true
630 },
631 disabled = {
632 color = {127, 127, 127},
633 face = fs_font_face,
634 size = fs_font_size,
635 bold = true,
636 shadow = true
637 },
638
639 wui_attack_box_slider_label = {
640 color = wui_font_color,
641 face = wui_font_face,
642 size = 10,
643 bold = true,
644 shadow = true
645 },
646 wui_info_panel_heading = {
647 color = { 209, 209, 209 },
648 face = wui_font_face,
649 size = wui_font_size,
650 bold = true,
651 },
652 wui_info_panel_paragraph = {
653 color = { 255, 255, 0 },
654 face = wui_font_face,
655 size = wui_font_size,
656 },
657 -- Messages
658 wui_message_heading = {
659 color = { 209, 209, 209 },
660 face = wui_font_face,
661 size = 18,
662 bold = true,
663 },
664 wui_message_paragraph = {
665 color = { 255, 255, 0 },
666 face = wui_font_face,
667 size = 12,
668 },
669 wui_window_title = {
670 color = fs_font_color,
671 face = wui_font_face,
672 size = 13,
673 bold=true,
674 shadow=true,
675 },
676 wui_game_speed_and_coordinates = {
677 color = wui_font_color,
678 face = "condensed",
679 size = wui_font_size,
680 bold = true,
681 shadow = true
682 },
683 },
101}684}
102685
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2019-05-05 18:53:14 +0000
+++ src/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -107,7 +107,6 @@
107 graphic107 graphic
108 graphic_fonthandler108 graphic_fonthandler
109 graphic_text109 graphic_text
110 graphic_text_constants
111 helper110 helper
112 io_filesystem111 io_filesystem
113 logic112 logic
114113
=== modified file 'src/editor/tools/info_tool.cc'
--- src/editor/tools/info_tool.cc 2019-04-09 16:43:49 +0000
+++ src/editor/tools/info_tool.cc 2019-05-26 02:00:17 +0000
@@ -39,7 +39,8 @@
39 EditorActionArgs* /* args */,39 EditorActionArgs* /* args */,
40 Widelands::Map* map) {40 Widelands::Map* map) {
4141
42 static constexpr int kListFontsize = UI_FONT_SIZE_MESSAGE;42 constexpr UI::FontStyle font_style = UI::FontStyle::kWuiInfoPanelParagraph;
43
43 parent.stop_painting();44 parent.stop_painting();
4445
45 UI::Window* const w =46 UI::Window* const w =
@@ -53,7 +54,7 @@
53 std::string buf = as_heading(_("Node"), UI::PanelStyle::kWui, true);54 std::string buf = as_heading(_("Node"), UI::PanelStyle::kWui, true);
54 buf += as_listitem(55 buf += as_listitem(
55 (boost::format(_("Coordinates: (%1$i, %2$i)")) % center.node.x % center.node.y).str(),56 (boost::format(_("Coordinates: (%1$i, %2$i)")) % center.node.x % center.node.y).str(),
56 kListFontsize);57 font_style);
5758
58 std::vector<std::string> caps_strings;59 std::vector<std::string> caps_strings;
59 Widelands::NodeCaps const caps = f.nodecaps();60 Widelands::NodeCaps const caps = f.nodecaps();
@@ -100,15 +101,15 @@
100 buf += as_listitem((boost::format(_("Caps: %s")) %101 buf += as_listitem((boost::format(_("Caps: %s")) %
101 i18n::localize_list(caps_strings, i18n::ConcatenateWith::COMMA))102 i18n::localize_list(caps_strings, i18n::ConcatenateWith::COMMA))
102 .str(),103 .str(),
103 kListFontsize);104 font_style);
104105
105 if (f.get_owned_by() > 0) {106 if (f.get_owned_by() > 0) {
106 buf += as_listitem(107 buf += as_listitem(
107 (boost::format(_("Owned by: Player %u")) % static_cast<unsigned int>(f.get_owned_by()))108 (boost::format(_("Owned by: Player %u")) % static_cast<unsigned int>(f.get_owned_by()))
108 .str(),109 .str(),
109 kListFontsize);110 font_style);
110 } else {111 } else {
111 buf += as_listitem(_("Owned by: —"), kListFontsize);112 buf += as_listitem(_("Owned by: —"), font_style);
112 }113 }
113114
114 // *** Terrain info115 // *** Terrain info
@@ -119,7 +120,7 @@
119 center.triangle.t == Widelands::TriangleIndex::D ? tf.terrain_d() : tf.terrain_r());120 center.triangle.t == Widelands::TriangleIndex::D ? tf.terrain_d() : tf.terrain_r());
120121
121 buf += as_listitem(122 buf += as_listitem(
122 (boost::format(pgettext("terrain_name", "Name: %s")) % ter.descname()).str(), kListFontsize);123 (boost::format(pgettext("terrain_name", "Name: %s")) % ter.descname()).str(), font_style);
123124
124 std::vector<std::string> terrain_is_strings;125 std::vector<std::string> terrain_is_strings;
125 for (const Widelands::TerrainDescription::Type& terrain_type : ter.get_types()) {126 for (const Widelands::TerrainDescription::Type& terrain_type : ter.get_types()) {
@@ -132,10 +133,10 @@
132 (boost::format(_("Is: %s")) %133 (boost::format(_("Is: %s")) %
133 i18n::localize_list(terrain_is_strings, i18n::ConcatenateWith::AMPERSAND))134 i18n::localize_list(terrain_is_strings, i18n::ConcatenateWith::AMPERSAND))
134 .str(),135 .str(),
135 kListFontsize);136 font_style);
136 buf += as_listitem(137 buf += as_listitem(
137 (boost::format(_("Editor Category: %s")) % ter.editor_category()->descname()).str(),138 (boost::format(_("Editor Category: %s")) % ter.editor_category()->descname()).str(),
138 kListFontsize);139 font_style);
139140
140 // *** Map Object info141 // *** Map Object info
141 const Widelands::BaseImmovable* immovable = f.get_immovable();142 const Widelands::BaseImmovable* immovable = f.get_immovable();
@@ -146,7 +147,7 @@
146 if (immovable) {147 if (immovable) {
147 buf +=148 buf +=
148 as_listitem((boost::format(_("Immovable: %s")) % immovable->descr().descname()).str(),149 as_listitem((boost::format(_("Immovable: %s")) % immovable->descr().descname()).str(),
149 kListFontsize);150 font_style);
150 }151 }
151152
152 if (bob) {153 if (bob) {
@@ -179,19 +180,19 @@
179 buf += as_listitem((boost::format(_("Animals: %s")) %180 buf += as_listitem((boost::format(_("Animals: %s")) %
180 i18n::localize_list(critternames, i18n::ConcatenateWith::COMMA))181 i18n::localize_list(critternames, i18n::ConcatenateWith::COMMA))
181 .str(),182 .str(),
182 kListFontsize);183 font_style);
183 }184 }
184 if (!workernames.empty()) {185 if (!workernames.empty()) {
185 buf += as_listitem((boost::format(_("Workers: %s")) %186 buf += as_listitem((boost::format(_("Workers: %s")) %
186 i18n::localize_list(workernames, i18n::ConcatenateWith::COMMA))187 i18n::localize_list(workernames, i18n::ConcatenateWith::COMMA))
187 .str(),188 .str(),
188 kListFontsize);189 font_style);
189 }190 }
190 if (!shipnames.empty()) {191 if (!shipnames.empty()) {
191 buf += as_listitem((boost::format(_("Ships: %s")) %192 buf += as_listitem((boost::format(_("Ships: %s")) %
192 i18n::localize_list(shipnames, i18n::ConcatenateWith::COMMA))193 i18n::localize_list(shipnames, i18n::ConcatenateWith::COMMA))
193 .str(),194 .str(),
194 kListFontsize);195 font_style);
195 }196 }
196 }197 }
197 }198 }
@@ -204,28 +205,28 @@
204 (boost::format(pgettext("resources", "%1%x %2%")) % static_cast<unsigned int>(ramount) %205 (boost::format(pgettext("resources", "%1%x %2%")) % static_cast<unsigned int>(ramount) %
205 world.get_resource(f.get_resources())->descname())206 world.get_resource(f.get_resources())->descname())
206 .str(),207 .str(),
207 kListFontsize);208 font_style);
208 }209 }
209210
210 // *** Map info211 // *** Map info
211 buf += as_heading(_("Map"), UI::PanelStyle::kWui);212 buf += as_heading(_("Map"), UI::PanelStyle::kWui);
212 buf += as_listitem(213 buf += as_listitem(
213 (boost::format(pgettext("map_name", "Name: %s")) % map->get_name()).str(), kListFontsize);214 (boost::format(pgettext("map_name", "Name: %s")) % map->get_name()).str(), font_style);
214 buf += as_listitem(215 buf += as_listitem(
215 (boost::format(_("Size: %1% x %2%")) % map->get_width() % map->get_height()).str(),216 (boost::format(_("Size: %1% x %2%")) % map->get_width() % map->get_height()).str(),
216 kListFontsize);217 font_style);
217218
218 if (map->get_nrplayers() > 0) {219 if (map->get_nrplayers() > 0) {
219 buf += as_listitem(220 buf += as_listitem(
220 (boost::format(_("Players: %u")) % static_cast<unsigned int>(map->get_nrplayers())).str(),221 (boost::format(_("Players: %u")) % static_cast<unsigned int>(map->get_nrplayers())).str(),
221 kListFontsize);222 font_style);
222 } else {223 } else {
223 buf += as_listitem(_("Players: –"), kListFontsize);224 buf += as_listitem(_("Players: –"), font_style);
224 }225 }
225226
226 buf += as_listitem((boost::format(_("Author: %s")) % map->get_author()).str(), kListFontsize);227 buf += as_listitem((boost::format(_("Author: %s")) % map->get_author()).str(), font_style);
227 buf += as_listitem(228 buf += as_listitem(
228 (boost::format(_("Description: %s")) % map->get_description()).str(), kListFontsize);229 (boost::format(_("Description: %s")) % map->get_description()).str(), font_style);
229230
230 multiline_textarea->set_text(as_richtext(buf));231 multiline_textarea->set_text(as_richtext(buf));
231232
232233
=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc'
--- src/editor/ui_menus/main_menu_load_or_save_map.cc 2019-04-18 16:50:35 +0000
+++ src/editor/ui_menus/main_menu_load_or_save_map.cc 2019-05-26 02:00:17 +0000
@@ -55,7 +55,7 @@
55 get_inner_w() - right_column_x_ - padding_,55 get_inner_w() - right_column_x_ - padding_,
56 tableh_,56 tableh_,
57 UI::PanelStyle::kWui),57 UI::PanelStyle::kWui),
58 directory_info_(this, padding_, get_inner_h() - 2 * buth_ - 4 * padding_),58 directory_info_(this, padding_, get_inner_h() - 2 * buth_ - 4 * padding_, 0, 0),
59 ok_(this,59 ok_(this,
60 "ok",60 "ok",
61 UI::g_fh->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ :61 UI::g_fh->fontset()->is_rtl() ? get_inner_w() / 2 - butw_ - padding_ :
6262
=== modified file 'src/editor/ui_menus/main_menu_map_options.cc'
--- src/editor/ui_menus/main_menu_map_options.cc 2019-02-23 11:00:49 +0000
+++ src/editor/ui_menus/main_menu_map_options.cc 2019-05-26 02:00:17 +0000
@@ -28,6 +28,7 @@
28#include "editor/editorinteractive.h"28#include "editor/editorinteractive.h"
29#include "graphic/font_handler.h"29#include "graphic/font_handler.h"
30#include "graphic/graphic.h"30#include "graphic/graphic.h"
31#include "graphic/text_layout.h"
31#include "logic/map.h"32#include "logic/map.h"
32#include "ui_basic/editbox.h"33#include "ui_basic/editbox.h"
33#include "ui_basic/multilineeditbox.h"34#include "ui_basic/multilineeditbox.h"
@@ -45,7 +46,7 @@
45 : UI::Window(&parent, "map_options", 0, 0, 350, parent.get_inner_h() - 80, _("Map Options")),46 : UI::Window(&parent, "map_options", 0, 0, 350, parent.get_inner_h() - 80, _("Map Options")),
46 padding_(4),47 padding_(4),
47 indent_(10),48 indent_(10),
48 labelh_(text_height() + 4),49 labelh_(text_height(UI::FontStyle::kLabel) + 4),
49 checkbox_space_(25),50 checkbox_space_(25),
50 butw_((get_inner_w() - 3 * padding_) / 2),51 butw_((get_inner_w() - 3 * padding_) / 2),
51 max_w_(get_inner_w() - 2 * padding_),52 max_w_(get_inner_w() - 2 * padding_),
@@ -72,8 +73,8 @@
72 tags_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),73 tags_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),
73 teams_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),74 teams_box_(&tabs_, padding_, padding_, UI::Box::Vertical, max_w_, get_inner_h(), 0),
7475
75 name_(&main_box_, 0, 0, max_w_, 0, 2, UI::PanelStyle::kWui),76 name_(&main_box_, 0, 0, max_w_, UI::PanelStyle::kWui),
76 author_(&main_box_, 0, 0, max_w_, 0, 2, UI::PanelStyle::kWui),77 author_(&main_box_, 0, 0, max_w_, UI::PanelStyle::kWui),
77 size_(&main_box_, 0, 0, max_w_ - indent_, labelh_, ""),78 size_(&main_box_, 0, 0, max_w_ - indent_, labelh_, ""),
7879
79 teams_list_(80 teams_list_(
8081
=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
--- src/editor/ui_menus/main_menu_random_map.cc 2019-04-24 07:09:29 +0000
+++ src/editor/ui_menus/main_menu_random_map.cc 2019-05-26 02:00:17 +0000
@@ -32,6 +32,7 @@
32#include "editor/editorinteractive.h"32#include "editor/editorinteractive.h"
33#include "editor/map_generator.h"33#include "editor/map_generator.h"
34#include "graphic/font_handler.h"34#include "graphic/font_handler.h"
35#include "graphic/text_layout.h"
35#include "logic/editor_game_base.h"36#include "logic/editor_game_base.h"
36#include "logic/map.h"37#include "logic/map.h"
37#include "logic/map_objects/world/world.h"38#include "logic/map_objects/world/world.h"
@@ -51,7 +52,7 @@
51 // UI elements52 // UI elements
52 margin_(4),53 margin_(4),
53 box_width_(get_inner_w() - 2 * margin_),54 box_width_(get_inner_w() - 2 * margin_),
54 label_height_(text_height() + 2),55 label_height_(text_height(UI::FontStyle::kLabel) + 2),
55 box_(this, margin_, margin_, UI::Box::Vertical, 0, 0, margin_),56 box_(this, margin_, margin_, UI::Box::Vertical, 0, 0, margin_),
56 // Size57 // Size
57 width_(&box_,58 width_(&box_,
@@ -108,8 +109,8 @@
108 resource_amount_(2),109 resource_amount_(2),
109 world_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),110 world_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
110 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),111 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
111 world_label_(&world_box_, 0, 0, _("Climate:")),112 world_label_(&world_box_, 0, 0, 0, 0, _("Climate:")),
112 resources_label_(&resources_box_, 0, 0, _("Resources:")),113 resources_label_(&resources_box_, 0, 0, 0, 0, _("Resources:")),
113 world_(&world_box_,114 world_(&world_box_,
114 "world",115 "world",
115 0,116 0,
@@ -171,7 +172,7 @@
171 UI::SpinBox::Type::kSmall,172 UI::SpinBox::Type::kSmall,
172 5),173 5),
173 mountains_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),174 mountains_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
174 mountains_label_(&mountains_box_, 0, 0, _("Mountains:")),175 mountains_label_(&mountains_box_, 0, 0, 0, 0, _("Mountains:")),
175 mountains_(&mountains_box_,176 mountains_(&mountains_box_,
176 0,177 0,
177 0,178 0,
@@ -182,22 +183,18 @@
182 island_mode_(&box_, Vector2i::zero(), _("Island mode")),183 island_mode_(&box_, Vector2i::zero(), _("Island mode")),
183 // Geeky stuff184 // Geeky stuff
184 map_number_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),185 map_number_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
185 map_number_label_(&map_number_box_, 0, 0, _("Random number:")),186 map_number_label_(&map_number_box_, 0, 0, 0, 0, _("Random number:")),
186 map_number_edit_(&map_number_box_,187 map_number_edit_(&map_number_box_,
187 0,188 0,
188 0,189 0,
189 box_width_ - 2 * margin_ - map_number_label_.get_w(),190 box_width_ - 2 * margin_ - map_number_label_.get_w(),
190 0,
191 2,
192 UI::PanelStyle::kWui),191 UI::PanelStyle::kWui),
193 map_id_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),192 map_id_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
194 map_id_label_(&map_id_box_, 0, 0, _("Map ID:")),193 map_id_label_(&map_id_box_, 0, 0, 0, 0, _("Map ID:")),
195 map_id_edit_(&map_id_box_,194 map_id_edit_(&map_id_box_,
196 0,195 0,
197 0,196 0,
198 box_width_ - 2 * margin_ - map_id_label_.get_w(),197 box_width_ - 2 * margin_ - map_id_label_.get_w(),
199 0,
200 2,
201 UI::PanelStyle::kWui),198 UI::PanelStyle::kWui),
202 // Buttons199 // Buttons
203 button_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),200 button_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_),
204201
=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
--- src/editor/ui_menus/main_menu_save_map.cc 2019-03-18 21:10:56 +0000
+++ src/editor/ui_menus/main_menu_save_map.cc 2019-05-26 02:00:17 +0000
@@ -83,7 +83,7 @@
8383
84 editbox_ = new UI::EditBox(84 editbox_ = new UI::EditBox(
85 this, editbox_label_.get_x() + editbox_label_.get_w() + padding_, editbox_label_.get_y(),85 this, editbox_label_.get_x() + editbox_label_.get_w() + padding_, editbox_label_.get_y(),
86 tablew_ - editbox_label_.get_w() - padding_ + 1, buth_, 2, UI::PanelStyle::kWui);86 tablew_ - editbox_label_.get_w() - padding_ + 1, UI::PanelStyle::kWui);
87 editbox_->set_text(parent.egbase().map().get_name());87 editbox_->set_text(parent.egbase().map().get_name());
8888
89 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));89 editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));
9090
=== modified file 'src/editor/ui_menus/main_menu_save_map_make_directory.cc'
--- src/editor/ui_menus/main_menu_save_map_make_directory.cc 2019-02-23 11:00:49 +0000
+++ src/editor/ui_menus/main_menu_save_map_make_directory.cc 2019-05-26 02:00:17 +0000
@@ -41,7 +41,7 @@
41 get_inner_h() - 3 * padding_ - buth_,41 get_inner_h() - 3 * padding_ - buth_,
42 padding_ / 2),42 padding_ / 2),
43 label_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, buth_, _("Enter Directory Name:")),43 label_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, buth_, _("Enter Directory Name:")),
44 edit_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, 0, 4, UI::PanelStyle::kWui),44 edit_(&vbox_, 0, 0, get_inner_w() - 2 * padding_, UI::PanelStyle::kWui),
45 ok_button_(this,45 ok_button_(this,
46 "ok",46 "ok",
47 UI::g_fh->fontset()->is_rtl() ? padding_ : get_inner_w() - butw_ - padding_,47 UI::g_fh->fontset()->is_rtl() ? padding_ : get_inner_w() - butw_ - padding_,
4848
=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc 2019-02-27 19:00:36 +0000
+++ src/editor/ui_menus/player_menu.cc 2019-05-26 02:00:17 +0000
@@ -160,13 +160,11 @@
160 UI::Box* row = new UI::Box(&box_, 0, 0, UI::Box::Horizontal);160 UI::Box* row = new UI::Box(&box_, 0, 0, UI::Box::Horizontal);
161161
162 // Name162 // Name
163 UI::EditBox* plr_name = new UI::EditBox(row, 0, 0, 0, 0, kMargin, UI::PanelStyle::kWui);163 UI::EditBox* plr_name = new UI::EditBox(row, 0, 0, 0, UI::PanelStyle::kWui);
164 if (map_has_player) {164 if (map_has_player) {
165 plr_name->set_text(map.get_scenario_player_name(p));165 plr_name->set_text(map.get_scenario_player_name(p));
166 }166 }
167 plr_name->changed.connect(boost::bind(&EditorPlayerMenu::name_changed, this, p - 1));167 plr_name->changed.connect(boost::bind(&EditorPlayerMenu::name_changed, this, p - 1));
168 row->add(plr_name, UI::Box::Resizing::kFillSpace);
169 row->add_space(kMargin);
170168
171 // Tribe169 // Tribe
172 UI::Dropdown<std::string>* plr_tribe =170 UI::Dropdown<std::string>* plr_tribe =
@@ -189,8 +187,6 @@
189 "");187 "");
190 plr_tribe->selected.connect(188 plr_tribe->selected.connect(
191 boost::bind(&EditorPlayerMenu::player_tribe_clicked, boost::ref(*this), p - 1));189 boost::bind(&EditorPlayerMenu::player_tribe_clicked, boost::ref(*this), p - 1));
192 row->add(plr_tribe);
193 row->add_space(kMargin);
194190
195 // Starting position191 // Starting position
196 const Image* player_image =192 const Image* player_image =
@@ -204,8 +200,17 @@
204 player_image, _("Set this player’s starting position"));200 player_image, _("Set this player’s starting position"));
205 plr_position->sigclicked.connect(201 plr_position->sigclicked.connect(
206 boost::bind(&EditorPlayerMenu::set_starting_pos_clicked, boost::ref(*this), p));202 boost::bind(&EditorPlayerMenu::set_starting_pos_clicked, boost::ref(*this), p));
203
204 // Add the elements to the row
205 row->add(plr_name, UI::Box::Resizing::kFillSpace);
206 row->add_space(kMargin);
207
208 row->add(plr_tribe);
209 row->add_space(kMargin);
210
207 row->add(plr_position);211 row->add(plr_position);
208212
213 // Add the row itself
209 box_.add(row, UI::Box::Resizing::kFullSize);214 box_.add(row, UI::Box::Resizing::kFullSize);
210 box_.add_space(kMargin);215 box_.add_space(kMargin);
211 row->set_visible(map_has_player);216 row->set_visible(map_has_player);
@@ -227,7 +232,7 @@
227 assert(!rows_.empty());232 assert(!rows_.empty());
228 const Widelands::PlayerNumber nr_players = eia().egbase().map().get_nrplayers();233 const Widelands::PlayerNumber nr_players = eia().egbase().map().get_nrplayers();
229 box_.set_size(310, no_of_players_.get_h() + kMargin +234 box_.set_size(310, no_of_players_.get_h() + kMargin +
230 nr_players * (rows_.front()->tribe->get_h() + kMargin));235 nr_players * (rows_.front()->name->get_h() + kMargin));
231 set_inner_size(box_.get_w() + 2 * kMargin, box_.get_h() + 2 * kMargin);236 set_inner_size(box_.get_w() + 2 * kMargin, box_.get_h() + 2 * kMargin);
232}237}
233238
@@ -319,10 +324,10 @@
319 // Signal player position states via button states324 // Signal player position states via button states
320 iterate_player_numbers(pn, map->get_nrplayers()) {325 iterate_player_numbers(pn, map->get_nrplayers()) {
321 if (pn == row) {326 if (pn == row) {
322 rows_.at(pn - 1)->position->set_background_style(UI::ButtonStyle::kWuiPrimary);327 rows_.at(pn - 1)->position->set_style(UI::ButtonStyle::kWuiPrimary);
323 rows_.at(pn - 1)->position->set_perm_pressed(true);328 rows_.at(pn - 1)->position->set_perm_pressed(true);
324 } else {329 } else {
325 rows_.at(pn - 1)->position->set_background_style(UI::ButtonStyle::kWuiSecondary);330 rows_.at(pn - 1)->position->set_style(UI::ButtonStyle::kWuiSecondary);
326 rows_.at(pn - 1)->position->set_perm_pressed(map->get_starting_pos(pn) !=331 rows_.at(pn - 1)->position->set_perm_pressed(map->get_starting_pos(pn) !=
327 Widelands::Coords::null());332 Widelands::Coords::null());
328 }333 }
329334
=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2019-02-27 19:00:36 +0000
+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2019-05-26 02:00:17 +0000
@@ -73,7 +73,7 @@
73 UI::SpinBox::Units::kNone,73 UI::SpinBox::Units::kNone,
74 UI::SpinBox::Type::kSmall),74 UI::SpinBox::Type::kSmall),
75 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, 1),75 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, 1),
76 cur_selection_(&box_, 0, 0, "", UI::Align::kCenter) {76 cur_selection_(&box_, 0, 0, 0, 0, "", UI::Align::kCenter) {
77 // Configure spin boxes77 // Configure spin boxes
78 change_by_.set_tooltip(78 change_by_.set_tooltip(
79 /** TRANSLATORS: Editor change rseources access keys. **/79 /** TRANSLATORS: Editor change rseources access keys. **/
8080
=== modified file 'src/graphic/CMakeLists.txt'
--- src/graphic/CMakeLists.txt 2019-05-11 10:22:57 +0000
+++ src/graphic/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -1,3 +1,4 @@
1add_subdirectory(styles)
1add_subdirectory(text)2add_subdirectory(text)
23
3# TODO(sirver): Separate this directory into a base directory and one4# TODO(sirver): Separate this directory into a base directory and one
@@ -5,20 +6,12 @@
56
6# Align and color7# Align and color
78
8
9wl_library(graphic_styles
10 SRCS
11 panel_styles.cc
12 panel_styles.h
13 DEPENDS
14 graphic_color
15 graphic_surface
16)
17
18wl_library(graphic_align9wl_library(graphic_align
19 SRCS10 SRCS
20 align.h11 align.h
21 align.cc12 align.cc
13 DEPENDS
14 base_geometry
22)15)
2316
24wl_library(graphic_color17wl_library(graphic_color
@@ -269,12 +262,6 @@
269 graphic_text262 graphic_text
270)263)
271264
272wl_library(graphic_text_constants
273 SRCS
274 text_constants.h
275 text_constants.cc
276)
277
278wl_library(graphic_text_layout265wl_library(graphic_text_layout
279 SRCS266 SRCS
280 text_layout.cc267 text_layout.cc
@@ -284,8 +271,8 @@
284 graphic_align271 graphic_align
285 graphic_color272 graphic_color
286 graphic_surface273 graphic_surface
274 graphic_styles
287 graphic_text275 graphic_text
288 graphic_text_constants
289 graphic_fonthandler276 graphic_fonthandler
290 graphic_styles277 graphic_styles
291)278)
@@ -304,7 +291,6 @@
304 graphic_color291 graphic_color
305 graphic_fonthandler292 graphic_fonthandler
306 graphic_text293 graphic_text
307 graphic_text_constants
308 graphic_text_layout294 graphic_text_layout
309)295)
310296
@@ -343,7 +329,6 @@
343 graphic_render_queue329 graphic_render_queue
344 graphic_styles330 graphic_styles
345 graphic_surface331 graphic_surface
346 graphic_text_layout
347 io_filesystem332 io_filesystem
348 io_stream333 io_stream
349 logic_constants334 logic_constants
@@ -355,3 +340,4 @@
355 scripting_lua_table340 scripting_lua_table
356 sound341 sound
357)342)
343
358344
=== modified file 'src/graphic/align.cc'
--- src/graphic/align.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/align.cc 2019-05-26 02:00:17 +0000
@@ -19,4 +19,51 @@
1919
20#include "graphic/align.h"20#include "graphic/align.h"
2121
22// Dummy22namespace UI {
23
24/**
25 * Align pt horizontally to match align based on width w.
26 *
27 * When correcting for align, we never move from pixel boundaries to
28 * sub-pixels, because this might lead from pixel-perfect rendering to
29 * subsampled rendering - this can lead to blurry texts. That is why we
30 * never do float divisions in this function.
31 */
32void correct_for_align(Align align, uint32_t w, Vector2i* pt) {
33 if (align == Align::kCenter) {
34 pt->x -= w / 2;
35 } else if (align == Align::kRight) {
36 pt->x -= w;
37 }
38}
39
40/**
41 * Adjust the y coordinate in 'point 'pt' to vertically center an element with height 'h'.
42 */
43void center_vertically(uint32_t h, Vector2i* pt) {
44 pt->y -= h / 2;
45}
46
47
48/**
49 * This mirrors the horizontal alignment for RTL languages.
50 *
51 * Do not store this value as it is based on the global font setting.
52 */
53Align mirror_alignment(Align alignment, bool is_rtl) {
54 if (is_rtl) {
55 switch (alignment) {
56 case Align::kLeft:
57 alignment = Align::kRight;
58 break;
59 case Align::kRight:
60 alignment = Align::kLeft;
61 break;
62 case Align::kCenter:
63 break;
64 }
65 }
66 return alignment;
67}
68
69} // namespace UI
2370
=== modified file 'src/graphic/align.h'
--- src/graphic/align.h 2019-02-23 11:00:49 +0000
+++ src/graphic/align.h 2019-05-26 02:00:17 +0000
@@ -20,6 +20,10 @@
20#ifndef WL_GRAPHIC_ALIGN_H20#ifndef WL_GRAPHIC_ALIGN_H
21#define WL_GRAPHIC_ALIGN_H21#define WL_GRAPHIC_ALIGN_H
2222
23#include <string>
24
25#include "base/vector.h"
26
23namespace UI {27namespace UI {
2428
25// TODO(GunChleoc): Step 1: Clean up superfluous usages of kLeft/kTop, especially with dalls to29// TODO(GunChleoc): Step 1: Clean up superfluous usages of kLeft/kTop, especially with dalls to
@@ -33,5 +37,9 @@
33 kTop = kLeft,37 kTop = kLeft,
34 kBottom = kRight,38 kBottom = kRight,
35};39};
40
41void center_vertically(uint32_t h, Vector2i* pt);
42void correct_for_align(Align, uint32_t w, Vector2i* pt);
43Align mirror_alignment(Align alignment, bool is_rtl);
36} // namespace UI44} // namespace UI
37#endif // end of include guard: WL_GRAPHIC_ALIGN_H45#endif // end of include guard: WL_GRAPHIC_ALIGN_H
3846
=== modified file 'src/graphic/font_handler.cc'
--- src/graphic/font_handler.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/font_handler.cc 2019-05-26 02:00:17 +0000
@@ -87,7 +87,7 @@
87 const std::string hash = boost::lexical_cast<std::string>(w) + text;87 const std::string hash = boost::lexical_cast<std::string>(w) + text;
88 std::shared_ptr<const RenderedText> rendered_text = render_cache_->get(hash);88 std::shared_ptr<const RenderedText> rendered_text = render_cache_->get(hash);
89 if (rendered_text == nullptr) {89 if (rendered_text == nullptr) {
90 rendered_text = render_cache_->insert(hash, rt_renderer_->render(text, w));90 rendered_text = render_cache_->insert(hash, rt_renderer_->render(text, w, fontset()->is_rtl()));
91 }91 }
92 return rendered_text;92 return rendered_text;
93 }93 }
9494
=== modified file 'src/graphic/graphic.cc'
--- src/graphic/graphic.cc 2019-02-28 08:02:18 +0000
+++ src/graphic/graphic.cc 2019-05-26 02:00:17 +0000
@@ -35,7 +35,6 @@
35#include "graphic/render_queue.h"35#include "graphic/render_queue.h"
36#include "graphic/rendertarget.h"36#include "graphic/rendertarget.h"
37#include "graphic/screen.h"37#include "graphic/screen.h"
38#include "graphic/text_layout.h"
39#include "graphic/texture.h"38#include "graphic/texture.h"
40#include "io/filesystem/layered_filesystem.h"39#include "io/filesystem/layered_filesystem.h"
41#include "io/streamwrite.h"40#include "io/streamwrite.h"
4241
=== removed file 'src/graphic/panel_styles.cc'
--- src/graphic/panel_styles.cc 2017-06-12 11:07:47 +0000
+++ src/graphic/panel_styles.cc 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1// Dummy to make CMake happy
20
=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc 2019-04-24 06:32:02 +0000
+++ src/graphic/rendertarget.cc 2019-05-26 02:00:17 +0000
@@ -20,10 +20,10 @@
20#include "graphic/rendertarget.h"20#include "graphic/rendertarget.h"
2121
22#include "base/macros.h"22#include "base/macros.h"
23#include "graphic/align.h"
23#include "graphic/animation.h"24#include "graphic/animation.h"
24#include "graphic/graphic.h"25#include "graphic/graphic.h"
25#include "graphic/surface.h"26#include "graphic/surface.h"
26#include "graphic/text_layout.h"
2727
28/**28/**
29 * Build a render target for the given surface.29 * Build a render target for the given surface.
3030
=== modified file 'src/graphic/style_manager.cc'
--- src/graphic/style_manager.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/style_manager.cc 2019-05-26 02:00:17 +0000
@@ -21,21 +21,55 @@
2121
22#include <memory>22#include <memory>
2323
24#include <boost/format.hpp>
25
24#include "base/scoped_timer.h"26#include "base/scoped_timer.h"
25#include "base/wexception.h"27#include "base/wexception.h"
26#include "graphic/graphic.h"28#include "graphic/graphic.h"
27#include "scripting/lua_interface.h"29#include "scripting/lua_interface.h"
2830
29namespace {31namespace {
30// Read image filename and RGB color from LuaTable32// Read RGB color from LuaTable
31UI::PanelStyleInfo* read_style(const LuaTable& table) {33RGBColor read_rgb_color(const LuaTable& table) {
34 std::vector<int> rgbcolor = table.array_entries<int>();
35 if (rgbcolor.size() != 3) {
36 throw wexception("Expected 3 entries for RGB color, but got %" PRIuS ".", rgbcolor.size());
37 }
38 return RGBColor(rgbcolor[0], rgbcolor[1], rgbcolor[2]);
39}
40
41// Read font style from LuaTable
42UI::FontStyleInfo* read_font_style(const LuaTable& parent_table, const std::string& table_key) {
43 std::unique_ptr<LuaTable> style_table = parent_table.get_table(table_key);
44 const int size = style_table->get_int("size");
45 if (size < 1) {
46 throw wexception("Font size %d too small for %s, must be at least 1!", size, table_key.c_str());
47 }
48 return new UI::FontStyleInfo(
49 style_table->get_string("face"),
50 read_rgb_color(*style_table->get_table("color")),
51 size,
52 style_table->has_key<std::string>("bold") ? style_table->get_bool("bold") : false,
53 style_table->has_key<std::string>("italic") ? style_table->get_bool("italic") : false,
54 style_table->has_key<std::string>("underline") ? style_table->get_bool("underline") : false,
55 style_table->has_key<std::string>("shadow") ? style_table->get_bool("shadow") : false);
56}
57
58// Read image filename and RGBA color from LuaTable
59UI::PanelStyleInfo* read_panel_style(const LuaTable& table) {
32 const std::string image = table.get_string("image");60 const std::string image = table.get_string("image");
33 std::vector<int> rgbcolor = table.get_table("color")->array_entries<int>();61 std::vector<int> rgbcolor = table.get_table("color")->array_entries<int>();
34 if (rgbcolor.size() != 3) {62 if (rgbcolor.size() != 3) {
35 throw wexception("Expected 3 entries for RGB color, but got %" PRIuS ".", rgbcolor.size());63 throw wexception("Expected 3 entries for RGB color, but got %" PRIuS ".", rgbcolor.size());
36 }64 }
37 return new UI::PanelStyleInfo(image.empty() ? nullptr : g_gr->images().get(image),65 return new UI::PanelStyleInfo(image.empty() ? nullptr : g_gr->images().get(image),
38 RGBAColor(rgbcolor[0], rgbcolor[1], rgbcolor[2], 0));66 RGBAColor(rgbcolor[0], rgbcolor[1], rgbcolor[2], 0),
67 table.has_key<std::string>("margin") ? table.get_int("margin") : 0);
68}
69
70// Read text panel style from LuaTable
71UI::TextPanelStyleInfo* read_text_panel_style(const LuaTable& table) {
72 return new UI::TextPanelStyleInfo(read_font_style(table, "font"), read_panel_style(*table.get_table("background")));
39}73}
4074
41// Stupid completeness check - enum classes weren't meant for iterating, so we just compare the size75// Stupid completeness check - enum classes weren't meant for iterating, so we just compare the size
@@ -59,45 +93,34 @@
59 dropdownstyles_.clear();93 dropdownstyles_.clear();
60 scrollbarstyles_.clear();94 scrollbarstyles_.clear();
6195
62 log("Style Manager: Loading %sinit.lua ... ", kTemplateDir.c_str());
63
64 LuaInterface lua;96 LuaInterface lua;
65 std::unique_ptr<LuaTable> table(lua.run_script(kTemplateDir + "init.lua"));97 std::unique_ptr<LuaTable> table(lua.run_script(kTemplateDir + "init.lua"));
6698
67 log("took %ums\n", timer.ms_since_last_query());
68 log("Style Manager: Reading button styles ... ");
69
70 // Buttons99 // Buttons
71 std::unique_ptr<LuaTable> element_table = table->get_table("buttons");100 std::unique_ptr<LuaTable> element_table = table->get_table("buttons");
72 std::unique_ptr<LuaTable> style_table = element_table->get_table("fsmenu");101 std::unique_ptr<LuaTable> style_table = element_table->get_table("fsmenu");
73 add_button_style(UI::ButtonStyle::kFsMenuMenu, *style_table->get_table("menu").get());102 add_button_style(UI::ButtonStyle::kFsMenuMenu, *style_table->get_table("menu"));
74 add_button_style(UI::ButtonStyle::kFsMenuPrimary, *style_table->get_table("primary").get());103 add_button_style(UI::ButtonStyle::kFsMenuPrimary, *style_table->get_table("primary"));
75 add_button_style(UI::ButtonStyle::kFsMenuSecondary, *style_table->get_table("secondary").get());104 add_button_style(UI::ButtonStyle::kFsMenuSecondary, *style_table->get_table("secondary"));
76 style_table = element_table->get_table("wui");105 style_table = element_table->get_table("wui");
77 add_button_style(UI::ButtonStyle::kWuiMenu, *style_table->get_table("menu").get());106 add_button_style(UI::ButtonStyle::kWuiMenu, *style_table->get_table("menu"));
78 add_button_style(UI::ButtonStyle::kWuiPrimary, *style_table->get_table("primary").get());107 add_button_style(UI::ButtonStyle::kWuiPrimary, *style_table->get_table("primary"));
79 add_button_style(UI::ButtonStyle::kWuiSecondary, *style_table->get_table("secondary").get());108 add_button_style(UI::ButtonStyle::kWuiSecondary, *style_table->get_table("secondary"));
80 add_button_style(109 add_button_style(
81 UI::ButtonStyle::kWuiBuildingStats, *style_table->get_table("building_stats").get());110 UI::ButtonStyle::kWuiBuildingStats, *style_table->get_table("building_stats"));
82 check_completeness(111 check_completeness(
83 "buttons", buttonstyles_.size(), static_cast<size_t>(UI::ButtonStyle::kWuiBuildingStats));112 "buttons", buttonstyles_.size(), static_cast<size_t>(UI::ButtonStyle::kWuiBuildingStats));
84113
85 log("took %ums\n", timer.ms_since_last_query());
86 log("Style Manager: Reading slider styles ... ");
87
88 // Sliders114 // Sliders
89 element_table = table->get_table("sliders");115 element_table = table->get_table("sliders");
90 style_table = element_table->get_table("fsmenu");116 style_table = element_table->get_table("fsmenu");
91 add_slider_style(UI::SliderStyle::kFsMenu, *style_table->get_table("menu").get());117 add_slider_style(UI::SliderStyle::kFsMenu, *style_table->get_table("menu"));
92 style_table = element_table->get_table("wui");118 style_table = element_table->get_table("wui");
93 add_slider_style(UI::SliderStyle::kWuiLight, *style_table->get_table("light").get());119 add_slider_style(UI::SliderStyle::kWuiLight, *style_table->get_table("light"));
94 add_slider_style(UI::SliderStyle::kWuiDark, *style_table->get_table("dark").get());120 add_slider_style(UI::SliderStyle::kWuiDark, *style_table->get_table("dark"));
95 check_completeness(121 check_completeness(
96 "sliders", sliderstyles_.size(), static_cast<size_t>(UI::SliderStyle::kWuiDark));122 "sliders", sliderstyles_.size(), static_cast<size_t>(UI::SliderStyle::kWuiDark));
97123
98 log("took %ums\n", timer.ms_since_last_query());
99 log("Style Manager: Reading tabpanel styles ... ");
100
101 // Tabpanels124 // Tabpanels
102 element_table = table->get_table("tabpanels");125 element_table = table->get_table("tabpanels");
103 style_table = element_table->get_table("fsmenu");126 style_table = element_table->get_table("fsmenu");
@@ -108,21 +131,13 @@
108 check_completeness(131 check_completeness(
109 "tabpanels", tabpanelstyles_.size(), static_cast<size_t>(UI::TabPanelStyle::kWuiDark));132 "tabpanels", tabpanelstyles_.size(), static_cast<size_t>(UI::TabPanelStyle::kWuiDark));
110133
111 log("took %ums\n", timer.ms_since_last_query());
112 log("Style Manager: Reading editbox styles ... ");
113
114 // Editboxes134 // Editboxes
115 element_table = table->get_table("editboxes");135 element_table = table->get_table("editboxes");
116 style_table = element_table->get_table("fsmenu");136 add_editbox_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
117 add_style(UI::PanelStyle::kFsMenu, *style_table->get_table("menu").get(), &editboxstyles_);137 add_editbox_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
118 style_table = element_table->get_table("wui");
119 add_style(UI::PanelStyle::kWui, *style_table->get_table("menu").get(), &editboxstyles_);
120 check_completeness(138 check_completeness(
121 "editboxes", editboxstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));139 "editboxes", editboxstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
122140
123 log("took %ums\n", timer.ms_since_last_query());
124 log("Style Manager: Reading dropdown styles ... ");
125
126 // Dropdowns141 // Dropdowns
127 element_table = table->get_table("dropdowns");142 element_table = table->get_table("dropdowns");
128 style_table = element_table->get_table("fsmenu");143 style_table = element_table->get_table("fsmenu");
@@ -132,9 +147,6 @@
132 check_completeness(147 check_completeness(
133 "dropdowns", dropdownstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));148 "dropdowns", dropdownstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
134149
135 log("took %ums\n", timer.ms_since_last_query());
136 log("Style Manager: Reading scrollbar styles ... ");
137
138 // Scrollbars150 // Scrollbars
139 element_table = table->get_table("scrollbars");151 element_table = table->get_table("scrollbars");
140 style_table = element_table->get_table("fsmenu");152 style_table = element_table->get_table("fsmenu");
@@ -144,18 +156,81 @@
144 check_completeness(156 check_completeness(
145 "scrollbars", scrollbarstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));157 "scrollbars", scrollbarstyles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
146158
147 log("took %ums\n", timer.ms_since_last_query());159 // Building statistics etc. for map objects
160 set_building_statistics_style(*table->get_table("building_statistics"));
161
162 // Progress bars
163 element_table = table->get_table("progressbar");
164 add_progressbar_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
165 add_progressbar_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
166 check_completeness(
167 "progressbars", progressbar_styles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
168
169 // Table and listselect
170 element_table = table->get_table("tables");
171 add_table_style(UI::PanelStyle::kFsMenu, *element_table->get_table("fsmenu"));
172 add_table_style(UI::PanelStyle::kWui, *element_table->get_table("wui"));
173 check_completeness(
174 "tables", table_styles_.size(), static_cast<size_t>(UI::PanelStyle::kWui));
175
176 // Statistics plot
177 set_statistics_plot_style(*table->get_table("statistics_plot"));
178
179 // Ware info in warehouses, construction actions etc.
180 element_table = table->get_table("wareinfo");
181 add_ware_info_style(UI::WareInfoStyle::kNormal, *element_table->get_table("normal"));
182 add_ware_info_style(UI::WareInfoStyle::kHighlight, *element_table->get_table("highlight"));
183 check_completeness(
184 "wareinfos", ware_info_styles_.size(), static_cast<size_t>(UI::WareInfoStyle::kHighlight));
185
186 // Special elements
187 minimum_font_size_ = table->get_int("minimum_font_size");
188 if (minimum_font_size_ < 1) {
189 throw wexception("Font size too small for minimum_font_size, must be at least 1!");
190 }
191 minimap_icon_frame_ = read_rgb_color(*table->get_table("minimap_icon_frame"));
192
193 // Fonts
194 element_table = table->get_table("fonts");
195 add_font_style(UI::FontStyle::kChatMessage, *element_table, "chat_message");
196 add_font_style(UI::FontStyle::kChatPlayername, *element_table, "chat_playername");
197 add_font_style(UI::FontStyle::kChatServer, *element_table, "chat_server");
198 add_font_style(UI::FontStyle::kChatTimestamp, *element_table, "chat_timestamp");
199 add_font_style(UI::FontStyle::kChatWhisper, *element_table, "chat_whisper");
200 add_font_style(UI::FontStyle::kFsGameSetupHeadings, *element_table, "fsmenu_game_setup_headings");
201 add_font_style(UI::FontStyle::kFsGameSetupSuperuser, *element_table, "fsmenu_game_setup_superuser");
202 add_font_style(UI::FontStyle::kFsGameSetupIrcClient, *element_table, "fsmenu_game_setup_irc_client");
203 add_font_style(UI::FontStyle::kFsGameSetupMapname, *element_table, "fsmenu_game_setup_mapname");
204 add_font_style(UI::FontStyle::kFsMenuGameTip, *element_table, "fsmenu_gametip");
205 add_font_style(UI::FontStyle::kFsMenuInfoPanelHeading, *element_table, "fsmenu_info_panel_heading");
206 add_font_style(UI::FontStyle::kFsMenuInfoPanelParagraph, *element_table, "fsmenu_info_panel_paragraph");
207 add_font_style(UI::FontStyle::kFsMenuIntro, *element_table, "fsmenu_intro");
208 add_font_style(UI::FontStyle::kFsMenuTitle, *element_table, "fsmenu_title");
209 add_font_style(UI::FontStyle::kFsMenuTranslationInfo, *element_table, "fsmenu_translation_info");
210 add_font_style(UI::FontStyle::kDisabled, *element_table, "disabled");
211 add_font_style(UI::FontStyle::kLabel, *element_table, "label");
212 add_font_style(UI::FontStyle::kTooltipHeader, *element_table, "tooltip_header");
213 add_font_style(UI::FontStyle::kTooltip, *element_table, "tooltip");
214 add_font_style(UI::FontStyle::kWarning, *element_table, "warning");
215 add_font_style(UI::FontStyle::kWuiAttackBoxSliderLabel, *element_table, "wui_attack_box_slider_label");
216 add_font_style(UI::FontStyle::kWuiGameSpeedAndCoordinates, *element_table, "wui_game_speed_and_coordinates");
217 add_font_style(UI::FontStyle::kWuiInfoPanelHeading, *element_table, "wui_info_panel_heading");
218 add_font_style(UI::FontStyle::kWuiInfoPanelParagraph, *element_table, "wui_info_panel_paragraph");
219 add_font_style(UI::FontStyle::kWuiMessageHeading, *element_table, "wui_message_heading");
220 add_font_style(UI::FontStyle::kWuiMessageParagraph, *element_table, "wui_message_paragraph");
221 add_font_style(UI::FontStyle::kWuiWindowTitle, *element_table, "wui_window_title");
222 check_completeness("fonts", fontstyles_.size(), static_cast<size_t>(UI::FontStyle::kWuiWindowTitle));
148}223}
149224
150// Return functions for the styles225// Return functions for the styles
151const UI::PanelStyleInfo* StyleManager::button_style(UI::ButtonStyle style) const {226const UI::ButtonStyleInfo& StyleManager::button_style(UI::ButtonStyle style) const {
152 assert(buttonstyles_.count(style) == 1);227 assert(buttonstyles_.count(style) == 1);
153 return buttonstyles_.at(style).get();228 return *buttonstyles_.at(style);
154}229}
155230
156const UI::PanelStyleInfo* StyleManager::slider_style(UI::SliderStyle style) const {231const UI::TextPanelStyleInfo& StyleManager::slider_style(UI::SliderStyle style) const {
157 assert(sliderstyles_.count(style) == 1);232 assert(sliderstyles_.count(style) == 1);
158 return sliderstyles_.at(style).get();233 return *sliderstyles_.at(style);
159}234}
160235
161const UI::PanelStyleInfo* StyleManager::tabpanel_style(UI::TabPanelStyle style) const {236const UI::PanelStyleInfo* StyleManager::tabpanel_style(UI::TabPanelStyle style) const {
@@ -163,9 +238,9 @@
163 return tabpanelstyles_.at(style).get();238 return tabpanelstyles_.at(style).get();
164}239}
165240
166const UI::PanelStyleInfo* StyleManager::editbox_style(UI::PanelStyle style) const {241const UI::TextPanelStyleInfo& StyleManager::editbox_style(UI::PanelStyle style) const {
167 assert(editboxstyles_.count(style) == 1);242 assert(editboxstyles_.count(style) == 1);
168 return editboxstyles_.at(style).get();243 return *editboxstyles_.at(style);
169}244}
170245
171const UI::PanelStyleInfo* StyleManager::dropdown_style(UI::PanelStyle style) const {246const UI::PanelStyleInfo* StyleManager::dropdown_style(UI::PanelStyle style) const {
@@ -178,22 +253,143 @@
178 return scrollbarstyles_.at(style).get();253 return scrollbarstyles_.at(style).get();
179}254}
180255
256const UI::BuildingStatisticsStyleInfo& StyleManager::building_statistics_style() const {
257 return *building_statistics_style_;
258}
259
260const UI::ProgressbarStyleInfo& StyleManager::progressbar_style(UI::PanelStyle style) const {
261 assert(progressbar_styles_.count(style) == 1);
262 return *progressbar_styles_.at(style);
263}
264
265const UI::StatisticsPlotStyleInfo& StyleManager::statistics_plot_style() const {
266 return *statistics_plot_style_;
267}
268
269const UI::TableStyleInfo& StyleManager::table_style(UI::PanelStyle style) const {
270 assert(table_styles_.count(style) == 1);
271 return *table_styles_.at(style);
272}
273
274const UI::WareInfoStyleInfo& StyleManager::ware_info_style(UI::WareInfoStyle style) const {
275 assert(ware_info_styles_.count(style) == 1);
276 return *ware_info_styles_.at(style);
277}
278
279const UI::FontStyleInfo& StyleManager::font_style(UI::FontStyle style) const {
280 assert(fontstyles_.count(style) == 1);
281 return *fontstyles_.at(style);
282}
283
284int StyleManager::minimum_font_size() const {
285 return minimum_font_size_;
286}
287
288const RGBColor& StyleManager::minimap_icon_frame() const {
289 return minimap_icon_frame_;
290}
291
292std::string StyleManager::color_tag(const std::string& text, const RGBColor& color) {
293 static boost::format f("<font color=%s>%s</font>");
294 f % color.hex_value();
295 f % text;
296 return f.str();
297}
298
181// Fill the maps299// Fill the maps
182void StyleManager::add_button_style(UI::ButtonStyle style, const LuaTable& table) {300void StyleManager::add_button_style(UI::ButtonStyle style, const LuaTable& table) {
183 buttonstyles_.insert(301 buttonstyles_.insert(
184 std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));302 std::make_pair(
303 style,
304 std::unique_ptr<const UI::ButtonStyleInfo>(
305 new UI::ButtonStyleInfo(
306 read_text_panel_style(*table.get_table("enabled")),
307 read_text_panel_style(*table.get_table("disabled"))))));
185}308}
186309
187void StyleManager::add_slider_style(UI::SliderStyle style, const LuaTable& table) {310void StyleManager::add_slider_style(UI::SliderStyle style, const LuaTable& table) {
188 sliderstyles_.insert(311 sliderstyles_.insert(
189 std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));312 std::make_pair(style, std::unique_ptr<UI::TextPanelStyleInfo>(read_text_panel_style(table))));
190}313}
314
315void StyleManager::add_editbox_style(UI::PanelStyle style, const LuaTable& table) {
316 editboxstyles_.insert(
317 std::make_pair(style, std::unique_ptr<UI::TextPanelStyleInfo>(read_text_panel_style(table))));
318}
319
191320
192void StyleManager::add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table) {321void StyleManager::add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table) {
193 tabpanelstyles_.insert(322 tabpanelstyles_.insert(
194 std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));323 std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_panel_style(table))));
324}
325
326void StyleManager::add_progressbar_style(UI::PanelStyle style, const LuaTable& table) {
327 std::unique_ptr<LuaTable> color_table = table.get_table("background_colors");
328 progressbar_styles_.insert(std::make_pair(
329 style,
330 std::unique_ptr<const UI::ProgressbarStyleInfo>(
331 new UI::ProgressbarStyleInfo(
332 read_font_style(table, "font"),
333 read_rgb_color(*color_table->get_table("low")),
334 read_rgb_color(*color_table->get_table("medium")),
335 read_rgb_color(*color_table->get_table("high"))))));
336}
337
338void StyleManager::add_table_style(UI::PanelStyle style, const LuaTable& table) {
339 table_styles_.insert(std::make_pair(style,
340 std::unique_ptr<const UI::TableStyleInfo>(
341 new UI::TableStyleInfo(
342 read_font_style(table, "enabled"),
343 read_font_style(table, "disabled")))));
344}
345
346void StyleManager::set_statistics_plot_style(const LuaTable& table) {
347 std::unique_ptr<LuaTable> fonts_table = table.get_table("fonts");
348 std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
349 statistics_plot_style_.reset(new UI::StatisticsPlotStyleInfo(
350 read_font_style(*fonts_table, "x_tick"),
351 read_font_style(*fonts_table, "y_min_value"),
352 read_font_style(*fonts_table, "y_max_value"),
353 read_rgb_color(*colors_table->get_table("axis_line")),
354 read_rgb_color(*colors_table->get_table("zero_line"))));
355}
356
357void StyleManager::set_building_statistics_style(const LuaTable& table) {
358 std::unique_ptr<LuaTable> window_table = table.get_table("statistics_window");
359 std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
360 std::unique_ptr<LuaTable> fonts_table = window_table->get_table("fonts");
361 building_statistics_style_.reset(new UI::BuildingStatisticsStyleInfo(
362 read_font_style(*fonts_table, "button_font"),
363 read_font_style(*fonts_table, "details_font"),
364 window_table->get_int("editbox_margin"),
365 read_font_style(table, "census_font"),
366 read_font_style(table, "statistics_font"),
367 read_rgb_color(*colors_table->get_table("construction")),
368 read_rgb_color(*colors_table->get_table("neutral")),
369 read_rgb_color(*colors_table->get_table("low")),
370 read_rgb_color(*colors_table->get_table("medium")),
371 read_rgb_color(*colors_table->get_table("high"))));
372}
373
374void StyleManager::add_ware_info_style(UI::WareInfoStyle style, const LuaTable& table) {
375 std::unique_ptr<LuaTable> fonts_table = table.get_table("fonts");
376 std::unique_ptr<LuaTable> colors_table = table.get_table("colors");
377 ware_info_styles_.insert(
378 std::make_pair(style,
379 std::unique_ptr<const UI::WareInfoStyleInfo>(
380 new UI::WareInfoStyleInfo(
381 read_font_style(*fonts_table, "header"),
382 read_font_style(*fonts_table, "info"),
383 g_gr->images().get(table.get_string("icon_background_image")),
384 read_rgb_color(*colors_table->get_table("icon_frame")),
385 read_rgb_color(*colors_table->get_table("icon_background")),
386 read_rgb_color(*colors_table->get_table("info_background"))))));
195}387}
196388
197void StyleManager::add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map) {389void StyleManager::add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map) {
198 map->insert(std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_style(table))));390 map->insert(std::make_pair(style, std::unique_ptr<UI::PanelStyleInfo>(read_panel_style(table))));
391}
392
393void StyleManager::add_font_style(UI::FontStyle font_key, const LuaTable& table, const std::string& table_key) {
394 fontstyles_.emplace(std::make_pair(font_key, std::unique_ptr<UI::FontStyleInfo>(read_font_style(table, table_key))));
199}395}
200396
=== modified file 'src/graphic/style_manager.h'
--- src/graphic/style_manager.h 2019-02-23 11:00:49 +0000
+++ src/graphic/style_manager.h 2019-05-26 02:00:17 +0000
@@ -23,7 +23,15 @@
23#include <map>23#include <map>
24#include <memory>24#include <memory>
2525
26#include "graphic/panel_styles.h"26#include "graphic/styles/building_statistics_style.h"
27#include "graphic/styles/button_style.h"
28#include "graphic/styles/font_style.h"
29#include "graphic/styles/panel_styles.h"
30#include "graphic/styles/progress_bar_style.h"
31#include "graphic/styles/statistics_plot_style.h"
32#include "graphic/styles/table_style.h"
33#include "graphic/styles/text_panel_style.h"
34#include "graphic/styles/ware_info_style.h"
27#include "scripting/lua_table.h"35#include "scripting/lua_table.h"
2836
29static const std::string kTemplateDir = "templates/default/";37static const std::string kTemplateDir = "templates/default/";
@@ -36,27 +44,54 @@
36 // Late initialization, because Graphics needs to load the image files first.44 // Late initialization, because Graphics needs to load the image files first.
37 void init();45 void init();
3846
39 const UI::PanelStyleInfo* button_style(UI::ButtonStyle) const;47 const UI::BuildingStatisticsStyleInfo& building_statistics_style() const;
40 const UI::PanelStyleInfo* slider_style(UI::SliderStyle) const;48 const UI::ButtonStyleInfo& button_style(UI::ButtonStyle) const;
49 const UI::TextPanelStyleInfo& slider_style(UI::SliderStyle) const;
41 const UI::PanelStyleInfo* tabpanel_style(UI::TabPanelStyle) const;50 const UI::PanelStyleInfo* tabpanel_style(UI::TabPanelStyle) const;
42 const UI::PanelStyleInfo* editbox_style(UI::PanelStyle) const;51 const UI::TextPanelStyleInfo& editbox_style(UI::PanelStyle) const;
43 const UI::PanelStyleInfo* dropdown_style(UI::PanelStyle) const;52 const UI::PanelStyleInfo* dropdown_style(UI::PanelStyle) const;
44 const UI::PanelStyleInfo* scrollbar_style(UI::PanelStyle) const;53 const UI::PanelStyleInfo* scrollbar_style(UI::PanelStyle) const;
54 const UI::ProgressbarStyleInfo& progressbar_style(UI::PanelStyle) const;
55 const UI::StatisticsPlotStyleInfo& statistics_plot_style() const;
56 const UI::TableStyleInfo& table_style(UI::PanelStyle) const;
57 const UI::WareInfoStyleInfo& ware_info_style(UI::WareInfoStyle) const;
58 const UI::FontStyleInfo& font_style(UI::FontStyle style) const;
59
60 // Special elements
61 int minimum_font_size() const;
62 const RGBColor& minimap_icon_frame() const;
63 static std::string color_tag(const std::string& text, const RGBColor& color);
4564
46private:65private:
47 using PanelStyleMap = std::map<UI::PanelStyle, std::unique_ptr<const UI::PanelStyleInfo>>;66 using PanelStyleMap = std::map<UI::PanelStyle, std::unique_ptr<const UI::PanelStyleInfo>>;
48 void add_button_style(UI::ButtonStyle style, const LuaTable& table);67 void add_button_style(UI::ButtonStyle style, const LuaTable& table);
49 void add_slider_style(UI::SliderStyle style, const LuaTable& table);68 void add_slider_style(UI::SliderStyle style, const LuaTable& table);
69 void add_editbox_style(UI::PanelStyle style, const LuaTable& table);
50 void add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table);70 void add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table);
71 void add_progressbar_style(UI::PanelStyle style, const LuaTable& table);
72 void add_table_style(UI::PanelStyle style, const LuaTable& table);
73 void set_statistics_plot_style(const LuaTable& table);
74 void set_building_statistics_style(const LuaTable& table);
75 void add_ware_info_style(UI::WareInfoStyle style, const LuaTable& table);
51 void add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map);76 void add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map);
77 void add_font_style(UI::FontStyle font, const LuaTable& table, const std::string& key);
5278
53 std::map<UI::ButtonStyle, std::unique_ptr<const UI::PanelStyleInfo>> buttonstyles_;79 std::map<UI::ButtonStyle, std::unique_ptr<const UI::ButtonStyleInfo>> buttonstyles_;
54 std::map<UI::SliderStyle, std::unique_ptr<const UI::PanelStyleInfo>> sliderstyles_;80 std::map<UI::PanelStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> editboxstyles_;
81 std::map<UI::SliderStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> sliderstyles_;
55 std::map<UI::TabPanelStyle, std::unique_ptr<const UI::PanelStyleInfo>> tabpanelstyles_;82 std::map<UI::TabPanelStyle, std::unique_ptr<const UI::PanelStyleInfo>> tabpanelstyles_;
56 PanelStyleMap editboxstyles_;
57 PanelStyleMap dropdownstyles_;83 PanelStyleMap dropdownstyles_;
58 PanelStyleMap scrollbarstyles_;84 PanelStyleMap scrollbarstyles_;
5985
86 int minimum_font_size_;
87 RGBColor minimap_icon_frame_;
88 std::map<UI::FontStyle, std::unique_ptr<const UI::FontStyleInfo>> fontstyles_;
89 std::unique_ptr<const UI::BuildingStatisticsStyleInfo> building_statistics_style_;
90 std::map<UI::PanelStyle, std::unique_ptr<const UI::ProgressbarStyleInfo>> progressbar_styles_;
91 std::unique_ptr<const UI::StatisticsPlotStyleInfo> statistics_plot_style_;
92 std::map<UI::PanelStyle, std::unique_ptr<const UI::TableStyleInfo>> table_styles_;
93 std::map<UI::WareInfoStyle, std::unique_ptr<const UI::WareInfoStyleInfo>> ware_info_styles_;
94
60 DISALLOW_COPY_AND_ASSIGN(StyleManager);95 DISALLOW_COPY_AND_ASSIGN(StyleManager);
61};96};
6297
6398
=== added directory 'src/graphic/styles'
=== added file 'src/graphic/styles/CMakeLists.txt'
--- src/graphic/styles/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -0,0 +1,18 @@
1wl_library(graphic_styles
2 SRCS
3 building_statistics_style.h
4 button_style.h
5 font_style.cc
6 font_style.h
7 panel_styles.h
8 progress_bar_style.h
9 text_panel_style.h
10 statistics_plot_style.h
11 table_style.h
12 ware_info_style.h
13 DEPENDS
14 base_exceptions
15 base_log
16 graphic_color
17 graphic_surface
18)
019
=== added file 'src/graphic/styles/building_statistics_style.h'
--- src/graphic/styles/building_statistics_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/building_statistics_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,99 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
21#define WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
22
23#include <memory>
24
25#include "graphic/color.h"
26#include "graphic/styles/font_style.h"
27
28namespace UI {
29
30struct BuildingStatisticsStyleInfo {
31 explicit BuildingStatisticsStyleInfo(UI::FontStyleInfo* init_building_statistics_button_font,
32 UI::FontStyleInfo* init_building_statistics_details_font,
33 int init_editbox_margin,
34 UI::FontStyleInfo* init_census,
35 UI::FontStyleInfo* init_statistics,
36 const RGBColor& init_construction_color,
37 const RGBColor& init_neutral_color,
38 const RGBColor& init_low_color,
39 const RGBColor& init_medium_color,
40 const RGBColor& init_high_color) :
41 building_statistics_button_font_(init_building_statistics_button_font),
42 building_statistics_details_font_(init_building_statistics_details_font),
43 editbox_margin_(init_editbox_margin),
44 census_font_(init_census),
45 statistics_font_(init_statistics),
46 construction_color_(init_construction_color),
47 neutral_color_(init_neutral_color),
48 low_color_(init_low_color),
49 medium_color_(init_medium_color),
50 high_color_(init_high_color) {}
51
52 const UI::FontStyleInfo& building_statistics_button_font() const {
53 return *building_statistics_button_font_.get();
54 }
55 const UI::FontStyleInfo& building_statistics_details_font() const {
56 return *building_statistics_details_font_.get();
57 }
58 int editbox_margin() const {
59 return editbox_margin_;
60 }
61
62 const UI::FontStyleInfo& census_font() const {
63 return *census_font_.get();
64 }
65 const UI::FontStyleInfo& statistics_font() const {
66 return *statistics_font_.get();
67 }
68 const RGBColor& construction_color() const {
69 return construction_color_;
70 }
71 const RGBColor& neutral_color() const {
72 return neutral_color_;
73 }
74 const RGBColor& low_color() const {
75 return low_color_;
76 }
77 const RGBColor& medium_color() const {
78 return medium_color_;
79 }
80 const RGBColor& high_color() const {
81 return high_color_;
82 }
83
84private:
85 std::unique_ptr<const UI::FontStyleInfo> building_statistics_button_font_;
86 std::unique_ptr<const UI::FontStyleInfo> building_statistics_details_font_;
87 int editbox_margin_;
88 std::unique_ptr<const UI::FontStyleInfo> census_font_;
89 std::unique_ptr<const UI::FontStyleInfo> statistics_font_;
90 const RGBColor construction_color_;
91 const RGBColor neutral_color_;
92 const RGBColor low_color_;
93 const RGBColor medium_color_;
94 const RGBColor high_color_;
95};
96
97} // namespace UI
98
99#endif // end of include guard: WL_GRAPHIC_STYLES_BUILDING_STATISTICS_STYLE_H
0100
=== added file 'src/graphic/styles/button_style.h'
--- src/graphic/styles/button_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/button_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_BUTTON_STYLE_H
21#define WL_GRAPHIC_STYLES_BUTTON_STYLE_H
22
23#include <memory>
24
25#include "graphic/styles/font_style.h"
26#include "graphic/styles/panel_styles.h"
27#include "graphic/styles/text_panel_style.h"
28
29namespace UI {
30
31enum class ButtonStyle {
32 kFsMenuMenu,
33 kFsMenuPrimary,
34 kFsMenuSecondary,
35 kWuiMenu,
36 kWuiPrimary,
37 kWuiSecondary,
38 kWuiBuildingStats
39};
40
41struct ButtonStyleInfo {
42 ButtonStyleInfo(const UI::TextPanelStyleInfo* init_enabled, const UI::TextPanelStyleInfo* init_disabled) :
43 enabled_(init_enabled),
44 disabled_(init_disabled) {
45 }
46 ButtonStyleInfo(const ButtonStyleInfo& other) :
47 enabled_(new UI::TextPanelStyleInfo(other.enabled())),
48 disabled_(new UI::TextPanelStyleInfo(other.disabled())) {
49 }
50
51 const UI::TextPanelStyleInfo& enabled() const {
52 return *enabled_.get();
53 }
54 const UI::TextPanelStyleInfo& disabled() const {
55 return *disabled_.get();
56 }
57
58private:
59 std::unique_ptr<const UI::TextPanelStyleInfo> enabled_;
60 std::unique_ptr<const UI::TextPanelStyleInfo> disabled_;
61};
62
63} // namespace UI
64
65#endif // end of include guard: WL_GRAPHIC_STYLES_BUTTON_STYLE_H
066
=== added file 'src/graphic/styles/font_style.cc'
--- src/graphic/styles/font_style.cc 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/font_style.cc 2019-05-26 02:00:17 +0000
@@ -0,0 +1,130 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#include "graphic/styles/font_style.h"
21
22#include <boost/format.hpp>
23
24#include "base/log.h"
25#include "base/wexception.h"
26
27namespace UI {
28
29FontStyleInfo::FontStyleInfo(const std::string& init_face, const RGBColor& init_color, int init_size,
30 bool init_bold, bool init_italic, bool init_underline, bool init_shadow) :
31 face_(string_to_face(init_face)),
32 color_(init_color),
33 size_(init_size),
34 bold_(init_bold),
35 italic_(init_italic),
36 underline_(init_underline),
37 shadow_(init_shadow) {
38}
39
40FontStyleInfo::FontStyleInfo(const FontStyleInfo& other) :
41 face_(other.face()),
42 color_(other.color()),
43 size_(other.size()),
44 bold_(other.bold()),
45 italic_(other.italic()),
46 underline_(other.underline()),
47 shadow_(other.shadow())
48{}
49
50const std::string FontStyleInfo::face_to_string() const {
51 switch (face_) {
52 case Face::kSans:
53 return "sans";
54 case Face::kSerif:
55 return "serif";
56 case Face::kCondensed:
57 return "condensed";
58 }
59 return "sans";
60}
61
62FontStyleInfo::Face FontStyleInfo::string_to_face(const std::string& init_face) {
63 FontStyleInfo::Face result;
64 if (init_face == "sans") {
65 result = Face::kSans;
66 } else if (init_face == "serif") {
67 result = Face::kSerif;
68 } else if (init_face == "condensed") {
69 result = Face::kCondensed;
70 } else {
71 throw wexception("Unknown font face '%s', expected 'sans', 'serif' or 'condensed'", init_face.c_str());
72 }
73 return result;
74}
75
76std::string FontStyleInfo::as_font_tag(const std::string& text) const {
77 static boost::format f("<font face=%s size=%d color=%s%s>%s</font>");
78 std::string optionals = "";
79 if (bold_) {
80 optionals += " bold=1";
81 }
82 if (italic_) {
83 optionals += " italic=1";
84 }
85 if (shadow_) {
86 optionals += " shadow=1";
87 }
88 if (underline_) {
89 optionals += " underline=1";
90 }
91 f % face_to_string();
92 f % size_;
93 f % color_.hex_value();
94 f % optionals;
95 f % text;
96 return f.str();
97}
98
99FontStyleInfo::Face FontStyleInfo::face() const {
100 return face_;
101}
102void FontStyleInfo::make_condensed() {
103 face_ = Face::kCondensed;
104}
105const RGBColor& FontStyleInfo::color() const {
106 return color_;
107}
108void FontStyleInfo::set_color(const RGBColor& new_color) {
109 color_ = new_color;
110}
111int FontStyleInfo::size() const {
112 return size_;
113}
114void FontStyleInfo::set_size(int new_size) {
115 size_ = new_size;
116}
117bool FontStyleInfo::bold() const {
118 return bold_;
119}
120bool FontStyleInfo::italic() const {
121 return italic_;
122}
123bool FontStyleInfo::underline() const {
124 return underline_;
125}
126bool FontStyleInfo::shadow() const {
127 return shadow_;
128}
129
130} // namespace UI
0131
=== added file 'src/graphic/styles/font_style.h'
--- src/graphic/styles/font_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/font_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_FONT_STYLE_H
21#define WL_GRAPHIC_STYLES_FONT_STYLE_H
22
23#include <string>
24
25#include "graphic/color.h"
26
27namespace UI {
28enum class FontStyle {
29 kChatMessage,
30 kChatPlayername,
31 kChatServer,
32 kChatTimestamp,
33 kChatWhisper,
34 kFsGameSetupHeadings,
35 kFsGameSetupIrcClient,
36 kFsGameSetupSuperuser,
37 kFsGameSetupMapname,
38 kFsMenuGameTip,
39 kFsMenuInfoPanelHeading,
40 kFsMenuInfoPanelParagraph,
41 kFsMenuIntro,
42 kFsMenuTitle,
43 kFsMenuTranslationInfo,
44 kDisabled,
45 kLabel,
46 kTooltipHeader,
47 kTooltip,
48 kWarning,
49 kWuiAttackBoxSliderLabel,
50 kWuiGameSpeedAndCoordinates,
51 kWuiInfoPanelHeading,
52 kWuiInfoPanelParagraph,
53 kWuiMessageHeading,
54 kWuiMessageParagraph,
55 kWuiWindowTitle
56};
57
58struct FontStyleInfo {
59 enum class Face { kSans, kSerif, kCondensed };
60
61 explicit FontStyleInfo(const std::string& init_face, const RGBColor& init_color, int init_size,
62 bool init_bold, bool init_italic, bool init_underline, bool init_shadow);
63 explicit FontStyleInfo(const FontStyleInfo& other);
64 FontStyleInfo& operator=(const FontStyleInfo& other) = default;
65
66 std::string as_font_tag(const std::string& text) const;
67
68 Face face() const;
69 void make_condensed();
70
71 const RGBColor& color() const;
72 void set_color(const RGBColor& new_color);
73
74 int size() const;
75 void set_size(int new_size);
76
77 bool bold() const;
78 bool italic() const;
79 bool underline() const;
80 bool shadow() const;
81
82private:
83 static Face string_to_face(const std::string& face_);
84 const std::string face_to_string() const;
85
86 Face face_;
87 RGBColor color_;
88 int size_;
89 const bool bold_;
90 const bool italic_;
91 const bool underline_;
92 const bool shadow_;
93};
94
95} // namespace UI
96
97#endif // end of include guard: WL_GRAPHIC_STYLES_FONT_STYLE_H
098
=== renamed file 'src/graphic/panel_styles.h' => 'src/graphic/styles/panel_styles.h'
--- src/graphic/panel_styles.h 2019-02-23 11:00:49 +0000
+++ src/graphic/styles/panel_styles.h 2019-05-26 02:00:17 +0000
@@ -17,41 +17,47 @@
17 *17 *
18 */18 */
1919
20#ifndef WL_GRAPHIC_PANEL_STYLES_H20#ifndef WL_GRAPHIC_STYLES_PANEL_STYLES_H
21#define WL_GRAPHIC_PANEL_STYLES_H21#define WL_GRAPHIC_STYLES_PANEL_STYLES_H
22
23#include <map>
24#include <memory>
2225
23#include "graphic/color.h"26#include "graphic/color.h"
27#include "graphic/styles/font_style.h"
24#include "graphic/image.h"28#include "graphic/image.h"
2529
26namespace UI {30namespace UI {
2731
28// Buttons
29enum class ButtonStyle {
30 kFsMenuMenu,
31 kFsMenuPrimary,
32 kFsMenuSecondary,
33 kWuiMenu,
34 kWuiPrimary,
35 kWuiSecondary,
36 kWuiBuildingStats
37};
38enum class SliderStyle { kFsMenu, kWuiLight, kWuiDark };
39
40// Backgrounds32// Backgrounds
41enum class PanelStyle { kFsMenu, kWui };33enum class PanelStyle { kFsMenu, kWui };
42enum class TabPanelStyle { kFsMenu, kWuiLight, kWuiDark };34enum class TabPanelStyle { kFsMenu, kWuiLight, kWuiDark };
4335
44struct PanelStyleInfo {36struct PanelStyleInfo {
45 PanelStyleInfo(const Image* init_image, const RGBAColor& init_color)37 PanelStyleInfo(const Image* init_image, const RGBAColor& init_color, int init_margin)
46 : image(init_image), color(init_color) {38 : margin_(init_margin), image_(init_image), color_(init_color) {
47 }39 }
48 PanelStyleInfo() : PanelStyleInfo(nullptr, RGBAColor(0, 0, 0, 0)) {40 PanelStyleInfo(const PanelStyleInfo& other)
49 }41 : image_(other.image()), color_(other.color()) {
5042 }
51 const Image* image;43
52 const RGBAColor color;44 const RGBAColor& color() const {
45 return color_;
46 }
47 const Image* image() const {
48 return image_;
49 }
50
51 int margin() const {
52 return margin_;
53 }
54
55private:
56 int margin_;
57 const Image* image_;
58 RGBAColor color_;
53};59};
5460
55} // namespace UI61} // namespace UI
5662
57#endif // end of include guard: WL_GRAPHIC_PANEL_STYLES_H63#endif // end of include guard: WL_GRAPHIC_STYLES_PANEL_STYLES_H
5864
=== added file 'src/graphic/styles/progress_bar_style.h'
--- src/graphic/styles/progress_bar_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/progress_bar_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
21#define WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
22
23#include <memory>
24
25#include "graphic/color.h"
26#include "graphic/styles/font_style.h"
27
28namespace UI {
29
30struct ProgressbarStyleInfo {
31 explicit ProgressbarStyleInfo(UI::FontStyleInfo* init_font,
32 const RGBColor& init_low_color,
33 const RGBColor& init_medium_color,
34 const RGBColor& init_high_color) :
35 font_(init_font),
36 low_color_(init_low_color),
37 medium_color_(init_medium_color),
38 high_color_(init_high_color) {}
39 explicit ProgressbarStyleInfo(const ProgressbarStyleInfo& other):
40 font_(new UI::FontStyleInfo(other.font())),
41 low_color_(other.low_color()),
42 medium_color_(other.medium_color()),
43 high_color_(other.high_color())
44 {
45 }
46
47 const UI::FontStyleInfo& font() const {
48 return *font_.get();
49 }
50 const RGBColor& low_color() const {
51 return low_color_;
52 }
53 const RGBColor& medium_color() const {
54 return medium_color_;
55 }
56 const RGBColor& high_color() const {
57 return high_color_;
58 }
59
60private:
61 std::unique_ptr<const UI::FontStyleInfo> font_;
62 const RGBColor low_color_;
63 const RGBColor medium_color_;
64 const RGBColor high_color_;
65};
66
67} // namespace UI
68
69#endif // end of include guard: WL_GRAPHIC_STYLES_PROGRESS_BAR_STYLE_H
070
=== added file 'src/graphic/styles/statistics_plot_style.h'
--- src/graphic/styles/statistics_plot_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/statistics_plot_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
21#define WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
22
23#include <memory>
24
25#include "graphic/color.h"
26#include "graphic/styles/font_style.h"
27
28namespace UI {
29
30struct StatisticsPlotStyleInfo {
31 explicit StatisticsPlotStyleInfo(UI::FontStyleInfo* init_x_tick_font,
32 UI::FontStyleInfo* init_y_min_value_font,
33 UI::FontStyleInfo* init_y_max_value_font,
34 const RGBColor& init_axis_line_color,
35 const RGBColor& init_zero_line_color) :
36 x_tick_font_(init_x_tick_font),
37 y_min_value_font_(init_y_min_value_font),
38 y_max_value_font_(init_y_max_value_font),
39 axis_line_color_(init_axis_line_color),
40 zero_line_color_(init_zero_line_color) {}
41
42 const UI::FontStyleInfo& x_tick_font() const {
43 return *x_tick_font_.get();
44 }
45 const UI::FontStyleInfo& y_min_value_font() const {
46 return *y_min_value_font_.get();
47 }
48 const UI::FontStyleInfo& y_max_value_font() const {
49 return *y_max_value_font_.get();
50 }
51 const RGBColor& axis_line_color() const {
52 return axis_line_color_;
53 }
54 const RGBColor& zero_line_color() const {
55 return zero_line_color_;
56 }
57
58private:
59 std::unique_ptr<const UI::FontStyleInfo> x_tick_font_;
60 std::unique_ptr<const UI::FontStyleInfo> y_min_value_font_;
61 std::unique_ptr<const UI::FontStyleInfo> y_max_value_font_;
62 const RGBColor axis_line_color_;
63 const RGBColor zero_line_color_;
64};
65
66} // namespace UI
67
68#endif // end of include guard: WL_GRAPHIC_STYLES_STATISTICS_PLOT_STYLE_H
069
=== added file 'src/graphic/styles/table_style.h'
--- src/graphic/styles/table_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/table_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_TABLE_STYLE_H
21#define WL_GRAPHIC_STYLES_TABLE_STYLE_H
22
23#include <memory>
24
25#include "graphic/styles/font_style.h"
26
27namespace UI {
28
29struct TableStyleInfo {
30 explicit TableStyleInfo(UI::FontStyleInfo* init_enabled, UI::FontStyleInfo* init_disabled) :
31 enabled_(init_enabled), disabled_(init_disabled) {}
32
33 const UI::FontStyleInfo& enabled() const {
34 return *enabled_.get();
35 }
36 const UI::FontStyleInfo& disabled() const {
37 return *disabled_.get();
38 }
39
40private:
41 std::unique_ptr<const UI::FontStyleInfo> enabled_;
42 std::unique_ptr<const UI::FontStyleInfo> disabled_;
43};
44
45} // namespace UI
46
47#endif // end of include guard: WL_GRAPHIC_STYLES_TABLE_STYLE_H
048
=== added file 'src/graphic/styles/text_panel_style.h'
--- src/graphic/styles/text_panel_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/text_panel_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,61 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
21#define WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
22
23#include <memory>
24
25#include "graphic/styles/font_style.h"
26#include "graphic/styles/panel_styles.h"
27
28namespace UI {
29
30enum class SliderStyle { kFsMenu, kWuiLight, kWuiDark };
31
32struct TextPanelStyleInfo {
33 explicit TextPanelStyleInfo(const UI::FontStyleInfo* init_font, const UI::PanelStyleInfo* init_background) :
34 background_(init_background),
35 font_(init_font) {
36 }
37 explicit TextPanelStyleInfo(const TextPanelStyleInfo& other) :
38 background_(new UI::PanelStyleInfo(other.background())),
39 font_(new UI::FontStyleInfo(other.font())) {
40 }
41 TextPanelStyleInfo& operator=(const TextPanelStyleInfo& other) = default;
42
43 const UI::FontStyleInfo& font() const {
44 return *font_.get();
45 }
46 void set_font(const UI::FontStyleInfo& new_font) {
47 font_.reset(new UI::FontStyleInfo(new_font));
48 }
49
50 const UI::PanelStyleInfo& background() const {
51 return *background_.get();
52 }
53
54private:
55 std::unique_ptr<const UI::PanelStyleInfo> background_;
56 std::unique_ptr<const UI::FontStyleInfo> font_;
57};
58
59} // namespace UI
60
61#endif // end of include guard: WL_GRAPHIC_STYLES_TEXT_PANEL_STYLE_H
062
=== added file 'src/graphic/styles/ware_info_style.h'
--- src/graphic/styles/ware_info_style.h 1970-01-01 00:00:00 +0000
+++ src/graphic/styles/ware_info_style.h 2019-05-26 02:00:17 +0000
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
21#define WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
22
23#include <memory>
24
25#include "graphic/color.h"
26#include "graphic/styles/font_style.h"
27#include "graphic/image.h"
28
29namespace UI {
30
31enum class WareInfoStyle {
32 kNormal,
33 kHighlight
34};
35
36struct WareInfoStyleInfo {
37 explicit WareInfoStyleInfo(UI::FontStyleInfo* init_header_font,
38 UI::FontStyleInfo* init_info_font,
39 const Image* init_icon_background_image,
40 const RGBColor& init_icon_frame,
41 const RGBColor& init_icon_background,
42 const RGBColor& init_info_background) :
43 header_font_(init_header_font),
44 info_font_(init_info_font),
45 icon_background_image_(init_icon_background_image),
46 icon_frame_(init_icon_frame),
47 icon_background_(init_icon_background),
48 info_background_(init_info_background) {}
49
50 const UI::FontStyleInfo& header_font() const {
51 return *header_font_.get();
52 }
53 const UI::FontStyleInfo& info_font() const {
54 return *info_font_.get();
55 }
56 const Image* icon_background_image() const {
57 return icon_background_image_;
58 }
59 const RGBColor& icon_frame() const {
60 return icon_frame_;
61 }
62 const RGBColor& icon_background() const {
63 return icon_background_;
64 }
65 const RGBColor& info_background() const {
66 return info_background_;
67 }
68
69private:
70 std::unique_ptr<const UI::FontStyleInfo> header_font_;
71 std::unique_ptr<const UI::FontStyleInfo> info_font_;
72 const Image* icon_background_image_;
73 const RGBColor icon_frame_;
74 const RGBColor icon_background_;
75 const RGBColor info_background_;
76};
77
78} // namespace UI
79
80#endif // end of include guard: WL_GRAPHIC_STYLES_WARE_INFO_STYLE_H
081
=== modified file 'src/graphic/text/CMakeLists.txt'
--- src/graphic/text/CMakeLists.txt 2018-03-02 06:01:51 +0000
+++ src/graphic/text/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -41,7 +41,6 @@
41 graphic_playercolor41 graphic_playercolor
42 graphic_sdl_utils42 graphic_sdl_utils
43 graphic_surface43 graphic_surface
44 graphic_text_layout
45 io_fileread44 io_fileread
46 io_filesystem45 io_filesystem
47 scripting_lua_interface46 scripting_lua_interface
4847
=== modified file 'src/graphic/text/font_set.cc'
--- src/graphic/text/font_set.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/text/font_set.cc 2019-05-26 02:00:17 +0000
@@ -27,6 +27,7 @@
2727
28#include "base/i18n.h"28#include "base/i18n.h"
29#include "base/log.h"29#include "base/log.h"
30#include "graphic/text/bidi.h"
30#include "io/filesystem/layered_filesystem.h"31#include "io/filesystem/layered_filesystem.h"
31#include "scripting/lua_interface.h"32#include "scripting/lua_interface.h"
32#include "scripting/lua_table.h"33#include "scripting/lua_table.h"
3334
=== modified file 'src/graphic/text/font_set.h'
--- src/graphic/text/font_set.h 2019-02-23 11:00:49 +0000
+++ src/graphic/text/font_set.h 2019-05-26 02:00:17 +0000
@@ -25,6 +25,7 @@
25#include <string>25#include <string>
2626
27#include "base/macros.h"27#include "base/macros.h"
28#include "graphic/align.h"
28#include "scripting/lua_table.h"29#include "scripting/lua_table.h"
2930
30namespace UI {31namespace UI {
@@ -32,8 +33,6 @@
32// Contains font information for a locale33// Contains font information for a locale
33struct FontSet {34struct FontSet {
3435
35 enum class Face { kSans, kSerif, kCondensed };
36
37 static constexpr const char* kFallbackFont = "DejaVu/DejaVuSans.ttf";36 static constexpr const char* kFallbackFont = "DejaVu/DejaVuSans.ttf";
3837
39 /// Create a fontset from i18n/fonts.lua38 /// Create a fontset from i18n/fonts.lua
@@ -62,6 +61,7 @@
62 // Returns true iff the fontset's script is written from right to left.61 // Returns true iff the fontset's script is written from right to left.
63 bool is_rtl() const;62 bool is_rtl() const;
6463
64
65private:65private:
66 /// Parses font information for the given fontset name from Lua.66 /// Parses font information for the given fontset name from Lua.
67 /// The fontset definitions are in i18n/fonts.lua67 /// The fontset definitions are in i18n/fonts.lua
6868
=== modified file 'src/graphic/text/rendered_text.cc'
--- src/graphic/text/rendered_text.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/text/rendered_text.cc 2019-05-26 02:00:17 +0000
@@ -22,7 +22,6 @@
22#include <memory>22#include <memory>
2323
24#include "graphic/graphic.h"24#include "graphic/graphic.h"
25#include "graphic/text_layout.h"
2625
27namespace UI {26namespace UI {
28// RenderedRect27// RenderedRect
2928
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2019-05-04 09:59:51 +0000
+++ src/graphic/text/rt_render.cc 2019-05-26 02:00:17 +0000
@@ -48,11 +48,23 @@
48#include "graphic/text/rt_parse.h"48#include "graphic/text/rt_parse.h"
49#include "graphic/text/sdl_ttf_font.h"49#include "graphic/text/sdl_ttf_font.h"
50#include "graphic/text/textstream.h"50#include "graphic/text/textstream.h"
51#include "graphic/text_layout.h"
52#include "graphic/texture.h"51#include "graphic/texture.h"
53#include "io/filesystem/filesystem_exceptions.h"52#include "io/filesystem/filesystem_exceptions.h"
54#include "io/filesystem/layered_filesystem.h"53#include "io/filesystem/layered_filesystem.h"
5554
55namespace {
56/**
57 * This function replaces some HTML entities in strings, e.g. &nbsp;.
58 * It is used by the renderer after the tags have been parsed.
59 */
60void replace_entities(std::string* text) {
61 boost::replace_all(*text, "&gt;", ">");
62 boost::replace_all(*text, "&lt;", "<");
63 boost::replace_all(*text, "&nbsp;", " ");
64 boost::replace_all(*text, "&amp;", "&"); // Must be performed last
65}
66} // namespace
67
56namespace RT {68namespace RT {
5769
58static const uint16_t INFINITE_WIDTH = 65535; // 2^16-170static const uint16_t INFINITE_WIDTH = 65535; // 2^16-1
@@ -93,6 +105,7 @@
93 uint8_t spacing;105 uint8_t spacing;
94 UI::Align halign;106 UI::Align halign;
95 UI::Align valign;107 UI::Align valign;
108 const bool is_rtl;
96 std::string reference;109 std::string reference;
97};110};
98111
@@ -975,7 +988,7 @@
975 : RenderNode(ns),988 : RenderNode(ns),
976 image_(image),989 image_(image),
977 filename_(""),990 filename_(""),
978 scale_(1.0f),991 scale_(1.0),
979 color_(RGBColor(0, 0, 0)),992 color_(RGBColor(0, 0, 0)),
980 use_playercolor_(false) {993 use_playercolor_(false) {
981 check_size();994 check_size();
@@ -1234,7 +1247,7 @@
1234 nodestyle_.halign = UI::Align::kLeft;1247 nodestyle_.halign = UI::Align::kLeft;
1235 }1248 }
1236 }1249 }
1237 nodestyle_.halign = mirror_alignment(nodestyle_.halign);1250 nodestyle_.halign = mirror_alignment(nodestyle_.halign, nodestyle_.is_rtl);
1238 if (a.has("valign")) {1251 if (a.has("valign")) {
1239 const std::string align = a["valign"].get_string();1252 const std::string align = a["valign"].get_string();
1240 if (align == "bottom") {1253 if (align == "bottom") {
@@ -1715,7 +1728,7 @@
1715}1728}
17161729
1717std::shared_ptr<RenderNode>1730std::shared_ptr<RenderNode>
1718Renderer::layout(const std::string& text, uint16_t width, const TagSet& allowed_tags) {1731Renderer::layout(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags) {
1719 std::unique_ptr<Tag> rt(parser_->parse(text, allowed_tags));1732 std::unique_ptr<Tag> rt(parser_->parse(text, allowed_tags));
17201733
1721 if (!width) {1734 if (!width) {
@@ -1735,6 +1748,7 @@
1735 0,1748 0,
1736 UI::Align::kLeft,1749 UI::Align::kLeft,
1737 UI::Align::kTop,1750 UI::Align::kTop,
1751 is_rtl,
1738 ""};1752 ""};
17391753
1740 RTTagHandler rtrn(1754 RTTagHandler rtrn(
@@ -1749,8 +1763,8 @@
1749}1763}
17501764
1751std::shared_ptr<const UI::RenderedText>1765std::shared_ptr<const UI::RenderedText>
1752Renderer::render(const std::string& text, uint16_t width, const TagSet& allowed_tags) {1766Renderer::render(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags) {
1753 std::shared_ptr<RenderNode> node(layout(text, width, allowed_tags));1767 std::shared_ptr<RenderNode> node(layout(text, width, is_rtl, allowed_tags));
1754 return std::shared_ptr<const UI::RenderedText>(node->render(texture_cache_));1768 return std::shared_ptr<const UI::RenderedText>(node->render(texture_cache_));
1755}1769}
1756} // namespace RT1770} // namespace RT
17571771
=== modified file 'src/graphic/text/rt_render.h'
--- src/graphic/text/rt_render.h 2019-02-23 11:00:49 +0000
+++ src/graphic/text/rt_render.h 2019-05-26 02:00:17 +0000
@@ -70,11 +70,11 @@
70 // Render the given string in the given width. Restricts the allowed tags to70 // Render the given string in the given width. Restricts the allowed tags to
71 // the ones in TagSet.71 // the ones in TagSet.
72 std::shared_ptr<const UI::RenderedText>72 std::shared_ptr<const UI::RenderedText>
73 render(const std::string&, uint16_t width, const TagSet& tagset = TagSet());73 render(const std::string&, uint16_t width, bool is_rtl, const TagSet& tagset = TagSet());
7474
75private:75private:
76 std::shared_ptr<RenderNode>76 std::shared_ptr<RenderNode>
77 layout(const std::string& text, uint16_t width, const TagSet& allowed_tags);77 layout(const std::string& text, uint16_t width, bool is_rtl, const TagSet& allowed_tags);
7878
79 std::unique_ptr<FontCache> font_cache_;79 std::unique_ptr<FontCache> font_cache_;
80 std::unique_ptr<Parser> parser_;80 std::unique_ptr<Parser> parser_;
8181
=== removed file 'src/graphic/text_constants.cc'
--- src/graphic/text_constants.cc 2017-03-04 12:37:17 +0000
+++ src/graphic/text_constants.cc 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1// Dummy to make CMake happy
20
=== removed file 'src/graphic/text_constants.h'
--- src/graphic/text_constants.h 2019-02-23 11:00:49 +0000
+++ src/graphic/text_constants.h 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
1/*
2 * Copyright (C) 2006-2019 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_GRAPHIC_TEXT_CONSTANTS_H
21#define WL_GRAPHIC_TEXT_CONSTANTS_H
22
23// Basic constants for often used text attributes.
24
25/// Font Sizes
26#define UI_FONT_SIZE_BIG 22
27#define UI_FONT_SIZE_SMALL 14
28#define UI_FONT_SIZE_MESSAGE 12
29#define UI_FONT_SIZE_ULTRASMALL 10
30constexpr int kMinimumFontSize = 6;
31constexpr int kLineMargin = 1;
32
33/// Font colors
34
35/// Global UI font color
36#define UI_FONT_CLR_FG RGBColor(255, 255, 0)
37#define UI_FONT_CLR_DISABLED RGBColor(127, 127, 127)
38#define UI_FONT_CLR_WARNING RGBColor(255, 22, 22)
39
40/// Tooltip font color
41#define UI_FONT_TOOLTIP_CLR RGBColor(255, 255, 0)
42
43/// Colors for good/ok/bad
44#define UI_FONT_CLR_BRIGHT RGBColor(255, 250, 170)
45#define UI_FONT_CLR_DARK RGBColor(163, 144, 19)
46#define UI_FONT_CLR_BAD RGBColor(187, 0, 0)
47#define UI_FONT_CLR_OK RGBColor(255, 225, 30)
48#define UI_FONT_CLR_GOOD RGBColor(0, 187, 0)
49
50#endif // end of include guard: WL_GRAPHIC_TEXT_CONSTANTS_H
510
=== modified file 'src/graphic/text_layout.cc'
--- src/graphic/text_layout.cc 2019-04-18 16:50:35 +0000
+++ src/graphic/text_layout.cc 2019-05-26 02:00:17 +0000
@@ -19,18 +19,14 @@
1919
20#include "graphic/text_layout.h"20#include "graphic/text_layout.h"
2121
22#include <map>
23
24#include <SDL_ttf.h>
25#include <boost/algorithm/string.hpp>22#include <boost/algorithm/string.hpp>
26#include <boost/format.hpp>23#include <boost/format.hpp>
2724
28#include "graphic/font_handler.h"25#include "graphic/font_handler.h"
29#include "graphic/graphic.h"26#include "graphic/graphic.h"
30#include "graphic/image.h"27#include "graphic/image.h"
31#include "graphic/text/bidi.h"28#include "graphic/style_manager.h"
32#include "graphic/text/font_set.h"29#include "graphic/text/font_set.h"
33#include "graphic/text_constants.h"
3430
35namespace {31namespace {
36bool is_paragraph(const std::string& text) {32bool is_paragraph(const std::string& text) {
@@ -40,70 +36,8 @@
40bool is_div(const std::string& text) {36bool is_div(const std::string& text) {
41 return boost::starts_with(text, "<div");37 return boost::starts_with(text, "<div");
42}38}
43} // namespace39
4440std::string as_richtext_paragraph(const std::string& text, UI::Align align) {
45void replace_entities(std::string* text) {
46 boost::replace_all(*text, "&gt;", ">");
47 boost::replace_all(*text, "&lt;", "<");
48 boost::replace_all(*text, "&nbsp;", " ");
49 boost::replace_all(*text, "&amp;", "&"); // Must be performed last
50}
51
52int text_width(const std::string& text, int ptsize) {
53 return UI::g_fh
54 ->render(as_editorfont(
55 text.substr(0, g_gr->max_texture_size_for_font_rendering() / text_height() - 1),
56 ptsize - UI::g_fh->fontset()->size_offset()))
57 ->width();
58}
59
60int text_height(int ptsize, UI::FontSet::Face face) {
61 return UI::g_fh
62 ->render(as_aligned(UI::g_fh->fontset()->representative_character(), UI::Align::kLeft,
63 ptsize - UI::g_fh->fontset()->size_offset(), RGBColor(0, 0, 0), face))
64 ->height();
65}
66
67std::string richtext_escape(const std::string& given_text) {
68 std::string text = given_text;
69 boost::replace_all(text, "&", "&amp;"); // Must be performed first
70 boost::replace_all(text, ">", "&gt;");
71 boost::replace_all(text, "<", "&lt;");
72 return text;
73}
74
75std::string as_game_tip(const std::string& txt) {
76 static boost::format f(
77 "<rt><p align=center><font color=21211b face=serif size=16>%s</font></p></rt>");
78 f % txt;
79 return f.str();
80}
81
82std::string
83as_uifont(const std::string& txt, int size, const RGBColor& clr, UI::FontSet::Face face) {
84 return as_aligned(txt, UI::Align::kLeft, size, clr, face);
85}
86
87std::string
88as_condensed(const std::string& text, UI::Align align, int ptsize, const RGBColor& clr) {
89 return as_aligned(text, align, ptsize, clr, UI::FontSet::Face::kCondensed);
90}
91
92std::string as_editorfont(const std::string& text, int ptsize, const RGBColor& clr) {
93 // UI Text is always bold due to historic reasons
94 static boost::format f(
95 "<rt keep_spaces=1><p><font face=sans size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
96 f % ptsize;
97 f % clr.hex_value();
98 f % richtext_escape(text);
99 return f.str();
100}
101
102std::string as_aligned(const std::string& txt,
103 UI::Align align,
104 int ptsize,
105 const RGBColor& clr,
106 UI::FontSet::Face face) {
107 std::string alignment = "left";41 std::string alignment = "left";
108 switch (align) {42 switch (align) {
109 case UI::Align::kCenter:43 case UI::Align::kCenter:
@@ -117,38 +51,48 @@
117 break;51 break;
118 }52 }
11953
120 std::string font_face = "sans";54 static boost::format f("<rt><p align=%s>%s</p></rt>");
121
122 switch (face) {
123 case UI::FontSet::Face::kCondensed:
124 font_face = "condensed";
125 break;
126 case UI::FontSet::Face::kSerif:
127 font_face = "serif";
128 break;
129 case UI::FontSet::Face::kSans:
130 font_face = "sans";
131 break;
132 }
133
134 // UI Text is always bold due to historic reasons
135 static boost::format f(
136 "<rt><p align=%s><font face=%s size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
137 f % alignment;55 f % alignment;
138 f % font_face;56 f % text;
139 f % ptsize;
140 f % clr.hex_value();
141 f % txt;
142 return f.str();57 return f.str();
143}58}
59} // namespace
60
61int text_width(const std::string& text, const UI::FontStyleInfo& style, float scale) {
62 UI::FontStyleInfo info(style);
63 info.set_size(info.size() * scale - UI::g_fh->fontset()->size_offset());
64 return UI::g_fh
65 ->render(as_editor_richtext_paragraph(text, info))->width();
66}
67
68int text_height(const UI::FontStyleInfo& style, float scale) {
69 UI::FontStyleInfo info(style);
70 info.set_size(info.size() * scale - UI::g_fh->fontset()->size_offset());
71 return UI::g_fh
72 ->render(as_richtext_paragraph(UI::g_fh->fontset()->representative_character(), info))
73 ->height();
74}
75
76int text_height(UI::FontStyle style, float scale) {
77 return text_height(g_gr->styles().font_style(style), scale);
78}
79
80std::string richtext_escape(const std::string& given_text) {
81 std::string text = given_text;
82 boost::replace_all(text, "&", "&amp;"); // Must be performed first
83 boost::replace_all(text, ">", "&gt;");
84 boost::replace_all(text, "<", "&lt;");
85 return text;
86}
14487
145/// Bullet list item88/// Bullet list item
146std::string as_listitem(const std::string& txt, int ptsize, const RGBColor& clr) {89std::string as_listitem(const std::string& txt, UI::FontStyle style) {
147 static boost::format f("<div width=100%%><div><p><font size=%d "90 static boost::format f("<div width=100%%><div><p><font size=%d "
148 "color=%s>•</font></p></div><div><p><space gap=6></p></div><div "91 "color=%s>•</font></p></div><div><p><space gap=6></p></div><div "
149 "width=*><p><font size=%d color=%s>%s<vspace "92 "width=*><p><font size=%d color=%s>%s<vspace "
150 "gap=6></font></p></div></div>");93 "gap=6></font></p></div></div>");
151 f % ptsize % clr.hex_value() % ptsize % clr.hex_value() % txt;94 const UI::FontStyleInfo& font_style = g_gr->styles().font_style(style);
95 f % font_style.size() % font_style.color().hex_value() % font_style.size() % font_style.color().hex_value() % txt;
152 return f.str();96 return f.str();
153}97}
15498
@@ -158,33 +102,83 @@
158 return f.str();102 return f.str();
159}103}
160104
161std::string as_tooltip(const std::string& txt) {105std::string as_richtext_paragraph(const std::string& text, UI::FontStyle style, UI::Align align) {
162 static boost::format f("<rt><p><font face=sans size=%i bold=1 color=%s>%s</font></p></rt>");106 return as_richtext_paragraph(text, g_gr->styles().font_style(style), align);
163107}
164 f % UI_FONT_SIZE_SMALL;108
165 f % UI_FONT_TOOLTIP_CLR.hex_value();109std::string as_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style, UI::Align align) {
166 f % txt;110 return as_richtext_paragraph(style.as_font_tag(text), align);
167 return f.str();111}
168}112
169113std::string as_editor_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style) {
170std::string as_waresinfo(const std::string& txt) {114 static boost::format f("<rt keep_spaces=1><p>%s</p></rt>");
171 static boost::format f("<rt><p><font face=condensed size=10 bold=0 color=%s>%s</font></p></rt>");115 f % style.as_font_tag(text);
172 f % UI_FONT_TOOLTIP_CLR.hex_value();116 return f.str();
173 f % txt;117}
174 return f.str();118
119std::string as_game_tip(const std::string& txt) {
120 static boost::format f("<rt><p align=center>%s</p></rt>");
121 f % g_gr->styles().font_style(UI::FontStyle::kFsMenuGameTip).as_font_tag(txt);
122 return f.str();
123}
124
125std::string as_mapobject_message(const std::string& image, int width, const std::string& txt, const RGBColor* player_color) {
126 assert(!image.empty());
127 assert(!txt.empty());
128 const std::string image_type = g_gr->images().has(image) ? "src" : "object";
129 static boost::format f_color("<div padding_r=10><p><img width=%d %s=%s color=%s></p></div>"
130 "<div width=*><p>%s</p></div>");
131 static boost::format f_nocolor("<div padding_r=10><p><img width=%d %s=%s></p></div>"
132 "<div width=*><p>%s</p></div>");
133 if (player_color != nullptr) {
134 f_color % width;
135 f_color % image_type;
136 f_color % image;
137 f_color % player_color->hex_value();
138 f_color % g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(txt);
139 return f_color.str();
140 } else {
141 f_nocolor % width;
142 f_nocolor % image_type;
143 f_nocolor % image;
144 f_nocolor % g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(txt);
145 return f_nocolor.str();
146 }
175}147}
176148
177std::string as_message(const std::string& heading, const std::string& body) {149std::string as_message(const std::string& heading, const std::string& body) {
178 return (150 return (
179 (boost::format(151 (boost::format(
180 "<rt><p><font size=18 bold=1 color=D1D1D1>%s<br></font></p><vspace gap=6>%s</rt>") %152 "<rt><p>%s<br></p><vspace gap=6>%s</rt>") %
181 heading %153 g_gr->styles().font_style(UI::FontStyle::kWuiMessageHeading).as_font_tag(heading) %
182 (is_paragraph(body) || is_div(body) ?154 (is_paragraph(body) || is_div(body) ?
183 body :155 body :
184 (boost::format("<p><font size=%d>%s</font></p>") % UI_FONT_SIZE_MESSAGE % body).str()))156 (boost::format("<p>%s</p>") %
157 g_gr->styles().font_style(UI::FontStyle::kWuiMessageParagraph).as_font_tag(body))
158 .str()))
185 .str());159 .str());
186}160}
187161
162std::shared_ptr<const UI::RenderedText> autofit_text(const std::string& text,
163 const UI::FontStyleInfo& font_info,
164 int width) {
165 std::shared_ptr<const UI::RenderedText> rendered_text =
166 UI::g_fh->render(as_richtext_paragraph(text, font_info));
167
168 // Autoshrink if it doesn't fit
169 if (width > 0 && rendered_text->width() > width) {
170 const int minimum_size = g_gr->styles().minimum_font_size();
171 // We take a copy, because we are changing values during the autofit.
172 UI::FontStyleInfo temp_font_info(font_info);
173 temp_font_info.make_condensed();
174 while (rendered_text->width() > width && temp_font_info.size() >= minimum_size) {
175 rendered_text = UI::g_fh->render(as_richtext_paragraph(text, temp_font_info));
176 temp_font_info.set_size(temp_font_info.size() - 1);
177 }
178 }
179 return rendered_text;
180}
181
188std::string as_heading_with_content(const std::string& header,182std::string as_heading_with_content(const std::string& header,
189 const std::string& content,183 const std::string& content,
190 UI::PanelStyle style,184 UI::PanelStyle style,
@@ -192,18 +186,16 @@
192 bool noescape) {186 bool noescape) {
193 switch (style) {187 switch (style) {
194 case UI::PanelStyle::kFsMenu:188 case UI::PanelStyle::kFsMenu:
195 return (boost::format(189 return (boost::format("<p>%s%s %s</p>") %
196 "<p><font size=%i bold=1 shadow=1>%s%s <font color=D1D1D1>%s</font></font></p>") %190 (is_first ? "" : "<vspace gap=9>") %
197 UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=9>") %191 g_gr->styles().font_style(UI::FontStyle::kFsMenuInfoPanelHeading).as_font_tag(noescape ? header : richtext_escape(header)) %
198 (noescape ? header : richtext_escape(header)) %192 g_gr->styles().font_style(UI::FontStyle::kFsMenuInfoPanelParagraph).as_font_tag(noescape ? content : richtext_escape(content)))
199 (noescape ? content : richtext_escape(content)))
200 .str();193 .str();
201 case UI::PanelStyle::kWui:194 case UI::PanelStyle::kWui:
202 return (boost::format(195 return (boost::format("<p>%s%s %s</p>") %
203 "<p><font size=%i>%s<font bold=1 color=D1D1D1>%s</font> %s</font></p>") %196 (is_first ? "" : "<vspace gap=6>") %
204 UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=6>") %197 g_gr->styles().font_style(UI::FontStyle::kWuiInfoPanelHeading).as_font_tag(noescape ? header : richtext_escape(header)) %
205 (noescape ? header : richtext_escape(header)) %198 g_gr->styles().font_style(UI::FontStyle::kWuiInfoPanelParagraph).as_font_tag(noescape ? content : richtext_escape(content)))
206 (noescape ? content : richtext_escape(content)))
207 .str();199 .str();
208 }200 }
209 NEVER_HERE();201 NEVER_HERE();
@@ -212,12 +204,16 @@
212std::string as_heading(const std::string& txt, UI::PanelStyle style, bool is_first) {204std::string as_heading(const std::string& txt, UI::PanelStyle style, bool is_first) {
213 switch (style) {205 switch (style) {
214 case UI::PanelStyle::kFsMenu:206 case UI::PanelStyle::kFsMenu:
215 return (boost::format("<p><font size=%i bold=1 shadow=1>%s%s</font></p>") %207 return (boost::format("<p>%s%s</p>") % (is_first ? "" : "<vspace gap=9>") %
216 UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=9>") % richtext_escape(txt))208 g_gr->styles()
209 .font_style(UI::FontStyle::kFsMenuInfoPanelHeading)
210 .as_font_tag(richtext_escape(txt)))
217 .str();211 .str();
218 case UI::PanelStyle::kWui:212 case UI::PanelStyle::kWui:
219 return (boost::format("<p><font size=%i bold=1 color=D1D1D1>%s%s</font></p>") %213 return (boost::format("<p>%s%s</p>") % (is_first ? "" : "<vspace gap=6>") %
220 UI_FONT_SIZE_SMALL % (is_first ? "" : "<vspace gap=6>") % richtext_escape(txt))214 g_gr->styles()
215 .font_style(UI::FontStyle::kWuiInfoPanelHeading)
216 .as_font_tag(richtext_escape(txt)))
221 .str();217 .str();
222 }218 }
223 NEVER_HERE();219 NEVER_HERE();
@@ -226,78 +222,17 @@
226std::string as_content(const std::string& txt, UI::PanelStyle style) {222std::string as_content(const std::string& txt, UI::PanelStyle style) {
227 switch (style) {223 switch (style) {
228 case UI::PanelStyle::kFsMenu:224 case UI::PanelStyle::kFsMenu:
229 return (boost::format("<p><font size=%i color=D1D1D1 shadow=1><vspace gap=2>%s</font></p>") %225 return (boost::format("<p><vspace gap=2>%s</p>") %
230 UI_FONT_SIZE_SMALL % richtext_escape(txt))226 g_gr->styles()
227 .font_style(UI::FontStyle::kFsMenuInfoPanelParagraph)
228 .as_font_tag(richtext_escape(txt)))
231 .str();229 .str();
232 case UI::PanelStyle::kWui:230 case UI::PanelStyle::kWui:
233 return (boost::format("<p><font size=%i><vspace gap=2>%s</font></p>") %231 return (boost::format("<p><vspace gap=2>%s</p>") %
234 (UI_FONT_SIZE_SMALL - 2) % richtext_escape(txt))232 g_gr->styles()
233 .font_style(UI::FontStyle::kWuiInfoPanelParagraph)
234 .as_font_tag(richtext_escape(txt)))
235 .str();235 .str();
236 }236 }
237 NEVER_HERE();237 NEVER_HERE();
238}238}
239
240std::shared_ptr<const UI::RenderedText>
241autofit_ui_text(const std::string& text, int width, RGBColor color, int fontsize) {
242 std::shared_ptr<const UI::RenderedText> result =
243 UI::g_fh->render(as_uifont(richtext_escape(text), fontsize, color));
244 if (width > 0) { // Autofit
245 for (; result->width() > width && fontsize >= kMinimumFontSize; --fontsize) {
246 result = UI::g_fh->render(
247 as_condensed(richtext_escape(text), UI::Align::kLeft, fontsize, color));
248 }
249 }
250 return result;
251}
252
253namespace UI {
254
255/**
256 * This mirrors the horizontal alignment for RTL languages.
257 *
258 * Do not store this value as it is based on the global font setting.
259 *
260 * If 'checkme' is not empty, mirror the alignment if the first 20 characters contain an RTL
261 * character. Otherwise, mirror if the current fontset is RTL.
262 */
263Align mirror_alignment(Align alignment, const std::string& checkme) {
264 bool do_swap_alignment = checkme.empty() ? UI::g_fh->fontset()->is_rtl() :
265 i18n::has_rtl_character(checkme.c_str(), 20);
266 if (do_swap_alignment) {
267 switch (alignment) {
268 case Align::kLeft:
269 alignment = Align::kRight;
270 break;
271 case Align::kRight:
272 alignment = Align::kLeft;
273 break;
274 case Align::kCenter:
275 break;
276 }
277 }
278 return alignment;
279}
280
281/**
282 * Align pt horizontally to match align based on width w.
283 *
284 * When correcting for align, we never move from pixel boundaries to
285 * sub-pixels, because this might lead from pixel-perfect rendering to
286 * subsampled rendering - this can lead to blurry texts. That is why we
287 * never do float divisions in this function.
288 */
289void correct_for_align(Align align, uint32_t w, Vector2i* pt) {
290
291 if (align == Align::kCenter)
292 pt->x -= w / 2;
293 else if (align == Align::kRight)
294 pt->x -= w;
295}
296
297/**
298 * Adjust the y coordinate in 'point 'pt' to vertically center an element with height 'h'.
299 */
300void center_vertically(uint32_t h, Vector2i* pt) {
301 pt->y -= h / 2;
302}
303} // namespace UI
304239
=== modified file 'src/graphic/text_layout.h'
--- src/graphic/text_layout.h 2019-04-18 16:50:35 +0000
+++ src/graphic/text_layout.h 2019-05-26 02:00:17 +0000
@@ -23,30 +23,26 @@
23#include <string>23#include <string>
2424
25#include "graphic/align.h"25#include "graphic/align.h"
26#include "graphic/styles/font_style.h"
27#include "graphic/styles/panel_styles.h"
28#include "graphic/text/rendered_text.h"
26#include "graphic/color.h"29#include "graphic/color.h"
27#include "graphic/font_handler.h"30#include "graphic/font_handler.h"
28#include "graphic/image.h"31#include "graphic/image.h"
29#include "graphic/panel_styles.h"
30#include "graphic/text/font_set.h"32#include "graphic/text/font_set.h"
31#include "graphic/text_constants.h"33
3234/**
33/**35 * Returns the exact width of the text rendered as editorfont for the given font size.
34 * This function replaces some HTML entities in strings, e.g. %nbsp;.36 * This function is inefficient; only call when we need the exact width.
35 * It is used by the renderers after the tags have been parsed.37 */
36 */38int text_width(const std::string& text, const UI::FontStyleInfo& style, float scale = 1.0f);
37void replace_entities(std::string* text);39
3840/**
39/**41 * Returns the exact height of the text rendered for the given font size and face.
40 * Returns the exact width of the text rendered as editorfont for the given font size.42 * This function is inefficient; only call when we need the exact height.
41 * This function is inefficient; only call when we need the exact width.43 */
42 */44int text_height(const UI::FontStyleInfo& style, float scale = 1.0f);
43int text_width(const std::string& text, int ptsize = UI_FONT_SIZE_SMALL);45int text_height(UI::FontStyle style, float scale = 1.0f);
44
45/**
46 * Returns the exact height of the text rendered for the given font size and face.
47 * This function is inefficient; only call when we need the exact height.
48 */
49int text_height(int ptsize = UI_FONT_SIZE_SMALL, UI::FontSet::Face face = UI::FontSet::Face::kSans);
5046
51/**47/**
52 * Checks it the given string is RichText or not. Does not do validity checking.48 * Checks it the given string is RichText or not. Does not do validity checking.
@@ -60,42 +56,35 @@
60 */56 */
61std::string richtext_escape(const std::string& given_text);57std::string richtext_escape(const std::string& given_text);
6258
59std::string as_richtext(const std::string&);
60
63/**61/**
64 * Convenience functions to convert simple text into a valid block62 * Convenience functions to convert simple text into a valid block
65 * of rich text which can be rendered.63 * of rich text which can be rendered.
66 */64 */
67std::string as_uifont(const std::string&,65std::string as_richtext_paragraph(const std::string& text, UI::FontStyle style, UI::Align align = UI::Align::kLeft);
68 int ptsize = UI_FONT_SIZE_SMALL,66std::string as_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style, UI::Align align = UI::Align::kLeft);
69 const RGBColor& clr = UI_FONT_CLR_FG,67std::string as_editor_richtext_paragraph(const std::string& text, const UI::FontStyleInfo& style);
70 UI::FontSet::Face face = UI::FontSet::Face::kSans);68
7169std::string as_listitem(const std::string&, UI::FontStyle style);
72// Same as as_aligned, but with the condensed font preselected.70
73std::string as_condensed(const std::string& text,
74 UI::Align align = UI::Align::kLeft,
75 int ptsize = UI_FONT_SIZE_SMALL,
76 const RGBColor& clr = UI_FONT_CLR_FG);
77
78std::string as_editorfont(const std::string& text,
79 int ptsize = UI_FONT_SIZE_SMALL,
80 const RGBColor& clr = UI_FONT_CLR_FG);
81
82std::string as_aligned(const std::string& txt,
83 UI::Align align,
84 int ptsize = UI_FONT_SIZE_SMALL,
85 const RGBColor& clr = UI_FONT_CLR_FG,
86 UI::FontSet::Face face = UI::FontSet::Face::kSans);
87
88std::string as_listitem(const std::string&,
89 int ptsize = UI_FONT_SIZE_SMALL,
90 const RGBColor& clr = UI_FONT_CLR_FG);
91
92std::string as_richtext(const std::string&);
93std::string as_tooltip(const std::string&);
94std::string as_waresinfo(const std::string&);
95std::string as_game_tip(const std::string&);71std::string as_game_tip(const std::string&);
72/// Format message to player. 'image' is either an image filename or a map object name.
73std::string as_mapobject_message(const std::string& image, int width, const std::string& txt, const RGBColor* player_color = nullptr);
96std::string as_message(const std::string& heading, const std::string& body);74std::string as_message(const std::string& heading, const std::string& body);
9775
98/**76/**
77
78 * Render 'text' with the given font style. If 'width' > 0 and the rendered image is too
79 * wide, it will first use the condensed font face and then make the text
80 * smaller until it fits 'width'. The resulting font size will not go below
81 * 'StyleManager::minimum_font_size()'.
82 */
83std::shared_ptr<const UI::RenderedText> autofit_text(const std::string& text,
84 const UI::FontStyleInfo& font_info,
85 int width);
86
87/**
99 * 'is_first' omits the vertical gap before the line.88 * 'is_first' omits the vertical gap before the line.
100 * 'noescape' is needed for error message formatting and does not call richtext_escape. */89 * 'noescape' is needed for error message formatting and does not call richtext_escape. */
101std::string as_heading_with_content(const std::string& header,90std::string as_heading_with_content(const std::string& header,
@@ -112,24 +101,4 @@
112/// Paragraph in menu info texts101/// Paragraph in menu info texts
113std::string as_content(const std::string& txt, UI::PanelStyle style);102std::string as_content(const std::string& txt, UI::PanelStyle style);
114103
115/**
116 * Render 'text' as ui_font. If 'width' > 0 and the rendered image is too
117 * wide, it will first use the condensed font face and then make the text
118 * smaller until it fits 'width'. The resulting font size will not go below
119 * 'kMinimumFontSize'.
120 */
121std::shared_ptr<const UI::RenderedText> autofit_ui_text(const std::string& text,
122 int width = 0,
123 RGBColor color = UI_FONT_CLR_FG,
124 int fontsize = UI_FONT_SIZE_SMALL);
125
126namespace UI {
127
128Align mirror_alignment(Align alignment, const std::string& checkme = "");
129
130void center_vertically(uint32_t h, Vector2i* pt);
131void correct_for_align(Align, uint32_t w, Vector2i* pt);
132
133} // namespace UI
134
135#endif // end of include guard: WL_GRAPHIC_TEXT_LAYOUT_H104#endif // end of include guard: WL_GRAPHIC_TEXT_LAYOUT_H
136105
=== modified file 'src/graphic/wordwrap.cc'
--- src/graphic/wordwrap.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/wordwrap.cc 2019-05-26 02:00:17 +0000
@@ -36,6 +36,30 @@
36#include "graphic/text/font_io.h"36#include "graphic/text/font_io.h"
37#include "graphic/text_layout.h"37#include "graphic/text_layout.h"
3838
39namespace {
40std::string as_editorfont(const std::string& text, int ptsize, const RGBColor& clr) {
41 // UI Text is always bold due to historic reasons
42 static boost::format f(
43 "<rt keep_spaces=1><p><font face=sans size=%i bold=1 shadow=1 color=%s>%s</font></p></rt>");
44 f % ptsize;
45 f % clr.hex_value();
46 f % richtext_escape(text);
47 return f.str();
48}
49
50int text_width(const std::string& text, int ptsize) {
51 RGBColor color(0, 0, 0);
52 return UI::g_fh->render(as_editorfont(text, ptsize - UI::g_fh->fontset()->size_offset(), color))
53 ->width();
54}
55
56int text_height(int ptsize) {
57 RGBColor font_color(0, 0, 0);
58 const UI::FontStyleInfo font_info("sans", font_color, ptsize, false, false, false, false);
59 return UI::g_fh->render(as_richtext_paragraph(UI::g_fh->fontset()->representative_character(), font_info))->height();
60}
61} // namespace
62
39namespace UI {63namespace UI {
4064
41WordWrap::WordWrap(int fontsize, const RGBColor& color, uint32_t gwrapwidth)65WordWrap::WordWrap(int fontsize, const RGBColor& color, uint32_t gwrapwidth)
@@ -299,7 +323,7 @@
299323
300 ++where.y;324 ++where.y;
301325
302 Align alignment = mirror_alignment(align);326 Align alignment = mirror_alignment(align, g_fh->fontset()->is_rtl());
303327
304 const int fontheight = text_height(fontsize_);328 const int fontheight = text_height(fontsize_);
305 for (uint32_t line = 0; line < lines_.size(); ++line, where.y += fontheight) {329 for (uint32_t line = 0; line < lines_.size(); ++line, where.y += fontheight) {
306330
=== modified file 'src/graphic/wordwrap.h'
--- src/graphic/wordwrap.h 2019-02-23 11:00:49 +0000
+++ src/graphic/wordwrap.h 2019-05-26 02:00:17 +0000
@@ -27,8 +27,8 @@
27#include "base/vector.h"27#include "base/vector.h"
28#include "graphic/align.h"28#include "graphic/align.h"
29#include "graphic/color.h"29#include "graphic/color.h"
30#include "graphic/graphic.h"
30#include "graphic/text/sdl_ttf_font.h"31#include "graphic/text/sdl_ttf_font.h"
31#include "graphic/text_constants.h"
3232
33class RenderTarget;33class RenderTarget;
3434
@@ -38,9 +38,9 @@
38 * Helper struct that provides word wrapping and related functionality.38 * Helper struct that provides word wrapping and related functionality.
39 */39 */
40struct WordWrap {40struct WordWrap {
41 WordWrap(int fontsize = UI_FONT_SIZE_SMALL,41 static constexpr int kLineMargin = 1;
42 const RGBColor& color = UI_FONT_CLR_FG,42
43 uint32_t wrapwidth = std::numeric_limits<uint32_t>::max());43 explicit WordWrap(int fontsize, const RGBColor& color, uint32_t wrapwidth);
4444
45 void set_wrapwidth(uint32_t wrapwidth);45 void set_wrapwidth(uint32_t wrapwidth);
4646
4747
=== modified file 'src/io/filesystem/filesystem.cc'
--- src/io/filesystem/filesystem.cc 2019-02-23 11:00:49 +0000
+++ src/io/filesystem/filesystem.cc 2019-05-26 02:00:17 +0000
@@ -205,7 +205,7 @@
205 (boost::format(pgettext("illegal_filename_characters", "%s at the start of the filename")) %205 (boost::format(pgettext("illegal_filename_characters", "%s at the start of the filename")) %
206 richtext_escape(i18n::localize_list(starting_characters, i18n::ConcatenateWith::OR)))206 richtext_escape(i18n::localize_list(starting_characters, i18n::ConcatenateWith::OR)))
207 .str(),207 .str(),
208 UI_FONT_SIZE_MESSAGE));208 UI::FontStyle::kWuiMessageParagraph));
209209
210 const std::string illegal(as_listitem(210 const std::string illegal(as_listitem(
211 /** TRANSLATORS: Tooltip entry for characters in illegal filenames.211 /** TRANSLATORS: Tooltip entry for characters in illegal filenames.
@@ -213,7 +213,7 @@
213 (boost::format(pgettext("illegal_filename_characters", "%s anywhere in the filename")) %213 (boost::format(pgettext("illegal_filename_characters", "%s anywhere in the filename")) %
214 richtext_escape(i18n::localize_list(illegal_filename_characters, i18n::ConcatenateWith::OR)))214 richtext_escape(i18n::localize_list(illegal_filename_characters, i18n::ConcatenateWith::OR)))
215 .str(),215 .str(),
216 UI_FONT_SIZE_MESSAGE));216 UI::FontStyle::kWuiMessageParagraph));
217217
218 return (boost::format("%s%s%s") %218 return (boost::format("%s%s%s") %
219 /** TRANSLATORS: Tooltip header for characters in illegal filenames.219 /** TRANSLATORS: Tooltip header for characters in illegal filenames.
220220
=== modified file 'src/logic/map_objects/CMakeLists.txt'
--- src/logic/map_objects/CMakeLists.txt 2019-05-05 18:53:14 +0000
+++ src/logic/map_objects/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -125,7 +125,6 @@
125 graphic_fonthandler125 graphic_fonthandler
126 graphic_image_io126 graphic_image_io
127 graphic_surface127 graphic_surface
128 graphic_text_constants
129 graphic_text_layout128 graphic_text_layout
130 helper129 helper
131 io_fileread130 io_fileread
132131
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc 2019-05-19 12:25:24 +0000
+++ src/logic/map_objects/immovable.cc 2019-05-26 02:00:17 +0000
@@ -32,7 +32,6 @@
32#include "config.h"32#include "config.h"
33#include "graphic/graphic.h"33#include "graphic/graphic.h"
34#include "graphic/rendertarget.h"34#include "graphic/rendertarget.h"
35#include "graphic/text_constants.h"
36#include "helper.h"35#include "helper.h"
37#include "io/fileread.h"36#include "io/fileread.h"
38#include "io/filewrite.h"37#include "io/filewrite.h"
@@ -526,9 +525,7 @@
526525
527 // Additionally, if statistics are enabled, draw a progression string526 // Additionally, if statistics are enabled, draw a progression string
528 do_draw_info(draw_text, descr().descname(),527 do_draw_info(draw_text, descr().descname(),
529 (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %528 g_gr->styles().color_tag((boost::format(_("%i%% built")) % (100 * done / total)).str(), g_gr->styles().building_statistics_style().construction_color()),
530 (boost::format(_("%i%% built")) % (100 * done / total)).str())
531 .str(),
532 point_on_dst, scale, dst);529 point_on_dst, scale, dst);
533}530}
534531
535532
=== modified file 'src/logic/map_objects/map_object.cc'
--- src/logic/map_objects/map_object.cc 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/map_object.cc 2019-05-26 02:00:17 +0000
@@ -32,6 +32,7 @@
32#include "graphic/font_handler.h"32#include "graphic/font_handler.h"
33#include "graphic/graphic.h"33#include "graphic/graphic.h"
34#include "graphic/rendertarget.h"34#include "graphic/rendertarget.h"
35#include "graphic/style_manager.h"
35#include "graphic/text_layout.h"36#include "graphic/text_layout.h"
36#include "io/fileread.h"37#include "io/fileread.h"
37#include "io/filewrite.h"38#include "io/filewrite.h"
@@ -485,20 +486,25 @@
485 if (scale < 1.f) {486 if (scale < 1.f) {
486 return;487 return;
487 }488 }
488 const int font_size = scale * UI_FONT_SIZE_SMALL;489
490 UI::FontStyleInfo census_font(g_gr->styles().building_statistics_style().census_font());
491 census_font.set_size(scale * census_font.size());
489492
490 // We always render this so we can have a stable position for the statistics string.493 // We always render this so we can have a stable position for the statistics string.
491 std::shared_ptr<const UI::RenderedText> rendered_census =494 std::shared_ptr<const UI::RenderedText> rendered_census =
492 UI::g_fh->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);495 UI::g_fh->render(as_richtext_paragraph(census, census_font, UI::Align::kCenter), 120 * scale);
493 Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;496 Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;
494 if ((draw_text & TextToDraw::kCensus) != TextToDraw::kNone) {497 if ((draw_text & TextToDraw::kCensus) != TextToDraw::kNone) {
495 rendered_census->draw(*dst, position, UI::Align::kCenter);498 rendered_census->draw(*dst, position, UI::Align::kCenter);
496 }499 }
497500
498 if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone && !statictics.empty()) {501 if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone && !statictics.empty()) {
502 UI::FontStyleInfo statistics_font(g_gr->styles().building_statistics_style().statistics_font());
503 statistics_font.set_size(scale * statistics_font.size());
504
499 std::shared_ptr<const UI::RenderedText> rendered_statistics =505 std::shared_ptr<const UI::RenderedText> rendered_statistics =
500 UI::g_fh->render(as_condensed(statictics, UI::Align::kCenter, font_size));506 UI::g_fh->render(as_richtext_paragraph(statictics, statistics_font, UI::Align::kCenter));
501 position.y += rendered_census->height() + text_height(font_size) / 4;507 position.y += rendered_census->height() + text_height(statistics_font) / 4;
502 rendered_statistics->draw(*dst, position, UI::Align::kCenter);508 rendered_statistics->draw(*dst, position, UI::Align::kCenter);
503 }509 }
504}510}
505511
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc 2019-05-11 13:48:12 +0000
+++ src/logic/map_objects/tribes/building.cc 2019-05-26 02:00:17 +0000
@@ -33,7 +33,7 @@
33#include "economy/input_queue.h"33#include "economy/input_queue.h"
34#include "economy/request.h"34#include "economy/request.h"
35#include "graphic/rendertarget.h"35#include "graphic/rendertarget.h"
36#include "graphic/text_constants.h"36#include "graphic/text_layout.h"
37#include "io/filesystem/filesystem.h"37#include "io/filesystem/filesystem.h"
38#include "io/filesystem/layered_filesystem.h"38#include "io/filesystem/layered_filesystem.h"
39#include "logic/game.h"39#include "logic/game.h"
@@ -774,10 +774,10 @@
774 uint32_t throttle_time,774 uint32_t throttle_time,
775 uint32_t throttle_radius) {775 uint32_t throttle_radius) {
776 const std::string rt_description =776 const std::string rt_description =
777 (boost::format("<div padding_r=10><p><img object=%s color=%s></p></div>"777 as_mapobject_message(descr().name(),
778 "<div width=*><p><font size=%d>%s</font></p></div>") %778 descr().representative_image()->width(),
779 descr().name() % owner().get_playercolor().hex_value() % UI_FONT_SIZE_MESSAGE % description)779 description,
780 .str();780 &owner().get_playercolor());
781781
782 std::unique_ptr<Message> msg(new Message(msgtype, game.get_gametime(), title, icon_filename,782 std::unique_ptr<Message> msg(new Message(msgtype, game.get_gametime(), title, icon_filename,
783 heading, rt_description, get_position(),783 heading, rt_description, get_position(),
784784
=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
--- src/logic/map_objects/tribes/constructionsite.cc 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/tribes/constructionsite.cc 2019-05-26 02:00:17 +0000
@@ -30,7 +30,6 @@
30#include "graphic/animation.h"30#include "graphic/animation.h"
31#include "graphic/graphic.h"31#include "graphic/graphic.h"
32#include "graphic/rendertarget.h"32#include "graphic/rendertarget.h"
33#include "graphic/text_constants.h"
34#include "logic/editor_game_base.h"33#include "logic/editor_game_base.h"
35#include "logic/game.h"34#include "logic/game.h"
36#include "logic/map_objects/tribes/tribe_descr.h"35#include "logic/map_objects/tribes/tribe_descr.h"
@@ -110,9 +109,7 @@
110109
111void ConstructionSite::update_statistics_string(std::string* s) {110void ConstructionSite::update_statistics_string(std::string* s) {
112 unsigned int percent = (get_built_per64k() * 100) >> 16;111 unsigned int percent = (get_built_per64k() * 100) >> 16;
113 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %112 *s = g_gr->styles().color_tag((boost::format(_("%i%% built")) % percent).str(), g_gr->styles().building_statistics_style().construction_color());
114 (boost::format(_("%i%% built")) % percent))
115 .str();
116}113}
117114
118/*115/*
119116
=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-05-26 02:00:17 +0000
@@ -29,7 +29,6 @@
29#include "economy/wares_queue.h"29#include "economy/wares_queue.h"
30#include "graphic/animation.h"30#include "graphic/animation.h"
31#include "graphic/rendertarget.h"31#include "graphic/rendertarget.h"
32#include "graphic/text_constants.h"
33#include "logic/editor_game_base.h"32#include "logic/editor_game_base.h"
34#include "logic/game.h"33#include "logic/game.h"
35#include "logic/map_objects/tribes/tribe_descr.h"34#include "logic/map_objects/tribes/tribe_descr.h"
@@ -103,9 +102,7 @@
103*/102*/
104void DismantleSite::update_statistics_string(std::string* s) {103void DismantleSite::update_statistics_string(std::string* s) {
105 unsigned int percent = (get_built_per64k() * 100) >> 16;104 unsigned int percent = (get_built_per64k() * 100) >> 16;
106 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %105 *s = g_gr->styles().color_tag((boost::format(_("%u%% dismantled")) % percent).str(), g_gr->styles().building_statistics_style().construction_color());
107 (boost::format(_("%u%% dismantled")) % percent))
108 .str();
109}106}
110107
111/*108/*
112109
=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
--- src/logic/map_objects/tribes/militarysite.cc 2019-05-18 20:43:25 +0000
+++ src/logic/map_objects/tribes/militarysite.cc 2019-05-26 02:00:17 +0000
@@ -30,7 +30,6 @@
30#include "base/macros.h"30#include "base/macros.h"
31#include "economy/flag.h"31#include "economy/flag.h"
32#include "economy/request.h"32#include "economy/request.h"
33#include "graphic/text_constants.h"
34#include "logic/editor_game_base.h"33#include "logic/editor_game_base.h"
35#include "logic/game.h"34#include "logic/game.h"
36#include "logic/map_objects/findbob.h"35#include "logic/map_objects/findbob.h"
@@ -396,10 +395,9 @@
396 .str();395 .str();
397 }396 }
398 }397 }
399 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %398 *s = g_gr->styles().color_tag(
400 // Line break to make Codecheck happy.399 // Line break to make Codecheck happy.
401 *s)400 *s, g_gr->styles().building_statistics_style().medium_color());
402 .str();
403}401}
404402
405bool MilitarySite::init(EditorGameBase& egbase) {403bool MilitarySite::init(EditorGameBase& egbase) {
406404
=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
--- src/logic/map_objects/tribes/productionsite.cc 2019-05-22 15:46:08 +0000
+++ src/logic/map_objects/tribes/productionsite.cc 2019-05-26 02:00:17 +0000
@@ -32,7 +32,6 @@
32#include "economy/ware_instance.h"32#include "economy/ware_instance.h"
33#include "economy/wares_queue.h"33#include "economy/wares_queue.h"
34#include "economy/workers_queue.h"34#include "economy/workers_queue.h"
35#include "graphic/text_constants.h"
36#include "logic/editor_game_base.h"35#include "logic/editor_game_base.h"
37#include "logic/game.h"36#include "logic/game.h"
38#include "logic/game_data_error.h"37#include "logic/game_data_error.h"
@@ -296,28 +295,23 @@
296 nr_workers += working_positions_[--i].worker ? 1 : 0;295 nr_workers += working_positions_[--i].worker ? 1 : 0;
297296
298 if (nr_workers == 0) {297 if (nr_workers == 0) {
299 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BAD.hex_value() %298 *s = g_gr->styles().color_tag(_("(not occupied)"), g_gr->styles().building_statistics_style().low_color());
300 _("(not occupied)"))
301 .str();
302 return;299 return;
303 }300 }
304301
305 if (uint32_t const nr_requests = nr_working_positions - nr_workers) {302 if (uint32_t const nr_requests = nr_working_positions - nr_workers) {
306 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BAD.hex_value() %303 *s = g_gr->styles().color_tag(
307 (nr_requests == 1 ?304 (nr_requests == 1 ?
308 /** TRANSLATORS: Productivity label on a building if there is 1 worker missing */305 /** TRANSLATORS: Productivity label on a building if there is 1 worker missing */
309 _("Worker missing") :306 _("Worker missing") :
310 /** TRANSLATORS: Productivity label on a building if there is more than 1 worker307 /** TRANSLATORS: Productivity label on a building if there is more than 1 worker
311 missing. If you need plural forms here, please let us know. */308 missing. If you need plural forms here, please let us know. */
312 _("Workers missing")))309 _("Workers missing")), g_gr->styles().building_statistics_style().low_color());
313 .str();
314 return;310 return;
315 }311 }
316312
317 if (is_stopped_) {313 if (is_stopped_) {
318 *s = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_BRIGHT.hex_value() %314 *s = g_gr->styles().color_tag(_("(stopped)"), g_gr->styles().building_statistics_style().neutral_color());
319 _("(stopped)"))
320 .str();
321 return;315 return;
322 }316 }
323 *s = statistics_string_on_changed_statistics_;317 *s = statistics_string_on_changed_statistics_;
@@ -407,34 +401,32 @@
407401
408 const unsigned int lastPercOk = (lastOk * 100) / (STATISTICS_VECTOR_LENGTH / 2);402 const unsigned int lastPercOk = (lastOk * 100) / (STATISTICS_VECTOR_LENGTH / 2);
409403
410 std::string color;
411 if (percOk < 33)
412 color = UI_FONT_CLR_BAD.hex_value();
413 else if (percOk < 66)
414 color = UI_FONT_CLR_OK.hex_value();
415 else
416 color = UI_FONT_CLR_GOOD.hex_value();
417 const std::string perc_str =404 const std::string perc_str =
418 (boost::format("<font color=%s>%s</font>") % color % (boost::format(_("%i%%")) % percOk))405 g_gr->styles().color_tag((boost::format(_("%i%%")) % percOk).str(),
419 .str();406 (percOk < 33) ? g_gr->styles().building_statistics_style().low_color() :
420407 (percOk < 66) ?
421 std::string trend;408 g_gr->styles().building_statistics_style().medium_color() :
422 if (lastPercOk > percOk) {409 g_gr->styles().building_statistics_style().high_color());
423 trend_ = Trend::kRising;
424 color = UI_FONT_CLR_GOOD.hex_value();
425 trend = "+";
426 } else if (lastPercOk < percOk) {
427 trend_ = Trend::kFalling;
428 color = UI_FONT_CLR_BAD.hex_value();
429 trend = "-";
430 } else {
431 trend_ = Trend::kUnchanged;
432 color = UI_FONT_CLR_BRIGHT.hex_value();
433 trend = "=";
434 }
435 const std::string trend_str = (boost::format("<font color=%s>%s</font>") % color % trend).str();
436410
437 if (0 < percOk && percOk < 100) {411 if (0 < percOk && percOk < 100) {
412 RGBColor color = g_gr->styles().building_statistics_style().high_color();
413 std::string trend;
414 if (lastPercOk > percOk) {
415 trend_ = Trend::kRising;
416 color = g_gr->styles().building_statistics_style().high_color();
417 trend = "+";
418 } else if (lastPercOk < percOk) {
419 trend_ = Trend::kFalling;
420 color = g_gr->styles().building_statistics_style().low_color();
421 trend = "-";
422 } else {
423 trend_ = Trend::kUnchanged;
424 color = g_gr->styles().building_statistics_style().neutral_color();
425 trend = "=";
426 }
427
428 const std::string trend_str = g_gr->styles().color_tag((boost::format(_("%i%%")) % trend).str(), color);
429
438 // TODO(GunChleoc): We might need to reverse the order here for RTL languages430 // TODO(GunChleoc): We might need to reverse the order here for RTL languages
439 statistics_string_on_changed_statistics_ =431 statistics_string_on_changed_statistics_ =
440 (boost::format("%s\u2009%s") % perc_str % trend_str).str();432 (boost::format("%s\u2009%s") % perc_str % trend_str).str();
441433
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc 2019-05-11 13:48:12 +0000
+++ src/logic/map_objects/tribes/ship.cc 2019-05-26 02:00:17 +0000
@@ -31,7 +31,7 @@
31#include "economy/portdock.h"31#include "economy/portdock.h"
32#include "economy/wares_queue.h"32#include "economy/wares_queue.h"
33#include "graphic/rendertarget.h"33#include "graphic/rendertarget.h"
34#include "graphic/text_constants.h"34#include "graphic/text_layout.h"
35#include "io/fileread.h"35#include "io/fileread.h"
36#include "io/filewrite.h"36#include "io/filewrite.h"
37#include "logic/game.h"37#include "logic/game.h"
@@ -1061,9 +1061,7 @@
1061 case (ShipStates::kSinkAnimation):1061 case (ShipStates::kSinkAnimation):
1062 break;1062 break;
1063 }1063 }
1064 statistics_string = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %1064 statistics_string = g_gr->styles().color_tag(statistics_string, g_gr->styles().building_statistics_style().medium_color());
1065 statistics_string)
1066 .str();
1067 }1065 }
10681066
1069 do_draw_info(draw_text, shipname_, statistics_string, calc_drawpos(egbase, point_on_dst, scale),1067 do_draw_info(draw_text, shipname_, statistics_string, calc_drawpos(egbase, point_on_dst, scale),
@@ -1128,10 +1126,7 @@
1128 const std::string& description,1126 const std::string& description,
1129 const std::string& picture) {1127 const std::string& picture) {
1130 const std::string rt_description =1128 const std::string rt_description =
1131 (boost::format("<div padding_r=10><p><img src=%s></p></div>"1129 as_mapobject_message(picture, g_gr->images().get(picture)->width(), description);
1132 "<div width=*><p><font size=%d>%s</font></p></div>") %
1133 picture % UI_FONT_SIZE_MESSAGE % description)
1134 .str();
11351130
1136 get_owner()->add_message(game, std::unique_ptr<Message>(new Message(1131 get_owner()->add_message(game, std::unique_ptr<Message>(new Message(
1137 Message::Type::kSeafaring, game.get_gametime(), title, picture,1132 Message::Type::kSeafaring, game.get_gametime(), title, picture,
11381133
=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc 2019-05-25 10:47:18 +0000
+++ src/logic/map_objects/tribes/worker.cc 2019-05-26 02:00:17 +0000
@@ -33,8 +33,9 @@
33#include "economy/portdock.h"33#include "economy/portdock.h"
34#include "economy/road.h"34#include "economy/road.h"
35#include "economy/transfer.h"35#include "economy/transfer.h"
36#include "graphic/graphic.h"
36#include "graphic/rendertarget.h"37#include "graphic/rendertarget.h"
37#include "graphic/text_constants.h"38#include "graphic/text_layout.h"
38#include "helper.h"39#include "helper.h"
39#include "io/fileread.h"40#include "io/fileread.h"
40#include "io/filewrite.h"41#include "io/filewrite.h"
@@ -972,12 +973,12 @@
972 MapObjectDescr::OwnerType::kTribe, get_owner());973 MapObjectDescr::OwnerType::kTribe, get_owner());
973974
974 // Geologist also sends a message notifying the player975 // Geologist also sends a message notifying the player
976 // TODO(GunChleoc): We keep formatting this even when timeout has not elapsed
975 if (rdescr && rdescr->detectable() && position.field->get_resources_amount()) {977 if (rdescr && rdescr->detectable() && position.field->get_resources_amount()) {
976 const std::string message =978 const std::string rt_description =
977 (boost::format("<div padding_r=10><p><img object=%s></p></div>"979 as_mapobject_message(ri.descr().name(),
978 "<div width=*><p><font size=%d>%s</font></p></div>") %980 g_gr->images().get(rdescr->representative_image())->width(),
979 ri.descr().name() % UI_FONT_SIZE_MESSAGE % _("A geologist found resources."))981 _("A geologist found resources."));
980 .str();
981982
982 // We should add a message to the player's message queue - but only,983 // We should add a message to the player's message queue - but only,
983 // if there is not already a similar one in list.984 // if there is not already a similar one in list.
@@ -985,7 +986,7 @@
985 game,986 game,
986 std::unique_ptr<Message>(new Message(Message::Type::kGeologists, game.get_gametime(),987 std::unique_ptr<Message>(new Message(Message::Type::kGeologists, game.get_gametime(),
987 rdescr->descname(), rdescr->representative_image(),988 rdescr->descname(), rdescr->representative_image(),
988 ri.descr().descname(), message, position, serial_,989 ri.descr().descname(), rt_description, position, serial_,
989 rdescr->name())),990 rdescr->name())),
990 rdescr->timeout_ms(), rdescr->timeout_radius());991 rdescr->timeout_ms(), rdescr->timeout_radius());
991 }992 }
992993
=== modified file 'src/ui_basic/CMakeLists.txt'
--- src/ui_basic/CMakeLists.txt 2019-04-09 04:51:44 +0000
+++ src/ui_basic/CMakeLists.txt 2019-05-26 02:00:17 +0000
@@ -67,7 +67,6 @@
67 graphic_styles67 graphic_styles
68 graphic_surface68 graphic_surface
69 graphic_text69 graphic_text
70 graphic_text_constants
71 graphic_text_layout70 graphic_text_layout
72 graphic_wordwrap71 graphic_wordwrap
73 io_filesystem72 io_filesystem
7473
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/button.cc 2019-05-26 02:00:17 +0000
@@ -24,7 +24,6 @@
24#include "graphic/image.h"24#include "graphic/image.h"
25#include "graphic/rendertarget.h"25#include "graphic/rendertarget.h"
26#include "graphic/style_manager.h"26#include "graphic/style_manager.h"
27#include "graphic/text_constants.h"
28#include "graphic/text_layout.h"27#include "graphic/text_layout.h"
29#include "ui_basic/mouse_constants.h"28#include "ui_basic/mouse_constants.h"
3029
@@ -58,7 +57,7 @@
58 time_nextact_(0),57 time_nextact_(0),
59 title_(title_text),58 title_(title_text),
60 title_image_(title_image),59 title_image_(title_image),
61 background_style_(g_gr->styles().button_style(init_style)) {60 style_(&g_gr->styles().button_style(init_style)) {
62 set_thinks(false);61 set_thinks(false);
63 // Don't allow focus62 // Don't allow focus
64 assert(!get_can_focus());63 assert(!get_can_focus());
@@ -89,7 +88,7 @@
89 UI::Button::ImageMode::kShrink) {88 UI::Button::ImageMode::kShrink) {
90 // Automatically resize for font height and give it a margin.89 // Automatically resize for font height and give it a margin.
91 if (h < 1) {90 if (h < 1) {
92 int new_height = text_height() + 4;91 const int new_height = text_height(g_gr->styles().button_style(init_style).enabled().font()) + 4;
93 set_desired_size(w, new_height);92 set_desired_size(w, new_height);
94 set_size(w, new_height);93 set_size(w, new_height);
95 }94 }
@@ -170,8 +169,10 @@
170 const bool is_monochrome =169 const bool is_monochrome =
171 !enabled_ && static_cast<int>(disable_style_ & ButtonDisableStyle::kMonochrome);170 !enabled_ && static_cast<int>(disable_style_ & ButtonDisableStyle::kMonochrome);
172171
172 const UI::TextPanelStyleInfo& style_to_use = is_monochrome ? style_->disabled() : style_->enabled();
173
173 // Draw the background174 // Draw the background
174 draw_background(dst, *background_style_);175 draw_background(dst, style_to_use.background());
175176
176 if (is_flat && highlighted_)177 if (is_flat && highlighted_)
177 dst.brighten_rect(Recti(0, 0, get_w(), get_h()), MOUSE_OVER_BRIGHT_FACTOR);178 dst.brighten_rect(Recti(0, 0, get_w(), get_h()), MOUSE_OVER_BRIGHT_FACTOR);
@@ -216,8 +217,11 @@
216 } else if (title_.length()) {217 } else if (title_.length()) {
217 // Otherwise draw title string centered218 // Otherwise draw title string centered
218 std::shared_ptr<const UI::RenderedText> rendered_text =219 std::shared_ptr<const UI::RenderedText> rendered_text =
219 autofit_ui_text(title_, get_inner_w() - 2 * kButtonImageMargin,220 autofit_text(
220 is_monochrome ? UI_FONT_CLR_DISABLED : UI_FONT_CLR_FG);221 richtext_escape(title_),
222 style_to_use.font(),
223 get_inner_w() - 2 * kButtonImageMargin);
224
221 // Blit on pixel boundary (not float), so that the text is blitted pixel perfect.225 // Blit on pixel boundary (not float), so that the text is blitted pixel perfect.
222 rendered_text->draw(dst, Vector2i((get_w() - rendered_text->width()) / 2,226 rendered_text->draw(dst, Vector2i((get_w() - rendered_text->width()) / 2,
223 (get_h() - rendered_text->height()) / 2));227 (get_h() - rendered_text->height()) / 2));
@@ -363,8 +367,8 @@
363 UI::Button::VisualState::kRaised);367 UI::Button::VisualState::kRaised);
364}368}
365369
366void Button::set_background_style(UI::ButtonStyle bstyle) {370void Button::set_style(UI::ButtonStyle bstyle) {
367 background_style_ = g_gr->styles().button_style(bstyle);371 style_ = &g_gr->styles().button_style(bstyle);
368}372}
369373
370void Button::toggle() {374void Button::toggle() {
371375
=== modified file 'src/ui_basic/button.h'
--- src/ui_basic/button.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/button.h 2019-05-26 02:00:17 +0000
@@ -25,7 +25,7 @@
25#include <boost/signals2.hpp>25#include <boost/signals2.hpp>
2626
27#include "graphic/color.h"27#include "graphic/color.h"
28#include "graphic/text_layout.h"28#include "graphic/styles/button_style.h"
29#include "ui_basic/panel.h"29#include "ui_basic/panel.h"
3030
31namespace UI {31namespace UI {
@@ -146,7 +146,7 @@
146 void set_perm_pressed(bool pressed);146 void set_perm_pressed(bool pressed);
147147
148 /// Change the background style of the button.148 /// Change the background style of the button.
149 void set_background_style(UI::ButtonStyle bstyle);149 void set_style(UI::ButtonStyle bstyle);
150150
151 /// Convenience function. Toggles between raised and permpressed style151 /// Convenience function. Toggles between raised and permpressed style
152 void toggle();152 void toggle();
@@ -172,7 +172,7 @@
172 std::string title_; // title string used when title_image_ == nullptr172 std::string title_; // title string used when title_image_ == nullptr
173 const Image* title_image_; // custom icon on the button173 const Image* title_image_; // custom icon on the button
174174
175 const UI::PanelStyleInfo* background_style_; // Background color and texture. Not owned.175 const UI::ButtonStyleInfo* style_; // Background color and texture. Not owned.
176};176};
177177
178} // namespace UI178} // namespace UI
179179
=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/checkbox.cc 2019-05-26 02:00:17 +0000
@@ -80,7 +80,7 @@
80 }80 }
81 rendered_text_ = label_text_.empty() ?81 rendered_text_ = label_text_.empty() ?
82 nullptr :82 nullptr :
83 UI::g_fh->render(as_uifont(label_text_), text_width(get_w(), pic_width));83 UI::g_fh->render(as_richtext_paragraph(label_text_, UI::FontStyle::kLabel), text_width(get_w(), pic_width));
84 if (rendered_text_.get()) {84 if (rendered_text_.get()) {
85 w = std::max(rendered_text_->width() + kPadding + pic_width, w);85 w = std::max(rendered_text_->width() + kPadding + pic_width, w);
86 h = std::max(rendered_text_->height(), h);86 h = std::max(rendered_text_->height(), h);
8787
=== modified file 'src/ui_basic/dropdown.cc'
--- src/ui_basic/dropdown.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/dropdown.cc 2019-05-26 02:00:17 +0000
@@ -29,18 +29,25 @@
29#include "graphic/font_handler.h"29#include "graphic/font_handler.h"
30#include "graphic/graphic.h"30#include "graphic/graphic.h"
31#include "graphic/rendertarget.h"31#include "graphic/rendertarget.h"
32#include "graphic/text_layout.h"
32#include "ui_basic/mouse_constants.h"33#include "ui_basic/mouse_constants.h"
33#include "ui_basic/tabpanel.h"34#include "ui_basic/tabpanel.h"
34#include "ui_basic/window.h"35#include "ui_basic/window.h"
3536
36namespace {37namespace {
3738int base_height(int button_dimension, UI::PanelStyle style) {
38int base_height(int button_dimension) {39 int result = std::max(
39 return std::max(
40 button_dimension,40 button_dimension,
41 UI::g_fh->render(as_uifont(UI::g_fh->fontset()->representative_character()))->height() + 2);41 text_height(g_gr->styles().table_style(style).enabled()) + 2);
42}42 return result;
4343}
44
45
46/*
47int BaseDropdown::base_height(int button_dimension) const {
48 return std::max(button_dimension, text_height(g_gr->styles().table_style(UI::PanelStyle::kWui).enabled()) + 2);
49}
50*/
44} // namespace51} // namespace
4552
46namespace UI {53namespace UI {
@@ -61,13 +68,14 @@
61 y,68 y,
62 type == DropdownType::kPictorial ? button_dimension : w,69 type == DropdownType::kPictorial ? button_dimension : w,
63 // Height only to fit the button, so we can use this in Box layout.70 // Height only to fit the button, so we can use this in Box layout.
64 base_height(button_dimension)),71 base_height(button_dimension, style)),
65 id_(next_id_++),72 id_(next_id_++),
66 max_list_height_(h - 2 * get_h()),73 max_list_height_(h - 2 * get_h()),
67 list_width_(w),74 list_width_(w),
68 list_offset_x_(0),75 list_offset_x_(0),
69 list_offset_y_(0),76 list_offset_y_(0),
70 button_dimension_(button_dimension),77 button_dimension_(button_dimension),
78 base_height_(base_height(button_dimension, style)),
71 mouse_tolerance_(50),79 mouse_tolerance_(50),
72 button_box_(this, 0, 0, UI::Box::Horizontal, w, h),80 button_box_(this, 0, 0, UI::Box::Horizontal, w, h),
73 push_button_(type == DropdownType::kTextual ?81 push_button_(type == DropdownType::kTextual ?
@@ -154,16 +162,16 @@
154}162}
155163
156void BaseDropdown::set_height(int height) {164void BaseDropdown::set_height(int height) {
157 max_list_height_ = height - base_height(button_dimension_);165 max_list_height_ = height - base_height_;
158 layout();166 layout();
159}167}
160168
161void BaseDropdown::set_max_items(int items) {169void BaseDropdown::set_max_items(int items) {
162 set_height(list_->get_lineheight() * items + base_height(button_dimension_));170 set_height(list_->get_lineheight() * items + base_height_);
163}171}
164172
165void BaseDropdown::layout() {173void BaseDropdown::layout() {
166 const int base_h = base_height(button_dimension_);174 const int base_h = base_height_;
167 const int w = type_ == DropdownType::kPictorial ? button_dimension_ : get_w();175 const int w = type_ == DropdownType::kPictorial ? button_dimension_ : get_w();
168 button_box_.set_size(w, base_h);176 button_box_.set_size(w, base_h);
169 display_button_.set_desired_size(177 display_button_.set_desired_size(
170178
=== modified file 'src/ui_basic/dropdown.h'
--- src/ui_basic/dropdown.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/dropdown.h 2019-05-26 02:00:17 +0000
@@ -179,7 +179,8 @@
179 int list_width_;179 int list_width_;
180 int list_offset_x_;180 int list_offset_x_;
181 int list_offset_y_;181 int list_offset_y_;
182 int button_dimension_;182 const int button_dimension_;
183 const int base_height_;
183 const int mouse_tolerance_; // Allow mouse outside the panel a bit before autocollapse184 const int mouse_tolerance_; // Allow mouse outside the panel a bit before autocollapse
184 UI::Box button_box_;185 UI::Box button_box_;
185 UI::Button* push_button_; // Only used in textual dropdowns186 UI::Button* push_button_; // Only used in textual dropdowns
186187
=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc 2019-05-25 08:25:55 +0000
+++ src/ui_basic/editbox.cc 2019-05-26 02:00:17 +0000
@@ -34,7 +34,6 @@
34#include "graphic/text/bidi.h"34#include "graphic/text/bidi.h"
35#include "graphic/text/font_set.h"35#include "graphic/text/font_set.h"
36#include "graphic/text/rt_errors.h"36#include "graphic/text/rt_errors.h"
37#include "graphic/text_constants.h"
38#include "graphic/text_layout.h"37#include "graphic/text_layout.h"
39#include "ui_basic/mouse_constants.h"38#include "ui_basic/mouse_constants.h"
4039
@@ -43,23 +42,30 @@
43namespace {42namespace {
4443
45constexpr int kMarginX = 4;44constexpr int kMarginX = 4;
45constexpr int kLineMargin = 1;
4646
47} // namespace47} // namespace
4848
49namespace UI {49namespace UI {
5050
51struct EditBoxImpl {51struct EditBoxImpl {
52 /**52 explicit EditBoxImpl(const UI::TextPanelStyleInfo& init_style) :
53 * Font used for rendering text.53 background_style(&init_style.background()), font_style(&init_style.font()),
54 */54 margin(init_style.background().margin()), font_scale(1.0f) {
55 /*@{*/55 }
56 std::string fontname;
57 uint32_t fontsize;
58 /*@}*/
5956
60 /// Background color and texture57 /// Background color and texture
61 const UI::PanelStyleInfo* background_style;58 const UI::PanelStyleInfo* background_style;
6259
60 /// Font style
61 const UI::FontStyleInfo* font_style;
62
63 /// Margin around the test
64 int margin;
65
66 /// Scale for font size
67 float font_scale;
68
63 /// Maximum number of characters in the input69 /// Maximum number of characters in the input
64 uint32_t maxLength;70 uint32_t maxLength;
6571
@@ -80,22 +86,17 @@
80 int32_t x,86 int32_t x,
81 int32_t y,87 int32_t y,
82 uint32_t w,88 uint32_t w,
83 uint32_t h,89 UI::PanelStyle style)
84 int margin_y,90 : Panel(parent, x, y, w,
85 UI::PanelStyle style,91 text_height(g_gr->styles().editbox_style(style).font())
86 int font_size)92 + 2 * g_gr->styles().editbox_style(style).background().margin()),
87 : Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),93 m_(new EditBoxImpl(g_gr->styles().editbox_style(style))),
88 m_(new EditBoxImpl),
89 history_active_(false),94 history_active_(false),
90 history_position_(-1),95 history_position_(-1),
91 password_(false),96 password_(false),
92 warning_(false) {97 warning_(false) {
93 set_thinks(false);98 set_thinks(false);
9499
95 m_->background_style = g_gr->styles().editbox_style(style);
96 m_->fontname = UI::g_fh->fontset()->sans();
97 m_->fontsize = font_size;
98
99 // Set alignment to the UI language's principal writing direction100 // Set alignment to the UI language's principal writing direction
100 m_->align = UI::g_fh->fontset()->is_rtl() ? UI::Align::kRight : UI::Align::kLeft;101 m_->align = UI::g_fh->fontset()->is_rtl() ? UI::Align::kRight : UI::Align::kLeft;
101 m_->caret = 0;102 m_->caret = 0;
@@ -103,6 +104,7 @@
103 // yes, use *signed* max as maximum length; just a small safe-guard.104 // yes, use *signed* max as maximum length; just a small safe-guard.
104 set_max_length(std::numeric_limits<int32_t>::max());105 set_max_length(std::numeric_limits<int32_t>::max());
105106
107 set_thinks(false);
106 set_handle_mouse(true);108 set_handle_mouse(true);
107 set_can_focus(true);109 set_can_focus(true);
108 set_handle_textinput();110 set_handle_textinput();
@@ -148,9 +150,9 @@
148 * If the current string is longer than the new maximum length,150 * If the current string is longer than the new maximum length,
149 * its end is cut off to fit into the maximum length.151 * its end is cut off to fit into the maximum length.
150 */152 */
151void EditBox::set_max_length(uint32_t const n) {153void EditBox::set_max_length(int const n) {
152 m_->maxLength =154 m_->maxLength =
153 std::min(g_gr->max_texture_size_for_font_rendering() / text_height(), static_cast<int>(n));155 std::min(g_gr->max_texture_size_for_font_rendering() / text_height(*m_->font_style), n);
154156
155 if (m_->text.size() > m_->maxLength) {157 if (m_->text.size() > m_->maxLength) {
156 m_->text.erase(m_->text.begin() + m_->maxLength, m_->text.end());158 m_->text.erase(m_->text.begin() + m_->maxLength, m_->text.end());
@@ -161,6 +163,22 @@
161 }163 }
162}164}
163165
166void EditBox::set_font_scale(float scale) {
167 m_->font_scale = scale;
168}
169
170void EditBox::set_font_style(const UI::FontStyleInfo& style) {
171 m_->font_style = &style;
172 const int new_height = text_height(style) + 2 * m_->margin;
173 set_size(get_w(), new_height);
174 set_desired_size(get_w(), new_height);
175}
176
177void EditBox::set_font_style_and_margin(const UI::FontStyleInfo& style, int margin) {
178 m_->margin = margin;
179 set_font_style(style);
180}
181
164/**182/**
165 * The mouse was clicked on this editbox183 * The mouse was clicked on this editbox
166 */184 */
@@ -389,12 +407,13 @@
389 }407 }
390408
391 const int max_width = get_w() - 2 * kMarginX;409 const int max_width = get_w() - 2 * kMarginX;
392410 FontStyleInfo scaled_style(*m_->font_style);
411 scaled_style.set_size(scaled_style.size() * m_->font_scale);
393 std::shared_ptr<const UI::RenderedText> rendered_text =412 std::shared_ptr<const UI::RenderedText> rendered_text =
394 UI::g_fh->render(as_editorfont(m_->text, m_->fontsize));413 UI::g_fh->render(as_editor_richtext_paragraph(password_ ? text_to_asterisk() : m_->text, scaled_style));
395414
396 const int linewidth = rendered_text->width();415 const int linewidth = rendered_text->width();
397 const int lineheight = m_->text.empty() ? text_height(m_->fontsize) : rendered_text->height();416 const int lineheight = m_->text.empty() ? text_height(scaled_style) : rendered_text->height();
398417
399 Vector2i point(kMarginX, get_h() / 2);418 Vector2i point(kMarginX, get_h() / 2);
400 if (m_->align == UI::Align::kRight) {419 if (m_->align == UI::Align::kRight) {
@@ -403,33 +422,27 @@
403 UI::center_vertically(lineheight, &point);422 UI::center_vertically(lineheight, &point);
404423
405 // Crop to max_width while blitting424 // Crop to max_width while blitting
406 if (!password_) {425 if (max_width < linewidth) {
407 if (max_width < linewidth) {426 // Fix positioning for BiDi languages.
408 // Fix positioning for BiDi languages.427 if (UI::g_fh->fontset()->is_rtl()) {
409 if (UI::g_fh->fontset()->is_rtl()) {428 point.x = 0.f;
410 point.x = 0.f;429 }
411 }430 // We want this always on, e.g. for mixed language savegame filenames
412 // We want this always on, e.g. for mixed language savegame filenames431 if (i18n::has_rtl_character(m_->text.c_str(), 100)) { // Restrict check for efficiency
413 if (i18n::has_rtl_character(m_->text.c_str(), 100)) { // Restrict check for efficiency432 // TODO(GunChleoc): Arabic: Fix scrolloffset
433 rendered_text->draw(dst, point, Recti(linewidth - max_width, 0, linewidth, lineheight));
434 } else {
435 if (m_->align == UI::Align::kRight) {
414 // TODO(GunChleoc): Arabic: Fix scrolloffset436 // TODO(GunChleoc): Arabic: Fix scrolloffset
415 rendered_text->draw(dst, point, Recti(linewidth - max_width, 0, linewidth, lineheight));437 rendered_text->draw(
438 dst, point,
439 Recti(point.x + m_->scrolloffset + kMarginX, 0, max_width, lineheight));
416 } else {440 } else {
417 if (m_->align == UI::Align::kRight) {441 rendered_text->draw(dst, point, Recti(-m_->scrolloffset, 0, max_width, lineheight));
418 // TODO(GunChleoc): Arabic: Fix scrolloffset
419 rendered_text->draw(
420 dst, point,
421 Recti(point.x + m_->scrolloffset + kMarginX, 0, max_width, lineheight));
422 } else {
423 rendered_text->draw(dst, point, Recti(-m_->scrolloffset, 0, max_width, lineheight));
424 }
425 }442 }
426 } else {
427 rendered_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
428 }443 }
429 } else {444 } else {
430 std::shared_ptr<const UI::RenderedText> password_text =445 rendered_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
431 UI::g_fh->render(as_editorfont(text_to_asterisk(), m_->fontsize));
432 password_text->draw(dst, point, Recti(0, 0, max_width, lineheight));
433 }446 }
434447
435 if (has_focus()) {448 if (has_focus()) {
@@ -443,9 +456,9 @@
443 }456 }
444457
445 // TODO(GunChleoc): Arabic: Fix cursor position for BIDI text.458 // TODO(GunChleoc): Arabic: Fix cursor position for BIDI text.
446 int caret_x = text_width(line_to_caret, m_->fontsize);459 int caret_x = text_width(line_to_caret, *m_->font_style, m_->font_scale);
447460
448 const uint16_t fontheight = text_height(m_->fontsize);461 const uint16_t fontheight = text_height(*m_->font_style, m_->font_scale);
449462
450 const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png");463 const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png");
451 Vector2i caretpt = Vector2i::zero();464 Vector2i caretpt = Vector2i::zero();
@@ -461,8 +474,8 @@
461void EditBox::check_caret() {474void EditBox::check_caret() {
462 std::string leftstr(m_->text, 0, m_->caret);475 std::string leftstr(m_->text, 0, m_->caret);
463 std::string rightstr(m_->text, m_->caret, std::string::npos);476 std::string rightstr(m_->text, m_->caret, std::string::npos);
464 int32_t leftw = text_width(leftstr, m_->fontsize);477 int32_t leftw = text_width(leftstr, *m_->font_style, m_->font_scale);
465 int32_t rightw = text_width(rightstr, m_->fontsize);478 int32_t rightw = text_width(rightstr, *m_->font_style, m_->font_scale);
466479
467 int32_t caretpos = 0;480 int32_t caretpos = 0;
468481
469482
=== modified file 'src/ui_basic/editbox.h'
--- src/ui_basic/editbox.h 2019-05-15 09:58:33 +0000
+++ src/ui_basic/editbox.h 2019-05-26 02:00:17 +0000
@@ -26,6 +26,7 @@
26#include <boost/signals2.hpp>26#include <boost/signals2.hpp>
2727
28#include "graphic/align.h"28#include "graphic/align.h"
29#include "graphic/style_manager.h"
29#include "ui_basic/button.h"30#include "ui_basic/button.h"
3031
31#define CHAT_HISTORY_SIZE 532#define CHAT_HISTORY_SIZE 5
@@ -48,10 +49,7 @@
48 int32_t x,49 int32_t x,
49 int32_t y,50 int32_t y,
50 uint32_t w,51 uint32_t w,
51 uint32_t h,52 UI::PanelStyle style);
52 int margin_y,
53 UI::PanelStyle style,
54 int font_size = UI_FONT_SIZE_SMALL);
55 ~EditBox() override;53 ~EditBox() override;
5654
57 boost::signals2::signal<void()> changed;55 boost::signals2::signal<void()> changed;
@@ -60,7 +58,10 @@
6058
61 const std::string& text() const;59 const std::string& text() const;
62 void set_text(const std::string&);60 void set_text(const std::string&);
63 void set_max_length(uint32_t);61 void set_max_length(int);
62 void set_font_scale(float scale);
63 void set_font_style(const UI::FontStyleInfo& style);
64 void set_font_style_and_margin(const UI::FontStyleInfo& style, int margin);
6465
65 void activate_history(bool activate) {66 void activate_history(bool activate) {
66 history_active_ = activate;67 history_active_ = activate;
6768
=== modified file 'src/ui_basic/fullscreen_window.cc'
--- src/ui_basic/fullscreen_window.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/fullscreen_window.cc 2019-05-26 02:00:17 +0000
@@ -22,9 +22,9 @@
22#include <cstdio>22#include <cstdio>
23#include <memory>23#include <memory>
2424
25#include "base/log.h"
25#include "graphic/rendertarget.h"26#include "graphic/rendertarget.h"
26#include "graphic/style_manager.h"27#include "graphic/style_manager.h"
27#include "graphic/text_constants.h"
2828
29/*29/*
30==============================================================================30==============================================================================
@@ -177,12 +177,8 @@
177 }177 }
178}178}
179179
180int FullscreenWindow::fs_small() {180float FullscreenWindow::scale_factor() const {
181 return UI_FONT_SIZE_SMALL * get_h() / 600;181 return std::max(1.0f, get_h() / 600.0f);
182}
183
184int FullscreenWindow::fs_big() {
185 return UI_FONT_SIZE_BIG * get_h() / 600;
186}182}
187183
188} // namespace UI184} // namespace UI
189185
=== modified file 'src/ui_basic/fullscreen_window.h'
--- src/ui_basic/fullscreen_window.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/fullscreen_window.h 2019-05-26 02:00:17 +0000
@@ -71,9 +71,8 @@
71 FullscreenWindow();71 FullscreenWindow();
72 ~FullscreenWindow() override;72 ~FullscreenWindow() override;
7373
74 /// \return the size for texts fitting to current resolution74 /// \return the font size scale factor for fitting texts to current resolution
75 int fs_small();75 float scale_factor() const;
76 int fs_big();
7776
78protected:77protected:
79 void draw(RenderTarget&) override;78 void draw(RenderTarget&) override;
8079
=== modified file 'src/ui_basic/listselect.cc'
--- src/ui_basic/listselect.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/listselect.cc 2019-05-26 02:00:17 +0000
@@ -30,7 +30,6 @@
30#include "graphic/rendertarget.h"30#include "graphic/rendertarget.h"
31#include "graphic/style_manager.h"31#include "graphic/style_manager.h"
32#include "graphic/text/bidi.h"32#include "graphic/text/bidi.h"
33#include "graphic/text_constants.h"
34#include "graphic/text_layout.h"33#include "graphic/text_layout.h"
35#include "ui_basic/mouse_constants.h"34#include "ui_basic/mouse_constants.h"
3635
@@ -54,16 +53,17 @@
54 UI::PanelStyle style,53 UI::PanelStyle style,
55 const ListselectLayout selection_mode)54 const ListselectLayout selection_mode)
56 : Panel(parent, x, y, w, h),55 : Panel(parent, x, y, w, h),
57 lineheight_(text_height() + kMargin),
58 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style),56 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style),
59 scrollpos_(0),57 scrollpos_(0),
60 selection_(no_selection_index()),58 selection_(no_selection_index()),
61 last_click_time_(-10000),59 last_click_time_(-10000),
62 last_selection_(no_selection_index()),60 last_selection_(no_selection_index()),
63 selection_mode_(selection_mode),61 selection_mode_(selection_mode),
62 font_style_(&g_gr->styles().table_style(style).enabled()),
64 background_style_(selection_mode == ListselectLayout::kDropdown ?63 background_style_(selection_mode == ListselectLayout::kDropdown ?
65 g_gr->styles().dropdown_style(style) :64 g_gr->styles().dropdown_style(style) :
66 nullptr) {65 nullptr),
66 lineheight_(text_height(*font_style_) + kMargin) {
67 set_thinks(false);67 set_thinks(false);
6868
69 scrollbar_.moved.connect(boost::bind(&BaseListselect::set_scrollpos, this, _1));69 scrollbar_.moved.connect(boost::bind(&BaseListselect::set_scrollpos, this, _1));
@@ -297,7 +297,7 @@
297 for (size_t i = 0; i < entry_records_.size(); ++i) {297 for (size_t i = 0; i < entry_records_.size(); ++i) {
298 const EntryRecord& er = *entry_records_[i];298 const EntryRecord& er = *entry_records_[i];
299 std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(299 std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(
300 as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));300 as_richtext_paragraph(richtext_escape(er.name), *font_style_));
301 int picw = max_pic_width_ ? max_pic_width_ + 10 : 0;301 int picw = max_pic_width_ ? max_pic_width_ + 10 : 0;
302 int difference = rendered_text->width() + picw + 8 - get_eff_w();302 int difference = rendered_text->width() + picw + 8 - get_eff_w();
303 if (difference > 0) {303 if (difference > 0) {
@@ -342,7 +342,7 @@
342342
343 const EntryRecord& er = *entry_records_[idx];343 const EntryRecord& er = *entry_records_[idx];
344 std::shared_ptr<const UI::RenderedText> rendered_text =344 std::shared_ptr<const UI::RenderedText> rendered_text =
345 UI::g_fh->render(as_uifont(richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));345 UI::g_fh->render(as_richtext_paragraph(richtext_escape(er.name), *font_style_));
346346
347 int lineheight = std::max(get_lineheight(), rendered_text->height());347 int lineheight = std::max(get_lineheight(), rendered_text->height());
348348
349349
=== modified file 'src/ui_basic/listselect.h'
--- src/ui_basic/listselect.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/listselect.h 2019-05-26 02:00:17 +0000
@@ -26,6 +26,7 @@
26#include <boost/signals2.hpp>26#include <boost/signals2.hpp>
2727
28#include "graphic/color.h"28#include "graphic/color.h"
29#include "graphic/styles/font_style.h"
29#include "ui_basic/panel.h"30#include "ui_basic/panel.h"
30#include "ui_basic/scrollbar.h"31#include "ui_basic/scrollbar.h"
3132
@@ -139,7 +140,6 @@
139 using EntryRecordDeque = std::deque<EntryRecord*>;140 using EntryRecordDeque = std::deque<EntryRecord*>;
140141
141 int max_pic_width_;142 int max_pic_width_;
142 int lineheight_;
143 EntryRecordDeque entry_records_;143 EntryRecordDeque entry_records_;
144 Scrollbar scrollbar_;144 Scrollbar scrollbar_;
145 uint32_t scrollpos_; // in pixels145 uint32_t scrollpos_; // in pixels
@@ -148,7 +148,9 @@
148 uint32_t last_selection_; // for double clicks148 uint32_t last_selection_; // for double clicks
149 ListselectLayout selection_mode_;149 ListselectLayout selection_mode_;
150 const Image* check_pic_;150 const Image* check_pic_;
151 const FontStyleInfo* font_style_;
151 const UI::PanelStyleInfo* background_style_; // Background color and texture. Not owned.152 const UI::PanelStyleInfo* background_style_; // Background color and texture. Not owned.
153 int lineheight_;
152 std::string current_tooltip_;154 std::string current_tooltip_;
153};155};
154156
155157
=== modified file 'src/ui_basic/messagebox.cc'
--- src/ui_basic/messagebox.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/messagebox.cc 2019-05-26 02:00:17 +0000
@@ -22,6 +22,7 @@
22#include "base/i18n.h"22#include "base/i18n.h"
23#include "graphic/font_handler.h"23#include "graphic/font_handler.h"
24#include "graphic/graphic.h"24#include "graphic/graphic.h"
25#include "graphic/text_layout.h"
25#include "ui_basic/window.h"26#include "ui_basic/window.h"
2627
27namespace UI {28namespace UI {
@@ -44,19 +45,21 @@
44 // Make sure that there is space for buttons + message, but not too tall45 // Make sure that there is space for buttons + message, but not too tall
45 const int maxheight = std::min(260, std::max(outerheight * 2 / 3, 200));46 const int maxheight = std::min(260, std::max(outerheight * 2 / 3, 200));
4647
48 const UI::FontStyle font_style = UI::FontStyle::kLabel;
49
47 const int margin = 5;50 const int margin = 5;
48 int width, height = 0;51 int width, height = 0;
49 {52 {
50 std::shared_ptr<const UI::RenderedText> temp_rendered_text =53 std::shared_ptr<const UI::RenderedText> temp_rendered_text =
51 g_fh->render(as_uifont(text), maxwidth);54 g_fh->render(as_richtext_paragraph(text, font_style), maxwidth);
52 width = temp_rendered_text->width();55 width = temp_rendered_text->width();
53 height = temp_rendered_text->height();56 height = temp_rendered_text->height();
54 }57 }
5558
56 // Stupid heuristic to avoid excessively long lines59 // Stupid heuristic to avoid excessively long lines
57 if (height < 2 * UI_FONT_SIZE_SMALL) {60 if (height < 2 * text_height(font_style)) {
58 std::shared_ptr<const UI::RenderedText> temp_rendered_text =61 std::shared_ptr<const UI::RenderedText> temp_rendered_text =
59 g_fh->render(as_uifont(text), maxwidth / 2);62 g_fh->render(as_richtext_paragraph(text, font_style), maxwidth / 2);
60 width = temp_rendered_text->width();63 width = temp_rendered_text->width();
61 height = temp_rendered_text->height();64 height = temp_rendered_text->height();
62 }65 }
6366
=== modified file 'src/ui_basic/multilineeditbox.cc'
--- src/ui_basic/multilineeditbox.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/multilineeditbox.cc 2019-05-26 02:00:17 +0000
@@ -41,8 +41,8 @@
41 /// The text in the edit box41 /// The text in the edit box
42 std::string text;42 std::string text;
4343
44 /// Background color and texture44 /// Background color and texture + font style
45 const UI::PanelStyleInfo* background_style;45 const UI::TextPanelStyleInfo& style;
4646
47 /// Position of the cursor inside the text.47 /// Position of the cursor inside the text.
48 /// 0 indicates that the cursor is before the first character,48 /// 0 indicates that the cursor is before the first character,
@@ -60,7 +60,7 @@
60 WordWrap ww;60 WordWrap ww;
61 /*@}*/61 /*@}*/
6262
63 Data(MultilineEditbox&, const UI::PanelStyleInfo* style);63 Data(MultilineEditbox&, const TextPanelStyleInfo& style);
64 void refresh_ww();64 void refresh_ww();
6565
66 void update();66 void update();
@@ -81,7 +81,7 @@
8181
82/**82/**
83 * Initialize an editbox that supports multiline strings.83 * Initialize an editbox that supports multiline strings.
84 */84*/
85MultilineEditbox::MultilineEditbox(85MultilineEditbox::MultilineEditbox(
86 Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, UI::PanelStyle style)86 Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, UI::PanelStyle style)
87 : Panel(parent, x, y, w, h), d_(new Data(*this, g_gr->styles().editbox_style(style))) {87 : Panel(parent, x, y, w, h), d_(new Data(*this, g_gr->styles().editbox_style(style))) {
@@ -91,17 +91,18 @@
91 set_handle_textinput();91 set_handle_textinput();
92}92}
9393
94MultilineEditbox::Data::Data(MultilineEditbox& o, const UI::PanelStyleInfo* style)94MultilineEditbox::Data::Data(MultilineEditbox& o, const UI::TextPanelStyleInfo& init_style)
95 : scrollbar(95 : scrollbar(
96 &o, o.get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, o.get_h(), UI::PanelStyle::kWui),96 &o, o.get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, o.get_h(), UI::PanelStyle::kWui),
97 background_style(style),97 style(init_style),
98 cursor_pos(0),98 cursor_pos(0),
99 lineheight(text_height()),99 lineheight(text_height(style.font())),
100 maxbytes(std::min(g_gr->max_texture_size_for_font_rendering() *100 maxbytes(std::min(g_gr->max_texture_size_for_font_rendering() *
101 g_gr->max_texture_size_for_font_rendering() /101 g_gr->max_texture_size_for_font_rendering() /
102 (text_height() * text_height()),102 (text_height(style.font()) * text_height(style.font())),
103 std::numeric_limits<int32_t>::max())),103 std::numeric_limits<int32_t>::max())),
104 ww_valid(false),104 ww_valid(false),
105 ww(style.font().size(), style.font().color(), o.get_w()),
105 owner(o) {106 owner(o) {
106 scrollbar.moved.connect(boost::bind(&MultilineEditbox::scrollpos_changed, &o, _1));107 scrollbar.moved.connect(boost::bind(&MultilineEditbox::scrollpos_changed, &o, _1));
107108
@@ -413,7 +414,7 @@
413 * Redraw the Editbox414 * Redraw the Editbox
414 */415 */
415void MultilineEditbox::draw(RenderTarget& dst) {416void MultilineEditbox::draw(RenderTarget& dst) {
416 draw_background(dst, *d_->background_style);417 draw_background(dst, d_->style.background());
417418
418 // Draw border.419 // Draw border.
419 if (get_w() >= 4 && get_h() >= 4) {420 if (get_w() >= 4 && get_h() >= 4) {
@@ -437,7 +438,6 @@
437 d_->refresh_ww();438 d_->refresh_ww();
438439
439 d_->ww.set_draw_caret(has_focus());440 d_->ww.set_draw_caret(has_focus());
440
441 d_->ww.draw(dst, Vector2i(0, -int32_t(d_->scrollbar.get_scrollpos())), UI::Align::kLeft,441 d_->ww.draw(dst, Vector2i(0, -int32_t(d_->scrollbar.get_scrollpos())), UI::Align::kLeft,
442 has_focus() ? d_->cursor_pos : std::numeric_limits<uint32_t>::max());442 has_focus() ? d_->cursor_pos : std::numeric_limits<uint32_t>::max());
443}443}
444444
=== modified file 'src/ui_basic/multilinetextarea.cc'
--- src/ui_basic/multilinetextarea.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/multilinetextarea.cc 2019-05-26 02:00:17 +0000
@@ -23,9 +23,10 @@
23#include <boost/bind.hpp>23#include <boost/bind.hpp>
2424
25#include "graphic/font_handler.h"25#include "graphic/font_handler.h"
26#include "graphic/graphic.h"
26#include "graphic/rendertarget.h"27#include "graphic/rendertarget.h"
28#include "graphic/text/bidi.h"
27#include "graphic/text/font_set.h"29#include "graphic/text/font_set.h"
28#include "graphic/text_constants.h"
29#include "graphic/text_layout.h"30#include "graphic/text_layout.h"
3031
31namespace UI {32namespace UI {
@@ -44,19 +45,30 @@
44 MultilineTextarea::ScrollMode scroll_mode)45 MultilineTextarea::ScrollMode scroll_mode)
45 : Panel(parent, x, y, w, h),46 : Panel(parent, x, y, w, h),
46 text_(text),47 text_(text),
47 color_(UI_FONT_CLR_FG),48 style_(&g_gr->styles().font_style(FontStyle::kLabel)),
49 font_scale_(1.0f),
48 align_(align),50 align_(align),
49 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style, false) {51 scrollbar_(this, get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, h, style, false) {
50 set_thinks(false);52 set_thinks(false);
5153
52 scrollbar_.moved.connect(boost::bind(&MultilineTextarea::scrollpos_changed, this, _1));54 scrollbar_.moved.connect(boost::bind(&MultilineTextarea::scrollpos_changed, this, _1));
5355
54 scrollbar_.set_singlestepsize(text_height());56 scrollbar_.set_singlestepsize(text_height(*style_, font_scale_));
55 scrollbar_.set_steps(1);57 scrollbar_.set_steps(1);
56 set_scrollmode(scroll_mode);58 set_scrollmode(scroll_mode);
57 assert(scrollmode_ == MultilineTextarea::ScrollMode::kNoScrolling || Scrollbar::kSize <= w);59 assert(scrollmode_ == MultilineTextarea::ScrollMode::kNoScrolling || Scrollbar::kSize <= w);
58}60}
5961
62void MultilineTextarea::set_style(const UI::FontStyleInfo& style) {
63 style_ = &style;
64 recompute();
65}
66void MultilineTextarea::set_font_scale(float scale) {
67 font_scale_ = scale;
68 scrollbar_.set_singlestepsize(text_height(*style_, font_scale_));
69 recompute();
70}
71
60/**72/**
61 * Replace the current text with a new one.73 * Replace the current text with a new one.
62 * Fix up scrolling state if necessary.74 * Fix up scrolling state if necessary.
@@ -66,11 +78,6 @@
66 recompute();78 recompute();
67}79}
6880
69void MultilineTextarea::set_color(RGBColor fg) {
70 color_ = fg;
71 recompute();
72}
73
74/**81/**
75 * Recompute the text rendering or rich-text layouting,82 * Recompute the text rendering or rich-text layouting,
76 * and adjust scrollbar settings accordingly.83 * and adjust scrollbar settings accordingly.
@@ -129,7 +136,7 @@
129 // Take care of the scrollbar136 // Take care of the scrollbar
130 scrollbar_.set_pos(Vector2i(get_w() - Scrollbar::kSize, 0));137 scrollbar_.set_pos(Vector2i(get_w() - Scrollbar::kSize, 0));
131 scrollbar_.set_size(Scrollbar::kSize, get_h());138 scrollbar_.set_size(Scrollbar::kSize, get_h());
132 scrollbar_.set_pagesize(get_h() - 2 * UI_FONT_SIZE_BIG);139 scrollbar_.set_pagesize(get_h() - 2 * style_->size() * font_scale_);
133}140}
134141
135/**142/**
@@ -140,7 +147,7 @@
140 return;147 return;
141 }148 }
142 int anchor = 0;149 int anchor = 0;
143 Align alignment = mirror_alignment(align_, text_);150 Align alignment = mirror_alignment(align_, i18n::has_rtl_character(text_.c_str(), 20));
144 switch (alignment) {151 switch (alignment) {
145 // TODO(Arty): We might want to revisit this after the font renderer can handle long strings152 // TODO(Arty): We might want to revisit this after the font renderer can handle long strings
146 // without whitespaces differently.153 // without whitespaces differently.
@@ -192,7 +199,10 @@
192 // TODO(GunChleoc): Revisit this once the old font renderer is completely gone.199 // TODO(GunChleoc): Revisit this once the old font renderer is completely gone.
193 boost::replace_all(temp, "\n\n", "<br>&nbsp;<br>");200 boost::replace_all(temp, "\n\n", "<br>&nbsp;<br>");
194 boost::replace_all(temp, "\n", "<br>");201 boost::replace_all(temp, "\n", "<br>");
195 return as_aligned(temp, align_, UI_FONT_SIZE_SMALL, color_);202
203 FontStyleInfo scaled_style(*style_);
204 scaled_style.set_size(std::max(g_gr->styles().minimum_font_size(), static_cast<int>(std::ceil(scaled_style.size() * font_scale_))));
205 return as_richtext_paragraph(temp, scaled_style, align_);
196}206}
197207
198} // namespace UI208} // namespace UI
199209
=== modified file 'src/ui_basic/multilinetextarea.h'
--- src/ui_basic/multilinetextarea.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/multilinetextarea.h 2019-05-26 02:00:17 +0000
@@ -23,13 +23,12 @@
23#include <memory>23#include <memory>
2424
25#include "graphic/align.h"25#include "graphic/align.h"
26#include "graphic/color.h"26#include "graphic/styles/panel_styles.h"
27#include "graphic/text_layout.h"27#include "graphic/text_layout.h"
28#include "ui_basic/panel.h"28#include "ui_basic/panel.h"
29#include "ui_basic/scrollbar.h"29#include "ui_basic/scrollbar.h"
3030
31namespace UI {31namespace UI {
32struct Scrollbar;
3332
34/**33/**
35 * This defines an area, where a text can easily be printed.34 * This defines an area, where a text can easily be printed.
@@ -65,7 +64,8 @@
65 return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();64 return scrollbar_.is_enabled() ? get_w() - Scrollbar::kSize : get_w();
66 }65 }
6766
68 void set_color(RGBColor fg);67 void set_style(const FontStyleInfo& style);
68 void set_font_scale(float scale);
6969
70 // Drawing and event handlers70 // Drawing and event handlers
71 void draw(RenderTarget&) override;71 void draw(RenderTarget&) override;
@@ -88,10 +88,13 @@
88 * turns '\\n' into '<br>' tags as needed, then creates the richtext style wrappers.88 * turns '\\n' into '<br>' tags as needed, then creates the richtext style wrappers.
89 */89 */
90 std::string make_richtext();90 std::string make_richtext();
91
92 std::string text_;91 std::string text_;
93 std::shared_ptr<const UI::RenderedText> rendered_text_;92
94 RGBColor color_;93 std::shared_ptr<const UI::RenderedText> rendered_text_;
94
95 const FontStyleInfo* style_;
96 float font_scale_;
97
95 const Align align_;98 const Align align_;
9699
97 Scrollbar scrollbar_;100 Scrollbar scrollbar_;
98101
=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc 2019-04-24 06:01:37 +0000
+++ src/ui_basic/panel.cc 2019-05-26 02:00:17 +0000
@@ -24,7 +24,6 @@
24#include "graphic/graphic.h"24#include "graphic/graphic.h"
25#include "graphic/rendertarget.h"25#include "graphic/rendertarget.h"
26#include "graphic/text/font_set.h"26#include "graphic/text/font_set.h"
27#include "graphic/text_constants.h"
28#include "graphic/text_layout.h"27#include "graphic/text_layout.h"
29#include "profile/profile.h"28#include "profile/profile.h"
30#include "sound/sound_handler.h"29#include "sound/sound_handler.h"
@@ -458,12 +457,12 @@
458 draw_background(dst, Recti(0, 0, get_w(), get_h()), info);457 draw_background(dst, Recti(0, 0, get_w(), get_h()), info);
459}458}
460void Panel::draw_background(RenderTarget& dst, Recti rect, const UI::PanelStyleInfo& info) {459void Panel::draw_background(RenderTarget& dst, Recti rect, const UI::PanelStyleInfo& info) {
461 if (info.image != nullptr) {460 if (info.image() != nullptr) {
462 dst.fill_rect(rect, RGBAColor(0, 0, 0, 255));461 dst.fill_rect(rect, RGBAColor(0, 0, 0, 255));
463 dst.tile(rect, info.image, Vector2i(get_x(), get_y()));462 dst.tile(rect, info.image(), Vector2i(get_x(), get_y()));
464 }463 }
465 if (info.color != RGBAColor(0, 0, 0, 0)) {464 if (info.color() != RGBAColor(0, 0, 0, 0)) {
466 dst.fill_rect(rect, info.color, BlendMode::UseAlpha);465 dst.fill_rect(rect, info.color(), BlendMode::UseAlpha);
467 }466 }
468}467}
469468
@@ -1082,7 +1081,7 @@
1082 RenderTarget& dst = *g_gr->get_render_target();1081 RenderTarget& dst = *g_gr->get_render_target();
1083 std::string text_to_render = text;1082 std::string text_to_render = text;
1084 if (!is_richtext(text_to_render)) {1083 if (!is_richtext(text_to_render)) {
1085 text_to_render = as_tooltip(text_to_render);1084 text_to_render = as_richtext_paragraph(text_to_render, UI::FontStyle::kTooltip);
1086 }1085 }
10871086
1088 constexpr uint32_t kTipWidthMax = 360;1087 constexpr uint32_t kTipWidthMax = 360;
10891088
=== modified file 'src/ui_basic/panel.h'
--- src/ui_basic/panel.h 2019-05-05 11:20:18 +0000
+++ src/ui_basic/panel.h 2019-05-26 02:00:17 +0000
@@ -33,7 +33,7 @@
33#include "base/vector.h"33#include "base/vector.h"
34#include "graphic/align.h"34#include "graphic/align.h"
35#include "graphic/font_handler.h"35#include "graphic/font_handler.h"
36#include "graphic/panel_styles.h"36#include "graphic/styles/panel_styles.h"
37#include "sound/constants.h"37#include "sound/constants.h"
3838
39class RenderTarget;39class RenderTarget;
4040
=== modified file 'src/ui_basic/progressbar.cc'
--- src/ui_basic/progressbar.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/progressbar.cc 2019-05-26 02:00:17 +0000
@@ -24,6 +24,7 @@
24#include <boost/format.hpp>24#include <boost/format.hpp>
2525
26#include "graphic/font_handler.h"26#include "graphic/font_handler.h"
27#include "graphic/graphic.h"
27#include "graphic/rendertarget.h"28#include "graphic/rendertarget.h"
28#include "graphic/text_layout.h"29#include "graphic/text_layout.h"
2930
@@ -37,7 +38,7 @@
37 int32_t const w,38 int32_t const w,
38 int32_t const h,39 int32_t const h,
39 uint32_t const orientation)40 uint32_t const orientation)
40 : Panel(parent, x, y, w, h), orientation_(orientation), state_(0), total_(100) {41 : Panel(parent, x, y, w, h), orientation_(orientation), state_(0), total_(100), style_(g_gr->styles().progressbar_style(UI::PanelStyle::kWui)) {
41}42}
4243
43/**44/**
@@ -66,9 +67,9 @@
66 assert(0 <= fraction);67 assert(0 <= fraction);
67 assert(fraction <= 1);68 assert(fraction <= 1);
6869
69 const RGBColor color = fraction <= 0.33f ?70 const RGBColor& color = fraction <= 0.33f ? style_.low_color() : fraction <= 0.67f ?
70 RGBColor(255, 0, 0) :71 style_.medium_color() :
71 fraction <= 0.67f ? RGBColor(255, 255, 0) : RGBColor(0, 255, 0);72 style_.high_color();
7273
73 // Draw the actual bar74 // Draw the actual bar
74 if (orientation_ == Horizontal) {75 if (orientation_ == Horizontal) {
@@ -85,11 +86,8 @@
85 }86 }
8687
87 // Print the state in percent without decimal points.88 // Print the state in percent without decimal points.
88 const std::string progress_text = (boost::format("<font color=%s>%u%%</font>") %
89 UI_FONT_CLR_BRIGHT.hex_value() % floorf(fraction * 100.f))
90 .str();
91 std::shared_ptr<const UI::RenderedText> rendered_text =89 std::shared_ptr<const UI::RenderedText> rendered_text =
92 UI::g_fh->render(as_uifont(progress_text));90 UI::g_fh->render(as_richtext_paragraph((boost::format("%u%%") % floorf(fraction * 100.f)).str(), style_.font()));
93 Vector2i pos(get_w() / 2, get_h() / 2);91 Vector2i pos(get_w() / 2, get_h() / 2);
94 UI::center_vertically(rendered_text->height(), &pos);92 UI::center_vertically(rendered_text->height(), &pos);
95 rendered_text->draw(dst, pos, UI::Align::kCenter);93 rendered_text->draw(dst, pos, UI::Align::kCenter);
9694
=== modified file 'src/ui_basic/progressbar.h'
--- src/ui_basic/progressbar.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/progressbar.h 2019-05-26 02:00:17 +0000
@@ -20,6 +20,7 @@
20#ifndef WL_UI_BASIC_PROGRESSBAR_H20#ifndef WL_UI_BASIC_PROGRESSBAR_H
21#define WL_UI_BASIC_PROGRESSBAR_H21#define WL_UI_BASIC_PROGRESSBAR_H
2222
23#include "graphic/style_manager.h"
23#include "ui_basic/panel.h"24#include "ui_basic/panel.h"
2425
25namespace UI {26namespace UI {
@@ -58,6 +59,7 @@
58 uint32_t orientation_;59 uint32_t orientation_;
59 uint32_t state_; ///< state_ is [0..total_]60 uint32_t state_; ///< state_ is [0..total_]
60 uint32_t total_; ///< maximum progress61 uint32_t total_; ///< maximum progress
62 const UI::ProgressbarStyleInfo& style_;
61};63};
62} // namespace UI64} // namespace UI
6365
6466
=== modified file 'src/ui_basic/progresswindow.cc'
--- src/ui_basic/progresswindow.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/progresswindow.cc 2019-05-26 02:00:17 +0000
@@ -28,14 +28,10 @@
28#include "graphic/graphic.h"28#include "graphic/graphic.h"
29#include "graphic/rendertarget.h"29#include "graphic/rendertarget.h"
30#include "graphic/text/font_set.h"30#include "graphic/text/font_set.h"
31#include "graphic/text_constants.h"
32#include "graphic/text_layout.h"31#include "graphic/text_layout.h"
33#include "io/filesystem/layered_filesystem.h"32#include "io/filesystem/layered_filesystem.h"
3433
35namespace {34namespace {
36
37#define PROGRESS_FONT_COLOR_FG RGBColor(128, 128, 255)
38#define PROGRESS_FONT_COLOR_BG RGBColor(64, 64, 0)
39#define PROGRESS_STATUS_RECT_PADDING 235#define PROGRESS_STATUS_RECT_PADDING 2
40#define PROGRESS_STATUS_BORDER_X 236#define PROGRESS_STATUS_BORDER_X 2
41#define PROGRESS_STATUS_BORDER_Y 237#define PROGRESS_STATUS_BORDER_Y 2
@@ -46,7 +42,7 @@
46namespace UI {42namespace UI {
4743
48ProgressWindow::ProgressWindow(const std::string& background)44ProgressWindow::ProgressWindow(const std::string& background)
49 : UI::FullscreenWindow(), label_center_(Vector2i::zero()) {45 : UI::FullscreenWindow(), label_center_(Vector2i::zero()), style_(g_gr->styles().progressbar_style(UI::PanelStyle::kFsMenu)) {
50 set_background(background);46 set_background(background);
51 step(_("Loading…"));47 step(_("Loading…"));
52}48}
@@ -63,7 +59,7 @@
63 label_center_.x = get_w() / 2;59 label_center_.x = get_w() / 2;
64 label_center_.y = get_h() * PROGRESS_LABEL_POSITION_Y / 100;60 label_center_.y = get_h() * PROGRESS_LABEL_POSITION_Y / 100;
6561
66 const uint32_t h = text_height();62 const uint32_t h = text_height(style_.font());
6763
68 label_rectangle_.x = get_w() / 4;64 label_rectangle_.x = get_w() / 4;
69 label_rectangle_.w = get_w() / 2;65 label_rectangle_.w = get_w() / 2;
@@ -76,7 +72,9 @@
76 border_rect.w += 2 * PROGRESS_STATUS_BORDER_X;72 border_rect.w += 2 * PROGRESS_STATUS_BORDER_X;
77 border_rect.h += 2 * PROGRESS_STATUS_BORDER_Y;73 border_rect.h += 2 * PROGRESS_STATUS_BORDER_Y;
7874
79 rt.draw_rect(border_rect, PROGRESS_FONT_COLOR_FG);75 rt.draw_rect(border_rect, style_.font().color());
76 // TODO(GunChleoc): this should depend on actual progress. Add a total steps variable and reuse the Progressbar class.
77 rt.fill_rect(label_rectangle_, style_.medium_color());
80}78}
8179
82/// Set a picture to render in the background80/// Set a picture to render in the background
@@ -97,9 +95,8 @@
97 // always repaint the background first95 // always repaint the background first
98 draw(rt);96 draw(rt);
9997
100 rt.fill_rect(label_rectangle_, PROGRESS_FONT_COLOR_BG);
101 std::shared_ptr<const UI::RenderedText> rendered_text =98 std::shared_ptr<const UI::RenderedText> rendered_text =
102 UI::g_fh->render(as_uifont(description, UI_FONT_SIZE_SMALL, PROGRESS_FONT_COLOR_FG));99 UI::g_fh->render(as_richtext_paragraph(description, style_.font()));
103 UI::center_vertically(rendered_text->height(), &label_center_);100 UI::center_vertically(rendered_text->height(), &label_center_);
104 rendered_text->draw(rt, label_center_, UI::Align::kCenter);101 rendered_text->draw(rt, label_center_, UI::Align::kCenter);
105102
106103
=== modified file 'src/ui_basic/progresswindow.h'
--- src/ui_basic/progresswindow.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/progresswindow.h 2019-05-26 02:00:17 +0000
@@ -67,6 +67,7 @@
67 Recti label_rectangle_;67 Recti label_rectangle_;
68 VisualizationArray visualizations_;68 VisualizationArray visualizations_;
69 std::string background_;69 std::string background_;
70 const UI::ProgressbarStyleInfo& style_;
7071
71 void draw(RenderTarget&) override;72 void draw(RenderTarget&) override;
72 void update(bool repaint);73 void update(bool repaint);
7374
=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc 2019-03-16 07:46:10 +0000
+++ src/ui_basic/slider.cc 2019-05-26 02:00:17 +0000
@@ -72,7 +72,7 @@
72 highlighted_(false),72 highlighted_(false),
73 pressed_(false),73 pressed_(false),
74 enabled_(enabled),74 enabled_(enabled),
75 cursor_style_(g_gr->styles().slider_style(style)),75 cursor_style_(&g_gr->styles().slider_style(style).background()),
76 x_gap_(x_gap),76 x_gap_(x_gap),
77 y_gap_(y_gap),77 y_gap_(y_gap),
78 bar_size_(bar_size),78 bar_size_(bar_size),
@@ -487,22 +487,23 @@
487 const uint32_t w,487 const uint32_t w,
488 const uint32_t h,488 const uint32_t h,
489 const std::vector<std::string>& labels_in,489 const std::vector<std::string>& labels_in,
490 uint32_t value_,490 uint32_t init_value,
491 SliderStyle style,491 SliderStyle init_style,
492 const std::string& tooltip_text,492 const std::string& tooltip_text,
493 const uint32_t cursor_size,493 const uint32_t cursor_size,
494 const bool enabled)494 const bool enabled)
495 : Panel(parent, x, y, w, h, tooltip_text),495 : Panel(parent, x, y, w, h, tooltip_text),
496 style(g_gr->styles().slider_style(init_style)),
496 slider(this,497 slider(this,
497 // here, we take into account the h_gap introduced by HorizontalSlider498 // here, we take into account the h_gap introduced by HorizontalSlider
498 w / (2 * labels_in.size()) - cursor_size / 2,499 w / (2 * labels_in.size()) - cursor_size / 2,
499 0,500 0,
500 w - (w / labels_in.size()) + cursor_size,501 w - (w / labels_in.size()) + cursor_size,
501 h - text_height(UI_FONT_SIZE_SMALL - 2, UI::FontSet::Face::kCondensed) - 2,502 h - text_height(style.font()) - 2,
502 0,503 0,
503 labels_in.size() - 1,504 labels_in.size() - 1,
504 value_,505 init_value,
505 style,506 init_style,
506 tooltip_text,507 tooltip_text,
507 cursor_size,508 cursor_size,
508 enabled),509 enabled),
@@ -524,7 +525,7 @@
524525
525 for (uint32_t i = 0; i < labels.size(); i++) {526 for (uint32_t i = 0; i < labels.size(); i++) {
526 std::shared_ptr<const UI::RenderedText> rendered_text =527 std::shared_ptr<const UI::RenderedText> rendered_text =
527 UI::g_fh->render(as_condensed(labels[i], UI::Align::kCenter, UI_FONT_SIZE_SMALL - 2));528 UI::g_fh->render(as_richtext_paragraph(labels[i], style.font()));
528 rendered_text->draw(529 rendered_text->draw(
529 dst, Vector2i(gap_1 + i * gap_n, get_h() - rendered_text->height()), UI::Align::kCenter);530 dst, Vector2i(gap_1 + i * gap_n, get_h() - rendered_text->height()), UI::Align::kCenter);
530 }531 }
@@ -542,7 +543,7 @@
542 assert(labels.size());543 assert(labels.size());
543 slider.set_pos(Vector2i(w / (2 * labels.size()) - slider.cursor_size_ / 2, 0));544 slider.set_pos(Vector2i(w / (2 * labels.size()) - slider.cursor_size_ / 2, 0));
544 slider.set_size(w - (w / labels.size()) + slider.cursor_size_,545 slider.set_size(w - (w / labels.size()) + slider.cursor_size_,
545 h - text_height(UI_FONT_SIZE_SMALL - 2, UI::FontSet::Face::kCondensed) + 2);546 h - text_height(style.font()) + 2);
546 Panel::layout();547 Panel::layout();
547}548}
548} // namespace UI549} // namespace UI
549550
=== modified file 'src/ui_basic/slider.h'
--- src/ui_basic/slider.h 2019-03-16 07:28:07 +0000
+++ src/ui_basic/slider.h 2019-05-26 02:00:17 +0000
@@ -21,6 +21,7 @@
2121
22#include <boost/signals2.hpp>22#include <boost/signals2.hpp>
2323
24#include "graphic/styles/text_panel_style.h"
24#include "ui_basic/panel.h"25#include "ui_basic/panel.h"
2526
26namespace UI {27namespace UI {
@@ -236,6 +237,11 @@
236 void draw(RenderTarget& dst) override;237 void draw(RenderTarget& dst) override;
237 void layout() override;238 void layout() override;
238239
240private:
241 // We need the style to initialize the slider, so it has to come first.
242 const UI::TextPanelStyleInfo& style;
243
244protected:
239 HorizontalSlider slider;245 HorizontalSlider slider;
240246
241private:247private:
242248
=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc 2019-02-23 11:00:49 +0000
+++ src/ui_basic/spinbox.cc 2019-05-26 02:00:17 +0000
@@ -31,7 +31,6 @@
31#include "graphic/font_handler.h"31#include "graphic/font_handler.h"
32#include "graphic/graphic.h"32#include "graphic/graphic.h"
33#include "graphic/text/font_set.h"33#include "graphic/text/font_set.h"
34#include "graphic/text_constants.h"
35#include "ui_basic/button.h"34#include "ui_basic/button.h"
36#include "ui_basic/multilinetextarea.h"35#include "ui_basic/multilinetextarea.h"
37#include "ui_basic/textarea.h"36#include "ui_basic/textarea.h"
3837
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2019-04-18 16:50:35 +0000
+++ src/ui_basic/table.cc 2019-05-26 02:00:17 +0000
@@ -22,14 +22,13 @@
22#include <boost/bind.hpp>22#include <boost/bind.hpp>
2323
24#include "graphic/font_handler.h"24#include "graphic/font_handler.h"
25#include "graphic/graphic.h"
25#include "graphic/rendertarget.h"26#include "graphic/rendertarget.h"
26#include "graphic/text/bidi.h"27#include "graphic/text/bidi.h"
27#include "graphic/text/font_set.h"28#include "graphic/text/font_set.h"
28#include "graphic/text_constants.h"
29#include "graphic/text_layout.h"29#include "graphic/text_layout.h"
30#include "graphic/texture.h"30#include "graphic/texture.h"
31#include "ui_basic/mouse_constants.h"31#include "ui_basic/mouse_constants.h"
32#include "ui_basic/scrollbar.h"
3332
34namespace UI {33namespace UI {
3534
@@ -49,8 +48,9 @@
49 TableRows rowtype)48 TableRows rowtype)
50 : Panel(parent, x, y, w, h),49 : Panel(parent, x, y, w, h),
51 total_width_(0),50 total_width_(0),
52 headerheight_(text_height() + 4),51 lineheight_(text_height(g_gr->styles().table_style(style).enabled())),
53 lineheight_(text_height()),52 headerheight_(lineheight_ + 4),
53 style_(style),
54 button_style_(style == UI::PanelStyle::kFsMenu ? UI::ButtonStyle::kFsMenuMenu :54 button_style_(style == UI::PanelStyle::kFsMenu ? UI::ButtonStyle::kFsMenuMenu :
55 UI::ButtonStyle::kWuiSecondary),55 UI::ButtonStyle::kWuiSecondary),
56 scrollbar_(nullptr),56 scrollbar_(nullptr),
@@ -239,7 +239,7 @@
239 for (uint32_t i = 0, curx = 0; i < nr_columns; ++i) {239 for (uint32_t i = 0, curx = 0; i < nr_columns; ++i) {
240 const Column& column = columns_[i];240 const Column& column = columns_[i];
241 const int curw = column.width;241 const int curw = column.width;
242 Align alignment = mirror_alignment(column.alignment);242 Align alignment = mirror_alignment(column.alignment, g_fh->fontset()->is_rtl());
243243
244 const Image* entry_picture = er.get_picture(i);244 const Image* entry_picture = er.get_picture(i);
245 const std::string& entry_string = er.get_string(i);245 const std::string& entry_string = er.get_string(i);
@@ -300,12 +300,19 @@
300 curx += curw;300 curx += curw;
301 continue;301 continue;
302 }302 }
303 std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh->render(303
304 as_uifont(richtext_escape(entry_string), UI_FONT_SIZE_SMALL, er.get_color()));304 const UI::FontStyleInfo& font_style =
305 er.font_style() != nullptr ?
306 *er.font_style() :
307 er.is_disabled() ?
308 g_gr->styles().table_style(style_).disabled() :
309 g_gr->styles().table_style(style_).enabled();
310 std::shared_ptr<const UI::RenderedText> rendered_text =
311 UI::g_fh->render(as_richtext_paragraph(richtext_escape(entry_string), font_style));
305312
306 // Fix text alignment for BiDi languages if the entry contains an RTL character. We want313 // Fix text alignment for BiDi languages if the entry contains an RTL character. We want
307 // this always on, e.g. for mixed language savegame filenames.314 // this always on, e.g. for mixed language savegame filenames.
308 alignment = mirror_alignment(column.alignment, entry_string);315 alignment = mirror_alignment(column.alignment, i18n::has_rtl_character(entry_string.c_str(), 20));
309316
310 // Position the text according to alignment317 // Position the text according to alignment
311 switch (alignment) {318 switch (alignment) {
@@ -718,7 +725,7 @@
718 return ea.get_string(column) < eb.get_string(column);725 return ea.get_string(column) < eb.get_string(column);
719}726}
720727
721Table<void*>::EntryRecord::EntryRecord(void* const e) : entry_(e), clr(UI_FONT_CLR_FG) {728Table<void*>::EntryRecord::EntryRecord(void* const e) : entry_(e), font_style_(nullptr), disabled_(false) {
722}729}
723730
724void Table<void*>::EntryRecord::set_picture(uint8_t const col,731void Table<void*>::EntryRecord::set_picture(uint8_t const col,
725732
=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h 2019-04-18 16:50:35 +0000
+++ src/ui_basic/table.h 2019-05-26 02:00:17 +0000
@@ -29,12 +29,12 @@
2929
30#include "graphic/align.h"30#include "graphic/align.h"
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to status/vote changes: