]> git.decadent.org.uk Git - ion3.git/blob - ioncore/gr.h
2d552985c5fc09dec39bc174333307fe829b7eb9
[ion3.git] / ioncore / gr.h
1 /*
2  * ion/ioncore/gr.h
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #ifndef ION_IONCORE_GR_H
13 #define ION_IONCORE_GR_H
14
15 #include <libtu/stringstore.h>
16
17 #include "common.h"
18 #include "rectangle.h"
19
20
21 INTRCLASS(GrBrush);
22 DECLCLASS(GrBrush){
23     Obj obj;
24 };
25
26
27 #include "rootwin.h"
28
29 /* Types */
30
31 #define GR_FONT_EXTENTS_INIT {0, 0, 0}
32
33 typedef struct{
34     uint max_height;
35     uint max_width;
36     uint baseline;
37 } GrFontExtents;
38
39 #define GR_BORDER_WIDTHS_INIT {0, 0, 0, 0, 0, 0, 0}
40
41 typedef struct{
42     uint top, bottom, left, right;
43     uint tb_ileft, tb_iright;
44     uint spacing;
45 } GrBorderWidths;
46
47 typedef StringId GrAttr;
48
49 #define GRATTR_NONE STRINGID_NONE
50
51 #define GR_STYLESPEC_INIT {0, NULL}
52
53 typedef struct{
54     GrAttr attr;
55     uint score;
56 } GrAttrScore;
57
58 typedef struct{
59     uint n;
60     GrAttrScore *attrs;
61 } GrStyleSpec;
62
63 #define GR_TEXTELEM_INIT {NULL, 0, GR_STYLESPEC_INIT}
64
65 typedef struct{
66     char *text;
67     int iw;
68     GrStyleSpec attr;
69 } GrTextElem;
70
71 typedef enum{
72     GR_TRANSPARENCY_NO,
73     GR_TRANSPARENCY_YES,
74     GR_TRANSPARENCY_DEFAULT
75 } GrTransparency;
76
77 typedef enum{
78     GR_BORDERLINE_NONE,
79     GR_BORDERLINE_LEFT,
80     GR_BORDERLINE_RIGHT,
81     GR_BORDERLINE_TOP,
82     GR_BORDERLINE_BOTTOM
83 } GrBorderLine;
84
85 /* Flags to grbrush_begin */
86 #define GRBRUSH_AMEND       0x0001
87 #define GRBRUSH_NEED_CLIP   0x0004
88 #define GRBRUSH_NO_CLEAR_OK 0x0008 /* implied by GRBRUSH_AMEND */
89 #define GRBRUSH_KEEP_ATTR   0x0010
90
91 /* Engines etc. */
92
93 typedef GrBrush *GrGetBrushFn(Window win, WRootWin *rootwin,
94                               const char *style);
95
96 extern bool gr_register_engine(const char *engine,  GrGetBrushFn *fn);
97 extern void gr_unregister_engine(const char *engine);
98 extern bool gr_select_engine(const char *engine);
99 extern void gr_refresh();
100 extern void gr_read_config();
101
102  /* Every star ('*') element of 'spec' increases score by one.
103   * Every other element of 'spec' found in 'attr' increases the score by the
104   * number set in attr times two. Any element of 'spec' (other than star),
105   *  not found in 'attr', forces score to zero.
106   */
107 extern uint gr_stylespec_score(const GrStyleSpec *spec, const GrStyleSpec *attr);
108 extern uint gr_stylespec_score2(const GrStyleSpec *spec, const GrStyleSpec *attr,
109                                 const GrStyleSpec *attr2);
110
111 extern void gr_stylespec_init(GrStyleSpec *spec);
112 extern bool gr_stylespec_set(GrStyleSpec *spec, GrAttr a);
113 extern void gr_stylespec_unset(GrStyleSpec *spec, GrAttr a);
114 extern bool gr_stylespec_add(GrStyleSpec *spec, GrAttr a, uint score);
115 extern bool gr_stylespec_append(GrStyleSpec *dst, const GrStyleSpec *src);
116 extern void gr_stylespec_unalloc(GrStyleSpec *spec);
117 extern bool gr_stylespec_equals(const GrStyleSpec *s1, const GrStyleSpec *s2);
118 extern bool gr_stylespec_load(GrStyleSpec *spec, const char *str);
119 extern bool gr_stylespec_load_(GrStyleSpec *spec, const char *str, 
120                                bool no_order_score);
121
122 /* GrBrush */
123
124 extern GrBrush *gr_get_brush(Window win, WRootWin *rootwin,
125                              const char *style);
126
127 DYNFUN GrBrush *grbrush_get_slave(GrBrush *brush, WRootWin *rootwin, 
128                                   const char *style);
129
130 extern void grbrush_release(GrBrush *brush);
131
132 extern bool grbrush_init(GrBrush *brush);
133 extern void grbrush_deinit(GrBrush *brush);
134
135 DYNFUN void grbrush_begin(GrBrush *brush, const WRectangle *geom,
136                           int flags);
137 DYNFUN void grbrush_end(GrBrush *brush);
138
139 /* Attributes */
140
141 DYNFUN void grbrush_init_attr(GrBrush *brush, const GrStyleSpec *spec);
142 DYNFUN void grbrush_set_attr(GrBrush *brush, GrAttr attr);
143 DYNFUN void grbrush_unset_attr(GrBrush *brush, GrAttr attr);
144
145 /* Border drawing */
146
147 DYNFUN void grbrush_get_border_widths(GrBrush *brush, GrBorderWidths *bdi);
148
149 DYNFUN void grbrush_draw_border(GrBrush *brush, const WRectangle *geom);
150 DYNFUN void grbrush_draw_borderline(GrBrush *brush, const WRectangle *geom,
151                                     GrBorderLine line);
152
153 /* String drawing */
154
155 DYNFUN void grbrush_get_font_extents(GrBrush *brush, GrFontExtents *fnti);
156
157 DYNFUN uint grbrush_get_text_width(GrBrush *brush, const char *text, uint len);
158
159 DYNFUN void grbrush_draw_string(GrBrush *brush, int x, int y,
160                                 const char *str, int len, bool needfill);
161
162 /* Textbox drawing */
163
164 DYNFUN void grbrush_draw_textbox(GrBrush *brush, const WRectangle *geom,
165                                  const char *text, bool needfill);
166
167 DYNFUN void grbrush_draw_textboxes(GrBrush *brush, const WRectangle *geom,
168                                    int n, const GrTextElem *elem, 
169                                    bool needfill);
170
171 /* Misc */
172
173 /* Behaviour of the following two functions for "slave brushes" is undefined. 
174  * If the parameter rough to grbrush_set_window_shape is set, the actual 
175  * shape may be changed for corner smoothing and other superfluous effects.
176  * (This feature is only used by floatframes.)
177  */
178 DYNFUN void grbrush_set_window_shape(GrBrush *brush, bool rough,
179                                      int n, const WRectangle *rects);
180
181 DYNFUN void grbrush_enable_transparency(GrBrush *brush, GrTransparency mode);
182
183 DYNFUN void grbrush_fill_area(GrBrush *brush, const WRectangle *geom);
184 DYNFUN void grbrush_clear_area(GrBrush *brush, const WRectangle *geom);
185
186 DYNFUN bool grbrush_get_extra(GrBrush *brush, const char *key, 
187                               char type, void *data);
188
189 #endif /* ION_IONCORE_GR_H */