Merge lp:~tintou/pantheon-photos/grid-css into lp:~pantheon-photos/pantheon-photos/trunk

Proposed by Corentin Noël
Status: Merged
Approved by: Danielle Foré
Approved revision: 3134
Merged at revision: 3135
Proposed branch: lp:~tintou/pantheon-photos/grid-css
Merge into: lp:~pantheon-photos/pantheon-photos/trunk
Diff against target: 885 lines (+133/-455)
8 files modified
src/CheckerboardLayout.vala (+114/-264)
src/MediaPage.vala (+0/-4)
src/Thumbnail.vala (+13/-4)
src/config/Config.vala (+0/-88)
src/config/ConfigurationInterfaces.vala (+0/-31)
src/config/GSettingsEngine.vala (+0/-1)
src/events/EventDirectoryItem.vala (+6/-27)
src/util/image.vala (+0/-36)
To merge this branch: bzr merge lp:~tintou/pantheon-photos/grid-css
Reviewer Review Type Date Requested Status
Photos Devs Pending
Review via email: mp+315732@code.launchpad.net

Commit message

Replace Cairo drawing in CheckBoardLayout with Gtk.CSS

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

This is great! Just a couple more things:

There's a whole bunch of constants we can get rid of in src/config/Config.vala from lines 45 to 53.

There are two unused methods
* draw_rounded_corners_filled in image.vala:65.1-65.32
* CheckerboardItem.get_selection_border_width in CheckerboardLayout.vala:454.5-454.42

Revision history for this message
Danielle Foré (danrabbit) wrote :

Oops, looks like you already did a new commit to remove those methods, my bad

Revision history for this message
Danielle Foré (danrabbit) wrote :

