1 /*
2  * Copyright (C) 2001 Havoc Pennington
3  * Copyright (C) 2016 Alberts Muktupāvels
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef META_DRAW_OP_PRIVATE_H
20 #define META_DRAW_OP_PRIVATE_H
21 
22 #include <gtk/gtk.h>
23 
24 #include "meta-color-spec-private.h"
25 #include "meta-draw-spec-private.h"
26 #include "meta-gradient-spec-private.h"
27 
28 G_BEGIN_DECLS
29 
30 typedef struct _MetaDrawInfo MetaDrawInfo;
31 typedef struct _MetaDrawOp MetaDrawOp;
32 typedef struct _MetaDrawOpList MetaDrawOpList;
33 
34 /**
35  * A drawing operation in our simple vector drawing language.
36  */
37 typedef enum
38 {
39   /** Basic drawing-- line */
40   META_DRAW_LINE,
41   /** Basic drawing-- rectangle */
42   META_DRAW_RECTANGLE,
43   /** Basic drawing-- arc */
44   META_DRAW_ARC,
45 
46   /** Clip to a rectangle */
47   META_DRAW_CLIP,
48 
49   /* Texture thingies */
50 
51   /** Just a filled rectangle with alpha */
52   META_DRAW_TINT,
53   META_DRAW_GRADIENT,
54   META_DRAW_IMAGE,
55 
56   /** GTK theme engine stuff */
57   META_DRAW_GTK_ARROW,
58   META_DRAW_GTK_BOX,
59   META_DRAW_GTK_VLINE,
60 
61   /** App's window icon */
62   META_DRAW_ICON,
63   /** App's window title */
64   META_DRAW_TITLE,
65   /** a draw op list */
66   META_DRAW_OP_LIST,
67   /** tiled draw op list */
68   META_DRAW_TILE
69 } MetaDrawType;
70 
71 typedef enum
72 {
73   META_IMAGE_FILL_SCALE, /* default, needs to be all-bits-zero for g_new0 */
74   META_IMAGE_FILL_TILE
75 } MetaImageFillType;
76 
77 struct _MetaDrawInfo
78 {
79   gint         scale;
80 
81   GdkPixbuf   *mini_icon;
82   GdkPixbuf   *icon;
83   PangoLayout *title_layout;
84   gint         title_layout_width;
85   gint         title_layout_height;
86 
87   gint         left_width;
88   gint         right_width;
89   gint         top_height;
90   gint         bottom_height;
91 
92   gdouble      width;
93   gdouble      height;
94 };
95 
96 /**
97  * A single drawing operation in our simple vector drawing language.
98  */
99 struct _MetaDrawOp
100 {
101   MetaDrawType type;
102 
103   /* Positions are strings because they can be expressions */
104   union
105   {
106     struct {
107       MetaColorSpec *color_spec;
108       int dash_on_length;
109       int dash_off_length;
110       int width;
111       MetaDrawSpec *x1;
112       MetaDrawSpec *y1;
113       MetaDrawSpec *x2;
114       MetaDrawSpec *y2;
115     } line;
116 
117     struct {
118       MetaColorSpec *color_spec;
119       gboolean filled;
120       MetaDrawSpec *x;
121       MetaDrawSpec *y;
122       MetaDrawSpec *width;
123       MetaDrawSpec *height;
124     } rectangle;
125 
126     struct {
127       MetaColorSpec *color_spec;
128       gboolean filled;
129       MetaDrawSpec *x;
130       MetaDrawSpec *y;
131       MetaDrawSpec *width;
132       MetaDrawSpec *height;
133       double start_angle;
134       double extent_angle;
135     } arc;
136 
137     struct {
138       MetaDrawSpec *x;
139       MetaDrawSpec *y;
140       MetaDrawSpec *width;
141       MetaDrawSpec *height;
142     } clip;
143 
144     struct {
145       MetaColorSpec *color_spec;
146       MetaAlphaGradientSpec *alpha_spec;
147       MetaDrawSpec *x;
148       MetaDrawSpec *y;
149       MetaDrawSpec *width;
150       MetaDrawSpec *height;
151     } tint;
152 
153     struct {
154       MetaGradientSpec *gradient_spec;
155       MetaAlphaGradientSpec *alpha_spec;
156       MetaDrawSpec *x;
157       MetaDrawSpec *y;
158       MetaDrawSpec *width;
159       MetaDrawSpec *height;
160     } gradient;
161 
162     struct {
163       MetaColorSpec *colorize_spec;
164       MetaAlphaGradientSpec *alpha_spec;
165       GdkPixbuf *pixbuf;
166       MetaDrawSpec *x;
167       MetaDrawSpec *y;
168       MetaDrawSpec *width;
169       MetaDrawSpec *height;
170 
171       guint32 colorize_cache_pixel;
172       GdkPixbuf *colorize_cache_pixbuf;
173       MetaImageFillType fill_type;
174       unsigned int vertical_stripes : 1;
175       unsigned int horizontal_stripes : 1;
176     } image;
177 
178     struct {
179       GtkStateFlags state;
180       GtkShadowType shadow;
181       GtkArrowType arrow;
182       gboolean filled;
183 
184       MetaDrawSpec *x;
185       MetaDrawSpec *y;
186       MetaDrawSpec *width;
187       MetaDrawSpec *height;
188     } gtk_arrow;
189 
190     struct {
191       GtkStateFlags state;
192       GtkShadowType shadow;
193       MetaDrawSpec *x;
194       MetaDrawSpec *y;
195       MetaDrawSpec *width;
196       MetaDrawSpec *height;
197     } gtk_box;
198 
199     struct {
200       GtkStateFlags state;
201       MetaDrawSpec *x;
202       MetaDrawSpec *y1;
203       MetaDrawSpec *y2;
204     } gtk_vline;
205 
206     struct {
207       MetaAlphaGradientSpec *alpha_spec;
208       MetaDrawSpec *x;
209       MetaDrawSpec *y;
210       MetaDrawSpec *width;
211       MetaDrawSpec *height;
212       MetaImageFillType fill_type;
213     } icon;
214 
215     struct {
216       MetaColorSpec *color_spec;
217       MetaDrawSpec *x;
218       MetaDrawSpec *y;
219       MetaDrawSpec *ellipsize_width;
220     } title;
221 
222     struct {
223       MetaDrawOpList *op_list;
224       MetaDrawSpec *x;
225       MetaDrawSpec *y;
226       MetaDrawSpec *width;
227       MetaDrawSpec *height;
228     } op_list;
229 
230     struct {
231       MetaDrawOpList *op_list;
232       MetaDrawSpec *x;
233       MetaDrawSpec *y;
234       MetaDrawSpec *width;
235       MetaDrawSpec *height;
236       MetaDrawSpec *tile_xoffset;
237       MetaDrawSpec *tile_yoffset;
238       MetaDrawSpec *tile_width;
239       MetaDrawSpec *tile_height;
240     } tile;
241 
242   } data;
243 };
244 
245 G_GNUC_INTERNAL
246 MetaDrawOp     *meta_draw_op_new                  (MetaDrawType           type);
247 
248 G_GNUC_INTERNAL
249 void            meta_draw_op_free                 (MetaDrawOp            *op);
250 
251 G_GNUC_INTERNAL
252 MetaDrawOpList *meta_draw_op_list_new             (int                    n_preallocs);
253 
254 G_GNUC_INTERNAL
255 void            meta_draw_op_list_ref             (MetaDrawOpList        *op_list);
256 
257 G_GNUC_INTERNAL
258 void            meta_draw_op_list_unref           (MetaDrawOpList        *op_list);
259 
260 G_GNUC_INTERNAL
261 void            meta_draw_op_list_draw_with_style (const MetaDrawOpList  *op_list,
262                                                    GtkStyleContext       *context,
263                                                    cairo_t               *cr,
264                                                    const MetaDrawInfo    *info,
265                                                    MetaRectangleDouble    rect);
266 
267 G_GNUC_INTERNAL
268 void            meta_draw_op_list_append          (MetaDrawOpList        *op_list,
269                                                    MetaDrawOp            *op);
270 
271 G_GNUC_INTERNAL
272 gboolean        meta_draw_op_list_validate        (MetaDrawOpList        *op_list,
273                                                    GError               **error);
274 
275 G_GNUC_INTERNAL
276 gboolean        meta_draw_op_list_contains        (MetaDrawOpList        *op_list,
277                                                    MetaDrawOpList        *child);
278 
279 G_END_DECLS
280 
281 #endif
282