]> git.decadent.org.uk Git - ion3.git/blob - ioncore/gr.h
[svn-inject] Installing original source of ion3
[ion3.git] / ioncore / gr.h
1 /*
2  * ion/ioncore/gr.h
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
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 "common.h"
16 #include "rectangle.h"
17
18
19 INTRCLASS(GrBrush);
20 DECLCLASS(GrBrush){
21     Obj obj;
22 };
23
24
25 #include "rootwin.h"
26
27 /* Types */
28
29 #define GR_FONT_EXTENTS_INIT {0, 0, 0}
30
31 typedef struct{
32     uint max_height;
33     uint max_width;
34     uint baseline;
35 } GrFontExtents;
36
37 #define GR_BORDER_WIDTHS_INIT {0, 0, 0, 0, 0, 0, 0}
38
39 typedef struct{
40     uint top, bottom, left, right;
41     uint tb_ileft, tb_iright;
42     uint spacing;
43 } GrBorderWidths;
44
45 typedef struct{
46     char *text;
47     int iw;
48     char *attr;
49 } GrTextElem;
50
51 typedef enum{
52     GR_TRANSPARENCY_NO,
53     GR_TRANSPARENCY_YES,
54     GR_TRANSPARENCY_DEFAULT
55 } GrTransparency;
56
57 typedef enum{
58     GR_BORDERLINE_NONE,
59     GR_BORDERLINE_LEFT,
60     GR_BORDERLINE_RIGHT,
61     GR_BORDERLINE_TOP,
62     GR_BORDERLINE_BOTTOM
63 } GrBorderLine;
64
65 /* Flags to grbrush_begin */
66 #define GRBRUSH_AMEND       0x0001
67 #define GRBRUSH_NEED_CLIP   0x0004
68 #define GRBRUSH_NO_CLEAR_OK 0x0008 /* implied by GRBRUSH_AMEND */
69
70 /* Engines etc. */
71
72 typedef GrBrush *GrGetBrushFn(Window win, WRootWin *rootwin,
73                               const char *style);
74
75 extern bool gr_register_engine(const char *engine,  GrGetBrushFn *fn);
76 extern void gr_unregister_engine(const char *engine);
77 extern bool gr_select_engine(const char *engine);
78 extern void gr_refresh();
79 extern void gr_read_config();
80
81 /* Stylespecs are of the from attr1-attr2-etc. We require that each attr in
82  * 'spec' matches the one at same index in 'attrib' when '*' matches anything.
83  * The score increment for exact match is 2*3^index and 1*3^index for '*' 
84  * match. If all elements of 'spec' match those of 'attrib' exactly, the 
85  * accumulated score is returned. Otherwise the matching fails and zero is
86  * returned. For example:
87  *  
88  *  spec        attrib            score
89  *     foo-*-baz     foo-bar-baz        2+1*3+2*3^2 = 23
90  *  foo-bar          foo-bar-baz        2+2*3         = 8
91  *  foo-baz          foo-bar-baz        0
92  * 
93  * gr_stylespec_score2 continues matching from attrib_p2 (if not NULL) when
94  * it has reached end of attrib.
95  */
96 extern uint gr_stylespec_score(const char *spec, const char *attrib);
97 extern uint gr_stylespec_score2(const char *spec, const char *attrib, 
98                                 const char *attrib_p2);
99
100 /* GrBrush */
101
102 extern GrBrush *gr_get_brush(Window win, WRootWin *rootwin,
103                              const char *style);
104
105 extern GrBrush *grbrush_get_slave(GrBrush *brush, WRootWin *rootwin, 
106                                   const char *style);
107
108 extern void grbrush_release(GrBrush *brush);
109
110 extern bool grbrush_init(GrBrush *brush);
111 extern void grbrush_deinit(GrBrush *brush);
112
113 extern void grbrush_begin(GrBrush *brush, const WRectangle *geom,
114                           int flags);
115 extern void grbrush_end(GrBrush *brush);
116
117 /* Border drawing */
118
119 DYNFUN void grbrush_get_border_widths(GrBrush *brush, GrBorderWidths *bdi);
120
121 DYNFUN void grbrush_draw_border(GrBrush *brush, const WRectangle *geom,
122                                 const char *attrib);
123 DYNFUN void grbrush_draw_borderline(GrBrush *brush, const WRectangle *geom,
124                                     const char *attrib, GrBorderLine line);
125
126 /* String drawing */
127
128 DYNFUN void grbrush_get_font_extents(GrBrush *brush, GrFontExtents *fnti);
129
130 DYNFUN uint grbrush_get_text_width(GrBrush *brush, const char *text, uint len);
131
132 DYNFUN void grbrush_draw_string(GrBrush *brush, int x, int y,
133                                 const char *str, int len, bool needfill,
134                                 const char *attrib);
135
136 /* Textbox drawing */
137
138 DYNFUN void grbrush_draw_textbox(GrBrush *brush, const WRectangle *geom,
139                                  const char *text, const char *attr,
140                                  bool needfill);
141
142 DYNFUN void grbrush_draw_textboxes(GrBrush *brush, const WRectangle *geom,
143                                    int n, const GrTextElem *elem, 
144                                    bool needfill, const char *common_attrib);
145
146 /* Misc */
147
148 /* Behaviour of the following two functions for "slave brushes" is undefined. 
149  * If the parameter rough to grbrush_set_window_shape is set, the actual 
150  * shape may be changed for corner smoothing and other superfluous effects.
151  * (This feature is only used by floatframes.)
152  */
153 DYNFUN void grbrush_set_window_shape(GrBrush *brush, bool rough,
154                                      int n, const WRectangle *rects);
155
156 DYNFUN void grbrush_enable_transparency(GrBrush *brush, GrTransparency mode);
157
158 DYNFUN void grbrush_fill_area(GrBrush *brush, const WRectangle *geom, 
159                               const char *attr);
160 DYNFUN void grbrush_clear_area(GrBrush *brush, const WRectangle *geom);
161
162 DYNFUN bool grbrush_get_extra(GrBrush *brush, const char *key, 
163                               char type, void *data);
164
165 #endif /* ION_IONCORE_GR_H */