1 /*
2 (C) Copyright 2000 Joel Vennin
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Adonthell 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 Adonthell 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 Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "win_theme.h"
20 #include "win_scrollbar.h"
21
22
23
win_scrollbar()24 win_scrollbar::win_scrollbar()
25 {
26 wsc_=NULL;
27
28 init();
29
30 set_visible_scrollbar(true);
31
32 set_trans_scrollbar(false);
33
34 set_brightness_scrollbar(false);
35
36 refresh();
37 }
38
39
win_scrollbar(win_scroll * wsc)40 win_scrollbar::win_scrollbar(win_scroll * wsc)
41 {
42 wsc_=wsc;
43
44 init();
45
46 set_visible_scrollbar(true);
47
48 set_trans_scrollbar(false);
49
50 set_brightness_scrollbar(false);
51
52 refresh();
53 }
54
55
win_scrollbar(win_scrollbar & ws)56 win_scrollbar::win_scrollbar(win_scrollbar & ws)
57 {
58 wsc_=NULL;
59
60 init();
61
62 set_visible_scrollbar(true);
63
64 set_trans_scrollbar(false);
65
66 set_brightness_scrollbar(false);
67
68 *this=ws;
69
70 refresh();
71 }
72
73
win_scrollbar(char * rep)74 win_scrollbar::win_scrollbar(char * rep)
75 {
76 wsc_=NULL;
77
78 init();
79
80 set_visible_scrollbar(true);
81
82 set_trans_scrollbar(false);
83
84 set_brightness_scrollbar(false);
85
86 load(rep);
87
88 refresh();
89 }
90
~win_scrollbar()91 win_scrollbar::~win_scrollbar()
92 {
93 destroy();
94 }
95
96
set_scrollbar(win_scrollbar & ws)97 void win_scrollbar::set_scrollbar(win_scrollbar & ws)
98 {
99 *this=ws;
100 refresh();
101 }
102
set_scrollbar(win_theme & wt)103 void win_scrollbar::set_scrollbar(win_theme & wt)
104 {
105 *this=*(wt.scrollbar);
106 refresh();
107 }
108
init()109 void win_scrollbar::init()
110 {
111 back_bot_=NULL;
112 back_mid_=NULL;
113 back_top_=NULL;
114 bar_top_=NULL;
115 bar_bot_=NULL;
116 bar_mid_=NULL;
117 bar_flex_=NULL;
118 bar_=NULL;
119 back_=NULL;
120 bar_brightness_=NULL;
121 back_brightness_=NULL;
122 bar_draw_=NULL;
123 back_draw_=NULL;
124 }
125
operator =(win_scrollbar & wb)126 win_scrollbar & win_scrollbar::operator=(win_scrollbar & wb)
127 {
128 destroy();
129 bar_top_=new image();
130 *bar_top_=*(wb.bar_top_);
131 bar_mid_=new image();
132 *bar_mid_=*(wb.bar_mid_);
133 bar_bot_=new image();
134 *bar_bot_=*(wb.bar_bot_);
135 bar_flex_=new image();
136 *bar_flex_=*(wb.bar_flex_);
137
138 back_top_=new image();
139 *back_top_=*(wb.back_top_);
140 back_mid_=new image();
141 *back_mid_=*(wb.back_mid_);
142 back_bot_=new image();
143 *back_bot_=*(wb.back_bot_);
144
145 bar_=new image();
146 back_=new image();
147 bar_->set_mask(true);
148 back_->set_mask(true);
149
150
151 bar_brightness_ = new image();
152 back_brightness_ = new image();
153 bar_brightness_->set_mask(true);
154 back_brightness_->set_mask(true);
155
156 update_back();
157 update_bar();
158
159 return *this;
160 }
161
162
163
load(char * theme)164 void win_scrollbar::load(char * theme)
165 {
166 destroy();
167 char path[255];char tmp[255];
168 strcpy(path,WIN_DIRECTORY);
169 strcat(path,WIN_SCROLLBAR_DIRECTORY);
170 strcat(path,theme);
171
172 bar_=new image();
173 back_=new image();
174 bar_->set_mask(true);
175 back_->set_mask(true);
176
177 bar_brightness_ = new image();
178 back_brightness_ = new image();
179 bar_brightness_->set_mask(true);
180 back_brightness_->set_mask(true);
181
182 bar_top_=new image();
183 strcpy(tmp,path);
184 strcat(tmp,WIN_SCROLLBAR_BAR_TOP);
185 bar_top_->load_pnm(tmp);
186
187 bar_mid_=new image();
188 strcpy(tmp,path);
189 strcat(tmp,WIN_SCROLLBAR_BAR_MID);
190 bar_mid_->load_pnm(tmp);
191
192 bar_bot_=new image();
193 strcpy(tmp,path);
194 strcat(tmp,WIN_SCROLLBAR_BAR_BOT);
195 bar_bot_->load_pnm(tmp);
196
197 bar_flex_=new image();
198 strcpy(tmp,path);
199 strcat(tmp,WIN_SCROLLBAR_BAR_FLEX);
200 bar_flex_->load_pnm(tmp);
201
202 back_top_=new image();
203 strcpy(tmp,path);
204 strcat(tmp,WIN_SCROLLBAR_BACK_TOP);
205 back_top_->load_pnm(tmp);
206
207 back_mid_=new image();
208 strcpy(tmp,path);
209 strcat(tmp,WIN_SCROLLBAR_BACK_MID);
210 back_mid_->load_pnm(tmp);
211
212 back_bot_=new image();
213 strcpy(tmp,path);
214 strcat(tmp,WIN_SCROLLBAR_BACK_BOT);
215 back_bot_->load_pnm(tmp);
216 }
217
update_back()218 void win_scrollbar::update_back()
219 {
220 if(!wsc_ || !back_) return;
221
222 back_->resize(back_mid_->length(),wsc_->height());
223
224
225 back_->tile(*back_mid_);
226
227
228 //back_->putbox_img(back_top_,0,0);
229 back_top_->draw(0,0,NULL,back_);
230
231 //back_->putbox_img(back_bot_,0,wsc_->height()-back_bot_->height());
232 back_bot_->draw(0,wsc_->height()-back_bot_->height(),NULL,back_);
233
234
235 back_brightness_->brightness(*back_, WIN_BRIGHTNESS_LEVEL);
236
237 }
238
refresh()239 void win_scrollbar::refresh()
240 {
241 if(brightness_)
242 {
243 bar_draw_=bar_brightness_;
244
245 back_draw_=back_brightness_;
246 }
247 else
248 {
249 bar_draw_=bar_;
250
251 back_draw_=back_;
252 }
253 }
254
255
destroy()256 void win_scrollbar::destroy()
257 {
258 if(back_bot_) delete back_bot_;
259
260 if(back_top_) delete back_top_;
261
262 if(back_mid_) delete back_mid_;
263
264 if(bar_bot_) delete bar_bot_;
265
266 if(bar_mid_) delete bar_mid_;
267
268 if(bar_top_) delete bar_top_;
269
270 if(bar_flex_) delete bar_flex_;
271
272 if(bar_) delete bar_;
273
274 if(back_) delete back_;
275
276 if(bar_brightness_) delete bar_brightness_;
277
278 if(back_brightness_) delete back_brightness_;
279 }
280
281
update_bar()282 void win_scrollbar::update_bar()
283 {
284 if(!wsc_ || !bar_) return;
285 if (!(wsc_->height() + wsc_->amplitude())) return;
286
287 u_int16 calcul = (wsc_->height() * wsc_->height()) / (wsc_->height() + wsc_->amplitude());
288
289 //if(calcul == bar_->height() || bar_->height() == (bar_top_->height() + bar_mid_->height() + bar_bot_->height())) return;
290
291 if( calcul > bar_top_->height() + bar_mid_->height() + bar_bot_->height())
292 {
293
294
295 bar_->resize(bar_top_->length(), calcul);
296
297 //bar_->putbox_tile_img( bar_flex_ );
298 bar_->tile(*bar_flex_);
299
300 //bar_->putbox_img(bar_top_,0,0);
301 bar_top_->draw(0,0,NULL,bar_);
302
303 //bar_->putbox_img(bar_bot_, 0, bar_->height() - bar_bot_->height());
304 bar_bot_->draw(0,bar_->height() - bar_bot_->height(),NULL,bar_);
305
306 //bar_->putbox_img(bar_mid_,0,( bar_->height() - bar_mid_->height() ) >>1 );
307 bar_mid_->draw(0,(bar_->height() - bar_mid_->height() ) >> 1, NULL,bar_);
308 }
309 else
310 {
311 bar_->resize(bar_top_->length(), bar_top_->height() + bar_mid_->height() + bar_bot_->height());
312
313 //bar_->putbox_img(bar_top_,0,0);
314 bar_top_->draw(0,0,NULL,bar_);
315
316 //bar_->putbox_img(bar_bot_,0,bar_->height() - bar_bot_->height());
317 bar_bot_->draw(0,bar_->height() - bar_bot_->height(),NULL,bar_);
318
319 //bar_->putbox_img(bar_mid_,0,bar_top_->height());
320 bar_mid_->draw(0,bar_top_->height(),NULL,bar_);
321 }
322 bar_brightness_->brightness(*bar_,WIN_BRIGHTNESS_LEVEL);
323 }
324
325
draw(drawing_area * da)326 void win_scrollbar::draw(drawing_area * da)
327 {
328 if(!visible_ || !back_draw_ || !bar_draw_) return;
329
330 back_draw_->draw(wsc_->real_x() + wsc_->length() - back_->length(), wsc_->real_y() , da );
331
332 bar_draw_->draw(1 + wsc_->real_x() + wsc_->length() - back_->length(), wsc_->real_y() + wsc_->cursor_y() , da);
333 }
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352