Adonthell  0.4
win_background.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 #include <string.h>
13 #include "win_theme.h"
14 #include "win_background.h"
15 
16 win_background::win_background()
17 {
18  wb_=NULL;
19 
20  init();
21 
22  set_visible_background(false);
23 
24  set_brightness_background(false);
25 
26  set_trans_background(true);
27 }
28 
29 
30 win_background::win_background(win_base * wb)
31 {
32  wb_=wb;
33 
34  init();
35 
36  set_visible_background(false);
37 
38  set_brightness_background(false);
39 
40  set_trans_background(true);
41 }
42 
43 
44 win_background::win_background(char *rep)
45 {
46  wb_=NULL;
47 
48  init();
49 
50  set_visible_background(false);
51 
52  set_brightness_background(false);
53 
54  set_trans_background(true);
55 
56  win_background::load(rep);
57 
58  refresh();
59 }
60 
61 
62 win_background::win_background(win_background & wb)
63 {
64  wb_=NULL;
65 
66  init();
67 
68  set_visible_background(false);
69 
70  set_brightness_background(false);
71 
72  set_trans_background(true);
73 
74  *this=wb;
75 
76  refresh();
77 }
78 
79 
80 win_background::~win_background()
81 {
82  destroy();
83 }
84 
85 
86 void win_background::destroy()
87 {
88  if(background_template_) delete background_template_;
89  if(background_) delete background_;
90  if(background_brightness_) delete background_brightness_;
91  init();
92 }
93 
94 
95 void win_background::init()
96 {
97  background_template_=NULL;
98  background_=NULL;
99  background_brightness_=NULL;
100  background_draw_=NULL;
101 }
102 
103 
104 win_background & win_background::operator=(win_background & wb)
105 {
106  destroy();
107  background_template_=new image();
108  *background_template_=*(wb.background_template_);
109  background_=new image();
110  background_->set_mask(false);
111  background_brightness_= new image();
112  background_brightness_->set_mask(true);
113 
114  update();
115 
116  return *this;
117 
118 }
119 
120 
121 void win_background::set_background(win_background & wb)
122 {
123  *this=wb;
124  refresh();
125 }
126 
127 void win_background::set_background(win_theme & wt)
128 {
129  *this=*(wt.background);
130  refresh();
131 }
132 
133 void win_background::set_brightness_background(bool b)
134 {
135  brightness_=b;
136  refresh();
137 }
138 
139 void win_background::refresh()
140 {
141  background_draw_=(brightness_)? background_brightness_ : background_ ;
142 }
143 
144 void win_background::load(char *rep)
145 {
146  destroy();
147  char path[255];
148  strcpy(path,WIN_DIRECTORY);
149  strcat(path,WIN_BACKGROUND_DIRECTORY);
150  strcat(path,rep);
151  strcat(path,WIN_BACKGROUND_FILE);
152  background_template_=new image();
153  background_template_->load_pnm(path);//new
154 
155  background_=new image();
156  background_->set_mask(true);
157 
158  background_brightness_=new image();
159  background_brightness_->set_mask(true);
160 }
161 
162 
163 void win_background::update()
164 {
165  if(!background_template_) return ;
166 
167  background_->resize(wb_->length(),wb_->height());
168  background_->tile(*background_template_);
169  background_brightness_->brightness(*background_,WIN_BRIGHTNESS_LEVEL);
170 }
171 
172 
173 void win_background::draw(drawing_area * da)
174 {
175  if(!visible_ || !background_draw_ || !wb_) return;
176  background_draw_->draw(wb_->real_x(),wb_->real_y(),da);
177 }
178 
179 
180 void win_background::set_trans_background(bool b)
181 {
182  if(!background_template_) return;
183  if(b)
184  {
185  background_->set_alpha(130);
186  background_brightness_->set_alpha(130);
187  }
188  else
189  {
190  background_->set_alpha(255);
191  background_brightness_->set_alpha(255);
192  }
193 }
194 
195 
196 
197 
198 
199 
200 
201 
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
void resize(u_int16 l, u_int16 h)
Resize this image.
Definition: image.cc:73
s_int16 real_x() const
Return the horizontal position of the win_*.
Definition: win_base.h:100
Image manipulation class.
Definition: image.h:41
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
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&#39;s object.
Definition: win_base.h:47
void set_mask(bool m)
Sets the mask parameter of the surface.
Definition: surface.cc:198