… | |
… | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | our $FOCUS; # the widget with current focus |
10 | use Crossfire::Client; |
11 | |
11 | |
12 | # class methods for events |
12 | # class methods for events |
13 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
13 | sub feed_sdl_key_down_event { $::FOCUS->key_down ($_[0]) if $::FOCUS } |
14 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
14 | sub feed_sdl_key_up_event { $::FOCUS->key_up ($_[0]) if $::FOCUS } |
15 | sub feed_sdl_button_down_event { } |
15 | sub feed_sdl_button_down_event { } |
16 | sub feed_sdl_button_up_event { } |
16 | sub feed_sdl_button_up_event { } |
17 | |
17 | |
18 | sub new { |
18 | sub new { |
19 | my $class = shift; |
19 | my $class = shift; |
… | |
… | |
37 | Carp::confess "size_request is abtract"; |
37 | Carp::confess "size_request is abtract"; |
38 | } |
38 | } |
39 | |
39 | |
40 | sub size_allocate { |
40 | sub size_allocate { |
41 | my ($self, $w, $h) = @_; |
41 | my ($self, $w, $h) = @_; |
|
|
42 | |
42 | $self->w ($w); |
43 | $self->{w} = $w; |
43 | $self->h ($h); |
44 | $self->{h} = $h; |
44 | } |
45 | } |
45 | |
46 | |
46 | sub focus_in { |
47 | sub focus_in { |
47 | my ($widget) = @_; |
48 | my ($widget) = @_; |
48 | $FOCUS = $widget; |
49 | $::FOCUS = $widget; |
49 | } |
50 | } |
50 | |
51 | |
51 | sub focus_out { |
52 | sub focus_out { |
52 | my ($widget) = @_; |
53 | my ($widget) = @_; |
53 | } |
54 | } |
… | |
… | |
78 | my ($self) = @_; |
79 | my ($self) = @_; |
79 | |
80 | |
80 | glPushMatrix; |
81 | glPushMatrix; |
81 | glTranslate $self->{x}, $self->{y}, 0; |
82 | glTranslate $self->{x}, $self->{y}, 0; |
82 | $self->_draw; |
83 | $self->_draw; |
|
|
84 | if ($self == $::HOVER) { |
|
|
85 | glColor 1, 1, 1, 1; |
|
|
86 | glBegin GL_LINES; |
|
|
87 | glVertex 0, 0; |
|
|
88 | glVertex $self->{w} - 1, 0; |
|
|
89 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
90 | glVertex 0, $self->{h} - 1; |
|
|
91 | glVertex 0, 0; |
|
|
92 | glEnd; |
|
|
93 | } |
83 | glPopMatrix; |
94 | glPopMatrix; |
84 | } |
95 | } |
85 | |
96 | |
86 | sub _draw { |
97 | sub _draw { |
87 | my ($self) = @_; |
98 | my ($self) = @_; |
… | |
… | |
134 | my ($self) = @_; |
145 | my ($self) = @_; |
135 | |
146 | |
136 | #$self->deactivate; |
147 | #$self->deactivate; |
137 | } |
148 | } |
138 | |
149 | |
|
|
150 | ############################################################################# |
|
|
151 | |
139 | package Crossfire::Client::Widget::Container; |
152 | package Crossfire::Client::Widget::Container; |
140 | |
153 | |
141 | our @ISA = Crossfire::Client::Widget::; |
154 | our @ISA = Crossfire::Client::Widget::; |
142 | |
155 | |
143 | sub new { |
156 | sub new { |
… | |
… | |
157 | |
170 | |
158 | @{$self->{children}} = |
171 | @{$self->{children}} = |
159 | sort { $a->{z} <=> $b->{z} } |
172 | sort { $a->{z} <=> $b->{z} } |
160 | @{$self->{children}}, $chld; |
173 | @{$self->{children}}, $chld; |
161 | |
174 | |
162 | $self->size_allocate ($self->{w}, $self->{h}); |
175 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
176 | if $self->{w}; #TODO: check for "realised state" |
163 | } |
177 | } |
164 | |
178 | |
165 | sub remove { |
179 | sub remove { |
166 | my ($self, $widget) = @_; |
180 | my ($self, $widget) = @_; |
167 | |
181 | |
… | |
… | |
171 | } |
185 | } |
172 | |
186 | |
173 | sub find_widget { |
187 | sub find_widget { |
174 | my ($self, $x, $y) = @_; |
188 | my ($self, $x, $y) = @_; |
175 | |
189 | |
|
|
190 | $x -= $self->{x}; |
|
|
191 | $y -= $self->{y}; |
|
|
192 | |
176 | my $res; |
193 | my $res; |
177 | |
194 | |
178 | for (@{ $self->{children} }) { |
195 | for (reverse @{ $self->{children} }) { |
179 | $res = $_->find_widget ($x, $y) |
196 | $res = $_->find_widget ($x, $y) |
180 | and return $res; |
197 | and return $res; |
181 | } |
198 | } |
182 | |
199 | |
183 | () |
200 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
184 | } |
|
|
185 | |
|
|
186 | sub size_request { |
|
|
187 | my ($self) = @_; |
|
|
188 | |
|
|
189 | my ($hs, $ws) = (0, 0); |
|
|
190 | for (@{$self->{children} || []}) { |
|
|
191 | my ($w, $h) = $_->size_request; |
|
|
192 | $hs += $h; |
|
|
193 | if ($ws < $w) { $ws = $w } |
|
|
194 | } |
|
|
195 | |
|
|
196 | return ($ws, $hs); |
|
|
197 | } |
201 | } |
198 | |
202 | |
199 | sub _draw { |
203 | sub _draw { |
200 | my ($self) = @_; |
204 | my ($self) = @_; |
201 | |
205 | |
202 | $_->draw for @{$self->{children}}; |
206 | $_->draw for @{$self->{children}}; |
203 | } |
207 | } |
204 | |
208 | |
|
|
209 | ############################################################################# |
|
|
210 | |
205 | package Crossfire::Client::Widget::Bin; |
211 | package Crossfire::Client::Widget::Bin; |
206 | |
212 | |
207 | our @ISA = Crossfire::Client::Widget::Container::; |
213 | our @ISA = Crossfire::Client::Widget::Container::; |
208 | |
214 | |
209 | sub get { $_[0]->{children}[0] } |
215 | sub child { $_[0]->{children}[0] } |
210 | |
216 | |
211 | sub size_request { |
217 | sub size_request { |
212 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
218 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
213 | } |
219 | } |
214 | |
220 | |
215 | sub size_allocate { |
221 | sub size_allocate { |
216 | my ($self, $w, $h) = @_; |
222 | my ($self, $w, $h) = @_; |
|
|
223 | |
217 | $self->SUPER::size_allocate ($w, $h); |
224 | $self->SUPER::size_allocate ($w, $h); |
218 | $self->{children}[0]->size_allocate ($w, $h) |
225 | $self->{children}[0]->size_allocate ($w, $h) |
219 | if $self->{children}[0] |
226 | if $self->{children}[0] |
220 | } |
227 | } |
221 | |
228 | |
|
|
229 | ############################################################################# |
|
|
230 | |
222 | package Crossfire::Client::Widget::Toplevel; |
231 | package Crossfire::Client::Widget::Toplevel; |
223 | |
232 | |
224 | our @ISA = Crossfire::Client::Widget::Container::; |
233 | our @ISA = Crossfire::Client::Widget::Container::; |
225 | |
234 | |
226 | sub update { |
235 | sub update { |
227 | my ($self) = @_; |
236 | my ($self) = @_; |
228 | |
237 | |
229 | ::refresh (); |
238 | ::refresh (); |
230 | } |
239 | } |
231 | |
240 | |
|
|
241 | sub add { |
|
|
242 | my ($self, $widget) = @_; |
|
|
243 | |
|
|
244 | $self->SUPER::add ($widget); |
|
|
245 | |
|
|
246 | $widget->size_allocate ($widget->size_request); |
|
|
247 | } |
|
|
248 | |
|
|
249 | ############################################################################# |
|
|
250 | |
232 | package Crossfire::Client::Widget::Window; |
251 | package Crossfire::Client::Widget::Window; |
233 | |
252 | |
234 | our @ISA = Crossfire::Client::Widget::Bin::; |
253 | our @ISA = Crossfire::Client::Widget::Bin::; |
235 | |
254 | |
236 | use SDL::OpenGL; |
255 | use SDL::OpenGL; |
237 | |
256 | |
238 | sub add { |
257 | sub new { |
239 | my ($self, $chld) = @_; |
258 | my ($class, $x, $y, $z, $w, $h) = @_; |
240 | warn "ADD $chld\n"; |
|
|
241 | $self->SUPER::add ($chld); |
|
|
242 | $chld->set_parent ($self); |
|
|
243 | } |
|
|
244 | |
259 | |
245 | sub remove { |
260 | my $self = $class->SUPER::new; |
246 | my ($self) = @_; |
261 | |
247 | # TODO FIXME: removing a child from a window will crash, see render_chld |
262 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
248 | # $self->update; |
|
|
249 | } |
263 | } |
250 | |
264 | |
251 | sub update { |
265 | sub update { |
252 | my ($self) = @_; |
266 | my ($self) = @_; |
|
|
267 | |
253 | $self->render_chld; |
268 | $self->render_chld; |
|
|
269 | $self->SUPER::update; |
254 | } |
270 | } |
255 | |
271 | |
256 | sub render_chld { |
272 | sub render_chld { |
257 | my ($self) = @_; |
273 | my ($self) = @_; |
258 | my $chld = $self->get; |
|
|
259 | my ($w, $h) = $self->size_request; |
|
|
260 | |
274 | |
261 | require Carp; |
|
|
262 | Carp::cluck "RENDERCHI $w $h"; |
|
|
263 | warn "RENDERCHI $w $h\n"; |
|
|
264 | $self->{texture} = |
275 | $self->{texture} = |
265 | Crossfire::Client::Texture->new_from_opengl ( |
276 | Crossfire::Client::Texture->new_from_opengl ( |
266 | $w, $h, sub { $chld->draw } |
277 | $self->{w}, $self->{h}, sub { $self->child->draw } |
267 | ); |
278 | ); |
268 | $self->{texture}->upload; |
|
|
269 | } |
|
|
270 | |
|
|
271 | sub size_request { |
|
|
272 | my ($self) = @_; |
|
|
273 | ($self->w, $self->h) |
|
|
274 | } |
279 | } |
275 | |
280 | |
276 | sub size_allocate { |
281 | sub size_allocate { |
277 | my ($self, $w, $h) = @_; |
282 | my ($self, $w, $h) = @_; |
278 | |
283 | |
279 | $self->w ($w); |
284 | $self->{w} = $w; |
280 | $self->h ($h); |
285 | $self->{h} = $h; |
|
|
286 | |
281 | $self->get->size_allocate ($w, $h); |
287 | $self->child->size_allocate ($w, $h); |
282 | |
288 | |
283 | $self->update; #TODO: Move this to the size_request event propably? |
289 | $self->render_chld; |
284 | } |
290 | } |
285 | |
291 | |
286 | sub _draw { |
292 | sub _draw { |
287 | my ($self) = @_; |
293 | my ($self) = @_; |
288 | |
294 | |
… | |
… | |
305 | |
311 | |
306 | glDisable GL_BLEND; |
312 | glDisable GL_BLEND; |
307 | glDisable GL_TEXTURE_2D; |
313 | glDisable GL_TEXTURE_2D; |
308 | } |
314 | } |
309 | |
315 | |
|
|
316 | ############################################################################# |
|
|
317 | |
310 | package Crossfire::Client::Widget::Frame; |
318 | package Crossfire::Client::Widget::Frame; |
311 | |
319 | |
312 | our @ISA = Crossfire::Client::Widget::Bin::; |
320 | our @ISA = Crossfire::Client::Widget::Bin::; |
313 | |
321 | |
314 | use SDL::OpenGL; |
322 | use SDL::OpenGL; |
315 | |
323 | |
316 | sub size_request { |
324 | sub size_request { |
317 | my ($self) = @_; |
325 | my ($self) = @_; |
318 | my $chld = $self->get |
326 | my $chld = $self->child |
319 | or return (0, 0); |
327 | or return (0, 0); |
320 | |
328 | |
321 | $chld->move (2, 2); |
329 | $chld->move (2, 2); |
322 | |
330 | |
323 | map { $_ + 4 } $chld->size_request; |
331 | map { $_ + 4 } $chld->size_request; |
324 | } |
332 | } |
325 | |
333 | |
326 | sub size_allocate { |
334 | sub size_allocate { |
327 | my ($self, $w, $h) = @_; |
335 | my ($self, $w, $h) = @_; |
328 | |
336 | |
329 | $self->w ($w); |
337 | $self->{w} = $w; |
330 | $self->h ($h); |
338 | $self->{h} = $h; |
331 | |
339 | |
332 | $self->get->size_allocate ($w - 4, $h - 4); |
340 | $self->child->size_allocate ($w - 4, $h - 4); |
333 | $self->get->move (2, 2); |
341 | $self->child->move (2, 2); |
334 | } |
342 | } |
335 | |
343 | |
336 | sub _draw { |
344 | sub _draw { |
337 | my ($self) = @_; |
345 | my ($self) = @_; |
338 | |
346 | |
339 | my $chld = $self->get; |
347 | my $chld = $self->child; |
340 | |
348 | |
341 | my ($w, $h) = $chld->size_request; |
349 | my ($w, $h) = $chld->size_request; |
342 | |
350 | |
343 | glBegin GL_QUADS; |
351 | glBegin GL_QUADS; |
344 | glColor 0, 0, 0; |
352 | glColor 0, 0, 0; |
… | |
… | |
349 | glEnd; |
357 | glEnd; |
350 | |
358 | |
351 | $chld->draw; |
359 | $chld->draw; |
352 | } |
360 | } |
353 | |
361 | |
|
|
362 | ############################################################################# |
|
|
363 | |
354 | package Crossfire::Client::Widget::FancyFrame; |
364 | package Crossfire::Client::Widget::FancyFrame; |
355 | |
365 | |
356 | our @ISA = Crossfire::Client::Widget::Frame::; |
366 | our @ISA = Crossfire::Client::Widget::Bin::; |
357 | |
367 | |
358 | use SDL::OpenGL; |
368 | use SDL::OpenGL; |
359 | |
369 | |
360 | sub new { |
370 | my @tex = |
361 | my ($self, $theme) = @_; |
|
|
362 | $self = $self->SUPER::new; |
|
|
363 | |
|
|
364 | $self->{txts} = [ |
|
|
365 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
371 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
366 | qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ |
372 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
367 | ]; |
|
|
368 | $self |
|
|
369 | } |
|
|
370 | |
373 | |
371 | sub size_request { |
374 | sub size_request { |
372 | my ($self) = @_; |
375 | my ($self) = @_; |
|
|
376 | |
373 | my ($w, $h) = $self->get->size_request; |
377 | my ($w, $h) = $self->SUPER::size_request; |
374 | |
378 | |
375 | $h += $self->{txts}->[1]->{height}; |
379 | $h += $tex[1]->{height}; |
376 | $h += $self->{txts}->[4]->{height}; |
380 | $h += $tex[4]->{height}; |
377 | $w += $self->{txts}->[2]->{width}; |
381 | $w += $tex[2]->{width}; |
378 | $w += $self->{txts}->[3]->{width}; |
382 | $w += $tex[3]->{width}; |
379 | |
383 | |
380 | ($w, $h) |
384 | ($w, $h) |
381 | } |
385 | } |
382 | |
386 | |
383 | sub size_allocate { |
387 | sub size_allocate { |
384 | my ($self, $w, $h) = @_; |
388 | my ($self, $w, $h) = @_; |
385 | |
389 | |
386 | $self->w ($w); |
390 | $self->SUPER::size_allocate ($w, $h); |
387 | $self->h ($h); |
391 | |
388 | $h -= $self->{txts}->[1]->{height}; |
392 | $h -= $tex[1]->{height}; |
389 | $h -= $self->{txts}->[4]->{height}; |
393 | $h -= $tex[4]->{height}; |
390 | $w -= $self->{txts}->[2]->{width}; |
394 | $w -= $tex[2]->{width}; |
391 | $w -= $self->{txts}->[3]->{width}; |
395 | $w -= $tex[3]->{width}; |
392 | |
396 | |
393 | $h = $h < 0 ? 0 : $h; |
397 | $h = $h < 0 ? 0 : $h; |
394 | $w = $w < 0 ? 0 : $w; |
398 | $w = $w < 0 ? 0 : $w; |
395 | warn "CHILD:$w $h\n"; |
399 | |
396 | $self->get->size_allocate ($w, $h); |
400 | $self->child->size_allocate ($w, $h); |
397 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
401 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
398 | } |
402 | } |
399 | |
403 | |
400 | sub _draw { |
404 | sub _draw { |
401 | my ($self) = @_; |
405 | my ($self) = @_; |
402 | |
406 | |
403 | my ($w, $h) = ($self->w, $self->h); |
407 | my ($w, $h) = ($self->{w}, $self->{h}); |
404 | my ($cw, $ch) = ($self->get->w, $self->get->h); |
408 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
405 | |
409 | |
406 | glEnable GL_BLEND; |
410 | glEnable GL_BLEND; |
407 | glEnable GL_TEXTURE_2D; |
411 | glEnable GL_TEXTURE_2D; |
408 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
412 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
409 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
413 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
410 | |
414 | |
411 | my $top = $self->{txts}->[1]; |
415 | my $top = $tex[1]; |
412 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
416 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
413 | |
417 | |
414 | glBegin GL_QUADS; |
418 | glBegin GL_QUADS; |
415 | glTexCoord 0, 0; glVertex 0 , 0; |
419 | glTexCoord 0, 0; glVertex 0 , 0; |
416 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
420 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
417 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
421 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
418 | glTexCoord 1, 0; glVertex $w , 0; |
422 | glTexCoord 1, 0; glVertex $w , 0; |
419 | glEnd; |
423 | glEnd; |
420 | |
424 | |
421 | my $left = $self->{txts}->[3]; |
425 | my $left = $tex[3]; |
422 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
426 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
423 | |
427 | |
424 | glBegin GL_QUADS; |
428 | glBegin GL_QUADS; |
425 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
429 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
426 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
430 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
427 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
431 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
428 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
432 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
429 | glEnd; |
433 | glEnd; |
430 | |
434 | |
431 | my $right = $self->{txts}->[2]; |
435 | my $right = $tex[2]; |
432 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
436 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
433 | |
437 | |
434 | glBegin GL_QUADS; |
438 | glBegin GL_QUADS; |
435 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
439 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
436 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
440 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
437 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
441 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
438 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
442 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
439 | glEnd; |
443 | glEnd; |
440 | |
444 | |
441 | my $bottom = $self->{txts}->[4]; |
445 | my $bottom = $tex[4]; |
442 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
446 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
443 | |
447 | |
444 | glBegin GL_QUADS; |
448 | glBegin GL_QUADS; |
445 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
449 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
446 | glTexCoord 0, 1; glVertex 0 , $h; |
450 | glTexCoord 0, 1; glVertex 0 , $h; |
447 | glTexCoord 1, 1; glVertex $w , $h; |
451 | glTexCoord 1, 1; glVertex $w , $h; |
448 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
452 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
449 | glEnd; |
453 | glEnd; |
450 | |
454 | |
451 | my $bg = $self->{txts}->[0]; |
455 | my $bg = $tex[0]; |
452 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
456 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
453 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
457 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
454 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
458 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
455 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
459 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
456 | |
460 | |
… | |
… | |
465 | glEnd; |
469 | glEnd; |
466 | |
470 | |
467 | glDisable GL_BLEND; |
471 | glDisable GL_BLEND; |
468 | glDisable GL_TEXTURE_2D; |
472 | glDisable GL_TEXTURE_2D; |
469 | |
473 | |
470 | $self->get->draw; |
474 | $self->child->draw; |
471 | |
475 | |
472 | } |
476 | } |
|
|
477 | |
|
|
478 | ############################################################################# |
473 | |
479 | |
474 | package Crossfire::Client::Widget::Table; |
480 | package Crossfire::Client::Widget::Table; |
475 | |
481 | |
476 | our @ISA = Crossfire::Client::Widget::Bin::; |
482 | our @ISA = Crossfire::Client::Widget::Bin::; |
477 | |
483 | |
… | |
… | |
554 | |
560 | |
555 | $y += $self->max_row_height ($yi); |
561 | $y += $self->max_row_height ($yi); |
556 | } |
562 | } |
557 | } |
563 | } |
558 | |
564 | |
|
|
565 | ############################################################################# |
|
|
566 | |
559 | package Crossfire::Client::Widget::VBox; |
567 | package Crossfire::Client::Widget::VBox; |
560 | |
568 | |
561 | our @ISA = Crossfire::Client::Widget::Container::; |
569 | our @ISA = Crossfire::Client::Widget::Container::; |
562 | |
570 | |
563 | use SDL::OpenGL; |
571 | use SDL::OpenGL; |
|
|
572 | |
|
|
573 | sub size_request { |
|
|
574 | my ($self) = @_; |
|
|
575 | |
|
|
576 | my @alloc = map [$_->size_request], @{$self->{children}}; |
|
|
577 | |
|
|
578 | ( |
|
|
579 | (List::Util::max map $_->[0], @alloc), |
|
|
580 | (List::Util::sum map $_->[1], @alloc), |
|
|
581 | ) |
|
|
582 | } |
564 | |
583 | |
565 | sub size_allocate { |
584 | sub size_allocate { |
566 | my ($self, $w, $h) = @_; |
585 | my ($self, $w, $h) = @_; |
567 | |
586 | |
568 | $self->w ($w); |
587 | $self->w ($w); |
… | |
… | |
601 | $y += $h; |
620 | $y += $h; |
602 | } |
621 | } |
603 | } |
622 | } |
604 | } |
623 | } |
605 | |
624 | |
606 | sub _draw { |
625 | ############################################################################# |
607 | my ($self) = @_; |
|
|
608 | |
|
|
609 | my ($x, $y); |
|
|
610 | for (@{$self->{children} || []}) { |
|
|
611 | $_->draw; |
|
|
612 | $y += $_->h; |
|
|
613 | } |
|
|
614 | } |
|
|
615 | |
626 | |
616 | package Crossfire::Client::Widget::Label; |
627 | package Crossfire::Client::Widget::Label; |
617 | |
628 | |
618 | our @ISA = Crossfire::Client::Widget::; |
629 | our @ISA = Crossfire::Client::Widget::; |
619 | |
630 | |
… | |
… | |
676 | |
687 | |
677 | glDisable GL_BLEND; |
688 | glDisable GL_BLEND; |
678 | glDisable GL_TEXTURE_2D; |
689 | glDisable GL_TEXTURE_2D; |
679 | } |
690 | } |
680 | |
691 | |
|
|
692 | ############################################################################# |
|
|
693 | |
681 | package Crossfire::Client::Widget::TextEntry; |
694 | package Crossfire::Client::Widget::TextEntry; |
682 | |
695 | |
683 | our @ISA = Crossfire::Client::Widget::Label::; |
696 | our @ISA = Crossfire::Client::Widget::Label::; |
684 | |
697 | |
685 | use SDL; |
698 | use SDL; |
… | |
… | |
702 | } elsif ($uni) { |
715 | } elsif ($uni) { |
703 | $text .= chr $uni; |
716 | $text .= chr $uni; |
704 | } |
717 | } |
705 | $self->set_text ($text); |
718 | $self->set_text ($text); |
706 | } |
719 | } |
|
|
720 | |
|
|
721 | ############################################################################# |
707 | |
722 | |
708 | package Crossfire::Client::Widget::MapWidget; |
723 | package Crossfire::Client::Widget::MapWidget; |
709 | |
724 | |
710 | use strict; |
725 | use strict; |
711 | |
726 | |
… | |
… | |
878 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
893 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
879 | $::CONN->send ("command run_stop"); |
894 | $::CONN->send ("command run_stop"); |
880 | } |
895 | } |
881 | } |
896 | } |
882 | |
897 | |
|
|
898 | ############################################################################# |
|
|
899 | |
883 | package Crossfire::Client::Widget::Animator; |
900 | package Crossfire::Client::Widget::Animator; |
884 | |
901 | |
885 | use SDL::OpenGL; |
902 | use SDL::OpenGL; |
886 | |
903 | |
887 | our @ISA = Crossfire::Client::Widget::Bin::; |
904 | our @ISA = Crossfire::Client::Widget::Bin::; |