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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2003 Richard Hult <richard@imendio.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <cdk/cdk.h>
#include <cdk/cdkx.h>
#include <ctk/ctk.h>
#include "drw-utils.h"
static GdkPixbuf *
create_tile_pixbuf (GdkPixbuf *dest_pixbuf,
GdkPixbuf *src_pixbuf,
CdkRectangle *field_geom,
guint alpha,
CdkColor *bg_color)<--- Parameter 'bg_color' can be declared as pointer to const
{
gboolean need_composite;
gboolean use_simple;
gdouble cx, cy;
gdouble colorv;
gint pwidth, pheight;
need_composite = (alpha < 255 || gdk_pixbuf_get_has_alpha (src_pixbuf));
use_simple = (dest_pixbuf == NULL);
if (dest_pixbuf == NULL)
dest_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8,
field_geom->width, field_geom->height);
if (need_composite && use_simple)
colorv = ((bg_color->red & 0xff00) << 8) |
(bg_color->green & 0xff00) |
((bg_color->blue & 0xff00) >> 8);
else
colorv = 0;
pwidth = gdk_pixbuf_get_width (src_pixbuf);
pheight = gdk_pixbuf_get_height (src_pixbuf);
for (cy = 0; cy < field_geom->height; cy += pheight) {
for (cx = 0; cx < field_geom->width; cx += pwidth) {
if (need_composite && !use_simple)
gdk_pixbuf_composite (src_pixbuf, dest_pixbuf,
cx, cy,
MIN (pwidth, field_geom->width - cx),
MIN (pheight, field_geom->height - cy),
cx, cy,
1.0, 1.0,
GDK_INTERP_BILINEAR,
alpha);
else if (need_composite && use_simple)
gdk_pixbuf_composite_color (src_pixbuf, dest_pixbuf,
cx, cy,
MIN (pwidth, field_geom->width - cx),
MIN (pheight, field_geom->height - cy),
cx, cy,
1.0, 1.0,
GDK_INTERP_BILINEAR,
alpha,
65536, 65536, 65536,
colorv, colorv);
else
gdk_pixbuf_copy_area (src_pixbuf,
0, 0,
MIN (pwidth, field_geom->width - cx),
MIN (pheight, field_geom->height - cy),
dest_pixbuf,
cx, cy);
}
}
return dest_pixbuf;
}
static gboolean
window_draw_event (CtkWidget *widget,
cairo_t *cr,
gpointer data)
{
int width;
int height;
ctk_window_get_size (CTK_WINDOW (widget), &width, &height);
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_paint (cr);
/* draw a box */
cairo_rectangle (cr, 0, 0, width, height);
cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 0.5);
cairo_fill (cr);
return FALSE;
}
static void
set_pixmap_background (CtkWidget *window)
{
CdkScreen *screen;
GdkPixbuf *tmp_pixbuf, *pixbuf, *tile_pixbuf;
CdkRectangle rect;
CdkColor color;
gint width, height, scale;
cairo_t *cr;
ctk_widget_realize (window);
screen = ctk_widget_get_screen (window);
scale = ctk_widget_get_scale_factor (window);
width = WidthOfScreen (cdk_x11_screen_get_xscreen (screen)) / scale;
height = HeightOfScreen (cdk_x11_screen_get_xscreen (screen)) / scale;
tmp_pixbuf = gdk_pixbuf_get_from_window (cdk_screen_get_root_window (screen),
0,
0,
width, height);
pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/ocean-stripes.png", NULL);
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
color.red = 0;
color.blue = 0;
color.green = 0;
tile_pixbuf = create_tile_pixbuf (NULL,
pixbuf,
&rect,
155,
&color);
g_object_unref (pixbuf);
gdk_pixbuf_composite (tile_pixbuf,
tmp_pixbuf,
0,
0,
width,
height,
0,
0,
scale,
scale,
GDK_INTERP_NEAREST,
225);
g_object_unref (tile_pixbuf);
cr = cdk_cairo_create (ctk_widget_get_window (window));
cdk_cairo_set_source_pixbuf (cr, tmp_pixbuf, 0, 0);
cairo_paint (cr);
g_object_unref (tmp_pixbuf);
cairo_destroy (cr);
}
void
drw_setup_background (CtkWidget *window)
{
CdkScreen *screen;
gboolean is_composited;
screen = ctk_widget_get_screen (window);
is_composited = cdk_screen_is_composited (screen);
if (is_composited) {
g_signal_connect (window, "draw", G_CALLBACK (window_draw_event), window);
} else {
set_pixmap_background (window);
}
}
|