Commit 33b02ce5 authored by Jim Nelson's avatar Jim Nelson

#2025: Images with transparencies now painted with proper background color. Courtesy Philip Beam.

parent 3f9a73f6
......@@ -384,8 +384,12 @@ public abstract class CheckerboardItem : ThumbnailView {
}
}
protected virtual void paint_image(Gdk.GC gc, Gdk.Drawable drawable, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
drawable.draw_pixbuf(gc, display_pixbuf, 0, 0, origin.x, origin.y, -1, -1,
protected virtual void paint_image(Gdk.GC bg_gc, Gdk.Drawable drawable, Gdk.Pixbuf pixbuf, Gdk.Point origin) {
if (pixbuf.get_has_alpha()) {
drawable.draw_rectangle(bg_gc, true, origin.x, origin.y,
pixbuf.get_width(), pixbuf.get_height());
}
drawable.draw_pixbuf(bg_gc, display_pixbuf, 0, 0, origin.x, origin.y, -1, -1,
Gdk.RgbDither.NORMAL, 0, 0);
}
......@@ -394,7 +398,7 @@ public abstract class CheckerboardItem : ThumbnailView {
+ BORDER_WIDTH;
}
public void paint(Gdk.Drawable drawable, Gdk.GC gc, Gdk.GC text_gc, Gdk.GC? border_gc) {
public void paint(Gdk.Drawable drawable, Gdk.GC bg_gc, Gdk.GC select_gc, Gdk.GC text_gc, Gdk.GC? border_gc) {
// calc the top-left point of the pixbuf
Gdk.Point pixbuf_origin = Gdk.Point();
pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;
......@@ -405,7 +409,7 @@ public abstract class CheckerboardItem : ThumbnailView {
// border thickness depends on the size of the thumbnail
int scale = int.max(pixbuf_dim.width, pixbuf_dim.height);
paint_border(gc, drawable, pixbuf_dim, pixbuf_origin,
paint_border(select_gc, drawable, pixbuf_dim, pixbuf_origin,
get_selection_border_width(scale));
}
......@@ -414,7 +418,7 @@ public abstract class CheckerboardItem : ThumbnailView {
paint_border(border_gc, drawable, pixbuf_dim, pixbuf_origin, BORDER_WIDTH);
if (display_pixbuf != null)
paint_image(gc, drawable, display_pixbuf, pixbuf_origin);
paint_image(bg_gc, drawable, display_pixbuf, pixbuf_origin);
// get trinkets to determine the max width (pixbuf vs. trinkets)
int trinkets_width = 0;
......@@ -456,7 +460,7 @@ public abstract class CheckerboardItem : ThumbnailView {
foreach (Gdk.Pixbuf trinket in trinkets) {
current_trinkets_width = current_trinkets_width + trinket.get_width() +
TRINKET_PADDING;
drawable.draw_pixbuf(gc, trinket, 0, 0,
drawable.draw_pixbuf(select_gc, trinket, 0, 0,
pixbuf_origin.x + TRINKET_PADDING,
pixbuf_origin.y + pixbuf_dim.height - trinket.get_height() - TRINKET_PADDING,
trinket.get_width(), trinket.get_height(), Gdk.RgbDither.NORMAL, 0, 0);
......@@ -566,6 +570,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
private Gdk.GC unselected_gc = null;
private Gdk.GC border_gc = null;
private Gdk.GC selection_band_gc = null;
private Gdk.GC background_gc = null;
private Gdk.Rectangle visible_page = Gdk.Rectangle();
private int last_width = 0;
private int columns = 0;
......@@ -1480,6 +1485,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
unselected_gc = new Gdk.GC(window);
border_gc = new Gdk.GC(window);
selection_band_gc = new Gdk.GC(window);
background_gc = new Gdk.GC(window);
set_colors();
}
......@@ -1525,6 +1531,8 @@ public class CheckerboardLayout : Gtk.DrawingArea {
gc_values.foreground = selected_color;
selection_band_gc.set_values(gc_values, mask);
background_gc.set_foreground(this.get_style().bg[Gtk.StateType.NORMAL]);
}
private override void size_allocate(Gdk.Rectangle allocation) {
......@@ -1552,8 +1560,8 @@ public class CheckerboardLayout : Gtk.DrawingArea {
// have all items in the exposed area paint themselves
foreach (CheckerboardItem item in intersection(event.area))
item.paint(window, item.is_selected() ? selected_gc : unselected_gc, unselected_gc,
border_gc);
item.paint(window, background_gc, item.is_selected() ? selected_gc : unselected_gc,
unselected_gc, border_gc);
} else {
// draw the message in the center of the window
Pango.Layout pango_layout = create_pango_layout(message);
......
......@@ -212,6 +212,11 @@ public abstract class PhotoCanvas {
// get_scaled_pixbuf_position().x and get_scaled_pixbuf_position().y
public void paint_pixbuf(Gdk.Pixbuf pixbuf) {
if (pixbuf.get_has_alpha()) {
drawable.draw_rectangle(container.style.black_gc, true,
scaled_position.x, scaled_position.y,
pixbuf.get_width(), pixbuf.get_height());
}
drawable.draw_pixbuf(default_gc, pixbuf,
0, 0,
scaled_position.x, scaled_position.y,
......@@ -220,6 +225,11 @@ public abstract class PhotoCanvas {
}
public void paint_pixbuf_area(Gdk.Pixbuf pixbuf, Box source_area) {
if (pixbuf.get_has_alpha()) {
drawable.draw_rectangle(container.style.black_gc, true,
scaled_position.x + source_area.left, scaled_position.y + source_area.top,
source_area.get_width(), source_area.get_height());
}
drawable.draw_pixbuf(default_gc, pixbuf,
source_area.left, source_area.top,
scaled_position.x + source_area.left, scaled_position.y + source_area.top,
......@@ -251,6 +261,9 @@ public abstract class PhotoCanvas {
}
public void erase_horizontal_line(int x, int y, int width) {
if (scaled.get_has_alpha())
draw_horizontal_line(container.style.black_gc, x, y, width);
drawable.draw_pixbuf(default_gc, scaled,
x, y,
scaled_position.x + x, scaled_position.y + y,
......@@ -274,6 +287,9 @@ public abstract class PhotoCanvas {
}
public void erase_vertical_line(int x, int y, int height) {
if (scaled.get_has_alpha())
draw_vertical_line(container.style.black_gc, x, y, height);
drawable.draw_pixbuf(default_gc, scaled,
x, y,
scaled_position.x + x, scaled_position.y + y,
......
......@@ -122,9 +122,13 @@ class EventDirectoryItem : CheckerboardItem {
protected override void paint_image(Gdk.GC gc, Gdk.Drawable drawable, Gdk.Pixbuf pixbuf,
Gdk.Point origin) {
Dimensions dimensions = Dimensions.for_pixbuf(pixbuf);
if (pixbuf.get_has_alpha())
draw_rounded_corners_filled(gc, drawable, dimensions, origin, 6.0);
// use rounded corners on events
Cairo.Context cx = get_rounded_corners_context(drawable, Dimensions.for_pixbuf(pixbuf),
origin, 6.0);
Cairo.Context cx = get_rounded_corners_context(drawable, dimensions, origin, 6.0);
Gdk.cairo_set_source_pixbuf(cx, pixbuf, origin.x, origin.y);
cx.paint();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment