Adonthell
0.4
|
00001 /* 00002 $Id: win_scroll.cc,v 1.5 2002/12/02 14:31:55 ksterker Exp $ 00003 00004 (C) Copyright 2000 Joel Vennin 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details 00013 */ 00014 00015 #include "win_scroll.h" 00016 00017 00018 win_scroll::win_scroll():win_scrollbar(this) 00019 { 00020 00021 cursor_y_=0; 00022 00023 max_amplitude_=0; 00024 00025 cur_amplitude_=0; 00026 00027 index_pad_=PAD_DEFAULT; 00028 00029 set_auto_scrollbar(false); 00030 00031 set_auto_refresh(false); 00032 00033 } 00034 00035 00036 bool win_scroll::down() 00037 { 00038 00039 if( max_amplitude_ == 0 ) return false; 00040 00041 if( cur_amplitude_ + index_pad_ > max_amplitude_ ) cur_amplitude_ = max_amplitude_; 00042 else cur_amplitude_ += index_pad_; 00043 00044 update_amplitude(); 00045 00046 on_down(); 00047 00048 return true; 00049 00050 } 00051 00052 00053 void win_scroll::resize(u_int16 tl,u_int16 th) 00054 { 00055 win_container::resize(tl,th); 00056 00057 find_amplitude(); 00058 00059 win_scrollbar::update_back(); 00060 00061 win_scrollbar::update_bar(); 00062 } 00063 00064 00065 bool win_scroll::up() 00066 { 00067 if( max_amplitude_==0 ) return false ; 00068 00069 if( cur_amplitude_-index_pad_ < 0) cur_amplitude_ = 0; 00070 else cur_amplitude_ -= index_pad_; 00071 00072 update_amplitude(); 00073 00074 on_up(); 00075 00076 return true; 00077 } 00078 00079 void win_scroll::set_pos (const u_int8 pos) 00080 { 00081 cur_amplitude_ = (max_amplitude_ * pos) / 255; 00082 if (max_amplitude_ != 0) update_amplitude (); 00083 } 00084 00085 void win_scroll::update_amplitude() 00086 { 00087 for(lwb::iterator i=list_wb_.begin() ; i!=list_wb_.end() ; i++) 00088 { 00089 (*i)->pad_y() = -cur_amplitude_ ; 00090 (*i)->update_position(); 00091 } 00092 00093 cursor_y_= ((height() - win_scrollbar::height_bar()) * cur_amplitude_) / max_amplitude_; 00094 } 00095 00096 00097 void win_scroll::set_space_between_border(u_int16 tmp) 00098 { 00099 00100 win_container::set_space_with_border(tmp); 00101 00102 find_amplitude(); 00103 00104 win_scrollbar::update_bar(); 00105 00106 } 00107 00108 00109 void win_scroll::set_space_between_object(u_int16 tmp) 00110 { 00111 win_container::set_space_with_object(tmp); 00112 00113 find_amplitude(); 00114 00115 win_scrollbar::update_bar(); 00116 } 00117 00118 00119 void win_scroll::add(win_base *wb) 00120 { 00121 win_container::add(wb); 00122 00123 find_amplitude(); 00124 00125 win_scrollbar::update_bar(); 00126 } 00127 00128 00129 void win_scroll::remove(win_base *wb) 00130 { 00131 win_container::remove(wb); 00132 00133 find_amplitude(); 00134 00135 win_scrollbar::update_bar(); 00136 } 00137 00138 00139 void win_scroll::remove_all() 00140 { 00141 win_container::remove_all(); 00142 00143 max_amplitude_=0; 00144 00145 cur_amplitude_=0; 00146 00147 win_scrollbar::update_bar(); 00148 } 00149 00150 00151 void win_scroll::destroy() 00152 { 00153 win_container::destroy(); 00154 00155 max_amplitude_=0; 00156 00157 cur_amplitude_=0; 00158 00159 win_scrollbar::update_bar(); 00160 } 00161 00162 00163 bool win_scroll::draw() 00164 { 00165 if(win_base::draw()) 00166 { 00167 assign_drawing_area(wb_father_); 00168 00169 win_background::draw(this); 00170 00171 for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++) 00172 (*i)->draw(); 00173 00174 win_scrollbar::draw(wb_father_); 00175 00176 win_border::draw(wb_father_); 00177 00178 detach_drawing_area(); 00179 00180 return true; 00181 } 00182 return false; 00183 } 00184 00185 00186 bool win_scroll::update() 00187 { 00188 if(win_container::update()) 00189 { 00190 if(auto_scrollbar_) 00191 { 00192 u_int16 old = amplitude(); 00193 find_amplitude(); 00194 if(old != amplitude()) 00195 { 00196 win_scrollbar::set_visible_scrollbar(amplitude()!=0); 00197 win_scrollbar::update_bar(); 00198 } 00199 } 00200 else if(auto_refresh_) 00201 { 00202 u_int16 old = amplitude(); find_amplitude(); 00203 if(old != amplitude()) 00204 win_scrollbar::update_bar(); 00205 } 00206 return true; 00207 } 00208 return false; 00209 } 00210 00211 00212 bool win_scroll::input_update() 00213 { 00214 if(win_container::input_update()) 00215 { 00216 if(focus_object_) return true; 00217 if(input::is_pushed(win_keys::KEY_UP)) up(); 00218 if(input::is_pushed(win_keys::KEY_DOWN)) down(); 00219 return true; 00220 } 00221 return false; 00222 } 00223 00224 00225 void win_scroll::find_amplitude() 00226 { 00227 //search the max y object to calcul the amplitude 00228 max_amplitude_ = cursor_y_ = cur_amplitude_ = 0; 00229 00230 // max_amplitude_ = 0; 00231 00232 for(lwb::iterator i=list_wb_.begin() ; i!=list_wb_.end() ; i++) 00233 if((*i)->y() + (*i)->height() > height() - space_with_border() && (*i)->y() + (*i)->height() - height() + space_with_border() > max_amplitude_ ) 00234 max_amplitude_ = (*i)->y() + (*i)->height() - height() + space_with_border(); 00235 } 00236