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
1=== modified file 'configure.ac'
2--- configure.ac 2013-08-19 12:03:59 +0000
3+++ configure.ac 2013-08-27 12:54:13 +0000
4@@ -1,5 +1,5 @@
5 # When releasing also remember to update the soname as instructed below
6-AC_INIT(libunity, 7.0.12)
7+AC_INIT(libunity, 7.1.0)
8
9 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
10 AM_CONFIG_HEADER(config.h)
11
12=== modified file 'debian/changelog'
13--- debian/changelog 2013-08-26 09:19:55 +0000
14+++ debian/changelog 2013-08-27 12:54:13 +0000
15@@ -1,8 +1,12 @@
16-libunity (7.0.12+13.10.20130821-0ubuntu2) UNRELEASED; urgency=low
17+libunity (7.1.0-0ubuntu1) UNRELEASED; urgency=low
18
19+ [ Pawel Stolowski ]
20 * Removed openweathermap scope from list of client scopes.
21
22- -- Pawel Stolowski <pawel.stolowski@ubuntu.com> Mon, 26 Aug 2013 11:19:11 +0200
23+ [ Michal Hruby ]
24+ * Added colorize API to AnnotatedIcon.
25+
26+ -- Michal Hruby <michal.hruby@canonical.com> Tue, 27 Aug 2013 00:02:47 +0100
27
28 libunity (7.0.12+13.10.20130821-0ubuntu1) saucy; urgency=low
29
30
31=== modified file 'debian/libunity9.symbols'
32--- debian/libunity9.symbols 2013-08-16 10:35:23 +0000
33+++ debian/libunity9.symbols 2013-08-27 12:54:13 +0000
34@@ -125,6 +125,7 @@
35 unity_annotated_icon_get_type@Base 5.94.0
36 unity_annotated_icon_new@Base 5.94.0
37 unity_annotated_icon_set_category@Base 5.94.0
38+ unity_annotated_icon_set_colorize_rgba@Base 0replaceme
39 unity_annotated_icon_set_icon@Base 5.94.0
40 unity_annotated_icon_set_ribbon@Base 5.94.0
41 unity_annotated_icon_set_size_hint@Base 6.8.0
42
43=== modified file 'protocol/Makefile.am'
44--- protocol/Makefile.am 2013-08-01 12:18:10 +0000
45+++ protocol/Makefile.am 2013-08-27 12:54:13 +0000
46@@ -40,7 +40,7 @@
47 $(NULL)
48
49 libunity_protocol_private_la_LIBADD = \
50- $(LIBUNITY_LIBS)
51+ $(LIBUNITY_LIBS) -lm
52
53 libunity_protocol_private_la_LDFLAGS = \
54 $(LIBPROTOCOL_LT_LDFLAGS) \
55
56=== modified file 'protocol/protocol-icon.vala'
57--- protocol/protocol-icon.vala 2013-07-23 13:22:36 +0000
58+++ protocol/protocol-icon.vala 2013-08-27 12:54:13 +0000
59@@ -58,6 +58,7 @@
60 public string ribbon { get; set; }
61 public CategoryType category { get; set; default = CategoryType.NONE; }
62 public bool use_small_icon { get; set; }
63+ public uint32 colorize_value { get; set; }
64
65 public AnnotatedIcon (Icon? base_icon)
66 {
67@@ -81,6 +82,22 @@
68 return _hints[name];
69 }
70
71+ public void set_colorize_rgba (double r, double g, double b, double a)
72+ {
73+ const uint MAX_VAL = 255;
74+ const double MAX_VAL_DBL = 255.0;
75+ uint32 color = 0;
76+ color += uint.min (MAX_VAL, (uint) Math.round (r * MAX_VAL_DBL));
77+ color <<= 8;
78+ color += uint.min (MAX_VAL, (uint) Math.round (g * MAX_VAL_DBL));
79+ color <<= 8;
80+ color += uint.min (MAX_VAL, (uint) Math.round (b * MAX_VAL_DBL));
81+ color <<= 8;
82+ color += uint.min (MAX_VAL, (uint) Math.round (a * MAX_VAL_DBL));
83+
84+ colorize_value = color;
85+ }
86+
87 private bool equal (Icon? icon2)
88 {
89 return (this.to_string () == icon2.to_string ());
90@@ -136,6 +153,13 @@
91 icon._hints.remove ("use-small-icon");
92 }
93
94+ unowned Variant colorize_variant = icon.get_hint ("colorize-value");
95+ if (colorize_variant != null)
96+ {
97+ icon.colorize_value = colorize_variant.get_uint32 ();
98+ icon._hints.remove ("colorize-value");
99+ }
100+
101 return icon;
102 }
103
104@@ -152,6 +176,8 @@
105 add_hint ("ribbon", ribbon);
106 if (use_small_icon)
107 add_hint ("use-small-icon", new Variant.boolean (true));
108+ if (colorize_value > 0)
109+ add_hint ("colorize-value", new Variant.uint32 (colorize_value));
110
111 Variant dict = _hints;
112 tokens.add (dict.print (true));
113
114=== modified file 'src/unity-icon.vala'
115--- src/unity-icon.vala 2012-09-24 13:53:47 +0000
116+++ src/unity-icon.vala 2013-08-27 12:54:13 +0000
117@@ -104,6 +104,11 @@
118 set { _pai.use_small_icon = value == IconSizeHint.SMALL; }
119 }
120
121+ public void set_colorize_rgba (double r, double g, double b, double a)
122+ {
123+ _pai.set_colorize_rgba (r, g, b, a);
124+ }
125+
126 public AnnotatedIcon (Icon base_icon)
127 {
128 Object (icon: base_icon);
129
130=== modified file 'test/vala/test-previews.vala'
131--- test/vala/test-previews.vala 2013-03-22 12:55:21 +0000
132+++ test/vala/test-previews.vala 2013-08-27 12:54:13 +0000
133@@ -58,6 +58,8 @@
134 test_proto_annotated_icon_with_metadata);
135 GLib.Test.add_data_func ("/Unit/AnnotatedIcon/WithMetadata",
136 test_annotated_icon_with_metadata);
137+ GLib.Test.add_data_func ("/Unit/AnnotatedIcon/WithColor",
138+ test_annotated_icon_with_color);
139 }
140
141 static bool previews_equal (Variant data, Variant data2)
142@@ -128,6 +130,23 @@
143 assert (de_anno.use_small_icon == true);
144 }
145
146+ static void test_annotated_icon_with_color ()
147+ {
148+ var icon = new ThemedIcon ("internet");
149+ var anno_icon = new Unity.AnnotatedIcon (icon);
150+ anno_icon.set_colorize_rgba (0.5, 0.0, 1.0, 1.0);
151+ assert (anno_icon.icon.equal (icon));
152+ var serialized = anno_icon.to_string ();
153+
154+ var deserialized = Icon.new_for_string (serialized);
155+ assert (deserialized.to_string () == serialized);
156+
157+ var de_anno = deserialized as Protocol.AnnotatedIcon;
158+ assert (de_anno != null);
159+ assert (de_anno.icon.equal (icon));
160+ assert (de_anno.colorize_value == 0x8000ffff);
161+ }
162+
163 static void test_preview_generic ()
164 {
165 var thumbnail = new ThemedIcon ("internet");

Subscribers

People subscribed via source and target branches