Merge lp:~unity-team/unity/unity.fix-607251 into lp:unity
- unity.fix-607251
- Merge into trunk
Proposed by
Mirco Müller
Status: | Merged |
---|---|
Approved by: | Gord Allott |
Approved revision: | no longer in the source branch. |
Merged at revision: | 422 |
Proposed branch: | lp:~unity-team/unity/unity.fix-607251 |
Merge into: | lp:unity |
Diff against target: |
701 lines (+464/-142) 6 files modified
unity-private/launcher/quicklist-check-menu-item.vala (+19/-20) unity-private/launcher/quicklist-controller.vala (+2/-1) unity-private/launcher/quicklist-image-menu-item.vala (+4/-4) unity-private/launcher/quicklist-menu-item.vala (+4/-4) unity-private/launcher/quicklist-radio-menu-item.vala (+17/-20) unity/quicklist-rendering.vala (+418/-93) |
To merge this branch: | bzr merge lp:~unity-team/unity/unity.fix-607251 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+31833@code.launchpad.net |
Commit message
Description of the change
This branch implements custom checkmark- and radiobutton-items for quicklists. The design is based on a mockup image I received from Otto (via Neil) and some discussions with Otto during the Prague platform sprint.
Image-items are not meant to be used in quicklists I was told by Design.
Since there are still unanswered questions about item-alignment, but I don't want to further keep this defering I propose a merge now. Alignment questions, once answered by Design, can be addressed in a later branch.
To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'unity-private/launcher/quicklist-check-menu-item.vala' | |||
2 | --- unity-private/launcher/quicklist-check-menu-item.vala 2010-07-22 19:32:14 +0000 | |||
3 | +++ unity-private/launcher/quicklist-check-menu-item.vala 2010-08-05 14:54:49 +0000 | |||
4 | @@ -51,11 +51,11 @@ | |||
5 | 51 | int width; | 51 | int width; |
6 | 52 | int height; | 52 | int height; |
7 | 53 | Gtk.Settings settings = Gtk.Settings.get_default (); | 53 | Gtk.Settings settings = Gtk.Settings.get_default (); |
13 | 54 | Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name, | 54 | Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name, |
14 | 55 | this.label + " ☐", | 55 | this.label, |
15 | 56 | out width, | 56 | out width, |
16 | 57 | out height); | 57 | out height); |
17 | 58 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); | 58 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN) + 30.0f; |
18 | 59 | natural_width_p = min_width_p; | 59 | natural_width_p = min_width_p; |
19 | 60 | } | 60 | } |
20 | 61 | 61 | ||
21 | @@ -125,21 +125,20 @@ | |||
22 | 125 | 125 | ||
23 | 126 | string formatted_label = Utils.strip_characters (label, "", "_", "_"); | 126 | string formatted_label = Utils.strip_characters (label, "", "_", "_"); |
24 | 127 | 127 | ||
40 | 128 | if (active) | 128 | //Unity.QuicklistRendering.RadioItem.normal_mask (normal_cr, |
41 | 129 | formatted_label = "☑ " + formatted_label; | 129 | Unity.QuicklistRendering.CheckmarkItem.normal_mask (normal_cr, |
42 | 130 | else | 130 | this.last_width, |
43 | 131 | formatted_label = "☐ " + formatted_label; | 131 | this.last_height, |
44 | 132 | 132 | settings.gtk_font_name, | |
45 | 133 | Unity.QuicklistRendering.Item.normal_mask (normal_cr, | 133 | formatted_label, |
46 | 134 | this.last_width, | 134 | active); |
47 | 135 | this.last_height, | 135 | //Unity.QuicklistRendering.RadioItem.selected_mask (selected_cr, |
48 | 136 | settings.gtk_font_name, | 136 | Unity.QuicklistRendering.CheckmarkItem.selected_mask (selected_cr, |
49 | 137 | formatted_label); | 137 | this.last_width, |
50 | 138 | Unity.QuicklistRendering.Item.selected_mask (selected_cr, | 138 | this.last_height, |
51 | 139 | this.last_width, | 139 | settings.gtk_font_name, |
52 | 140 | this.last_height, | 140 | formatted_label, |
53 | 141 | settings.gtk_font_name, | 141 | active); |
39 | 142 | formatted_label); | ||
54 | 143 | 142 | ||
55 | 144 | normal_layer.set_mask_from_surface (normal_surf); | 143 | normal_layer.set_mask_from_surface (normal_surf); |
56 | 145 | normal_layer.set_color (white_color); | 144 | normal_layer.set_color (white_color); |
57 | 146 | 145 | ||
58 | === modified file 'unity-private/launcher/quicklist-controller.vala' | |||
59 | --- unity-private/launcher/quicklist-controller.vala 2010-08-05 11:29:25 +0000 | |||
60 | +++ unity-private/launcher/quicklist-controller.vala 2010-08-05 14:54:49 +0000 | |||
61 | @@ -334,7 +334,8 @@ | |||
62 | 334 | 334 | ||
63 | 335 | else | 335 | else |
64 | 336 | { | 336 | { |
66 | 337 | warning ("not a menu item we understand, %s", dbusmenuitem.property_get ("type")); | 337 | warning ("not a menu item we understand, %s", |
67 | 338 | dbusmenuitem.property_get ("type")); | ||
68 | 338 | return null; | 339 | return null; |
69 | 339 | } | 340 | } |
70 | 340 | 341 | ||
71 | 341 | 342 | ||
72 | === modified file 'unity-private/launcher/quicklist-image-menu-item.vala' | |||
73 | --- unity-private/launcher/quicklist-image-menu-item.vala 2010-07-22 19:32:14 +0000 | |||
74 | +++ unity-private/launcher/quicklist-image-menu-item.vala 2010-08-05 14:54:49 +0000 | |||
75 | @@ -52,10 +52,10 @@ | |||
76 | 52 | int width; | 52 | int width; |
77 | 53 | int height; | 53 | int height; |
78 | 54 | Gtk.Settings settings = Gtk.Settings.get_default (); | 54 | Gtk.Settings settings = Gtk.Settings.get_default (); |
83 | 55 | Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name, | 55 | Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name, |
84 | 56 | this.label, | 56 | this.label, |
85 | 57 | out width, | 57 | out width, |
86 | 58 | out height); | 58 | out height); |
87 | 59 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); | 59 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); |
88 | 60 | natural_width_p = min_width_p; | 60 | natural_width_p = min_width_p; |
89 | 61 | } | 61 | } |
90 | 62 | 62 | ||
91 | === modified file 'unity-private/launcher/quicklist-menu-item.vala' | |||
92 | --- unity-private/launcher/quicklist-menu-item.vala 2010-07-22 19:32:14 +0000 | |||
93 | +++ unity-private/launcher/quicklist-menu-item.vala 2010-08-05 14:54:49 +0000 | |||
94 | @@ -53,10 +53,10 @@ | |||
95 | 53 | int width; | 53 | int width; |
96 | 54 | int height; | 54 | int height; |
97 | 55 | Gtk.Settings settings = Gtk.Settings.get_default (); | 55 | Gtk.Settings settings = Gtk.Settings.get_default (); |
102 | 56 | Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name, | 56 | Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name, |
103 | 57 | this.label, | 57 | this.label, |
104 | 58 | out width, | 58 | out width, |
105 | 59 | out height); | 59 | out height); |
106 | 60 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); | 60 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); |
107 | 61 | natural_width_p = min_width_p; | 61 | natural_width_p = min_width_p; |
108 | 62 | } | 62 | } |
109 | 63 | 63 | ||
110 | === modified file 'unity-private/launcher/quicklist-radio-menu-item.vala' | |||
111 | --- unity-private/launcher/quicklist-radio-menu-item.vala 2010-07-22 19:32:14 +0000 | |||
112 | +++ unity-private/launcher/quicklist-radio-menu-item.vala 2010-08-05 14:54:49 +0000 | |||
113 | @@ -51,11 +51,11 @@ | |||
114 | 51 | int width; | 51 | int width; |
115 | 52 | int height; | 52 | int height; |
116 | 53 | Gtk.Settings settings = Gtk.Settings.get_default (); | 53 | Gtk.Settings settings = Gtk.Settings.get_default (); |
122 | 54 | Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name, | 54 | Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name, |
123 | 55 | this.label + " ☐", | 55 | this.label, |
124 | 56 | out width, | 56 | out width, |
125 | 57 | out height); | 57 | out height); |
126 | 58 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN); | 58 | min_width_p = (float) width + (float) Ctk.em_to_pixel (2 * MARGIN) + 30.0f; |
127 | 59 | natural_width_p = min_width_p; | 59 | natural_width_p = min_width_p; |
128 | 60 | } | 60 | } |
129 | 61 | 61 | ||
130 | @@ -125,21 +125,18 @@ | |||
131 | 125 | 125 | ||
132 | 126 | string formatted_label = Utils.strip_characters (label, "", "_", "_"); | 126 | string formatted_label = Utils.strip_characters (label, "", "_", "_"); |
133 | 127 | 127 | ||
149 | 128 | if (active) | 128 | Unity.QuicklistRendering.RadioItem.normal_mask (normal_cr, |
150 | 129 | formatted_label = "◉ " + formatted_label; | 129 | this.last_width, |
151 | 130 | else | 130 | this.last_height, |
152 | 131 | formatted_label = "○ " + formatted_label; | 131 | settings.gtk_font_name, |
153 | 132 | 132 | formatted_label, | |
154 | 133 | Unity.QuicklistRendering.Item.normal_mask (normal_cr, | 133 | active); |
155 | 134 | this.last_width, | 134 | Unity.QuicklistRendering.RadioItem.selected_mask (selected_cr, |
156 | 135 | this.last_height, | 135 | this.last_width, |
157 | 136 | settings.gtk_font_name, | 136 | this.last_height, |
158 | 137 | formatted_label); | 137 | settings.gtk_font_name, |
159 | 138 | Unity.QuicklistRendering.Item.selected_mask (selected_cr, | 138 | formatted_label, |
160 | 139 | this.last_width, | 139 | active); |
146 | 140 | this.last_height, | ||
147 | 141 | settings.gtk_font_name, | ||
148 | 142 | formatted_label); | ||
161 | 143 | 140 | ||
162 | 144 | normal_layer.set_mask_from_surface (normal_surf); | 141 | normal_layer.set_mask_from_surface (normal_surf); |
163 | 145 | normal_layer.set_color (white_color); | 142 | normal_layer.set_color (white_color); |
164 | 146 | 143 | ||
165 | === modified file 'unity/quicklist-rendering.vala' | |||
166 | --- unity/quicklist-rendering.vala 2010-06-30 11:39:35 +0000 | |||
167 | +++ unity/quicklist-rendering.vala 2010-08-05 14:54:49 +0000 | |||
168 | @@ -40,6 +40,99 @@ | |||
169 | 40 | const float ANCHOR_WIDTH = 0.75f; | 40 | const float ANCHOR_WIDTH = 0.75f; |
170 | 41 | const float ANCHOR_WIDTH_ABS = 10.0f; | 41 | const float ANCHOR_WIDTH_ABS = 10.0f; |
171 | 42 | 42 | ||
172 | 43 | private static double | ||
173 | 44 | _align (double val) | ||
174 | 45 | { | ||
175 | 46 | double fract = val - (int) val; | ||
176 | 47 | |||
177 | 48 | if (fract != 0.5f) | ||
178 | 49 | return (double) ((int) val + 0.5f); | ||
179 | 50 | else | ||
180 | 51 | return val; | ||
181 | 52 | } | ||
182 | 53 | |||
183 | 54 | public static void | ||
184 | 55 | get_text_extents (string font, | ||
185 | 56 | string text, | ||
186 | 57 | out int width, | ||
187 | 58 | out int height) | ||
188 | 59 | { | ||
189 | 60 | Cairo.Surface surface = new Cairo.ImageSurface (Cairo.Format.A1, 1, 1); | ||
190 | 61 | Cairo.Context cr = new Cairo.Context (surface); | ||
191 | 62 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
192 | 63 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
193 | 64 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
194 | 65 | desc.set_weight (Pango.Weight.NORMAL); | ||
195 | 66 | layout.set_font_description (desc); | ||
196 | 67 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
197 | 68 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
198 | 69 | layout.set_text (text, -1); | ||
199 | 70 | Pango.Context pango_context = layout.get_context (); | ||
200 | 71 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
201 | 72 | Pango.cairo_context_set_font_options (pango_context, | ||
202 | 73 | screen.get_font_options ()); | ||
203 | 74 | Pango.cairo_context_set_resolution (pango_context, | ||
204 | 75 | (float) settings.gtk_xft_dpi / | ||
205 | 76 | (float) Pango.SCALE); | ||
206 | 77 | layout.context_changed (); | ||
207 | 78 | Pango.Rectangle log_rect; | ||
208 | 79 | layout.get_extents (null, out log_rect); | ||
209 | 80 | width = log_rect.width / Pango.SCALE; | ||
210 | 81 | height = log_rect.height / Pango.SCALE; | ||
211 | 82 | } | ||
212 | 83 | |||
213 | 84 | private static void | ||
214 | 85 | _round_rect (Cairo.Context cr, | ||
215 | 86 | double aspect, // aspect-ratio | ||
216 | 87 | double x, // top-left corner | ||
217 | 88 | double y, // top-left corner | ||
218 | 89 | double corner_radius, // "size" of the corners | ||
219 | 90 | double width, // width of the rectangle | ||
220 | 91 | double height) // height of the rectangle | ||
221 | 92 | { | ||
222 | 93 | double radius = corner_radius / aspect; | ||
223 | 94 | |||
224 | 95 | // top-left, right of the corner | ||
225 | 96 | cr.move_to (x + radius, y); | ||
226 | 97 | |||
227 | 98 | // top-right, left of the corner | ||
228 | 99 | cr.line_to (x + width - radius, y); | ||
229 | 100 | |||
230 | 101 | // top-right, below the corner | ||
231 | 102 | cr.arc (x + width - radius, | ||
232 | 103 | y + radius, | ||
233 | 104 | radius, | ||
234 | 105 | -90.0f * GLib.Math.PI / 180.0f, | ||
235 | 106 | 0.0f * GLib.Math.PI / 180.0f); | ||
236 | 107 | |||
237 | 108 | // bottom-right, above the corner | ||
238 | 109 | cr.line_to (x + width, y + height - radius); | ||
239 | 110 | |||
240 | 111 | // bottom-right, left of the corner | ||
241 | 112 | cr.arc (x + width - radius, | ||
242 | 113 | y + height - radius, | ||
243 | 114 | radius, | ||
244 | 115 | 0.0f * GLib.Math.PI / 180.0f, | ||
245 | 116 | 90.0f * GLib.Math.PI / 180.0f); | ||
246 | 117 | |||
247 | 118 | // bottom-left, right of the corner | ||
248 | 119 | cr.line_to (x + radius, y + height); | ||
249 | 120 | |||
250 | 121 | // bottom-left, above the corner | ||
251 | 122 | cr.arc (x + radius, | ||
252 | 123 | y + height - radius, | ||
253 | 124 | radius, | ||
254 | 125 | 90.0f * GLib.Math.PI / 180.0f, | ||
255 | 126 | 180.0f * GLib.Math.PI / 180.0f); | ||
256 | 127 | |||
257 | 128 | // top-left, right of the corner | ||
258 | 129 | cr.arc (x + radius, | ||
259 | 130 | y + radius, | ||
260 | 131 | radius, | ||
261 | 132 | 180.0f * GLib.Math.PI / 180.0f, | ||
262 | 133 | 270.0f * GLib.Math.PI / 180.0f); | ||
263 | 134 | } | ||
264 | 135 | |||
265 | 43 | public class Seperator : GLib.Object | 136 | public class Seperator : GLib.Object |
266 | 44 | { | 137 | { |
267 | 45 | public static void | 138 | public static void |
268 | @@ -87,90 +180,333 @@ | |||
269 | 87 | } | 180 | } |
270 | 88 | } | 181 | } |
271 | 89 | 182 | ||
272 | 183 | public class CheckmarkItem : GLib.Object | ||
273 | 184 | { | ||
274 | 185 | public static void | ||
275 | 186 | normal_mask (Cairo.Context cr, | ||
276 | 187 | int w, | ||
277 | 188 | int h, | ||
278 | 189 | string font, | ||
279 | 190 | string text, | ||
280 | 191 | bool enabled) | ||
281 | 192 | { | ||
282 | 193 | // clear context | ||
283 | 194 | cr.set_operator (Cairo.Operator.CLEAR); | ||
284 | 195 | cr.paint (); | ||
285 | 196 | |||
286 | 197 | // setup correct filled-drawing | ||
287 | 198 | cr.set_operator (Cairo.Operator.SOURCE); | ||
288 | 199 | cr.scale (1.0f, 1.0f); | ||
289 | 200 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
290 | 201 | cr.set_line_width (1.0f); | ||
291 | 202 | |||
292 | 203 | // draw checkmark | ||
293 | 204 | cr.save (); | ||
294 | 205 | cr.translate (_align ((30.0f - 16.0f) / 2.0f), | ||
295 | 206 | _align (((double) h - 16.0f) / 2.0f)); | ||
296 | 207 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f); | ||
297 | 208 | _round_rect (cr, | ||
298 | 209 | 1.0f, // aspect | ||
299 | 210 | 0.0f, // top-left corner | ||
300 | 211 | 0.0f, // top-left corner | ||
301 | 212 | 3.0f, // "size" of the corners | ||
302 | 213 | 16.0f, // width of the rectangle | ||
303 | 214 | 16.0f); // height of the rectangle | ||
304 | 215 | cr.stroke (); | ||
305 | 216 | |||
306 | 217 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
307 | 218 | |||
308 | 219 | if (enabled) | ||
309 | 220 | { | ||
310 | 221 | cr.translate (3.0f, 1.0f); | ||
311 | 222 | |||
312 | 223 | cr.move_to (0.0f, 6.0f); | ||
313 | 224 | cr.line_to (0.0f, 8.0f); | ||
314 | 225 | cr.line_to (4.0f, 12.0f); | ||
315 | 226 | cr.line_to (6.0f, 12.0f); | ||
316 | 227 | cr.line_to (15.0f, 1.0f); | ||
317 | 228 | cr.line_to (15.0f, 0.0f); | ||
318 | 229 | cr.line_to (14.0f, 0.0f); | ||
319 | 230 | cr.line_to (5.0f, 9.0f); | ||
320 | 231 | cr.line_to (1.0f, 5.0f); | ||
321 | 232 | cr.close_path (); | ||
322 | 233 | cr.fill (); | ||
323 | 234 | } | ||
324 | 235 | cr.restore (); | ||
325 | 236 | |||
326 | 237 | // draw text | ||
327 | 238 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
328 | 239 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
329 | 240 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
330 | 241 | desc.set_weight (Pango.Weight.NORMAL); | ||
331 | 242 | layout.set_font_description (desc); | ||
332 | 243 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
333 | 244 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
334 | 245 | layout.set_text (text, -1); | ||
335 | 246 | Pango.Context pango_context = layout.get_context (); | ||
336 | 247 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
337 | 248 | Pango.cairo_context_set_font_options (pango_context, | ||
338 | 249 | screen.get_font_options ()); | ||
339 | 250 | Pango.cairo_context_set_resolution (pango_context, | ||
340 | 251 | (float) settings.gtk_xft_dpi / | ||
341 | 252 | (float) Pango.SCALE); | ||
342 | 253 | layout.context_changed (); | ||
343 | 254 | |||
344 | 255 | int text_width; | ||
345 | 256 | int text_height; | ||
346 | 257 | get_text_extents (font, text, out text_width, out text_height); | ||
347 | 258 | cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN), | ||
348 | 259 | (float) (h - text_height) / 2.0f); | ||
349 | 260 | |||
350 | 261 | Pango.cairo_show_layout (cr, layout); | ||
351 | 262 | } | ||
352 | 263 | |||
353 | 264 | public static void | ||
354 | 265 | selected_mask (Cairo.Context cr, | ||
355 | 266 | int w, | ||
356 | 267 | int h, | ||
357 | 268 | string font, | ||
358 | 269 | string text, | ||
359 | 270 | bool enabled) | ||
360 | 271 | { | ||
361 | 272 | // clear context | ||
362 | 273 | cr.set_operator (Cairo.Operator.CLEAR); | ||
363 | 274 | cr.paint (); | ||
364 | 275 | |||
365 | 276 | // setup correct filled-drawing | ||
366 | 277 | cr.set_operator (Cairo.Operator.SOURCE); | ||
367 | 278 | cr.scale (1.0f, 1.0f); | ||
368 | 279 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
369 | 280 | cr.set_line_width (1.0f); | ||
370 | 281 | |||
371 | 282 | // draw rounded rectangle | ||
372 | 283 | _round_rect (cr, | ||
373 | 284 | 1.0f, | ||
374 | 285 | 0.5f, | ||
375 | 286 | 0.5f, | ||
376 | 287 | ITEM_CORNER_RADIUS_ABS, | ||
377 | 288 | w - 1.0f, | ||
378 | 289 | h - 1.0f); | ||
379 | 290 | cr.fill (); | ||
380 | 291 | |||
381 | 292 | cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.0f); | ||
382 | 293 | |||
383 | 294 | // draw checkmark | ||
384 | 295 | cr.save (); | ||
385 | 296 | cr.translate (_align ((30.0f - 16.0f) / 2.0f), | ||
386 | 297 | _align (((double) h - 16.0f) / 2.0f)); | ||
387 | 298 | |||
388 | 299 | _round_rect (cr, | ||
389 | 300 | 1.0f, // aspect | ||
390 | 301 | 0.0f, // top-left corner | ||
391 | 302 | 0.0f, // top-left corner | ||
392 | 303 | 3.0f, // "size" of the corners | ||
393 | 304 | 16.0f, // width of the rectangle | ||
394 | 305 | 16.0f); // height of the rectangle | ||
395 | 306 | cr.stroke (); | ||
396 | 307 | |||
397 | 308 | if (enabled) | ||
398 | 309 | { | ||
399 | 310 | cr.translate (3.0f, 1.0f); | ||
400 | 311 | |||
401 | 312 | cr.move_to (0.0f, 6.0f); | ||
402 | 313 | cr.line_to (0.0f, 8.0f); | ||
403 | 314 | cr.line_to (4.0f, 12.0f); | ||
404 | 315 | cr.line_to (6.0f, 12.0f); | ||
405 | 316 | cr.line_to (15.0f, 1.0f); | ||
406 | 317 | cr.line_to (15.0f, 0.0f); | ||
407 | 318 | cr.line_to (14.0f, 0.0f); | ||
408 | 319 | cr.line_to (5.0f, 9.0f); | ||
409 | 320 | cr.line_to (1.0f, 5.0f); | ||
410 | 321 | cr.close_path (); | ||
411 | 322 | cr.fill (); | ||
412 | 323 | } | ||
413 | 324 | cr.restore (); | ||
414 | 325 | |||
415 | 326 | // draw text | ||
416 | 327 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
417 | 328 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
418 | 329 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
419 | 330 | desc.set_weight (Pango.Weight.NORMAL); | ||
420 | 331 | layout.set_font_description (desc); | ||
421 | 332 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
422 | 333 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
423 | 334 | layout.set_text (text, -1); | ||
424 | 335 | Pango.Context pango_context = layout.get_context (); | ||
425 | 336 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
426 | 337 | Pango.cairo_context_set_font_options (pango_context, | ||
427 | 338 | screen.get_font_options ()); | ||
428 | 339 | Pango.cairo_context_set_resolution (pango_context, | ||
429 | 340 | (float) settings.gtk_xft_dpi / | ||
430 | 341 | (float) Pango.SCALE); | ||
431 | 342 | layout.context_changed (); | ||
432 | 343 | |||
433 | 344 | int text_width; | ||
434 | 345 | int text_height; | ||
435 | 346 | get_text_extents (font, text, out text_width, out text_height); | ||
436 | 347 | cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN), | ||
437 | 348 | (float) (h - text_height) / 2.0f); | ||
438 | 349 | |||
439 | 350 | Pango.cairo_show_layout (cr, layout); | ||
440 | 351 | } | ||
441 | 352 | |||
442 | 353 | } | ||
443 | 354 | |||
444 | 355 | public class RadioItem : GLib.Object | ||
445 | 356 | { | ||
446 | 357 | public static void | ||
447 | 358 | normal_mask (Cairo.Context cr, | ||
448 | 359 | int w, | ||
449 | 360 | int h, | ||
450 | 361 | string font, | ||
451 | 362 | string text, | ||
452 | 363 | bool enabled) | ||
453 | 364 | { | ||
454 | 365 | // clear context | ||
455 | 366 | cr.set_operator (Cairo.Operator.CLEAR); | ||
456 | 367 | cr.paint (); | ||
457 | 368 | |||
458 | 369 | // setup correct filled-drawing | ||
459 | 370 | cr.set_operator (Cairo.Operator.SOURCE); | ||
460 | 371 | cr.scale (1.0f, 1.0f); | ||
461 | 372 | cr.set_line_width (1.0f); | ||
462 | 373 | |||
463 | 374 | double x = _align (15.0f); | ||
464 | 375 | double y = _align ((double) h / 2.0f); | ||
465 | 376 | double r1 = 3.5f; | ||
466 | 377 | double r2 = 8.5f; | ||
467 | 378 | |||
468 | 379 | // draw radio button | ||
469 | 380 | if (enabled) | ||
470 | 381 | { | ||
471 | 382 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
472 | 383 | cr.arc (x, y, r1, 0.0f * (GLib.Math.PI / 180.0f), | ||
473 | 384 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
474 | 385 | cr.fill (); | ||
475 | 386 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f); | ||
476 | 387 | cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f), | ||
477 | 388 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
478 | 389 | cr.stroke (); | ||
479 | 390 | } | ||
480 | 391 | else | ||
481 | 392 | { | ||
482 | 393 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f); | ||
483 | 394 | cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f), | ||
484 | 395 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
485 | 396 | cr.stroke (); | ||
486 | 397 | } | ||
487 | 398 | |||
488 | 399 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
489 | 400 | |||
490 | 401 | // draw text | ||
491 | 402 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
492 | 403 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
493 | 404 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
494 | 405 | desc.set_weight (Pango.Weight.NORMAL); | ||
495 | 406 | layout.set_font_description (desc); | ||
496 | 407 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
497 | 408 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
498 | 409 | layout.set_text (text, -1); | ||
499 | 410 | Pango.Context pango_context = layout.get_context (); | ||
500 | 411 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
501 | 412 | Pango.cairo_context_set_font_options (pango_context, | ||
502 | 413 | screen.get_font_options ()); | ||
503 | 414 | Pango.cairo_context_set_resolution (pango_context, | ||
504 | 415 | (float) settings.gtk_xft_dpi / | ||
505 | 416 | (float) Pango.SCALE); | ||
506 | 417 | layout.context_changed (); | ||
507 | 418 | |||
508 | 419 | int text_width; | ||
509 | 420 | int text_height; | ||
510 | 421 | get_text_extents (font, text, out text_width, out text_height); | ||
511 | 422 | cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN), | ||
512 | 423 | (float) (h - text_height) / 2.0f); | ||
513 | 424 | |||
514 | 425 | Pango.cairo_show_layout (cr, layout); | ||
515 | 426 | } | ||
516 | 427 | |||
517 | 428 | public static void | ||
518 | 429 | selected_mask (Cairo.Context cr, | ||
519 | 430 | int w, | ||
520 | 431 | int h, | ||
521 | 432 | string font, | ||
522 | 433 | string text, | ||
523 | 434 | bool enabled) | ||
524 | 435 | { | ||
525 | 436 | // clear context | ||
526 | 437 | cr.set_operator (Cairo.Operator.CLEAR); | ||
527 | 438 | cr.paint (); | ||
528 | 439 | |||
529 | 440 | // setup correct filled-drawing | ||
530 | 441 | cr.set_operator (Cairo.Operator.SOURCE); | ||
531 | 442 | cr.scale (1.0f, 1.0f); | ||
532 | 443 | cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f); | ||
533 | 444 | |||
534 | 445 | // draw rounded rectangle | ||
535 | 446 | _round_rect (cr, | ||
536 | 447 | 1.0f, | ||
537 | 448 | 0.5f, | ||
538 | 449 | 0.5f, | ||
539 | 450 | ITEM_CORNER_RADIUS_ABS, | ||
540 | 451 | w - 1.0f, | ||
541 | 452 | h - 1.0f); | ||
542 | 453 | cr.fill (); | ||
543 | 454 | |||
544 | 455 | double x = _align (15.0f); | ||
545 | 456 | double y = _align ((double) h / 2.0f); | ||
546 | 457 | double r1 = 3.5f; | ||
547 | 458 | double r2 = 8.5f; | ||
548 | 459 | |||
549 | 460 | cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.0f); | ||
550 | 461 | |||
551 | 462 | // draw radio button | ||
552 | 463 | if (enabled) | ||
553 | 464 | { | ||
554 | 465 | cr.arc (x, y, r1, 0.0f * (GLib.Math.PI / 180.0f), | ||
555 | 466 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
556 | 467 | cr.fill (); | ||
557 | 468 | cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f), | ||
558 | 469 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
559 | 470 | cr.stroke (); | ||
560 | 471 | } | ||
561 | 472 | else | ||
562 | 473 | { | ||
563 | 474 | cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f), | ||
564 | 475 | 360.0f * (GLib.Math.PI / 180.0f)); | ||
565 | 476 | cr.stroke (); | ||
566 | 477 | } | ||
567 | 478 | |||
568 | 479 | // draw text | ||
569 | 480 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
570 | 481 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
571 | 482 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
572 | 483 | desc.set_weight (Pango.Weight.NORMAL); | ||
573 | 484 | layout.set_font_description (desc); | ||
574 | 485 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
575 | 486 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
576 | 487 | layout.set_text (text, -1); | ||
577 | 488 | |||
578 | 489 | Pango.Context pango_context = layout.get_context (); | ||
579 | 490 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
580 | 491 | Pango.cairo_context_set_font_options (pango_context, | ||
581 | 492 | screen.get_font_options ()); | ||
582 | 493 | Pango.cairo_context_set_resolution (pango_context, | ||
583 | 494 | (float) settings.gtk_xft_dpi / | ||
584 | 495 | (float) Pango.SCALE); | ||
585 | 496 | layout.context_changed (); | ||
586 | 497 | |||
587 | 498 | int text_width; | ||
588 | 499 | int text_height; | ||
589 | 500 | get_text_extents (font, text, out text_width, out text_height); | ||
590 | 501 | cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN), | ||
591 | 502 | (float) (h - text_height) / 2.0f); | ||
592 | 503 | |||
593 | 504 | Pango.cairo_show_layout (cr, layout); | ||
594 | 505 | } | ||
595 | 506 | } | ||
596 | 507 | |||
597 | 90 | public class Item : GLib.Object | 508 | public class Item : GLib.Object |
598 | 91 | { | 509 | { |
599 | 92 | private static void | ||
600 | 93 | _round_rect (Cairo.Context cr, | ||
601 | 94 | double aspect, // aspect-ratio | ||
602 | 95 | double x, // top-left corner | ||
603 | 96 | double y, // top-left corner | ||
604 | 97 | double corner_radius, // "size" of the corners | ||
605 | 98 | double width, // width of the rectangle | ||
606 | 99 | double height) // height of the rectangle | ||
607 | 100 | { | ||
608 | 101 | double radius = corner_radius / aspect; | ||
609 | 102 | |||
610 | 103 | // top-left, right of the corner | ||
611 | 104 | cr.move_to (x + radius, y); | ||
612 | 105 | |||
613 | 106 | // top-right, left of the corner | ||
614 | 107 | cr.line_to (x + width - radius, y); | ||
615 | 108 | |||
616 | 109 | // top-right, below the corner | ||
617 | 110 | cr.arc (x + width - radius, | ||
618 | 111 | y + radius, | ||
619 | 112 | radius, | ||
620 | 113 | -90.0f * GLib.Math.PI / 180.0f, | ||
621 | 114 | 0.0f * GLib.Math.PI / 180.0f); | ||
622 | 115 | |||
623 | 116 | // bottom-right, above the corner | ||
624 | 117 | cr.line_to (x + width, y + height - radius); | ||
625 | 118 | |||
626 | 119 | // bottom-right, left of the corner | ||
627 | 120 | cr.arc (x + width - radius, | ||
628 | 121 | y + height - radius, | ||
629 | 122 | radius, | ||
630 | 123 | 0.0f * GLib.Math.PI / 180.0f, | ||
631 | 124 | 90.0f * GLib.Math.PI / 180.0f); | ||
632 | 125 | |||
633 | 126 | // bottom-left, right of the corner | ||
634 | 127 | cr.line_to (x + radius, y + height); | ||
635 | 128 | |||
636 | 129 | // bottom-left, above the corner | ||
637 | 130 | cr.arc (x + radius, | ||
638 | 131 | y + height - radius, | ||
639 | 132 | radius, | ||
640 | 133 | 90.0f * GLib.Math.PI / 180.0f, | ||
641 | 134 | 180.0f * GLib.Math.PI / 180.0f); | ||
642 | 135 | |||
643 | 136 | // top-left, right of the corner | ||
644 | 137 | cr.arc (x + radius, | ||
645 | 138 | y + radius, | ||
646 | 139 | radius, | ||
647 | 140 | 180.0f * GLib.Math.PI / 180.0f, | ||
648 | 141 | 270.0f * GLib.Math.PI / 180.0f); | ||
649 | 142 | } | ||
650 | 143 | |||
651 | 144 | public static void | ||
652 | 145 | get_text_extents (string font, | ||
653 | 146 | string text, | ||
654 | 147 | out int width, | ||
655 | 148 | out int height) | ||
656 | 149 | { | ||
657 | 150 | Cairo.Surface surface = new Cairo.ImageSurface (Cairo.Format.A1, 1, 1); | ||
658 | 151 | Cairo.Context cr = new Cairo.Context (surface); | ||
659 | 152 | Pango.Layout layout = Pango.cairo_create_layout (cr); | ||
660 | 153 | Gtk.Settings settings = Gtk.Settings.get_default (); | ||
661 | 154 | Pango.FontDescription desc = Pango.FontDescription.from_string (font); | ||
662 | 155 | desc.set_weight (Pango.Weight.NORMAL); | ||
663 | 156 | layout.set_font_description (desc); | ||
664 | 157 | layout.set_wrap (Pango.WrapMode.WORD_CHAR); | ||
665 | 158 | layout.set_ellipsize (Pango.EllipsizeMode.END); | ||
666 | 159 | layout.set_text (text, -1); | ||
667 | 160 | Pango.Context pango_context = layout.get_context (); | ||
668 | 161 | Gdk.Screen screen = Gdk.Screen.get_default (); | ||
669 | 162 | Pango.cairo_context_set_font_options (pango_context, | ||
670 | 163 | screen.get_font_options ()); | ||
671 | 164 | Pango.cairo_context_set_resolution (pango_context, | ||
672 | 165 | (float) settings.gtk_xft_dpi / | ||
673 | 166 | (float) Pango.SCALE); | ||
674 | 167 | layout.context_changed (); | ||
675 | 168 | Pango.Rectangle log_rect; | ||
676 | 169 | layout.get_extents (null, out log_rect); | ||
677 | 170 | width = log_rect.width / Pango.SCALE; | ||
678 | 171 | height = log_rect.height / Pango.SCALE; | ||
679 | 172 | } | ||
680 | 173 | |||
681 | 174 | public static void | 510 | public static void |
682 | 175 | normal_mask (Cairo.Context cr, | 511 | normal_mask (Cairo.Context cr, |
683 | 176 | int w, | 512 | int w, |
684 | @@ -271,17 +607,6 @@ | |||
685 | 271 | 607 | ||
686 | 272 | public class Menu : GLib.Object | 608 | public class Menu : GLib.Object |
687 | 273 | { | 609 | { |
688 | 274 | private static double | ||
689 | 275 | _align (double val) | ||
690 | 276 | { | ||
691 | 277 | double fract = val - (int) val; | ||
692 | 278 | |||
693 | 279 | if (fract != 0.5f) | ||
694 | 280 | return (double) ((int) val + 0.5f); | ||
695 | 281 | else | ||
696 | 282 | return val; | ||
697 | 283 | } | ||
698 | 284 | |||
699 | 285 | private static void | 610 | private static void |
700 | 286 | _setup (out Cairo.Surface surf, | 611 | _setup (out Cairo.Surface surf, |
701 | 287 | out Cairo.Context cr, | 612 | out Cairo.Context cr, |
approved, couldn't test the radio items (lack of apps with radio items) but everything else seems to work fine :)