]> Dogcows Code - chaz/tint2/blob - src/util/area.c
fixed bug with active task
[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 void refresh (Area *a)
34 {
35 if (a->redraw) {
36 //printf("draw pix\n");
37 draw(a, 0);
38 if (a->use_active)
39 draw(a, 1);
40 a->redraw = 0;
41 //printf("end draw pix\n");
42 }
43
44 Pixmap *pmap = (a->is_active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
45
46 // draw current Area
47 XCopyArea (server.dsp, *pmap, server.pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
48
49 // and then refresh child object
50 GSList *l = a->list;
51 for (; l ; l = l->next)
52 refresh(l->data);
53 }
54
55
56 void set_redraw (Area *a)
57 {
58 a->redraw = 1;
59
60 GSList *l;
61 for (l = a->list ; l ; l = l->next)
62 set_redraw(l->data);
63 }
64
65
66 void draw (Area *a, int active)
67 {
68 Pixmap *pmap = (active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
69
70 //printf("begin draw area\n");
71 if (*pmap) XFreePixmap (server.dsp, *pmap);
72 *pmap = server_create_pixmap (a->width, a->height);
73
74 // add layer of root pixmap
75 XCopyArea (server.dsp, server.pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
76
77 cairo_surface_t *cs;
78 cairo_t *c;
79
80 cs = cairo_xlib_surface_create (server.dsp, *pmap, server.visual, a->width, a->height);
81 c = cairo_create (cs);
82
83 draw_background (a, c, active);
84
85 if (a->draw_foreground)
86 a->draw_foreground(a, c, active);
87
88 cairo_destroy (c);
89 cairo_surface_destroy (cs);
90 }
91
92
93 void draw_background (Area *a, cairo_t *c, int active)
94 {
95 Pmap *pix = (active == 0) ? (&a->pix) : (&a->pix_active);
96
97 if (pix->back.alpha > 0.0) {
98 //printf(" draw_background (%d %d) RGBA (%lf, %lf, %lf, %lf)\n", a->posx, a->posy, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
99 draw_rect(c, pix->border.width, pix->border.width, a->width-(2.0 * pix->border.width), a->height-(2.0*pix->border.width), pix->border.rounded - pix->border.width/1.571);
100 cairo_set_source_rgba(c, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
101
102 cairo_fill(c);
103 }
104
105 if (pix->border.width > 0 && pix->border.alpha > 0.0) {
106 cairo_set_line_width (c, pix->border.width);
107
108 // draw border inside (x, y, width, height)
109 draw_rect(c, pix->border.width/2.0, pix->border.width/2.0, a->width - pix->border.width, a->height - pix->border.width, pix->border.rounded);
110 /*
111 // convert : radian = degre * M_PI/180
112 // définir le dégradé dans un carré de (0,0) (100,100)
113 // ensuite ce dégradé est extrapolé selon le ratio width/height
114 // dans repère (0, 0) (100, 100)
115 double X0, Y0, X1, Y1, degre;
116 // x = X * (a->width / 100), y = Y * (a->height / 100)
117 double x0, y0, x1, y1;
118 X0 = 0;
119 Y0 = 100;
120 X1 = 100;
121 Y1 = 0;
122 degre = 45;
123 // et ensuite faire la changement d'unité du repère
124 // car ce qui doit resté inchangée est les traits et pas la direction
125
126 // il faut d'abord appliquer une rotation de 90° (et -180° si l'angle est supérieur à 180°)
127 // ceci peut être appliqué une fois pour toute au départ
128 // ensuite calculer l'angle dans le nouveau repère
129 // puis faire une rotation de 90°
130 x0 = X0 * ((double)a->width / 100);
131 x1 = X1 * ((double)a->width / 100);
132 y0 = Y0 * ((double)a->height / 100);
133 y1 = Y1 * ((double)a->height / 100);
134
135 x0 = X0 * ((double)a->height / 100);
136 x1 = X1 * ((double)a->height / 100);
137 y0 = Y0 * ((double)a->width / 100);
138 y1 = Y1 * ((double)a->width / 100);
139 printf("repère (%d, %d) points (%lf, %lf) (%lf, %lf)\n", a->width, a->height, x0, y0, x1, y1);
140
141 cairo_pattern_t *linpat;
142 linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
143 cairo_pattern_add_color_stop_rgba (linpat, 0, a->border.color[0], a->border.color[1], a->border.color[2], a->border.alpha);
144 cairo_pattern_add_color_stop_rgba (linpat, 1, a->border.color[0], a->border.color[1], a->border.color[2], 0);
145 cairo_set_source (c, linpat);
146 */
147 cairo_set_source_rgba (c, pix->border.color[0], pix->border.color[1], pix->border.color[2], pix->border.alpha);
148
149 cairo_stroke (c);
150 //cairo_pattern_destroy (linpat);
151 }
152 }
153
154
155 void remove_area (Area *a)
156 {
157 Area *parent;
158
159 parent = (Area*)a->parent;
160 parent->list = g_slist_remove(parent->list, a);
161 set_redraw (parent);
162
163 }
164
165
166 void add_area (Area *a)
167 {
168 Area *parent;
169
170 parent = (Area*)a->parent;
171 parent->list = g_slist_remove(parent->list, a);
172 set_redraw (parent);
173
174 }
175
176
177 void free_area (Area *a)
178 {
179 GSList *l0;
180 for (l0 = a->list; l0 ; l0 = l0->next)
181 free_area (l0->data);
182
183 if (a->list) {
184 g_slist_free(a->list);
185 a->list = 0;
186 }
187 }
188
This page took 0.048763 seconds and 5 git commands to generate.