]> Dogcows Code - chaz/tint2/blob - src/util/area.c
New import
[chaz/tint2] / src / util / area.c
1 /**************************************************************************
2 *
3 * Tint2 : area
4 *
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
6 *
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.
10 *
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 **************************************************************************/
19
20 #include <X11/Xlib.h>
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27
28 #include "window.h"
29 #include "server.h"
30 #include "area.h"
31
32
33
34 void redraw (Area *a)
35 {
36 a->redraw = 1;
37
38 GSList *l;
39 for (l = a->list ; l ; l = l->next)
40 redraw(l->data);
41 }
42
43
44 int draw (Area *a)
45 {
46 if (!a->redraw) return 0;
47
48 cairo_surface_t *cs;
49 cairo_t *c;
50 int ret = 0;
51
52 if (a->pmap) XFreePixmap (server.dsp, a->pmap);
53 a->pmap = server_create_pixmap (a->width, a->height);
54
55 // add layer of root pixmap
56 XCopyArea (server.dsp, server.pmap, a->pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
57
58 cs = cairo_xlib_surface_create (server.dsp, a->pmap, server.visual, a->width, a->height);
59 c = cairo_create (cs);
60
61 draw_background (a, c);
62
63 if (a->draw_foreground) {
64 ret = a->draw_foreground(a, c);
65 }
66 else {
67 // parcours de la liste des sous objets
68 }
69
70 cairo_destroy (c);
71 cairo_surface_destroy (cs);
72 a->redraw = 0;
73
74 return ret;
75 }
76
77
78 void draw_background (Area *a, cairo_t *c)
79 {
80 if (a->back.alpha > 0.0) {
81 //printf(" draw_background %d %d\n", a->width, a->height);
82 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);
83 /*
84 double x0, y0, x1, y1;
85 x0 = 0;
86 y0 = 100;
87 x1 = 100;
88 y1 = 0;
89
90 cairo_pattern_t *linpat;
91 cairo_matrix_t matrix;
92 linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
93
94 cairo_pattern_add_color_stop_rgba (linpat, 0, a->back.color[0], a->back.color[1], a->back.color[2], a->back.alpha);
95 cairo_pattern_add_color_stop_rgba (linpat, 1, a->back.color[0], a->back.color[1], a->back.color[2], 0);
96 //cairo_matrix_init_scale (&matrix, a->height, a->width);
97 //cairo_pattern_set_matrix (linpat, &matrix);
98 cairo_set_source (c, linpat);
99 */
100 cairo_set_source_rgba(c, a->back.color[0], a->back.color[1], a->back.color[2], a->back.alpha);
101
102 cairo_fill(c);
103 //cairo_pattern_destroy (linpat);
104 }
105
106 if (a->border.width > 0 && a->border.alpha > 0.0) {
107 cairo_set_line_width (c, a->border.width);
108
109 // draw border inside (x, y, width, height)
110 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);
111 /*
112 // convert : radian = degre * M_PI/180
113 // définir le dégradé dans un carré de (0,0) (100,100)
114 // ensuite ce dégradé est extrapolé selon le ratio width/height
115 // dans repère (0, 0) (100, 100)
116 double X0, Y0, X1, Y1, degre;
117 // x = X * (a->width / 100), y = Y * (a->height / 100)
118 double x0, y0, x1, y1;
119 X0 = 0;
120 Y0 = 100;
121 X1 = 100;
122 Y1 = 0;
123 degre = 45;
124 // et ensuite faire la changement d'unité du repère
125 // car ce qui doit resté inchangée est les traits et pas la direction
126
127 // il faut d'abord appliquer une rotation de 90° (et -180° si l'angle est supérieur à 180°)
128 // ceci peut être appliqué une fois pour toute au départ
129 // ensuite calculer l'angle dans le nouveau repère
130 // puis faire une rotation de 90°
131 x0 = X0 * ((double)a->width / 100);
132 x1 = X1 * ((double)a->width / 100);
133 y0 = Y0 * ((double)a->height / 100);
134 y1 = Y1 * ((double)a->height / 100);
135
136 x0 = X0 * ((double)a->height / 100);
137 x1 = X1 * ((double)a->height / 100);
138 y0 = Y0 * ((double)a->width / 100);
139 y1 = Y1 * ((double)a->width / 100);
140 printf("repère (%d, %d) points (%lf, %lf) (%lf, %lf)\n", a->width, a->height, x0, y0, x1, y1);
141
142 cairo_pattern_t *linpat;
143 linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
144 cairo_pattern_add_color_stop_rgba (linpat, 0, a->border.color[0], a->border.color[1], a->border.color[2], a->border.alpha);
145 cairo_pattern_add_color_stop_rgba (linpat, 1, a->border.color[0], a->border.color[1], a->border.color[2], 0);
146 cairo_set_source (c, linpat);
147 */
148 cairo_set_source_rgba (c, a->border.color[0], a->border.color[1], a->border.color[2], a->border.alpha);
149
150 cairo_stroke (c);
151 //cairo_pattern_destroy (linpat);
152 }
153 }
154
155
156 void refresh (Area *a)
157 {
158 XCopyArea (server.dsp, a->pmap, server.pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
159 }
160
161
162 void remove_area (Area *a)
163 {
164 Area *parent;
165
166 parent = (Area*)a->parent;
167 parent->list = g_slist_remove(parent->list, a);
168 redraw (parent);
169
170 }
171
172
173 void add_area (Area *a)
174 {
175 Area *parent;
176
177 parent = (Area*)a->parent;
178 parent->list = g_slist_remove(parent->list, a);
179 redraw (parent);
180
181 }
182
This page took 0.042264 seconds and 5 git commands to generate.