]>
Dogcows Code - chaz/tint2/blob - src/util/area.c
1 /**************************************************************************
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
38 for (l
= a
->list
; l
; l
= l
->next
)
50 //printf("begin draw area\n");
51 if (a
->pmap
) XFreePixmap (server
.dsp
, a
->pmap
);
52 a
->pmap
= server_create_pixmap (a
->width
, a
->height
);
54 // add layer of root pixmap
55 XCopyArea (server
.dsp
, server
.pmap
, a
->pmap
, server
.gc
, a
->posx
, a
->posy
, a
->width
, a
->height
, 0, 0);
57 cs
= cairo_xlib_surface_create (server
.dsp
, a
->pmap
, server
.visual
, a
->width
, a
->height
);
58 c
= cairo_create (cs
);
60 draw_background (a
, c
);
62 if (a
->draw_foreground
)
63 ret
= a
->draw_foreground(a
, c
);
66 cairo_surface_destroy (cs
);
70 XCopyArea (server
.dsp
, a
->pmap
, server
.pmap
, server
.gc
, 0, 0, a
->width
, a
->height
, a
->posx
, a
->posy
);
74 for (; l
; l
= l
->next
)
77 //printf("end draw area\n");
82 void draw_background (Area
*a
, cairo_t
*c
)
84 if (a
->back
.alpha
> 0.0) {
85 //printf(" draw_background %d %d\n", a->width, a->height);
86 draw_rect(c
, a
->border
.width
, a
->border
.width
, a
->width
-(2.0 * a
->border
.width
), a
->height
-(2.0*a
->border
.width
), a
->border
.rounded
- a
->border
.width
/1.571);
88 double x0, y0, x1, y1;
94 cairo_pattern_t *linpat;
95 cairo_matrix_t matrix;
96 linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
98 cairo_pattern_add_color_stop_rgba (linpat, 0, a->back.color[0], a->back.color[1], a->back.color[2], a->back.alpha);
99 cairo_pattern_add_color_stop_rgba (linpat, 1, a->back.color[0], a->back.color[1], a->back.color[2], 0);
100 //cairo_matrix_init_scale (&matrix, a->height, a->width);
101 //cairo_pattern_set_matrix (linpat, &matrix);
102 cairo_set_source (c, linpat);
104 cairo_set_source_rgba(c
, a
->back
.color
[0], a
->back
.color
[1], a
->back
.color
[2], a
->back
.alpha
);
107 //cairo_pattern_destroy (linpat);
110 if (a
->border
.width
> 0 && a
->border
.alpha
> 0.0) {
111 cairo_set_line_width (c
, a
->border
.width
);
113 // draw border inside (x, y, width, height)
114 draw_rect(c
, a
->border
.width
/2.0, a
->border
.width
/2.0, a
->width
- a
->border
.width
, a
->height
- a
->border
.width
, a
->border
.rounded
);
116 // convert : radian = degre * M_PI/180
117 // définir le dégradé dans un carré de (0,0) (100,100)
118 // ensuite ce dégradé est extrapolé selon le ratio width/height
119 // dans repère (0, 0) (100, 100)
120 double X0, Y0, X1, Y1, degre;
121 // x = X * (a->width / 100), y = Y * (a->height / 100)
122 double x0, y0, x1, y1;
128 // et ensuite faire la changement d'unité du repère
129 // car ce qui doit resté inchangée est les traits et pas la direction
131 // il faut d'abord appliquer une rotation de 90° (et -180° si l'angle est supérieur à 180°)
132 // ceci peut être appliqué une fois pour toute au départ
133 // ensuite calculer l'angle dans le nouveau repère
134 // puis faire une rotation de 90°
135 x0 = X0 * ((double)a->width / 100);
136 x1 = X1 * ((double)a->width / 100);
137 y0 = Y0 * ((double)a->height / 100);
138 y1 = Y1 * ((double)a->height / 100);
140 x0 = X0 * ((double)a->height / 100);
141 x1 = X1 * ((double)a->height / 100);
142 y0 = Y0 * ((double)a->width / 100);
143 y1 = Y1 * ((double)a->width / 100);
144 printf("repère (%d, %d) points (%lf, %lf) (%lf, %lf)\n", a->width, a->height, x0, y0, x1, y1);
146 cairo_pattern_t *linpat;
147 linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
148 cairo_pattern_add_color_stop_rgba (linpat, 0, a->border.color[0], a->border.color[1], a->border.color[2], a->border.alpha);
149 cairo_pattern_add_color_stop_rgba (linpat, 1, a->border.color[0], a->border.color[1], a->border.color[2], 0);
150 cairo_set_source (c, linpat);
152 cairo_set_source_rgba (c
, a
->border
.color
[0], a
->border
.color
[1], a
->border
.color
[2], a
->border
.alpha
);
155 //cairo_pattern_destroy (linpat);
160 void remove_area (Area
*a
)
164 parent
= (Area
*)a
->parent
;
165 parent
->list
= g_slist_remove(parent
->list
, a
);
171 void add_area (Area
*a
)
175 parent
= (Area
*)a
->parent
;
176 parent
->list
= g_slist_remove(parent
->list
, a
);
182 void free_area (Area
*a
)
185 for (l0
= a
->list
; l0
; l0
= l0
->next
)
186 free_area (l0
->data
);
189 g_slist_free(a
->list
);
This page took 0.044067 seconds and 5 git commands to generate.