]> git.decadent.org.uk Git - ion3.git/blob - de/brush.c
[svn-inject] Installing original source of ion3
[ion3.git] / de / brush.c
1 /*
2  * ion/de/brush.c
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 #include <string.h>
13
14 #include <libtu/objp.h>
15 #include <libextl/extl.h>
16
17 #include <ioncore/common.h>
18 #include <ioncore/rootwin.h>
19 #include <ioncore/extlconv.h>
20 #include <ioncore/ioncore.h>
21
22 #include "brush.h"
23 #include "style.h"
24 #include "font.h"
25 #include "colour.h"
26 #include "private.h"
27
28
29 /*{{{ Brush creation and releasing */
30
31
32 bool debrush_init(DEBrush *brush, Window win,
33                   const char *stylename, DEStyle *style)
34 {
35     brush->d=style;
36     brush->extras_fn=NULL;
37     brush->indicator_w=0;
38     brush->win=win;
39     brush->clip_set=FALSE;
40     
41     style->usecount++;
42
43     if(!grbrush_init(&(brush->grbrush))){
44         style->usecount--;
45         return FALSE;
46     }
47     
48     if(MATCHES("tab-frame", stylename) || MATCHES("tab-info", stylename)){
49         brush->extras_fn=debrush_tab_extras;
50         if(!style->tabbrush_data_ok)
51             destyle_create_tab_gcs(style);
52     }else if(MATCHES("tab-menuentry", stylename)){
53         brush->extras_fn=debrush_menuentry_extras;
54         brush->indicator_w=grbrush_get_text_width((GrBrush*)brush, 
55                                                   DE_SUB_IND, 
56                                                   DE_SUB_IND_LEN);
57     }
58     
59     return TRUE;
60 }
61
62
63 DEBrush *create_debrush(Window win, const char *stylename, DEStyle *style)
64 {
65     CREATEOBJ_IMPL(DEBrush, debrush, (p, win, stylename, style));
66 }
67
68
69 static DEBrush *do_get_brush(Window win, WRootWin *rootwin, 
70                              const char *stylename, bool slave)
71 {
72     DEStyle *style=de_get_style(rootwin, stylename);
73     DEBrush *brush;
74     
75     if(style==NULL)
76         return NULL;
77     
78     brush=create_debrush(win, stylename, style);
79     
80     /* Set background colour */
81     if(brush!=NULL && !slave){
82         grbrush_enable_transparency(&(brush->grbrush), 
83                                     GR_TRANSPARENCY_DEFAULT);
84     }
85     
86     return brush;
87 }
88
89
90 DEBrush *de_get_brush(Window win, WRootWin *rootwin, const char *stylename)
91 {
92     return do_get_brush(win, rootwin, stylename, FALSE);
93 }
94
95
96 DEBrush *debrush_get_slave(DEBrush *master, WRootWin *rootwin, 
97                            const char *stylename)
98 {
99     return do_get_brush(master->win, rootwin, stylename, TRUE);
100 }
101
102
103 void debrush_deinit(DEBrush *brush)
104 {
105     destyle_unref(brush->d);
106     brush->d=NULL;
107     grbrush_deinit(&(brush->grbrush));
108 }
109
110
111 void debrush_release(DEBrush *brush)
112 {
113     destroy_obj((Obj*)brush);
114 }
115
116
117 /*}}}*/
118
119
120 /*{{{ Border widths and extra information */
121
122
123 void debrush_get_border_widths(DEBrush *brush, GrBorderWidths *bdw)
124 {
125     DEStyle *style=brush->d;
126     DEBorder *bd=&(style->border);
127     uint tmp;
128     
129     switch(bd->style){
130     case DEBORDER_RIDGE:
131     case DEBORDER_GROOVE:
132         tmp=bd->sh+bd->hl+bd->pad;
133         bdw->top=tmp; bdw->bottom=tmp; bdw->left=tmp; bdw->right=tmp;
134         break;
135     case DEBORDER_INLAID:
136         tmp=bd->sh+bd->pad; bdw->top=tmp; bdw->left=tmp;
137         tmp=bd->hl+bd->pad; bdw->bottom=tmp; bdw->right=tmp;
138         break;
139     case DEBORDER_ELEVATED:
140     default:
141         tmp=bd->hl+bd->pad; bdw->top=tmp; bdw->left=tmp;
142         tmp=bd->sh+bd->pad; bdw->bottom=tmp; bdw->right=tmp;
143         break;
144     }
145     
146     bdw->tb_ileft=bdw->left;
147     bdw->tb_iright=bdw->right;
148     bdw->spacing=style->spacing;
149     
150     bdw->right+=brush->indicator_w;
151     bdw->tb_iright+=brush->indicator_w;
152 }
153
154
155 bool debrush_get_extra(DEBrush *brush, const char *key, char type, void *data)
156 {
157     DEStyle *style=brush->d;
158     while(style!=NULL){
159         if(extl_table_get(style->data_table, 's', type, key, data))
160             return TRUE;
161         style=style->based_on;
162     }
163     return FALSE;
164 }
165
166
167
168 /*}}}*/
169
170
171 /*{{{ Class implementation */
172
173
174 static DynFunTab debrush_dynfuntab[]={
175     {grbrush_release, debrush_release},
176     {grbrush_draw_border, debrush_draw_border},
177     {grbrush_draw_borderline, debrush_draw_borderline},
178     {grbrush_get_border_widths, debrush_get_border_widths},
179     {grbrush_draw_string, debrush_draw_string},
180     {debrush_do_draw_string, debrush_do_draw_string_default},
181     {grbrush_get_font_extents, debrush_get_font_extents},
182     {(DynFun*)grbrush_get_text_width, (DynFun*)debrush_get_text_width},
183     {grbrush_draw_textbox, debrush_draw_textbox},
184     {grbrush_draw_textboxes, debrush_draw_textboxes},
185     {grbrush_set_window_shape, debrush_set_window_shape},
186     {grbrush_enable_transparency, debrush_enable_transparency},
187     {grbrush_clear_area, debrush_clear_area},
188     {grbrush_fill_area, debrush_fill_area},
189     {(DynFun*)grbrush_get_extra, (DynFun*)debrush_get_extra},
190     {(DynFun*)grbrush_get_slave, (DynFun*)debrush_get_slave},
191     {grbrush_begin, debrush_begin},
192     {grbrush_end, debrush_end},
193     END_DYNFUNTAB
194 };
195
196
197 IMPLCLASS(DEBrush, GrBrush, debrush_deinit, debrush_dynfuntab);
198
199
200 /*}}}*/
201
202
203