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