39 |
if (menu) menu->invalidate_area(get_area()); |
if (menu) menu->invalidate_area(get_area()); |
40 |
} |
} |
41 |
|
|
42 |
//---------------------------------------- |
void |
43 |
// Button implementation |
Widget::invoke_listener() |
|
//---------------------------------------- |
|
|
void |
|
|
Button::draw(px::GC &gc, const px::Rect &r) |
|
44 |
{ |
{ |
45 |
char bordername[50]; |
if (listener) |
46 |
sprintf(bordername, "b%dx%d%s", get_w(), get_h(), |
listener->on_action(this); |
|
highlighted ? "h" : ""); |
|
|
px::Surface *s = enigma::GetImage(bordername); |
|
|
blit(gc, get_x(), get_y(), s); |
|
47 |
} |
} |
48 |
|
|
|
|
|
49 |
void Image::draw (px::GC &gc, const px::Rect &r) |
void Image::draw (px::GC &gc, const px::Rect &r) |
50 |
{ |
{ |
51 |
if (px::Surface *s = enigma::GetImage(imgname.c_str())) |
if (px::Surface *s = enigma::GetImage(imgname.c_str())) |
112 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
px::Rect Container::boundingbox() |
px::Rect |
116 |
|
Container::boundingbox() |
117 |
{ |
{ |
118 |
if (!m_widgets.empty()) { |
if (!m_widgets.empty()) { |
119 |
iterator i=begin(); |
iterator i=begin(); |
126 |
} |
} |
127 |
|
|
128 |
|
|
|
|
|
129 |
//---------------------------------------- |
//---------------------------------------- |
130 |
// TextButton implementation. |
// Button implementation |
131 |
//---------------------------------------- |
//---------------------------------------- |
|
px::Font *TextButton::menufont = 0; |
|
|
px::Font *TextButton::menufont_pressed = 0; |
|
|
|
|
|
TextButton::TextButton(const string &t, ActionListener *al) |
|
|
: text(t), pressed(false), listener(al) |
|
|
{ |
|
|
if (menufont == 0) { |
|
|
menufont = enigma::GetFont("menufont"); //menufont"); |
|
|
menufont_pressed = enigma::GetFont("menufontsel"); |
|
|
} |
|
|
} |
|
|
|
|
132 |
void |
void |
133 |
TextButton::set_text(const std::string &t) |
Button::draw(px::GC &gc, const px::Rect &r) |
134 |
{ |
{ |
135 |
text = t; |
char bordername[50]; |
136 |
redraw(); |
sprintf(bordername, "b%dx%d%s", get_w(), get_h(), |
137 |
|
highlighted ? "h" : ""); |
138 |
|
if (px::Surface *s = enigma::GetImage(bordername)) |
139 |
|
blit(gc, get_x(), get_y(), s); |
140 |
} |
} |
141 |
|
|
142 |
|
//---------------------------------------- |
143 |
|
// PushButton implementation |
144 |
|
//---------------------------------------- |
145 |
|
|
146 |
bool |
bool |
147 |
TextButton::on_event(const SDL_Event &e) |
PushButton::on_event(const SDL_Event &e) |
148 |
{ |
{ |
149 |
switch (e.type) { |
switch (e.type) { |
150 |
case SDL_MOUSEBUTTONDOWN: |
case SDL_MOUSEBUTTONDOWN: |
157 |
pressed = false; |
pressed = false; |
158 |
redraw(); |
redraw(); |
159 |
sound::PlaySound("menuok"); |
sound::PlaySound("menuok"); |
160 |
if (listener) |
invoke_listener(); |
|
listener->on_action(this); |
|
161 |
} |
} |
162 |
return true; |
return true; |
163 |
default: |
default: |
165 |
} |
} |
166 |
} |
} |
167 |
|
|
168 |
|
//---------------------------------------- |
169 |
|
// TextButton implementation. |
170 |
|
//---------------------------------------- |
171 |
|
px::Font *TextButton::menufont = 0; |
172 |
|
px::Font *TextButton::menufont_pressed = 0; |
173 |
|
|
174 |
|
TextButton::TextButton(const string &t, ActionListener *al) |
175 |
|
: text(t) |
176 |
|
{ |
177 |
|
if (menufont == 0) { |
178 |
|
menufont = enigma::GetFont("menufont"); //menufont"); |
179 |
|
menufont_pressed = enigma::GetFont("menufontsel"); |
180 |
|
} |
181 |
|
set_listener(al); |
182 |
|
} |
183 |
|
|
184 |
|
void |
185 |
|
TextButton::set_text(const std::string &t) |
186 |
|
{ |
187 |
|
text = t; |
188 |
|
redraw(); |
189 |
|
} |
190 |
|
|
191 |
void |
void |
192 |
TextButton::draw(px::GC &gc, const px::Rect &r) |
TextButton::draw(px::GC &gc, const px::Rect &r) |
193 |
{ |
{ |
194 |
Button::draw(gc,r); |
Button::draw(gc,r); |
195 |
Font *f = pressed ? menufont_pressed : menufont; |
Font *f = is_pressed() ? menufont_pressed : menufont; |
196 |
int h = f->get_height(); |
int h = f->get_height(); |
197 |
int w = f->get_width(text.c_str()); |
int w = f->get_width(text.c_str()); |
198 |
int x = get_x() + (get_w()-w)/2; |
int x = get_x() + (get_w()-w)/2; |
201 |
f->render (gc, x, y, text.c_str()); |
f->render (gc, x, y, text.c_str()); |
202 |
} |
} |
203 |
|
|
204 |
|
//---------------------------------------- |
205 |
|
// ImageButton implementation. |
206 |
|
//---------------------------------------- |
207 |
|
ImageButton::ImageButton(const std::string &unselected, |
208 |
|
const std::string &selected) |
209 |
|
: fname_sel(selected), |
210 |
|
fname_unsel(unselected) |
211 |
|
{} |
212 |
|
|
213 |
|
void |
214 |
|
ImageButton::draw(px::GC &gc, const px::Rect &r) |
215 |
|
{ |
216 |
|
Button::draw(gc, r); |
217 |
|
string &fname = is_pressed() ? fname_sel : fname_unsel; |
218 |
|
|
219 |
|
if (Surface *s = enigma::GetImage(fname.c_str())) { |
220 |
|
int w=s->width(); |
221 |
|
int h=s->height(); |
222 |
|
int x = get_x() + (get_w()-w)/2; |
223 |
|
int y = get_y() + (get_h()-h)/2; |
224 |
|
blit(gc, x, y, s); |
225 |
|
} |
226 |
|
} |
227 |
|
|
228 |
//---------------------------------------- |
//---------------------------------------- |
229 |
// Menu implementation. |
// Menu implementation. |