Adonthell  0.4
win_object.h
1 /*
2  (C) Copyright 2000, 2001 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef _WIN_OBJECT_H_
21 #define _WIN_OBJECT_H_
22 
23 #include "win_container.h"
24 
25 template<class T>
26 class win_object : public win_base, public T
27 {
28  public:
29 
30  win_object();
31 
32 
33  ~win_object();
34 
35  bool draw();
36 
37  bool update();
38 
39 
40  bool input_update();
41 
42 
43  void set_brightness(bool b);
44 
45  void set_trans(bool b);
46 
47 
48  void pack();
49 
50 
51  void set_auto_refresh(bool b);
52 
53 
54  protected:
55 
56  void refresh();
57 
58  image * img_tmp_;
59  image * img_brightness_;
60 
61  bool auto_refresh_;
62 
63 };
64 
65 template<class T>
67 {
68  img_tmp_ = new image();
69  img_brightness_ = new image();
70 
71  set_auto_refresh(false);
72 }
73 
74 template<class T>
76 {
77  if( img_tmp_ !=NULL ) delete img_tmp_ ;
78  if( img_brightness_ != NULL) delete img_brightness_ ;
79 }
80 
81 
82 template<class T> bool
84 {
85  if(win_base::draw())
86  {
87  assign_drawing_area(wb_father_);
88 
89  win_background::draw(this);
90 
91  if( auto_refresh_ ) refresh();
92 
93  if(brightness_ || trans_)
94  {
95 
96  if( brightness_ ) img_brightness_->draw(win_base::real_x(), win_base::real_y(), this);
97  else img_tmp_->draw(win_base::real_x(), win_base::real_y(), this);
98  }
99  else T::draw(win_base::real_x(), win_base::real_y(), this);
100 
101 
102  win_border::draw(wb_father_);
103 
104  detach_drawing_area();
105 
106  return true;
107  }
108  return false;
109 }
110 
111 
112 template<class T> bool
114 {
115 
116  if(win_base::update())
117  {
118  T::update();
119  return true;
120  }
121  return false;
122 }
123 
124 
125 template<class T> bool
127 {
129  {
130 
131  if(input::has_been_pushed(win_keys::KEY_ACTIVATE_ENTRY)) on_activate_key();
132  T::input_update();
133 
134  return true;
135  }
136  return false;
137 }
138 
139 
140 template<class T> void
142 {
144  refresh();
145 }
146 
147 
148 
149 template<class T> void
151 {
153  refresh();
154 }
155 
156 template<class T> void
158 {
159  if(T::length() != win_base::length() || T::height() != win_base::height())
160  {
161  win_base::resize(T::length(), T::height());
162  img_tmp_->resize(T::length(), T::height());
163  }
164  refresh();
165 }
166 
167 
168 template<class T> void
170 {
171  auto_refresh_ = b;
172 }
173 
174 
175 
176 template<class T> void
178 {
179  //put the T drawable object in image
180  if(T::length() && T::height())
181  {
182  img_tmp_->fillrect(0,0,T::length(),T::height(),screen::trans_col());
183 
184  T::draw(0,0,NULL,img_tmp_);
185 
186  if(brightness_)
187  {
188  img_brightness_->brightness(*img_tmp_,WIN_BRIGHTNESS_LEVEL);
189  img_brightness_->set_mask(true);
190  }
191 
192  if(trans_) {img_tmp_->set_alpha(130);img_brightness_->set_alpha(130);}
193  else {img_tmp_->set_alpha(255);img_brightness_->set_alpha(255);}
194  }
195 }
196 
197 #endif
win_base::draw
virtual bool draw()
Draw process.
Definition: win_base.cc:111
win_base
Common properties for each win_base's object.
Definition: win_base.h:51
win_object::set_trans
void set_trans(bool b)
Set the transluency parameter.
Definition: win_object.h:150
win_object::set_brightness
void set_brightness(bool b)
Set the transluency parameter.
Definition: win_object.h:141
win_object::update
bool update()
Update process.
Definition: win_object.h:113
win_object::draw
bool draw()
Draw process.
Definition: win_object.h:83
drawing_area::height
u_int16 height() const
Returns the height of the drawing_area.
Definition: drawing_area.h:101
win_base::input_update
virtual bool input_update()
Input Update process .
Definition: win_base.cc:106
win_base::update
virtual bool update()
Update process.
Definition: win_base.cc:94
win_base::resize
virtual void resize(u_int16 tl, u_int16 th)
Rezise the win_*.
Definition: win_base.cc:85
win_base::real_y
s_int16 real_y() const
Return the vertical position of the win_*.
Definition: win_base.h:112
win_base::set_trans
virtual void set_trans(const bool b)
Set the transluency parameter.
Definition: win_base.h:184
win_base::set_brightness
virtual void set_brightness(const bool b)
Set the transluency parameter.
Definition: win_base.h:198
screen::trans_col
static u_int32 trans_col()
Returns the translucent color in screen's depth format.
Definition: screen.h:110
image
Image manipulation class.
Definition: image.h:45
win_base::real_x
s_int16 real_x() const
Return the horizontal position of the win_*.
Definition: win_base.h:104
win_object
Definition: win_object.h:26
input::has_been_pushed
static bool has_been_pushed(SDL_Keycode key)
Returns whether a key has been pushed since last function call, false otherwise.
Definition: input.cc:119
win_object::input_update
bool input_update()
Input Update process .
Definition: win_object.h:126
drawing_area::length
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:93