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

Proposed by Daniel van Vugt
Status: Merged
Approved by: Sam Spilsbury
Approved revision: no longer in the source branch.
Merged at revision: 2398
Proposed branch: lp:~vanvugt/unity/fix-1010348
Merge into: lp:unity
Diff against target: 98 lines (+60/-1)
3 files modified
launcher/BamfLauncherIcon.cpp (+33/-1)
launcher/BamfLauncherIcon.h (+2/-0)
tests/test_bamflaunchericon.cpp (+25/-0)
To merge this branch: bzr merge lp:~vanvugt/unity/fix-1010348
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Sam Spilsbury (community) Approve
Review via email: mp+109519@code.launchpad.net

This proposal supersedes a proposal from 2012-06-08.

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 : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

Fair question. And the answer is: Not today.

Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Unit tests pass for me.

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

One thing this misses is the support for the 3 digits hex codes... i.e. #abc == #aabbcc...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/BamfLauncherIcon.cpp'
--- launcher/BamfLauncherIcon.cpp 2012-06-01 09:33:15 +0000
+++ launcher/BamfLauncherIcon.cpp 2012-06-10 09:49:20 +0000
@@ -782,6 +782,38 @@
782 }782 }
783}783}
784784
785//
786// ColorStrToARGB:
787// Parses a color string in the form: "#rrggbbaa", where # and aa are optional.
788// Returns the color in 32-bit ARGB format: 0xaarrggbb.
789//
790// In Nux 3.x, this function is superseded by:
791// nux::color::Color(std::string const& hex)
792// (even though this function is much smaller and faster)
793//
794// I would really like to #if NUX_VERSION <= ... around this code, but
795// no such integer macro seems to exist in the Nux headers.
796//
797unsigned int ColorStrToARGB(const char *str)
798{
799 unsigned int ret = 0;
800 if (str)
801 {
802 const char *hex = str[0] == '#' ? str + 1 : str;
803 int digits = 0, color = 0;
804 if (sscanf(hex, "%x%n", &color, &digits))
805 {
806 if (hex[digits]) // extra characters after the hex
807 ret = 0;
808 else if (digits == 6)
809 ret = (unsigned int)color | 0xff000000;
810 else if (digits == 8) // Convert RGBA to ARGB:
811 ret = ((unsigned int)color >> 8) | ((unsigned int)color << 24);
812 }
813 }
814 return ret;
815}
816
785void BamfLauncherIcon::UpdateBackgroundColor()817void BamfLauncherIcon::UpdateBackgroundColor()
786{818{
787 bool last_use_custom_bg_color = use_custom_bg_color_;819 bool last_use_custom_bg_color = use_custom_bg_color_;
@@ -792,7 +824,7 @@
792 use_custom_bg_color_ = !color.empty();824 use_custom_bg_color_ = !color.empty();
793825
794 if (use_custom_bg_color_)826 if (use_custom_bg_color_)
795 bg_color_ = nux::Color(color);827 bg_color_ = nux::Color(ColorStrToARGB(color.c_str()));
796828
797 if (last_use_custom_bg_color != use_custom_bg_color_ ||829 if (last_use_custom_bg_color != use_custom_bg_color_ ||
798 last_bg_color != bg_color_)830 last_bg_color != bg_color_)
799831
=== modified file 'launcher/BamfLauncherIcon.h'
--- launcher/BamfLauncherIcon.h 2012-05-28 16:16:06 +0000
+++ launcher/BamfLauncherIcon.h 2012-06-10 09:49:20 +0000
@@ -34,6 +34,8 @@
34namespace launcher34namespace launcher
35{35{
3636
37extern unsigned int ColorStrToARGB(const char *str);
38
37class Launcher;39class Launcher;
3840
39class BamfLauncherIcon : public SimpleLauncherIcon41class BamfLauncherIcon : public SimpleLauncherIcon
4042
=== modified file 'tests/test_bamflaunchericon.cpp'
--- tests/test_bamflaunchericon.cpp 2012-06-06 15:42:07 +0000
+++ tests/test_bamflaunchericon.cpp 2012-06-10 09:49:20 +0000
@@ -65,4 +65,29 @@
65 EXPECT_EQ(color.alpha, 0xff / 255.0f);65 EXPECT_EQ(color.alpha, 0xff / 255.0f);
66}66}
6767
68TEST_F(TestBamfLauncherIcon, TestColorStringConversion)
69{
70 EXPECT_EQ(launcher::ColorStrToARGB("#12345678"), 0x78123456);
71 EXPECT_EQ(launcher::ColorStrToARGB("12345678"), 0x78123456);
72 EXPECT_EQ(launcher::ColorStrToARGB("#12345678q"), 0x0);
73 EXPECT_EQ(launcher::ColorStrToARGB("12345678q"), 0x0);
74 EXPECT_EQ(launcher::ColorStrToARGB("#1234567890"), 0x0);
75 EXPECT_EQ(launcher::ColorStrToARGB("1234567890"), 0x0);
76 EXPECT_EQ(launcher::ColorStrToARGB("#AABBCC"), 0xFFAABBCC);
77 EXPECT_EQ(launcher::ColorStrToARGB("AABBCC"), 0xFFAABBCC);
78 EXPECT_EQ(launcher::ColorStrToARGB("#eeddccbb"), 0xBBEEDDCC);
79 EXPECT_EQ(launcher::ColorStrToARGB("eeddccbb"), 0xBBEEDDCC);
80 EXPECT_EQ(launcher::ColorStrToARGB("#2040"), 0x0);
81 EXPECT_EQ(launcher::ColorStrToARGB("2040"), 0x0);
82 EXPECT_EQ(launcher::ColorStrToARGB("#2040809"), 0x0);
83 EXPECT_EQ(launcher::ColorStrToARGB("2040809"), 0x0);
84 EXPECT_EQ(launcher::ColorStrToARGB("#204080"), 0xFF204080);
85 EXPECT_EQ(launcher::ColorStrToARGB("204080"), 0xFF204080);
86 EXPECT_EQ(launcher::ColorStrToARGB("#blah"), 0x0);
87 EXPECT_EQ(launcher::ColorStrToARGB("blah"), 0x0);
88 EXPECT_EQ(launcher::ColorStrToARGB("#"), 0x0);
89 EXPECT_EQ(launcher::ColorStrToARGB(""), 0x0);
90 EXPECT_EQ(launcher::ColorStrToARGB("helloworld helloworld !!!!"), 0x0);
91}
92
68}93}