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