Merge lp:~nha/widelands/fonthandler into lp:widelands

Proposed by Nicolai Hähnle
Status: Merged
Merged at revision: 5815
Proposed branch: lp:~nha/widelands/fonthandler
Merge into: lp:widelands
Diff against target: 6429 lines (+2315/-1476)
65 files modified
src/constants.h (+2/-2)
src/graphic/font.cc (+240/-0)
src/graphic/font.h (+109/-0)
src/graphic/font_handler.cc (+240/-157)
src/graphic/font_handler.h (+43/-27)
src/graphic/font_loader.cc (+0/-121)
src/graphic/font_loader.h (+0/-52)
src/graphic/render/render_sdl.cc (+2/-2)
src/graphic/wordwrap.cc (+293/-0)
src/graphic/wordwrap.h (+80/-0)
src/logic/building.cc (+5/-8)
src/rect.h (+2/-2)
src/ui_basic/button.cc (+41/-49)
src/ui_basic/button.h (+10/-24)
src/ui_basic/editbox.cc (+4/-7)
src/ui_basic/helpwindow.cc (+4/-3)
src/ui_basic/listselect.cc (+3/-5)
src/ui_basic/multilineeditbox.cc (+445/-247)
src/ui_basic/multilineeditbox.h (+22/-19)
src/ui_basic/multilinetextarea.h (+0/-4)
src/ui_basic/panel.cc (+26/-25)
src/ui_basic/panel.h (+1/-1)
src/ui_basic/progressbar.cc (+3/-3)
src/ui_basic/progresswindow.cc (+5/-3)
src/ui_basic/spinbox.cc (+20/-21)
src/ui_basic/spinbox.h (+2/-0)
src/ui_basic/table.cc (+9/-7)
src/ui_basic/textarea.cc (+67/-91)
src/ui_basic/textarea.h (+12/-10)
src/ui_basic/window.cc (+4/-4)
src/ui_fsmenu/base.cc (+40/-9)
src/ui_fsmenu/base.h (+25/-12)
src/ui_fsmenu/campaign_select.cc (+36/-36)
src/ui_fsmenu/campaign_select.h (+0/-2)
src/ui_fsmenu/editor.cc (+13/-13)
src/ui_fsmenu/editor_mapselect.cc (+24/-23)
src/ui_fsmenu/fileview.cc (+8/-7)
src/ui_fsmenu/intro.cc (+1/-1)
src/ui_fsmenu/launchMPG.cc (+41/-37)
src/ui_fsmenu/launchSPG.cc (+38/-36)
src/ui_fsmenu/launchSPG.h (+0/-2)
src/ui_fsmenu/loadgame.cc (+19/-18)
src/ui_fsmenu/loadreplay.cc (+13/-15)
src/ui_fsmenu/loadreplay.h (+2/-4)
src/ui_fsmenu/main.cc (+35/-36)
src/ui_fsmenu/main.h (+0/-2)
src/ui_fsmenu/mapselect.cc (+41/-42)
src/ui_fsmenu/mapselect.h (+0/-2)
src/ui_fsmenu/multiplayer.cc (+19/-17)
src/ui_fsmenu/netsetup_ggz.cc (+27/-26)
src/ui_fsmenu/netsetup_lan.cc (+31/-32)
src/ui_fsmenu/netsetup_lan.h (+0/-2)
src/ui_fsmenu/options.cc (+110/-113)
src/ui_fsmenu/options.h (+0/-4)
src/ui_fsmenu/singleplayer.cc (+17/-16)
src/wui/attack_box.cc (+5/-1)
src/wui/bulldozeconfirm.cc (+4/-5)
src/wui/game_tips.cc (+8/-5)
src/wui/interactive_base.cc (+7/-8)
src/wui/military_box.cc (+1/-1)
src/wui/multiplayersetupgroup.cc (+24/-17)
src/wui/playerdescrgroup.cc (+10/-10)
src/wui/playerdescrgroup.h (+5/-3)
src/wui/plot_area.cc (+13/-21)
src/wui/waresdisplay.cc (+4/-4)
To merge this branch: bzr merge lp:~nha/widelands/fonthandler
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+47929@code.launchpad.net

Description of the change

I've been doing some cleanups of this branch, and I'd like to get it merged soonish. It doesn't yet do everything that I originally set out to do, but I think it's in a usable state.

The fundamental change of how the Font_Handler works is that we no longer want to cache entire pages of text, but instead only cache individual pre-rendered lines as pictures. The advantage is that very long multiline texts do not have to be rendered all at once, and we limit the size of pictures generated in this way. We also do not have to re-render texts when the caret moves, and we can more naturally integrate more complex graphics in richtext fields in OpenGL mode. However, that last part - refactoring richtext support - has not been implemented yet.

Visible changes:
1. The caret now works in OpenGL mode (yay!)
2. Font rendering now uses proper alpha-rendering
3. Multi-line texts no longer have ridiculously large spacing between lines in the new renderer. However, since Multiline_Textarea refactoring is pending the richtext changes, this is not yet the case everywhere, but only in Multiline_Editbox and those place that call draw_multiline directly (e.g. game tips).

If you have some spare minutes to test, I'd appreciate bug reports. If I don't hear anything, I'm going to merge this in the next few days (probably Wednesday).

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

Great work! I did only a very quick test though, but OpenGL and Software Rendering of Text areas worked for me. I tested with the atlantean scenario that contains plenty of text messages.

One thing I noticed though is that the background of tooltips are yellow now; this makes the tooltips hard to read. I also noticed that the size of the tooltips is not correct in all cases (mouse over the various buttons at the bottom of the screen) - but this only in the Software renderer. I can't say if any of this issues are related to your branches' changes though. So I do not set this to Needs fixing.

Revision history for this message
Nicolai Hähnle (nha) wrote :

Not to dampen your enthusiasm too much, but those text messages are rich text, which is unfortunately not affected yet.

I've increased the contrast of those tool tips, so they should definitely be easy to read now. Of course one can tweak the colours if desired, but I don't think that's the important point.

I cannot reproduce a problem with tooltip sizes, that sounds really weird. I don't see a difference between OpenGL and software rendering here (and there really shouldn't be one, at least as far as size computations are concerned). Which button shows the effect?

Revision history for this message
SirVer (sirver) wrote :

Ooh, alright. I now properly tested occurences of Multiline_Editbox and Multiline_Textarea and haven't seen any errors. I also like the tooltips much better now. I was unable to reproduce the size bug I mentioned yesterday - If I stumple upon it again, i'll report a bug. Likely this problem is not related to your changes though.

So I have no objections and suggest a merge. Good job!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/constants.h'
2--- src/constants.h 2010-01-11 13:35:27 +0000
3+++ src/constants.h 2011-01-31 17:56:23 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2002-2003, 2006-2010 by the Widelands Development Team
7+ * Copyright (C) 2002-2003, 2006-2011 by the Widelands Development Team
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11@@ -85,7 +85,7 @@
12 #define UI_FONT_BIG_CLR UI_FONT_CLR_FG, UI_FONT_CLR_BG
13 /// small is used for ultrasmall, too
14 #define UI_FONT_SMALL_CLR UI_FONT_CLR_FG, UI_FONT_CLR_BG
15-#define UI_FONT_TOOLTIP_CLR RGBColor(255, 255, 0), RGBColor(63, 52, 34)
16+#define UI_FONT_TOOLTIP_CLR RGBColor(255, 255, 0)
17 //@}
18
19 /// the actual game logic doesn't know about frames
20
21=== added file 'src/graphic/font.cc'
22--- src/graphic/font.cc 1970-01-01 00:00:00 +0000
23+++ src/graphic/font.cc 2011-01-31 17:56:23 +0000
24@@ -0,0 +1,240 @@
25+/*
26+ * Copyright (C) 2002-2011 by the Widelands Development Team
27+ *
28+ * This program is free software; you can redistribute it and/or
29+ * modify it under the terms of the GNU General Public License
30+ * as published by the Free Software Foundation; either version 2
31+ * of the License, or (at your option) any later version.
32+ *
33+ * This program is distributed in the hope that it will be useful,
34+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
35+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36+ * GNU General Public License for more details.
37+ *
38+ * You should have received a copy of the GNU General Public License
39+ * along with this program; if not, write to the Free Software
40+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41+ *
42+ */
43+
44+#include "font.h"
45+
46+#include <map>
47+
48+#include "constants.h"
49+#include "io/filesystem/layered_filesystem.h"
50+
51+namespace {
52+
53+struct FontDescr {
54+ std::string name;
55+ int size;
56+
57+ bool operator<(const FontDescr & o) const {
58+ return
59+ size < o.size ||
60+ (size == o.size && name < o.name);
61+ }
62+};
63+
64+typedef std::map<FontDescr, UI::Font *> FontMap;
65+
66+FontMap g_fontmap;
67+
68+} // anonymous namespace
69+
70+
71+namespace UI {
72+
73+/**
74+ * Open a font file and load the corresponding font.
75+ */
76+Font::Font(const std::string & name, int size)
77+{
78+ // Load the TrueType Font
79+ std::string filename = "fonts/";
80+ filename += name;
81+
82+ // We must keep this File Read open, otherwise the following calls are
83+ // crashing. do not know why...
84+ m_fontfile.Open(*g_fs, filename.c_str());
85+
86+ SDL_RWops * const ops = SDL_RWFromMem(m_fontfile.Data(0), m_fontfile.GetSize());
87+ if (!ops)
88+ throw wexception("could not load font!: RWops Pointer invalid");
89+
90+ m_font = TTF_OpenFontIndexRW(ops, 1, size, 0);
91+ if (!m_font)
92+ throw wexception("could not load font!: %s", TTF_GetError());
93+
94+ // Compute the line skip based on some glyphs by sampling some letters,
95+ // special characters, and accented/umlauted versions of capital A
96+ // It seems more reasonable to use TTF_FontLineSkip(), but the fonts
97+ // we use claim to have a very excessive line skip.
98+ static uint16_t glyphs[] = {'A', '_', '@', ',', 'q', 'y', '"', 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5};
99+ int32_t minminy = 0;
100+ int32_t maxmaxy = 0;
101+
102+ for (unsigned int idx = 0; idx < sizeof(glyphs) / sizeof(glyphs[0]); ++idx) {
103+ int miny, maxy;
104+ if (TTF_GlyphMetrics(m_font, glyphs[idx], 0, 0, &miny, &maxy, 0) < 0)
105+ continue; // error, e.g. glyph not found
106+
107+ if (miny < minminy)
108+ minminy = miny;
109+ if (maxy > maxmaxy)
110+ maxmaxy = maxy;
111+ }
112+
113+ m_computed_lineskip = maxmaxy - minminy + 1;
114+}
115+
116+/**
117+ * Free all resources associated with this font.
118+ */
119+Font::~Font()
120+{
121+ TTF_CloseFont(m_font);
122+ m_font = 0;
123+}
124+
125+/**
126+ * \return the maximum height of glyphs of this font.
127+ */
128+uint32_t Font::height() const
129+{
130+ return TTF_FontHeight(m_font);
131+}
132+
133+/**
134+ * \return the number of pixels between lines in this font (from baseline to baseline).
135+ */
136+uint32_t Font::lineskip() const
137+{
138+ return m_computed_lineskip;
139+}
140+
141+/**
142+ * Return the font for the given name and size.
143+ *
144+ * \note Fonts are cached and need not be freed explicitly. \see shutdown
145+ */
146+Font * Font::get(const std::string & name, int size)
147+{
148+ FontDescr descr;
149+ descr.name = name;
150+ descr.size = size;
151+
152+ FontMap::iterator it = g_fontmap.find(descr);
153+ if (it == g_fontmap.end()) {
154+ Font * font = new Font(name, size);
155+ it = g_fontmap.insert(std::make_pair(descr, font)).first;
156+ }
157+
158+ //TODO: get rid of this nasty hack
159+ //This is required until Font_Handler completely switches to the new render_line()-based functionality
160+ TTF_SetFontStyle(it->second->get_ttf_font(), TTF_STYLE_BOLD);
161+
162+ return it->second;
163+}
164+
165+/**
166+ * Free all registered fonts.
167+ */
168+void Font::shutdown()
169+{
170+ while (!g_fontmap.empty()) {
171+ delete g_fontmap.begin()->second;
172+ g_fontmap.erase(g_fontmap.begin());
173+ }
174+}
175+
176+/**
177+ * Compute the bare width (without caret padding) of the given string.
178+ */
179+uint32_t TextStyle::calc_bare_width(const std::string & text) const
180+{
181+ int w, h;
182+ TTF_SizeUTF8(font->get_ttf_font(), text.c_str(), &w, &h);
183+ return w;
184+}
185+
186+
187+/*
188+=============================
189+
190+Default fonts and styles
191+
192+=============================
193+*/
194+
195+Font * Font::ui_big()
196+{
197+ Font * font = 0;
198+ if (!font)
199+ font = Font::get(UI_FONT_BIG);
200+ return font;
201+}
202+
203+Font * Font::ui_small()
204+{
205+ Font * font = 0;
206+ if (!font)
207+ font = Font::get(UI_FONT_SMALL);
208+ return font;
209+}
210+
211+Font * Font::ui_ultrasmall()
212+{
213+ Font * font = 0;
214+ if (!font)
215+ font = Font::get(UI_FONT_ULTRASMALL);
216+ return font;
217+}
218+
219+const TextStyle & TextStyle::ui_big()
220+{
221+ static TextStyle style;
222+ static bool init = false;
223+
224+ if (!init) {
225+ style.font = Font::ui_big();
226+ style.fg = UI_FONT_CLR_FG;
227+ style.bold = true;
228+ init = true;
229+ }
230+
231+ return style;
232+}
233+
234+const TextStyle & TextStyle::ui_small()
235+{
236+ static TextStyle style;
237+ static bool init = false;
238+
239+ if (!init) {
240+ style.font = Font::ui_small();
241+ style.fg = UI_FONT_CLR_FG;
242+ style.bold = true;
243+ init = true;
244+ }
245+
246+ return style;
247+}
248+
249+const TextStyle & TextStyle::ui_ultrasmall()
250+{
251+ static TextStyle style;
252+ static bool init = false;
253+
254+ if (!init) {
255+ style.font = Font::ui_ultrasmall();
256+ style.fg = UI_FONT_CLR_FG;
257+ style.bold = true;
258+ init = true;
259+ }
260+
261+ return style;
262+}
263+
264+} // namespace UI
265
266=== added file 'src/graphic/font.h'
267--- src/graphic/font.h 1970-01-01 00:00:00 +0000
268+++ src/graphic/font.h 2011-01-31 17:56:23 +0000
269@@ -0,0 +1,109 @@
270+/*
271+ * Copyright (C) 2002-2011 by the Widelands Development Team
272+ *
273+ * This program is free software; you can redistribute it and/or
274+ * modify it under the terms of the GNU General Public License
275+ * as published by the Free Software Foundation; either version 2
276+ * of the License, or (at your option) any later version.
277+ *
278+ * This program is distributed in the hope that it will be useful,
279+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
280+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
281+ * GNU General Public License for more details.
282+ *
283+ * You should have received a copy of the GNU General Public License
284+ * along with this program; if not, write to the Free Software
285+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
286+ *
287+ */
288+
289+#ifndef FONT_H
290+#define FONT_H
291+
292+#include <boost/shared_ptr.hpp>
293+
294+#include <SDL_ttf.h>
295+
296+#include "io/fileread.h"
297+#include "rgbcolor.h"
298+
299+namespace UI {
300+
301+/**
302+ * Margin around text that is kept to make space for the caret.
303+ */
304+#define LINE_MARGIN 1
305+
306+
307+/**
308+ * Wrapper object around a font.
309+ *
310+ * Fonts in our sense are defined by the general font shape (given by the font
311+ * name) and the size of the font.
312+ */
313+struct Font {
314+ static void shutdown();
315+ static Font * get(const std::string & name, int size);
316+ static Font * ui_big();
317+ static Font * ui_small();
318+ static Font * ui_ultrasmall();
319+
320+ uint32_t height() const;
321+ uint32_t lineskip() const;
322+
323+ TTF_Font * get_ttf_font() const {return m_font;}
324+
325+private:
326+ Font(const std::string & name, int size);
327+ ~Font();
328+
329+ FileRead m_fontfile;
330+ TTF_Font * m_font;
331+ uint32_t m_computed_lineskip;
332+};
333+
334+/**
335+ * Text style combines font with other characteristics like color
336+ * and style (italics, bold).
337+ */
338+struct TextStyle {
339+ TextStyle() :
340+ font(0),
341+ fg(255, 255, 255),
342+ bold(false),
343+ italics(false),
344+ underline(false)
345+ {}
346+
347+ static TextStyle makebold(Font * font, RGBColor fg) {
348+ TextStyle ts;
349+ ts.font = font;
350+ ts.bold = true;
351+ ts.fg = fg;
352+ return ts;
353+ }
354+
355+ static const TextStyle & ui_big();
356+ static const TextStyle & ui_small();
357+ static const TextStyle & ui_ultrasmall();
358+ uint32_t calc_bare_width(const std::string & text) const;
359+
360+ Font * font;
361+ RGBColor fg;
362+ bool bold : 1;
363+ bool italics : 1;
364+ bool underline : 1;
365+
366+ bool operator== (const TextStyle & o) const {
367+ return
368+ font == o.font && fg == o.fg &&
369+ bold == o.bold && italics == o.italics && underline == o.underline;
370+ }
371+ bool operator!= (const TextStyle & o) const {
372+ return !(*this == o);
373+ }
374+};
375+
376+} // namespace UI
377+
378+#endif // FONT_H
379
380=== modified file 'src/graphic/font_handler.cc'
381--- src/graphic/font_handler.cc 2010-11-27 16:23:39 +0000
382+++ src/graphic/font_handler.cc 2011-01-31 17:56:23 +0000
383@@ -1,5 +1,5 @@
384 /*
385- * Copyright (C) 2002-2010 by the Widelands Development Team
386+ * Copyright (C) 2002-2011 by the Widelands Development Team
387 *
388 * This program is free software; you can redistribute it and/or
389 * modify it under the terms of the GNU General Public License
390@@ -22,7 +22,7 @@
391 #include "font_handler.h"
392
393 #include "io/filesystem/filesystem.h"
394-#include "font_loader.h"
395+#include "font.h"
396 #include "helper.h"
397 #include "log.h"
398 #include "wexception.h"
399@@ -32,30 +32,68 @@
400 #include "rendertarget.h"
401 #include "surface.h"
402 #include "graphic/render/surface_sdl.h"
403+#include "wordwrap.h"
404
405 #include <SDL_image.h>
406 #include <SDL_ttf.h>
407
408 #include <algorithm>
409 #include <iostream>
410+#include <boost/concept_check.hpp>
411+#include <boost/concept_check.hpp>
412+#include <scripting/pdep/llimits.h>
413
414 namespace UI {
415
416-#define LINE_MARGIN 1
417+/// The global unique \ref Font_Handler object
418+Font_Handler * g_fh = 0;
419+
420+/**
421+ * The line cache stores unprocessed rendered lines of text.
422+ */
423+struct LineCacheEntry {
424+ /*@{*/
425+ TextStyle style;
426+ std::string text;
427+ /*@}*/
428+
429+ /*@{*/
430+ PictureID picture;
431+ uint32_t width;
432+ uint32_t height;
433+ /*@}*/
434+};
435+
436+typedef std::list<LineCacheEntry> LineCache;
437+
438+static const unsigned MaxLineCacheSize = 500;
439+
440+/**
441+ * Internal data of the \ref Font_Handler.
442+ */
443+struct Font_Handler::Data {
444+ LineCache linecache;
445+
446+ const LineCacheEntry & get_line(const TextStyle & style, const std::string & text);
447+
448+private:
449+ void render_line(LineCacheEntry & lce);
450+};
451
452 /**
453 * Plain Constructor
454 */
455-Font_Handler::Font_Handler() {
456+Font_Handler::Font_Handler() :
457+ d(new Data)
458+{
459 if (TTF_Init() == -1)
460 throw wexception
461 ("True Type library did not initialize: %s\n", TTF_GetError());
462- m_font_loader = new Font_Loader();
463 }
464
465
466 Font_Handler::~Font_Handler() {
467- delete m_font_loader;
468+ Font::shutdown();
469 TTF_Quit();
470 }
471
472@@ -66,7 +104,7 @@
473 uint32_t Font_Handler::get_fontheight
474 (std::string const & name, int32_t const size)
475 {
476- TTF_Font * const f = m_font_loader->get_font(name, size);
477+ TTF_Font * const f = Font::get(name, size)->get_ttf_font();
478 const int32_t fontheight = TTF_FontHeight(f);
479 if (fontheight < 0)
480 throw wexception
481@@ -75,6 +113,124 @@
482 return fontheight;
483 }
484
485+/**
486+ * Get a cache entry for the given text (without linebreaks!) rendered
487+ * in the given style.
488+ *
489+ * If there is no pre-existing cache entry, a new one is created.
490+ */
491+const LineCacheEntry & Font_Handler::Data::get_line(const UI::TextStyle & style, const std::string & text)
492+{
493+ for (LineCache::iterator it = linecache.begin(); it != linecache.end(); ++it) {
494+ if (it->style != style || it->text != text)
495+ continue;
496+
497+ // Found a hit, move to front
498+ if (it != linecache.begin())
499+ linecache.splice(linecache.begin(), linecache, it);
500+ return *it;
501+ }
502+
503+ // Cache miss; render a new picture
504+ LineCache::iterator it = linecache.insert(linecache.begin(), LineCacheEntry());
505+ it->style = style;
506+ it->text = text;
507+ render_line(*it);
508+
509+ while (linecache.size() > MaxLineCacheSize)
510+ linecache.pop_back();
511+
512+ return *it;
513+}
514+
515+/**
516+ * Render the picture of a \ref LineCacheEntry whose key data has
517+ * already been filled in.
518+ */
519+void Font_Handler::Data::render_line(LineCacheEntry & lce)
520+{
521+ //static int count = 0;
522+ //log("render_line(%s): %i\n", lce.text.c_str(), ++count);
523+
524+ TTF_Font * font = lce.style.font->get_ttf_font();
525+ SDL_Color sdl_fg = {lce.style.fg.r(), lce.style.fg.g(), lce.style.fg.b(), 0};
526+
527+ // Work around an Issue in SDL_TTF that dies when the surface
528+ // has zero width
529+ int width = 0;
530+ if (TTF_SizeUTF8(font, lce.text.c_str(), &width, 0) < 0 or !width) {
531+ lce.width = 0;
532+ lce.height = TTF_FontHeight(font);
533+ return;
534+ }
535+
536+ int32_t font_style = TTF_STYLE_NORMAL;
537+ if (lce.style.bold)
538+ font_style |= TTF_STYLE_BOLD;
539+ if (lce.style.italics)
540+ font_style |= TTF_STYLE_ITALIC;
541+ if (lce.style.underline)
542+ font_style |= TTF_STYLE_UNDERLINE;
543+ TTF_SetFontStyle(font, font_style);
544+
545+ SDL_Surface * text_surface = TTF_RenderUTF8_Blended(font, lce.text.c_str(), sdl_fg);
546+ if (!text_surface) {
547+ log
548+ ("Font_Handler::render_line, an error : %s\n",
549+ TTF_GetError());
550+ log("Text was: '%s'\n", lce.text.c_str());
551+ return;
552+ }
553+
554+ lce.picture = g_gr->convert_sdl_surface_to_picture(text_surface, true);
555+ lce.width = lce.picture->get_w();
556+ lce.height = lce.picture->get_h();
557+}
558+
559+/**
560+ * Draw unwrapped, single-line text (i.e. no line breaks).
561+ */
562+void Font_Handler::draw_text
563+ (RenderTarget & dst,
564+ const TextStyle & style,
565+ Point dstpoint,
566+ const std::string & text,
567+ Align align,
568+ uint32_t caret)
569+{
570+ const LineCacheEntry & lce = d->get_line(style, text);
571+
572+ do_align(align, dstpoint.x, dstpoint.y, lce.width + 2 * LINE_MARGIN, lce.height);
573+
574+ if (lce.picture && lce.picture->valid())
575+ dst.blit(Point(dstpoint.x + LINE_MARGIN, dstpoint.y), lce.picture);
576+
577+ if (caret <= text.size())
578+ draw_caret(dst, style, dstpoint, text, caret);
579+}
580+
581+/**
582+ * Draw multi-line text, optionally with wrapping.
583+ *
584+ * @note Consider using @ref WordWrap directly, if the same multi-line
585+ * text is going to be rendered many times.
586+ */
587+void Font_Handler::draw_multiline
588+ (RenderTarget & dst,
589+ const TextStyle & style,
590+ Point dstpoint,
591+ const std::string & text,
592+ Align align,
593+ uint32_t wrap,
594+ uint32_t caret)
595+{
596+ WordWrap ww(style, wrap);
597+
598+ ww.wrap(text);
599+ ww.draw(dst, dstpoint, align, caret);
600+}
601+
602+
603 /*
604 * Draw this string, if it is not cached, create the cache for it.
605 *
606@@ -85,7 +241,7 @@
607 * windows ...) this is the death, for a whole new surface is rendered
608 * with everything that has been written so far.
609 */
610-// TODO: rename this to draw text
611+// TODO: get rid of this (depends on refactor of Multiline_Textarea)
612 void Font_Handler::draw_string
613 (RenderTarget & dst,
614 std::string const & fontname,
615@@ -95,50 +251,27 @@
616 Align const align,
617 uint32_t const wrap,
618 Widget_Cache const widget_cache,
619- PictureID * widget_cache_id,
620- uint32_t const caret,
621- bool const transparent)
622+ PictureID * widget_cache_id)
623 {
624- TTF_Font & font = *m_font_loader->get_font(fontname, fontsize);
625+ TTF_Font & font = *Font::get(fontname, fontsize)->get_ttf_font();
626 //Width and height of text, needed for alignment
627 uint32_t w, h;
628 PictureID picid;
629 //log("Font_Handler::draw_string(%s)\n", text.c_str());
630 //Fontrender takes care of caching
631 if (widget_cache == Widget_Cache_None) {
632- // look if text is cached
633- _Cache_Infos ci =
634- {g_gr->get_no_picture(), text, &font, fg, bg, caret, 0, 0};
635-
636- std::list<_Cache_Infos>::iterator i =
637- find(m_cache.begin(), m_cache.end(), ci);
638-
639- if (i != m_cache.end()) {
640- // Ok, it is cached, blit it and done
641- picid = i->picture_id;
642- w = i->w;
643- h = i->h;
644- if (i != m_cache.begin()) {
645- m_cache.push_front (*i);
646- m_cache.erase (i);
647- }
648+ TextStyle style;
649+ style.font = Font::get(fontname, fontsize);
650+ style.fg = fg;
651+ style.bold = true;
652+
653+ if (wrap == std::numeric_limits<uint32_t>::max() && text.find('\n') == std::string::npos) {
654+ draw_text(dst, style, dstpoint, text, align);
655 } else {
656- //not cached, create a new surface and cache it
657- ci.picture_id =
658- create_text_surface
659- (font, fg, bg, text, align, wrap, 0, caret, transparent);
660- g_gr->get_picture_size(ci.picture_id, ci.w, ci.h);
661- ci.f = &font;
662- m_cache.push_front (ci);
663-
664- while (m_cache.size() > CACHE_ARRAY_SIZE)
665- m_cache.pop_back();
666-
667- //Set for alignment and blitting
668- picid = ci.picture_id;
669- w = ci.w;
670- h = ci.h;
671+ draw_multiline(dst, style, dstpoint, text, align, wrap);
672 }
673+
674+ return;
675 } else if (widget_cache == Widget_Cache_Use) {
676 // Widget gave us an explicit picid.
677 g_gr->get_picture_size(*widget_cache_id, w, h);
678@@ -147,8 +280,10 @@
679 // We need to (re)create the picid for the widget.
680 // The old picture is freed automatically
681 *widget_cache_id =
682- create_text_surface
683- (font, fg, bg, text, align, wrap, 0, caret, transparent);
684+ convert_sdl_surface
685+ (*create_sdl_text_surface
686+ (font, fg, bg, text, align, wrap, 0),
687+ bg, true);
688 g_gr->get_picture_size(*widget_cache_id, w, h);
689 picid = *widget_cache_id;
690 }
691@@ -157,32 +292,13 @@
692 }
693
694 /*
695-* Creates a Widelands surface of the given text, checks if multiline or not
696-*/
697-PictureID Font_Handler::create_text_surface
698- (TTF_Font & font, RGBColor const fg, RGBColor const bg,
699- std::string const & text, Align const align,
700- uint32_t const wrap,
701- uint32_t const linespacing,
702- uint32_t const caret,
703- bool const transparent)
704-{
705- return
706- convert_sdl_surface
707- (*create_sdl_text_surface
708- (font, fg, bg, text, align, wrap, linespacing, caret),
709- bg, transparent);
710-}
711-
712-/*
713 * This function renders a short (single line) text surface
714 */
715 SDL_Surface * Font_Handler::create_single_line_text_surface
716 (TTF_Font & font,
717 RGBColor const fg, RGBColor const bg,
718 std::string text,
719- Align,
720- uint32_t const caret)
721+ Align)
722 {
723 // render this block in a SDL Surface
724 SDL_Color sdl_fg = {fg.r(), fg.g(), fg.b(), 0};
725@@ -215,10 +331,6 @@
726 SDL_Rect r; r.x = LINE_MARGIN, r.y = 0;
727 SDL_BlitSurface(text_surface, 0, surface, &r);
728 SDL_FreeSurface(text_surface);
729- if (caret != std::numeric_limits<uint32_t>::max()) {
730- std::string const text_caret_pos = text.substr(0, caret);
731- render_caret(font, *surface, text_caret_pos);
732- }
733 return surface;
734 } else {
735 log
736@@ -242,8 +354,7 @@
737 std::string const & text,
738 Align const align,
739 uint32_t const wrap,
740- uint32_t const linespacing,
741- uint32_t caret)
742+ uint32_t const linespacing)
743 {
744 assert(wrap != std::numeric_limits<uint32_t>::max());
745 assert(2 * LINE_MARGIN < wrap);
746@@ -256,9 +367,6 @@
747 SDL_Color sdl_fg = {fg.r(), fg.g(), fg.b(), 0};
748 SDL_Color sdl_bg = {bg.r(), bg.g(), bg.b(), 0};
749
750- uint32_t cur_text_pos = 0;
751- uint32_t i = 0;
752-
753 std::string const lines = word_wrap_text(font, text, wrap);
754 std::string::size_type const lines_size = lines.size();
755 struct {std::string::size_type pos; bool done;} j = {0, false};
756@@ -298,17 +406,6 @@
757 SDL_Rect r; r.x = LINE_MARGIN, r.y = 0;
758 SDL_BlitSurface(text_surface, 0, surface, &r);
759 SDL_FreeSurface(text_surface);
760- if (caret != std::numeric_limits<uint32_t>::max()) {
761- uint32_t const new_text_pos = cur_text_pos + line_size;
762- if (new_text_pos >= caret - i) {
763- int32_t const caret_line_pos = caret - cur_text_pos - i;
764- line.resize(caret_line_pos);
765- render_caret(font, *surface, line);
766- caret = std::numeric_limits<uint32_t>::max();
767- } else
768- cur_text_pos = new_text_pos;
769- ++i;
770- }
771
772 m_rendered_lines.push_back(surface);
773 global_surface_height += surface->h + linespacing;
774@@ -333,35 +430,31 @@
775
776 }
777
778-void Font_Handler::render_caret
779- (TTF_Font & font,
780- SDL_Surface & line,
781- std::string const & text_caret_pos)
782+/**
783+ * Draw the caret for the given text rendered exactly at the given point
784+ * (including \ref LINE_MARGIN).
785+ */
786+void Font_Handler::draw_caret
787+ (RenderTarget & dst,
788+ const TextStyle & style,
789+ Point dstpoint,
790+ const std::string & text,
791+ uint32_t caret)
792 {
793- int32_t caret_x, caret_y;
794-
795- TTF_SizeUTF8(&font, text_caret_pos.c_str(), &caret_x, &caret_y);
796- caret_x += LINE_MARGIN;
797-
798- //TODO: Implement caret rendering for opengl
799- if (!g_opengl)
800- {
801- PictureID caret = g_gr->get_picture(PicMod_Game, "pics/caret.png");
802- upcast(SurfaceSDL, sdlsurf, caret.get());
803- assert(sdlsurf);
804- SDL_Surface * const caret_surf_sdl = sdlsurf->get_sdl_surface();
805-
806- SDL_Rect r;
807- r.x = caret_x - caret_surf_sdl->w;
808- r.y = (caret_y - caret_surf_sdl->h) / 2;
809-
810- SDL_BlitSurface(caret_surf_sdl, 0, &line, &r);
811- } else {
812- log("WARNING: Should render caret here but it is not implemented\n");
813- }
814-
815+ std::string sub = text.substr(0, caret);
816+ int caret_x, caret_y;
817+
818+ TTF_SizeUTF8(style.font->get_ttf_font(), sub.c_str(), &caret_x, &caret_y);
819+
820+ PictureID caretpic = g_gr->get_picture(PicMod_UI, "pics/caret.png");
821+ Point caretpt;
822+ caretpt.x = dstpoint.x + caret_x + LINE_MARGIN - caretpic->get_w();
823+ caretpt.y = dstpoint.y + (caret_y - caretpic->get_h()) / 2;
824+
825+ dst.blit(caretpt, caretpic);
826 }
827
828+
829 /*
830 * Renders a string into a SDL surface
831 * Richtext works with this method, because whole richtext content
832@@ -376,7 +469,7 @@
833 int32_t const style,
834 uint32_t const linespacing)
835 {
836- TTF_Font & font = *m_font_loader->get_font(fontname, fontsize);
837+ TTF_Font & font = *Font::get(fontname, fontsize)->get_ttf_font();
838 TTF_SetFontStyle(&font, style);
839 return
840 create_sdl_text_surface(font, fg, bg, text, align, wrap, linespacing);
841@@ -390,15 +483,14 @@
842 std::string const & text,
843 Align const align,
844 uint32_t const wrap,
845- uint32_t const linespacing,
846- uint32_t const caret)
847+ uint32_t const linespacing)
848 {
849 return
850 wrap != std::numeric_limits<uint32_t>::max() ?
851 create_static_long_text_surface
852- (font, fg, bg, text, align, wrap, linespacing, caret)
853+ (font, fg, bg, text, align, wrap, linespacing)
854 :
855- create_single_line_text_surface(font, fg, bg, text, align, caret);
856+ create_single_line_text_surface(font, fg, bg, text, align);
857 }
858
859 /*
860@@ -834,6 +926,7 @@
861 void Font_Handler::flush_cache()
862 {
863 m_cache.clear();
864+ d->linecache.clear();
865 }
866
867 //Inserts linebreaks into a text, so it doesn't get bigger than max_width
868@@ -918,50 +1011,11 @@
869 {
870 return
871 word_wrap_text
872- (*m_font_loader->get_font(fontname, fontsize),
873+ (*Font::get(fontname, fontsize)->get_ttf_font(),
874 unwrapped_text,
875 max_width);
876 }
877
878-
879-//calculates size of a given text
880-void Font_Handler::get_size
881- (std::string const & fontname, int32_t const fontsize,
882- std::string text,
883- uint32_t & w, uint32_t & h,
884- uint32_t const wrap)
885-{
886- TTF_Font & font = *m_font_loader->get_font(fontname, fontsize);
887-
888- if (wrap < std::numeric_limits<uint32_t>::max())
889- text = word_wrap_text(font, text, wrap);
890-
891- w = 0;
892- h = 0;
893- std::string::size_type const text_size = text.size();
894- struct {std::string::size_type pos; bool done;} j = {0, false};
895- for (; not j.done;)
896- {
897- std::string::size_type line_end = text.find('\n', j.pos);
898- if (line_end == std::string::npos) {
899- line_end = text_size;
900- j.done = true;
901- }
902- std::string::size_type line_size = line_end - j.pos;
903- std::string line = text.substr(j.pos, line_size);
904-
905- int32_t line_w, line_h;
906- TTF_SizeUTF8(&font, line.empty() ? " " : line.c_str(), &line_w, &line_h);
907-
908- if (static_cast<int32_t>(w) < line_w)
909- w = line_w;
910- h += line_h;
911-
912- j.pos = line_end + 1;
913- }
914- w += 2 * LINE_MARGIN;
915-}
916-
917 //calcultes linewidth of a given text
918 int32_t Font_Handler::calc_linewidth(TTF_Font & font, std::string const & text)
919 {
920@@ -970,4 +1024,33 @@
921 return w;
922 }
923
924-}
925+/**
926+ * Compute the total size of the given text, when wrapped to the given
927+ * maximum width and rendered in the given text style.
928+ */
929+void Font_Handler::get_size
930+ (const TextStyle & textstyle,
931+ const std::string & text,
932+ uint32_t & w, uint32_t & h,
933+ uint32_t wrap)
934+{
935+ WordWrap ww(textstyle, wrap);
936+ ww.wrap(text);
937+ w = ww.width();
938+ h = ww.height();
939+}
940+
941+/**
942+ * Calculates size of a given text.
943+ */
944+void Font_Handler::get_size
945+ (std::string const & fontname, int32_t const fontsize,
946+ const std::string & text,
947+ uint32_t & w, uint32_t & h,
948+ uint32_t const wrap)
949+{
950+ // use bold style by default for historical reasons
951+ get_size(TextStyle::makebold(Font::get(fontname, fontsize), RGBColor(255, 255, 255)), text, w, h, wrap);
952+}
953+
954+} // namespace UI
955
956=== modified file 'src/graphic/font_handler.h'
957--- src/graphic/font_handler.h 2010-11-27 13:30:37 +0000
958+++ src/graphic/font_handler.h 2011-01-31 17:56:23 +0000
959@@ -1,5 +1,5 @@
960 /*
961- * Copyright (C) 2002-2004, 2006-2009 by the Widelands Development Team
962+ * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team
963 *
964 * This program is free software; you can redistribute it and/or
965 * modify it under the terms of the GNU General Public License
966@@ -29,6 +29,8 @@
967
968 #include <SDL_ttf.h>
969
970+#include <boost/scoped_ptr.hpp>
971+
972 #include <list>
973 #include <cstring>
974 #include <vector>
975@@ -37,7 +39,7 @@
976
977 namespace UI {
978 struct Text_Block;
979-struct Font_Loader;
980+struct TextStyle;
981
982 /** class Font_Handler
983 *
984@@ -46,6 +48,23 @@
985 struct Font_Handler {
986 Font_Handler();
987 ~Font_Handler();
988+
989+ void draw_text
990+ (RenderTarget &,
991+ const TextStyle &,
992+ Point dstpoint,
993+ const std::string & text,
994+ Align align = Align_CenterLeft,
995+ uint32_t caret = std::numeric_limits<uint32_t>::max());
996+ void draw_multiline
997+ (RenderTarget &,
998+ const TextStyle &,
999+ Point dstpoint,
1000+ const std::string & text,
1001+ Align align = Align_CenterLeft,
1002+ uint32_t wrap = std::numeric_limits<uint32_t>::max(),
1003+ uint32_t caret = std::numeric_limits<uint32_t>::max());
1004+
1005 void draw_string
1006 (RenderTarget &,
1007 const std::string & font,
1008@@ -56,12 +75,16 @@
1009 Align align = Align_CenterLeft,
1010 uint32_t wrap = std::numeric_limits<uint32_t>::max(),
1011 Widget_Cache widget_cache = Widget_Cache_None,
1012- PictureID * widget_cache_id = 0,
1013- uint32_t caret = std::numeric_limits<uint32_t>::max(),
1014- bool transparent = true);
1015+ PictureID * widget_cache_id = 0);
1016+
1017+ void get_size
1018+ (const TextStyle &,
1019+ const std::string & text,
1020+ uint32_t & w, uint32_t & h,
1021+ uint32_t wrap = std::numeric_limits<uint32_t>::max());
1022 void get_size
1023 (std::string const & fontname, int32_t size,
1024- std::string text,
1025+ const std::string & text,
1026 uint32_t & w, uint32_t & h,
1027 uint32_t wrap = std::numeric_limits<uint32_t>::max());
1028 int32_t calc_linewidth(TTF_Font &, const std::string & text);
1029@@ -115,19 +138,12 @@
1030 private:
1031 static const uint32_t CACHE_ARRAY_SIZE = 500;
1032
1033- Font_Loader * m_font_loader;
1034 std::list<_Cache_Infos> m_cache;
1035
1036+ struct Data;
1037+ boost::scoped_ptr<Data> d;
1038+
1039 private:
1040- PictureID create_text_surface
1041- (TTF_Font &,
1042- RGBColor fg, RGBColor bg,
1043- std::string const & text,
1044- Align,
1045- uint32_t wrap = std::numeric_limits<uint32_t>::max(),
1046- uint32_t line_spacing = 0,
1047- uint32_t caret = std::numeric_limits<uint32_t>::max(),
1048- bool transparent = true);
1049 PictureID convert_sdl_surface
1050 (SDL_Surface &, const RGBColor bg, bool transparent = false);
1051 SDL_Surface * draw_string_sdl_surface
1052@@ -143,19 +159,16 @@
1053 std::string const & text,
1054 Align,
1055 uint32_t wrap = std::numeric_limits<uint32_t>::max(),
1056- uint32_t linespacing = 0,
1057- uint32_t caret = std::numeric_limits<uint32_t>::max());
1058+ uint32_t linespacing = 0);
1059 SDL_Surface * create_static_long_text_surface
1060 (TTF_Font &, RGBColor fg, RGBColor bg,
1061 std::string const & text,
1062 Align,
1063 uint32_t wrap = std::numeric_limits<uint32_t>::max(),
1064- uint32_t linespacing = 0,
1065- uint32_t caret = std::numeric_limits<uint32_t>::max());
1066+ uint32_t linespacing = 0);
1067 SDL_Surface * create_single_line_text_surface
1068 (TTF_Font &, RGBColor fg, RGBColor bg,
1069- std::string text, Align,
1070- uint32_t caret = std::numeric_limits<uint32_t>::max());
1071+ std::string text, Align);
1072 SDL_Surface * create_empty_sdl_surface(uint32_t w, uint32_t h);
1073 SDL_Surface * join_sdl_surfaces
1074 (uint32_t w, uint32_t h,
1075@@ -168,13 +181,16 @@
1076 SDL_Surface * load_image(std::string file);
1077 SDL_Surface * render_space
1078 (Text_Block &, RGBColor bg, int32_t style = TTF_STYLE_NORMAL);
1079- void render_caret
1080- (TTF_Font &,
1081- SDL_Surface & line,
1082- const std::string & text_caret_pos);
1083+
1084+ void draw_caret
1085+ (RenderTarget &,
1086+ const TextStyle &,
1087+ Point dstpoint,
1088+ const std::string & text,
1089+ uint32_t caret);
1090 };
1091
1092-extern Font_Handler * g_fh; // the default font
1093+extern Font_Handler * g_fh;
1094
1095 }
1096
1097
1098=== removed file 'src/graphic/font_loader.cc'
1099--- src/graphic/font_loader.cc 2010-05-18 13:21:05 +0000
1100+++ src/graphic/font_loader.cc 1970-01-01 00:00:00 +0000
1101@@ -1,121 +0,0 @@
1102-/*
1103- * Copyright (C) 2002, 2008-2009 by the Widelands Development Team
1104- *
1105- * This program is free software; you can redistribute it and/or
1106- * modify it under the terms of the GNU General Public License
1107- * as published by the Free Software Foundation; either version 2
1108- * of the License, or (at your option) any later version.
1109- *
1110- * This program is distributed in the hope that it will be useful,
1111- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1112- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1113- * GNU General Public License for more details.
1114- *
1115- * You should have received a copy of the GNU General Public License
1116- * along with this program; if not, write to the Free Software
1117- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1118- *
1119- */
1120-
1121-#include "font_loader.h"
1122-#include "font_handler.h"
1123-
1124-#include "io/fileread.h"
1125-#include "io/filesystem/layered_filesystem.h"
1126-
1127-#include "wexception.h"
1128-
1129-#include <SDL_ttf.h>
1130-
1131-#include <iostream>
1132-#include <string>
1133-#include <cstring>
1134-
1135-namespace UI {
1136-
1137-Font_Handler * g_fh = 0; // the font handler
1138-
1139-/*
1140-===============================================================================
1141-
1142-Font Loader IMPLEMENTATION
1143-
1144-===============================================================================
1145-*/
1146-
1147-
1148-/*
1149-* Opens a font file and returns a TTF_FONT* pointer.
1150-*/
1151-
1152-TTF_Font * Font_Loader::open_font(std::string const & name, int32_t const size)
1153-{
1154- // Load the TrueType Font
1155- std::string filename = "fonts/";
1156- filename += name;
1157-
1158- // We must keep this File Read open, otherwise the following calls are
1159- // crashing. do not know why...
1160- FileRead & fr = *new FileRead();
1161- fr.Open(*g_fs, filename.c_str());
1162-
1163- m_freads.push_back(&fr);
1164-
1165- SDL_RWops * const ops = SDL_RWFromMem(fr.Data(0), fr.GetSize());
1166- if (!ops)
1167- throw wexception("could not load font!: RWops Pointer invalid");
1168-
1169- if (TTF_Font * const font = TTF_OpenFontIndexRW(ops, 1, size, 0))
1170- return font;
1171- else
1172- throw wexception("could not load font!: %s", TTF_GetError());
1173-}
1174-
1175-/*
1176-* Looks for a font with given name and size in the font cache and returns it.
1177-* Ohterwise font will be loaded with open_font and chached.
1178-*/
1179-TTF_Font * Font_Loader::get_font(std::string const & name, int32_t const size)
1180-{
1181- char buffer[5];
1182- snprintf(buffer, sizeof(buffer), "%i", size);
1183-
1184- const std::string key_name = name + '-' + buffer;
1185- std::map<std::string, TTF_Font *>::iterator const it =
1186- m_font_table.find(key_name);
1187- if (it != m_font_table.end()) {
1188- TTF_SetFontStyle(it->second, TTF_STYLE_BOLD);
1189- return it->second;
1190- }
1191-
1192- TTF_Font * const font = open_font(name, size);
1193-
1194- if (font) {
1195- TTF_SetFontStyle(font, TTF_STYLE_BOLD);
1196- m_font_table.insert(std::pair<std::string, TTF_Font *>(key_name, font));
1197- }
1198- return font;
1199-}
1200-
1201-/*
1202-* Clears the font cache.
1203-*/
1204-void Font_Loader::clear_fonts() {
1205- for
1206- (std::map<std::string, TTF_Font *>::iterator i = m_font_table.begin();
1207- i != m_font_table.end();
1208- ++i)
1209- TTF_CloseFont(i->second);
1210- m_font_table.clear();
1211-
1212- for (uint32_t i = 0; i < m_freads.size(); ++i)
1213- delete m_freads[i];
1214- m_freads.clear();
1215-}
1216-
1217-
1218-Font_Loader::~Font_Loader() {
1219- clear_fonts();
1220-}
1221-
1222-}
1223
1224=== removed file 'src/graphic/font_loader.h'
1225--- src/graphic/font_loader.h 2010-05-12 10:16:44 +0000
1226+++ src/graphic/font_loader.h 1970-01-01 00:00:00 +0000
1227@@ -1,52 +0,0 @@
1228-/*
1229- * Copyright (C) 2002-2004, 2006, 2008-2009 by the Widelands Development Team
1230- *
1231- * This program is free software; you can redistribute it and/or
1232- * modify it under the terms of the GNU General Public License
1233- * as published by the Free Software Foundation; either version 2
1234- * of the License, or (at your option) any later version.
1235- *
1236- * This program is distributed in the hope that it will be useful,
1237- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1238- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1239- * GNU General Public License for more details.
1240- *
1241- * You should have received a copy of the GNU General Public License
1242- * along with this program; if not, write to the Free Software
1243- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1244- *
1245- */
1246-
1247-#ifndef FONT_LOADER_H
1248-#define FONT_LOADER_H
1249-
1250-#include "io/fileread.h"
1251-
1252-#include <SDL_ttf.h>
1253-
1254-#include <map>
1255-#include <string>
1256-#include <cstring>
1257-#include <vector>
1258-
1259-namespace UI {
1260-
1261-/*
1262- * Font
1263- *
1264- * this represents a loaded font used by the FontHandler
1265- */
1266-struct Font_Loader {
1267- Font_Loader() {};
1268- ~Font_Loader();
1269- TTF_Font * open_font(const std::string & name, int32_t size);
1270- TTF_Font * get_font (std::string const & name, int32_t size);
1271- void clear_fonts();
1272-private:
1273- std::map<std::string, TTF_Font *> m_font_table;
1274- std::vector<FileRead *> m_freads;
1275-};
1276-
1277-}
1278-
1279-#endif
1280
1281=== modified file 'src/graphic/render/render_sdl.cc'
1282--- src/graphic/render/render_sdl.cc 2010-11-27 16:23:39 +0000
1283+++ src/graphic/render/render_sdl.cc 2011-01-31 17:56:23 +0000
1284@@ -73,7 +73,7 @@
1285 //log("SurfaceSDL::draw_rect()\n");
1286 const uint32_t color = clr.map(format());
1287
1288- const Point bl = rc.bottom_left() - Point(1, 1);
1289+ const Point bl = rc.bottom_right() - Point(1, 1);
1290
1291 for (int32_t x = rc.x + 1; x < bl.x; ++x) {
1292 set_pixel(x, rc.y, color);
1293@@ -126,7 +126,7 @@
1294
1295 //log("SurfaceSDL::brighten_rect()\n");
1296
1297- const Point bl = rc.bottom_left();
1298+ const Point bl = rc.bottom_right();
1299
1300 lock(IPixelAccess::Lock_Normal);
1301
1302
1303=== added file 'src/graphic/wordwrap.cc'
1304--- src/graphic/wordwrap.cc 1970-01-01 00:00:00 +0000
1305+++ src/graphic/wordwrap.cc 2011-01-31 17:56:23 +0000
1306@@ -0,0 +1,293 @@
1307+/*
1308+ * Copyright (C) 2002-2011 by the Widelands Development Team
1309+ *
1310+ * This program is free software; you can redistribute it and/or
1311+ * modify it under the terms of the GNU General Public License
1312+ * as published by the Free Software Foundation; either version 2
1313+ * of the License, or (at your option) any later version.
1314+ *
1315+ * This program is distributed in the hope that it will be useful,
1316+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1317+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1318+ * GNU General Public License for more details.
1319+ *
1320+ * You should have received a copy of the GNU General Public License
1321+ * along with this program; if not, write to the Free Software
1322+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1323+ */
1324+
1325+/*
1326+ * The original version of the word wrapping algorithm was taken
1327+ * from Wesnoth -- http://www.wesnoth.org
1328+ */
1329+
1330+#include "wordwrap.h"
1331+
1332+#include "font_handler.h"
1333+#include "log.h"
1334+#include "rendertarget.h"
1335+
1336+namespace UI {
1337+
1338+/**
1339+ * Initialize the wordwrap object with an unlimited line length
1340+ * and a default-constructed text style.
1341+ */
1342+WordWrap::WordWrap() :
1343+ m_wrapwidth(std::numeric_limits<uint32_t>::max())
1344+{
1345+}
1346+
1347+WordWrap::WordWrap(const TextStyle & style, uint32_t wrapwidth) :
1348+ m_style(style)
1349+{
1350+ m_wrapwidth = wrapwidth;
1351+
1352+ if (m_wrapwidth < std::numeric_limits<uint32_t>::max()) {
1353+ if (m_wrapwidth < 2 * LINE_MARGIN)
1354+ m_wrapwidth = 0;
1355+ else
1356+ m_wrapwidth -= 2 * LINE_MARGIN;
1357+ }
1358+}
1359+
1360+/**
1361+ * Set the text style for future wrapping operations.
1362+ */
1363+void WordWrap::set_style(const TextStyle & style)
1364+{
1365+ m_style = style;
1366+}
1367+
1368+/**
1369+ * Set the wrap width (i.e. line width limit in pixels) for future wrapping operations.
1370+ */
1371+void WordWrap::set_wrapwidth(uint32_t wrapwidth)
1372+{
1373+ m_wrapwidth = wrapwidth;
1374+}
1375+
1376+/**
1377+ * Return the wrap width. This can be larger than the actual @ref width of the final
1378+ * text.
1379+ */
1380+uint32_t WordWrap::wrapwidth() const
1381+{
1382+ return m_wrapwidth;
1383+}
1384+
1385+/**
1386+ * Perform the wrapping computations for the given text and fill in
1387+ * the private data containing the wrapped results.
1388+ */
1389+void WordWrap::wrap(const std::string & text)
1390+{
1391+ //static int count = 0;
1392+ //log("word_wrap_text(%u): %i\n", m_wrapwidth, ++count);
1393+
1394+ m_lines.clear();
1395+
1396+ std::string::size_type line_start = 0;
1397+
1398+ while (line_start <= text.size()) {
1399+ std::string::size_type next_line_start;
1400+ std::string::size_type line_end;
1401+
1402+ compute_end_of_line(text, line_start, line_end, next_line_start);
1403+
1404+ LineData ld;
1405+ ld.start = line_start;
1406+ ld.text = text.substr(line_start, line_end - line_start);
1407+ m_lines.push_back(ld);
1408+
1409+ line_start = next_line_start;
1410+ }
1411+}
1412+
1413+
1414+/**
1415+ * Compute the position where the line that starts at \p line_start
1416+ * ends.
1417+ */
1418+void WordWrap::compute_end_of_line
1419+ (const std::string & text,
1420+ std::string::size_type line_start,
1421+ std::string::size_type & line_end,
1422+ std::string::size_type & next_line_start)
1423+{
1424+ std::string::size_type orig_end = text.find('\n', line_start);
1425+ if (orig_end == std::string::npos)
1426+ orig_end = text.size();
1427+
1428+ if (m_wrapwidth == std::numeric_limits<uint32_t>::max() || orig_end - line_start <= 1) {
1429+ // Special fast path when wrapping is disabled or
1430+ // original text line contains at most one character
1431+ line_end = orig_end;
1432+ next_line_start = orig_end + 1;
1433+ return;
1434+ }
1435+
1436+ // Optimism: perhaps the entire line fits?
1437+ if (m_style.calc_bare_width(text.substr(line_start, orig_end - line_start)) <= m_wrapwidth) {
1438+ line_end = orig_end;
1439+ next_line_start = orig_end + 1;
1440+ return;
1441+ }
1442+
1443+ // Okay, we really do need to wrap; get a first rough estimate using binary search
1444+ // Invariant: [line_start, end_lower) fits,
1445+ // but everything strictly longer than [line_start, end_upper) does not fit
1446+ // We force the lower bound to allow at least one character,
1447+ // otherwise the word wrap might get into an infinite loop.
1448+ std::string::size_type end_upper = orig_end - 1;
1449+ std::string::size_type end_lower = line_start + 1;
1450+
1451+ while (end_upper - end_lower > 4) {
1452+ std::string::size_type mid = end_lower + (end_upper - end_lower + 1) / 2;
1453+
1454+ if (m_style.calc_bare_width(text.substr(line_start, mid - line_start)) <= m_wrapwidth) {
1455+ end_lower = mid;
1456+ } else {
1457+ end_upper = mid - 1;
1458+ }
1459+ }
1460+
1461+ // Narrow it down to a word break
1462+ // Invariant: space points to a space character such that [line_start, space) fits
1463+ std::string::size_type space = end_lower;
1464+
1465+ while (space > line_start && text[space] != ' ')
1466+ --space;
1467+
1468+ for (;;) {
1469+ std::string::size_type nextspace = text.find(' ', space + 1);
1470+ if (nextspace > end_upper)
1471+ break; // we already know that this cannot possibly fit
1472+
1473+ // check whether the next word still fits
1474+ if (m_style.calc_bare_width(text.substr(line_start, nextspace - line_start)) > m_wrapwidth)
1475+ break;
1476+
1477+ space = nextspace;
1478+ }
1479+
1480+ if (space > line_start) {
1481+ line_end = space;
1482+ next_line_start = space + 1;
1483+ return;
1484+ }
1485+
1486+ // Nasty special case: the line starts with a single word that is too big to fit
1487+ // Continue the binary search until we narrowed down exactly how many characters fit
1488+ while (end_upper > end_lower) {
1489+ std::string::size_type mid = end_lower + (end_upper - end_lower + 1) / 2;
1490+
1491+ if (m_style.calc_bare_width(text.substr(line_start, mid - line_start)) <= m_wrapwidth)
1492+ end_lower = mid;
1493+ else
1494+ end_upper = mid - 1;
1495+ }
1496+
1497+ next_line_start = line_end = end_lower;
1498+}
1499+
1500+
1501+/**
1502+ * Compute the width (including border) of the word-wrapped text.
1503+ *
1504+ * \note This is rather inefficient right now.
1505+ */
1506+uint32_t WordWrap::width() const
1507+{
1508+ uint32_t width = 0;
1509+
1510+ for (uint32_t line = 0; line < m_lines.size(); ++line) {
1511+ uint32_t linewidth = m_style.calc_bare_width(m_lines[line].text);
1512+ if (linewidth > width)
1513+ width = linewidth;
1514+ }
1515+
1516+ return width + 2 * LINE_MARGIN;
1517+}
1518+
1519+/**
1520+ * Compute the total height of the word-wrapped text.
1521+ */
1522+uint32_t WordWrap::height() const
1523+{
1524+ uint32_t fontheight = m_style.font->height();
1525+ uint32_t lineskip = m_style.font->lineskip();
1526+
1527+ return fontheight + (m_lines.size() - 1) * lineskip;
1528+}
1529+
1530+/**
1531+ * Given an offset @p caret into the original text, compute the @p line that it
1532+ * appears in in the wrapped text, and also the @p pos within that line (as an offset).
1533+ */
1534+void WordWrap::calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const
1535+{
1536+ assert(m_lines.size());
1537+ assert(m_lines[0].start == 0);
1538+
1539+ uint32_t min = 0;
1540+ uint32_t max = m_lines.size() - 1;
1541+
1542+ while (max > min) {
1543+ uint32_t mid = min + (max - min + 1) / 2;
1544+
1545+ if (caret >= m_lines[mid].start)
1546+ min = mid;
1547+ else
1548+ max = mid - 1;
1549+ }
1550+
1551+ assert(caret >= m_lines[min].start);
1552+
1553+ line = min;
1554+ pos = caret - m_lines[min].start;
1555+}
1556+
1557+/**
1558+ * Return the starting offset of line number @p line in the original text.
1559+ */
1560+uint32_t WordWrap::line_offset(uint32_t line) const
1561+{
1562+ return m_lines[line].start;
1563+}
1564+
1565+/**
1566+ * Draw the word-wrapped text onto \p dst, anchored at \p where with the given alignment.
1567+ *
1568+ * \note This also draws the caret, if any.
1569+ */
1570+void WordWrap::draw(RenderTarget & dst, Point where, Align align, uint32_t caret)
1571+{
1572+ uint32_t fontheight = m_style.font->height();
1573+ uint32_t lineskip = m_style.font->lineskip();
1574+ uint32_t caretline, caretpos;
1575+
1576+ calc_wrapped_pos(caret, caretline, caretpos);
1577+
1578+ if ((align & Align_Vertical) != Align_Top) {
1579+ uint32_t h = height();
1580+
1581+ if ((align & Align_Vertical) == Align_VCenter)
1582+ where.y -= (h + 1) / 2;
1583+ else
1584+ where.y -= h;
1585+ }
1586+
1587+ ++where.y;
1588+ for (uint32_t line = 0; line < m_lines.size(); ++line, where.y += lineskip) {
1589+ if (where.y >= dst.get_h() || int32_t(where.y + fontheight) <= 0)
1590+ continue;
1591+
1592+ g_fh->draw_text
1593+ (dst, m_style, where, m_lines[line].text, Align(align & Align_Horizontal),
1594+ line == caretline ? caretpos : std::numeric_limits<uint32_t>::max());
1595+ }
1596+}
1597+
1598+
1599+} // namespace UI
1600
1601=== added file 'src/graphic/wordwrap.h'
1602--- src/graphic/wordwrap.h 1970-01-01 00:00:00 +0000
1603+++ src/graphic/wordwrap.h 2011-01-31 17:56:23 +0000
1604@@ -0,0 +1,80 @@
1605+/*
1606+ * Copyright (C) 2010-2011 by the Widelands Development Team
1607+ *
1608+ * This program is free software; you can redistribute it and/or
1609+ * modify it under the terms of the GNU General Public License
1610+ * as published by the Free Software Foundation; either version 2
1611+ * of the License, or (at your option) any later version.
1612+ *
1613+ * This program is distributed in the hope that it will be useful,
1614+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1615+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616+ * GNU General Public License for more details.
1617+ *
1618+ * You should have received a copy of the GNU General Public License
1619+ * along with this program; if not, write to the Free Software
1620+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1621+ */
1622+
1623+#ifndef WORDWRAP_H
1624+#define WORDWRAP_H
1625+
1626+#include <string>
1627+
1628+#include "font.h"
1629+#include "point.h"
1630+#include "ui_basic/align.h"
1631+
1632+struct RenderTarget;
1633+
1634+namespace UI {
1635+
1636+/**
1637+ * Helper struct that provides word wrapping and related functionality.
1638+ */
1639+struct WordWrap {
1640+ WordWrap();
1641+ WordWrap(const TextStyle & style, uint32_t wrapwidth = std::numeric_limits<uint32_t>::max());
1642+
1643+ void set_style(const TextStyle & style);
1644+ void set_wrapwidth(uint32_t wrapwidth);
1645+
1646+ uint32_t wrapwidth() const;
1647+
1648+ void wrap(const std::string & text);
1649+
1650+ uint32_t width() const;
1651+ uint32_t height() const;
1652+
1653+ void draw
1654+ (RenderTarget & dst, Point where, Align align = Align_Left,
1655+ uint32_t caret = std::numeric_limits<uint32_t>::max());
1656+
1657+ void calc_wrapped_pos(uint32_t caret, uint32_t & line, uint32_t & pos) const;
1658+ uint32_t nrlines() const {return m_lines.size();}
1659+ uint32_t line_offset(uint32_t line) const;
1660+
1661+private:
1662+ struct LineData {
1663+ /// Textual content of the line
1664+ std::string text;
1665+
1666+ /// Starting offset of this line within the original un-wrapped text
1667+ uint32_t start;
1668+ };
1669+
1670+ void compute_end_of_line
1671+ (const std::string & text,
1672+ std::string::size_type line_start,
1673+ std::string::size_type & line_end,
1674+ std::string::size_type & next_line_start);
1675+
1676+ TextStyle m_style;
1677+ uint32_t m_wrapwidth;
1678+
1679+ std::vector<LineData> m_lines;
1680+};
1681+
1682+} // namespace UI
1683+
1684+#endif // WORDWRAP_H
1685
1686=== modified file 'src/logic/building.cc'
1687--- src/logic/building.cc 2010-11-01 14:00:56 +0000
1688+++ src/logic/building.cc 2011-01-31 17:56:23 +0000
1689@@ -30,6 +30,7 @@
1690 #include "productionsite.h"
1691 #include "profile/profile.h"
1692 #include "graphic/rendertarget.h"
1693+#include "graphic/font.h"
1694 #include "graphic/font_handler.h"
1695 #include "sound/sound_handler.h"
1696 #include "tribe.h"
1697@@ -734,10 +735,8 @@
1698
1699 if (dpyflags & Interactive_Base::dfShowCensus) {
1700 // TODO make more here
1701- UI::g_fh->draw_string
1702- (dst,
1703- UI_FONT_SMALL,
1704- UI_FONT_SMALL_CLR,
1705+ UI::g_fh->draw_text
1706+ (dst, UI::TextStyle::ui_small(),
1707 pos - Point(0, 45),
1708 info_string(igbase.building_census_format()),
1709 UI::Align_Center);
1710@@ -749,10 +748,8 @@
1711 (!iplayer->player().see_all() &&
1712 iplayer->player().is_hostile(*get_owner()))
1713 return;
1714- UI::g_fh->draw_string
1715- (dst,
1716- UI_FONT_SMALL,
1717- UI_FONT_SMALL_CLR,
1718+ UI::g_fh->draw_text
1719+ (dst, UI::TextStyle::ui_small(),
1720 pos - Point(0, 35),
1721 info_string(igbase.building_statistics_format()),
1722 UI::Align_Center);
1723
1724=== modified file 'src/rect.h'
1725--- src/rect.h 2010-05-24 16:07:20 +0000
1726+++ src/rect.h 2011-01-31 17:56:23 +0000
1727@@ -1,5 +1,5 @@
1728 /*
1729- * Copyright (C) 2002-2004, 2006-2007 by the Widelands Development Team
1730+ * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
1731 *
1732 * This program is free software; you can redistribute it and/or
1733 * modify it under the terms of the GNU General Public License
1734@@ -27,7 +27,7 @@
1735 Rect(const Point p, const uint32_t W, const uint32_t H) throw ()
1736 : Point(p), w(W), h(H)
1737 {}
1738- Point bottom_left() const {return *this + Point(w, h);}
1739+ Point bottom_right() const {return *this + Point(w, h);}
1740
1741 /**
1742 * Returns true if this rectangle contains the given point.
1743
1744=== modified file 'src/ui_basic/button.cc'
1745--- src/ui_basic/button.cc 2010-12-30 17:01:47 +0000
1746+++ src/ui_basic/button.cc 2011-01-31 17:56:23 +0000
1747@@ -21,6 +21,7 @@
1748
1749 #include "mouse_constants.h"
1750
1751+#include "graphic/font.h"
1752 #include "graphic/font_handler.h"
1753 #include "graphic/picture.h"
1754 #include "graphic/rendertarget.h"
1755@@ -37,26 +38,23 @@
1756 PictureID background_picture_id,
1757 std::string const & title_text,
1758 std::string const & tooltip_text,
1759- bool const _enabled, bool const flat,
1760- std::string const & fontname,
1761- uint32_t const fontsize)
1762+ bool const _enabled, bool const flat)
1763 :
1764- NamedPanel (parent, name, x, y, w, h, tooltip_text),
1765- m_highlighted (false),
1766- m_pressed (false),
1767- m_permpressed (false),
1768- m_enabled (_enabled),
1769- m_repeating (false),
1770- m_flat (flat),
1771+ NamedPanel (parent, name, x, y, w, h, tooltip_text),
1772+ m_highlighted (false),
1773+ m_pressed (false),
1774+ m_permpressed (false),
1775+ m_enabled (_enabled),
1776+ m_repeating (false),
1777+ m_flat (flat),
1778 m_draw_flat_background(false),
1779- m_title (title_text),
1780- m_pic_background (background_picture_id),
1781- m_pic_custom (g_gr->get_no_picture()),
1782- m_pic_custom_disabled (g_gr->get_no_picture()),
1783- m_fontname (fontname),
1784- m_fontsize (fontsize),
1785- m_clr_down (229, 161, 2),
1786- m_draw_caret (false)
1787+ m_title (title_text),
1788+ m_pic_background(background_picture_id),
1789+ m_pic_custom (g_gr->get_no_picture()),
1790+ m_pic_custom_disabled(g_gr->get_no_picture()),
1791+ m_font(UI::Font::ui_small()),
1792+ m_clr_down (229, 161, 2),
1793+ m_draw_caret (false)
1794 {
1795 set_think(false);
1796
1797@@ -72,25 +70,22 @@
1798 PictureID background_picture_id,
1799 const PictureID foreground_picture_id,
1800 const std::string & tooltip_text,
1801- bool const _enabled, bool const flat,
1802- const std::string & fontname,
1803- const uint32_t fontsize)
1804+ bool const _enabled, bool const flat)
1805 :
1806- NamedPanel (parent, name, x, y, w, h, tooltip_text),
1807- m_highlighted (false),
1808- m_pressed (false),
1809- m_permpressed (false),
1810- m_enabled (_enabled),
1811- m_repeating (false),
1812- m_flat (flat),
1813+ NamedPanel (parent, name, x, y, w, h, tooltip_text),
1814+ m_highlighted (false),
1815+ m_pressed (false),
1816+ m_permpressed (false),
1817+ m_enabled (_enabled),
1818+ m_repeating (false),
1819+ m_flat (flat),
1820 m_draw_flat_background(false),
1821- m_pic_background (background_picture_id),
1822- m_pic_custom (foreground_picture_id),
1823- m_pic_custom_disabled (g_gr->create_grayed_out_pic(foreground_picture_id)),
1824- m_fontname (fontname),
1825- m_fontsize (fontsize),
1826- m_clr_down (229, 161, 2),
1827- m_draw_caret (false)
1828+ m_pic_background(background_picture_id),
1829+ m_pic_custom (foreground_picture_id),
1830+ m_pic_custom_disabled(g_gr->create_grayed_out_pic(foreground_picture_id)),
1831+ m_font(UI::Font::ui_small()),
1832+ m_clr_down (229, 161, 2),
1833+ m_draw_caret (false)
1834 {
1835 set_think(false);
1836
1837@@ -189,20 +184,17 @@
1838 (get_h() - static_cast<int32_t>(cph)) >> 1),
1839 m_enabled ? m_pic_custom : m_pic_custom_disabled);
1840
1841- } else if (m_title.length()) // otherwise draw title string centered
1842- UI::g_fh->draw_string
1843- (dst,
1844- m_fontname,
1845- m_fontsize,
1846- m_enabled ? UI_FONT_CLR_FG : UI_FONT_CLR_DISABLED, UI_FONT_CLR_BG,
1847- Point(get_w() >> 1, get_h() >> 1),
1848- m_title,
1849- Align_Center,
1850- std::numeric_limits<uint32_t>::max(),
1851- Widget_Cache_None,
1852- 0,
1853- m_draw_caret ? m_title.length() :
1854- std::numeric_limits<uint32_t>::max());
1855+ } else if (m_title.length()) {
1856+ // otherwise draw title string centered
1857+ UI::TextStyle ts;
1858+ ts.font = m_font;
1859+ ts.bold = true;
1860+ ts.fg = m_enabled ? UI_FONT_CLR_FG : UI_FONT_CLR_DISABLED;
1861+ UI::g_fh->draw_text
1862+ (dst, ts, Point(get_w() / 2, get_h() / 2),
1863+ m_title, Align_Center,
1864+ m_draw_caret ? m_title.length() : std::numeric_limits<uint32_t>::max());
1865+ }
1866
1867 // draw border
1868 // a pressed but not highlighted button occurs when the user has pressed
1869
1870=== modified file 'src/ui_basic/button.h'
1871--- src/ui_basic/button.h 2010-12-30 17:01:47 +0000
1872+++ src/ui_basic/button.h 2011-01-31 17:56:23 +0000
1873@@ -31,6 +31,8 @@
1874
1875 namespace UI {
1876
1877+struct Font;
1878+
1879 /// This is simply a button. Override void clicked() to react to the click.
1880 /// This is all that is needed in most cases, but if there is a need to give a
1881 /// callback function to the button, there are some templates for that below.
1882@@ -43,9 +45,7 @@
1883 std::string const & title_text,
1884 std::string const & tooltip_text = std::string(),
1885 bool const _enabled = true,
1886- bool const flat = false,
1887- std::string const & fontname = UI_FONT_NAME,
1888- uint32_t const fontsize = UI_FONT_SIZE_SMALL);
1889+ bool const flat = false);
1890 Button /// for pictorial buttons
1891 (Panel * const parent,
1892 std::string const & name,
1893@@ -54,9 +54,7 @@
1894 const PictureID foreground_picture_id,
1895 std::string const & tooltip_text = std::string(),
1896 bool const _enabled = true,
1897- bool const flat = false,
1898- const std::string & fontname = UI_FONT_NAME,
1899- const uint32_t fontsize = UI_FONT_SIZE_SMALL);
1900+ bool const flat = false);
1901 ~Button();
1902
1903 void set_pic(PictureID picid);
1904@@ -67,10 +65,7 @@
1905 void set_enabled(bool on);
1906 void set_repeating(bool const on) {m_repeating = on;}
1907 void set_draw_caret(bool draw_caret) {m_draw_caret = draw_caret;}
1908- void set_font(std::string const & name, int32_t size) {
1909- m_fontname = name;
1910- m_fontsize = size;
1911- }
1912+ void set_font(Font * font) {m_font = font;}
1913 bool is_snap_target() const {return true;}
1914
1915 // Drawing and event handlers
1916@@ -108,8 +103,7 @@
1917 PictureID m_pic_background; // background texture (picture ID)
1918 PictureID m_pic_custom; // custom icon on the button
1919 PictureID m_pic_custom_disabled;
1920- std::string m_fontname;
1921- uint32_t m_fontsize;
1922+ Font * m_font;
1923
1924 RGBColor m_clr_down; // color of border while a flat button is "down"
1925 bool m_draw_caret;
1926@@ -127,9 +121,7 @@
1927 const std::string & title_text,
1928 std::string const & tooltip_text = std::string(),
1929 bool const _enabled = true,
1930- bool const flat = false,
1931- const std::string & fontname = UI_FONT_NAME,
1932- const uint32_t fontsize = UI_FONT_SIZE_SMALL)
1933+ bool const flat = false)
1934 :
1935 Button
1936 (parent, name,
1937@@ -137,9 +129,7 @@
1938 background_pictute_id,
1939 title_text,
1940 tooltip_text,
1941- _enabled, flat,
1942- fontname,
1943- fontsize),
1944+ _enabled, flat),
1945 _callback_function (callback_function)
1946 {}
1947 Callback_Button /// for pictorial buttons
1948@@ -151,9 +141,7 @@
1949 boost::function<void()> callback_function,
1950 std::string const & tooltip_text = std::string(),
1951 bool const _enabled = true,
1952- bool const flat = false,
1953- const std::string & fontname = UI_FONT_NAME,
1954- const uint32_t fontsize = UI_FONT_SIZE_SMALL)
1955+ bool const flat = false)
1956 :
1957 Button
1958 (parent, name,
1959@@ -161,9 +149,7 @@
1960 background_pictute_id,
1961 foreground_picture_id,
1962 tooltip_text,
1963- _enabled, flat,
1964- fontname,
1965- fontsize),
1966+ _enabled, flat),
1967 _callback_function (callback_function)
1968 {}
1969
1970
1971=== modified file 'src/ui_basic/editbox.cc'
1972--- src/ui_basic/editbox.cc 2010-11-27 13:30:37 +0000
1973+++ src/ui_basic/editbox.cc 2011-01-31 17:56:23 +0000
1974@@ -21,6 +21,7 @@
1975
1976 #include "mouse_constants.h"
1977
1978+#include "graphic/font.h"
1979 #include "graphic/font_handler.h"
1980 #include "graphic/rendertarget.h"
1981 #include "helper.h"
1982@@ -393,17 +394,13 @@
1983
1984 pos.x += m->scrolloffset;
1985
1986- UI::g_fh->draw_string
1987+ UI::g_fh->draw_text
1988 (dst,
1989- m->fontname, m->fontsize, m->fontcolor, UI_FONT_CLR_BG,
1990+ TextStyle::makebold(Font::get(m->fontname, m->fontsize), m->fontcolor),
1991 pos,
1992 m->text,
1993 align(),
1994- std::numeric_limits<uint32_t>::max(),
1995- Widget_Cache_None,
1996- 0,
1997- has_focus() ? static_cast<int32_t>(m->caret) :
1998- std::numeric_limits<uint32_t>::max());
1999+ has_focus() ? static_cast<int32_t>(m->caret) : std::numeric_limits<uint32_t>::max());
2000 }
2001
2002 /**
2003
2004=== modified file 'src/ui_basic/helpwindow.cc'
2005--- src/ui_basic/helpwindow.cc 2010-12-20 18:17:09 +0000
2006+++ src/ui_basic/helpwindow.cc 2011-01-31 17:56:23 +0000
2007@@ -23,6 +23,7 @@
2008 #include "i18n.h"
2009 #include "window.h"
2010 #include "button.h"
2011+#include "graphic/font.h"
2012 #include "graphic/font_handler.h"
2013 #include "wlapplication.h"
2014
2015@@ -68,14 +69,14 @@
2016 set_inner_size(in_width, in_height);
2017 set_pos(Point((g_gr->get_xres() - out_width) / 2, (g_gr->get_yres() - out_height) / 2));
2018
2019- new Callback_Button
2020+ Button * btn = new Callback_Button
2021 (this, "ok",
2022 in_width / 3, in_height - but_height * 3 / 2,
2023 in_width / 3, but_height,
2024 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
2025 boost::bind(&HelpWindow::pressedOk, boost::ref(*this)),
2026- _("OK"), std::string(), true, false,
2027- UI_FONT_NAME, (fontsize < 12 ? 12 : fontsize));
2028+ _("OK"), std::string(), true, false);
2029+ btn->set_font(Font::get(UI_FONT_NAME, (fontsize < 12 ? 12 : fontsize)));
2030
2031 textarea->set_size(in_width - 10, in_height - 10 - (2 * but_height));
2032 }
2033
2034=== modified file 'src/ui_basic/listselect.cc'
2035--- src/ui_basic/listselect.cc 2010-12-03 21:42:50 +0000
2036+++ src/ui_basic/listselect.cc 2011-01-31 17:56:23 +0000
2037@@ -20,6 +20,7 @@
2038 #include "listselect.h"
2039
2040 #include "constants.h"
2041+#include "graphic/font.h"
2042 #include "graphic/font_handler.h"
2043 #include "graphic/offscreensurface.h"
2044 #include "graphic/rendertarget.h"
2045@@ -392,11 +393,9 @@
2046 const RGBColor col = er.use_clr ? er.clr : UI_FONT_CLR_FG;
2047
2048 // Horizontal center the string
2049- UI::g_fh->draw_string
2050+ UI::g_fh->draw_text
2051 (dst,
2052- m_fontname, m_fontsize,
2053- col,
2054- RGBColor(107, 87, 55),
2055+ TextStyle::makebold(Font::get(m_fontname, m_fontsize), col),
2056 Point
2057 (x,
2058 y +
2059@@ -407,7 +406,6 @@
2060 m_align);
2061
2062 // Now draw pictures
2063-
2064 if (er.picid != g_gr->get_no_picture()) {
2065 uint32_t w, h;
2066 g_gr->get_picture_size(er.picid, w, h);
2067
2068=== modified file 'src/ui_basic/multilineeditbox.cc'
2069--- src/ui_basic/multilineeditbox.cc 2010-11-27 13:30:37 +0000
2070+++ src/ui_basic/multilineeditbox.cc 2011-01-31 17:56:23 +0000
2071@@ -1,5 +1,5 @@
2072 /*
2073- * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
2074+ * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team
2075 *
2076 * This program is free software; you can redistribute it and/or
2077 * modify it under the terms of the GNU General Public License
2078@@ -23,202 +23,394 @@
2079 #include "constants.h"
2080 #include "graphic/font_handler.h"
2081 #include "graphic/rendertarget.h"
2082+#include "graphic/wordwrap.h"
2083 #include "helper.h"
2084 #include "wlapplication.h"
2085-
2086-#include <SDL_keysym.h>
2087-
2088-#include <algorithm>
2089+#include <scripting/pdep/llimits.h>
2090
2091 namespace UI {
2092+
2093+static const int32_t ms_darken_value = -20;
2094+static const int32_t ms_scrollbar_w = 24;
2095+
2096+struct Multiline_Editbox::Data {
2097+ Scrollbar scrollbar;
2098+
2099+ /// The text in the edit box
2100+ std::string text;
2101+
2102+ /// Position of the cursor inside the text.
2103+ /// 0 indicates that the cursor is before the first character,
2104+ /// text.size() inidicates that the cursor is after the last character.
2105+ uint32_t cursor_pos;
2106+
2107+ /// Font and style
2108+ TextStyle textstyle;
2109+
2110+ /// Maximum length of the text string, in bytes
2111+ uint32_t maxbytes;
2112+
2113+ /// Cached wrapping info; see @ref refresh_ww and @ref update
2114+ /*@{*/
2115+ bool ww_valid;
2116+ WordWrap ww;
2117+ /*@}*/
2118+
2119+ Data(Multiline_Editbox &);
2120+ void refresh_ww();
2121+
2122+ void update();
2123+
2124+ void scroll_cursor_into_view();
2125+ void set_cursor_pos(uint32_t cursor_pos);
2126+
2127+ uint32_t prev_char(uint32_t cursor);
2128+ uint32_t next_char(uint32_t cursor);
2129+ uint32_t snap_to_char(uint32_t cursor);
2130+
2131+ void erase_bytes(uint32_t start, uint32_t end);
2132+ void insert(uint32_t where, const std::string & s);
2133+
2134+ bool is_utf8_extended(char ch) const;
2135+ std::string unicode_to_utf8(uint16_t unicode) const;
2136+
2137+private:
2138+ Multiline_Editbox & owner;
2139+};
2140+
2141 /**
2142 * Initialize an editbox that supports multiline strings.
2143 */
2144 Multiline_Editbox::Multiline_Editbox
2145 (Panel * parent,
2146 int32_t x, int32_t y, uint32_t w, uint32_t h,
2147- const char * text)
2148+ const std::string & text)
2149 :
2150- Multiline_Textarea(parent, x, y, w, h, text, Align_Left, true),
2151- m_cur_pos (get_text().size()),
2152- m_maxchars (0xffff),
2153- m_needs_update (false)
2154+ Panel(parent, x, y, w, h),
2155+ d(new Data(*this))
2156 {
2157- set_scrollmode(ScrollNormal);
2158 set_handle_mouse(true);
2159 set_can_focus(true);
2160 set_think(false);
2161-}
2162-
2163-
2164-/**
2165- * A key event must be handled
2166-*/
2167-bool Multiline_Editbox::handle_key(bool const down, SDL_keysym const code) {
2168- m_needs_update = true;
2169-
2170+
2171+ set_text(text);
2172+}
2173+
2174+Multiline_Editbox::Data::Data(Multiline_Editbox & o)
2175+:
2176+scrollbar(&o, o.get_w() - ms_scrollbar_w, 0, ms_scrollbar_w, o.get_h(), false),
2177+cursor_pos(0),
2178+textstyle(TextStyle::ui_small()),
2179+maxbytes(0xffff),
2180+ww_valid(false),
2181+owner(o)
2182+{
2183+ scrollbar.moved.set(&o, &Multiline_Editbox::scrollpos_changed);
2184+
2185+ scrollbar.set_pagesize(owner.get_h() - 2 * textstyle.font->height());
2186+ scrollbar.set_singlestepsize(textstyle.font->height());
2187+}
2188+
2189+/**
2190+ * Call this function whenever some part of the data changes that potentially
2191+ * requires some redrawing.
2192+ */
2193+void Multiline_Editbox::Data::update()
2194+{
2195+ ww_valid = false;
2196+ owner.update();
2197+}
2198+
2199+/**
2200+ * Return the text currently stored by the editbox.
2201+ */
2202+std::string const & Multiline_Editbox::get_text() const
2203+{
2204+ return d->text;
2205+}
2206+
2207+/**
2208+ * Replace the currently stored text with something else.
2209+ */
2210+void Multiline_Editbox::set_text(const std::string & text)
2211+{
2212+ if (text == d->text)
2213+ return;
2214+
2215+ d->text = text;
2216+ while (d->text.size() > d->maxbytes)
2217+ d->erase_bytes(d->prev_char(d->text.size()), d->text.size());
2218+
2219+ if (d->cursor_pos > d->text.size())
2220+ d->cursor_pos = d->text.size();
2221+
2222+ d->update();
2223+ d->scroll_cursor_into_view();
2224+
2225+ changed.call();
2226+}
2227+
2228+/**
2229+ * Set the text style.
2230+ */
2231+void Multiline_Editbox::set_textstyle(const UI::TextStyle & ts)
2232+{
2233+ if (d->textstyle == ts)
2234+ return;
2235+
2236+ d->textstyle = ts;
2237+ d->update();
2238+
2239+}
2240+
2241+/**
2242+ * Set the maximum number of bytes in the scrollbar text.
2243+ *
2244+ * This will shorten the currently stored text when necessary.
2245+ */
2246+void Multiline_Editbox::set_maximum_bytes(const uint32_t n)
2247+{
2248+ while (n < d->text.size())
2249+ d->erase_bytes(d->prev_char(d->text.size()), d->text.size());
2250+ d->maxbytes = n;
2251+
2252+ // do not need to update here, because erase() will
2253+ // update when necessary
2254+}
2255+
2256+/**
2257+ * Return the currently set maximum number of bytes.
2258+ */
2259+uint32_t Multiline_Editbox::get_maximum_bytes() const
2260+{
2261+ return d->maxbytes;
2262+}
2263+
2264+/**
2265+ * Return @c true iff the given character is an extended byte of
2266+ * a multi-byte UTF8 character.
2267+ */
2268+bool Multiline_Editbox::Data::is_utf8_extended(char ch) const
2269+{
2270+ return (ch & 0xc0) == 0x80;
2271+}
2272+
2273+/**
2274+ * Convert a unicode character into a multi-byte utf8 string.
2275+ */
2276+std::string Multiline_Editbox::Data::unicode_to_utf8(uint16_t unicode) const
2277+{
2278+ unsigned char buf[4];
2279+
2280+ memset(buf, 0, sizeof(buf));
2281+
2282+ if (unicode < 0x80) {
2283+ buf[0] = unicode;
2284+ } else if (unicode < 0x800) {
2285+ buf[0] = ((unicode & 0x7c0) >> 6) | 0xc0;
2286+ buf[1] = (unicode & 0x3f) | 0x80;
2287+ } else {
2288+ buf[0] = ((unicode & 0xf000) >> 12) | 0xe0;
2289+ buf[1] = ((unicode & 0xfc0) >> 6) | 0x80;
2290+ buf[2] = (unicode & 0x3f) | 0x80;
2291+ }
2292+
2293+ return reinterpret_cast<char *>(buf);
2294+}
2295+
2296+/**
2297+ * Erase the given range of bytes, adjust the cursor position, and update.
2298+ */
2299+void Multiline_Editbox::Data::erase_bytes(uint32_t start, uint32_t end)
2300+{
2301+ assert(start <= end);
2302+ assert(end <= text.size());
2303+
2304+ uint32_t nbytes = end - start;
2305+ text.erase(start, nbytes);
2306+ update();
2307+
2308+ if (cursor_pos >= end)
2309+ set_cursor_pos(cursor_pos - nbytes);
2310+ else if (cursor_pos > start)
2311+ set_cursor_pos(start);
2312+}
2313+
2314+/**
2315+ * Find the starting byte of the previous character
2316+ */
2317+uint32_t Multiline_Editbox::Data::prev_char(uint32_t cursor)
2318+{
2319+ assert(cursor <= text.size());
2320+
2321+ if (cursor == 0)
2322+ return cursor;
2323+
2324+ do {
2325+ --cursor;
2326+ } while (cursor > 0 && is_utf8_extended(text[cursor]));
2327+
2328+ return cursor;
2329+}
2330+
2331+/**
2332+ * Find the starting byte of the next character
2333+ */
2334+uint32_t Multiline_Editbox::Data::next_char(uint32_t cursor)
2335+{
2336+ assert(cursor <= text.size());
2337+
2338+ if (cursor >= text.size())
2339+ return cursor;
2340+
2341+ do {
2342+ ++cursor;
2343+ } while (cursor < text.size() && is_utf8_extended(text[cursor]));
2344+
2345+ return cursor;
2346+}
2347+
2348+/**
2349+ * Return the starting offset of the (multi-byte) character that @p cursor points to.
2350+ */
2351+uint32_t Multiline_Editbox::Data::snap_to_char(uint32_t cursor)
2352+{
2353+ while (cursor > 0 && is_utf8_extended(text[cursor]))
2354+ --cursor;
2355+ return cursor;
2356+}
2357+
2358+/**
2359+ * This is called by the UI code whenever a key press or release arrives
2360+ */
2361+bool Multiline_Editbox::handle_key(bool const down, SDL_keysym const code)
2362+{
2363 if (down) {
2364- std::string txt =
2365- UI::g_fh->word_wrap_text
2366- (m_fontname, m_fontsize, get_text(), get_eff_w());
2367- assert(m_cur_pos <= txt.size());
2368 switch (code.sym) {
2369-
2370 case SDLK_DELETE:
2371- if (m_cur_pos < txt.size()) {
2372- do {
2373- ++m_cur_pos;
2374- } while
2375- (m_cur_pos < txt.size() &&
2376- ((txt.at(m_cur_pos) & 0xc0) == 0x80));
2377- // fallthrough - handle it like backspace
2378- } else
2379- break;
2380+ if (d->cursor_pos < d->text.size()) {
2381+ d->erase_bytes(d->cursor_pos, d->next_char(d->cursor_pos));
2382+ changed.call();
2383+ }
2384+ break;
2385
2386 case SDLK_BACKSPACE:
2387- if (txt.size() and m_cur_pos) {
2388- while ((txt.at(--m_cur_pos) & 0xc0) == 0x80) {
2389- txt.erase(txt.begin() + m_cur_pos);
2390- if (m_cur_pos == 0)
2391+ if (d->cursor_pos > 0) {
2392+ d->erase_bytes(d->prev_char(d->cursor_pos), d->cursor_pos);
2393+ changed.call();
2394+ }
2395+ break;
2396+
2397+ case SDLK_LEFT: {
2398+ if (code.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
2399+ uint32_t newpos = d->prev_char(d->cursor_pos);
2400+ while (newpos > 0 && isspace(d->text[newpos]))
2401+ newpos = d->prev_char(newpos);
2402+ while (newpos > 0) {
2403+ uint32_t prev = d->prev_char(newpos);
2404+ if (isspace(d->text[prev]))
2405 break;
2406+ newpos = prev;
2407 }
2408- txt.erase(txt.begin() + m_cur_pos);
2409- set_text(txt.c_str());
2410- }
2411- break;
2412-
2413- case SDLK_LEFT:
2414- if (0 < m_cur_pos) {
2415- while ((txt.at(--m_cur_pos) & 0xc0) == 0x80) {};
2416- if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
2417- for (uint32_t new_cur_pos = m_cur_pos;; m_cur_pos = new_cur_pos)
2418- if (0 == new_cur_pos or isspace(txt.at(--new_cur_pos)))
2419- break;
2420- }
2421- break;
2422+ d->set_cursor_pos(newpos);
2423+ } else {
2424+ d->set_cursor_pos(d->prev_char(d->cursor_pos));
2425+ }
2426+ break;
2427+ }
2428
2429 case SDLK_RIGHT:
2430- if (m_cur_pos < txt.size()) {
2431- do {
2432- ++m_cur_pos;
2433- if (m_cur_pos >= txt.size()) {
2434- break;
2435- }
2436-
2437- } while ((txt.at(m_cur_pos) & 0xc0) == 0x80);
2438-
2439- if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
2440- for (uint32_t new_cur_pos = m_cur_pos;; ++new_cur_pos) {
2441- assert ((new_cur_pos - 1) < txt.size());
2442- if
2443- (new_cur_pos == txt.size()
2444- or
2445- isspace(txt.at(new_cur_pos - 1)))
2446- {
2447- m_cur_pos = new_cur_pos;
2448- break;
2449- }
2450- }
2451+ if (code.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
2452+ uint32_t newpos = d->next_char(d->cursor_pos);
2453+ while (newpos < d->text.size() && isspace(d->text[newpos]))
2454+ newpos = d->next_char(newpos);
2455+ while (newpos < d->text.size() && !isspace(d->text[newpos]))
2456+ newpos = d->next_char(newpos);
2457+ d->set_cursor_pos(newpos);
2458+ } else {
2459+ d->set_cursor_pos(d->next_char(d->cursor_pos));
2460 }
2461 break;
2462
2463 case SDLK_DOWN:
2464- if (m_cur_pos < txt.size()) {
2465- uint32_t begin_of_line = m_cur_pos;
2466-
2467- assert(begin_of_line < txt.size());
2468- if (txt.at(begin_of_line) == '\n')
2469- --begin_of_line;
2470- while (begin_of_line > 0 && txt.at(begin_of_line) != '\n')
2471- --begin_of_line;
2472- if (begin_of_line)
2473- ++begin_of_line;
2474- uint32_t begin_of_next_line = m_cur_pos;
2475- while
2476- (begin_of_next_line < txt.size()
2477- &&
2478- txt.at(begin_of_next_line) != '\n')
2479- ++begin_of_next_line;
2480- begin_of_next_line += begin_of_next_line == txt.size() ? -1 : 1;
2481- uint32_t end_of_next_line = begin_of_next_line;
2482- while
2483- (end_of_next_line < txt.size() &&
2484- txt.at(end_of_next_line) != '\n')
2485- ++end_of_next_line;
2486- m_cur_pos =
2487- begin_of_next_line + m_cur_pos - begin_of_line
2488- >
2489- end_of_next_line ? end_of_next_line :
2490- begin_of_next_line + m_cur_pos - begin_of_line;
2491- // Care about unicode letters
2492- while (m_cur_pos < txt.size() && (txt.at(m_cur_pos) & 0xc0) == 0x80)
2493- ++m_cur_pos;
2494+ if (d->cursor_pos < d->text.size()) {
2495+ d->refresh_ww();
2496+
2497+ uint32_t cursorline, cursorpos;
2498+ d->ww.calc_wrapped_pos(d->cursor_pos, cursorline, cursorpos);
2499+
2500+ if (cursorline + 1 < d->ww.nrlines()) {
2501+ uint32_t lineend = d->text.size();
2502+ if (cursorline + 2 < d->ww.nrlines())
2503+ lineend = d->prev_char(d->ww.line_offset(cursorline + 2));
2504+
2505+ uint32_t newpos = d->ww.line_offset(cursorline + 1) + cursorpos;
2506+ if (newpos > lineend)
2507+ newpos = lineend;
2508+ else
2509+ newpos = d->snap_to_char(newpos);
2510+ d->set_cursor_pos(newpos);
2511+ } else {
2512+ d->set_cursor_pos(d->text.size());
2513+ }
2514 }
2515 break;
2516
2517 case SDLK_UP:
2518- if (m_cur_pos > 0) {
2519- uint32_t begin_of_line = m_cur_pos;
2520-
2521- if (begin_of_line >= txt.size()) {
2522- begin_of_line = txt.size() - 1;
2523+ if (d->cursor_pos > 0) {
2524+ d->refresh_ww();
2525+
2526+ uint32_t cursorline, cursorpos;
2527+ d->ww.calc_wrapped_pos(d->cursor_pos, cursorline, cursorpos);
2528+
2529+ if (cursorline > 0) {
2530+ uint32_t newpos = d->ww.line_offset(cursorline-1) + cursorpos;
2531+ uint32_t lineend = d->prev_char(d->ww.line_offset(cursorline));
2532+
2533+ if (newpos > lineend)
2534+ newpos = lineend;
2535+ else
2536+ newpos = d->snap_to_char(newpos);
2537+ d->set_cursor_pos(newpos);
2538+ } else {
2539+ d->set_cursor_pos(0);
2540 }
2541- assert (begin_of_line < txt.size());
2542- if (txt.at(begin_of_line) == '\n')
2543- --begin_of_line;
2544- while (begin_of_line > 0 && txt.at(begin_of_line) != '\n')
2545- --begin_of_line;
2546- if (begin_of_line)
2547- ++begin_of_line;
2548- uint32_t end_of_last_line = begin_of_line;
2549- if (begin_of_line)
2550- --end_of_last_line;
2551- uint32_t begin_of_lastline = end_of_last_line;
2552- assert(begin_of_lastline < txt.size());
2553- if (begin_of_lastline > 0 && txt.at(begin_of_lastline) == '\n')
2554- --begin_of_lastline;
2555- while (begin_of_lastline > 0 && txt.at(begin_of_lastline) != '\n')
2556- --begin_of_lastline;
2557- if (begin_of_lastline)
2558- ++begin_of_lastline;
2559- m_cur_pos =
2560- begin_of_lastline + (m_cur_pos - begin_of_line)
2561- >
2562- end_of_last_line ? end_of_last_line :
2563- begin_of_lastline + (m_cur_pos - begin_of_line);
2564- // Care about unicode letters
2565- while (m_cur_pos < txt.size() && (txt.at(m_cur_pos) & 0xc0) == 0x80)
2566- ++m_cur_pos;
2567 }
2568 break;
2569
2570 case SDLK_HOME:
2571- if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
2572- m_cur_pos = 0;
2573- else
2574- while (0 < m_cur_pos) {
2575- uint32_t const preceding_cur_pos = m_cur_pos - 1;
2576- if (txt.at(preceding_cur_pos) == '\n')
2577- break;
2578- else
2579- m_cur_pos = preceding_cur_pos;
2580- }
2581+ if (code.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
2582+ d->set_cursor_pos(0);
2583+ } else {
2584+ d->refresh_ww();
2585+
2586+ uint32_t cursorline, cursorpos;
2587+ d->ww.calc_wrapped_pos(d->cursor_pos, cursorline, cursorpos);
2588+
2589+ d->set_cursor_pos(d->ww.line_offset(cursorline));
2590+ }
2591 break;
2592
2593 case SDLK_END:
2594- if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
2595- m_cur_pos = txt.size();
2596- else
2597- while (m_cur_pos < txt.size() and txt.at(m_cur_pos) != '\n')
2598- ++m_cur_pos;
2599+ if (code.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
2600+ d->set_cursor_pos(d->text.size());
2601+ } else {
2602+ d->refresh_ww();
2603+
2604+ uint32_t cursorline, cursorpos;
2605+ d->ww.calc_wrapped_pos(d->cursor_pos, cursorline, cursorpos);
2606+
2607+ if (cursorline + 1 < d->ww.nrlines())
2608+ d->set_cursor_pos(d->prev_char(d->ww.line_offset(cursorline + 1)));
2609+ else
2610+ d->set_cursor_pos(d->text.size());
2611+ }
2612 break;
2613
2614 case SDLK_RETURN:
2615 case SDLK_KP_ENTER:
2616- if (txt.size() < m_maxchars) {
2617- txt.insert(txt.begin() + m_cur_pos++, 1, '\n');
2618- set_text(txt.c_str());
2619- }
2620+ d->insert(d->cursor_pos, "\n");
2621+ changed.call();
2622 break;
2623
2624 default:
2625@@ -226,33 +418,16 @@
2626 // example ~ + o results in a o with a tilde over it. The ~ is reported
2627 // as a 0 on keystroke, the o then as the unicode character. We simply
2628 // ignore the 0.
2629- if (is_printable(code) and code.unicode and txt.size() < m_maxchars) {
2630- if (code.unicode < 0x80) // 1 byte char
2631- txt.insert(txt.begin() + m_cur_pos++, 1, code.unicode);
2632- else if (code.unicode < 0x800) { // 2 byte char
2633- txt.insert
2634- (txt.begin() + m_cur_pos++,
2635- (((code.unicode & 0x7c0) >> 6) | 0xc0));
2636- txt.insert
2637- (txt.begin() + m_cur_pos++,
2638- ((code.unicode & 0x3f) | 0x80));
2639- } else { // 3 byte char
2640- txt.insert
2641- (txt.begin() + m_cur_pos++,
2642- (((code.unicode & 0xf000) >> 12) | 0xe0));
2643- txt.insert
2644- (txt.begin() + m_cur_pos++,
2645- (((code.unicode & 0xfc0) >> 6) | 0x80));
2646- txt.insert
2647- (txt.begin() + m_cur_pos++,
2648- ((code.unicode & 0x3f) | 0x80));
2649+ if (is_printable(code) and code.unicode) {
2650+ std::string utf8 = d->unicode_to_utf8(code.unicode);
2651+
2652+ if (d->text.size() + utf8.size() <= d->maxbytes) {
2653+ d->insert(d->cursor_pos, utf8);
2654+ changed.call();
2655 }
2656 }
2657- set_text(txt.c_str());
2658 break;
2659 }
2660- set_text(txt.c_str());
2661- changed.call();
2662 return true;
2663 }
2664
2665@@ -267,11 +442,9 @@
2666 {
2667 if (btn == SDL_BUTTON_LEFT and not has_focus()) {
2668 focus();
2669- Multiline_Textarea::set_text(get_text().c_str());
2670- changed.call();
2671 return true;
2672 }
2673- return Multiline_Textarea::handle_mousepress(btn, x, y);
2674+ return Panel::handle_mousepress(btn, x, y);
2675 }
2676 bool Multiline_Editbox::handle_mouserelease(const Uint8, int32_t, int32_t)
2677 {
2678@@ -280,75 +453,100 @@
2679
2680 /**
2681 * Redraw the Editbox
2682-*/
2683+ */
2684 void Multiline_Editbox::draw(RenderTarget & dst)
2685 {
2686 // make the whole area a bit darker
2687 dst.brighten_rect(Rect(Point(0, 0), get_w(), get_h()), ms_darken_value);
2688- if (get_text().size()) {
2689- UI::g_fh->draw_string
2690- (dst,
2691- m_fontname,
2692- m_fontsize,
2693- m_fcolor,
2694- RGBColor(107, 87, 55),
2695- Point(get_halign(), 0 - m_textpos),
2696- get_text(),
2697- m_align,
2698- get_eff_w(),
2699- m_cache_mode,
2700- &m_cache_id,
2701- // explicit cast is necessary to avoid a compiler warning
2702- has_focus() ? static_cast<int32_t>(m_cur_pos) :
2703- std::numeric_limits<uint32_t>::max());
2704- draw_scrollbar();
2705-
2706- uint32_t w; // just to run g_fh->get_size_from_cache
2707- UI::g_fh->get_size_from_cache(m_cache_id, w, m_textheight);
2708-
2709- m_cache_mode = Widget_Cache_Use;
2710- }
2711-}
2712-
2713-/**
2714- * Set text function needs to take care of the current
2715- * position
2716- */
2717-void Multiline_Editbox::set_text(char const * const str)
2718-{
2719- CalcLinePos();
2720-
2721- Multiline_Textarea::set_text(str);
2722-}
2723-
2724-/**
2725- * Calculate the height position of the cursor and write it to m_textpos
2726- * so the scrollbar can follow the cursor.
2727- */
2728-void Multiline_Editbox::CalcLinePos()
2729-{
2730- if (m_textheight < static_cast<uint32_t>(get_h())) {
2731- m_textpos = 0;
2732- return;
2733- }
2734-
2735- std::string const & str = get_text().c_str();
2736- size_t leng = str.size();
2737- uint32_t lbtt = 0; // linebreaks to top
2738- uint32_t lbtb = 0; // linebreaks to bottom
2739-
2740- for
2741- (size_t i = 0;
2742- i < std::min(m_cur_pos, static_cast<uint32_t>(str.size() - 1));
2743- ++i)
2744- if (str.at(i) == '\n')
2745- ++lbtt;
2746- for (size_t i = m_cur_pos; i < leng; ++i)
2747- if (str.at(i) == '\n')
2748- ++lbtb;
2749-
2750- m_textpos = (lbtt == 0) & (lbtb == 0) ?
2751- 0 : (m_textheight - get_h()) * lbtt / (lbtb + lbtt);
2752-}
2753-
2754-}
2755+
2756+ d->refresh_ww();
2757+
2758+ d->ww.draw
2759+ (dst, Point(0, -int32_t(d->scrollbar.get_scrollpos())), Align_Left,
2760+ has_focus() ? d->cursor_pos : std::numeric_limits<uint32_t>::max());
2761+}
2762+
2763+/**
2764+ * Insert the given string starting at cursor position @p where.
2765+ * Update the cursor so that it stays in the same place, but note that the cursor is "right-magnetic":
2766+ * If @p where is equal to the current cursor position, then the cursor is moved.
2767+ * This is usually what one wants.
2768+ */
2769+void Multiline_Editbox::Data::insert(uint32_t where, const std::string & s)
2770+{
2771+ text.insert(where, s);
2772+ update();
2773+
2774+ if (cursor_pos >= where)
2775+ set_cursor_pos(cursor_pos + s.size());
2776+}
2777+
2778+/**
2779+ * Change the position of the cursor, cause a display refresh and scroll the cursor
2780+ * into view when necessary.
2781+ */
2782+void Multiline_Editbox::Data::set_cursor_pos(uint32_t newpos)
2783+{
2784+ assert(newpos <= text.size());
2785+
2786+ if (cursor_pos == newpos)
2787+ return;
2788+
2789+ cursor_pos = newpos;
2790+ owner.update();
2791+
2792+ scroll_cursor_into_view();
2793+}
2794+
2795+/**
2796+ * Ensure that the cursor is visible.
2797+ */
2798+void Multiline_Editbox::Data::scroll_cursor_into_view()
2799+{
2800+ refresh_ww();
2801+
2802+ uint32_t cursorline, cursorpos;
2803+ ww.calc_wrapped_pos(cursor_pos, cursorline, cursorpos);
2804+
2805+ int32_t lineheight = textstyle.font->height();
2806+ int32_t lineskip = textstyle.font->lineskip();
2807+ int32_t top = cursorline * lineskip;
2808+
2809+ if (top < int32_t(scrollbar.get_scrollpos())) {
2810+ scrollbar.set_scrollpos(top - lineheight);
2811+ owner.update();
2812+ } else if (top + lineheight > int32_t(scrollbar.get_scrollpos()) + owner.get_h()) {
2813+ scrollbar.set_scrollpos(top - owner.get_h() + 2 * lineheight);
2814+ owner.update();
2815+ }
2816+}
2817+
2818+/**
2819+ * Callback function called by the scrollbar.
2820+ */
2821+void Multiline_Editbox::scrollpos_changed(int32_t)
2822+{
2823+ update();
2824+}
2825+
2826+/**
2827+ * Re-wrap the string and update the scrollbar range accordingly.
2828+ */
2829+void Multiline_Editbox::Data::refresh_ww()
2830+{
2831+ if (int32_t(ww.wrapwidth()) != owner.get_w() - ms_scrollbar_w)
2832+ ww_valid = false;
2833+ if (ww_valid)
2834+ return;
2835+
2836+ ww.set_style(textstyle);
2837+ ww.set_wrapwidth(owner.get_w() - ms_scrollbar_w);
2838+
2839+ ww.wrap(text);
2840+ ww_valid = true;
2841+
2842+ int32_t textheight = ww.height();
2843+ scrollbar.set_steps(textheight - owner.get_h());
2844+}
2845+
2846+} // namespace UI
2847
2848=== modified file 'src/ui_basic/multilineeditbox.h'
2849--- src/ui_basic/multilineeditbox.h 2009-09-30 18:31:29 +0000
2850+++ src/ui_basic/multilineeditbox.h 2011-01-31 17:56:23 +0000
2851@@ -1,5 +1,5 @@
2852 /*
2853- * Copyright (C) 2002, 2006, 2008-2009 by Widelands Development Team
2854+ * Copyright (C) 2002, 2006, 2008-2011 by Widelands Development Team
2855 *
2856 * This program is free software; you can redistribute it and/or
2857 * modify it under the terms of the GNU General Public License
2858@@ -20,41 +20,44 @@
2859 #ifndef UI_MULTILINEEDITBOX_H
2860 #define UI_MULTILINEEDITBOX_H
2861
2862-#include "multilinetextarea.h"
2863+#include "panel.h"
2864 #include "m_signal.h"
2865
2866+#include <boost/scoped_ptr.hpp>
2867+
2868 namespace UI {
2869-struct Scrollbar;
2870+
2871+struct TextStyle;
2872
2873 /**
2874- * This behaves like an editbox, but looks like
2875- * a multiline textarea
2876- *
2877- * Shift + del or Shift + backspace deletes all text
2878+ * A panel that allows entering multi-line string, i.e. like a hybrid between
2879+ * @ref Editbox and @ref Multiline_Textarea
2880 */
2881-struct Multiline_Editbox : public Multiline_Textarea {
2882+struct Multiline_Editbox : public Panel {
2883 Multiline_Editbox
2884- (Panel *, int32_t x, int32_t y, uint32_t w, uint32_t h, char const *);
2885+ (Panel *, int32_t x, int32_t y, uint32_t w, uint32_t h, const std::string & text);
2886
2887 Signal changed;
2888
2889+ std::string const & get_text() const;
2890+ void set_text(std::string const &);
2891+ void set_textstyle(const TextStyle &);
2892+
2893+ void set_maximum_bytes(uint32_t n);
2894+ uint32_t get_maximum_bytes() const;
2895+
2896+protected:
2897 void draw(RenderTarget &);
2898- void set_maximum_chars(int32_t const n) {m_maxchars = n;}
2899- int32_t get_maximum_chars() {return m_maxchars;}
2900
2901 bool handle_mousepress (Uint8 btn, int32_t x, int32_t y);
2902 bool handle_mouserelease(Uint8 btn, int32_t x, int32_t y);
2903 bool handle_key(bool down, SDL_keysym);
2904- void set_text(char const *);
2905
2906 private:
2907- void CalcLinePos();
2908- static const int32_t ms_darken_value = -20;
2909- uint32_t m_cur_pos;
2910- uint32_t m_char_pos;
2911- uint32_t m_line_pos;
2912- uint32_t m_maxchars;
2913- bool m_needs_update;
2914+ void scrollpos_changed(int32_t);
2915+
2916+ struct Data;
2917+ boost::scoped_ptr<Data> d;
2918 };
2919
2920 }
2921
2922=== modified file 'src/ui_basic/multilinetextarea.h'
2923--- src/ui_basic/multilinetextarea.h 2010-09-25 08:11:16 +0000
2924+++ src/ui_basic/multilinetextarea.h 2011-01-31 17:56:23 +0000
2925@@ -31,10 +31,6 @@
2926 /**
2927 * This defines an area, where a text can easily be printed.
2928 * The textarea transparently handles explicit line-breaks and word wrapping.
2929- *
2930- * Do not use it blindly for big texts: the font handler needs to re-break the
2931- * entire text whenever the textarea is drawn, this is a trade-off which greatly
2932- * simplifies this class.
2933 */
2934 struct Multiline_Textarea : public Panel {
2935 enum ScrollMode {
2936
2937=== modified file 'src/ui_basic/panel.cc'
2938--- src/ui_basic/panel.cc 2010-12-03 21:41:49 +0000
2939+++ src/ui_basic/panel.cc 2011-01-31 17:56:23 +0000
2940@@ -1,5 +1,5 @@
2941 /*
2942- * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
2943+ * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team
2944 *
2945 * This program is free software; you can redistribute it and/or
2946 * modify it under the terms of the GNU General Public License
2947@@ -23,10 +23,12 @@
2948 #include "graphic/font_handler.h"
2949 #include "graphic/offscreensurface.h"
2950 #include "graphic/rendertarget.h"
2951+#include "graphic/wordwrap.h"
2952 #include "log.h"
2953 #include "profile/profile.h"
2954 #include "sound/sound_handler.h"
2955 #include "wlapplication.h"
2956+#include <boost/concept_check.hpp>
2957
2958 namespace UI {
2959
2960@@ -1089,39 +1091,38 @@
2961 /**
2962 * Draw the tooltip.
2963 */
2964-void Panel::draw_tooltip(RenderTarget & dst, char const * const text)
2965+void Panel::draw_tooltip(RenderTarget & dst, const std::string & text)
2966 {
2967-#define TIP_WIDTH_MAX 360
2968- uint32_t tip_width, tip_height;
2969- UI::g_fh->get_size
2970- (UI_FONT_TOOLTIP, text, tip_width, tip_height, TIP_WIDTH_MAX);
2971- tip_width += 4;
2972- tip_height += 4;
2973+ static const uint32_t TIP_WIDTH_MAX = 360;
2974+ static TextStyle tooltip_style;
2975+ if (!tooltip_style.font) {
2976+ tooltip_style.font = Font::get(UI_FONT_TOOLTIP);
2977+ tooltip_style.fg = UI_FONT_TOOLTIP_CLR;
2978+ tooltip_style.bold = true;
2979+ }
2980+
2981+ WordWrap ww(tooltip_style, TIP_WIDTH_MAX);
2982+
2983+ ww.wrap(text);
2984+
2985+ uint32_t tip_width = ww.width() + 4;
2986+ uint32_t tip_height = ww.height() + 4;
2987+
2988 const WLApplication & wlapplication = *WLApplication::get();
2989 Rect r
2990 (wlapplication.get_mouse_position() + Point(2, 32),
2991 tip_width, tip_height);
2992- const Point tooltip_bottom_left = r.bottom_left();
2993- const Point screen_bottom_left(g_gr->get_xres(), g_gr->get_yres());
2994- if (screen_bottom_left.x < tooltip_bottom_left.x)
2995+ const Point tooltip_bottom_right = r.bottom_right();
2996+ const Point screen_bottom_right(g_gr->get_xres(), g_gr->get_yres());
2997+ if (screen_bottom_right.x < tooltip_bottom_right.x)
2998 r.x -= 4 + r.w;
2999- if (screen_bottom_left.y < tooltip_bottom_left.y)
3000+ if (screen_bottom_right.y < tooltip_bottom_right.y)
3001 r.y -= 35 + r.h;
3002
3003- dst.fill_rect(r, RGBColor(230, 200, 50));
3004+ dst.fill_rect(r, RGBColor(63, 52, 34));
3005 dst.draw_rect(r, RGBColor(0, 0, 0));
3006- UI::g_fh->draw_string
3007- (dst,
3008- UI_FONT_TOOLTIP,
3009- UI_FONT_TOOLTIP_CLR,
3010- r + Point(2, 2),
3011- text,
3012- Align_Left,
3013- TIP_WIDTH_MAX,
3014- Widget_Cache_None,
3015- 0,
3016- std::numeric_limits<uint32_t>::max(),
3017- false);
3018+
3019+ ww.draw(dst, r + Point(2, 2));
3020 }
3021
3022 std::string Panel::ui_fn() {
3023
3024=== modified file 'src/ui_basic/panel.h'
3025--- src/ui_basic/panel.h 2010-12-03 21:41:49 +0000
3026+++ src/ui_basic/panel.h 2011-01-31 17:56:23 +0000
3027@@ -282,7 +282,7 @@
3028 char * _tooltip;
3029
3030 protected:
3031- static void draw_tooltip(RenderTarget &, char const * const text);
3032+ static void draw_tooltip(RenderTarget &, const std::string & text);
3033
3034 public:
3035 void set_tooltip(const char * const);
3036
3037=== modified file 'src/ui_basic/progressbar.cc'
3038--- src/ui_basic/progressbar.cc 2010-05-12 10:16:44 +0000
3039+++ src/ui_basic/progressbar.cc 2011-01-31 17:56:23 +0000
3040@@ -20,6 +20,7 @@
3041 #include "progressbar.h"
3042
3043 #include "constants.h"
3044+#include "graphic/font.h"
3045 #include "graphic/font_handler.h"
3046 #include "graphic/rendertarget.h"
3047
3048@@ -107,9 +108,8 @@
3049 snprintf
3050 (buffer, sizeof(buffer), "%u%%", static_cast<uint32_t>(fraction * 100));
3051
3052- UI::g_fh->draw_string
3053- (dst,
3054- UI_FONT_SMALL, UI_FONT_SMALL_CLR,
3055+ UI::g_fh->draw_text
3056+ (dst, UI::TextStyle::ui_small(),
3057 Point(get_w() / 2, get_h() / 2),
3058 buffer,
3059 Align_Center);
3060
3061=== modified file 'src/ui_basic/progresswindow.cc'
3062--- src/ui_basic/progresswindow.cc 2010-11-27 13:51:57 +0000
3063+++ src/ui_basic/progresswindow.cc 2011-01-31 17:56:23 +0000
3064@@ -20,6 +20,7 @@
3065 #include "progresswindow.h"
3066
3067 #include "constants.h"
3068+#include "graphic/font.h"
3069 #include "graphic/font_handler.h"
3070 #include "graphic/rendertarget.h"
3071 #include "i18n.h"
3072@@ -143,9 +144,10 @@
3073 draw_background(rt, xres, yres);
3074
3075 rt.fill_rect(m_label_rectangle, PROGRESS_FONT_COLOR_BG);
3076- UI::g_fh->draw_string
3077- (rt, UI_FONT_SMALL, PROGRESS_FONT_COLOR,
3078- m_label_center, description, Align_Center);
3079+
3080+ UI::TextStyle ts(UI::TextStyle::ui_small());
3081+ ts.fg = PROGRESS_FONT_COLOR_FG;
3082+ UI::g_fh->draw_text(rt, ts, m_label_center, description, Align_Center);
3083 g_gr->update_rectangle(m_label_rectangle);
3084
3085 update(true);
3086
3087=== modified file 'src/ui_basic/spinbox.cc'
3088--- src/ui_basic/spinbox.cc 2010-11-01 23:54:06 +0000
3089+++ src/ui_basic/spinbox.cc 2011-01-31 17:56:23 +0000
3090@@ -57,11 +57,6 @@
3091 /// Special names for specific Values
3092 std::vector<IntValueTextReplacement> valrep;
3093
3094- /// Font variables
3095- std::string fontname;
3096- uint32_t fontsize;
3097- RGBColor fontcolor;
3098-
3099 /// The UI parts
3100 Textarea * text;
3101 Callback_Button * butPlus;
3102@@ -97,9 +92,6 @@
3103
3104 sbi->background = background;
3105 sbi->align = alignm;
3106- sbi->fontname = UI_FONT_NAME;
3107- sbi->fontsize = UI_FONT_SIZE_SMALL;
3108- sbi->fontcolor = UI_FONT_CLR_FG;
3109
3110 if (w < 20)
3111 throw wexception("Not enough space to draw spinbox");
3112@@ -115,7 +107,6 @@
3113
3114 sbi->text = new UI::Textarea
3115 (this, butw * 16 / 5, 0, textw, h, buf, Align_Center);
3116- sbi->text->set_font(sbi->fontname, sbi->fontsize, sbi->fontcolor);
3117 sbi->butPlus =
3118 new Callback_Button
3119 (this, "+",
3120@@ -123,7 +114,7 @@
3121 sbi->background,
3122 boost::bind(&SpinBox::changeValue, boost::ref(*this), 1),
3123 "+", _("Increase the value"),
3124- true, false, sbi->fontname, sbi->fontsize);
3125+ true, false);
3126 sbi->butMinus =
3127 new Callback_Button
3128 (this, "-",
3129@@ -131,7 +122,7 @@
3130 sbi->background,
3131 boost::bind(&SpinBox::changeValue, boost::ref(*this), -1),
3132 "-", _("Decrease the value"),
3133- true, false, sbi->fontname, sbi->fontsize);
3134+ true, false);
3135 sbi->butPlus->set_repeating(true);
3136 sbi->butMinus->set_repeating(true);
3137 if (m_big) {
3138@@ -142,7 +133,7 @@
3139 sbi->background,
3140 boost::bind(&SpinBox::changeValue, boost::ref(*this), 10),
3141 "++", _("Increase the value by 10"),
3142- true, false, sbi->fontname, sbi->fontsize);
3143+ true, false);
3144 sbi->butTenMinus =
3145 new Callback_Button
3146 (this, "--",
3147@@ -150,10 +141,12 @@
3148 sbi->background,
3149 boost::bind(&SpinBox::changeValue, boost::ref(*this), -10),
3150 "--", _("Decrease the value by 10"),
3151- true, false, sbi->fontname, sbi->fontsize);
3152+ true, false);
3153 sbi->butTenPlus->set_repeating(true);
3154 sbi->butTenMinus->set_repeating(true);
3155 }
3156+
3157+ set_font(UI_FONT_NAME, UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG);
3158 }
3159
3160
3161@@ -269,19 +262,25 @@
3162
3163 /**
3164 * Sets the font of all UI elements
3165+ *
3166+ * @deprecated, see set_textstyle
3167 */
3168 void SpinBox::set_font(std::string const & name, int32_t size, RGBColor color)
3169 {
3170- sbi->fontname = name;
3171- sbi->fontsize = size;
3172- sbi->fontcolor = color;
3173+ set_textstyle(TextStyle::makebold(Font::get(name, size), color));
3174+}
3175
3176- sbi->text->set_font(name, size, color);
3177- sbi->butPlus->set_font(name, size);
3178- sbi->butMinus->set_font(name, size);
3179+/**
3180+ * Sets the font and textstyle of all UI elements
3181+ */
3182+void SpinBox::set_textstyle(const TextStyle & textstyle)
3183+{
3184+ sbi->text->set_textstyle(textstyle);
3185+ sbi->butPlus->set_font(textstyle.font);
3186+ sbi->butMinus->set_font(textstyle.font);
3187 if (m_big) {
3188- sbi->butTenPlus->set_font(name, size);
3189- sbi->butTenMinus->set_font(name, size);
3190+ sbi->butTenPlus->set_font(textstyle.font);
3191+ sbi->butTenMinus->set_font(textstyle.font);
3192 }
3193 update();
3194 }
3195
3196=== modified file 'src/ui_basic/spinbox.h'
3197--- src/ui_basic/spinbox.h 2009-11-17 09:32:58 +0000
3198+++ src/ui_basic/spinbox.h 2011-01-31 17:56:23 +0000
3199@@ -29,6 +29,7 @@
3200
3201 struct SpinBoxImpl;
3202 struct IntValueTextReplacement;
3203+struct TextStyle;
3204
3205 /// A spinbox is an UI element for setting the integer value of a variable.
3206 struct SpinBox : public Panel {
3207@@ -50,6 +51,7 @@
3208 Align align() const;
3209 void setAlign(Align);
3210 void set_font(std::string const &, int32_t, RGBColor);
3211+ void set_textstyle(const TextStyle & style);
3212 void add_replacement(int32_t, std::string);
3213 void remove_replacement(int32_t);
3214 bool has_replacement(int32_t);
3215
3216=== modified file 'src/ui_basic/table.cc'
3217--- src/ui_basic/table.cc 2010-11-01 23:54:06 +0000
3218+++ src/ui_basic/table.cc 2011-01-31 17:56:23 +0000
3219@@ -19,6 +19,7 @@
3220
3221 #include "table.h"
3222
3223+#include "graphic/font.h"
3224 #include "graphic/font_handler.h"
3225 #include "graphic/rendertarget.h"
3226 #include "graphic/surface.h"
3227@@ -97,7 +98,8 @@
3228 complete_width, 0, width, m_headerheight,
3229 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
3230 boost::bind(&Table::header_button_clicked, boost::ref(*this), m_columns.size()),
3231- title, "", true, false, m_fontname, m_fontsize);
3232+ title, "", true, false);
3233+ c.btn->set_font(Font::get(m_fontname, m_fontsize));
3234 }
3235 c.width = width;
3236 c.alignment = alignment;
3237@@ -145,7 +147,8 @@
3238 complete_width, 0, column.width, m_headerheight,
3239 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
3240 boost::bind(&Table::header_button_clicked, boost::ref(*this), col),
3241- title, "", true, false, m_fontname, m_fontsize);
3242+ title, "", true, false);
3243+ column.btn->set_font(Font::get(m_fontname, m_fontsize));
3244 } else if (column.btn and title.empty()) { // had title before, not now
3245 delete column.btn;
3246 column.btn = 0;
3247@@ -291,18 +294,17 @@
3248 / 2),
3249 entry_picture);
3250
3251- UI::g_fh->draw_string
3252+ UI::g_fh->draw_text
3253 (dst,
3254- m_fontname, m_fontsize,
3255- col,
3256- RGBColor(107, 87, 55),
3257+ TextStyle::makebold(Font::get(m_fontname, m_fontsize), col),
3258 point +
3259 Point
3260 (picw,
3261 (static_cast<int32_t>(lineheight) -
3262 static_cast<int32_t>(stringh))
3263 / 2),
3264- entry_string, alignment);
3265+ entry_string,
3266+ alignment);
3267
3268 curx += curw;
3269 }
3270
3271=== modified file 'src/ui_basic/textarea.cc'
3272--- src/ui_basic/textarea.cc 2011-01-30 17:02:30 +0000
3273+++ src/ui_basic/textarea.cc 2011-01-31 17:56:23 +0000
3274@@ -26,71 +26,62 @@
3275 Textarea::Textarea
3276 (Panel * const parent,
3277 const int32_t x, const int32_t y,
3278- const std::string & text, const Align align, const bool multiline)
3279+ const std::string & text, const Align align)
3280 :
3281 Panel (parent, x, y, 0, 0),
3282 m_layoutmode(AutoMove),
3283- m_align (align),
3284- m_multiline(multiline)
3285+ m_align (align)
3286 {
3287- set_handle_mouse(false);
3288- set_think (false);
3289- set_font (UI_FONT_SMALL, UI_FONT_CLR_FG);
3290- set_text (text);
3291+ init();
3292+ set_text(text);
3293 }
3294
3295 Textarea::Textarea
3296 (Panel * const parent,
3297 const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
3298- const Align align, const bool multiline)
3299+ const Align align)
3300 :
3301 Panel (parent, x, y, w, h),
3302 m_layoutmode(AutoMove),
3303- m_align (align),
3304- m_multiline(multiline),
3305- m_fontname (UI_FONT_NAME),
3306- m_fontsize (UI_FONT_SIZE_SMALL),
3307- m_fcolor (UI_FONT_CLR_FG)
3308+ m_align (align)
3309 {
3310- set_handle_mouse(false);
3311- set_think(false);
3312+ init();
3313 }
3314
3315 Textarea:: Textarea
3316 (Panel * const parent,
3317 const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
3318- const std::string & text, const Align align,
3319- const bool multiline)
3320+ const std::string & text, const Align align)
3321 :
3322 Panel (parent, x, y, w, h),
3323 m_layoutmode(AutoMove),
3324- m_align (align),
3325- m_multiline(multiline),
3326- m_fontname (UI_FONT_NAME),
3327- m_fontsize (UI_FONT_SIZE_SMALL),
3328- m_fcolor (UI_FONT_CLR_FG)
3329+ m_align (align)
3330 {
3331- set_handle_mouse(false);
3332- set_think(false);
3333+ init();
3334 set_text(text);
3335 }
3336
3337 Textarea::Textarea
3338 (Panel * parent,
3339 const std::string & text,
3340- Align align, bool multiline, uint32_t width)
3341+ Align align, uint32_t width)
3342 :
3343 Panel(parent, 0, 0, width, 0),
3344 m_layoutmode(Layouted),
3345-m_align(align),
3346-m_multiline(multiline),
3347-m_fontname(UI_FONT_NAME),
3348-m_fontsize(UI_FONT_SIZE_SMALL),
3349-m_fcolor(UI_FONT_CLR_FG)
3350+m_align(align)
3351+{
3352+ init();
3353+ set_text(text);
3354+}
3355+
3356+/**
3357+ * Initialization tasks that are common to all constructors.
3358+ */
3359+void Textarea::init()
3360 {
3361 set_handle_mouse(false);
3362 set_think(false);
3363- set_text(text);
3364+ set_textstyle(TextStyle::ui_small());
3365 }
3366
3367 /**
3368@@ -107,14 +98,14 @@
3369 /**
3370 * Set the font of the textarea.
3371 */
3372-void Textarea::set_font(const std::string & name, int32_t size, RGBColor fg)
3373+void Textarea::set_textstyle(const TextStyle & style)
3374 {
3375+ if (m_textstyle == style)
3376+ return;
3377+
3378 if (m_layoutmode == AutoMove)
3379 collapse();
3380- m_fontname = name;
3381- m_fontsize = size;
3382- m_fcolor = fg;
3383- set_text(m_text);
3384+ m_textstyle = style;
3385 if (m_layoutmode == AutoMove)
3386 expand();
3387 else if (m_layoutmode == Layouted)
3388@@ -122,10 +113,19 @@
3389 }
3390
3391 /**
3392+ * @deprecated
3393+ */
3394+void Textarea::set_font(const std::string & name, int size, RGBColor clr)
3395+{
3396+ set_textstyle(TextStyle::makebold(Font::get(name, size), clr));
3397+}
3398+
3399+/**
3400 * Set the text of the Textarea. Size (or desired size) is automatically
3401 * adjusted depending on the Textarea mode.
3402 */
3403-void Textarea::set_text(const std::string & text) {
3404+void Textarea::set_text(const std::string & text)
3405+{
3406 if (m_text == text)
3407 return;
3408
3409@@ -141,7 +141,8 @@
3410 update();
3411 }
3412
3413-std::string Textarea::get_text() {
3414+std::string Textarea::get_text()
3415+{
3416 return m_text;
3417 }
3418
3419@@ -164,18 +165,15 @@
3420 */
3421 void Textarea::draw(RenderTarget & dst)
3422 {
3423- if (m_text.length())
3424- UI::g_fh->draw_string
3425- (dst,
3426- m_fontname, m_fontsize, m_fcolor, UI_FONT_CLR_BG,
3427- Point
3428- (m_align & Align_HCenter ?
3429- get_w() / 2 : m_align & Align_Right ? get_w() : 0,
3430- m_align & Align_VCenter ?
3431- get_h() / 2 : m_align & Align_Bottom ? get_h() : 0),
3432- m_text,
3433- m_align,
3434- m_multiline ? get_w() : std::numeric_limits<uint32_t>::max());
3435+ if (m_text.length()) {
3436+ Point anchor
3437+ (m_align & Align_HCenter ?
3438+ get_w() / 2 : m_align & Align_Right ? get_w() : 0,
3439+ m_align & Align_VCenter ?
3440+ get_h() / 2 : m_align & Align_Bottom ? get_h() : 0);
3441+
3442+ g_fh->draw_text(dst, m_textstyle, anchor, m_text, m_align);
3443+ }
3444 }
3445
3446
3447@@ -189,12 +187,10 @@
3448 int32_t w = get_w();
3449 int32_t h = get_h();
3450
3451- if (not m_multiline) {
3452- if (m_align & Align_HCenter)
3453- x += w >> 1;
3454- else if (m_align & Align_Right)
3455- x += w;
3456- }
3457+ if (m_align & Align_HCenter)
3458+ x += w >> 1;
3459+ else if (m_align & Align_Right)
3460+ x += w;
3461
3462 if (m_align & Align_VCenter)
3463 y += h >> 1;
3464@@ -202,7 +198,7 @@
3465 y += h;
3466
3467 set_pos(Point(x, y));
3468- set_size(m_multiline ? get_w() : 0, 0);
3469+ set_size(0, 0);
3470 }
3471
3472
3473@@ -211,26 +207,15 @@
3474 */
3475 void Textarea::expand()
3476 {
3477- if (!m_text.length())
3478- return;
3479-
3480 int32_t x = get_x();
3481 int32_t y = get_y();
3482- uint32_t w, h;
3483-
3484- UI::g_fh->get_size
3485- (m_fontname,
3486- m_fontsize,
3487- m_text,
3488- w, h,
3489- m_multiline ? get_w() : -1);
3490-
3491- if (not m_multiline) {
3492- if (m_align & Align_HCenter)
3493- x -= w >> 1;
3494- else if (m_align & Align_Right)
3495- x -= w;
3496- }
3497+ uint32_t w = m_textstyle.calc_bare_width(m_text);
3498+ uint32_t h = m_textstyle.font->height();
3499+
3500+ if (m_align & Align_HCenter)
3501+ x -= w >> 1;
3502+ else if (m_align & Align_Right)
3503+ x -= w;
3504
3505 if (m_align & Align_VCenter)
3506 y -= h >> 1;
3507@@ -238,7 +223,7 @@
3508 y -= h;
3509
3510 set_pos(Point(x, y));
3511- set_size(m_multiline ? get_w() : w, h);
3512+ set_size(w, h);
3513 }
3514
3515 /**
3516@@ -246,19 +231,10 @@
3517 */
3518 void Textarea::update_desired_size()
3519 {
3520- uint32_t olddesiredw, tmp;
3521-
3522- get_desired_size(olddesiredw, tmp);
3523-
3524- uint32_t w, h;
3525- UI::g_fh->get_size
3526- (m_fontname,
3527- m_fontsize,
3528- m_text,
3529- w, h,
3530- m_multiline ? olddesiredw : -1);
3531-
3532- set_desired_size(m_multiline ? olddesiredw : w, h);
3533+ uint32_t w = m_textstyle.calc_bare_width(m_text);
3534+ uint32_t h = m_textstyle.font->height();
3535+
3536+ set_desired_size(w, h);
3537 }
3538
3539 /**
3540@@ -267,8 +243,8 @@
3541 */
3542 void Textarea::set_fixed_size(const std::string & text)
3543 {
3544- uint32_t w, h;
3545- UI::g_fh->get_size(m_fontname, m_fontsize, text, w, h);
3546+ uint32_t w = m_textstyle.calc_bare_width(m_text);
3547+ uint32_t h = m_textstyle.font->height();
3548 set_size(w, h);
3549 set_desired_size(w, h);
3550 }
3551
3552=== modified file 'src/ui_basic/textarea.h'
3553--- src/ui_basic/textarea.h 2010-05-25 18:40:43 +0000
3554+++ src/ui_basic/textarea.h 2011-01-31 17:56:23 +0000
3555@@ -22,6 +22,7 @@
3556
3557 #include "align.h"
3558 #include "constants.h"
3559+#include "graphic/font.h"
3560 #include "panel.h"
3561
3562 namespace UI {
3563@@ -59,20 +60,20 @@
3564 (Panel * parent,
3565 int32_t x, int32_t y,
3566 std::string const & text = std::string(),
3567- Align align = Align_Left, bool multiline = false);
3568+ Align align = Align_Left);
3569 Textarea
3570 (Panel * parent,
3571 int32_t x, int32_t y, uint32_t w, uint32_t h,
3572- Align align = Align_Left, bool multiline = false);
3573+ Align align = Align_Left);
3574 Textarea
3575 (Panel * const parent,
3576 int32_t x, int32_t y, uint32_t w, uint32_t h,
3577 const std::string & text,
3578- Align align = Align_Left, bool multiline = false);
3579+ Align align = Align_Left);
3580 Textarea
3581 (Panel * parent,
3582 const std::string & text = std::string(),
3583- Align align = Align_Left, bool multiline = false, uint32_t width = 0);
3584+ Align align = Align_Left, uint32_t width = 0);
3585
3586 void set_layout_mode(LayoutMode lm);
3587 void set_fixed_size(const std::string & text);
3588@@ -83,22 +84,23 @@
3589 // Drawing and event handlers
3590 void draw(RenderTarget &);
3591
3592- void set_font(std::string const & name, int32_t size, RGBColor fg);
3593+ void set_textstyle(const TextStyle & style);
3594+ const TextStyle & get_textstyle() const {return m_textstyle;}
3595+
3596+ void set_font(const std::string & name, int size, RGBColor clr);
3597
3598 protected:
3599 virtual void update_desired_size();
3600
3601 private:
3602+ void init();
3603 void collapse();
3604 void expand();
3605
3606 LayoutMode m_layoutmode;
3607 std::string m_text;
3608- Align m_align;
3609- bool m_multiline;
3610- std::string m_fontname;
3611- int32_t m_fontsize;
3612- RGBColor m_fcolor;
3613+ Align m_align;
3614+ TextStyle m_textstyle;
3615 };
3616
3617 }
3618
3619=== modified file 'src/ui_basic/window.cc'
3620--- src/ui_basic/window.cc 2010-12-04 15:22:29 +0000
3621+++ src/ui_basic/window.cc 2011-01-31 17:56:23 +0000
3622@@ -20,6 +20,7 @@
3623 #include "window.h"
3624
3625 #include "constants.h"
3626+#include "graphic/font.h"
3627 #include "graphic/font_handler.h"
3628 #include "graphic/rendertarget.h"
3629 #include "wlapplication.h"
3630@@ -308,11 +309,10 @@
3631
3632 // draw the title if we have one
3633 if (m_title.length())
3634- UI::g_fh->draw_string
3635- (dst,
3636- UI_FONT_SMALL, UI_FONT_SMALL_CLR,
3637+ UI::g_fh->draw_text
3638+ (dst, UI::TextStyle::ui_small(),
3639 Point(get_lborder() + get_inner_w() / 2, TP_B_PIXMAP_THICKNESS / 2),
3640- m_title.c_str(), Align_Center);
3641+ m_title, Align_Center);
3642
3643 if (not _is_minimal) {
3644 const int32_t vt_bar_end = get_h() -
3645
3646=== modified file 'src/ui_fsmenu/base.cc'
3647--- src/ui_fsmenu/base.cc 2010-11-27 13:51:57 +0000
3648+++ src/ui_fsmenu/base.cc 2011-01-31 17:56:23 +0000
3649@@ -21,6 +21,7 @@
3650
3651 #include "constants.h"
3652 #include "io/filesystem/filesystem.h"
3653+#include "graphic/font.h"
3654 #include "graphic/graphic.h"
3655 #include "log.h"
3656 #include "profile/profile.h"
3657@@ -38,6 +39,12 @@
3658 ==============================================================================
3659 */
3660
3661+struct Fullscreen_Menu_Base::Data {
3662+ PictureID res_background;
3663+ UI::TextStyle textstyle_small;
3664+ UI::TextStyle textstyle_big;
3665+};
3666+
3667 /**
3668 * Initialize a pre-game menu
3669 *
3670@@ -45,10 +52,8 @@
3671 */
3672 Fullscreen_Menu_Base::Fullscreen_Menu_Base(char const * const bgpic)
3673 : UI::Panel(0, 0, 0, gr_x(), gr_y()),
3674- // Switch graphics mode if necessary
3675- m_xres(gr_x()), m_yres(gr_y())
3676+ d(new Data)
3677 {
3678-
3679 Section & s = g_options.pull_section("global");
3680
3681 #if USE_OPENGL
3682@@ -57,7 +62,7 @@
3683 #define GET_BOOL_USE_OPENGL false
3684 #endif
3685 WLApplication::get()->init_graphics
3686- (m_xres, m_yres,
3687+ (get_w(), get_h(),
3688 s.get_int("depth", 16),
3689 s.get_bool("fullscreen", false),
3690 GET_BOOL_USE_OPENGL);
3691@@ -73,8 +78,14 @@
3692 ("could not open splash screen; make sure that all data files are "
3693 "installed");
3694
3695- m_res_background = g_gr->get_resized_picture
3696- (background, m_xres, m_yres, Graphic::ResizeMode_Loose);
3697+ d->res_background = g_gr->get_resized_picture
3698+ (background, get_w(), get_h(), Graphic::ResizeMode_Loose);
3699+
3700+ d->textstyle_small = UI::TextStyle::ui_small();
3701+ d->textstyle_small.font = UI::Font::get(ui_fn(), fs_small());
3702+
3703+ d->textstyle_big = UI::TextStyle::ui_big();
3704+ d->textstyle_big.font = UI::Font::get(ui_fn(), fs_big());
3705 }
3706
3707 Fullscreen_Menu_Base::~Fullscreen_Menu_Base()
3708@@ -86,7 +97,7 @@
3709 * Draw the background / splash screen
3710 */
3711 void Fullscreen_Menu_Base::draw(RenderTarget & dst) {
3712- dst.blit(Point(0, 0), m_res_background);
3713+ dst.blit(Point(0, 0), d->res_background);
3714 }
3715
3716
3717@@ -100,9 +111,29 @@
3718
3719
3720 uint32_t Fullscreen_Menu_Base::fs_small() {
3721- return UI_FONT_SIZE_SMALL * gr_y() / 600;
3722+ return UI_FONT_SIZE_SMALL * get_h() / 600;
3723 }
3724
3725 uint32_t Fullscreen_Menu_Base::fs_big() {
3726- return UI_FONT_SIZE_BIG * gr_y() / 600;
3727+ return UI_FONT_SIZE_BIG * get_h() / 600;
3728+}
3729+
3730+UI::TextStyle & Fullscreen_Menu_Base::ts_small()
3731+{
3732+ return d->textstyle_small;
3733+}
3734+
3735+UI::TextStyle & Fullscreen_Menu_Base::ts_big()
3736+{
3737+ return d->textstyle_big;
3738+}
3739+
3740+UI::Font * Fullscreen_Menu_Base::font_small()
3741+{
3742+ return d->textstyle_small.font;
3743+}
3744+
3745+UI::Font * Fullscreen_Menu_Base::font_big()
3746+{
3747+ return d->textstyle_big.font;
3748 }
3749
3750=== modified file 'src/ui_fsmenu/base.h'
3751--- src/ui_fsmenu/base.h 2010-11-27 13:51:57 +0000
3752+++ src/ui_fsmenu/base.h 2011-01-31 17:56:23 +0000
3753@@ -20,9 +20,16 @@
3754 #ifndef FULLSCREEN_MENU_BASE_H
3755 #define FULLSCREEN_MENU_BASE_H
3756
3757+#include <boost/scoped_ptr.hpp>
3758+
3759 #include "ui_basic/panel.h"
3760 #include <string>
3761
3762+namespace UI {
3763+struct Font;
3764+struct TextStyle;
3765+}
3766+
3767 /**
3768 * This class is the base class for a fullscreen menu.
3769 * A fullscreen menu is a menu which takes the full screen; it has the size
3770@@ -35,19 +42,25 @@
3771 virtual void draw(RenderTarget &);
3772
3773 public:
3774-///\return the x/y value of current set resolution
3775-uint32_t gr_x();
3776-uint32_t gr_y();
3777-
3778-///\return the size for texts fitting to current resolution
3779-uint32_t fs_small();
3780-uint32_t fs_big();
3781-
3782-protected:
3783- uint32_t m_xres;
3784- uint32_t m_yres;
3785+ ///\return the size for texts fitting to current resolution
3786+ uint32_t fs_small();
3787+ uint32_t fs_big();
3788+
3789+ UI::TextStyle & ts_small();
3790+ UI::TextStyle & ts_big();
3791+
3792+ UI::Font * font_small();
3793+ UI::Font * font_big();
3794+
3795 private:
3796- PictureID m_res_background;
3797+ /**
3798+ * Query the configured screen resolution.
3799+ */
3800+ uint32_t gr_x();
3801+ uint32_t gr_y();
3802+
3803+ struct Data;
3804+ boost::scoped_ptr<Data> d;
3805 };
3806
3807
3808
3809=== modified file 'src/ui_fsmenu/campaign_select.cc'
3810--- src/ui_fsmenu/campaign_select.cc 2010-11-18 10:28:25 +0000
3811+++ src/ui_fsmenu/campaign_select.cc 2011-01-31 17:56:23 +0000
3812@@ -40,55 +40,56 @@
3813 Fullscreen_Menu_Base("choosemapmenu.jpg"),
3814
3815 // Values for alignment and size
3816- m_butw (m_xres / 4),
3817- m_buth (m_yres * 9 / 200),
3818+ m_butw (get_w() / 4),
3819+ m_buth (get_h() * 9 / 200),
3820 m_fs (fs_small()),
3821 m_fn (ui_fn()),
3822
3823 // Text labels
3824 title
3825 (this,
3826- m_xres / 2, m_yres * 9 / 50,
3827+ get_w() / 2, get_h() * 9 / 50,
3828 _("Select a campaign"), UI::Align_HCenter),
3829 label_campname
3830- (this, m_xres * 3 / 5, m_yres * 17 / 50, _("Campaign:")),
3831+ (this, get_w() * 3 / 5, get_h() * 17 / 50, _("Campaign:")),
3832 tacampname
3833- (this, m_xres * 61 / 100, m_yres * 3 / 8, ""),
3834+ (this, get_w() * 61 / 100, get_h() * 3 / 8, ""),
3835 label_difficulty
3836- (this, m_xres * 3 / 5, m_yres * 17 / 40, _("Difficulty:")),
3837+ (this, get_w() * 3 / 5, get_h() * 17 / 40, _("Difficulty:")),
3838 tadifficulty
3839- (this, m_xres * 61 / 100, m_yres * 23 / 50, ""),
3840+ (this, get_w() * 61 / 100, get_h() * 23 / 50, ""),
3841 label_campdescr
3842- (this, m_xres * 3 / 5, m_yres * 51 / 100, _("Description:")),
3843+ (this, get_w() * 3 / 5, get_h() * 51 / 100, _("Description:")),
3844 tacampdescr
3845 (this,
3846- m_xres * 61 / 100, m_yres * 11 / 20, m_xres * 9 / 25, m_yres * 7 / 25,
3847+ get_w() * 61 / 100, get_h() * 11 / 20, get_w() * 9 / 25, get_h() * 7 / 25,
3848 ""),
3849
3850 // Buttons
3851 b_ok
3852 (this, "ok",
3853- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
3854+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
3855 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
3856 boost::bind
3857 (&Fullscreen_Menu_CampaignSelect::clicked_ok, boost::ref(*this)),
3858- _("OK"), std::string(), false, false,
3859- m_fn, m_fs),
3860+ _("OK"), std::string(), false, false),
3861 back
3862 (this, "back",
3863- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
3864+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
3865 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
3866 boost::bind
3867 (&Fullscreen_Menu_CampaignSelect::end_modal, boost::ref(*this), 0),
3868- _("Back"), std::string(), true, false,
3869- m_fn, m_fs),
3870+ _("Back"), std::string(), true, false),
3871
3872 // Campaign list
3873 m_list
3874 (this,
3875- m_xres * 47 / 2500, m_yres * 3417 / 10000,
3876- m_xres * 711 / 1250, m_yres * 6083 / 10000)
3877+ get_w() * 47 / 2500, get_h() * 3417 / 10000,
3878+ get_w() * 711 / 1250, get_h() * 6083 / 10000)
3879 {
3880+ back.set_font(font_small());
3881+ b_ok.set_font(font_small());
3882+
3883 title .set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
3884 label_campname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
3885 tacampname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
3886@@ -251,51 +252,50 @@
3887 Fullscreen_Menu_Base("choosemapmenu.jpg"),
3888
3889 // Values for alignment and size
3890- m_xres (gr_x()),
3891- m_yres (gr_y()),
3892- m_butw (m_xres / 4),
3893- m_buth (m_yres * 9 / 200),
3894+ m_butw (get_w() / 4),
3895+ m_buth (get_h() * 9 / 200),
3896 m_fs (fs_small()),
3897 m_fn (ui_fn()),
3898
3899 // Text labels
3900 title
3901 (this,
3902- m_xres / 2, m_yres * 9 / 50, _("Choose your map!"),
3903+ get_w() / 2, get_h() * 9 / 50, _("Choose your map!"),
3904 UI::Align_HCenter),
3905- label_mapname (this, m_xres * 3 / 5, m_yres * 17 / 50, _("Name:")),
3906- tamapname (this, m_xres * 61 / 100, m_yres * 3 / 8, ""),
3907- label_author (this, m_xres * 3 / 5, m_yres * 17 / 40, _("Author:")),
3908- taauthor (this, m_xres * 61 / 100, m_yres * 23 / 50, ""),
3909- label_mapdescr(this, m_xres * 3 / 5, m_yres * 51 / 100, _("Description:")),
3910+ label_mapname (this, get_w() * 3 / 5, get_h() * 17 / 50, _("Name:")),
3911+ tamapname (this, get_w() * 61 / 100, get_h() * 3 / 8, ""),
3912+ label_author (this, get_w() * 3 / 5, get_h() * 17 / 40, _("Author:")),
3913+ taauthor (this, get_w() * 61 / 100, get_h() * 23 / 50, ""),
3914+ label_mapdescr(this, get_w() * 3 / 5, get_h() * 51 / 100, _("Description:")),
3915 tamapdescr
3916 (this,
3917- m_xres * 61 / 100, m_yres * 11 / 20, m_xres * 9 / 25, m_yres * 7 / 25),
3918+ get_w() * 61 / 100, get_h() * 11 / 20, get_w() * 9 / 25, get_h() * 7 / 25),
3919
3920 // Buttons
3921 b_ok
3922 (this, "ok",
3923- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
3924+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
3925 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
3926 boost::bind
3927 (&Fullscreen_Menu_CampaignMapSelect::clicked_ok, boost::ref(*this)),
3928- _("OK"), std::string(), false, false,
3929- m_fn, m_fs),
3930+ _("OK"), std::string(), false, false),
3931 back
3932 (this, "back",
3933- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
3934+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
3935 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
3936 boost::bind
3937 (&Fullscreen_Menu_CampaignMapSelect::end_modal, boost::ref(*this), 0),
3938- _("Back"), std::string(), true, false,
3939- m_fn, m_fs),
3940+ _("Back"), std::string(), true, false),
3941
3942 // Campaign map list
3943 m_list
3944 (this,
3945- m_xres * 47 / 2500, m_yres * 3417 / 10000,
3946- m_xres * 711 / 1250, m_yres * 6083 / 10000)
3947+ get_w() * 47 / 2500, get_h() * 3417 / 10000,
3948+ get_w() * 711 / 1250, get_h() * 6083 / 10000)
3949 {
3950+ b_ok.set_font(font_small());
3951+ back.set_font(font_small());
3952+
3953 title .set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
3954 label_mapname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
3955 tamapname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
3956
3957=== modified file 'src/ui_fsmenu/campaign_select.h'
3958--- src/ui_fsmenu/campaign_select.h 2010-11-08 20:15:10 +0000
3959+++ src/ui_fsmenu/campaign_select.h 2011-01-31 17:56:23 +0000
3960@@ -79,8 +79,6 @@
3961 void set_campaign(uint32_t);
3962
3963 private:
3964- uint32_t m_xres;
3965- uint32_t m_yres;
3966 uint32_t m_butw;
3967 uint32_t m_buth;
3968 uint32_t m_fs;
3969
3970=== modified file 'src/ui_fsmenu/editor.cc'
3971--- src/ui_fsmenu/editor.cc 2010-10-18 21:05:42 +0000
3972+++ src/ui_fsmenu/editor.cc 2011-01-31 17:56:23 +0000
3973@@ -26,36 +26,36 @@
3974 Fullscreen_Menu_Base("singleplmenu.jpg"),
3975
3976 // Values for alignment and size
3977- m_butw (m_xres * 7 / 20),
3978- m_buth (m_yres * 19 / 400),
3979- m_butx ((m_xres - m_butw) / 2),
3980+ m_butw (get_w() * 7 / 20),
3981+ m_buth (get_h() * 19 / 400),
3982+ m_butx ((get_w() - m_butw) / 2),
3983
3984 // Title
3985 title
3986- (this, m_xres / 2, m_yres * 3 / 40, _("Editor Menu"), UI::Align_HCenter),
3987+ (this, get_w() / 2, get_h() * 3 / 40, _("Editor Menu"), UI::Align_HCenter),
3988
3989 // Buttons
3990 new_map
3991 (this, "new_map",
3992- m_butx, m_yres * 6 / 25, m_butw, m_buth,
3993+ m_butx, get_h() * 6 / 25, m_butw, m_buth,
3994 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
3995 boost::bind(&Fullscreen_Menu_Editor::end_modal, boost::ref(*this), static_cast<int32_t>(New_Map)),
3996- _("New Map"), std::string(), true, false,
3997- ui_fn(), fs_small()),
3998+ _("New Map"), std::string(), true, false),
3999 load_map
4000 (this, "load_map",
4001- m_butx, m_yres * 61 / 200, m_butw, m_buth,
4002+ m_butx, get_h() * 61 / 200, m_butw, m_buth,
4003 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4004 boost::bind(&Fullscreen_Menu_Editor::end_modal, boost::ref(*this), static_cast<int32_t>(Load_Map)),
4005- _("Load Map"), std::string(), true, false,
4006- ui_fn(), fs_small()),
4007+ _("Load Map"), std::string(), true, false),
4008 back
4009 (this, "back",
4010- m_butx, m_yres * 3 / 4, m_butw, m_buth,
4011+ m_butx, get_h() * 3 / 4, m_butw, m_buth,
4012 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4013 boost::bind(&Fullscreen_Menu_Editor::end_modal, boost::ref(*this), static_cast<int32_t>(Back)),
4014- _("Back"), std::string(), true, false,
4015- ui_fn(), fs_small())
4016+ _("Back"), std::string(), true, false)
4017 {
4018+ new_map.set_font(font_small());
4019+ load_map.set_font(font_small());
4020+ back.set_font(font_small());
4021 title.set_font(ui_fn(), fs_big(), UI_FONT_CLR_FG);
4022 }
4023
4024=== modified file 'src/ui_fsmenu/editor_mapselect.cc'
4025--- src/ui_fsmenu/editor_mapselect.cc 2010-11-03 01:04:47 +0000
4026+++ src/ui_fsmenu/editor_mapselect.cc 2011-01-31 17:56:23 +0000
4027@@ -39,74 +39,75 @@
4028 Fullscreen_Menu_Base("choosemapmenu.jpg"),
4029
4030 // Values for alignment and size
4031- m_butw (m_xres / 4),
4032- m_buth (m_yres * 9 / 200),
4033+ m_butw (get_w() / 4),
4034+ m_buth (get_h() * 9 / 200),
4035 m_fs (fs_small()),
4036 m_fn (ui_fn()),
4037
4038 // Text labels
4039 m_title
4040 (this,
4041- m_xres / 2, m_yres * 9 / 50,
4042+ get_w() / 2, get_h() * 9 / 50,
4043 _("Choose your map!"), UI::Align_HCenter),
4044 m_label_name
4045 (this,
4046- m_xres * 7 / 10, m_yres * 17 / 50,
4047+ get_w() * 7 / 10, get_h() * 17 / 50,
4048 _("Name:"), UI::Align_Right),
4049- m_name (this, m_xres * 71 / 100, m_yres * 17 / 50, std::string()),
4050+ m_name (this, get_w() * 71 / 100, get_h() * 17 / 50, std::string()),
4051 m_label_author
4052 (this,
4053- m_xres * 7 / 10, m_yres * 3 / 8,
4054+ get_w() * 7 / 10, get_h() * 3 / 8,
4055 _("Author:"), UI::Align_Right),
4056- m_author (this, m_xres * 71 / 100, m_yres * 3 / 8, std::string()),
4057+ m_author (this, get_w() * 71 / 100, get_h() * 3 / 8, std::string()),
4058 m_label_size
4059 (this,
4060- m_xres * 7 / 10, m_yres * 41 / 100,
4061+ get_w() * 7 / 10, get_h() * 41 / 100,
4062 _("Size:"), UI::Align_Right),
4063- m_size (this, m_xres * 71 / 100, m_yres * 41 / 100, std::string()),
4064+ m_size (this, get_w() * 71 / 100, get_h() * 41 / 100, std::string()),
4065 m_label_world
4066 (this,
4067- m_xres * 7 / 10, m_yres * 89 / 200,
4068+ get_w() * 7 / 10, get_h() * 89 / 200,
4069 _("World:"), UI::Align_Right),
4070- m_world (this, m_xres * 71 / 100, m_yres * 89 / 200, std::string()),
4071+ m_world (this, get_w() * 71 / 100, get_h() * 89 / 200, std::string()),
4072 m_label_nr_players
4073 (this,
4074- m_xres * 7 / 10, m_yres * 12 / 25,
4075+ get_w() * 7 / 10, get_h() * 12 / 25,
4076 _("Players:"), UI::Align_Right),
4077- m_nr_players (this, m_xres * 71 / 100, m_yres * 12 / 25, std::string()),
4078+ m_nr_players (this, get_w() * 71 / 100, get_h() * 12 / 25, std::string()),
4079 m_label_descr
4080 (this,
4081- m_xres * 7 / 10, m_yres * 103 / 200,
4082+ get_w() * 7 / 10, get_h() * 103 / 200,
4083 _("Descr:"), UI::Align_Right),
4084 m_descr
4085 (this,
4086- m_xres * 71 / 100, m_yres * 13 / 25, m_xres / 4, m_yres * 63 / 200),
4087+ get_w() * 71 / 100, get_h() * 13 / 25, get_w() / 4, get_h() * 63 / 200),
4088
4089 // Buttons
4090 m_back
4091 (this, "back",
4092- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
4093+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
4094 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4095 boost::bind(&Fullscreen_Menu_Editor_MapSelect::end_modal, boost::ref(*this), 0),
4096- _("Back"), std::string(), true, false,
4097- m_fn, m_fs),
4098+ _("Back"), std::string(), true, false),
4099 m_ok
4100 (this, "ok",
4101- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
4102+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
4103 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4104 boost::bind(&Fullscreen_Menu_Editor_MapSelect::ok, boost::ref(*this)),
4105- _("OK"), std::string(), false, false,
4106- m_fn, m_fs),
4107+ _("OK"), std::string(), false, false),
4108
4109 // Map list
4110 m_list
4111 (this,
4112- m_xres * 47 / 2500, m_yres * 3417 / 10000,
4113- m_xres * 711 / 1250, m_yres * 6083 / 10000),
4114+ get_w() * 47 / 2500, get_h() * 3417 / 10000,
4115+ get_w() * 711 / 1250, get_h() * 6083 / 10000),
4116
4117 // Runtime variables
4118 m_curdir("maps"), m_basedir("maps")
4119 {
4120+ m_back.set_font(font_small());
4121+ m_ok.set_font(font_small());
4122+
4123 m_title .set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
4124 m_label_name .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4125 m_name .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4126
4127=== modified file 'src/ui_fsmenu/fileview.cc'
4128--- src/ui_fsmenu/fileview.cc 2010-11-01 23:29:48 +0000
4129+++ src/ui_fsmenu/fileview.cc 2011-01-31 17:56:23 +0000
4130@@ -30,21 +30,22 @@
4131 :
4132 Fullscreen_Menu_Base("fileviewmenu.jpg"),
4133
4134- title (this, m_xres * 3 / 50, m_yres / 10),
4135+ title (this, get_w() * 3 / 50, get_h() / 10),
4136
4137 textview
4138 (this,
4139- m_xres * 3 / 80, m_yres * 283 / 1000,
4140- m_xres * 919 / 1000, m_yres * 11 / 20),
4141+ get_w() * 3 / 80, get_h() * 283 / 1000,
4142+ get_w() * 919 / 1000, get_h() * 11 / 20),
4143
4144 close_button
4145 (this, "close",
4146- m_xres * 3 / 8, m_yres * 9 / 10, m_xres / 4, m_yres * 9 / 200,
4147+ get_w() * 3 / 8, get_h() * 9 / 10, get_w() / 4, get_h() * 9 / 200,
4148 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4149 boost::bind(&Fullscreen_Menu_TextView::end_modal, boost::ref(*this), 0),
4150- _("Close"), std::string(), true, false,
4151- ui_fn(), fs_small())
4152+ _("Close"), std::string(), true, false)
4153 {
4154+ close_button.set_font(font_small());
4155+
4156 Profile prof(filename.c_str(), "global", "texts"); // section-less file
4157 Section & section = prof.get_safe_section("global");
4158
4159@@ -53,7 +54,7 @@
4160
4161 title.set_font(ui_fn(), fs_big(), UI_FONT_CLR_FG);
4162 title.set_pos
4163- (Point((get_inner_w() - title.get_w()) / 2, m_yres * 167 / 1000));
4164+ (Point((get_inner_w() - title.get_w()) / 2, get_h() * 167 / 1000));
4165
4166 textview.set_font(PROSA_FONT, PROSA_FONT_CLR_FG);
4167 }
4168
4169=== modified file 'src/ui_fsmenu/intro.cc'
4170--- src/ui_fsmenu/intro.cc 2009-07-11 21:34:13 +0000
4171+++ src/ui_fsmenu/intro.cc 2011-01-31 17:56:23 +0000
4172@@ -28,7 +28,7 @@
4173 // Text area
4174 m_message
4175 (this,
4176- gr_x() / 2, gr_y() * 19 / 20,
4177+ get_w() / 2, get_h() * 19 / 20,
4178 _("Press ESC or click to continue ..."), UI::Align_HCenter)
4179 {
4180 m_message.set_font(ui_fn(), fs_small() * 6 / 5, RGBColor(192, 192, 128));
4181
4182=== modified file 'src/ui_fsmenu/launchMPG.cc'
4183--- src/ui_fsmenu/launchMPG.cc 2010-12-30 13:28:59 +0000
4184+++ src/ui_fsmenu/launchMPG.cc 2011-01-31 17:56:23 +0000
4185@@ -47,7 +47,7 @@
4186 struct MapOrSaveSelectionWindow : public UI::Window {
4187 MapOrSaveSelectionWindow
4188 (UI::Panel * parent, uint32_t w, uint32_t h,
4189- uint32_t fontsize, std::string fontname)
4190+ UI::Font * font)
4191 :
4192 Window(parent, "selection_window", 0, 0, w, h, _("Please select"))
4193 {
4194@@ -57,30 +57,32 @@
4195 uint32_t space = get_inner_w() / 40;
4196 uint32_t butw = get_inner_w() * 3 / 10;
4197 uint32_t buth = get_inner_h() * 8 / 10;
4198- new UI::Callback_Button
4199+ UI::Button * btn = new UI::Callback_Button
4200 (this, "map",
4201 space, y, butw, buth,
4202 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4203 boost::bind
4204 (&MapOrSaveSelectionWindow::pressedButton, boost::ref(*this), 1),
4205- _("Map"), _("Select a map"), true, false,
4206- fontname, fontsize);
4207- new UI::Callback_Button
4208+ _("Map"), _("Select a map"), true, false);
4209+ btn->set_font(font);
4210+
4211+ btn = new UI::Callback_Button
4212 (this, "saved_game",
4213 2 * space + butw, y, butw, buth,
4214 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4215 boost::bind
4216 (&MapOrSaveSelectionWindow::pressedButton, boost::ref(*this), 2),
4217- _("Saved game"), _("Select a saved game"), true, false,
4218- fontname, fontsize);
4219- new UI::Callback_Button
4220+ _("Saved game"), _("Select a saved game"), true, false);
4221+ btn->set_font(font);
4222+
4223+ btn = new UI::Callback_Button
4224 (this, "cancel",
4225 3 * space + 2 * butw, y, butw, buth,
4226 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4227 boost::bind
4228 (&MapOrSaveSelectionWindow::pressedButton, boost::ref(*this), 0),
4229- _("Cancel"), _("Cancel selection"), true, false,
4230- fontname, fontsize);
4231+ _("Cancel"), _("Cancel selection"), true, false);
4232+ btn->set_font(font);
4233 }
4234
4235 void pressedButton(uint8_t i) {
4236@@ -95,80 +97,75 @@
4237 Fullscreen_Menu_Base("launchMPGmenu.jpg"),
4238
4239 // Values for alignment and size
4240- m_butw (m_xres / 4),
4241- m_buth (m_yres * 9 / 200),
4242+ m_butw (get_w() / 4),
4243+ m_buth (get_h() * 9 / 200),
4244 m_fs (fs_small()),
4245 m_fn (ui_fn()),
4246
4247 // Buttons
4248 m_change_map_or_save
4249 (this, "change_map_or_save",
4250- m_xres * 37 / 50 + m_butw - m_buth, m_yres * 3 / 20, m_buth, m_buth,
4251+ get_w() * 37 / 50 + m_butw - m_buth, get_h() * 3 / 20, m_buth, m_buth,
4252 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4253 g_gr->get_picture(PicMod_UI, "pics/menu_toggle_minimap.png"),
4254 boost::bind
4255 (&Fullscreen_Menu_LaunchMPG::change_map_or_save, boost::ref(*this)),
4256- _("Change map or saved game"), false, false,
4257- m_fn, m_fs),
4258+ _("Change map or saved game"), false, false),
4259 m_ok
4260 (this, "ok",
4261- m_xres * 37 / 50, m_yres * 12 / 20, m_butw, m_buth,
4262+ get_w() * 37 / 50, get_h() * 12 / 20, m_butw, m_buth,
4263 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4264 boost::bind
4265 (&Fullscreen_Menu_LaunchMPG::start_clicked, boost::ref(*this)),
4266- _("Start game"), std::string(), false, false,
4267- m_fn, m_fs),
4268+ _("Start game"), std::string(), false, false),
4269 m_back
4270 (this, "back",
4271- m_xres * 37 / 50, m_yres * 218 / 240, m_butw, m_buth,
4272+ get_w() * 37 / 50, get_h() * 218 / 240, m_butw, m_buth,
4273 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4274 boost::bind(&Fullscreen_Menu_LaunchMPG::back_clicked, boost::ref(*this)),
4275- _("Back"), std::string(), true, false,
4276- m_fn, m_fs),
4277+ _("Back"), std::string(), true, false),
4278 m_wincondition
4279 (this, "win_condition",
4280- m_xres * 37 / 50, m_yres * 11 / 20, m_butw, m_buth,
4281+ get_w() * 37 / 50, get_h() * 11 / 20, m_butw, m_buth,
4282 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4283 boost::bind
4284 (&Fullscreen_Menu_LaunchMPG::win_condition_clicked,
4285 boost::ref(*this)),
4286- "", std::string(), false, false,
4287- m_fn, m_fs),
4288+ "", std::string(), false, false),
4289 m_help_button
4290 (this, "help",
4291- m_xres * 37 / 50 + m_butw - m_buth, m_yres / 100, m_buth, m_buth,
4292+ get_w() * 37 / 50 + m_butw - m_buth, get_h() / 100, m_buth, m_buth,
4293 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4294 g_gr->get_picture(PicMod_UI, "pics/menu_help.png"),
4295 boost::bind
4296 (&Fullscreen_Menu_LaunchMPG::help_clicked,
4297 boost::ref(*this)),
4298- _("Show the help window"), true, false,
4299- m_fn, m_fs),
4300+ _("Show the help window"), true, false),
4301
4302 // Text labels
4303 m_title
4304 (this,
4305- m_xres / 2, m_yres / 25,
4306+ get_w() / 2, get_h() / 25,
4307 _("Multiplayer Game Setup"), UI::Align_HCenter),
4308 m_mapname
4309 (this,
4310- m_xres * 37 / 50, m_yres * 3 / 20,
4311+ get_w() * 37 / 50, get_h() * 3 / 20,
4312 std::string()),
4313 m_clients
4314 (this,
4315- m_xres / 10, m_yres / 10,
4316+ get_w() / 10, get_h() / 10,
4317 _("Clients")),
4318 m_players
4319 (this,
4320- m_xres / 2, m_yres / 10,
4321+ get_w() / 2, get_h() / 10,
4322 _("Players")),
4323 m_map
4324 (this,
4325- m_xres * 8 / 10, m_yres / 10,
4326+ get_w() * 8 / 10, get_h() / 10,
4327 _("Map")),
4328
4329- m_map_info(this, m_xres * 37 / 50, m_yres * 2 / 10, m_butw, m_yres * 27 / 80),
4330- m_client_info(this, m_xres * 37 / 50, m_yres * 13 / 20, m_butw, m_yres * 5 / 20),
4331+ m_map_info(this, get_w() * 37 / 50, get_h() * 2 / 10, m_butw, get_h() * 27 / 80),
4332+ m_client_info(this, get_w() * 37 / 50, get_h() * 13 / 20, m_butw, get_h() * 5 / 20),
4333 m_help(0),
4334
4335 // Variables and objects used in the menu
4336@@ -176,6 +173,12 @@
4337 m_ctrl (ctrl),
4338 m_chat (0)
4339 {
4340+ m_back.set_font(font_small());
4341+ m_ok.set_font(font_small());
4342+ m_wincondition.set_font(font_small());
4343+ m_help_button.set_font(font_small());
4344+ m_change_map_or_save.set_font(font_small());
4345+
4346 // Register win condition scripts
4347 m_lua = create_LuaInterface();
4348 m_lua->register_scripts(*g_fs, "win_conditions", "scripting/win_conditions");
4349@@ -200,7 +203,7 @@
4350 m_mpsg =
4351 new MultiPlayerSetupGroup
4352 (this,
4353- m_xres / 50, m_yres / 8, m_xres * 57 / 80, m_yres / 2,
4354+ get_w() / 50, get_h() / 8, get_w() * 57 / 80, get_h() / 2,
4355 settings, m_butw, m_buth, m_fn, m_fs);
4356
4357 // If we are the host, open the map or save selection menu at startup
4358@@ -238,7 +241,8 @@
4359 void Fullscreen_Menu_LaunchMPG::setChatProvider(ChatProvider & chat)
4360 {
4361 delete m_chat;
4362- m_chat = new GameChatPanel(this, m_xres / 50, m_yres * 13 / 20, m_xres * 57 / 80, m_yres * 3 / 10, chat);
4363+ m_chat = new GameChatPanel
4364+ (this, get_w() / 50, get_h() * 13 / 20, get_w() * 57 / 80, get_h() * 3 / 10, chat);
4365 // For better readability
4366 m_chat->set_bg_color(RGBColor(50, 50, 50));
4367 }
4368@@ -299,7 +303,7 @@
4369 /// Opens a popup window to select a map or saved game
4370 void Fullscreen_Menu_LaunchMPG::change_map_or_save() {
4371 MapOrSaveSelectionWindow selection_window
4372- (this, m_xres / 2, m_yres / 20, m_fs, m_fn);
4373+ (this, get_w() / 2, get_h() / 20, font_small());
4374 switch (selection_window.run()) {
4375 case 1:
4376 select_map();
4377
4378=== modified file 'src/ui_fsmenu/launchSPG.cc'
4379--- src/ui_fsmenu/launchSPG.cc 2010-11-02 11:13:59 +0000
4380+++ src/ui_fsmenu/launchSPG.cc 2011-01-31 17:56:23 +0000
4381@@ -44,72 +44,66 @@
4382 Fullscreen_Menu_Base("launchgamemenu.jpg"),
4383
4384 // Values for alignment and size
4385- m_butw (m_xres / 4),
4386- m_buth (m_yres * 9 / 200),
4387- m_fs (fs_small()),
4388- m_fn (ui_fn()),
4389+ m_butw (get_w() / 4),
4390+ m_buth (get_h() * 9 / 200),
4391
4392 // Buttons
4393 m_select_map
4394 (this, "select_map",
4395- m_xres * 7 / 10, m_yres * 3 / 10, m_butw, m_buth,
4396+ get_w() * 7 / 10, get_h() * 3 / 10, m_butw, m_buth,
4397 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4398 boost::bind(&Fullscreen_Menu_LaunchSPG::select_map, boost::ref(*this)),
4399- _("Select map"), std::string(), false, false,
4400- m_fn, m_fs),
4401+ _("Select map"), std::string(), false, false),
4402 m_wincondition
4403 (this, "win_condition",
4404- m_xres * 7 / 10, m_yres * 4 / 10, m_butw, m_buth,
4405+ get_w() * 7 / 10, get_h() * 4 / 10, m_butw, m_buth,
4406 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4407 boost::bind
4408 (&Fullscreen_Menu_LaunchSPG::win_condition_clicked,
4409 boost::ref(*this)),
4410- "", std::string(), false, false,
4411- m_fn, m_fs),
4412+ "", std::string(), false, false),
4413 m_back
4414 (this, "back",
4415- m_xres * 7 / 10, m_yres * 9 / 20, m_butw, m_buth,
4416+ get_w() * 7 / 10, get_h() * 9 / 20, m_butw, m_buth,
4417 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4418 boost::bind(&Fullscreen_Menu_LaunchSPG::back_clicked, boost::ref(*this)),
4419- _("Back"), std::string(), true, false,
4420- m_fn, m_fs),
4421+ _("Back"), std::string(), true, false),
4422 m_ok
4423 (this, "ok",
4424- m_xres * 7 / 10, m_yres * 1 / 2, m_butw, m_buth,
4425+ get_w() * 7 / 10, get_h() * 1 / 2, m_butw, m_buth,
4426 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4427 boost::bind
4428 (&Fullscreen_Menu_LaunchSPG::start_clicked, boost::ref(*this)),
4429- _("Start game"), std::string(), false, false,
4430- m_fn, m_fs),
4431+ _("Start game"), std::string(), false, false),
4432
4433 // Text labels
4434 m_title
4435 (this,
4436- m_xres / 2, m_yres / 10,
4437+ get_w() / 2, get_h() / 10,
4438 _("Launch Game"), UI::Align_HCenter),
4439 m_mapname
4440 (this,
4441- m_xres * 7 / 10 + m_butw / 2, m_yres * 5 / 20,
4442+ get_w() * 7 / 10 + m_butw / 2, get_h() * 5 / 20,
4443 std::string(), UI::Align_HCenter),
4444 m_name
4445 (this,
4446- m_xres * 1 / 25, m_yres * 53 / 200,
4447+ get_w() * 1 / 25, get_h() * 53 / 200,
4448 _("Player's name"), UI::Align_Left),
4449 m_type
4450 (this,
4451- m_xres * 19 / 100, m_yres * 53 / 200,
4452+ get_w() * 19 / 100, get_h() * 53 / 200,
4453 _("Player's type"), UI::Align_Left),
4454 m_team
4455 (this,
4456- m_xres * 31 / 100, m_yres * 53 / 200,
4457+ get_w() * 31 / 100, get_h() * 53 / 200,
4458 _("Team"), UI::Align_Left),
4459 m_tribe
4460 (this,
4461- m_xres * 36 / 100, m_yres * 53 / 200,
4462+ get_w() * 36 / 100, get_h() * 53 / 200,
4463 _("Player's tribe"), UI::Align_Left),
4464 m_init
4465 (this,
4466- m_xres * 51 / 100, m_yres * 53 / 200,
4467+ get_w() * 51 / 100, get_h() * 53 / 200,
4468 _("Start type"), UI::Align_Left),
4469
4470 // Variables and objects used in the menu
4471@@ -128,22 +122,31 @@
4472 m_cur_wincondition = -1;
4473 win_condition_clicked();
4474
4475- m_title .set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
4476- m_mapname.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4477- m_name .set_font(m_fn, m_fs * 4 / 5, UI_FONT_CLR_FG);
4478- m_type .set_font(m_fn, m_fs * 4 / 5, UI_FONT_CLR_FG);
4479- m_team .set_font(m_fn, m_fs * 4 / 5, UI_FONT_CLR_FG);
4480- m_tribe .set_font(m_fn, m_fs * 4 / 5, UI_FONT_CLR_FG);
4481- m_init .set_font(m_fn, m_fs * 4 / 5, UI_FONT_CLR_FG);
4482-
4483- uint32_t y = m_yres / 4;
4484+ m_title .set_textstyle(ts_big());
4485+ m_mapname.set_textstyle(ts_small());
4486+
4487+ UI::TextStyle tsmaller
4488+ (UI::TextStyle::makebold
4489+ (UI::Font::get(ui_fn(), fs_small() * 4 / 5), UI_FONT_CLR_FG));
4490+ m_name.set_textstyle(tsmaller);
4491+ m_type.set_textstyle(tsmaller);
4492+ m_team.set_textstyle(tsmaller);
4493+ m_tribe.set_textstyle(tsmaller);
4494+ m_init.set_textstyle(tsmaller);
4495+
4496+ m_select_map.set_font(font_small());
4497+ m_wincondition.set_font(font_small());
4498+ m_back.set_font(font_small());
4499+ m_ok.set_font(font_small());
4500+
4501+ uint32_t y = get_h() / 4;
4502 char posIco[42];
4503 for (uint32_t i = 0; i < MAX_PLAYERS; ++i) {
4504 sprintf(posIco, "pics/fsel_editor_set_player_0%i_pos.png", i + 1);
4505 m_pos[i] =
4506 new UI::Callback_Button
4507 (this, "switch_to_position",
4508- m_xres / 100, y += m_buth, m_yres * 17 / 500, m_yres * 17 / 500,
4509+ get_w() / 100, y += m_buth, get_h() * 17 / 500, get_h() * 17 / 500,
4510 g_gr->get_picture(PicMod_UI, "pics/but1.png"),
4511 g_gr->get_picture(PicMod_Game, posIco),
4512 boost::bind
4513@@ -153,9 +156,8 @@
4514 m_players[i] =
4515 new PlayerDescriptionGroup
4516 (this,
4517- m_xres / 25, y, m_xres * 16 / 25, m_yres * 17 / 500,
4518- settings, i,
4519- m_fn, m_fs);
4520+ get_w() / 25, y, get_w() * 16 / 25, get_h() * 17 / 500,
4521+ settings, i, font_small());
4522 }
4523 }
4524
4525
4526=== modified file 'src/ui_fsmenu/launchSPG.h'
4527--- src/ui_fsmenu/launchSPG.h 2010-10-29 19:21:59 +0000
4528+++ src/ui_fsmenu/launchSPG.h 2011-01-31 17:56:23 +0000
4529@@ -74,8 +74,6 @@
4530
4531 uint32_t m_butw;
4532 uint32_t m_buth;
4533- uint32_t m_fs;
4534- std::string m_fn;
4535
4536 UI::Callback_Button m_select_map, m_wincondition, m_back, m_ok;
4537 UI::Callback_Button * m_pos[MAX_PLAYERS];
4538
4539=== modified file 'src/ui_fsmenu/loadgame.cc'
4540--- src/ui_fsmenu/loadgame.cc 2011-01-30 15:56:20 +0000
4541+++ src/ui_fsmenu/loadgame.cc 2011-01-31 17:56:23 +0000
4542@@ -34,8 +34,8 @@
4543 Fullscreen_Menu_Base("choosemapmenu.jpg"),
4544
4545 // Values for alignment and size
4546- m_butw (m_xres / 4),
4547- m_buth (m_yres * 9 / 200),
4548+ m_butw (get_w() / 4),
4549+ m_buth (get_h() * 9 / 200),
4550 m_fs (fs_small()),
4551 m_fn (ui_fn()),
4552
4553@@ -45,48 +45,49 @@
4554 // Buttons
4555 m_back
4556 (this, "back",
4557- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
4558+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
4559 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4560 boost::bind(&Fullscreen_Menu_LoadGame::end_modal, boost::ref(*this), 0),
4561- _("Back"), std::string(), true, false,
4562- m_fn, m_fs),
4563+ _("Back"), std::string(), true, false),
4564 m_ok
4565 (this, "ok",
4566- m_xres * 71 / 100, m_yres * 15 / 20, m_butw, m_buth,
4567+ get_w() * 71 / 100, get_h() * 15 / 20, m_butw, m_buth,
4568 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4569 boost::bind(&Fullscreen_Menu_LoadGame::clicked_ok, boost::ref(*this)),
4570- _("OK"), std::string(), false, false,
4571- m_fn, m_fs),
4572+ _("OK"), std::string(), false, false),
4573 m_delete
4574 (this, "delete",
4575- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
4576+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
4577 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4578 boost::bind
4579 (&Fullscreen_Menu_LoadGame::clicked_delete, boost::ref(*this)),
4580- _("Delete"), std::string(), false, false,
4581- m_fn, m_fs),
4582+ _("Delete"), std::string(), false, false),
4583
4584 // Replay list
4585 m_list
4586- (this, m_xres * 47 / 2500, m_yres * 3417 / 10000,
4587- m_xres * 711 / 1250, m_yres * 6083 / 10000),
4588+ (this, get_w() * 47 / 2500, get_h() * 3417 / 10000,
4589+ get_w() * 711 / 1250, get_h() * 6083 / 10000),
4590
4591 // Text areas
4592 m_title
4593 (this,
4594- m_xres / 2, m_yres * 3 / 20,
4595+ get_w() / 2, get_h() * 3 / 20,
4596 _("Choose saved game!"), UI::Align_HCenter),
4597 m_label_mapname
4598 (this,
4599- m_xres * 7 / 10, m_yres * 17 / 50,
4600+ get_w() * 7 / 10, get_h() * 17 / 50,
4601 _("Map Name:"), UI::Align_Right),
4602- m_tamapname(this, m_xres * 71 / 100, m_yres * 17 / 50),
4603+ m_tamapname(this, get_w() * 71 / 100, get_h() * 17 / 50),
4604 m_label_gametime
4605 (this,
4606- m_xres * 7 / 10, m_yres * 3 / 8,
4607+ get_w() * 7 / 10, get_h() * 3 / 8,
4608 _("Gametime:"), UI::Align_Right),
4609- m_tagametime(this, m_xres * 71 / 100, m_yres * 3 / 8)
4610+ m_tagametime(this, get_w() * 71 / 100, get_h() * 3 / 8)
4611 {
4612+ m_back.set_font(font_small());
4613+ m_ok.set_font(font_small());
4614+ m_delete.set_font(font_small());
4615+
4616 m_title .set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
4617 m_label_mapname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4618 m_tamapname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4619
4620=== modified file 'src/ui_fsmenu/loadreplay.cc'
4621--- src/ui_fsmenu/loadreplay.cc 2010-11-02 11:13:59 +0000
4622+++ src/ui_fsmenu/loadreplay.cc 2011-01-31 17:56:23 +0000
4623@@ -30,45 +30,43 @@
4624 Fullscreen_Menu_Base("choosemapmenu.jpg"),
4625
4626 // Values for alignment and size
4627- m_butw (m_xres / 4),
4628- m_buth (m_yres * 19 / 400),
4629- m_fs (fs_small()),
4630- m_fn (ui_fn()),
4631+ m_butw (get_w() / 4),
4632+ m_buth (get_h() * 19 / 400),
4633
4634 // Buttons
4635 m_back
4636 (this, "back",
4637- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
4638+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
4639 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4640 boost::bind
4641 (&Fullscreen_Menu_LoadReplay::end_modal, boost::ref(*this), 0),
4642- _("Back"), std::string(), true, false,
4643- m_fn, m_fs),
4644+ _("Back"), std::string(), true, false),
4645 m_ok
4646 (this, "ok",
4647- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
4648+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
4649 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4650 boost::bind(&Fullscreen_Menu_LoadReplay::clicked_ok, boost::ref(*this)),
4651- _("OK"), std::string(), false, false,
4652- m_fn, m_fs),
4653+ _("OK"), std::string(), false, false),
4654
4655 // Replay list
4656 m_list
4657 (this,
4658- m_xres * 47 / 2500, m_yres * 3417 / 10000,
4659- m_xres * 711 / 1250, m_yres * 6083 / 10000),
4660+ get_w() * 47 / 2500, get_h() * 3417 / 10000,
4661+ get_w() * 711 / 1250, get_h() * 6083 / 10000),
4662
4663 // Text area
4664 m_title
4665 (this,
4666- m_xres / 2, m_yres * 3 / 20, _("Choose a replay!"),
4667+ get_w() / 2, get_h() * 3 / 20, _("Choose a replay!"),
4668 UI::Align_HCenter)
4669 {
4670- m_title.set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
4671- m_list .set_font(m_fn, m_fs);
4672+ m_title.set_textstyle(ts_big());
4673+ m_list .set_font(ui_fn(), fs_small());
4674 m_list .selected.set(this, &Fullscreen_Menu_LoadReplay::replay_selected);
4675 m_list .double_clicked.set
4676 (this, &Fullscreen_Menu_LoadReplay::double_clicked);
4677+ m_back.set_font(font_small());
4678+ m_ok.set_font(font_small());
4679 fill_list();
4680 }
4681
4682
4683=== modified file 'src/ui_fsmenu/loadreplay.h'
4684--- src/ui_fsmenu/loadreplay.h 2010-10-17 19:42:01 +0000
4685+++ src/ui_fsmenu/loadreplay.h 2011-01-31 17:56:23 +0000
4686@@ -41,10 +41,8 @@
4687 void fill_list();
4688
4689 private:
4690- uint32_t m_butw;
4691- uint32_t m_buth;
4692- uint32_t m_fs;
4693- std::string m_fn;
4694+ uint32_t m_butw;
4695+ uint32_t m_buth;
4696
4697 UI::Callback_Button m_back, m_ok;
4698 UI::Listselect<std::string> m_list;
4699
4700=== modified file 'src/ui_fsmenu/main.cc'
4701--- src/ui_fsmenu/main.cc 2010-11-02 11:13:59 +0000
4702+++ src/ui_fsmenu/main.cc 2011-01-31 17:56:23 +0000
4703@@ -26,108 +26,107 @@
4704 Fullscreen_Menu_Base("mainmenu.jpg"),
4705
4706 // Values for alignment and size
4707- m_butx (m_xres * 13 / 40),
4708- m_butw (m_xres * 7 / 20),
4709- m_buth (m_yres * 19 / 400),
4710- m_fs (fs_small()),
4711- m_fn (ui_fn()),
4712+ m_butx (get_w() * 13 / 40),
4713+ m_butw (get_w() * 7 / 20),
4714+ m_buth (get_h() * 19 / 400),
4715 wlcr (WLCR),
4716
4717 // Buttons
4718 playtutorial
4719 (this, "play_tutorial",
4720- m_butx, m_yres * 42 / 200, m_butw, m_buth,
4721+ m_butx, get_h() * 42 / 200, m_butw, m_buth,
4722 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4723 boost::bind
4724 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4725 static_cast<int32_t>(mm_playtutorial)),
4726- _("Play Tutorial"), std::string(), true, false,
4727- m_fn, m_fs),
4728+ _("Play Tutorial"), std::string(), true, false),
4729 singleplayer
4730 (this, "single_player",
4731- m_butx, m_yres * 61 / 200, m_butw, m_buth,
4732+ m_butx, get_h() * 61 / 200, m_butw, m_buth,
4733 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4734 boost::bind
4735 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4736 static_cast<int32_t>(mm_singleplayer)),
4737- _("Single Player"), std::string(), true, false,
4738- m_fn, m_fs),
4739+ _("Single Player"), std::string(), true, false),
4740 multiplayer
4741 (this, "multi_player",
4742- m_butx, m_yres * 37 / 100, m_butw, m_buth,
4743+ m_butx, get_h() * 37 / 100, m_butw, m_buth,
4744 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4745 boost::bind
4746 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4747 static_cast<int32_t>(mm_multiplayer)),
4748- _("Multi Player"), std::string(), true, false,
4749- m_fn, m_fs),
4750+ _("Multi Player"), std::string(), true, false),
4751 replay
4752 (this, "replay",
4753- m_butx, m_yres * 87 / 200, m_butw, m_buth,
4754+ m_butx, get_h() * 87 / 200, m_butw, m_buth,
4755 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4756 boost::bind
4757 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4758 static_cast<int32_t>(mm_replay)),
4759- _("Watch Replay"), std::string(), true, false,
4760- m_fn, m_fs),
4761+ _("Watch Replay"), std::string(), true, false),
4762 editor
4763 (this, "editor",
4764- m_butx, m_yres * 100 / 200, m_butw, m_buth,
4765+ m_butx, get_h() * 100 / 200, m_butw, m_buth,
4766 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4767 boost::bind
4768 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4769 static_cast<int32_t>(mm_editor)),
4770- _("Editor"), std::string(), true, false,
4771- m_fn, m_fs),
4772+ _("Editor"), std::string(), true, false),
4773 options
4774 (this, "options",
4775- m_butx, m_yres * 119 / 200, m_butw, m_buth,
4776+ m_butx, get_h() * 119 / 200, m_butw, m_buth,
4777 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4778 boost::bind
4779 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4780 static_cast<int32_t>(mm_options)),
4781- _("Options"), std::string(), true, false,
4782- m_fn, m_fs),
4783+ _("Options"), std::string(), true, false),
4784 readme
4785 (this, "readme",
4786- m_butx, m_yres * 138 / 200, m_butw, m_buth,
4787+ m_butx, get_h() * 138 / 200, m_butw, m_buth,
4788 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4789 boost::bind
4790 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4791 static_cast<int32_t>(mm_readme)),
4792- _("View Readme"), std::string(), true, false,
4793- m_fn, m_fs),
4794+ _("View Readme"), std::string(), true, false),
4795 license
4796 (this, "license",
4797- m_butx, m_yres * 151 / 200, m_butw, m_buth,
4798+ m_butx, get_h() * 151 / 200, m_butw, m_buth,
4799 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4800 boost::bind
4801 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4802 static_cast<int32_t>(mm_license)),
4803- _("License"), std::string(), true, false,
4804- m_fn, m_fs),
4805+ _("License"), std::string(), true, false),
4806 exit
4807 (this, "exit",
4808- m_butx, m_yres * 178 / 200, m_butw, m_buth,
4809+ m_butx, get_h() * 178 / 200, m_butw, m_buth,
4810 g_gr->get_picture(PicMod_UI, "pics/but3.png"),
4811 boost::bind
4812 (&Fullscreen_Menu_Main::end_modal, boost::ref(*this),
4813 static_cast<int32_t>(mm_exit)),
4814- _("Exit Game"), std::string(), true, false,
4815- m_fn, m_fs),
4816+ _("Exit Game"), std::string(), true, false),
4817
4818 // Textlabels
4819 version
4820 (this,
4821- m_xres, m_yres,
4822+ get_w(), get_h(),
4823 _("Version ") + build_id() + '(' + build_type() + ')',
4824 UI::Align_BottomRight),
4825 copyright
4826 (this,
4827- 0, m_yres,
4828+ 0, get_h(),
4829 (wlcr + _("by the Widelands Development Team")).c_str(),
4830 UI::Align_BottomLeft)
4831 {
4832- version.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4833- copyright.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4834+ playtutorial.set_font(font_small());
4835+ singleplayer.set_font(font_small());
4836+ multiplayer.set_font(font_small());
4837+ replay.set_font(font_small());
4838+ editor.set_font(font_small());
4839+ options.set_font(font_small());
4840+ readme.set_font(font_small());
4841+ license.set_font(font_small());
4842+ exit.set_font(font_small());
4843+
4844+ version.set_textstyle(ts_small());
4845+ copyright.set_textstyle(ts_small());
4846 }
4847
4848=== modified file 'src/ui_fsmenu/main.h'
4849--- src/ui_fsmenu/main.h 2010-10-17 19:42:01 +0000
4850+++ src/ui_fsmenu/main.h 2011-01-31 17:56:23 +0000
4851@@ -46,8 +46,6 @@
4852 uint32_t m_butx;
4853 uint32_t m_butw;
4854 uint32_t m_buth;
4855- uint32_t m_fs;
4856- std::string m_fn;
4857 std::string wlcr;
4858 UI::Callback_Button playtutorial;
4859 UI::Callback_Button singleplayer;
4860
4861=== modified file 'src/ui_fsmenu/mapselect.cc'
4862--- src/ui_fsmenu/mapselect.cc 2010-11-05 21:46:43 +0000
4863+++ src/ui_fsmenu/mapselect.cc 2011-01-31 17:56:23 +0000
4864@@ -38,102 +38,101 @@
4865 Fullscreen_Menu_Base("choosemapmenu.jpg"),
4866
4867 // Values for alignment and size
4868- m_butw (m_xres / 4),
4869- m_buth (m_yres * 9 / 200),
4870- m_fs (fs_small()),
4871- m_fn (ui_fn()),
4872+ m_butw (get_w() / 4),
4873+ m_buth (get_h() * 9 / 200),
4874
4875 // Text labels
4876 m_title
4877 (this,
4878- m_xres / 2, m_yres * 9 / 50,
4879+ get_w() / 2, get_h() * 9 / 50,
4880 _("Choose your map!"),
4881 UI::Align_HCenter),
4882 m_label_load_map_as_scenario
4883 (this,
4884- m_xres * 23 / 25, m_yres * 11 / 40,
4885+ get_w() * 23 / 25, get_h() * 11 / 40,
4886 _("Load Map as scenario: "),
4887 UI::Align_Right),
4888 m_label_name
4889 (this,
4890- m_xres * 7 / 10, m_yres * 17 / 50,
4891+ get_w() * 7 / 10, get_h() * 17 / 50,
4892 _("Name:"),
4893 UI::Align_Right),
4894- m_name (this, m_xres * 71 / 100, m_yres * 17 / 50),
4895+ m_name (this, get_w() * 71 / 100, get_h() * 17 / 50),
4896 m_label_author
4897 (this,
4898- m_xres * 7 / 10, m_yres * 3 / 8,
4899+ get_w() * 7 / 10, get_h() * 3 / 8,
4900 _("Author:"),
4901 UI::Align_Right),
4902- m_author (this, m_xres * 71 / 100, m_yres * 3 / 8),
4903+ m_author (this, get_w() * 71 / 100, get_h() * 3 / 8),
4904 m_label_size
4905 (this,
4906- m_xres * 7 / 10, m_yres * 41 / 100,
4907+ get_w() * 7 / 10, get_h() * 41 / 100,
4908 _("Size:"),
4909 UI::Align_Right),
4910- m_size (this, m_xres * 71 / 100, m_yres * 41 / 100),
4911+ m_size (this, get_w() * 71 / 100, get_h() * 41 / 100),
4912 m_label_world
4913 (this,
4914- m_xres * 7 / 10, m_yres * 89 / 200,
4915+ get_w() * 7 / 10, get_h() * 89 / 200,
4916 _("World:"),
4917 UI::Align_Right),
4918- m_world (this, m_xres * 71 / 100, m_yres * 89 / 200),
4919+ m_world (this, get_w() * 71 / 100, get_h() * 89 / 200),
4920 m_label_nr_players
4921 (this,
4922- m_xres * 7 / 10, m_yres * 12 / 25,
4923+ get_w() * 7 / 10, get_h() * 12 / 25,
4924 _("Players:"),
4925 UI::Align_Right),
4926- m_nr_players (this, m_xres * 71 / 100, m_yres * 12 / 25),
4927+ m_nr_players (this, get_w() * 71 / 100, get_h() * 12 / 25),
4928 m_label_descr
4929 (this,
4930- m_xres * 7 / 10, m_yres * 103 / 200,
4931+ get_w() * 7 / 10, get_h() * 103 / 200,
4932 _("Descr:"),
4933 UI::Align_Right),
4934 m_descr
4935 (this,
4936- m_xres * 71 / 100, m_yres * 13 / 25, m_xres / 4, m_yres * 63 / 200),
4937+ get_w() * 71 / 100, get_h() * 13 / 25, get_w() / 4, get_h() * 63 / 200),
4938
4939 // Buttons
4940 m_back
4941 (this, "back",
4942- m_xres * 71 / 100, m_yres * 17 / 20, m_butw, m_buth,
4943+ get_w() * 71 / 100, get_h() * 17 / 20, m_butw, m_buth,
4944 g_gr->get_picture(PicMod_UI, "pics/but0.png"),
4945 boost::bind(&Fullscreen_Menu_MapSelect::end_modal, boost::ref(*this), 0),
4946- _("Back"), std::string(), true, false,
4947- m_fn, m_fs),
4948+ _("Back"), std::string(), true, false),
4949 m_ok
4950 (this, "ok",
4951- m_xres * 71 / 100, m_yres * 9 / 10, m_butw, m_buth,
4952+ get_w() * 71 / 100, get_h() * 9 / 10, m_butw, m_buth,
4953 g_gr->get_picture(PicMod_UI, "pics/but2.png"),
4954 boost::bind(&Fullscreen_Menu_MapSelect::ok, boost::ref(*this)),
4955- _("OK"), std::string(), false, false,
4956- m_fn, m_fs),
4957+ _("OK"), std::string(), false, false),
4958
4959 // Checkbox
4960- m_load_map_as_scenario (this, Point (m_xres * 187 / 200, m_yres * 7 / 25)),
4961+ m_load_map_as_scenario (this, Point (get_w() * 187 / 200, get_h() * 7 / 25)),
4962
4963 // Map table
4964 m_table
4965 (this,
4966- m_xres * 47 / 2500, m_yres * 3417 / 10000,
4967- m_xres * 711 / 1250, m_yres * 6083 / 10000),
4968+ get_w() * 47 / 2500, get_h() * 3417 / 10000,
4969+ get_w() * 711 / 1250, get_h() * 6083 / 10000),
4970 m_curdir("maps"), m_basedir("maps")
4971 {
4972- m_title.set_font(m_fn, fs_big(), UI_FONT_CLR_FG);
4973- m_label_load_map_as_scenario.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4974- m_label_name .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4975- m_name .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4976- m_label_author .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4977- m_author .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4978- m_label_size .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4979- m_size .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4980- m_label_world .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4981- m_world .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4982- m_label_nr_players .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4983- m_nr_players .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4984- m_label_descr .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4985- m_descr .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
4986- m_table .set_font(m_fn, m_fs);
4987+ m_title.set_textstyle(ts_big());
4988+ m_label_load_map_as_scenario.set_textstyle(ts_small());
4989+ m_label_name .set_textstyle(ts_small());
4990+ m_name .set_textstyle(ts_small());
4991+ m_label_author .set_textstyle(ts_small());
4992+ m_author .set_textstyle(ts_small());
4993+ m_label_size .set_textstyle(ts_small());
4994+ m_size .set_textstyle(ts_small());
4995+ m_label_world .set_textstyle(ts_small());
4996+ m_world .set_textstyle(ts_small());
4997+ m_label_nr_players .set_textstyle(ts_small());
4998+ m_nr_players .set_textstyle(ts_small());
4999+ m_label_descr .set_textstyle(ts_small());
5000+ m_descr .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to status/vote changes: