Adonthell  0.4
win_border.cc
1 /*
2  (C) Copyright 2000 Joel Vennin
3  Part of the Adonthell Project http://adonthell.linuxgames.com
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License.
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY.
9 
10  See the COPYING file for more details
11 */
12 
13 #include "win_theme.h"
14 #include "win_border.h"
15 
16 
17 win_border::win_border()
18 {
19  wb_=NULL;
20 
21  init();
22 
23  set_trans_border(false);
24 
25  set_visible_border( false );
26 
27  set_brightness_border( false );
28 
29 }
30 
31 
32 win_border::win_border(win_base *wb)
33 {
34  wb_=wb;
35 
36  init();
37 
38  set_trans_border(false);
39 
40  set_visible_border( false );
41 
42  set_brightness_border( false );
43 }
44 
45 win_border::win_border(char * rep,const char * size)
46 {
47  wb_=NULL;
48 
49  init();
50 
51  set_visible_border( false );
52 
53  set_trans_border(false);
54 
55  set_brightness_border( false );
56 
57  win_border::load(rep,size);
58 
59  refresh();
60 }
61 
62 
63 win_border::win_border(win_border & wb)
64 {
65  wb_=NULL;
66 
67  init();
68 
69  set_visible_border( false );
70 
71  set_trans_border(false);
72 
73  set_brightness_border( false );
74 
75  *this=wb;
76 
77  refresh();
78 }
79 
80 win_border::~win_border()
81 {
82  destroy();
83 }
84 
85 
86 void win_border::set_border(win_border & wb)
87 {
88  *this=wb;
89 
90  refresh();
91 }
92 
93 
94 void win_border::set_border(win_theme & wt, u_int8 size)
95 {
96  switch(size)
97  {
98  case NORMAL:
99  *this=*(wt.normal);
100  break;
101 
102  case MINI:
103  *this=*(wt.mini);
104  break;
105  }
106  refresh();
107 }
108 
109 
110 void win_border::init()
111 {
112  h_border_template_=NULL;
113  v_border_template_=NULL;
114  for(u_int8 i=0;i<NB_BORDER_IMAGE;i++)
115  border_[i]=border_brightness_[i]=NULL;
116 }
117 
118 win_border & win_border::operator=(win_border & wb)
119 {
120 
121  destroy();
122  h_border_template_=new image();
123  *h_border_template_=*(wb.h_border_template_);
124  v_border_template_=new image();
125  *v_border_template_=*(wb.v_border_template_);
126 
127  for(u_int8 i=0;i<NB_BORDER_IMAGE-2;i++)
128  {
129  border_[i]=new image();
130  border_brightness_[i]=new image();
131  *(border_[i])=*(wb.border_[i]);
132  *(border_brightness_[i])=*(wb.border_brightness_[i]);
133  border_[i]->set_mask(true);
134  border_brightness_[i]->set_mask(true);
135  }
136 
137  for(u_int8 i=NB_BORDER_IMAGE-2;i<NB_BORDER_IMAGE;i++)
138  {
139  border_[i]=new image();
140  border_brightness_[i]=new image();
141  border_[i]->set_mask(true);
142  border_brightness_[i]->set_mask(true);
143  }
144  update();
145  return *this;
146 }
147 
148 void win_border::destroy()
149 {
150  if(h_border_template_) delete h_border_template_;
151  if(v_border_template_) delete v_border_template_;
152 
153  for(u_int8 i = 0; i< NB_BORDER_IMAGE; i++)
154  {delete border_[i];delete border_brightness_[i];}
155 
156  init();
157 }
158 
159 void win_border::load(char * rep,const char *size)
160 {
161  destroy();
162 
163  char path[255];char tmp[255];
164  strcpy(path,WIN_DIRECTORY);
165  strcat(path,WIN_BORDER_DIRECTORY);
166  strcat(path,rep);
167  strcat(path,size);
168 
169  h_border_template_=new image();
170  strcpy(tmp,path);
171  strcat(tmp,WIN_H_BORDER_TEMPLATE_FILE);
172  h_border_template_->load_pnm(tmp);//new
173 
174 
175  v_border_template_=new image();
176  strcpy(tmp,path);
177  strcat(tmp,WIN_V_BORDER_TEMPLATE_FILE);
178  v_border_template_->load_pnm(tmp);//new
179 
180 
181  border_[0]=new image();
182  strcpy(tmp,path);
183  strcat(tmp,WIN_CORNER_TOP_LEFT_FILE);
184  border_[0]->load_pnm(tmp);
185  border_brightness_[0]=new image();
186  border_brightness_[0]->brightness(*(border_[0]),WIN_BRIGHTNESS_LEVEL);
187  border_[0]->set_mask(true);
188  border_brightness_[0]->set_mask(true);
189 
190  border_[1]=new image();
191  strcpy(tmp,path);
192  strcat(tmp,WIN_CORNER_TOP_RIGHT_FILE);
193  border_[1]->load_pnm(tmp);
194  border_brightness_[1]=new image();
195  border_brightness_[1]->brightness(*(border_[1]),WIN_BRIGHTNESS_LEVEL);
196  border_[1]->set_mask(true);
197  border_brightness_[1]->set_mask(true);
198 
199 
200  border_[2]=new image();
201  strcpy(tmp,path);
202  strcat(tmp,WIN_CORNER_BOTTOM_LEFT_FILE);
203  border_[2]->load_pnm(tmp);
204  border_brightness_[2]=new image();
205  border_brightness_[2]->brightness(*(border_[2]),WIN_BRIGHTNESS_LEVEL);
206  border_[2]->set_mask(true);
207  border_brightness_[2]->set_mask(true);
208 
209 
210  border_[3]=new image();
211  strcpy(tmp,path);
212  strcat(tmp,WIN_CORNER_BOTTOM_RIGHT_FILE);
213  border_[3]->load_pnm(tmp);
214  border_brightness_[3]=new image();
215  border_brightness_[3]->brightness(*(border_[3]),WIN_BRIGHTNESS_LEVEL);
216  border_[3]->set_mask(true);
217  border_brightness_[3]->set_mask(true);
218 
219  for(u_int8 i=NB_BORDER_IMAGE-2;i<NB_BORDER_IMAGE;i++)
220  {
221  border_[i]=new image();
222  border_brightness_[i]=new image();
223  border_[i]->set_mask(true);
224  border_brightness_[i]->set_mask(true);
225  }
226 }
227 
228 
229 void win_border::update()
230 {
231  if(!h_border_template_ || !v_border_template_ || !wb_) return;
232 
233  border_[4]->resize(v_border_template_->length(),wb_->height());
234  border_[4]->tile(*v_border_template_);
235  border_brightness_[4]->brightness(*(border_[4]),WIN_BRIGHTNESS_LEVEL);
236 
237  border_[5]->resize(wb_->length(),h_border_template_->height());
238  border_[5]->tile(*h_border_template_);
239  border_brightness_[5]->brightness(*(border_[5]),WIN_BRIGHTNESS_LEVEL);
240 }
241 
242 u_int16 win_border::height_border()
243 {
244  if(h_border_template_) return h_border_template_->height();
245  return 0;
246 }
247 
248 u_int16 win_border::length_border()
249 {
250  if(v_border_template_) return v_border_template_->length();
251  return 0;
252 }
253 
254 
255 void win_border::set_trans_border(bool b)
256 {
257  if(!h_border_template_) return;
258  if(b)
259  for(u_int8 i=0; i<NB_BORDER_IMAGE;i++)
260  {
261  border_[i]->set_alpha(130);
262  border_brightness_[i]->set_alpha(130);
263  }
264  else
265  for(u_int8 i=0; i<NB_BORDER_IMAGE;i++)
266  {
267  border_[i]->set_alpha(255);
268  border_brightness_[i]->set_alpha(255);
269  }
270 }
271 
272 
273 void win_border::draw(drawing_area * da)
274 {
275  if(!h_border_template_ || !visible_border_ || !wb_) return;
276 
277  u_int8 xodd = (border_draw_[0]->length () % 2);
278  u_int8 yodd = (border_draw_[0]->length () % 2);
279 
280  border_draw_[5]->draw(wb_->real_x(), wb_->real_y() - height_border(),da);
281 
282  border_draw_[5]->draw(wb_->real_x(), wb_->real_y() + wb_->height(),da);
283 
284  border_draw_[4]->draw(wb_->real_x() - length_border() , wb_->real_y(),da);
285 
286  border_draw_[4]->draw(wb_->real_x() + wb_->length(), wb_->real_y(),da);
287 
288  border_draw_[0]->draw(wb_->real_x() - (border_draw_[0]->length()>>1) - (length_border()>>1) - xodd,
289  wb_->real_y() - (border_draw_[0]->height()>>1) - (height_border()>>1) - yodd, da);
290 
291  border_draw_[1]->draw(wb_->real_x() + wb_->length() - (border_draw_[0]->length()>>1) + (length_border()>>1),
292  wb_->real_y() - (border_draw_[0]->height()>>1) - (height_border()>>1) - yodd, da);
293 
294  border_draw_[2]->draw(wb_->real_x() - (border_draw_[0]->length()>>1) - (length_border()>>1) - xodd ,
295  wb_->real_y() + wb_->height() - (border_draw_[0]->height()>>1) + (height_border()>>1), da);
296 
297  border_draw_[3]->draw(wb_->real_x() + wb_->length() - (border_draw_[0]->length()>>1) + (length_border()>>1),
298  wb_->real_y() + wb_->height() - (border_draw_[0]->height()>>1) + (height_border()>>1), da);
299 }
300 
301 
302 void win_border::set_brightness_border(bool b)
303 {
304  brightness_=b;
305  refresh();
306 }
307 
308 
309 void win_border::refresh()
310 {
311  border_draw_ = (brightness_) ? border_brightness_ : border_;
312 }
313 
314 
315 
316 
317 
318 
319 
320 
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
u_int16 length() const
Returns the length of the drawable.
Definition: drawable.h:76
void resize(u_int16 l, u_int16 h)
Resize this image.
Definition: image.cc:73
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
s_int16 real_x() const
Return the horizontal position of the win_*.
Definition: win_base.h:100
Image manipulation class.
Definition: image.h:41
#define u_int8
8 bits long unsigned integer
Definition: types.h:29
void tile(const surface &src)
Tiles a surface.
Definition: image.h:299
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:89
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
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:50
void set_alpha(u_int8 a)
Sets the alpha value of the surface.
Definition: surface.cc:208
u_int16 height() const
Returns the height of the drawable.
Definition: drawable.h:87
A* pathfinding algorithm implementation class.
Definition: path.h:48
void brightness(const surface &src, u_int8 cont, bool proceed_mask=false)
Applies a "brightness" to a surface.
Definition: image.cc:352
s_int8 load_pnm(string fname)
Loads an image from a file name, in PNM format, without alpha and mask values.
Definition: image.cc:172
Common properties for each win_base's object.
Definition: win_base.h:47
void set_mask(bool m)
Sets the mask parameter of the surface.
Definition: surface.cc:198
bool update()
Update process.
Definition: win_select.cc:298