← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/buttons into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/buttons into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/buttons/+merge/274064

Buttons now use the new font renderer and have uniform font size and style (the style was uniform in practice, but there was some code to set it individually that I got rid of).

Deleted draw_caret in Button class because it is unused.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/buttons into lp:widelands.
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc	2015-09-26 09:07:40 +0000
+++ src/ui_basic/button.cc	2015-10-11 09:50:18 +0000
@@ -20,7 +20,7 @@
 #include "ui_basic/button.h"
 
 #include "base/log.h"
-#include "graphic/font_handler.h"
+#include "graphic/font_handler1.h"
 #include "graphic/image.h"
 #include "graphic/rendertarget.h"
 #include "graphic/text_constants.h"
@@ -54,14 +54,11 @@
 	m_title         (title_text),
 	m_pic_background(bg_pic),
 	m_pic_custom    (nullptr),
-	m_textstyle(UI::TextStyle::ui_small()),
-	m_clr_down      (229, 161, 2),
-	m_draw_caret    (false)
+	m_clr_down      (229, 161, 2)
 {
 	// Automatically resize for font height and give it a margin.
 	if (h < 1) {
-		int new_height = m_textstyle.font->height() + 4;
-		set_desired_size(w, new_height);
+		set_desired_size(w, UI::g_fh1->render(as_uifont("."))->height() + 4);
 	}
 	set_thinks(false);
 }
@@ -87,9 +84,7 @@
 	m_time_nextact  (0),
 	m_pic_background(bg_pic),
 	m_pic_custom    (fg_pic),
-	m_textstyle(UI::TextStyle::ui_small()),
-	m_clr_down      (229, 161, 2),
-	m_draw_caret    (false)
+	m_clr_down      (229, 161, 2)
 {
 	set_thinks(false);
 }
@@ -219,14 +214,13 @@
 		}
 
 	} else if (m_title.length()) {
-		//  otherwise draw title string centered
-
-		m_textstyle.fg = m_enabled ? UI_FONT_CLR_FG : UI_FONT_CLR_DISABLED;
-
-		UI::g_fh->draw_text
-			(dst, m_textstyle, Point(get_w() / 2, get_h() / 2),
-			 m_title, Align_Center,
-			 m_draw_caret ? m_title.length() : std::numeric_limits<uint32_t>::max());
+		//  Otherwise draw title string centered
+		const Image* entry_text_im = UI::g_fh1->render(
+												  as_uifont(m_title,
+																UI_FONT_SIZE_SMALL,
+																m_enabled ? UI_FONT_CLR_FG : UI_FONT_CLR_DISABLED));
+		dst.blit(Point((get_w() - entry_text_im->width()) / 2, (get_h() - entry_text_im->height()) / 2),
+					entry_text_im);
 	}
 
 	//  draw border

=== modified file 'src/ui_basic/button.h'
--- src/ui_basic/button.h	2015-09-11 07:19:29 +0000
+++ src/ui_basic/button.h	2015-10-11 09:50:18 +0000
@@ -65,9 +65,6 @@
 	bool enabled() const {return m_enabled;}
 	void set_enabled(bool on);
 	void set_repeating(bool const on) {m_repeating = on;}
-	void set_draw_caret(bool draw_caret) {m_draw_caret = draw_caret;}
-	void set_font(Font * font) {m_textstyle.font = font;}
-	void set_textstyle(const UI::TextStyle& textstyle) {m_textstyle = textstyle;}
 	bool is_snap_target() const override {return true;}
 
 	// Drawing and event handlers
@@ -110,10 +107,8 @@
 
 	const Image* m_pic_background; //  background texture (picture ID)
 	const Image* m_pic_custom;     //  custom icon on the button
-	UI::TextStyle m_textstyle;
 
 	RGBColor    m_clr_down; //  color of border while a flat button is "down"
-	bool        m_draw_caret;
 };
 
 } // namespace UI

=== modified file 'src/ui_basic/helpwindow.cc'
--- src/ui_basic/helpwindow.cc	2015-10-02 07:02:00 +0000
+++ src/ui_basic/helpwindow.cc	2015-10-11 09:50:18 +0000
@@ -85,9 +85,6 @@
 		 g_gr->images().get("pics/but5.png"),
 		 _("OK"), std::string(), true, false);
 	btn->sigclicked.connect(boost::bind(&HelpWindow::clicked_ok, boost::ref(*this)));
-	btn->set_font(Font::get((UI::g_fh1->fontset()).serif(),
-									(fontsize < 12 ? 12 : fontsize)));
-
 	textarea->set_size(in_width - 10, in_height - 10 - (2 * but_height));
 	focus();
 }

=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc	2015-07-29 08:05:50 +0000
+++ src/ui_basic/spinbox.cc	2015-10-11 09:50:18 +0000
@@ -173,8 +173,6 @@
 
 	m_buttons.push_back(sbi->butMinus);
 	m_buttons.push_back(sbi->butPlus);