I'm going to make another branch about the constants. Looks like there's some unused ones maybe not related to this branch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CheckerboardLayout.vala'
2--- src/CheckerboardLayout.vala 2017-01-12 18:13:48 +0000
3+++ src/CheckerboardLayout.vala 2017-01-26 22:17:04 +0000
4@@ -18,6 +18,7 @@
5 */
6
7 private class CheckerboardItemText {
8+
9 private static int one_line_height = 0;
10
11 private string text;
12@@ -34,7 +35,6 @@
13 this.text = text;
14 this.marked_up = marked_up;
15 this.alignment = alignment;
16-
17 single_line = is_single_line ();
18 }
19
20@@ -121,12 +121,6 @@
21 public const int LABEL_PADDING = 4;
22 public const int BORDER_WIDTH = 0;
23
24- public const int SHADOW_RADIUS = 4;
25- public const float SHADOW_INITIAL_ALPHA = 0.3f;
26-
27- public const int TRINKET_SCALE = 16;
28- public const int TRINKET_PADDING = 1;
29-
30 public const int BRIGHTEN_SHIFT = 0x18;
31 public const int SELECTION_ICON_SIZE = 24;
32
33@@ -146,7 +140,6 @@
34 private Dimensions pixbuf_dim = Dimensions ();
35 private int col = -1;
36 private int row = -1;
37- private int horizontal_trinket_offset = 0;
38
39 public CheckerboardItem (ThumbnailSource source, Dimensions initial_pixbuf_dim, string title, string? comment,
40 bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {
41@@ -458,181 +451,61 @@
42 return selection_button_area;
43 }
44
45- protected virtual void paint_shadow (Cairo.Context ctx, Dimensions dimensions, Gdk.Point origin,
46- int radius, float initial_alpha) {
47- double rgb_all = 0.0;
48-
49- // top right corner
50- paint_shadow_in_corner (ctx, origin.x + dimensions.width, origin.y + radius, rgb_all, radius,
51- initial_alpha, -0.5 * Math.PI, 0);
52- // bottom right corner
53- paint_shadow_in_corner (ctx, origin.x + dimensions.width, origin.y + dimensions.height, rgb_all,
54- radius, initial_alpha, 0, 0.5 * Math.PI);
55- // bottom left corner
56- paint_shadow_in_corner (ctx, origin.x + radius, origin.y + dimensions.height, rgb_all, radius,
57- initial_alpha, 0.5 * Math.PI, Math.PI);
58-
59- // left right
60- Cairo.Pattern lr = new Cairo.Pattern.linear (0, origin.y + dimensions.height,
61- 0, origin.y + dimensions.height + radius);
62- lr.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
63- lr.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0.0);
64- ctx.set_source (lr);
65- ctx.rectangle (origin.x + radius, origin.y + dimensions.height, dimensions.width - radius, radius);
66- ctx.fill ();
67-
68- // top down
69- Cairo.Pattern td = new Cairo.Pattern.linear (origin.x + dimensions.width,
70- 0, origin.x + dimensions.width + radius, 0);
71- td.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
72- td.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0.0);
73- ctx.set_source (td);
74- ctx.rectangle (origin.x + dimensions.width, origin.y + radius,
75- radius, dimensions.height - radius);
76- ctx.fill ();
77- }
78-
79- protected void paint_shadow_in_corner (Cairo.Context ctx, int x, int y,
80- double rgb_all, float radius, float initial_alpha, double arc1, double arc2) {
81- Cairo.Pattern p = new Cairo.Pattern.radial (x, y, 0, x, y, radius);
82- p.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
83- p.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0);
84- ctx.set_source (p);
85- ctx.move_to (x, y);
86- ctx.arc (x, y, radius, arc1, arc2);
87- ctx.close_path ();
88- ctx.fill ();
89- }
90-
91- protected virtual void paint_border (Cairo.Context ctx, Dimensions object_dimensions,
92- Gdk.Point object_origin, int border_width) {
93- if (border_width == 1) {
94- ctx.rectangle (object_origin.x - border_width, object_origin.y - border_width,
95- object_dimensions.width + (border_width * 2),
96- object_dimensions.height + (border_width * 2));
97- ctx.fill ();
98- } else {
99- Dimensions dimensions = get_border_dimensions (object_dimensions, border_width);
100- Gdk.Point origin = get_border_origin (object_origin, border_width);
101-
102- // amount of rounding needed on corners varies by size of object
103- double scale = int.max (object_dimensions.width, object_dimensions.height);
104- draw_rounded_corners_filled (ctx, dimensions, origin, 0.25 * scale);
105- }
106- }
107-
108- protected virtual void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
109- if (pixbuf.get_has_alpha ()) {
110- ctx.rectangle (origin.x, origin.y, pixbuf.get_width (), pixbuf.get_height ());
111- ctx.fill ();
112- }
113- Gdk.cairo_set_source_pixbuf (ctx, pixbuf, origin.x, origin.y);
114- ctx.paint ();
115- }
116-
117- private int get_selection_border_width (int scale) {
118- return ((scale <= ((Thumbnail.MIN_SCALE + Thumbnail.MAX_SCALE) / 3)) ? 2 : 3)
119- + BORDER_WIDTH;
120- }
121-
122- protected virtual Gdk.Pixbuf? get_top_left_trinket (int scale) {
123- return null;
124- }
125-
126- protected virtual Gdk.Pixbuf? get_top_right_trinket (int scale) {
127- return null;
128- }
129-
130- protected virtual Gdk.Pixbuf? get_bottom_left_trinket (int scale) {
131- return null;
132- }
133-
134- protected virtual Gdk.Pixbuf? get_bottom_right_trinket (int scale) {
135- return null;
136- }
137-
138- public void paint (Cairo.Context ctx, Gdk.RGBA selected_color,
139- Gdk.RGBA text_color, Gdk.RGBA? border_color, int scale_factor) {
140- // calc the top-left point of the pixbuf
141+ public virtual void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
142 Gdk.Point pixbuf_origin = Gdk.Point ();
143 pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;
144 pixbuf_origin.y = allocation.y + FRAME_WIDTH + BORDER_WIDTH;
145
146- ctx.set_line_width (FRAME_WIDTH);
147- ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,
148- selected_color.alpha);
149-
150- // draw shadow
151- if (border_color != null) {
152- ctx.save ();
153- Dimensions shadow_dim = Dimensions ();
154- shadow_dim.width = pixbuf_dim.width + BORDER_WIDTH;
155- shadow_dim.height = pixbuf_dim.height + BORDER_WIDTH;
156- paint_shadow (ctx, shadow_dim, pixbuf_origin, SHADOW_RADIUS, SHADOW_INITIAL_ALPHA);
157- ctx.restore ();
158- }
159-
160- string? selection_icon = null;
161-
162- // draw selection border
163+ style_context.save ();
164+ string selection_icon = null;
165 if (is_selected ()) {
166- selection_icon = Resources.ICON_SELECTION_CHECKED;
167-
168- // border thickness depends on the size of the thumbnail
169- ctx.save ();
170- paint_border (ctx, pixbuf_dim, pixbuf_origin,
171- get_selection_border_width (int.max (pixbuf_dim.width, pixbuf_dim.height)));
172- ctx.restore ();
173- }
174-
175- // draw border
176- if (border_color != null) {
177- ctx.save ();
178- ctx.set_source_rgba (border_color.red, border_color.green, border_color.blue,
179- border_color.alpha);
180- paint_border (ctx, pixbuf_dim, pixbuf_origin, BORDER_WIDTH);
181- ctx.restore ();
182+ style_context.set_state (Gtk.StateFlags.CHECKED);
183+ selection_icon = Resources.ICON_SELECTION_REMOVE;
184+ } else {
185+ if (brightened != null) {
186+ selection_icon = Resources.ICON_SELECTION_ADD;
187+ }
188 }
189
190 if (display_pixbuf != null) {
191+ style_context.render_background (ctx, pixbuf_origin.x, pixbuf_origin.y, display_pixbuf.width, display_pixbuf.height);
192+ var radius = style_context.get_property ("border-radius", style_context.get_state ()).get_int ();
193 ctx.save ();
194- paint_image (ctx, display_pixbuf, pixbuf_origin);
195+ ctx.move_to (pixbuf_origin.x + radius, pixbuf_origin.y);
196+ ctx.arc (pixbuf_origin.x + display_pixbuf.width - radius, pixbuf_origin.y + radius, radius, Math.PI * 1.5, Math.PI * 2);
197+ ctx.arc (pixbuf_origin.x + display_pixbuf.width - radius, pixbuf_origin.y + display_pixbuf.height - radius, radius, 0, Math.PI * 0.5);
198+ ctx.arc (pixbuf_origin.x + radius, pixbuf_origin.y + display_pixbuf.height - radius, radius, Math.PI * 0.5, Math.PI);
199+ ctx.arc (pixbuf_origin.x + radius, pixbuf_origin.y + radius, radius, Math.PI, Math.PI * 1.5);
200+ ctx.close_path ();
201+ Gdk.cairo_set_source_pixbuf (ctx, display_pixbuf, pixbuf_origin.x, pixbuf_origin.y);
202+ ctx.clip ();
203+ ctx.paint ();
204 ctx.restore ();
205- }
206-
207- // decide which icon to use for the selection button
208- if (brightened != null && pixbuf != null) {
209- if (is_selected ())
210- selection_icon = Resources.ICON_SELECTION_REMOVE;
211- else
212- selection_icon = Resources.ICON_SELECTION_ADD;
213- }
214-
215+
216+ style_context.render_frame (ctx, pixbuf_origin.x, pixbuf_origin.y, display_pixbuf.width, display_pixbuf.height);
217+ }
218+
219+ // Add the selection helper
220 Gdk.Pixbuf? selection_icon_pix = null;
221+ var scale_factor = style_context.get_scale ();
222 if (selection_icon != null) {
223 try {
224- selection_icon_pix = Gtk.IconTheme.get_default ().load_icon_for_scale (selection_icon,
225- SELECTION_ICON_SIZE, scale_factor, Gtk.IconLookupFlags.GENERIC_FALLBACK);
226+ selection_icon_pix = Gtk.IconTheme.get_default ().load_icon_for_scale (selection_icon, SELECTION_ICON_SIZE, scale_factor, Gtk.IconLookupFlags.GENERIC_FALLBACK);
227 } catch (Error err) {
228 warning ("Could not load %s: %s", selection_icon, err.message);
229 }
230 }
231
232- // draw selector icon
233 if (selection_icon_pix != null) {
234- // calc the top-left point of the selection button
235 Gdk.Rectangle selection_icon_area = get_selection_button_area ();
236 ctx.save ();
237 ctx.scale (1.0 / scale_factor, 1.0 / scale_factor);
238- int icon_x = selection_icon_area.x * scale_factor;
239- int icon_y = selection_icon_area.y * scale_factor;
240- Gdk.cairo_set_source_pixbuf (ctx, selection_icon_pix, icon_x, icon_y);
241- ctx.paint ();
242+ style_context.render_icon (ctx, selection_icon_pix, selection_icon_area.x * scale_factor, selection_icon_area.y * scale_factor);
243 ctx.restore ();
244 }
245
246- ctx.set_source_rgba (text_color.red, text_color.green, text_color.blue, text_color.alpha);
247-
248+ // Add the title and subtitle
249+ style_context.add_class (Gtk.STYLE_CLASS_LABEL);
250 // title and subtitles are LABEL_PADDING below bottom of pixbuf
251 int text_y = allocation.y + FRAME_WIDTH + pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;
252 if (title != null && title_visible) {
253@@ -643,8 +516,9 @@
254 title.allocation.width = pixbuf_dim.width;
255 title.allocation.height = title.get_height ();
256
257- ctx.move_to (title.allocation.x, title.allocation.y);
258- Pango.cairo_show_layout (ctx, title.get_pango_layout (pixbuf_dim.width));
259+ var layout = title.get_pango_layout (pixbuf_dim.width);
260+ Pango.cairo_update_layout (ctx, layout);
261+ style_context.render_layout (ctx, title.allocation.x, title.allocation.y, layout);
262
263 text_y += title.get_height () + LABEL_PADDING;
264 }
265@@ -655,8 +529,9 @@
266 comment.allocation.width = pixbuf_dim.width;
267 comment.allocation.height = comment.get_height ();
268
269- ctx.move_to (comment.allocation.x, comment.allocation.y);
270- Pango.cairo_show_layout (ctx, comment.get_pango_layout (pixbuf_dim.width));
271+ var layout = comment.get_pango_layout (pixbuf_dim.width);
272+ Pango.cairo_update_layout (ctx, layout);
273+ style_context.render_layout (ctx, comment.allocation.x, comment.allocation.y, layout);
274
275 text_y += comment.get_height () + LABEL_PADDING;
276 }
277@@ -667,64 +542,14 @@
278 subtitle.allocation.width = pixbuf_dim.width;
279 subtitle.allocation.height = subtitle.get_height ();
280
281- ctx.move_to (subtitle.allocation.x, subtitle.allocation.y);
282- Pango.cairo_show_layout (ctx, subtitle.get_pango_layout (pixbuf_dim.width));
283+ var layout = subtitle.get_pango_layout (pixbuf_dim.width);
284+ Pango.cairo_update_layout (ctx, layout);
285+ style_context.render_layout (ctx, subtitle.allocation.x, subtitle.allocation.y, layout);
286
287 // increment text_y if more text lines follow
288 }
289
290- ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,
291- selected_color.alpha);
292-
293- // draw trinkets last
294- Gdk.Pixbuf? trinket = get_bottom_left_trinket (TRINKET_SCALE);
295- if (trinket != null) {
296- int x = pixbuf_origin.x + TRINKET_PADDING + get_horizontal_trinket_offset ();
297- int y = pixbuf_origin.y + pixbuf_dim.height - trinket.get_height () -
298- TRINKET_PADDING;
299- Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
300- ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
301- ctx.fill ();
302- }
303-
304- trinket = get_top_left_trinket (TRINKET_SCALE);
305- if (trinket != null) {
306- int x = pixbuf_origin.x + TRINKET_PADDING + get_horizontal_trinket_offset ();
307- int y = pixbuf_origin.y + TRINKET_PADDING;
308- Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
309- ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
310- ctx.fill ();
311- }
312-
313- trinket = get_top_right_trinket (TRINKET_SCALE);
314- if (trinket != null) {
315- int x = pixbuf_origin.x + pixbuf_dim.width - trinket.width -
316- get_horizontal_trinket_offset () - TRINKET_PADDING;
317- int y = pixbuf_origin.y + TRINKET_PADDING;
318- Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
319- ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
320- ctx.fill ();
321- }
322-
323- trinket = get_bottom_right_trinket (TRINKET_SCALE);
324- if (trinket != null) {
325- int x = pixbuf_origin.x + pixbuf_dim.width - trinket.width -
326- get_horizontal_trinket_offset () - TRINKET_PADDING;
327- int y = pixbuf_origin.y + pixbuf_dim.height - trinket.height -
328- TRINKET_PADDING;
329- Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
330- ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
331- ctx.fill ();
332- }
333- }
334-
335- protected void set_horizontal_trinket_offset (int horizontal_trinket_offset) {
336- assert (horizontal_trinket_offset >= 0);
337- this.horizontal_trinket_offset = horizontal_trinket_offset;
338- }
339-
340- protected int get_horizontal_trinket_offset () {
341- return horizontal_trinket_offset;
342+ style_context.restore ();
343 }
344
345 public void set_grid_coordinates (int col, int row) {
346@@ -802,6 +627,64 @@
347 }
348
349 public class CheckerboardLayout : Gtk.DrawingArea {
350+ private const string CHECKBOARD_CSS = """
351+ .checkerboard-layout {
352+ background-color: #383e41;
353+ background-image:
354+ linear-gradient(
355+ 45deg,
356+ alpha (
357+ #000,
358+ 0.1
359+ ) 25%,
360+ transparent 25%,
361+ transparent 75%,
362+ alpha (
363+ #000,
364+ 0.1
365+ ) 75%,
366+ alpha (
367+ #000,
368+ 0.1
369+ )
370+ ),
371+ linear-gradient(
372+ 45deg,
373+ alpha (
374+ #000,
375+ 0.1
376+ ) 25%,
377+ transparent 25%,
378+ transparent 75%,
379+ alpha (
380+ #000,
381+ 0.1
382+ ) 75%,
383+ alpha (
384+ #000,
385+ 0.1
386+ )
387+ );
388+ background-size: 24px 24px;
389+ background-position: 0 0, 12px 12px;
390+ }
391+ .checkboard-layout .item {
392+ background-color: #eee;
393+ }
394+ .checkerboard-layout .label {
395+ color: #c0c6c4;
396+ text-shadow: 0 1px 2px alpha(#000, 0.5);
397+ }
398+ .event {
399+ border: 3px solid #f4f4f4;
400+ border-radius: 6px;
401+ }
402+ .event:checked {
403+ border-color: @selected_bg_color;
404+ }
405+ """;
406+
407+
408 public const int TOP_PADDING = 16;
409 public const int BOTTOM_PADDING = 16;
410 public const int ROW_GUTTER_PADDING = 24;
411@@ -837,9 +720,6 @@
412 private Gtk.Adjustment hadjustment = null;
413 private Gtk.Adjustment vadjustment = null;
414 private string message = null;
415- private Gdk.RGBA selected_color;
416- private Gdk.RGBA unselected_color;
417- private Gdk.RGBA border_color;
418 private Gdk.Rectangle visible_page = Gdk.Rectangle ();
419 private int last_width = 0;
420 private int columns = 0;
421@@ -858,7 +738,6 @@
422
423 public CheckerboardLayout (ViewCollection view) {
424 this.view = view;
425- this.get_style_context ().add_class ("checkerboard-layout");
426
427 clear_drag_select ();
428
429@@ -873,7 +752,15 @@
430 view.items_selected.connect (on_items_selection_changed);
431 view.items_unselected.connect (on_items_selection_changed);
432
433- Config.Facade.get_instance ().colors_changed.connect (on_colors_changed);
434+ weak Gtk.StyleContext style_context = get_style_context ();
435+ style_context.add_class ("checkerboard-layout");
436+ var css_provicer = new Gtk.CssProvider ();
437+ try {
438+ css_provicer.load_from_data (CHECKBOARD_CSS);
439+ style_context.add_provider (css_provicer, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
440+ } catch (Error e) {
441+ critical (e.message);
442+ }
443
444 // CheckerboardItems offer tooltips
445 has_tooltip = true;
446@@ -902,8 +789,6 @@
447
448 if (parent != null)
449 parent.size_allocate.disconnect (on_viewport_resized);
450-
451- Config.Facade.get_instance ().colors_changed.disconnect (on_colors_changed);
452 }
453
454 public void set_adjustments (Gtk.Adjustment hadjustment, Gtk.Adjustment vadjustment) {
455@@ -1796,19 +1681,6 @@
456 }
457 }
458
459- public override void map () {
460- base.map ();
461-
462- set_colors ();
463- }
464-
465- private void set_colors (bool in_focus = true) {
466- // set up selected/unselected colors
467- selected_color = Config.Facade.get_instance ().get_selected_color (in_focus);
468- unselected_color = Config.Facade.get_instance ().get_unselected_color ();
469- border_color = Config.Facade.get_instance ().get_border_color ();
470- }
471-
472 public override void size_allocate (Gtk.Allocation allocation) {
473 base.size_allocate (allocation);
474
475@@ -1833,10 +1705,14 @@
476 expose_items ("draw");
477
478 // have all items in the exposed area paint themselves
479+ weak Gtk.StyleContext style_context = get_style_context ();
480+ style_context.save ();
481+ style_context.add_class ("card");
482 foreach (CheckerboardItem item in intersection (visible_page)) {
483- item.paint (ctx, item.is_selected () ? selected_color : unselected_color,
484- unselected_color, border_color, scale_factor);
485+ item.paint (ctx, style_context);
486 }
487+
488+ style_context.restore ();
489 } else {
490 // draw the message in the center of the window
491 Pango.Layout pango_layout = create_pango_layout (message);
492@@ -1852,7 +1728,6 @@
493 int y = allocation.height - text_height;
494 y = (y > 0) ? y / 2 : 0;
495
496- ctx.set_source_rgb (unselected_color.red, unselected_color.green, unselected_color.blue);
497 ctx.move_to (x, y);
498 Pango.cairo_show_layout (ctx, pango_layout);
499 }
500@@ -1878,25 +1753,6 @@
501 Gdk.Rectangle visible_page = get_adjustment_page (hadjustment, vadjustment);
502 Gdk.Rectangle visible_band = Gdk.Rectangle ();
503 visible_page.intersect (selection_band, out visible_band);
504-
505- // pixelate selection rectangle interior
506- if (visible_band.width > 1 && visible_band.height > 1) {
507- ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,
508- SELECTION_ALPHA);
509- ctx.rectangle (visible_band.x, visible_band.y, visible_band.width,
510- visible_band.height);
511- ctx.fill ();
512- }
513-
514- // border
515- // See this for an explanation of the adjustments to the band's dimensions
516- // http://cairographics.org/FAQ/#sharp_lines
517- ctx.set_line_width (1.0);
518- ctx.set_line_cap (Cairo.LineCap.SQUARE);
519- ctx.set_source_rgb (selected_color.red, selected_color.green, selected_color.blue);
520- ctx.rectangle ((double) selection_band.x + 0.5, (double) selection_band.y + 0.5,
521- (double) selection_band.width - 1.0, (double) selection_band.height - 1.0);
522- ctx.stroke ();
523 }
524
525 public override bool query_tooltip (int x, int y, bool keyboard_mode, Gtk.Tooltip tooltip) {
526@@ -1905,19 +1761,13 @@
527 return (item != null) ? item.query_tooltip (x, y, tooltip) : false;
528 }
529
530- private void on_colors_changed () {
531- set_colors ();
532- }
533-
534 public override bool focus_in_event (Gdk.EventFocus event) {
535- set_colors (true);
536 items_dirty ("focus_in_event", view.get_selected ());
537
538 return base.focus_in_event (event);
539 }
540
541 public override bool focus_out_event (Gdk.EventFocus event) {
542- set_colors (false);
543 items_dirty ("focus_out_event", view.get_selected ());
544
545 return base.focus_out_event (event);
546
547=== modified file 'src/MediaPage.vala'
548--- src/MediaPage.vala 2017-01-26 15:35:50 +0000
549+++ src/MediaPage.vala 2017-01-26 22:17:04 +0000
550@@ -24,10 +24,6 @@
551 string? comment, bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {
552 base (source, initial_pixbuf_dim, title, comment, marked_up, alignment);
553 }
554-
555- protected override void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
556- base.paint_image (ctx, pixbuf, origin);
557- }
558 }
559
560 public abstract class MediaPage : CheckerboardPage {
561
562=== modified file 'src/Thumbnail.vala'
563--- src/Thumbnail.vala 2017-01-12 18:13:48 +0000
564+++ src/Thumbnail.vala 2017-01-26 22:17:04 +0000
565@@ -24,6 +24,8 @@
566 // SIZE (int, scale)
567 public const string PROP_SIZE = "thumbnail-size";
568
569+ public const int FLAG_OFFSET = 1;
570+
571 public static int MIN_SCALE {
572 get {
573 return 92;
574@@ -371,10 +373,17 @@
575 base.unexposed ();
576 }
577
578- protected override Gdk.Pixbuf? get_top_right_trinket (int scale) {
579- Flaggable? flaggable = media as Flaggable;
580+ public override void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
581+ base.paint (ctx, style_context);
582
583- return (flaggable != null && flaggable.is_flagged ())
584- ? Resources.get_flag_trinket () : null;
585+ if (media != null && media is Flaggable) {
586+ if (((Flaggable) media).is_flagged ()) {
587+ style_context.save ();
588+ style_context.add_class (Granite.StyleClass.OVERLAY_BAR);
589+ var flag_icon = Resources.get_flag_trinket ();
590+ style_context.render_icon (ctx, flag_icon, allocation.x + allocation.width - (flag_icon.width + FRAME_WIDTH + BORDER_WIDTH + FLAG_OFFSET), allocation.y + FRAME_WIDTH + BORDER_WIDTH + FLAG_OFFSET);
591+ style_context.restore ();
592+ }
593+ }
594 }
595 }
596
597=== modified file 'src/config/Config.vala'
598--- src/config/Config.vala 2017-01-12 18:13:48 +0000
599+++ src/config/Config.vala 2017-01-26 22:17:04 +0000
600@@ -52,20 +52,10 @@
601 private const string DARK_UNFOCUSED_SELECTED_COLOR = "#888";
602 private const string LIGHT_UNFOCUSED_SELECTED_COLOR = "#888";
603
604- private string bg_color = null;
605- private string selected_color = null;
606- private string unselected_color = null;
607- private string unfocused_selected_color = null;
608- private string border_color = null;
609-
610 private static Facade instance = null;
611
612- public signal void colors_changed ();
613-
614 private Facade () {
615 base (new GSettingsConfigurationEngine ());
616-
617- bg_color_name_changed.connect (on_color_name_changed);
618 }
619
620 public static Facade get_instance () {
621@@ -74,84 +64,6 @@
622
623 return instance;
624 }
625-
626- private void on_color_name_changed () {
627- colors_changed ();
628- }
629-
630- private void set_text_colors (Gdk.RGBA bg_color) {
631- // since bg color is greyscale, we only need to compare the red value to the threshold,
632- // which determines whether the background is dark enough to need light text and selection
633- // colors or vice versa
634- if (bg_color.red > BLACK_THRESHOLD) {
635- selected_color = DARK_SELECTED_COLOR;
636- unselected_color = DARK_UNSELECTED_COLOR;
637- unfocused_selected_color = DARK_UNFOCUSED_SELECTED_COLOR;
638- border_color = DARK_BORDER_COLOR;
639- } else {
640- selected_color = LIGHT_SELECTED_COLOR;
641- unselected_color = LIGHT_UNSELECTED_COLOR;
642- unfocused_selected_color = LIGHT_UNFOCUSED_SELECTED_COLOR;
643- border_color = LIGHT_BORDER_COLOR;
644- }
645- }
646-
647- private void get_colors () {
648- bg_color = base.get_bg_color_name ();
649-
650- if (!is_color_parsable (bg_color))
651- bg_color = DEFAULT_BG_COLOR;
652-
653- set_text_colors (parse_color (bg_color));
654- }
655-
656- public Gdk.RGBA get_bg_color () {
657- if (is_string_empty (bg_color))
658- get_colors ();
659-
660- return parse_color (bg_color);
661- }
662-
663- public Gdk.RGBA get_selected_color (bool in_focus = true) {
664- if (in_focus) {
665- if (is_string_empty (selected_color))
666- get_colors ();
667-
668- return parse_color (selected_color);
669- } else {
670- if (is_string_empty (unfocused_selected_color))
671- get_colors ();
672-
673- return parse_color (unfocused_selected_color);
674- }
675- }
676-
677- public Gdk.RGBA get_unselected_color () {
678- if (is_string_empty (unselected_color))
679- get_colors ();
680-
681- return parse_color (unselected_color);
682- }
683-
684- public Gdk.RGBA get_border_color () {
685- if (is_string_empty (border_color))
686- get_colors ();
687-
688- return parse_color (border_color);
689- }
690-
691- public void set_bg_color (Gdk.RGBA color) {
692- uint8 col_tmp = (uint8) (color.red * 255.0);
693-
694- bg_color = "#%02X%02X%02X".printf (col_tmp, col_tmp, col_tmp);
695- set_bg_color_name (bg_color);
696-
697- set_text_colors (color);
698- }
699-
700- public void commit_bg_color () {
701- base.set_bg_color_name (bg_color);
702- }
703 }
704
705 // preconfigure may be deleted if not used.
706
707=== modified file 'src/config/ConfigurationInterfaces.vala'
708--- src/config/ConfigurationInterfaces.vala 2017-01-12 18:13:48 +0000
709+++ src/config/ConfigurationInterfaces.vala 2017-01-26 22:17:04 +0000
710@@ -34,7 +34,6 @@
711
712 public enum ConfigurableProperty {
713 AUTO_IMPORT_FROM_LIBRARY = 0,
714- BG_COLOR_NAME,
715 COMMIT_METADATA_TO_MASTERS,
716 DESKTOP_BACKGROUND_FILE,
717 DESKTOP_BACKGROUND_MODE,
718@@ -103,9 +102,6 @@
719 case AUTO_IMPORT_FROM_LIBRARY:
720 return "AUTO_IMPORT_FROM_LIBRARY";
721
722- case BG_COLOR_NAME:
723- return "BG_COLOR_NAME";
724-
725 case COMMIT_METADATA_TO_MASTERS:
726 return "COMMIT_METADATA_TO_MASTERS";
727
728@@ -321,7 +317,6 @@
729 private ConfigurationEngine engine;
730
731 public signal void auto_import_from_library_changed ();
732- public signal void bg_color_name_changed ();
733 public signal void commit_metadata_to_masters_changed ();
734 public signal void events_sort_ascending_changed ();
735 public signal void external_app_changed ();
736@@ -341,10 +336,6 @@
737 auto_import_from_library_changed ();
738 break;
739
740- case ConfigurableProperty.BG_COLOR_NAME:
741- bg_color_name_changed ();
742- break;
743-
744 case ConfigurableProperty.COMMIT_METADATA_TO_MASTERS:
745 commit_metadata_to_masters_changed ();
746 break;
747@@ -405,28 +396,6 @@
748 }
749
750 //
751- // bg color name
752- //
753- public virtual string get_bg_color_name () {
754- try {
755- return get_engine ().get_string_property (ConfigurableProperty.BG_COLOR_NAME);
756- } catch (ConfigurationError err) {
757- on_configuration_error (err);
758-
759- return "";
760- }
761- }
762-
763- public virtual void set_bg_color_name (string color_name) {
764- try {
765- get_engine ().set_string_property (ConfigurableProperty.BG_COLOR_NAME, color_name);
766- } catch (ConfigurationError err) {
767- on_configuration_error (err);
768- return;
769- }
770- }
771-
772- //
773 // commit metadata to masters
774 //
775 public virtual bool get_commit_metadata_to_masters () {
776
777=== modified file 'src/config/GSettingsEngine.vala'
778--- src/config/GSettingsEngine.vala 2017-01-12 18:13:48 +0000
779+++ src/config/GSettingsEngine.vala 2017-01-26 22:17:04 +0000
780@@ -47,7 +47,6 @@
781 schema_names = new string[ConfigurableProperty.NUM_PROPERTIES];
782
783 schema_names[ConfigurableProperty.AUTO_IMPORT_FROM_LIBRARY] = FILES_PREFS_SCHEMA_NAME;
784- schema_names[ConfigurableProperty.BG_COLOR_NAME] = UI_PREFS_SCHEMA_NAME;
785 schema_names[ConfigurableProperty.COMMIT_METADATA_TO_MASTERS] = FILES_PREFS_SCHEMA_NAME;
786 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_FILE] = SYSTEM_DESKTOP_SCHEMA_NAME;
787 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_MODE] = SYSTEM_DESKTOP_SCHEMA_NAME;
788
789=== modified file 'src/events/EventDirectoryItem.vala'
790--- src/events/EventDirectoryItem.vala 2017-01-12 18:13:48 +0000
791+++ src/events/EventDirectoryItem.vala 2017-01-26 22:17:04 +0000
792@@ -161,33 +161,12 @@
793 base.thumbnail_altered ();
794 }
795
796- protected override void paint_shadow (Cairo.Context ctx, Dimensions dimensions, Gdk.Point origin,
797- int radius, float initial_alpha) {
798- Dimensions altered = Dimensions (dimensions.width - 25, dimensions.height - 25);
799- base.paint_shadow (ctx, altered, origin, 36, initial_alpha);
800- }
801-
802- protected override void paint_border (Cairo.Context ctx, Dimensions object_dimensions,
803- Gdk.Point object_origin, int border_width) {
804- Dimensions dimensions = get_border_dimensions (object_dimensions, border_width);
805- Gdk.Point origin = get_border_origin (object_origin, border_width);
806-
807- draw_rounded_corners_filled (ctx, dimensions, origin, 6.0);
808- }
809-
810- protected override void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf,
811- Gdk.Point origin) {
812- Dimensions dimensions = Dimensions.for_pixbuf (pixbuf);
813-
814- if (pixbuf.get_has_alpha ())
815- draw_rounded_corners_filled (ctx, dimensions, origin, 6.0);
816-
817- // use rounded corners on events
818- context_rounded_corners (ctx, dimensions, origin, 6.0);
819- Gdk.cairo_set_source_pixbuf (ctx, pixbuf, origin.x, origin.y);
820- ctx.paint ();
821- }
822-
823+ public override void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
824+ style_context.save ();
825+ style_context.add_class ("event");
826+ base.paint (ctx, style_context);
827+ style_context.restore ();
828+ }
829 private void update_comment (bool init = false) {
830 string comment = event.get_comment ();
831 if (is_string_empty (comment))
832
833=== modified file 'src/util/image.vala'
834--- src/util/image.vala 2017-01-12 18:13:48 +0000
835+++ src/util/image.vala 2017-01-26 22:17:04 +0000
836@@ -17,11 +17,6 @@
837 * Boston, MA 02110-1301 USA
838 */
839
840-bool is_color_parsable (string spec) {
841- Gdk.Color color;
842- return Gdk.Color.parse (spec, out color);
843-}
844-
845 Gdk.RGBA parse_color (string spec) {
846 return fetch_color (spec);
847 }
848@@ -65,37 +60,6 @@
849 return pixbuf.scale_simple (resized.width, resized.height, interp);
850 }
851
852-private const double DEGREE = Math.PI / 180.0;
853-
854-void draw_rounded_corners_filled (Cairo.Context ctx, Dimensions dim, Gdk.Point origin,
855- double radius_proportion) {
856- context_rounded_corners (ctx, dim, origin, radius_proportion);
857- ctx.paint ();
858-}
859-
860-void context_rounded_corners (Cairo.Context cx, Dimensions dim, Gdk.Point origin,
861- double radius_proportion) {
862- // establish a reasonable range
863- radius_proportion = radius_proportion.clamp (2.0, 100.0);
864-
865- double left = origin.x;
866- double top = origin.y;
867- double right = origin.x + dim.width;
868- double bottom = origin.y + dim.height;
869-
870- // the radius of the corners is proportional to the distance of the minor axis
871- double radius = ((double) dim.minor_axis ()) / radius_proportion;
872-
873- // create context and clipping region, starting from the top right arc and working around
874- // clockwise
875- cx.move_to (left, top);
876- cx.arc (right - radius, top + radius, radius, -90 * DEGREE, 0 * DEGREE);
877- cx.arc (right - radius, bottom - radius, radius, 0 * DEGREE, 90 * DEGREE);
878- cx.arc (left + radius, bottom - radius, radius, 90 * DEGREE, 180 * DEGREE);
879- cx.arc (left + radius, top + radius, radius, 180 * DEGREE, 270 * DEGREE);
880- cx.clip ();
881-}
882-
883 inline uchar shift_color_byte (int b, int shift) {
884 return (uchar) (b + shift).clamp (0, 255);
885 }

Subscribers

People subscribed via source and target branches

to all changes: