summaryrefslogtreecommitdiff
path: root/test/test-nautilus-pixbuf-tile.c
blob: 51dc6e99aa344078f97e564507f444aa3044ae34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "test.h"

#include <libnautilus-extensions/nautilus-labeled-image.h>


static const char pixbuf_name[] = "/usr/share/pixmaps/gnome-globe.png";
static const char tile_name[] = "/gnome/share/nautilus/patterns/camouflage.png";

static int
pixbuf_drawing_area_expose_event (GtkWidget *widget,
				  GdkEventExpose *event,
				  gpointer callback_data)
{
	static GdkPixbuf *tile = NULL;
	GdkPixbuf *buffer;
	ArtIRect dest;
	ArtIRect tile_area;

	buffer = nautilus_gdk_pixbuf_get_global_buffer (widget->allocation.width, widget->allocation.height);

	if (tile == NULL) {
		tile = gdk_pixbuf_new_from_file (tile_name);
		g_assert (tile != NULL);
	}

	tile_area.x0 = 0;
	tile_area.y0 = 0;
	tile_area.x1 = widget->allocation.width;
	tile_area.y1 = widget->allocation.height;

	nautilus_gdk_pixbuf_draw_to_pixbuf_tiled (tile,
						  buffer,
						  &tile_area,
						  gdk_pixbuf_get_width (tile),
						  gdk_pixbuf_get_height (tile),
						  0,
						  0,
						  NAUTILUS_OPACITY_FULLY_OPAQUE,
						  GDK_INTERP_NEAREST);

	dest = nautilus_gtk_widget_get_bounds (widget);
	nautilus_gdk_pixbuf_draw_to_drawable (buffer,
					      widget->window,
					      widget->style->white_gc,
					      0,
					      0,
					      &dest,
					      GDK_RGB_DITHER_NONE,
					      GDK_PIXBUF_ALPHA_BILEVEL,
					      NAUTILUS_STANDARD_ALPHA_THRESHHOLD);

	nautilus_debug_draw_rectangle_and_cross (widget->window, &dest, 0xFF0000, TRUE);
	{
		ArtIRect one_tile;
		one_tile.x0 = widget->allocation.x;
		one_tile.y0 = widget->allocation.y;
		one_tile.x1 = gdk_pixbuf_get_width (tile);
		one_tile.y1 = gdk_pixbuf_get_height (tile);
		
		nautilus_debug_draw_rectangle_and_cross (widget->window, &one_tile, 0x0000FF, TRUE);
	}

	return TRUE;
}

static int
drawable_drawing_area_expose_event (GtkWidget *widget,
				    GdkEventExpose *event,
				    gpointer callback_data)
{
	static GdkPixbuf *tile = NULL;
	ArtIRect dest;

	if (tile == NULL) {
		tile = gdk_pixbuf_new_from_file (tile_name);
		g_assert (tile != NULL);
	}

	dest = nautilus_gtk_widget_get_bounds (widget);
	nautilus_gdk_pixbuf_draw_to_drawable_tiled (tile,
						    widget->window,
						    widget->style->white_gc,
						    &dest,
						    gdk_pixbuf_get_width (tile),
						    gdk_pixbuf_get_height (tile),
						    0,
						    0,
						    GDK_RGB_DITHER_NONE,
						    GDK_PIXBUF_ALPHA_BILEVEL,
						    NAUTILUS_STANDARD_ALPHA_THRESHHOLD);
	
	nautilus_debug_draw_rectangle_and_cross (widget->window, &dest, 0xFF0000, TRUE);
	{
		ArtIRect one_tile;
		one_tile.x0 = widget->allocation.x;
		one_tile.y0 = widget->allocation.y;
		one_tile.x1 = gdk_pixbuf_get_width (tile);
		one_tile.y1 = gdk_pixbuf_get_height (tile);
		
		nautilus_debug_draw_rectangle_and_cross (widget->window, &one_tile, 0x0000FF, TRUE);
	}

	return TRUE;
}

int 
main (int argc, char* argv[])
{
	GtkWidget *pixbuf_window;
	GtkWidget *pixbuf_drawing_area;
	GtkWidget *pixbuf_vbox;
	GtkWidget *drawable_window;
	GtkWidget *drawable_drawing_area;
	GtkWidget *drawable_vbox;
	
	test_init (&argc, &argv);

	pixbuf_window = test_window_new ("Pixbuf To Pixbuf Tile Test", 0);
	pixbuf_vbox = gtk_vbox_new (FALSE, 0);
	pixbuf_drawing_area = gtk_drawing_area_new ();
	gtk_signal_connect (GTK_OBJECT (pixbuf_drawing_area),
			    "expose_event",
			    GTK_SIGNAL_FUNC (pixbuf_drawing_area_expose_event),
			    NULL);
	gtk_box_pack_start (GTK_BOX (pixbuf_vbox), pixbuf_drawing_area, TRUE, TRUE, 0);
	gtk_container_add (GTK_CONTAINER (pixbuf_window), pixbuf_vbox);
	gtk_widget_show_all (pixbuf_window);


	drawable_window = test_window_new ("Pixbuf To Drawable Tile Test", 0);
	drawable_vbox = gtk_vbox_new (FALSE, 0);
	drawable_drawing_area = gtk_drawing_area_new ();
	gtk_signal_connect (GTK_OBJECT (drawable_drawing_area),
			    "expose_event",
			    GTK_SIGNAL_FUNC (drawable_drawing_area_expose_event),
			    NULL);
	gtk_box_pack_start (GTK_BOX (drawable_vbox), drawable_drawing_area, TRUE, TRUE, 0);
	gtk_container_add (GTK_CONTAINER (drawable_window), drawable_vbox);
	gtk_widget_show_all (drawable_window);

	gtk_main ();

	return 0;
}