Merge lp:~unity-team/unity/unity.fix-607251 into lp:unity

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
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+31833@code.launchpad.net

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 :

approved, couldn't test the radio items (lack of apps with radio items) but everything else seems to work fine :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'unity-private/launcher/quicklist-check-menu-item.vala'
--- unity-private/launcher/quicklist-check-menu-item.vala 2010-07-22 19:32:14 +0000
+++ unity-private/launcher/quicklist-check-menu-item.vala 2010-08-05 14:54:49 +0000
@@ -51,11 +51,11 @@
51 int width;51 int width;
52 int height;52 int height;
53 Gtk.Settings settings = Gtk.Settings.get_default ();53 Gtk.Settings settings = Gtk.Settings.get_default ();
54 Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name,54 Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name,
55 this.label + " ☐",55 this.label,
56 out width,56 out width,
57 out height);57 out height);
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;
59 natural_width_p = min_width_p;59 natural_width_p = min_width_p;
60 }60 }
6161
@@ -125,21 +125,20 @@
125125
126 string formatted_label = Utils.strip_characters (label, "", "_", "_");126 string formatted_label = Utils.strip_characters (label, "", "_", "_");
127127
128 if (active)128 //Unity.QuicklistRendering.RadioItem.normal_mask (normal_cr,
129 formatted_label = "☑ " + formatted_label;129 Unity.QuicklistRendering.CheckmarkItem.normal_mask (normal_cr,
130 else130 this.last_width,
131 formatted_label = "☐ " + formatted_label;131 this.last_height,
132132 settings.gtk_font_name,
133 Unity.QuicklistRendering.Item.normal_mask (normal_cr,133 formatted_label,
134 this.last_width,134 active);
135 this.last_height,135 //Unity.QuicklistRendering.RadioItem.selected_mask (selected_cr,
136 settings.gtk_font_name,136 Unity.QuicklistRendering.CheckmarkItem.selected_mask (selected_cr,
137 formatted_label);137 this.last_width,
138 Unity.QuicklistRendering.Item.selected_mask (selected_cr,138 this.last_height,
139 this.last_width,139 settings.gtk_font_name,
140 this.last_height,140 formatted_label,
141 settings.gtk_font_name,141 active);
142 formatted_label);
143142
144 normal_layer.set_mask_from_surface (normal_surf);143 normal_layer.set_mask_from_surface (normal_surf);
145 normal_layer.set_color (white_color);144 normal_layer.set_color (white_color);
146145
=== modified file 'unity-private/launcher/quicklist-controller.vala'
--- unity-private/launcher/quicklist-controller.vala 2010-08-05 11:29:25 +0000
+++ unity-private/launcher/quicklist-controller.vala 2010-08-05 14:54:49 +0000
@@ -334,7 +334,8 @@
334334
335 else335 else
336 {336 {
337 warning ("not a menu item we understand, %s", dbusmenuitem.property_get ("type"));337 warning ("not a menu item we understand, %s",
338 dbusmenuitem.property_get ("type"));
338 return null;339 return null;
339 }340 }
340341
341342
=== modified file 'unity-private/launcher/quicklist-image-menu-item.vala'
--- unity-private/launcher/quicklist-image-menu-item.vala 2010-07-22 19:32:14 +0000
+++ unity-private/launcher/quicklist-image-menu-item.vala 2010-08-05 14:54:49 +0000
@@ -52,10 +52,10 @@
52 int width;52 int width;
53 int height;53 int height;
54 Gtk.Settings settings = Gtk.Settings.get_default ();54 Gtk.Settings settings = Gtk.Settings.get_default ();
55 Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name,55 Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name,
56 this.label,56 this.label,
57 out width,57 out width,
58 out height);58 out height);
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);
60 natural_width_p = min_width_p;60 natural_width_p = min_width_p;
61 }61 }
6262
=== modified file 'unity-private/launcher/quicklist-menu-item.vala'
--- unity-private/launcher/quicklist-menu-item.vala 2010-07-22 19:32:14 +0000
+++ unity-private/launcher/quicklist-menu-item.vala 2010-08-05 14:54:49 +0000
@@ -53,10 +53,10 @@
53 int width;53 int width;
54 int height;54 int height;
55 Gtk.Settings settings = Gtk.Settings.get_default ();55 Gtk.Settings settings = Gtk.Settings.get_default ();
56 Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name,56 Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name,
57 this.label,57 this.label,
58 out width,58 out width,
59 out height);59 out height);
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);
61 natural_width_p = min_width_p;61 natural_width_p = min_width_p;
62 }62 }
6363
=== modified file 'unity-private/launcher/quicklist-radio-menu-item.vala'
--- unity-private/launcher/quicklist-radio-menu-item.vala 2010-07-22 19:32:14 +0000
+++ unity-private/launcher/quicklist-radio-menu-item.vala 2010-08-05 14:54:49 +0000
@@ -51,11 +51,11 @@
51 int width;51 int width;
52 int height;52 int height;
53 Gtk.Settings settings = Gtk.Settings.get_default ();53 Gtk.Settings settings = Gtk.Settings.get_default ();
54 Unity.QuicklistRendering.Item.get_text_extents (settings.gtk_font_name,54 Unity.QuicklistRendering.get_text_extents (settings.gtk_font_name,
55 this.label + " ☐",55 this.label,
56 out width,56 out width,
57 out height);57 out height);
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;
59 natural_width_p = min_width_p;59 natural_width_p = min_width_p;
60 }60 }
6161
@@ -125,21 +125,18 @@
125125
126 string formatted_label = Utils.strip_characters (label, "", "_", "_");126 string formatted_label = Utils.strip_characters (label, "", "_", "_");
127127
128 if (active)128 Unity.QuicklistRendering.RadioItem.normal_mask (normal_cr,
129 formatted_label = "◉ " + formatted_label;129 this.last_width,
130 else130 this.last_height,
131 formatted_label = "○ " + formatted_label;131 settings.gtk_font_name,
132132 formatted_label,
133 Unity.QuicklistRendering.Item.normal_mask (normal_cr,133 active);
134 this.last_width,134 Unity.QuicklistRendering.RadioItem.selected_mask (selected_cr,
135 this.last_height,135 this.last_width,
136 settings.gtk_font_name,136 this.last_height,
137 formatted_label);137 settings.gtk_font_name,
138 Unity.QuicklistRendering.Item.selected_mask (selected_cr,138 formatted_label,
139 this.last_width,139 active);
140 this.last_height,
141 settings.gtk_font_name,
142 formatted_label);
143140
144 normal_layer.set_mask_from_surface (normal_surf);141 normal_layer.set_mask_from_surface (normal_surf);
145 normal_layer.set_color (white_color);142 normal_layer.set_color (white_color);
146143
=== modified file 'unity/quicklist-rendering.vala'
--- unity/quicklist-rendering.vala 2010-06-30 11:39:35 +0000
+++ unity/quicklist-rendering.vala 2010-08-05 14:54:49 +0000
@@ -40,6 +40,99 @@
40 const float ANCHOR_WIDTH = 0.75f;40 const float ANCHOR_WIDTH = 0.75f;
41 const float ANCHOR_WIDTH_ABS = 10.0f;41 const float ANCHOR_WIDTH_ABS = 10.0f;
4242
43 private static double
44 _align (double val)
45 {
46 double fract = val - (int) val;
47
48 if (fract != 0.5f)
49 return (double) ((int) val + 0.5f);
50 else
51 return val;
52 }
53
54 public static void
55 get_text_extents (string font,
56 string text,
57 out int width,
58 out int height)
59 {
60 Cairo.Surface surface = new Cairo.ImageSurface (Cairo.Format.A1, 1, 1);
61 Cairo.Context cr = new Cairo.Context (surface);
62 Pango.Layout layout = Pango.cairo_create_layout (cr);
63 Gtk.Settings settings = Gtk.Settings.get_default ();
64 Pango.FontDescription desc = Pango.FontDescription.from_string (font);
65 desc.set_weight (Pango.Weight.NORMAL);
66 layout.set_font_description (desc);
67 layout.set_wrap (Pango.WrapMode.WORD_CHAR);
68 layout.set_ellipsize (Pango.EllipsizeMode.END);
69 layout.set_text (text, -1);
70 Pango.Context pango_context = layout.get_context ();
71 Gdk.Screen screen = Gdk.Screen.get_default ();
72 Pango.cairo_context_set_font_options (pango_context,
73 screen.get_font_options ());
74 Pango.cairo_context_set_resolution (pango_context,
75 (float) settings.gtk_xft_dpi /
76 (float) Pango.SCALE);
77 layout.context_changed ();
78 Pango.Rectangle log_rect;
79 layout.get_extents (null, out log_rect);
80 width = log_rect.width / Pango.SCALE;
81 height = log_rect.height / Pango.SCALE;
82 }
83
84 private static void
85 _round_rect (Cairo.Context cr,
86 double aspect, // aspect-ratio
87 double x, // top-left corner
88 double y, // top-left corner
89 double corner_radius, // "size" of the corners
90 double width, // width of the rectangle
91 double height) // height of the rectangle
92 {
93 double radius = corner_radius / aspect;
94
95 // top-left, right of the corner
96 cr.move_to (x + radius, y);
97
98 // top-right, left of the corner
99 cr.line_to (x + width - radius, y);
100
101 // top-right, below the corner
102 cr.arc (x + width - radius,
103 y + radius,
104 radius,
105 -90.0f * GLib.Math.PI / 180.0f,
106 0.0f * GLib.Math.PI / 180.0f);
107
108 // bottom-right, above the corner
109 cr.line_to (x + width, y + height - radius);
110
111 // bottom-right, left of the corner
112 cr.arc (x + width - radius,
113 y + height - radius,
114 radius,
115 0.0f * GLib.Math.PI / 180.0f,
116 90.0f * GLib.Math.PI / 180.0f);
117
118 // bottom-left, right of the corner
119 cr.line_to (x + radius, y + height);
120
121 // bottom-left, above the corner
122 cr.arc (x + radius,
123 y + height - radius,
124 radius,
125 90.0f * GLib.Math.PI / 180.0f,
126 180.0f * GLib.Math.PI / 180.0f);
127
128 // top-left, right of the corner
129 cr.arc (x + radius,
130 y + radius,
131 radius,
132 180.0f * GLib.Math.PI / 180.0f,
133 270.0f * GLib.Math.PI / 180.0f);
134 }
135
43 public class Seperator : GLib.Object136 public class Seperator : GLib.Object
44 {137 {
45 public static void138 public static void
@@ -87,90 +180,333 @@
87 }180 }
88 }181 }
89182
183 public class CheckmarkItem : GLib.Object
184 {
185 public static void
186 normal_mask (Cairo.Context cr,
187 int w,
188 int h,
189 string font,
190 string text,
191 bool enabled)
192 {
193 // clear context
194 cr.set_operator (Cairo.Operator.CLEAR);
195 cr.paint ();
196
197 // setup correct filled-drawing
198 cr.set_operator (Cairo.Operator.SOURCE);
199 cr.scale (1.0f, 1.0f);
200 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
201 cr.set_line_width (1.0f);
202
203 // draw checkmark
204 cr.save ();
205 cr.translate (_align ((30.0f - 16.0f) / 2.0f),
206 _align (((double) h - 16.0f) / 2.0f));
207 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f);
208 _round_rect (cr,
209 1.0f, // aspect
210 0.0f, // top-left corner
211 0.0f, // top-left corner
212 3.0f, // "size" of the corners
213 16.0f, // width of the rectangle
214 16.0f); // height of the rectangle
215 cr.stroke ();
216
217 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
218
219 if (enabled)
220 {
221 cr.translate (3.0f, 1.0f);
222
223 cr.move_to (0.0f, 6.0f);
224 cr.line_to (0.0f, 8.0f);
225 cr.line_to (4.0f, 12.0f);
226 cr.line_to (6.0f, 12.0f);
227 cr.line_to (15.0f, 1.0f);
228 cr.line_to (15.0f, 0.0f);
229 cr.line_to (14.0f, 0.0f);
230 cr.line_to (5.0f, 9.0f);
231 cr.line_to (1.0f, 5.0f);
232 cr.close_path ();
233 cr.fill ();
234 }
235 cr.restore ();
236
237 // draw text
238 Pango.Layout layout = Pango.cairo_create_layout (cr);
239 Gtk.Settings settings = Gtk.Settings.get_default ();
240 Pango.FontDescription desc = Pango.FontDescription.from_string (font);
241 desc.set_weight (Pango.Weight.NORMAL);
242 layout.set_font_description (desc);
243 layout.set_wrap (Pango.WrapMode.WORD_CHAR);
244 layout.set_ellipsize (Pango.EllipsizeMode.END);
245 layout.set_text (text, -1);
246 Pango.Context pango_context = layout.get_context ();
247 Gdk.Screen screen = Gdk.Screen.get_default ();
248 Pango.cairo_context_set_font_options (pango_context,
249 screen.get_font_options ());
250 Pango.cairo_context_set_resolution (pango_context,
251 (float) settings.gtk_xft_dpi /
252 (float) Pango.SCALE);
253 layout.context_changed ();
254
255 int text_width;
256 int text_height;
257 get_text_extents (font, text, out text_width, out text_height);
258 cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN),
259 (float) (h - text_height) / 2.0f);
260
261 Pango.cairo_show_layout (cr, layout);
262 }
263
264 public static void
265 selected_mask (Cairo.Context cr,
266 int w,
267 int h,
268 string font,
269 string text,
270 bool enabled)
271 {
272 // clear context
273 cr.set_operator (Cairo.Operator.CLEAR);
274 cr.paint ();
275
276 // setup correct filled-drawing
277 cr.set_operator (Cairo.Operator.SOURCE);
278 cr.scale (1.0f, 1.0f);
279 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
280 cr.set_line_width (1.0f);
281
282 // draw rounded rectangle
283 _round_rect (cr,
284 1.0f,
285 0.5f,
286 0.5f,
287 ITEM_CORNER_RADIUS_ABS,
288 w - 1.0f,
289 h - 1.0f);
290 cr.fill ();
291
292 cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.0f);
293
294 // draw checkmark
295 cr.save ();
296 cr.translate (_align ((30.0f - 16.0f) / 2.0f),
297 _align (((double) h - 16.0f) / 2.0f));
298
299 _round_rect (cr,
300 1.0f, // aspect
301 0.0f, // top-left corner
302 0.0f, // top-left corner
303 3.0f, // "size" of the corners
304 16.0f, // width of the rectangle
305 16.0f); // height of the rectangle
306 cr.stroke ();
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 }
354
355 public class RadioItem : GLib.Object
356 {
357 public static void
358 normal_mask (Cairo.Context cr,
359 int w,
360 int h,
361 string font,
362 string text,
363 bool enabled)
364 {
365 // clear context
366 cr.set_operator (Cairo.Operator.CLEAR);
367 cr.paint ();
368
369 // setup correct filled-drawing
370 cr.set_operator (Cairo.Operator.SOURCE);
371 cr.scale (1.0f, 1.0f);
372 cr.set_line_width (1.0f);
373
374 double x = _align (15.0f);
375 double y = _align ((double) h / 2.0f);
376 double r1 = 3.5f;
377 double r2 = 8.5f;
378
379 // draw radio button
380 if (enabled)
381 {
382 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
383 cr.arc (x, y, r1, 0.0f * (GLib.Math.PI / 180.0f),
384 360.0f * (GLib.Math.PI / 180.0f));
385 cr.fill ();
386 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f);
387 cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f),
388 360.0f * (GLib.Math.PI / 180.0f));
389 cr.stroke ();
390 }
391 else
392 {
393 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.65f);
394 cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f),
395 360.0f * (GLib.Math.PI / 180.0f));
396 cr.stroke ();
397 }
398
399 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
400
401 // draw text
402 Pango.Layout layout = Pango.cairo_create_layout (cr);
403 Gtk.Settings settings = Gtk.Settings.get_default ();
404 Pango.FontDescription desc = Pango.FontDescription.from_string (font);
405 desc.set_weight (Pango.Weight.NORMAL);
406 layout.set_font_description (desc);
407 layout.set_wrap (Pango.WrapMode.WORD_CHAR);
408 layout.set_ellipsize (Pango.EllipsizeMode.END);
409 layout.set_text (text, -1);
410 Pango.Context pango_context = layout.get_context ();
411 Gdk.Screen screen = Gdk.Screen.get_default ();
412 Pango.cairo_context_set_font_options (pango_context,
413 screen.get_font_options ());
414 Pango.cairo_context_set_resolution (pango_context,
415 (float) settings.gtk_xft_dpi /
416 (float) Pango.SCALE);
417 layout.context_changed ();
418
419 int text_width;
420 int text_height;
421 get_text_extents (font, text, out text_width, out text_height);
422 cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN),
423 (float) (h - text_height) / 2.0f);
424
425 Pango.cairo_show_layout (cr, layout);
426 }
427
428 public static void
429 selected_mask (Cairo.Context cr,
430 int w,
431 int h,
432 string font,
433 string text,
434 bool enabled)
435 {
436 // clear context
437 cr.set_operator (Cairo.Operator.CLEAR);
438 cr.paint ();
439
440 // setup correct filled-drawing
441 cr.set_operator (Cairo.Operator.SOURCE);
442 cr.scale (1.0f, 1.0f);
443 cr.set_source_rgba (1.0f, 1.0f, 1.0f, 1.0f);
444
445 // draw rounded rectangle
446 _round_rect (cr,
447 1.0f,
448 0.5f,
449 0.5f,
450 ITEM_CORNER_RADIUS_ABS,
451 w - 1.0f,
452 h - 1.0f);
453 cr.fill ();
454
455 double x = _align (15.0f);
456 double y = _align ((double) h / 2.0f);
457 double r1 = 3.5f;
458 double r2 = 8.5f;
459
460 cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.0f);
461
462 // draw radio button
463 if (enabled)
464 {
465 cr.arc (x, y, r1, 0.0f * (GLib.Math.PI / 180.0f),
466 360.0f * (GLib.Math.PI / 180.0f));
467 cr.fill ();
468 cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f),
469 360.0f * (GLib.Math.PI / 180.0f));
470 cr.stroke ();
471 }
472 else
473 {
474 cr.arc (x, y, r2, 0.0f * (GLib.Math.PI / 180.0f),
475 360.0f * (GLib.Math.PI / 180.0f));
476 cr.stroke ();
477 }
478
479 // draw text
480 Pango.Layout layout = Pango.cairo_create_layout (cr);
481 Gtk.Settings settings = Gtk.Settings.get_default ();
482 Pango.FontDescription desc = Pango.FontDescription.from_string (font);
483 desc.set_weight (Pango.Weight.NORMAL);
484 layout.set_font_description (desc);
485 layout.set_wrap (Pango.WrapMode.WORD_CHAR);
486 layout.set_ellipsize (Pango.EllipsizeMode.END);
487 layout.set_text (text, -1);
488
489 Pango.Context pango_context = layout.get_context ();
490 Gdk.Screen screen = Gdk.Screen.get_default ();
491 Pango.cairo_context_set_font_options (pango_context,
492 screen.get_font_options ());
493 Pango.cairo_context_set_resolution (pango_context,
494 (float) settings.gtk_xft_dpi /
495 (float) Pango.SCALE);
496 layout.context_changed ();
497
498 int text_width;
499 int text_height;
500 get_text_extents (font, text, out text_width, out text_height);
501 cr.move_to (30.0f + Ctk.em_to_pixel (MARGIN),
502 (float) (h - text_height) / 2.0f);
503
504 Pango.cairo_show_layout (cr, layout);
505 }
506 }
507
90 public class Item : GLib.Object508 public class Item : GLib.Object
91 {509 {
92 private static void
93 _round_rect (Cairo.Context cr,
94 double aspect, // aspect-ratio
95 double x, // top-left corner
96 double y, // top-left corner
97 double corner_radius, // "size" of the corners
98 double width, // width of the rectangle
99 double height) // height of the rectangle
100 {
101 double radius = corner_radius / aspect;
102
103 // top-left, right of the corner
104 cr.move_to (x + radius, y);
105
106 // top-right, left of the corner
107 cr.line_to (x + width - radius, y);
108
109 // top-right, below the corner
110 cr.arc (x + width - radius,
111 y + radius,
112 radius,
113 -90.0f * GLib.Math.PI / 180.0f,
114 0.0f * GLib.Math.PI / 180.0f);
115
116 // bottom-right, above the corner
117 cr.line_to (x + width, y + height - radius);
118
119 // bottom-right, left of the corner
120 cr.arc (x + width - radius,
121 y + height - radius,
122 radius,
123 0.0f * GLib.Math.PI / 180.0f,
124 90.0f * GLib.Math.PI / 180.0f);
125
126 // bottom-left, right of the corner
127 cr.line_to (x + radius, y + height);
128
129 // bottom-left, above the corner
130 cr.arc (x + radius,
131 y + height - radius,
132 radius,
133 90.0f * GLib.Math.PI / 180.0f,
134 180.0f * GLib.Math.PI / 180.0f);
135
136 // top-left, right of the corner
137 cr.arc (x + radius,
138 y + radius,
139 radius,
140 180.0f * GLib.Math.PI / 180.0f,
141 270.0f * GLib.Math.PI / 180.0f);
142 }
143
144 public static void
145 get_text_extents (string font,
146 string text,
147 out int width,
148 out int height)
149 {
150 Cairo.Surface surface = new Cairo.ImageSurface (Cairo.Format.A1, 1, 1);
151 Cairo.Context cr = new Cairo.Context (surface);
152 Pango.Layout layout = Pango.cairo_create_layout (cr);
153 Gtk.Settings settings = Gtk.Settings.get_default ();
154 Pango.FontDescription desc = Pango.FontDescription.from_string (font);
155 desc.set_weight (Pango.Weight.NORMAL);
156 layout.set_font_description (desc);
157 layout.set_wrap (Pango.WrapMode.WORD_CHAR);
158 layout.set_ellipsize (Pango.EllipsizeMode.END);
159 layout.set_text (text, -1);
160 Pango.Context pango_context = layout.get_context ();
161 Gdk.Screen screen = Gdk.Screen.get_default ();
162 Pango.cairo_context_set_font_options (pango_context,
163 screen.get_font_options ());
164 Pango.cairo_context_set_resolution (pango_context,
165 (float) settings.gtk_xft_dpi /
166 (float) Pango.SCALE);
167 layout.context_changed ();
168 Pango.Rectangle log_rect;
169 layout.get_extents (null, out log_rect);
170 width = log_rect.width / Pango.SCALE;
171 height = log_rect.height / Pango.SCALE;
172 }
173
174 public static void510 public static void
175 normal_mask (Cairo.Context cr,511 normal_mask (Cairo.Context cr,
176 int w,512 int w,
@@ -271,17 +607,6 @@
271607
272 public class Menu : GLib.Object608 public class Menu : GLib.Object
273 {609 {
274 private static double
275 _align (double val)
276 {
277 double fract = val - (int) val;
278
279 if (fract != 0.5f)
280 return (double) ((int) val + 0.5f);
281 else
282 return val;
283 }
284
285 private static void610 private static void
286 _setup (out Cairo.Surface surf,611 _setup (out Cairo.Surface surf,
287 out Cairo.Context cr,612 out Cairo.Context cr,