summaryrefslogtreecommitdiff
path: root/src/CheckerboardLayout.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-09-30 14:11:00 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-09-30 14:11:00 +0200
commit0ac947a9070322180e94d1b71e30836cce4d74bc (patch)
tree4a6f3923c250377536a5004ed203768111a1d27f /src/CheckerboardLayout.vala
parenteca5837e235a356c8db9416bbbc13577db3e6f76 (diff)
parent01b2b5ec9177046f64c6d0a6e73a6ac8a42089a1 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/CheckerboardLayout.vala')
-rw-r--r--src/CheckerboardLayout.vala120
1 files changed, 63 insertions, 57 deletions
diff --git a/src/CheckerboardLayout.vala b/src/CheckerboardLayout.vala
index 0c52748..c2d1a52 100644
--- a/src/CheckerboardLayout.vala
+++ b/src/CheckerboardLayout.vala
@@ -345,6 +345,18 @@ public abstract class CheckerboardItem : ThumbnailView {
return is_cursor;
}
+ public virtual void handle_mouse_motion(int x, int y, int height, int width) {
+
+ }
+
+ public virtual void handle_mouse_leave() {
+ unbrighten();
+ }
+
+ public virtual void handle_mouse_enter() {
+ brighten();
+ }
+
protected override void notify_membership_changed(DataCollection? collection) {
bool title_visible = (bool) get_collection_property(PROP_SHOW_TITLES, true);
bool comment_visible = (bool) get_collection_property(PROP_SHOW_COMMENTS, true);
@@ -572,7 +584,7 @@ public abstract class CheckerboardItem : ThumbnailView {
}
private int get_selection_border_width(int scale) {
- return ((scale <= ((Thumbnail.MIN_SCALE + Thumbnail.MAX_SCALE) / 3)) ? 2 : 3)
+ return ((scale <= ((Thumbnail.MIN_SCALE + Thumbnail.MAX_SCALE) / 3)) ? 5 : 4)
+ BORDER_WIDTH;
}
@@ -592,8 +604,8 @@ public abstract class CheckerboardItem : ThumbnailView {
return null;
}
- public void paint(Cairo.Context ctx, Gdk.RGBA bg_color, Gdk.RGBA selected_color,
- Gdk.RGBA text_color, Gdk.RGBA? border_color) {
+ public void paint(Gtk.StyleContext style_context, Cairo.Context ctx, Gdk.RGBA bg_color, Gdk.RGBA selected_color,
+ Gdk.RGBA? border_color, Gdk.RGBA? focus_color) {
ctx.save();
ctx.translate(allocation.x + FRAME_WIDTH,
allocation.y + FRAME_WIDTH);
@@ -619,8 +631,8 @@ public abstract class CheckerboardItem : ThumbnailView {
// draw a border for the cursor with the selection width and normal border color
if (is_cursor) {
ctx.save();
- ctx.set_source_rgba(border_color.red, border_color.green, border_color.blue,
- border_color.alpha);
+ ctx.set_source_rgba(focus_color.red, focus_color.green, focus_color.blue,
+ focus_color.alpha);
paint_border(ctx, pixbuf_dim, pixbuf_origin,
get_selection_border_width(int.max(pixbuf_dim.width, pixbuf_dim.height)));
ctx.restore();
@@ -635,15 +647,6 @@ public abstract class CheckerboardItem : ThumbnailView {
ctx.restore();
}
- // draw border
- if (border_color != null) {
- ctx.save();
- ctx.set_source_rgba(border_color.red, border_color.green, border_color.blue,
- border_color.alpha);
- paint_border(ctx, pixbuf_dim, pixbuf_origin, BORDER_WIDTH);
- ctx.restore();
- }
-
if (display_pixbuf != null) {
ctx.save();
ctx.set_source_rgba(bg_color.red, bg_color.green, bg_color.blue, bg_color.alpha);
@@ -651,45 +654,41 @@ public abstract class CheckerboardItem : ThumbnailView {
ctx.restore();
}
- ctx.set_source_rgba(text_color.red, text_color.green, text_color.blue, text_color.alpha);
-
// title and subtitles are LABEL_PADDING below bottom of pixbuf
int text_y = pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;
if (title != null && title_visible) {
- // get the layout sized so its with is no more than the pixbuf's
+ // get the layout sized so its width is no more than the pixbuf's
// resize the text width to be no more than the pixbuf's
title.allocation.x = 0;
title.allocation.y = text_y;
title.allocation.width = pixbuf_dim.width;
title.allocation.height = title.get_height();
-
- ctx.move_to(title.allocation.x, title.allocation.y);
- Pango.cairo_show_layout(ctx, title.get_pango_layout(pixbuf_dim.width));
-
+ style_context.render_layout(ctx, title.allocation.x, title.allocation.y,
+ title.get_pango_layout(pixbuf_dim.width));
+
text_y += title.get_height() + LABEL_PADDING;
}
-
+
if (comment != null && comment_visible) {
comment.allocation.x = 0;
comment.allocation.y = text_y;
comment.allocation.width = pixbuf_dim.width;
comment.allocation.height = comment.get_height();
-
- ctx.move_to(comment.allocation.x, comment.allocation.y);
- Pango.cairo_show_layout(ctx, comment.get_pango_layout(pixbuf_dim.width));
-
+ style_context.render_layout(ctx, comment.allocation.x, comment.allocation.y,
+ comment.get_pango_layout(pixbuf_dim.width));
+
text_y += comment.get_height() + LABEL_PADDING;
}
-
+
if (subtitle != null && subtitle_visible) {
subtitle.allocation.x = 0;
subtitle.allocation.y = text_y;
subtitle.allocation.width = pixbuf_dim.width;
subtitle.allocation.height = subtitle.get_height();
-
- ctx.move_to(subtitle.allocation.x, subtitle.allocation.y);
- Pango.cairo_show_layout(ctx, subtitle.get_pango_layout(pixbuf_dim.width));
-
+
+ style_context.render_layout(ctx, subtitle.allocation.x, subtitle.allocation.y,
+ subtitle.get_pango_layout(pixbuf_dim.width));
+
// increment text_y if more text lines follow
}
@@ -775,6 +774,7 @@ public abstract class CheckerboardItem : ThumbnailView {
notify_view_altered();
}
+
public void unbrighten() {
// "should", "can", "didn't already"
if (brightened == null || pixbuf == null)
@@ -860,6 +860,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
private string message = null;
private Gdk.RGBA selected_color;
private Gdk.RGBA unselected_color;
+ private Gdk.RGBA focus_color;
private Gdk.RGBA border_color;
private Gdk.RGBA bg_color;
private Gdk.Rectangle visible_page = Gdk.Rectangle();
@@ -880,6 +881,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
private bool reflow_needed = false;
public CheckerboardLayout(ViewCollection view) {
+ this.get_style_context().add_class("content-view");
this.view = view;
clear_drag_select();
@@ -894,8 +896,6 @@ public class CheckerboardLayout : Gtk.DrawingArea {
view.geometries_altered.connect(on_geometries_altered);
view.items_selected.connect(on_items_selection_changed);
view.items_unselected.connect(on_items_selection_changed);
-
- override_background_color(Gtk.StateFlags.NORMAL, Config.Facade.get_instance().get_bg_color());
Config.Facade.get_instance().colors_changed.connect(on_colors_changed);
@@ -1289,6 +1289,11 @@ public class CheckerboardLayout : Gtk.DrawingArea {
}
public bool handle_mouse_motion(CheckerboardItem item, int x, int y, Gdk.ModifierType mask) {
+ int dx = x - item.allocation.x;
+ int dy = y - item.allocation.y;
+
+ item.handle_mouse_motion(dx, dy, item.allocation.height, item.allocation.width);
+
if (!item.has_tags || is_drag_select_active())
return false;
int tag_index = internal_handle_tag_mouse_event(item, x, y);
@@ -1916,10 +1921,22 @@ public class CheckerboardLayout : Gtk.DrawingArea {
private void set_colors(bool in_focus = true) {
// set up selected/unselected colors
- selected_color = Config.Facade.get_instance().get_selected_color(in_focus);
- unselected_color = Config.Facade.get_instance().get_unselected_color();
- border_color = Config.Facade.get_instance().get_border_color();
- bg_color = get_style_context().get_background_color(Gtk.StateFlags.NORMAL);
+ var ctx = get_style_context();
+ ctx.save();
+ ctx.add_class("view");
+ var val = ctx.get_property("border-color", Gtk.StateFlags.NORMAL);
+ focus_color = *(Gdk.RGBA*)val.get_boxed();
+
+ val = ctx.get_property("border-color", Gtk.StateFlags.FOCUSED);
+ border_color = *(Gdk.RGBA*)val.get_boxed();
+
+ // Checked in GtkIconView - The selection is drawn using render_background
+ val = ctx.get_property("background-color", Gtk.StateFlags.FOCUSED | Gtk.StateFlags.SELECTED);
+ selected_color = *(Gdk.RGBA*)val.get_boxed();
+
+ val = ctx.get_property("color", Gtk.StateFlags.NORMAL);
+ unselected_color = *(Gdk.RGBA*)val.get_boxed();
+ ctx.restore();
}
public override void size_allocate(Gtk.Allocation allocation) {
@@ -1951,8 +1968,8 @@ public class CheckerboardLayout : Gtk.DrawingArea {
// have all items in the exposed area paint themselves
foreach (CheckerboardItem item in intersection(visible_page)) {
- item.paint(ctx, bg_color, item.is_selected() ? selected_color : unselected_color,
- unselected_color, border_color);
+ item.paint(get_style_context(), ctx, bg_color, item.is_selected() ? selected_color : unselected_color,
+ border_color, focus_color);
}
} else {
// draw the message in the center of the window
@@ -1968,9 +1985,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
int y = allocation.height - text_height;
y = (y > 0) ? y / 2 : 0;
- ctx.set_source_rgb(unselected_color.red, unselected_color.green, unselected_color.blue);
- ctx.move_to(x, y);
- Pango.cairo_show_layout(ctx, pango_layout);
+ get_style_context().render_layout(ctx, x, y, pango_layout);
}
bool result = (base.draw != null) ? base.draw(ctx) : true;
@@ -1995,24 +2010,16 @@ public class CheckerboardLayout : Gtk.DrawingArea {
Gdk.Rectangle visible_band = Gdk.Rectangle();
visible_page.intersect(selection_band, out visible_band);
+ get_style_context().save();
+ get_style_context().add_class(Gtk.STYLE_CLASS_RUBBERBAND);
// pixelate selection rectangle interior
if (visible_band.width > 1 && visible_band.height > 1) {
- ctx.set_source_rgba(selected_color.red, selected_color.green, selected_color.blue,
- SELECTION_ALPHA);
- ctx.rectangle(visible_band.x, visible_band.y, visible_band.width,
- visible_band.height);
- ctx.fill();
+ get_style_context().render_background(ctx, visible_band.x, visible_band.y, visible_band.width, visible_band.height);
}
// border
- // See this for an explanation of the adjustments to the band's dimensions
- // http://cairographics.org/FAQ/#sharp_lines
- ctx.set_line_width(1.0);
- ctx.set_line_cap(Cairo.LineCap.SQUARE);
- ctx.set_source_rgb(selected_color.red, selected_color.green, selected_color.blue);
- ctx.rectangle((double) selection_band.x + 0.5, (double) selection_band.y + 0.5,
- (double) selection_band.width - 1.0, (double) selection_band.height - 1.0);
- ctx.stroke();
+ get_style_context().render_frame(ctx, visible_band.x, visible_band.y, visible_band.width, visible_band.height);
+ get_style_context().restore();
}
public override bool query_tooltip(int x, int y, bool keyboard_mode, Gtk.Tooltip tooltip) {
@@ -2023,8 +2030,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
private void on_colors_changed() {
invalidate_transparent_background();
- override_background_color(Gtk.StateFlags.NORMAL, Config.Facade.get_instance().get_bg_color());
- set_colors();
+ queue_draw();
}
public override bool focus_in_event(Gdk.EventFocus event) {