Adonthell  0.4
win_container.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 
14 #include "win_container.h"
15 
16 win_container::win_container()
17 {
18  move(0,0);
19 
20  set_layout(NO_LAYOUT);
21 
22  set_space_with_border(SPACE_WITH_BORDER);
23 
24  set_space_with_object(SPACE_WITH_OBJECT);
25 
26  focus_object_ = NULL;
27 
28 }
29 
30 win_container::~win_container()
31 {
32  destroy();
33 }
34 
36 {
37  win_base::move(tx,ty);
38  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
39  (*i)->update_position();
40 }
41 
43 {
44  win_base::resize(tl,th);
45 
46  update_layout();
47 
48 }
49 
50 void win_container::update_position()
51 {
52  win_base::update_position();
53  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
54  (*i)->update_position();
55 }
56 
57 void win_container::add(win_base * w)
58 {
59  list_wb_.push_back(w);
60 
61  w->set_container(this);
62 
63  update_layout();
64 }
65 
66 void win_container::remove(win_base * w)
67 {
68  list_wb_.remove(w);
69 
70  w->set_container(NULL);
71 
72  update_layout();
73 }
74 
75 void win_container::remove_all()
76 {
77  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
78  {
79  (*i)->set_container(NULL);
80  list_wb_.erase(i);
81  }
82 }
83 
84 void win_container::destroy()
85 {
86  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
87  delete *i;
88  list_wb_.clear();
89 }
90 
92 {
93  if(win_base::update())
94  {
95  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
96  {
97  if(!(*i)->update())
98  {
99  list_wb_.erase(i);
100  delete *i--;
101  }
102  }
103  return true;
104  }
105  return false;
106 }
107 
108 
110 {
112  {
113  if(focus_object_) focus_object_->input_update();
114  return true;
115  }
116  return false;
117 }
118 
119 
120 void win_container::set_focus_object(win_base * f)
121 {
122  if(focus_object_) focus_object_->set_focus(false);
123  if(f) f->set_focus(true);
124  focus_object_ = f;
125 }
126 
128 {
130 
131  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
132  (*i)->set_brightness(b);
133 }
134 
136 {
138 
139  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
140  (*i)->set_trans(b);
141 }
142 
143 void win_container::set_visible_all(bool b)
144 {
145  set_visible(b);
146  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
147  (*i)->set_visible(b);
148 }
149 
150 
151 
153 {
154  if(win_base::draw())
155  {
156  assign_drawing_area(wb_father_);
157 
158  win_background::draw(this);
159 
160  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
161  (*i)->draw();
162 
163  win_border::draw(wb_father_);
164 
166 
167  return true;
168  }
169  return false;
170 }
171 
172 
173 
174 void win_container::update_layout()
175 {
176 
177  u_int16 indice_h=space_with_border_;
178 
179  switch(layout_)
180  {
181  case LIST_LAYOUT:
182 
183  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
184  {
185  (*i)->move((*i)->x(),indice_h);
186 
187  indice_h+=(*i)->height()+space_with_object_;
188  }
189 
190  break;
191  }
192 }
193 
194 /*
195 #include <list>
196 #include "types.h"
197 #include "image.h"
198 #include "win_types.h"
199 #include "win_base.h"
200 #include "win_border.h"
201 #include "win_theme.h"
202 #include "win_container.h"
203 
204 
205 //constructor
206 win_container::win_container(s_int16 tx,s_int16 ty,u_int16 tl,u_int16 th,win_theme * wth):win_base(tx,ty,tl,th,wth)
207 {
208  //clear the list og object
209  list_obj.clear();
210 
211  //set the space between border and object
212  space_between_border_=WIN_SPACE_BETWEEN_BORDER;
213 
214  //set space between object and another object
215  space_between_object_=WIN_SPACE_BETWEEN_OBJECT;
216 */
217  /*
218  //set justify ----> WARNING MAYBE IN WIN_BASE ????
219  justify_=WIN_JUSTIFY_NO;
220 
221  */
222 /*
223  //set layout equals no
224  layout_=WIN_LAYOUT_NO;
225 }
226 
227 
228 void win_container::set_space_between_object(u_int16 tmp)
229 {
230  //set the space between object and call update layout to redefine position of each element
231  space_between_object_=tmp;
232  update_layout();
233 }
234 
235 void win_container::set_space_between_border(u_int16 tmp)
236 {
237  //set the space between border and object and call update layout to redefine position of each element
238  space_between_border_=tmp;
239  update_layout();
240 }
241 
242 win_container::~win_container()
243 {
244  destroy();
245 }
246 
247 void win_container::add(win_base * tmp)
248 {
249  //add the object
250  list_obj.push_back(tmp);
251 
252  //set the new object
253  tmp->wb_father_=this;
254  tmp->update_real_position();
255 
256 
257  tmp->update_align();
258 
259  //update layout
260  update_layout();
261  //if the win_container is brightness set the new object in brightness mode
262  if(draw_brightness_) tmp->set_draw_brightness(true);
263 }
264 
265 
266 void win_container::remove(win_base * tmp)
267 {
268  list<win_base *>::iterator i=list_obj.begin();
269  while(i!=list_obj.end() && tmp!=(*i)) i++;
270  if(i!=list_obj.end())
271  {
272  //list_obj.remove(tmp);
273  tmp->wb_father_=NULL;
274  list_obj.erase(i);
275  update_layout();
276  }
277 }
278 
279 void win_container::remove_all()
280 {
281  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
282  (*i)->wb_father_=NULL;
283  list_obj.clear();
284 }
285 
286 void win_container::destroy()
287 {
288  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
289  delete *i;
290  list_obj.clear();
291 }
292 
293 void win_container::resize(u_int16 tl,u_int16 th)
294 {
295  win_base::resize(tl,th);
296  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
297  (*i)->update_align();
298 }
299 
300 bool win_container::update()
301 {
302  //call the win update ---> on update()
303  if(win_base::update())
304  {
305  //update all the element in the list
306  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
307  {
308  if(!(*i)->update())
309  {
310  remove(*i);
311  delete *i--;
312  }
313  }
314  return true;
315  }
316  return false;
317 }
318 
319 
320 bool win_container::draw()
321 {
322  if(win_base::draw())
323  {
324  assign_drawing_area(); //assign drawing area
325  //draw the background
326  draw_background();
327  //next draw all the element
328  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
329  (*i)->draw();
330  //draw the border
331  draw_border();
332  //detach the drawing area
333  detach_drawing_area();
334  return true;
335  }
336  return false;
337 }
338 
339 
340 //set visible mode for all element in list
341 void win_container::set_visible_all(bool b)
342 {
343  visible_=b;
344  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
345  (*i)->set_visible(visible_);
346 }
347 
348 //set draw brightness for all element in the list
349 void win_container::set_draw_brightness(bool b)
350 {
351  win_base::set_draw_brightness(b);
352  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
353  (*i)->set_draw_brightness(b);
354 }
355 */
356 /*
357 
358 //set justify an object in this container
359 void win_container::set_justify(win_base * wb, u_int8 just)
360 {
361  switch(just)
362  {
363  case WIN_JUSTIFY_LEFT:
364  wb->move(space_between_border_,wb->y());
365  break;
366  case WIN_JUSTIFY_RIGHT:
367  wb->move(length_-space_between_border_-wb->length(),wb->y());
368  break;
369  case WIN_JUSTIFY_CENTER:
370  if(length_>wb->length())
371  wb->move((length_-wb->length())>>1,wb->y());
372  break;
373  }
374 }
375 
376 //justify all the element
377 
378 */
379 
380 /*
381 void win_container::set_align_all(u_int8 a)
382 {
383  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
384  (*i)->set_align(a);
385 }
386 
387 
388 
389 
390 //sezt the layout and update
391 void win_container::set_layout(u_int8 lay)
392 {
393  layout_=lay;
394  update_layout();
395 }
396 
397 //
398 void win_container::update_real_position()
399 {
400  win_base::update_real_position();
401  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
402  (*i)->update_real_position();
403 }
404 
405 void win_container::move(s_int16 tx,s_int16 ty)
406 {
407  win_base::move(tx,ty);
408  update_real_position();
409 }
410 
411 
412 //just one layout actually but i whish add another --> grid layout
413 void win_container::update_layout()
414 {
415  u_int16 old_h=0;
416  u_int16 indice_h=space_between_border_;
417  u_int16 indice_l=space_between_border_;
418  switch(layout_)
419  {
420  case WIN_LAYOUT_LIST:
421  //u_int16 indice=space_between_border_;
422  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
423  {
424  (*i)->move((*i)->x(),indice_h);
425  indice_h+=(*i)->height()+space_between_object_;
426  }
427  break;
428 
429  case WIN_LAYOUT_AUTO:
430 
431  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
432  {
433 
434  if(indice_l+(*i)->length()>length_)
435  {
436  indice_l=space_between_border_;
437  indice_h+=old_h+space_between_object_;
438  (*i)->move(indice_l,indice_h);
439  }
440 
441  (*i)->move(indice_l,indice_h);
442  indice_l+=(*i)->length()+space_between_object_;
443  old_h=(*i)->height();
444  }
445  break;
446 
447 
448 
449 
450  default:
451  break;
452  }
453 }
454 
455 
456 void win_container::set_focus(bool b)
457 {
458  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
459  (*i)->set_focus(b);
460  focus_=b;
461 }
462 
463 
464 
465 
466 
467 
468 */
469 
470 
471 
472 
473 
474 
475 
476 
virtual void move(s_int16 tx, s_int16 ty)
Move the win_*.
Definition: win_base.cc:71
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
void detach_drawing_area()
Detach (if needed) the drawing_area which was attached to this one.
Definition: drawing_area.h:146
virtual void set_trans(bool b)
Set the transluency parameter.
void set_visible(const bool b)
Set the visible parameter.
Definition: win_base.h:136
void resize(u_int16, u_int16)
Rezise the win_*.
virtual bool input_update()
Input Update process .
void move(s_int16, s_int16)
Move the win_*.
virtual void set_brightness(bool b)
Set the transluency parameter.
virtual void set_trans(const bool b)
Set the transluency parameter.
Definition: win_base.h:180
void assign_drawing_area(const drawing_area *da)
Assign a drawing_area to this drawing_area.
Definition: drawing_area.h:127
virtual bool update()
Update process.
Definition: win_base.cc:90
virtual bool input_update()
Input Update process .
Definition: win_base.cc:102
virtual void resize(u_int16 tl, u_int16 th)
Rezise the win_*.
Definition: win_base.cc:81
virtual bool draw()
Draw process.
#define s_int16
16 bits long signed integer
Definition: types.h:41
void set_focus(const bool b)
Set the focus parameter.
Definition: win_base.h:166
virtual void set_brightness(const bool b)
Set the transluency parameter.
Definition: win_base.h:194
virtual bool update()
Update process.
Common properties for each win_base&#39;s object.
Definition: win_base.h:47
virtual bool draw()
Draw process.
Definition: win_base.cc:107