Merge lp:~vanvugt/unity/fix-1010348 into lp:unity

Proposed by Daniel van Vugt
Status: Superseded
Proposed branch: lp:~vanvugt/unity/fix-1010348
Merge into: lp:unity
Diff against target: 48 lines (+30/-1)
1 file modified
launcher/BamfLauncherIcon.cpp (+30/-1)
To merge this branch: bzr merge lp:~vanvugt/unity/fix-1010348
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+109307@code.launchpad.net

This proposal has been superseded by a proposal from 2012-06-10.

Commit message

Fix build failure with Nux 2.x. (LP: #1010348)

Don't depend on Nux 3.x API changes until it becomes necessary.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Can we have unit test for this?

Btw if I remember correctly when you do nux::Color(0xaabbccdd) nux create a nux color with
red = 0xbb
green = 0xcc
blue = 0xdd
alpha = 0xaa

and *not*
red = 0xaa
green = 0xbb
blue = 0xcc
alpha = 0xdd

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Fair question. And the answer is: Not today.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/BamfLauncherIcon.cpp'
2--- launcher/BamfLauncherIcon.cpp 2012-06-01 09:33:15 +0000
3+++ launcher/BamfLauncherIcon.cpp 2012-06-08 08:20:24 +0000
4@@ -782,6 +782,35 @@
5 }
6 }
7
8+//
9+// ParseColor:
10+// Parses a color string in the form: #rrggbbaa, where # and aa are optional.
11+//
12+// In Nux 3.x, this function is superseded by:
13+// nux::color::Color(std::string const& hex)
14+// (even though this function is much smaller and faster)
15+//
16+// I would really like to #if NUX_VERSION <= ... around this code, but
17+// no such integer macro seems to exist in the Nux headers.
18+//
19+static unsigned int ParseColor(const char *str)
20+{
21+ unsigned int ret = 0;
22+ if (str)
23+ {
24+ const char *hex = str[0] == '#' ? str + 1 : str;
25+ int digits = 0, color = 0;
26+ if (sscanf(hex, "%x%n", &color, &digits))
27+ {
28+ if (digits == 8)
29+ ret = (unsigned int)color;
30+ else if (digits == 6)
31+ ret = (unsigned int)color << 8;
32+ }
33+ }
34+ return ret;
35+}
36+
37 void BamfLauncherIcon::UpdateBackgroundColor()
38 {
39 bool last_use_custom_bg_color = use_custom_bg_color_;
40@@ -792,7 +821,7 @@
41 use_custom_bg_color_ = !color.empty();
42
43 if (use_custom_bg_color_)
44- bg_color_ = nux::Color(color);
45+ bg_color_ = nux::Color(ParseColor(color.c_str()));
46
47 if (last_use_custom_bg_color != use_custom_bg_color_ ||
48 last_bg_color != bg_color_)