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
=== modified file 'src/CheckerboardLayout.vala'
--- src/CheckerboardLayout.vala 2017-01-12 18:13:48 +0000
+++ src/CheckerboardLayout.vala 2017-01-26 22:17:04 +0000
@@ -18,6 +18,7 @@
18*/18*/
1919
20private class CheckerboardItemText {20private class CheckerboardItemText {
21
21 private static int one_line_height = 0;22 private static int one_line_height = 0;
2223
23 private string text;24 private string text;
@@ -34,7 +35,6 @@
34 this.text = text;35 this.text = text;
35 this.marked_up = marked_up;36 this.marked_up = marked_up;
36 this.alignment = alignment;37 this.alignment = alignment;
37
38 single_line = is_single_line ();38 single_line = is_single_line ();
39 }39 }
4040
@@ -121,12 +121,6 @@
121 public const int LABEL_PADDING = 4;121 public const int LABEL_PADDING = 4;
122 public const int BORDER_WIDTH = 0;122 public const int BORDER_WIDTH = 0;
123123
124 public const int SHADOW_RADIUS = 4;
125 public const float SHADOW_INITIAL_ALPHA = 0.3f;
126
127 public const int TRINKET_SCALE = 16;
128 public const int TRINKET_PADDING = 1;
129
130 public const int BRIGHTEN_SHIFT = 0x18;124 public const int BRIGHTEN_SHIFT = 0x18;
131 public const int SELECTION_ICON_SIZE = 24;125 public const int SELECTION_ICON_SIZE = 24;
132126
@@ -146,7 +140,6 @@
146 private Dimensions pixbuf_dim = Dimensions ();140 private Dimensions pixbuf_dim = Dimensions ();
147 private int col = -1;141 private int col = -1;
148 private int row = -1;142 private int row = -1;
149 private int horizontal_trinket_offset = 0;
150143
151 public CheckerboardItem (ThumbnailSource source, Dimensions initial_pixbuf_dim, string title, string? comment,144 public CheckerboardItem (ThumbnailSource source, Dimensions initial_pixbuf_dim, string title, string? comment,
152 bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {145 bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {
@@ -458,181 +451,61 @@
458 return selection_button_area;451 return selection_button_area;
459 }452 }
460453
461 protected virtual void paint_shadow (Cairo.Context ctx, Dimensions dimensions, Gdk.Point origin,454 public virtual void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
462 int radius, float initial_alpha) {
463 double rgb_all = 0.0;
464
465 // top right corner
466 paint_shadow_in_corner (ctx, origin.x + dimensions.width, origin.y + radius, rgb_all, radius,
467 initial_alpha, -0.5 * Math.PI, 0);
468 // bottom right corner
469 paint_shadow_in_corner (ctx, origin.x + dimensions.width, origin.y + dimensions.height, rgb_all,
470 radius, initial_alpha, 0, 0.5 * Math.PI);
471 // bottom left corner
472 paint_shadow_in_corner (ctx, origin.x + radius, origin.y + dimensions.height, rgb_all, radius,
473 initial_alpha, 0.5 * Math.PI, Math.PI);
474
475 // left right
476 Cairo.Pattern lr = new Cairo.Pattern.linear (0, origin.y + dimensions.height,
477 0, origin.y + dimensions.height + radius);
478 lr.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
479 lr.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0.0);
480 ctx.set_source (lr);
481 ctx.rectangle (origin.x + radius, origin.y + dimensions.height, dimensions.width - radius, radius);
482 ctx.fill ();
483
484 // top down
485 Cairo.Pattern td = new Cairo.Pattern.linear (origin.x + dimensions.width,
486 0, origin.x + dimensions.width + radius, 0);
487 td.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
488 td.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0.0);
489 ctx.set_source (td);
490 ctx.rectangle (origin.x + dimensions.width, origin.y + radius,
491 radius, dimensions.height - radius);
492 ctx.fill ();
493 }
494
495 protected void paint_shadow_in_corner (Cairo.Context ctx, int x, int y,
496 double rgb_all, float radius, float initial_alpha, double arc1, double arc2) {
497 Cairo.Pattern p = new Cairo.Pattern.radial (x, y, 0, x, y, radius);
498 p.add_color_stop_rgba (0.0, rgb_all, rgb_all, rgb_all, initial_alpha);
499 p.add_color_stop_rgba (1.0, rgb_all, rgb_all, rgb_all, 0);
500 ctx.set_source (p);
501 ctx.move_to (x, y);
502 ctx.arc (x, y, radius, arc1, arc2);
503 ctx.close_path ();
504 ctx.fill ();
505 }
506
507 protected virtual void paint_border (Cairo.Context ctx, Dimensions object_dimensions,
508 Gdk.Point object_origin, int border_width) {
509 if (border_width == 1) {
510 ctx.rectangle (object_origin.x - border_width, object_origin.y - border_width,
511 object_dimensions.width + (border_width * 2),
512 object_dimensions.height + (border_width * 2));
513 ctx.fill ();
514 } else {
515 Dimensions dimensions = get_border_dimensions (object_dimensions, border_width);
516 Gdk.Point origin = get_border_origin (object_origin, border_width);
517
518 // amount of rounding needed on corners varies by size of object
519 double scale = int.max (object_dimensions.width, object_dimensions.height);
520 draw_rounded_corners_filled (ctx, dimensions, origin, 0.25 * scale);
521 }
522 }
523
524 protected virtual void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
525 if (pixbuf.get_has_alpha ()) {
526 ctx.rectangle (origin.x, origin.y, pixbuf.get_width (), pixbuf.get_height ());
527 ctx.fill ();
528 }
529 Gdk.cairo_set_source_pixbuf (ctx, pixbuf, origin.x, origin.y);
530 ctx.paint ();
531 }
532
533 private int get_selection_border_width (int scale) {
534 return ((scale <= ((Thumbnail.MIN_SCALE + Thumbnail.MAX_SCALE) / 3)) ? 2 : 3)
535 + BORDER_WIDTH;
536 }
537
538 protected virtual Gdk.Pixbuf? get_top_left_trinket (int scale) {
539 return null;
540 }
541
542 protected virtual Gdk.Pixbuf? get_top_right_trinket (int scale) {
543 return null;
544 }
545
546 protected virtual Gdk.Pixbuf? get_bottom_left_trinket (int scale) {
547 return null;
548 }
549
550 protected virtual Gdk.Pixbuf? get_bottom_right_trinket (int scale) {
551 return null;
552 }
553
554 public void paint (Cairo.Context ctx, Gdk.RGBA selected_color,
555 Gdk.RGBA text_color, Gdk.RGBA? border_color, int scale_factor) {
556 // calc the top-left point of the pixbuf
557 Gdk.Point pixbuf_origin = Gdk.Point ();455 Gdk.Point pixbuf_origin = Gdk.Point ();
558 pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;456 pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;
559 pixbuf_origin.y = allocation.y + FRAME_WIDTH + BORDER_WIDTH;457 pixbuf_origin.y = allocation.y + FRAME_WIDTH + BORDER_WIDTH;
560458
561 ctx.set_line_width (FRAME_WIDTH);459 style_context.save ();
562 ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,460 string selection_icon = null;
563 selected_color.alpha);
564
565 // draw shadow
566 if (border_color != null) {
567 ctx.save ();
568 Dimensions shadow_dim = Dimensions ();
569 shadow_dim.width = pixbuf_dim.width + BORDER_WIDTH;
570 shadow_dim.height = pixbuf_dim.height + BORDER_WIDTH;
571 paint_shadow (ctx, shadow_dim, pixbuf_origin, SHADOW_RADIUS, SHADOW_INITIAL_ALPHA);
572 ctx.restore ();
573 }
574
575 string? selection_icon = null;
576
577 // draw selection border
578 if (is_selected ()) {461 if (is_selected ()) {
579 selection_icon = Resources.ICON_SELECTION_CHECKED;462 style_context.set_state (Gtk.StateFlags.CHECKED);
580463 selection_icon = Resources.ICON_SELECTION_REMOVE;
581 // border thickness depends on the size of the thumbnail464 } else {
582 ctx.save ();465 if (brightened != null) {
583 paint_border (ctx, pixbuf_dim, pixbuf_origin,466 selection_icon = Resources.ICON_SELECTION_ADD;
584 get_selection_border_width (int.max (pixbuf_dim.width, pixbuf_dim.height)));467 }
585 ctx.restore ();
586 }
587
588 // draw border
589 if (border_color != null) {
590 ctx.save ();
591 ctx.set_source_rgba (border_color.red, border_color.green, border_color.blue,
592 border_color.alpha);
593 paint_border (ctx, pixbuf_dim, pixbuf_origin, BORDER_WIDTH);
594 ctx.restore ();
595 }468 }
596469
597 if (display_pixbuf != null) {470 if (display_pixbuf != null) {
471 style_context.render_background (ctx, pixbuf_origin.x, pixbuf_origin.y, display_pixbuf.width, display_pixbuf.height);
472 var radius = style_context.get_property ("border-radius", style_context.get_state ()).get_int ();
598 ctx.save ();473 ctx.save ();
599 paint_image (ctx, display_pixbuf, pixbuf_origin);474 ctx.move_to (pixbuf_origin.x + radius, pixbuf_origin.y);
475 ctx.arc (pixbuf_origin.x + display_pixbuf.width - radius, pixbuf_origin.y + radius, radius, Math.PI * 1.5, Math.PI * 2);
476 ctx.arc (pixbuf_origin.x + display_pixbuf.width - radius, pixbuf_origin.y + display_pixbuf.height - radius, radius, 0, Math.PI * 0.5);
477 ctx.arc (pixbuf_origin.x + radius, pixbuf_origin.y + display_pixbuf.height - radius, radius, Math.PI * 0.5, Math.PI);
478 ctx.arc (pixbuf_origin.x + radius, pixbuf_origin.y + radius, radius, Math.PI, Math.PI * 1.5);
479 ctx.close_path ();
480 Gdk.cairo_set_source_pixbuf (ctx, display_pixbuf, pixbuf_origin.x, pixbuf_origin.y);
481 ctx.clip ();
482 ctx.paint ();
600 ctx.restore ();483 ctx.restore ();
601 }484
602485 style_context.render_frame (ctx, pixbuf_origin.x, pixbuf_origin.y, display_pixbuf.width, display_pixbuf.height);
603 // decide which icon to use for the selection button486 }
604 if (brightened != null && pixbuf != null) {487
605 if (is_selected ())488 // Add the selection helper
606 selection_icon = Resources.ICON_SELECTION_REMOVE;
607 else
608 selection_icon = Resources.ICON_SELECTION_ADD;
609 }
610
611 Gdk.Pixbuf? selection_icon_pix = null;489 Gdk.Pixbuf? selection_icon_pix = null;
490 var scale_factor = style_context.get_scale ();
612 if (selection_icon != null) {491 if (selection_icon != null) {
613 try {492 try {
614 selection_icon_pix = Gtk.IconTheme.get_default ().load_icon_for_scale (selection_icon,493 selection_icon_pix = Gtk.IconTheme.get_default ().load_icon_for_scale (selection_icon, SELECTION_ICON_SIZE, scale_factor, Gtk.IconLookupFlags.GENERIC_FALLBACK);
615 SELECTION_ICON_SIZE, scale_factor, Gtk.IconLookupFlags.GENERIC_FALLBACK);
616 } catch (Error err) {494 } catch (Error err) {
617 warning ("Could not load %s: %s", selection_icon, err.message);495 warning ("Could not load %s: %s", selection_icon, err.message);
618 }496 }
619 }497 }
620498
621 // draw selector icon
622 if (selection_icon_pix != null) {499 if (selection_icon_pix != null) {
623 // calc the top-left point of the selection button
624 Gdk.Rectangle selection_icon_area = get_selection_button_area ();500 Gdk.Rectangle selection_icon_area = get_selection_button_area ();
625 ctx.save ();501 ctx.save ();
626 ctx.scale (1.0 / scale_factor, 1.0 / scale_factor);502 ctx.scale (1.0 / scale_factor, 1.0 / scale_factor);
627 int icon_x = selection_icon_area.x * scale_factor;503 style_context.render_icon (ctx, selection_icon_pix, selection_icon_area.x * scale_factor, selection_icon_area.y * scale_factor);
628 int icon_y = selection_icon_area.y * scale_factor;
629 Gdk.cairo_set_source_pixbuf (ctx, selection_icon_pix, icon_x, icon_y);
630 ctx.paint ();
631 ctx.restore ();504 ctx.restore ();
632 }505 }
633506
634 ctx.set_source_rgba (text_color.red, text_color.green, text_color.blue, text_color.alpha);507 // Add the title and subtitle
635508 style_context.add_class (Gtk.STYLE_CLASS_LABEL);
636 // title and subtitles are LABEL_PADDING below bottom of pixbuf509 // title and subtitles are LABEL_PADDING below bottom of pixbuf
637 int text_y = allocation.y + FRAME_WIDTH + pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;510 int text_y = allocation.y + FRAME_WIDTH + pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;
638 if (title != null && title_visible) {511 if (title != null && title_visible) {
@@ -643,8 +516,9 @@
643 title.allocation.width = pixbuf_dim.width;516 title.allocation.width = pixbuf_dim.width;
644 title.allocation.height = title.get_height ();517 title.allocation.height = title.get_height ();
645518
646 ctx.move_to (title.allocation.x, title.allocation.y);519 var layout = title.get_pango_layout (pixbuf_dim.width);
647 Pango.cairo_show_layout (ctx, title.get_pango_layout (pixbuf_dim.width));520 Pango.cairo_update_layout (ctx, layout);
521 style_context.render_layout (ctx, title.allocation.x, title.allocation.y, layout);
648522
649 text_y += title.get_height () + LABEL_PADDING;523 text_y += title.get_height () + LABEL_PADDING;
650 }524 }
@@ -655,8 +529,9 @@
655 comment.allocation.width = pixbuf_dim.width;529 comment.allocation.width = pixbuf_dim.width;
656 comment.allocation.height = comment.get_height ();530 comment.allocation.height = comment.get_height ();
657531
658 ctx.move_to (comment.allocation.x, comment.allocation.y);532 var layout = comment.get_pango_layout (pixbuf_dim.width);
659 Pango.cairo_show_layout (ctx, comment.get_pango_layout (pixbuf_dim.width));533 Pango.cairo_update_layout (ctx, layout);
534 style_context.render_layout (ctx, comment.allocation.x, comment.allocation.y, layout);
660535
661 text_y += comment.get_height () + LABEL_PADDING;536 text_y += comment.get_height () + LABEL_PADDING;
662 }537 }
@@ -667,64 +542,14 @@
667 subtitle.allocation.width = pixbuf_dim.width;542 subtitle.allocation.width = pixbuf_dim.width;
668 subtitle.allocation.height = subtitle.get_height ();543 subtitle.allocation.height = subtitle.get_height ();
669544
670 ctx.move_to (subtitle.allocation.x, subtitle.allocation.y);545 var layout = subtitle.get_pango_layout (pixbuf_dim.width);
671 Pango.cairo_show_layout (ctx, subtitle.get_pango_layout (pixbuf_dim.width));546 Pango.cairo_update_layout (ctx, layout);
547 style_context.render_layout (ctx, subtitle.allocation.x, subtitle.allocation.y, layout);
672548
673 // increment text_y if more text lines follow549 // increment text_y if more text lines follow
674 }550 }
675551
676 ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,552 style_context.restore ();
677 selected_color.alpha);
678
679 // draw trinkets last
680 Gdk.Pixbuf? trinket = get_bottom_left_trinket (TRINKET_SCALE);
681 if (trinket != null) {
682 int x = pixbuf_origin.x + TRINKET_PADDING + get_horizontal_trinket_offset ();
683 int y = pixbuf_origin.y + pixbuf_dim.height - trinket.get_height () -
684 TRINKET_PADDING;
685 Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
686 ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
687 ctx.fill ();
688 }
689
690 trinket = get_top_left_trinket (TRINKET_SCALE);
691 if (trinket != null) {
692 int x = pixbuf_origin.x + TRINKET_PADDING + get_horizontal_trinket_offset ();
693 int y = pixbuf_origin.y + TRINKET_PADDING;
694 Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
695 ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
696 ctx.fill ();
697 }
698
699 trinket = get_top_right_trinket (TRINKET_SCALE);
700 if (trinket != null) {
701 int x = pixbuf_origin.x + pixbuf_dim.width - trinket.width -
702 get_horizontal_trinket_offset () - TRINKET_PADDING;
703 int y = pixbuf_origin.y + TRINKET_PADDING;
704 Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
705 ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
706 ctx.fill ();
707 }
708
709 trinket = get_bottom_right_trinket (TRINKET_SCALE);
710 if (trinket != null) {
711 int x = pixbuf_origin.x + pixbuf_dim.width - trinket.width -
712 get_horizontal_trinket_offset () - TRINKET_PADDING;
713 int y = pixbuf_origin.y + pixbuf_dim.height - trinket.height -
714 TRINKET_PADDING;
715 Gdk.cairo_set_source_pixbuf (ctx, trinket, x, y);
716 ctx.rectangle (x, y, trinket.get_width (), trinket.get_height ());
717 ctx.fill ();
718 }
719 }
720
721 protected void set_horizontal_trinket_offset (int horizontal_trinket_offset) {
722 assert (horizontal_trinket_offset >= 0);
723 this.horizontal_trinket_offset = horizontal_trinket_offset;
724 }
725
726 protected int get_horizontal_trinket_offset () {
727 return horizontal_trinket_offset;
728 }553 }
729554
730 public void set_grid_coordinates (int col, int row) {555 public void set_grid_coordinates (int col, int row) {
@@ -802,6 +627,64 @@
802}627}
803628
804public class CheckerboardLayout : Gtk.DrawingArea {629public class CheckerboardLayout : Gtk.DrawingArea {
630 private const string CHECKBOARD_CSS = """
631 .checkerboard-layout {
632 background-color: #383e41;
633 background-image:
634 linear-gradient(
635 45deg,
636 alpha (
637 #000,
638 0.1
639 ) 25%,
640 transparent 25%,
641 transparent 75%,
642 alpha (
643 #000,
644 0.1
645 ) 75%,
646 alpha (
647 #000,
648 0.1
649 )
650 ),
651 linear-gradient(
652 45deg,
653 alpha (
654 #000,
655 0.1
656 ) 25%,
657 transparent 25%,
658 transparent 75%,
659 alpha (
660 #000,
661 0.1
662 ) 75%,
663 alpha (
664 #000,
665 0.1
666 )
667 );
668 background-size: 24px 24px;
669 background-position: 0 0, 12px 12px;
670 }
671 .checkboard-layout .item {
672 background-color: #eee;
673 }
674 .checkerboard-layout .label {
675 color: #c0c6c4;
676 text-shadow: 0 1px 2px alpha(#000, 0.5);
677 }
678 .event {
679 border: 3px solid #f4f4f4;
680 border-radius: 6px;
681 }
682 .event:checked {
683 border-color: @selected_bg_color;
684 }
685 """;
686
687
805 public const int TOP_PADDING = 16;688 public const int TOP_PADDING = 16;
806 public const int BOTTOM_PADDING = 16;689 public const int BOTTOM_PADDING = 16;
807 public const int ROW_GUTTER_PADDING = 24;690 public const int ROW_GUTTER_PADDING = 24;
@@ -837,9 +720,6 @@
837 private Gtk.Adjustment hadjustment = null;720 private Gtk.Adjustment hadjustment = null;
838 private Gtk.Adjustment vadjustment = null;721 private Gtk.Adjustment vadjustment = null;
839 private string message = null;722 private string message = null;
840 private Gdk.RGBA selected_color;
841 private Gdk.RGBA unselected_color;
842 private Gdk.RGBA border_color;
843 private Gdk.Rectangle visible_page = Gdk.Rectangle ();723 private Gdk.Rectangle visible_page = Gdk.Rectangle ();
844 private int last_width = 0;724 private int last_width = 0;
845 private int columns = 0;725 private int columns = 0;
@@ -858,7 +738,6 @@
858738
859 public CheckerboardLayout (ViewCollection view) {739 public CheckerboardLayout (ViewCollection view) {
860 this.view = view;740 this.view = view;
861 this.get_style_context ().add_class ("checkerboard-layout");
862741
863 clear_drag_select ();742 clear_drag_select ();
864743
@@ -873,7 +752,15 @@
873 view.items_selected.connect (on_items_selection_changed);752 view.items_selected.connect (on_items_selection_changed);
874 view.items_unselected.connect (on_items_selection_changed);753 view.items_unselected.connect (on_items_selection_changed);
875754
876 Config.Facade.get_instance ().colors_changed.connect (on_colors_changed);755 weak Gtk.StyleContext style_context = get_style_context ();
756 style_context.add_class ("checkerboard-layout");
757 var css_provicer = new Gtk.CssProvider ();
758 try {
759 css_provicer.load_from_data (CHECKBOARD_CSS);
760 style_context.add_provider (css_provicer, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
761 } catch (Error e) {
762 critical (e.message);
763 }
877764
878 // CheckerboardItems offer tooltips765 // CheckerboardItems offer tooltips
879 has_tooltip = true;766 has_tooltip = true;
@@ -902,8 +789,6 @@
902789
903 if (parent != null)790 if (parent != null)
904 parent.size_allocate.disconnect (on_viewport_resized);791 parent.size_allocate.disconnect (on_viewport_resized);
905
906 Config.Facade.get_instance ().colors_changed.disconnect (on_colors_changed);
907 }792 }
908793
909 public void set_adjustments (Gtk.Adjustment hadjustment, Gtk.Adjustment vadjustment) {794 public void set_adjustments (Gtk.Adjustment hadjustment, Gtk.Adjustment vadjustment) {
@@ -1796,19 +1681,6 @@
1796 }1681 }
1797 }1682 }
17981683
1799 public override void map () {
1800 base.map ();
1801
1802 set_colors ();
1803 }
1804
1805 private void set_colors (bool in_focus = true) {
1806 // set up selected/unselected colors
1807 selected_color = Config.Facade.get_instance ().get_selected_color (in_focus);
1808 unselected_color = Config.Facade.get_instance ().get_unselected_color ();
1809 border_color = Config.Facade.get_instance ().get_border_color ();
1810 }
1811
1812 public override void size_allocate (Gtk.Allocation allocation) {1684 public override void size_allocate (Gtk.Allocation allocation) {
1813 base.size_allocate (allocation);1685 base.size_allocate (allocation);
18141686
@@ -1833,10 +1705,14 @@
1833 expose_items ("draw");1705 expose_items ("draw");
18341706
1835 // have all items in the exposed area paint themselves1707 // have all items in the exposed area paint themselves
1708 weak Gtk.StyleContext style_context = get_style_context ();
1709 style_context.save ();
1710 style_context.add_class ("card");
1836 foreach (CheckerboardItem item in intersection (visible_page)) {1711 foreach (CheckerboardItem item in intersection (visible_page)) {
1837 item.paint (ctx, item.is_selected () ? selected_color : unselected_color,1712 item.paint (ctx, style_context);
1838 unselected_color, border_color, scale_factor);
1839 }1713 }
1714
1715 style_context.restore ();
1840 } else {1716 } else {
1841 // draw the message in the center of the window1717 // draw the message in the center of the window
1842 Pango.Layout pango_layout = create_pango_layout (message);1718 Pango.Layout pango_layout = create_pango_layout (message);
@@ -1852,7 +1728,6 @@
1852 int y = allocation.height - text_height;1728 int y = allocation.height - text_height;
1853 y = (y > 0) ? y / 2 : 0;1729 y = (y > 0) ? y / 2 : 0;
18541730
1855 ctx.set_source_rgb (unselected_color.red, unselected_color.green, unselected_color.blue);
1856 ctx.move_to (x, y);1731 ctx.move_to (x, y);
1857 Pango.cairo_show_layout (ctx, pango_layout);1732 Pango.cairo_show_layout (ctx, pango_layout);
1858 }1733 }
@@ -1878,25 +1753,6 @@
1878 Gdk.Rectangle visible_page = get_adjustment_page (hadjustment, vadjustment);1753 Gdk.Rectangle visible_page = get_adjustment_page (hadjustment, vadjustment);
1879 Gdk.Rectangle visible_band = Gdk.Rectangle ();1754 Gdk.Rectangle visible_band = Gdk.Rectangle ();
1880 visible_page.intersect (selection_band, out visible_band);1755 visible_page.intersect (selection_band, out visible_band);
1881
1882 // pixelate selection rectangle interior
1883 if (visible_band.width > 1 && visible_band.height > 1) {
1884 ctx.set_source_rgba (selected_color.red, selected_color.green, selected_color.blue,
1885 SELECTION_ALPHA);
1886 ctx.rectangle (visible_band.x, visible_band.y, visible_band.width,
1887 visible_band.height);
1888 ctx.fill ();
1889 }
1890
1891 // border
1892 // See this for an explanation of the adjustments to the band's dimensions
1893 // http://cairographics.org/FAQ/#sharp_lines
1894 ctx.set_line_width (1.0);
1895 ctx.set_line_cap (Cairo.LineCap.SQUARE);
1896 ctx.set_source_rgb (selected_color.red, selected_color.green, selected_color.blue);
1897 ctx.rectangle ((double) selection_band.x + 0.5, (double) selection_band.y + 0.5,
1898 (double) selection_band.width - 1.0, (double) selection_band.height - 1.0);
1899 ctx.stroke ();
1900 }1756 }
19011757
1902 public override bool query_tooltip (int x, int y, bool keyboard_mode, Gtk.Tooltip tooltip) {1758 public override bool query_tooltip (int x, int y, bool keyboard_mode, Gtk.Tooltip tooltip) {
@@ -1905,19 +1761,13 @@
1905 return (item != null) ? item.query_tooltip (x, y, tooltip) : false;1761 return (item != null) ? item.query_tooltip (x, y, tooltip) : false;
1906 }1762 }
19071763
1908 private void on_colors_changed () {
1909 set_colors ();
1910 }
1911
1912 public override bool focus_in_event (Gdk.EventFocus event) {1764 public override bool focus_in_event (Gdk.EventFocus event) {
1913 set_colors (true);
1914 items_dirty ("focus_in_event", view.get_selected ());1765 items_dirty ("focus_in_event", view.get_selected ());
19151766
1916 return base.focus_in_event (event);1767 return base.focus_in_event (event);
1917 }1768 }
19181769
1919 public override bool focus_out_event (Gdk.EventFocus event) {1770 public override bool focus_out_event (Gdk.EventFocus event) {
1920 set_colors (false);
1921 items_dirty ("focus_out_event", view.get_selected ());1771 items_dirty ("focus_out_event", view.get_selected ());
19221772
1923 return base.focus_out_event (event);1773 return base.focus_out_event (event);
19241774
=== modified file 'src/MediaPage.vala'
--- src/MediaPage.vala 2017-01-26 15:35:50 +0000
+++ src/MediaPage.vala 2017-01-26 22:17:04 +0000
@@ -24,10 +24,6 @@
24 string? comment, bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {24 string? comment, bool marked_up = false, Pango.Alignment alignment = Pango.Alignment.LEFT) {
25 base (source, initial_pixbuf_dim, title, comment, marked_up, alignment);25 base (source, initial_pixbuf_dim, title, comment, marked_up, alignment);
26 }26 }
27
28 protected override void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
29 base.paint_image (ctx, pixbuf, origin);
30 }
31}27}
3228
33public abstract class MediaPage : CheckerboardPage {29public abstract class MediaPage : CheckerboardPage {
3430
=== modified file 'src/Thumbnail.vala'
--- src/Thumbnail.vala 2017-01-12 18:13:48 +0000
+++ src/Thumbnail.vala 2017-01-26 22:17:04 +0000
@@ -24,6 +24,8 @@
24 // SIZE (int, scale)24 // SIZE (int, scale)
25 public const string PROP_SIZE = "thumbnail-size";25 public const string PROP_SIZE = "thumbnail-size";
2626
27 public const int FLAG_OFFSET = 1;
28
27 public static int MIN_SCALE {29 public static int MIN_SCALE {
28 get {30 get {
29 return 92;31 return 92;
@@ -371,10 +373,17 @@
371 base.unexposed ();373 base.unexposed ();
372 }374 }
373375
374 protected override Gdk.Pixbuf? get_top_right_trinket (int scale) {376 public override void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
375 Flaggable? flaggable = media as Flaggable;377 base.paint (ctx, style_context);
376378
377 return (flaggable != null && flaggable.is_flagged ())379 if (media != null && media is Flaggable) {
378 ? Resources.get_flag_trinket () : null;380 if (((Flaggable) media).is_flagged ()) {
381 style_context.save ();
382 style_context.add_class (Granite.StyleClass.OVERLAY_BAR);
383 var flag_icon = Resources.get_flag_trinket ();
384 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);
385 style_context.restore ();
386 }
387 }
379 }388 }
380}389}
381390
=== modified file 'src/config/Config.vala'
--- src/config/Config.vala 2017-01-12 18:13:48 +0000
+++ src/config/Config.vala 2017-01-26 22:17:04 +0000
@@ -52,20 +52,10 @@
52 private const string DARK_UNFOCUSED_SELECTED_COLOR = "#888";52 private const string DARK_UNFOCUSED_SELECTED_COLOR = "#888";
53 private const string LIGHT_UNFOCUSED_SELECTED_COLOR = "#888";53 private const string LIGHT_UNFOCUSED_SELECTED_COLOR = "#888";
5454
55 private string bg_color = null;
56 private string selected_color = null;
57 private string unselected_color = null;
58 private string unfocused_selected_color = null;
59 private string border_color = null;
60
61 private static Facade instance = null;55 private static Facade instance = null;
6256
63 public signal void colors_changed ();
64
65 private Facade () {57 private Facade () {
66 base (new GSettingsConfigurationEngine ());58 base (new GSettingsConfigurationEngine ());
67
68 bg_color_name_changed.connect (on_color_name_changed);
69 }59 }
7060
71 public static Facade get_instance () {61 public static Facade get_instance () {
@@ -74,84 +64,6 @@
7464
75 return instance;65 return instance;
76 }66 }
77
78 private void on_color_name_changed () {
79 colors_changed ();
80 }
81
82 private void set_text_colors (Gdk.RGBA bg_color) {
83 // since bg color is greyscale, we only need to compare the red value to the threshold,
84 // which determines whether the background is dark enough to need light text and selection
85 // colors or vice versa
86 if (bg_color.red > BLACK_THRESHOLD) {
87 selected_color = DARK_SELECTED_COLOR;
88 unselected_color = DARK_UNSELECTED_COLOR;
89 unfocused_selected_color = DARK_UNFOCUSED_SELECTED_COLOR;
90 border_color = DARK_BORDER_COLOR;
91 } else {
92 selected_color = LIGHT_SELECTED_COLOR;
93 unselected_color = LIGHT_UNSELECTED_COLOR;
94 unfocused_selected_color = LIGHT_UNFOCUSED_SELECTED_COLOR;
95 border_color = LIGHT_BORDER_COLOR;
96 }
97 }
98
99 private void get_colors () {
100 bg_color = base.get_bg_color_name ();
101
102 if (!is_color_parsable (bg_color))
103 bg_color = DEFAULT_BG_COLOR;
104
105 set_text_colors (parse_color (bg_color));
106 }
107
108 public Gdk.RGBA get_bg_color () {
109 if (is_string_empty (bg_color))
110 get_colors ();
111
112 return parse_color (bg_color);
113 }
114
115 public Gdk.RGBA get_selected_color (bool in_focus = true) {
116 if (in_focus) {
117 if (is_string_empty (selected_color))
118 get_colors ();
119
120 return parse_color (selected_color);
121 } else {
122 if (is_string_empty (unfocused_selected_color))
123 get_colors ();
124
125 return parse_color (unfocused_selected_color);
126 }
127 }
128
129 public Gdk.RGBA get_unselected_color () {
130 if (is_string_empty (unselected_color))
131 get_colors ();
132
133 return parse_color (unselected_color);
134 }
135
136 public Gdk.RGBA get_border_color () {
137 if (is_string_empty (border_color))
138 get_colors ();
139
140 return parse_color (border_color);
141 }
142
143 public void set_bg_color (Gdk.RGBA color) {
144 uint8 col_tmp = (uint8) (color.red * 255.0);
145
146 bg_color = "#%02X%02X%02X".printf (col_tmp, col_tmp, col_tmp);
147 set_bg_color_name (bg_color);
148
149 set_text_colors (color);
150 }
151
152 public void commit_bg_color () {
153 base.set_bg_color_name (bg_color);
154 }
155}67}
15668
157// preconfigure may be deleted if not used.69// preconfigure may be deleted if not used.
15870
=== modified file 'src/config/ConfigurationInterfaces.vala'
--- src/config/ConfigurationInterfaces.vala 2017-01-12 18:13:48 +0000
+++ src/config/ConfigurationInterfaces.vala 2017-01-26 22:17:04 +0000
@@ -34,7 +34,6 @@
3434
35public enum ConfigurableProperty {35public enum ConfigurableProperty {
36 AUTO_IMPORT_FROM_LIBRARY = 0,36 AUTO_IMPORT_FROM_LIBRARY = 0,
37 BG_COLOR_NAME,
38 COMMIT_METADATA_TO_MASTERS,37 COMMIT_METADATA_TO_MASTERS,
39 DESKTOP_BACKGROUND_FILE,38 DESKTOP_BACKGROUND_FILE,
40 DESKTOP_BACKGROUND_MODE,39 DESKTOP_BACKGROUND_MODE,
@@ -103,9 +102,6 @@
103 case AUTO_IMPORT_FROM_LIBRARY:102 case AUTO_IMPORT_FROM_LIBRARY:
104 return "AUTO_IMPORT_FROM_LIBRARY";103 return "AUTO_IMPORT_FROM_LIBRARY";
105104
106 case BG_COLOR_NAME:
107 return "BG_COLOR_NAME";
108
109 case COMMIT_METADATA_TO_MASTERS:105 case COMMIT_METADATA_TO_MASTERS:
110 return "COMMIT_METADATA_TO_MASTERS";106 return "COMMIT_METADATA_TO_MASTERS";
111107
@@ -321,7 +317,6 @@
321 private ConfigurationEngine engine;317 private ConfigurationEngine engine;
322318
323 public signal void auto_import_from_library_changed ();319 public signal void auto_import_from_library_changed ();
324 public signal void bg_color_name_changed ();
325 public signal void commit_metadata_to_masters_changed ();320 public signal void commit_metadata_to_masters_changed ();
326 public signal void events_sort_ascending_changed ();321 public signal void events_sort_ascending_changed ();
327 public signal void external_app_changed ();322 public signal void external_app_changed ();
@@ -341,10 +336,6 @@
341 auto_import_from_library_changed ();336 auto_import_from_library_changed ();
342 break;337 break;
343338
344 case ConfigurableProperty.BG_COLOR_NAME:
345 bg_color_name_changed ();
346 break;
347
348 case ConfigurableProperty.COMMIT_METADATA_TO_MASTERS:339 case ConfigurableProperty.COMMIT_METADATA_TO_MASTERS:
349 commit_metadata_to_masters_changed ();340 commit_metadata_to_masters_changed ();
350 break;341 break;
@@ -405,28 +396,6 @@
405 }396 }
406397
407 //398 //
408 // bg color name
409 //
410 public virtual string get_bg_color_name () {
411 try {
412 return get_engine ().get_string_property (ConfigurableProperty.BG_COLOR_NAME);
413 } catch (ConfigurationError err) {
414 on_configuration_error (err);
415
416 return "";
417 }
418 }
419
420 public virtual void set_bg_color_name (string color_name) {
421 try {
422 get_engine ().set_string_property (ConfigurableProperty.BG_COLOR_NAME, color_name);
423 } catch (ConfigurationError err) {
424 on_configuration_error (err);
425 return;
426 }
427 }
428
429 //
430 // commit metadata to masters399 // commit metadata to masters
431 //400 //
432 public virtual bool get_commit_metadata_to_masters () {401 public virtual bool get_commit_metadata_to_masters () {
433402
=== modified file 'src/config/GSettingsEngine.vala'
--- src/config/GSettingsEngine.vala 2017-01-12 18:13:48 +0000
+++ src/config/GSettingsEngine.vala 2017-01-26 22:17:04 +0000
@@ -47,7 +47,6 @@
47 schema_names = new string[ConfigurableProperty.NUM_PROPERTIES];47 schema_names = new string[ConfigurableProperty.NUM_PROPERTIES];
4848
49 schema_names[ConfigurableProperty.AUTO_IMPORT_FROM_LIBRARY] = FILES_PREFS_SCHEMA_NAME;49 schema_names[ConfigurableProperty.AUTO_IMPORT_FROM_LIBRARY] = FILES_PREFS_SCHEMA_NAME;
50 schema_names[ConfigurableProperty.BG_COLOR_NAME] = UI_PREFS_SCHEMA_NAME;
51 schema_names[ConfigurableProperty.COMMIT_METADATA_TO_MASTERS] = FILES_PREFS_SCHEMA_NAME;50 schema_names[ConfigurableProperty.COMMIT_METADATA_TO_MASTERS] = FILES_PREFS_SCHEMA_NAME;
52 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_FILE] = SYSTEM_DESKTOP_SCHEMA_NAME;51 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_FILE] = SYSTEM_DESKTOP_SCHEMA_NAME;
53 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_MODE] = SYSTEM_DESKTOP_SCHEMA_NAME;52 schema_names[ConfigurableProperty.DESKTOP_BACKGROUND_MODE] = SYSTEM_DESKTOP_SCHEMA_NAME;
5453
=== modified file 'src/events/EventDirectoryItem.vala'
--- src/events/EventDirectoryItem.vala 2017-01-12 18:13:48 +0000
+++ src/events/EventDirectoryItem.vala 2017-01-26 22:17:04 +0000
@@ -161,33 +161,12 @@
161 base.thumbnail_altered ();161 base.thumbnail_altered ();
162 }162 }
163163
164 protected override void paint_shadow (Cairo.Context ctx, Dimensions dimensions, Gdk.Point origin,164 public override void paint (Cairo.Context ctx, Gtk.StyleContext style_context) {
165 int radius, float initial_alpha) {165 style_context.save ();
166 Dimensions altered = Dimensions (dimensions.width - 25, dimensions.height - 25);166 style_context.add_class ("event");
167 base.paint_shadow (ctx, altered, origin, 36, initial_alpha);167 base.paint (ctx, style_context);
168 }168 style_context.restore ();
169169 }
170 protected override void paint_border (Cairo.Context ctx, Dimensions object_dimensions,
171 Gdk.Point object_origin, int border_width) {
172 Dimensions dimensions = get_border_dimensions (object_dimensions, border_width);
173 Gdk.Point origin = get_border_origin (object_origin, border_width);
174
175 draw_rounded_corners_filled (ctx, dimensions, origin, 6.0);
176 }
177
178 protected override void paint_image (Cairo.Context ctx, Gdk.Pixbuf pixbuf,
179 Gdk.Point origin) {
180 Dimensions dimensions = Dimensions.for_pixbuf (pixbuf);
181
182 if (pixbuf.get_has_alpha ())
183 draw_rounded_corners_filled (ctx, dimensions, origin, 6.0);
184
185 // use rounded corners on events
186 context_rounded_corners (ctx, dimensions, origin, 6.0);
187 Gdk.cairo_set_source_pixbuf (ctx, pixbuf, origin.x, origin.y);
188 ctx.paint ();
189 }
190
191 private void update_comment (bool init = false) {170 private void update_comment (bool init = false) {
192 string comment = event.get_comment ();171 string comment = event.get_comment ();
193 if (is_string_empty (comment))172 if (is_string_empty (comment))
194173
=== modified file 'src/util/image.vala'
--- src/util/image.vala 2017-01-12 18:13:48 +0000
+++ src/util/image.vala 2017-01-26 22:17:04 +0000
@@ -17,11 +17,6 @@
17* Boston, MA 02110-1301 USA17* Boston, MA 02110-1301 USA
18*/18*/
1919
20bool is_color_parsable (string spec) {
21 Gdk.Color color;
22 return Gdk.Color.parse (spec, out color);
23}
24
25Gdk.RGBA parse_color (string spec) {20Gdk.RGBA parse_color (string spec) {
26 return fetch_color (spec);21 return fetch_color (spec);
27}22}
@@ -65,37 +60,6 @@
65 return pixbuf.scale_simple (resized.width, resized.height, interp);60 return pixbuf.scale_simple (resized.width, resized.height, interp);
66}61}
6762
68private const double DEGREE = Math.PI / 180.0;
69
70void draw_rounded_corners_filled (Cairo.Context ctx, Dimensions dim, Gdk.Point origin,
71 double radius_proportion) {
72 context_rounded_corners (ctx, dim, origin, radius_proportion);
73 ctx.paint ();
74}
75
76void context_rounded_corners (Cairo.Context cx, Dimensions dim, Gdk.Point origin,
77 double radius_proportion) {
78 // establish a reasonable range
79 radius_proportion = radius_proportion.clamp (2.0, 100.0);
80
81 double left = origin.x;
82 double top = origin.y;
83 double right = origin.x + dim.width;
84 double bottom = origin.y + dim.height;
85
86 // the radius of the corners is proportional to the distance of the minor axis
87 double radius = ((double) dim.minor_axis ()) / radius_proportion;
88
89 // create context and clipping region, starting from the top right arc and working around
90 // clockwise
91 cx.move_to (left, top);
92 cx.arc (right - radius, top + radius, radius, -90 * DEGREE, 0 * DEGREE);
93 cx.arc (right - radius, bottom - radius, radius, 0 * DEGREE, 90 * DEGREE);
94 cx.arc (left + radius, bottom - radius, radius, 90 * DEGREE, 180 * DEGREE);
95 cx.arc (left + radius, top + radius, radius, 180 * DEGREE, 270 * DEGREE);
96 cx.clip ();
97}
98
99inline uchar shift_color_byte (int b, int shift) {63inline uchar shift_color_byte (int b, int shift) {
100 return (uchar) (b + shift).clamp (0, 255);64 return (uchar) (b + shift).clamp (0, 255);
101}65}

Subscribers

People subscribed via source and target branches

to all changes: