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