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