← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1509791 into lp:widelands

 

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

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1509791 in widelands: "Flickering while mouseover the first time"
  https://bugs.launchpad.net/widelands/+bug/1509791

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1509791/+merge/278243

Fixes flickering with mouse over wares in warehouse window.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1509791 into lp:widelands.
=== modified file 'src/ui_basic/textarea.cc'
--- src/ui_basic/textarea.cc	2015-10-03 07:21:52 +0000
+++ src/ui_basic/textarea.cc	2015-11-22 08:23:34 +0000
@@ -96,6 +96,11 @@
 	if (m_layoutmode == AutoMove)
 		collapse();
 	m_textstyle = style;
+	rendered_text_ = UI::g_fh1->render(
+									as_uifont(m_text,
+												 m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
+												 m_textstyle.fg));
+
 	if (m_layoutmode == AutoMove)
 		expand();
 	else if (m_layoutmode == Layouted)
@@ -123,6 +128,10 @@
 		collapse(); // collapse() implicitly updates
 
 	m_text = text;
+	rendered_text_ = UI::g_fh1->render(
+									as_uifont(m_text,
+												 m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
+												 m_textstyle.fg));
 	if (m_layoutmode == AutoMove)
 		expand();
 	else if (m_layoutmode == Layouted)
@@ -149,13 +158,7 @@
 			 m_align & Align_VCenter ?
 			 get_h() / 2 : m_align & Align_Bottom ? get_h() : 0);
 
-		dst.blit(anchor,
-				 UI::g_fh1->render(
-						as_uifont(m_text,
-									 m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
-									 m_textstyle.fg)),
-				 BlendMode::UseAlpha,
-				 m_align);
+		dst.blit(anchor, rendered_text_, BlendMode::UseAlpha, m_align);
 	}
 }
 
@@ -192,19 +195,10 @@
 {
 	int32_t x = get_x();
 	int32_t y = get_y();
-	const Image* image = UI::g_fh1->render(
-									as_uifont(m_text,
-												 m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
-												 m_textstyle.fg));
-	uint32_t w = image->width();
-	uint16_t h = image->height();
-	// We want empty textareas to have height
-	if (m_text.empty()) {
-		h = UI::g_fh1->render(
-				 as_uifont(".",
-							  m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
-							  m_textstyle.fg))->height();
-	}
+
+	update_desired_size();
+	uint32_t w, h;
+	get_desired_size(w, h);
 
 	if      (m_align & Align_HCenter)
 		x -= w >> 1;
@@ -225,18 +219,19 @@
  */
 void Textarea::update_desired_size()
 {
-	const Image* image = UI::g_fh1->render(
-									as_uifont(m_text,
-												 m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
-												 m_textstyle.fg));
-	uint32_t w = image->width();
-	uint16_t h = image->height();
-	// We want empty textareas to have height
-	if (m_text.empty()) {
-		h = UI::g_fh1->render(
-				 as_uifont(".",
-							  m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
-							  m_textstyle.fg))->height();
+	uint32_t w = 0;
+	uint16_t h = 0;
+
+	if (rendered_text_) {
+		w = rendered_text_->width();
+		h = rendered_text_->height();
+		// We want empty textareas to have height
+		if (m_text.empty()) {
+			h = UI::g_fh1->render(
+					 as_uifont(".",
+								  m_textstyle.font->size() - UI::g_fh1->fontset().size_offset(),
+								  m_textstyle.fg))->height();
+		}
 	}
 	set_desired_size(w, h);
 }

=== modified file 'src/ui_basic/textarea.h'
--- src/ui_basic/textarea.h	2014-11-27 12:02:08 +0000
+++ src/ui_basic/textarea.h	2015-11-22 08:23:34 +0000
@@ -96,7 +96,7 @@
 
 	LayoutMode m_layoutmode;
 	std::string m_text;
-	const Image* m_text_image;
+	const Image* rendered_text_;
 	Align m_align;
 	UI::TextStyle m_textstyle;
 };

=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc	2015-11-11 09:52:55 +0000
+++ src/wui/waresdisplay.cc	2015-11-22 08:23:34 +0000
@@ -56,7 +56,7 @@
 	m_curware
 		(this,
 		 0, get_inner_h() - 25, get_inner_w(), 20,
-		 _("Stock"), UI::Align_Center),
+		 "", UI::Align_Center),
 
 	m_selectable(selectable),
 	m_horizontal(horizontal),
@@ -67,8 +67,17 @@
 		m_selected.insert(std::make_pair(index, false));
 		m_hidden.insert(std::make_pair(index, false));
 		m_in_selection.insert(std::make_pair(index, false));
+
+		// Prerender all texts to avoid flickering with mouseover
+		m_curware.set_text(index != Widelands::INVALID_INDEX ?
+									 (m_type == Widelands::wwWORKER ?
+										  m_tribe.get_worker_descr(index)->descname() :
+										  m_tribe.get_ware_descr(index)->descname()) :
+									 "");
 	}
 
+	m_curware.set_text(_("Stock"));
+
 	// Find out geometry from icons_order
 	unsigned int columns = icons_order().size();
 	unsigned int rows = 0;


Follow ups