… | |
… | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | use Crossfire::Client; |
10 | use Crossfire::Client; |
11 | |
11 | |
12 | our $FOCUS; # the widget with current focus |
|
|
13 | |
|
|
14 | # class methods for events |
12 | # class methods for events |
15 | 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 } |
16 | 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 } |
17 | sub feed_sdl_button_down_event { } |
15 | sub feed_sdl_button_down_event { } |
18 | sub feed_sdl_button_up_event { } |
16 | sub feed_sdl_button_up_event { } |
19 | |
17 | |
20 | sub new { |
18 | sub new { |
21 | my $class = shift; |
19 | my $class = shift; |
… | |
… | |
46 | $self->{h} = $h; |
44 | $self->{h} = $h; |
47 | } |
45 | } |
48 | |
46 | |
49 | sub focus_in { |
47 | sub focus_in { |
50 | my ($widget) = @_; |
48 | my ($widget) = @_; |
51 | $FOCUS = $widget; |
49 | $::FOCUS = $widget; |
52 | } |
50 | } |
53 | |
51 | |
54 | sub focus_out { |
52 | sub focus_out { |
55 | my ($widget) = @_; |
53 | my ($widget) = @_; |
56 | } |
54 | } |
… | |
… | |
81 | my ($self) = @_; |
79 | my ($self) = @_; |
82 | |
80 | |
83 | glPushMatrix; |
81 | glPushMatrix; |
84 | glTranslate $self->{x}, $self->{y}, 0; |
82 | glTranslate $self->{x}, $self->{y}, 0; |
85 | $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 | } |
86 | glPopMatrix; |
94 | glPopMatrix; |
87 | } |
95 | } |
88 | |
96 | |
89 | sub _draw { |
97 | sub _draw { |
90 | my ($self) = @_; |
98 | my ($self) = @_; |
… | |
… | |
162 | |
170 | |
163 | @{$self->{children}} = |
171 | @{$self->{children}} = |
164 | sort { $a->{z} <=> $b->{z} } |
172 | sort { $a->{z} <=> $b->{z} } |
165 | @{$self->{children}}, $chld; |
173 | @{$self->{children}}, $chld; |
166 | |
174 | |
167 | $self->size_allocate ($self->{w}, $self->{h}); |
175 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
176 | if $self->{w}; #TODO: check for "realised state" |
168 | } |
177 | } |
169 | |
178 | |
170 | sub remove { |
179 | sub remove { |
171 | my ($self, $widget) = @_; |
180 | my ($self, $widget) = @_; |
172 | |
181 | |
… | |
… | |
176 | } |
185 | } |
177 | |
186 | |
178 | sub find_widget { |
187 | sub find_widget { |
179 | my ($self, $x, $y) = @_; |
188 | my ($self, $x, $y) = @_; |
180 | |
189 | |
|
|
190 | $x -= $self->{x}; |
|
|
191 | $y -= $self->{y}; |
|
|
192 | |
181 | my $res; |
193 | my $res; |
182 | |
194 | |
183 | for (@{ $self->{children} }) { |
195 | for (reverse @{ $self->{children} }) { |
184 | $res = $_->find_widget ($x, $y) |
196 | $res = $_->find_widget ($x, $y) |
185 | and return $res; |
197 | and return $res; |
186 | } |
198 | } |
187 | |
199 | |
188 | () |
200 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
189 | } |
|
|
190 | |
|
|
191 | sub size_request { |
|
|
192 | my ($self) = @_; |
|
|
193 | |
|
|
194 | my ($hs, $ws) = (0, 0); |
|
|
195 | for (@{$self->{children} || []}) { |
|
|
196 | my ($w, $h) = $_->size_request; |
|
|
197 | $hs += $h; |
|
|
198 | if ($ws < $w) { $ws = $w } |
|
|
199 | } |
|
|
200 | |
|
|
201 | return ($ws, $hs); |
|
|
202 | } |
201 | } |
203 | |
202 | |
204 | sub _draw { |
203 | sub _draw { |
205 | my ($self) = @_; |
204 | my ($self) = @_; |
206 | |
205 | |
… | |
… | |
395 | $w -= $tex[2]->{width}; |
394 | $w -= $tex[2]->{width}; |
396 | $w -= $tex[3]->{width}; |
395 | $w -= $tex[3]->{width}; |
397 | |
396 | |
398 | $h = $h < 0 ? 0 : $h; |
397 | $h = $h < 0 ? 0 : $h; |
399 | $w = $w < 0 ? 0 : $w; |
398 | $w = $w < 0 ? 0 : $w; |
400 | warn "CHILD:$w $h\n"; |
399 | |
401 | $self->child->size_allocate ($w, $h); |
400 | $self->child->size_allocate ($w, $h); |
402 | $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
401 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
403 | } |
402 | } |
404 | |
403 | |
405 | sub _draw { |
404 | sub _draw { |
406 | my ($self) = @_; |
405 | my ($self) = @_; |
407 | |
406 | |
408 | my ($w, $h) = ($self->w, $self->h); |
407 | my ($w, $h) = ($self->{w}, $self->{h}); |
409 | my ($cw, $ch) = ($self->child->w, $self->child->h); |
408 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
410 | |
409 | |
411 | glEnable GL_BLEND; |
410 | glEnable GL_BLEND; |
412 | glEnable GL_TEXTURE_2D; |
411 | glEnable GL_TEXTURE_2D; |
413 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
412 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
413 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
… | |
… | |
568 | package Crossfire::Client::Widget::VBox; |
567 | package Crossfire::Client::Widget::VBox; |
569 | |
568 | |
570 | our @ISA = Crossfire::Client::Widget::Container::; |
569 | our @ISA = Crossfire::Client::Widget::Container::; |
571 | |
570 | |
572 | 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 | } |
573 | |
583 | |
574 | sub size_allocate { |
584 | sub size_allocate { |
575 | my ($self, $w, $h) = @_; |
585 | my ($self, $w, $h) = @_; |
576 | |
586 | |
577 | $self->w ($w); |
587 | $self->w ($w); |
… | |
… | |
607 | } else { |
617 | } else { |
608 | my ($cw, $h) = $_->size_request; |
618 | my ($cw, $h) = $_->size_request; |
609 | $_->size_allocate ($w, $h); |
619 | $_->size_allocate ($w, $h); |
610 | $y += $h; |
620 | $y += $h; |
611 | } |
621 | } |
612 | } |
|
|
613 | } |
|
|
614 | |
|
|
615 | sub _draw { |
|
|
616 | my ($self) = @_; |
|
|
617 | |
|
|
618 | my ($x, $y); |
|
|
619 | for (@{$self->{children} || []}) { |
|
|
620 | $_->draw; |
|
|
621 | $y += $_->h; |
|
|
622 | } |
622 | } |
623 | } |
623 | } |
624 | |
624 | |
625 | ############################################################################# |
625 | ############################################################################# |
626 | |
626 | |