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