-
-	set_font(UI::g_fh1->fontset().serif(), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG);
 }
 
 SpinBox::~SpinBox() {
@@ -296,32 +294,6 @@
 
 
 /**
- * Sets the font of all UI elements
- *
- * @deprecated, see set_textstyle
- */
-void SpinBox::set_font(const std::string & name, int32_t size, RGBColor color)
-{
-	set_textstyle(TextStyle::makebold(Font::get(name, size), color));
-}
-
-/**
- * Sets the font and textstyle of all UI elements
- */
-void SpinBox::set_textstyle(const TextStyle & textstyle)
-{
-	sbi->text->set_textstyle(textstyle);
-	sbi->butPlus->set_font(textstyle.font);
-	sbi->butMinus->set_font(textstyle.font);
-	if (m_big) {
-		sbi->butTenPlus->set_font(textstyle.font);
-		sbi->butTenMinus->set_font(textstyle.font);
-	}
-	update();
-}
-
-
-/**
  * Searches for value in sbi->valrep
  * \returns the place where value was found or -1 if the value wasn't found.
  */

=== modified file 'src/ui_basic/spinbox.h'
--- src/ui_basic/spinbox.h	2014-09-29 19:25:24 +0000
+++ src/ui_basic/spinbox.h	2015-10-11 09:50:18 +0000
@@ -53,8 +53,6 @@
 	std::string get_unit();
 	Align align() const;
 	void set_align(Align);
-	void set_font(const std::string &, int32_t, RGBColor);
-	void set_textstyle(const TextStyle & style);
 	void add_replacement(int32_t, std::string);
 	void remove_replacement(int32_t);
 	bool has_replacement(int32_t);

=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2015-09-26 09:07:40 +0000
+++ src/ui_basic/table.cc	2015-10-11 09:50:18 +0000
@@ -108,7 +108,6 @@
 					 title, tooltip_string, true, false);
 			c.btn->sigclicked.connect
 				(boost::bind(&Table::header_button_clicked, boost::ref(*this), m_columns.size()));
-			c.btn->set_font(Font::get(m_fontname, m_fontsize));
 		}
 		c.width = width;
 		c.alignment = alignment;
@@ -157,7 +156,6 @@
 				 title, "", true, false);
 		column.btn->sigclicked.connect
 			(boost::bind(&Table::header_button_clicked, boost::ref(*this), col));
-		column.btn->set_font(Font::get(m_fontname, m_fontsize));
 	} else if (title.empty()) { //  had title before, not now
 		if (column.btn) {
 			delete column.btn;

=== modified file 'src/wui/multiplayersetupgroup.cc'
--- src/wui/multiplayersetupgroup.cc	2015-09-04 06:16:58 +0000
+++ src/wui/multiplayersetupgroup.cc	2015-10-11 09:50:18 +0000
@@ -69,7 +69,6 @@
 			type->sigclicked.connect
 				(boost::bind
 					 (&MultiPlayerClientGroup::toggle_type, boost::ref(*this)));
-			type->set_font(font);
 			add(type, UI::Box::AlignCenter);
 		} else { // just a shown client
 			type_icon = new UI::Icon
@@ -156,7 +155,6 @@
 		 int32_t const /* x */, int32_t const /* y */, int32_t const w, int32_t const h,
 		 GameSettingsProvider * const settings,
 		 NetworkPlayerSettingsBackend * const npsb,
-		 UI::Font * font,
 		 std::map<std::string, const Image* > & tp,
 		 std::map<std::string, std::string> & tn)
 		 :
@@ -186,7 +184,6 @@
 		type->sigclicked.connect
 			(boost::bind
 				 (&MultiPlayerPlayerGroup::toggle_type, boost::ref(*this)));
-		type->set_font(font);
 		add(type, UI::Box::AlignCenter);
 		tribe = new UI::Button
 			(this, "player_tribe",
@@ -196,7 +193,6 @@
 		tribe->sigclicked.connect
 			(boost::bind
 				 (&MultiPlayerPlayerGroup::toggle_tribe, boost::ref(*this)));
-		tribe->set_font(font);
 		add(tribe, UI::Box::AlignCenter);
 		tribe->set_draw_flat_background(true);
 		init = new UI::Button
@@ -207,7 +203,6 @@
 		init->sigclicked.connect
 			(boost::bind
 				 (&MultiPlayerPlayerGroup::toggle_init, boost::ref(*this)));
-		init->set_font(font);
 		add(init, UI::Box::AlignCenter);
 		team = new UI::Button
 			(this, "player_team",
@@ -217,7 +212,6 @@
 		team->sigclicked.connect
 			(boost::bind
 				 (&MultiPlayerPlayerGroup::toggle_team, boost::ref(*this)));
-		team->set_font(font);
 		add(team, UI::Box::AlignCenter);
 	}
 
@@ -466,7 +460,7 @@
 		multi_player_player_groups.at(i) = new MultiPlayerPlayerGroup
 			(&playerbox, i,
 			 0, 0, playerbox.get_w(), buth,
-			 s, npsb.get(), UI::Font::get(fname, fsize),
+			 s, npsb.get(),
 			 m_tribepics, m_tribenames);
 		playerbox.add(multi_player_player_groups.at(i), 1);
 	}


Follow ups