00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _WIN_OBJECT_H_
00017 #define _WIN_OBJECT_H_
00018
00019 #include "win_container.h"
00020
00021 template<class T>
00022 class win_object : public win_base, public T
00023 {
00024 public:
00025
00026 win_object();
00027
00028
00029 ~win_object();
00030
00031 bool draw();
00032
00033 bool update();
00034
00035
00036 bool input_update();
00037
00038
00039 void set_brightness(bool b);
00040
00041 void set_trans(bool b);
00042
00043
00044 void pack();
00045
00046
00047 void set_auto_refresh(bool b);
00048
00049
00050 protected:
00051
00052 void refresh();
00053
00054 image * img_tmp_;
00055 image * img_brightness_;
00056
00057 bool auto_refresh_;
00058
00059 };
00060
00061 template<class T>
00062 win_object<T>::win_object()
00063 {
00064 img_tmp_ = new image();
00065 img_tmp_->set_mask(true);
00066 img_tmp_->set_dbl_mode (false);
00067
00068 img_brightness_ = new image();
00069 img_brightness_->set_dbl_mode (false);
00070
00071 set_auto_refresh(false);
00072 }
00073
00074 template<class T>
00075 win_object<T>::~win_object()
00076 {
00077 if( img_tmp_ !=NULL ) delete img_tmp_ ;
00078 if( img_brightness_ != NULL) delete img_brightness_ ;
00079 }
00080
00081
00082 template<class T> bool
00083 win_object<T>::draw()
00084 {
00085 if(win_base::draw())
00086 {
00087 assign_drawing_area(wb_father_);
00088
00089 win_background::draw(this);
00090
00091 if( auto_refresh_ ) refresh();
00092
00093 if(brightness_ || trans_)
00094 {
00095
00096 if( brightness_ ) img_brightness_->draw(win_base::real_x(), win_base::real_y(), this);
00097 else img_tmp_->draw(win_base::real_x(), win_base::real_y(), this);
00098 }
00099 else T::draw(win_base::real_x(), win_base::real_y(), this);
00100
00101
00102 win_border::draw(wb_father_);
00103
00104 detach_drawing_area();
00105
00106 return true;
00107 }
00108 return false;
00109 }
00110
00111
00112 template<class T> bool
00113 win_object<T>:: update()
00114 {
00115
00116 if(win_base::update())
00117 {
00118 T::update();
00119 return true;
00120 }
00121 return false;
00122 }
00123
00124
00125 template<class T> bool
00126 win_object<T>::input_update()
00127 {
00128 if(win_base::input_update())
00129 {
00130
00131 if(input::has_been_pushed(win_keys::KEY_ACTIVATE_ENTRY)) on_activate_key();
00132 T::input_update();
00133
00134 return true;
00135 }
00136 return false;
00137 }
00138
00139
00140 template<class T> void
00141 win_object<T>::set_brightness(bool b)
00142 {
00143 win_base::set_brightness(b);
00144 refresh();
00145 }
00146
00147
00148
00149 template<class T> void
00150 win_object<T>::set_trans(bool b)
00151 {
00152 win_base::set_trans(b);
00153 refresh();
00154 }
00155
00156 template<class T> void
00157 win_object<T>::pack()
00158 {
00159 if(T::length() != win_base::length() || T::height() != win_base::height())
00160 {
00161 win_base::resize(T::length(), T::height());
00162 img_tmp_->resize(T::length(), T::height());
00163 }
00164 refresh();
00165 }
00166
00167
00168 template<class T> void
00169 win_object<T>::set_auto_refresh(bool b)
00170 {
00171 auto_refresh_ = b;
00172 }
00173
00174
00175
00176 template<class T> void
00177 win_object<T>::refresh()
00178 {
00179
00180 if(T::length() && T::height())
00181 {
00182 img_tmp_->lock ();
00183 img_tmp_->fillrect(0,0,T::length(),T::height(),screen::trans_col());
00184 img_tmp_->unlock ();
00185
00186 T::draw(0,0,NULL,img_tmp_);
00187
00188 if(brightness_)
00189 {
00190 img_brightness_->brightness(*img_tmp_,WIN_BRIGHTNESS_LEVEL);
00191 img_brightness_->set_mask(true);
00192 }
00193
00194 if(trans_) {img_tmp_->set_alpha(130);img_brightness_->set_alpha(130);}
00195 else {img_tmp_->set_alpha(255);img_brightness_->set_alpha(255);}
00196 }
00197 }
00198
00199 #endif