Adonthell  0.4
win_object.h
1 /*
2  $Id: win_object.h,v 1.6 2004/10/25 06:55:01 ksterker Exp $
3 
4  (C) Copyright 2000, 2001 Joel Vennin
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details
13 */
14 
15 
16 #ifndef _WIN_OBJECT_H_
17 #define _WIN_OBJECT_H_
18 
19 #include "win_container.h"
20 
21 template<class T>
22 class win_object : public win_base, public T
23 {
24  public:
25 
26  win_object();
27 
28 
29  ~win_object();
30 
31  bool draw();
32 
33  bool update();
34 
35 
36  bool input_update();
37 
38 
39  void set_brightness(bool b);
40 
41  void set_trans(bool b);
42 
43 
44  void pack();
45 
46 
47  void set_auto_refresh(bool b);
48 
49 
50  protected:
51 
52  void refresh();
53 
54  image * img_tmp_;
55  image * img_brightness_;
56 
57  bool auto_refresh_;
58 
59 };
60 
61 template<class T>
63 {
64  img_tmp_ = new image();
65  img_tmp_->set_mask(true);
66  img_tmp_->set_dbl_mode (false);
67 
68  img_brightness_ = new image();
69  img_brightness_->set_dbl_mode (false);
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 
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_->lock ();
183  img_tmp_->fillrect(0,0,T::length(),T::height(),screen::trans_col());
184  img_tmp_->unlock ();
185 
186  T::draw(0,0,NULL,img_tmp_);
187 
188  if(brightness_)
189  {
190  img_brightness_->brightness(*img_tmp_,WIN_BRIGHTNESS_LEVEL);
191  img_brightness_->set_mask(true);
192  }
193 
194  if(trans_) {img_tmp_->set_alpha(130);img_brightness_->set_alpha(130);}
195  else {img_tmp_->set_alpha(255);img_brightness_->set_alpha(255);}
196  }
197 }
198 
199 #endif
u_int16 height() const
Returns the height of the drawing_area.
Definition: drawing_area.h:97
s_int16 real_y() const
Return the vertical position of the win_*.
Definition: win_base.h:108
bool update()
Update process.
Definition: win_object.h:113
void resize(u_int16 l, u_int16 h)
Resize this image.
Definition: image.cc:73
void detach_drawing_area()
Detach (if needed) the drawing_area which was attached to this one.
Definition: drawing_area.h:146
s_int16 real_x() const
Return the horizontal position of the win_*.
Definition: win_base.h:100
bool draw()
Draw process.
Definition: win_object.h:83
void set_brightness(bool b)
Set the transluency parameter.
Definition: win_object.h:141
void fillrect(s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
Fills an area of the surface with a given color.
Definition: surface.cc:260
Image manipulation class.
Definition: image.h:41
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
static bool has_been_pushed(SDLKey key)
Returns whether a key has been pushed since last function call, false otherwise.
Definition: input.cc:76
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:89
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
void unlock() const
Unlock the surface after you&#39;ve worked on it&#39;s pixels with the get_pix () and put_pix () methods...
Definition: surface.cc:294
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the surface.
Definition: surface.h:138
void set_alpha(u_int8 a)
Sets the alpha value of the surface.
Definition: surface.cc:208
virtual void set_brightness(const bool b)
Set the transluency parameter.
Definition: win_base.h:194
bool input_update()
Input Update process .
Definition: win_object.h:126
void brightness(const surface &src, u_int8 cont, bool proceed_mask=false)
Applies a "brightness" to a surface.
Definition: image.cc:352
void set_trans(bool b)
Set the transluency parameter.
Definition: win_object.h:150
static u_int32 trans_col()
Returns the translucent color in screen&#39;s depth format.
Definition: screen.h:89
Common properties for each win_base&#39;s object.
Definition: win_base.h:47
void set_mask(bool m)
Sets the mask parameter of the surface.
Definition: surface.cc:198
virtual bool draw()
Draw process.
Definition: win_base.cc:107
void lock() const
Locks the surface.
Definition: surface.cc:287