Merge lp:~mhr3/libunity/colorized-icon into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 285
Merged at revision: 284
Proposed branch: lp:~mhr3/libunity/colorized-icon
Merge into: lp:libunity
Diff against target: 165 lines (+59/-4)
7 files modified
configure.ac (+1/-1)
debian/changelog (+6/-2)
debian/libunity9.symbols (+1/-0)
protocol/Makefile.am (+1/-1)
protocol/protocol-icon.vala (+26/-0)
src/unity-icon.vala (+5/-0)
test/vala/test-previews.vala (+19/-0)
To merge this branch: bzr merge lp:~mhr3/libunity/colorized-icon
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+182363@code.launchpad.net

Commit message

Add API to colorize icons using Unity.AnnotatedIcon

Description of the change

Add API to colorize icons using Unity.AnnotatedIcon

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

108 + if (colorize_value >= 0)

Isn't it always going to be the case?

review: Needs Information
Revision history for this message
Michal Hruby (mhr3) wrote :

> 108 + if (colorize_value >= 0)
>
> Isn't it always going to be the case?

No, if set_colorize_rgba() is not called, it'll remain 0. (which would otherwise mean that the icon should use alpha 0.0 which doesn't make much sense).

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

> 108 + if (colorize_value >= 0)
>
> Isn't it always going to be the case?

Eh, right, I didn't pay attention to the operator, should indeed be just >

lp:~mhr3/libunity/colorized-icon updated
285. By Michal Hruby

