00001 /* 00002 (C) Copyright 2000 Joel Vennin 00003 Part of the Adonthell Project http://adonthell.linuxgames.com 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License. 00007 This program is distributed in the hope that it will be useful, 00008 but WITHOUT ANY WARRANTY. 00009 00010 See the COPYING file for more details 00011 */ 00012 00013 00014 #include "win_container.h" 00015 00016 win_container::win_container() 00017 { 00018 move(0,0); 00019 00020 set_layout(NO_LAYOUT); 00021 00022 set_space_with_border(SPACE_WITH_BORDER); 00023 00024 set_space_with_object(SPACE_WITH_OBJECT); 00025 00026 focus_object_ = NULL; 00027 00028 } 00029 00030 win_container::~win_container() 00031 { 00032 destroy(); 00033 } 00034 00035 void win_container::move(s_int16 tx, s_int16 ty) 00036 { 00037 win_base::move(tx,ty); 00038 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00039 (*i)->update_position(); 00040 } 00041 00042 void win_container::resize(u_int16 tl, u_int16 th) 00043 { 00044 win_base::resize(tl,th); 00045 00046 update_layout(); 00047 00048 } 00049 00050 void win_container::update_position() 00051 { 00052 win_base::update_position(); 00053 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00054 (*i)->update_position(); 00055 } 00056 00057 void win_container::add(win_base * w) 00058 { 00059 list_wb_.push_back(w); 00060 00061 w->set_container(this); 00062 00063 update_layout(); 00064 } 00065 00066 void win_container::remove(win_base * w) 00067 { 00068 list_wb_.remove(w); 00069 00070 w->set_container(NULL); 00071 00072 update_layout(); 00073 } 00074 00075 void win_container::remove_all() 00076 { 00077 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00078 { 00079 (*i)->set_container(NULL); 00080 list_wb_.erase(i); 00081 } 00082 } 00083 00084 void win_container::destroy() 00085 { 00086 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00087 delete *i; 00088 list_wb_.clear(); 00089 } 00090 00091 bool win_container::update() 00092 { 00093 if(win_base::update()) 00094 { 00095 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00096 { 00097 if(!(*i)->update()) 00098 { 00099 list_wb_.erase(i); 00100 delete *i--; 00101 } 00102 } 00103 return true; 00104 } 00105 return false; 00106 } 00107 00108 00109 bool win_container::input_update() 00110 { 00111 if(win_base::input_update()) 00112 { 00113 if(focus_object_) focus_object_->input_update(); 00114 return true; 00115 } 00116 return false; 00117 } 00118 00119 00120 void win_container::set_focus_object(win_base * f) 00121 { 00122 if(focus_object_) focus_object_->set_focus(false); 00123 if(f) f->set_focus(true); 00124 focus_object_ = f; 00125 } 00126 00127 void win_container::set_brightness(bool b) 00128 { 00129 win_base::set_brightness(b); 00130 00131 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00132 (*i)->set_brightness(b); 00133 } 00134 00135 void win_container::set_trans(bool b) 00136 { 00137 win_base::set_trans(b); 00138 00139 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00140 (*i)->set_trans(b); 00141 } 00142 00143 void win_container::set_visible_all(bool b) 00144 { 00145 set_visible(b); 00146 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00147 (*i)->set_visible(b); 00148 } 00149 00150 00151 00152 bool win_container::draw() 00153 { 00154 if(win_base::draw()) 00155 { 00156 assign_drawing_area(wb_father_); 00157 00158 win_background::draw(this); 00159 00160 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00161 (*i)->draw(); 00162 00163 win_border::draw(wb_father_); 00164 00165 detach_drawing_area(); 00166 00167 return true; 00168 } 00169 return false; 00170 } 00171 00172 00173 00174 void win_container::update_layout() 00175 { 00176 00177 u_int16 indice_h=space_with_border_; 00178 00179 switch(layout_) 00180 { 00181 case LIST_LAYOUT: 00182 00183 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00184 { 00185 (*i)->move((*i)->x(),indice_h); 00186 00187 indice_h+=(*i)->height()+space_with_object_; 00188 } 00189 00190 break; 00191 } 00192 } 00193 00194 /* 00195 #include <list> 00196 #include "types.h" 00197 #include "image.h" 00198 #include "win_types.h" 00199 #include "win_base.h" 00200 #include "win_border.h" 00201 #include "win_theme.h" 00202 #include "win_container.h" 00203 00204 00205 //constructor 00206 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) 00207 { 00208 //clear the list og object 00209 list_obj.clear(); 00210 00211 //set the space between border and object 00212 space_between_border_=WIN_SPACE_BETWEEN_BORDER; 00213 00214 //set space between object and another object 00215 space_between_object_=WIN_SPACE_BETWEEN_OBJECT; 00216 */ 00217 /* 00218 //set justify ----> WARNING MAYBE IN WIN_BASE ???? 00219 justify_=WIN_JUSTIFY_NO; 00220 00221 */ 00222 /* 00223 //set layout equals no 00224 layout_=WIN_LAYOUT_NO; 00225 } 00226 00227 00228 void win_container::set_space_between_object(u_int16 tmp) 00229 { 00230 //set the space between object and call update layout to redefine position of each element 00231 space_between_object_=tmp; 00232 update_layout(); 00233 } 00234 00235 void win_container::set_space_between_border(u_int16 tmp) 00236 { 00237 //set the space between border and object and call update layout to redefine position of each element 00238 space_between_border_=tmp; 00239 update_layout(); 00240 } 00241 00242 win_container::~win_container() 00243 { 00244 destroy(); 00245 } 00246 00247 void win_container::add(win_base * tmp) 00248 { 00249 //add the object 00250 list_obj.push_back(tmp); 00251 00252 //set the new object 00253 tmp->wb_father_=this; 00254 tmp->update_real_position(); 00255 00256 00257 tmp->update_align(); 00258 00259 //update layout 00260 update_layout(); 00261 //if the win_container is brightness set the new object in brightness mode 00262 if(draw_brightness_) tmp->set_draw_brightness(true); 00263 } 00264 00265 00266 void win_container::remove(win_base * tmp) 00267 { 00268 list<win_base *>::iterator i=list_obj.begin(); 00269 while(i!=list_obj.end() && tmp!=(*i)) i++; 00270 if(i!=list_obj.end()) 00271 { 00272 //list_obj.remove(tmp); 00273 tmp->wb_father_=NULL; 00274 list_obj.erase(i); 00275 update_layout(); 00276 } 00277 } 00278 00279 void win_container::remove_all() 00280 { 00281 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00282 (*i)->wb_father_=NULL; 00283 list_obj.clear(); 00284 } 00285 00286 void win_container::destroy() 00287 { 00288 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00289 delete *i; 00290 list_obj.clear(); 00291 } 00292 00293 void win_container::resize(u_int16 tl,u_int16 th) 00294 { 00295 win_base::resize(tl,th); 00296 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00297 (*i)->update_align(); 00298 } 00299 00300 bool win_container::update() 00301 { 00302 //call the win update ---> on update() 00303 if(win_base::update()) 00304 { 00305 //update all the element in the list 00306 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00307 { 00308 if(!(*i)->update()) 00309 { 00310 remove(*i); 00311 delete *i--; 00312 } 00313 } 00314 return true; 00315 } 00316 return false; 00317 } 00318 00319 00320 bool win_container::draw() 00321 { 00322 if(win_base::draw()) 00323 { 00324 assign_drawing_area(); //assign drawing area 00325 //draw the background 00326 draw_background(); 00327 //next draw all the element 00328 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00329 (*i)->draw(); 00330 //draw the border 00331 draw_border(); 00332 //detach the drawing area 00333 detach_drawing_area(); 00334 return true; 00335 } 00336 return false; 00337 } 00338 00339 00340 //set visible mode for all element in list 00341 void win_container::set_visible_all(bool b) 00342 { 00343 visible_=b; 00344 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00345 (*i)->set_visible(visible_); 00346 } 00347 00348 //set draw brightness for all element in the list 00349 void win_container::set_draw_brightness(bool b) 00350 { 00351 win_base::set_draw_brightness(b); 00352 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00353 (*i)->set_draw_brightness(b); 00354 } 00355 */ 00356 /* 00357 00358 //set justify an object in this container 00359 void win_container::set_justify(win_base * wb, u_int8 just) 00360 { 00361 switch(just) 00362 { 00363 case WIN_JUSTIFY_LEFT: 00364 wb->move(space_between_border_,wb->y()); 00365 break; 00366 case WIN_JUSTIFY_RIGHT: 00367 wb->move(length_-space_between_border_-wb->length(),wb->y()); 00368 break; 00369 case WIN_JUSTIFY_CENTER: 00370 if(length_>wb->length()) 00371 wb->move((length_-wb->length())>>1,wb->y()); 00372 break; 00373 } 00374 } 00375 00376 //justify all the element 00377 00378 */ 00379 00380 /* 00381 void win_container::set_align_all(u_int8 a) 00382 { 00383 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00384 (*i)->set_align(a); 00385 } 00386 00387 00388 00389 00390 //sezt the layout and update 00391 void win_container::set_layout(u_int8 lay) 00392 { 00393 layout_=lay; 00394 update_layout(); 00395 } 00396 00397 // 00398 void win_container::update_real_position() 00399 { 00400 win_base::update_real_position(); 00401 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00402 (*i)->update_real_position(); 00403 } 00404 00405 void win_container::move(s_int16 tx,s_int16 ty) 00406 { 00407 win_base::move(tx,ty); 00408 update_real_position(); 00409 } 00410 00411 00412 //just one layout actually but i whish add another --> grid layout 00413 void win_container::update_layout() 00414 { 00415 u_int16 old_h=0; 00416 u_int16 indice_h=space_between_border_; 00417 u_int16 indice_l=space_between_border_; 00418 switch(layout_) 00419 { 00420 case WIN_LAYOUT_LIST: 00421 //u_int16 indice=space_between_border_; 00422 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00423 { 00424 (*i)->move((*i)->x(),indice_h); 00425 indice_h+=(*i)->height()+space_between_object_; 00426 } 00427 break; 00428 00429 case WIN_LAYOUT_AUTO: 00430 00431 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00432 { 00433 00434 if(indice_l+(*i)->length()>length_) 00435 { 00436 indice_l=space_between_border_; 00437 indice_h+=old_h+space_between_object_; 00438 (*i)->move(indice_l,indice_h); 00439 } 00440 00441 (*i)->move(indice_l,indice_h); 00442 indice_l+=(*i)->length()+space_between_object_; 00443 old_h=(*i)->height(); 00444 } 00445 break; 00446 00447 00448 00449 00450 default: 00451 break; 00452 } 00453 } 00454 00455 00456 void win_container::set_focus(bool b) 00457 { 00458 for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++) 00459 (*i)->set_focus(b); 00460 focus_=b; 00461 } 00462 00463 00464 00465 00466 00467 00468 */ 00469 00470 00471 00472 00473 00474 00475 00476