Commit 78132c91 authored by Andy Hertzfeld's avatar Andy Hertzfeld

made tiled image backgrounds draw properly on the anti-aliased canvas


       made tiled image backgrounds draw properly on the anti-aliased
       canvas
parent aeac9661
2000-06-06 Andy Hertzfeld <andy@eazel.com>
made tiled image backgrounds work properly in anti-aliased mode
* libnautilus-extensions/nautilus-background-canvas-group.c:
(nautilus_background_canvas_group_initialize_class),
(nautilus_background_canvas_group_draw),
(nautilus_background_canvas_group_render):
overrode the render method so backgrounds draw in anti-aliased mode
* libnautilus-extensions/nautilus-background.c:
(nautilus_background_draw), (draw_pixbuf_aa), (draw_pixbuf_tiled),
(nautilus_background_draw_aa):
added nautilus_background_draw_aa to draw the background in
anti-aliased yet. We don't support gradients yet, but that's
coming soon.
* libnautilus-extensions/nautilus-background.h:
added nautilus_background_draw_aa
* libnautilus-extensions/nautilus-icon-canvas-item.c:
(nautilus_icon_canvas_item_render):
made it respect the is_bg flag
2000-06-05 Mathieu Lacage <mathieu@gnome.org>
* components/rpmview/Makefile.am: add
......
......@@ -26,6 +26,10 @@
#include "nautilus-background-canvas-group.h"
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
#include "nautilus-background.h"
#include "nautilus-gtk-macros.h"
......@@ -35,6 +39,8 @@ static void nautilus_background_canvas_group_destroy (GtkObject *object);
static void nautilus_background_canvas_group_finalize (GtkObject *object);
static void nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height);
static void nautilus_background_canvas_group_render (GnomeCanvasItem *item, GnomeCanvasBuf *buffer);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusBackgroundCanvasGroup, nautilus_background_canvas_group, GNOME_TYPE_CANVAS_GROUP)
......@@ -51,6 +57,7 @@ nautilus_background_canvas_group_initialize_class (gpointer klass)
object_class->finalize = nautilus_background_canvas_group_finalize;
canvas_item_class->draw = nautilus_background_canvas_group_draw;
canvas_item_class->render = nautilus_background_canvas_group_render;
}
static void
......@@ -113,5 +120,31 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, draw,
(item, drawable,
drawable_corner_x, drawable_corner_y,
drawable_width, drawable_height));
drawable_width, drawable_height));
}
/* draw the background for the anti-aliased canvas */
static void
nautilus_background_canvas_group_render (GnomeCanvasItem *item, GnomeCanvasBuf *buffer)
{
NautilusBackground *background;
background = nautilus_get_widget_background(GTK_WIDGET (item->canvas));
if (background != NULL)
nautilus_background_draw_aa(background, buffer);
else
gnome_canvas_buf_ensure_buf (buffer);
buffer->is_bg = FALSE;
buffer->is_buf = TRUE;
/* Call through to the GnomeCanvasGroup implementation, which will draw all
the canvas items.
*/
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, render ,
(item, buffer));
}
......@@ -33,6 +33,12 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
#include <libart_lgpl/art_svp_vpath.h>
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object,
gpointer klass);
......@@ -161,6 +167,97 @@ nautilus_background_draw (NautilusBackground *background,
}
}
static void
draw_pixbuf_aa (GdkPixbuf *pixbuf, GnomeCanvasBuf *buf, double affine[6], int x_offset, int y_offset)
{
void (* affine_function)
(art_u8 *dst, int x0, int y0, int x1, int y1, int dst_rowstride,
const art_u8 *src, int src_width, int src_height, int src_rowstride,
const double affine[6],
ArtFilterLevel level,
ArtAlphaGamma *alpha_gamma);
affine[4] += x_offset;
affine[5] += y_offset;
affine_function = gdk_pixbuf_get_has_alpha (pixbuf)
? art_rgb_rgba_affine
: art_rgb_affine;
(* affine_function)
(buf->buf,
buf->rect.x0, buf->rect.y0,
buf->rect.x1, buf->rect.y1,
buf->buf_rowstride,
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
affine,
ART_FILTER_NEAREST,
NULL);
affine[4] -= x_offset;
affine[5] -= y_offset;
}
static void
draw_pixbuf_tiled(GdkPixbuf *pixbuf, GnomeCanvasBuf *buffer)
{
int x, y;
int start_x, start_y;
int end_x, end_y;
int tile_x, tile_y;
int blit_x, blit_y;
int tile_width, tile_height;
int blit_width, blit_height;
int tile_offset_x, tile_offset_y;
double affine[6];
art_affine_identity(affine);
tile_width = gdk_pixbuf_get_width (pixbuf);
tile_height = gdk_pixbuf_get_height (pixbuf);
tile_offset_x = buffer->rect.x0 % tile_width;
tile_offset_y = buffer->rect.y0 % tile_height;
start_x = buffer->rect.x0 - tile_offset_x;
start_y = buffer->rect.y0 - tile_offset_y;
end_x = buffer->rect.x1;
end_y = buffer->rect.y1;
for (x = start_x; x < end_x; x += tile_width) {
blit_x = MAX (x, buffer->rect.x0);
tile_x = blit_x - x;
blit_width = MIN (tile_width, end_x - x) - tile_x;
for (y = start_y; y < end_y; y += tile_height) {
blit_y = MAX (y, buffer->rect.y0);
tile_y = blit_y - y;
blit_height = MIN (tile_height, end_y - y) - tile_y;
draw_pixbuf_aa(pixbuf, buffer, affine, x, y);
}
}
}
/* draw the background on the anti-aliased canvas */
void nautilus_background_draw_aa (NautilusBackground *background,
GnomeCanvasBuf *buffer)
{
if (background->details->tile_image) {
if (!buffer->is_buf) {
draw_pixbuf_tiled(background->details->tile_image, buffer);
buffer->is_buf = TRUE;
}
} else {
gnome_canvas_buf_ensure_buf(buffer);
}
}
char *
nautilus_background_get_color (NautilusBackground *background)
{
......
......@@ -43,6 +43,8 @@
#include <gdk/gdktypes.h>
#include <gtk/gtkwidget.h>
#include <libgnomeui/gnome-canvas.h>
typedef struct NautilusBackground NautilusBackground;
typedef struct NautilusBackgroundClass NautilusBackgroundClass;
......@@ -78,6 +80,10 @@ void nautilus_background_draw (NautilusBackgroun
int origin_x,
int origin_y);
/* Explicitly fills a rectangle with a background on the anti-aliased canvas. */
void nautilus_background_draw_aa (NautilusBackground *background,
GnomeCanvasBuf *buffer);
/* Handles a dragged color being dropped on a widget to change the background color. */
void nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
......
......@@ -1214,11 +1214,14 @@ nautilus_icon_canvas_item_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf)
/* compute the affine transform, but force the scale to 1.0 because the icon factory does
the scaling for us */
gnome_canvas_item_i2c_affine (item, i2c);
i2c[0] = 1.0;
i2c[3] = 1.0;
gnome_canvas_buf_ensure_buf (buf);
i2c[0] = 1.0;
i2c[3] = 1.0;
if (buf->is_bg) {
gnome_canvas_buf_ensure_buf (buf);
buf->is_bg = FALSE;
}
/* draw the icon */
if (gdk_pixbuf_get_has_alpha(temp_pixbuf))
art_rgb_rgba_affine (buf->buf,
......
......@@ -26,6 +26,10 @@
#include "nautilus-background-canvas-group.h"
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
#include "nautilus-background.h"
#include "nautilus-gtk-macros.h"
......@@ -35,6 +39,8 @@ static void nautilus_background_canvas_group_destroy (GtkObject *object);
static void nautilus_background_canvas_group_finalize (GtkObject *object);
static void nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height);
static void nautilus_background_canvas_group_render (GnomeCanvasItem *item, GnomeCanvasBuf *buffer);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusBackgroundCanvasGroup, nautilus_background_canvas_group, GNOME_TYPE_CANVAS_GROUP)
......@@ -51,6 +57,7 @@ nautilus_background_canvas_group_initialize_class (gpointer klass)
object_class->finalize = nautilus_background_canvas_group_finalize;
canvas_item_class->draw = nautilus_background_canvas_group_draw;
canvas_item_class->render = nautilus_background_canvas_group_render;
}
static void
......@@ -113,5 +120,31 @@ nautilus_background_canvas_group_draw (GnomeCanvasItem *item, GdkDrawable *drawa
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, draw,
(item, drawable,
drawable_corner_x, drawable_corner_y,
drawable_width, drawable_height));
drawable_width, drawable_height));
}
/* draw the background for the anti-aliased canvas */
static void
nautilus_background_canvas_group_render (GnomeCanvasItem *item, GnomeCanvasBuf *buffer)
{
NautilusBackground *background;
background = nautilus_get_widget_background(GTK_WIDGET (item->canvas));
if (background != NULL)
nautilus_background_draw_aa(background, buffer);
else
gnome_canvas_buf_ensure_buf (buffer);
buffer->is_bg = FALSE;
buffer->is_buf = TRUE;
/* Call through to the GnomeCanvasGroup implementation, which will draw all
the canvas items.
*/
NAUTILUS_CALL_PARENT_CLASS (GNOME_CANVAS_ITEM_CLASS, render ,
(item, buffer));
}
......@@ -33,6 +33,12 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-util.h>
#include <libart_lgpl/art_rgb_affine.h>
#include <libart_lgpl/art_rgb_rgba_affine.h>
#include <libart_lgpl/art_svp_vpath.h>
static void nautilus_background_initialize_class (gpointer klass);
static void nautilus_background_initialize (gpointer object,
gpointer klass);
......@@ -161,6 +167,97 @@ nautilus_background_draw (NautilusBackground *background,
}
}
static void
draw_pixbuf_aa (GdkPixbuf *pixbuf, GnomeCanvasBuf *buf, double affine[6], int x_offset, int y_offset)
{
void (* affine_function)
(art_u8 *dst, int x0, int y0, int x1, int y1, int dst_rowstride,
const art_u8 *src, int src_width, int src_height, int src_rowstride,
const double affine[6],
ArtFilterLevel level,
ArtAlphaGamma *alpha_gamma);
affine[4] += x_offset;
affine[5] += y_offset;
affine_function = gdk_pixbuf_get_has_alpha (pixbuf)
? art_rgb_rgba_affine
: art_rgb_affine;
(* affine_function)
(buf->buf,
buf->rect.x0, buf->rect.y0,
buf->rect.x1, buf->rect.y1,
buf->buf_rowstride,
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
affine,
ART_FILTER_NEAREST,
NULL);
affine[4] -= x_offset;
affine[5] -= y_offset;
}
static void
draw_pixbuf_tiled(GdkPixbuf *pixbuf, GnomeCanvasBuf *buffer)
{
int x, y;
int start_x, start_y;
int end_x, end_y;
int tile_x, tile_y;
int blit_x, blit_y;
int tile_width, tile_height;
int blit_width, blit_height;
int tile_offset_x, tile_offset_y;
double affine[6];
art_affine_identity(affine);
tile_width = gdk_pixbuf_get_width (pixbuf);
tile_height = gdk_pixbuf_get_height (pixbuf);
tile_offset_x = buffer->rect.x0 % tile_width;
tile_offset_y = buffer->rect.y0 % tile_height;
start_x = buffer->rect.x0 - tile_offset_x;
start_y = buffer->rect.y0 - tile_offset_y;
end_x = buffer->rect.x1;
end_y = buffer->rect.y1;
for (x = start_x; x < end_x; x += tile_width) {
blit_x = MAX (x, buffer->rect.x0);
tile_x = blit_x - x;
blit_width = MIN (tile_width, end_x - x) - tile_x;
for (y = start_y; y < end_y; y += tile_height) {
blit_y = MAX (y, buffer->rect.y0);
tile_y = blit_y - y;
blit_height = MIN (tile_height, end_y - y) - tile_y;
draw_pixbuf_aa(pixbuf, buffer, affine, x, y);
}
}
}
/* draw the background on the anti-aliased canvas */
void nautilus_background_draw_aa (NautilusBackground *background,
GnomeCanvasBuf *buffer)
{
if (background->details->tile_image) {
if (!buffer->is_buf) {
draw_pixbuf_tiled(background->details->tile_image, buffer);
buffer->is_buf = TRUE;
}
} else {
gnome_canvas_buf_ensure_buf(buffer);
}
}
char *
nautilus_background_get_color (NautilusBackground *background)
{
......
......@@ -43,6 +43,8 @@
#include <gdk/gdktypes.h>
#include <gtk/gtkwidget.h>
#include <libgnomeui/gnome-canvas.h>
typedef struct NautilusBackground NautilusBackground;
typedef struct NautilusBackgroundClass NautilusBackgroundClass;
......@@ -78,6 +80,10 @@ void nautilus_background_draw (NautilusBackgroun
int origin_x,
int origin_y);
/* Explicitly fills a rectangle with a background on the anti-aliased canvas. */
void nautilus_background_draw_aa (NautilusBackground *background,
GnomeCanvasBuf *buffer);
/* Handles a dragged color being dropped on a widget to change the background color. */
void nautilus_background_receive_dropped_color (NautilusBackground *background,
GtkWidget *widget,
......
......@@ -1214,11 +1214,14 @@ nautilus_icon_canvas_item_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf)
/* compute the affine transform, but force the scale to 1.0 because the icon factory does
the scaling for us */
gnome_canvas_item_i2c_affine (item, i2c);
i2c[0] = 1.0;
i2c[3] = 1.0;
gnome_canvas_buf_ensure_buf (buf);
i2c[0] = 1.0;
i2c[3] = 1.0;
if (buf->is_bg) {
gnome_canvas_buf_ensure_buf (buf);
buf->is_bg = FALSE;
}
/* draw the icon */
if (gdk_pixbuf_get_has_alpha(temp_pixbuf))
art_rgb_rgba_affine (buf->buf,
......
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