Merge branch 'contrib_goto_focus'
[notion.git] / ioncore / gr.h
blob96098c6061f285117de2c64a799c8216a5cc0fb5
1 /*
2 * ion/ioncore/gr.h
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #ifndef ION_IONCORE_GR_H
10 #define ION_IONCORE_GR_H
12 #include <libtu/stringstore.h>
14 #include "common.h"
15 #include "rectangle.h"
18 INTRCLASS(GrBrush);
19 DECLCLASS(GrBrush){
20 Obj obj;
24 #include "rootwin.h"
26 /* Types */
28 #define GR_FONT_EXTENTS_INIT {0, 0, 0}
30 typedef struct{
31 uint max_height;
32 uint max_width;
33 uint baseline;
34 } GrFontExtents;
36 #define GR_BORDER_WIDTHS_INIT {0, 0, 0, 0, 0, 0, 0}
38 typedef struct{
39 uint top, bottom, left, right;
40 uint tb_ileft, tb_iright;
41 uint spacing;
42 } GrBorderWidths;
44 typedef StringId GrAttr;
46 #define GRATTR_NONE STRINGID_NONE
48 #define GR_STYLESPEC_INIT {0, NULL}
50 typedef struct{
51 GrAttr attr;
52 uint score;
53 } GrAttrScore;
55 typedef struct{
56 uint n;
57 GrAttrScore *attrs;
58 } GrStyleSpec;
60 #define GR_TEXTELEM_INIT {NULL, 0, GR_STYLESPEC_INIT}
62 typedef struct{
63 char *text;
64 int iw;
65 GrStyleSpec attr;
66 } GrTextElem;
68 typedef enum{
69 GR_TRANSPARENCY_NO,
70 GR_TRANSPARENCY_YES,
71 GR_TRANSPARENCY_DEFAULT
72 } GrTransparency;
74 typedef enum{
75 GR_BORDERLINE_NONE,
76 GR_BORDERLINE_LEFT,
77 GR_BORDERLINE_RIGHT,
78 GR_BORDERLINE_TOP,
79 GR_BORDERLINE_BOTTOM
80 } GrBorderLine;
82 /* Flags to grbrush_begin */
83 #define GRBRUSH_AMEND 0x0001
84 #define GRBRUSH_NEED_CLIP 0x0004
85 #define GRBRUSH_NO_CLEAR_OK 0x0008 /* implied by GRBRUSH_AMEND */
86 #define GRBRUSH_KEEP_ATTR 0x0010
88 /* Engines etc. */
90 typedef GrBrush *GrGetBrushFn(Window win, WRootWin *rootwin,
91 const char *style);
93 extern bool gr_register_engine(const char *engine, GrGetBrushFn *fn);
94 extern void gr_unregister_engine(const char *engine);
95 extern bool gr_select_engine(const char *engine);
96 extern void gr_refresh();
97 extern void gr_read_config();
99 /* Every star ('*') element of 'spec' increases score by one.
100 * Every other element of 'spec' found in 'attr' increases the score by the
101 * number set in attr times two. Any element of 'spec' (other than star),
102 * not found in 'attr', forces score to zero.
104 extern uint gr_stylespec_score(const GrStyleSpec *spec, const GrStyleSpec *attr);
105 extern uint gr_stylespec_score2(const GrStyleSpec *spec, const GrStyleSpec *attr,
106 const GrStyleSpec *attr2);
108 extern void gr_stylespec_init(GrStyleSpec *spec);
109 extern bool gr_stylespec_set(GrStyleSpec *spec, GrAttr a);
110 extern bool gr_stylespec_isset(const GrStyleSpec *spec, GrAttr a);
111 extern void gr_stylespec_unset(GrStyleSpec *spec, GrAttr a);
112 extern bool gr_stylespec_add(GrStyleSpec *spec, GrAttr a, uint score);
113 extern bool gr_stylespec_append(GrStyleSpec *dst, const GrStyleSpec *src);
114 extern void gr_stylespec_unalloc(GrStyleSpec *spec);
115 extern bool gr_stylespec_equals(const GrStyleSpec *s1, const GrStyleSpec *s2);
116 extern bool gr_stylespec_load(GrStyleSpec *spec, const char *str);
117 extern bool gr_stylespec_load_(GrStyleSpec *spec, const char *str,
118 bool no_order_score);
120 /* GrBrush */
122 extern GrBrush *gr_get_brush(Window win, WRootWin *rootwin,
123 const char *style);
125 DYNFUN GrBrush *grbrush_get_slave(GrBrush *brush, WRootWin *rootwin,
126 const char *style);
128 extern void grbrush_release(GrBrush *brush);
130 extern bool grbrush_init(GrBrush *brush);
131 extern void grbrush_deinit(GrBrush *brush);
133 DYNFUN void grbrush_begin(GrBrush *brush, const WRectangle *geom,
134 int flags);
135 DYNFUN void grbrush_end(GrBrush *brush);
137 /* Attributes */
139 DYNFUN void grbrush_init_attr(GrBrush *brush, const GrStyleSpec *spec);
140 DYNFUN void grbrush_set_attr(GrBrush *brush, GrAttr attr);
141 DYNFUN void grbrush_unset_attr(GrBrush *brush, GrAttr attr);
143 /* Border drawing */
145 DYNFUN void grbrush_get_border_widths(GrBrush *brush, GrBorderWidths *bdi);
147 DYNFUN void grbrush_draw_border(GrBrush *brush, const WRectangle *geom);
148 DYNFUN void grbrush_draw_borderline(GrBrush *brush, const WRectangle *geom,
149 GrBorderLine line);
151 /* String drawing */
153 DYNFUN void grbrush_get_font_extents(GrBrush *brush, GrFontExtents *fnti);
155 DYNFUN uint grbrush_get_text_width(GrBrush *brush, const char *text, uint len);
157 DYNFUN void grbrush_draw_string(GrBrush *brush, int x, int y,
158 const char *str, int len, bool needfill);
160 /* Textbox drawing */
162 DYNFUN void grbrush_draw_textbox(GrBrush *brush, const WRectangle *geom,
163 const char *text, bool needfill);
165 DYNFUN void grbrush_draw_textboxes(GrBrush *brush, const WRectangle *geom,
166 int n, const GrTextElem *elem,
167 bool needfill);
169 /* Misc */
171 /* Behaviour of the following two functions for "slave brushes" is undefined.
172 * If the parameter rough to grbrush_set_window_shape is set, the actual
173 * shape may be changed for corner smoothing and other superfluous effects.
174 * (This feature is only used by floatframes.)
176 DYNFUN void grbrush_set_window_shape(GrBrush *brush, bool rough,
177 int n, const WRectangle *rects);
179 DYNFUN void grbrush_enable_transparency(GrBrush *brush, GrTransparency mode);
181 DYNFUN void grbrush_fill_area(GrBrush *brush, const WRectangle *geom);
182 DYNFUN void grbrush_clear_area(GrBrush *brush, const WRectangle *geom);
184 DYNFUN bool grbrush_get_extra(GrBrush *brush, const char *key,
185 char type, void *data);
187 #endif /* ION_IONCORE_GR_H */