Fix the comparison operator

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2013-08-19 12:03:59 +0000
+++ configure.ac 2013-08-27 12:54:13 +0000
@@ -1,5 +1,5 @@
1# When releasing also remember to update the soname as instructed below1# When releasing also remember to update the soname as instructed below
2AC_INIT(libunity, 7.0.12)2AC_INIT(libunity, 7.1.0)
33
4AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)4AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
5AM_CONFIG_HEADER(config.h)5AM_CONFIG_HEADER(config.h)
66
=== modified file 'debian/changelog'
--- debian/changelog 2013-08-26 09:19:55 +0000
+++ debian/changelog 2013-08-27 12:54:13 +0000
@@ -1,8 +1,12 @@
1libunity (7.0.12+13.10.20130821-0ubuntu2) UNRELEASED; urgency=low1libunity (7.1.0-0ubuntu1) UNRELEASED; urgency=low
22
3 [ Pawel Stolowski ]
3 * Removed openweathermap scope from list of client scopes.4 * Removed openweathermap scope from list of client scopes.
45
5 -- Pawel Stolowski <pawel.stolowski@ubuntu.com> Mon, 26 Aug 2013 11:19:11 +02006 [ Michal Hruby ]
7 * Added colorize API to AnnotatedIcon.
8
9 -- Michal Hruby <michal.hruby@canonical.com> Tue, 27 Aug 2013 00:02:47 +0100
610
7libunity (7.0.12+13.10.20130821-0ubuntu1) saucy; urgency=low11libunity (7.0.12+13.10.20130821-0ubuntu1) saucy; urgency=low
812
913
=== modified file 'debian/libunity9.symbols'
--- debian/libunity9.symbols 2013-08-16 10:35:23 +0000
+++ debian/libunity9.symbols 2013-08-27 12:54:13 +0000
@@ -125,6 +125,7 @@
125 unity_annotated_icon_get_type@Base 5.94.0125 unity_annotated_icon_get_type@Base 5.94.0
126 unity_annotated_icon_new@Base 5.94.0126 unity_annotated_icon_new@Base 5.94.0
127 unity_annotated_icon_set_category@Base 5.94.0127 unity_annotated_icon_set_category@Base 5.94.0
128 unity_annotated_icon_set_colorize_rgba@Base 0replaceme
128 unity_annotated_icon_set_icon@Base 5.94.0129 unity_annotated_icon_set_icon@Base 5.94.0
129 unity_annotated_icon_set_ribbon@Base 5.94.0130 unity_annotated_icon_set_ribbon@Base 5.94.0
130 unity_annotated_icon_set_size_hint@Base 6.8.0131 unity_annotated_icon_set_size_hint@Base 6.8.0
131132
=== modified file 'protocol/Makefile.am'
--- protocol/Makefile.am 2013-08-01 12:18:10 +0000
+++ protocol/Makefile.am 2013-08-27 12:54:13 +0000
@@ -40,7 +40,7 @@
40 $(NULL)40 $(NULL)
4141
42libunity_protocol_private_la_LIBADD = \42libunity_protocol_private_la_LIBADD = \
43 $(LIBUNITY_LIBS)43 $(LIBUNITY_LIBS) -lm
4444
45libunity_protocol_private_la_LDFLAGS = \45libunity_protocol_private_la_LDFLAGS = \
46 $(LIBPROTOCOL_LT_LDFLAGS) \46 $(LIBPROTOCOL_LT_LDFLAGS) \
4747
=== modified file 'protocol/protocol-icon.vala'
--- protocol/protocol-icon.vala 2013-07-23 13:22:36 +0000
+++ protocol/protocol-icon.vala 2013-08-27 12:54:13 +0000
@@ -58,6 +58,7 @@
58 public string ribbon { get; set; }58 public string ribbon { get; set; }
59 public CategoryType category { get; set; default = CategoryType.NONE; }59 public CategoryType category { get; set; default = CategoryType.NONE; }
60 public bool use_small_icon { get; set; }60 public bool use_small_icon { get; set; }
61 public uint32 colorize_value { get; set; }
6162
62 public AnnotatedIcon (Icon? base_icon)63 public AnnotatedIcon (Icon? base_icon)
63 {64 {
@@ -81,6 +82,22 @@
81 return _hints[name];82 return _hints[name];
82 }83 }
8384
85 public void set_colorize_rgba (double r, double g, double b, double a)
86 {
87 const uint MAX_VAL = 255;
88 const double MAX_VAL_DBL = 255.0;
89 uint32 color = 0;
90 color += uint.min (MAX_VAL, (uint) Math.round (r * MAX_VAL_DBL));
91 color <<= 8;
92 color += uint.min (MAX_VAL, (uint) Math.round (g * MAX_VAL_DBL));
93 color <<= 8;
94 color += uint.min (MAX_VAL, (uint) Math.round (b * MAX_VAL_DBL));
95 color <<= 8;
96 color += uint.min (MAX_VAL, (uint) Math.round (a * MAX_VAL_DBL));
97
98 colorize_value = color;
99 }
100
84 private bool equal (Icon? icon2)101 private bool equal (Icon? icon2)
85 {102 {
86 return (this.to_string () == icon2.to_string ());103 return (this.to_string () == icon2.to_string ());
@@ -136,6 +153,13 @@
136 icon._hints.remove ("use-small-icon");153 icon._hints.remove ("use-small-icon");
137 }154 }
138155
156 unowned Variant colorize_variant = icon.get_hint ("colorize-value");
157 if (colorize_variant != null)
158 {
159 icon.colorize_value = colorize_variant.get_uint32 ();
160 icon._hints.remove ("colorize-value");
161 }
162
139 return icon;163 return icon;
140 }164 }
141165
@@ -152,6 +176,8 @@
152 add_hint ("ribbon", ribbon);176 add_hint ("ribbon", ribbon);
153 if (use_small_icon)177 if (use_small_icon)
154 add_hint ("use-small-icon", new Variant.boolean (true));178 add_hint ("use-small-icon", new Variant.boolean (true));
179 if (colorize_value > 0)
180 add_hint ("colorize-value", new Variant.uint32 (colorize_value));
155181
156 Variant dict = _hints;182 Variant dict = _hints;
157 tokens.add (dict.print (true));183 tokens.add (dict.print (true));
158184
=== modified file 'src/unity-icon.vala'
--- src/unity-icon.vala 2012-09-24 13:53:47 +0000
+++ src/unity-icon.vala 2013-08-27 12:54:13 +0000
@@ -104,6 +104,11 @@
104 set { _pai.use_small_icon = value == IconSizeHint.SMALL; }104 set { _pai.use_small_icon = value == IconSizeHint.SMALL; }
105 }105 }
106106
107 public void set_colorize_rgba (double r, double g, double b, double a)
108 {
109 _pai.set_colorize_rgba (r, g, b, a);
110 }
111
107 public AnnotatedIcon (Icon base_icon)112 public AnnotatedIcon (Icon base_icon)
108 {113 {
109 Object (icon: base_icon);114 Object (icon: base_icon);
110115
=== modified file 'test/vala/test-previews.vala'
--- test/vala/test-previews.vala 2013-03-22 12:55:21 +0000
+++ test/vala/test-previews.vala 2013-08-27 12:54:13 +0000
@@ -58,6 +58,8 @@
58 test_proto_annotated_icon_with_metadata);58 test_proto_annotated_icon_with_metadata);
59 GLib.Test.add_data_func ("/Unit/AnnotatedIcon/WithMetadata",59 GLib.Test.add_data_func ("/Unit/AnnotatedIcon/WithMetadata",
60 test_annotated_icon_with_metadata);60 test_annotated_icon_with_metadata);
61 GLib.Test.add_data_func ("/Unit/AnnotatedIcon/WithColor",
62 test_annotated_icon_with_color);
61 }63 }
6264
63 static bool previews_equal (Variant data, Variant data2)65 static bool previews_equal (Variant data, Variant data2)
@@ -128,6 +130,23 @@
128 assert (de_anno.use_small_icon == true);130 assert (de_anno.use_small_icon == true);
129 }131 }
130132
133 static void test_annotated_icon_with_color ()
134 {
135 var icon = new ThemedIcon ("internet");
136 var anno_icon = new Unity.AnnotatedIcon (icon);
137 anno_icon.set_colorize_rgba (0.5, 0.0, 1.0, 1.0);
138 assert (anno_icon.icon.equal (icon));
139 var serialized = anno_icon.to_string ();
140
141 var deserialized = Icon.new_for_string (serialized);
142 assert (deserialized.to_string () == serialized);
143
144 var de_anno = deserialized as Protocol.AnnotatedIcon;
145 assert (de_anno != null);
146 assert (de_anno.icon.equal (icon));
147 assert (de_anno.colorize_value == 0x8000ffff);
148 }
149
131 static void test_preview_generic ()150 static void test_preview_generic ()
132 {151 {
133 var thumbnail = new ThemedIcon ("internet");152 var thumbnail = new ThemedIcon ("internet");

Subscribers

People subscribed via source and target branches