… | |
… | |
215 | package CFClient::Widget::Container; |
215 | package CFClient::Widget::Container; |
216 | |
216 | |
217 | our @ISA = CFClient::Widget::; |
217 | our @ISA = CFClient::Widget::; |
218 | |
218 | |
219 | sub new { |
219 | sub new { |
220 | my ($class, @widgets) = @_; |
220 | my ($class, %arg) = @_; |
|
|
221 | |
|
|
222 | my $children = delete $arg{children} || []; |
221 | |
223 | |
222 | my $self = $class->SUPER::new (children => []); |
224 | my $self = $class->SUPER::new (children => []); |
223 | $self->add ($_) for @widgets; |
225 | $self->add ($_) for @$children; |
224 | |
226 | |
225 | $self |
227 | $self |
226 | } |
228 | } |
227 | |
229 | |
228 | sub add { |
230 | sub add { |
… | |
… | |
296 | our @ISA = CFClient::Widget::Bin::; |
298 | our @ISA = CFClient::Widget::Bin::; |
297 | |
299 | |
298 | use SDL::OpenGL; |
300 | use SDL::OpenGL; |
299 | |
301 | |
300 | sub new { |
302 | sub new { |
301 | my ($class, $x, $y, $z, $w, $h) = @_; |
303 | my ($class, %arg) = @_; |
302 | |
304 | |
303 | my $self = $class->SUPER::new; |
305 | my $self = $class->SUPER::new (%arg); |
304 | |
|
|
305 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
|
|
306 | } |
306 | } |
307 | |
307 | |
308 | sub update { |
308 | sub update { |
309 | my ($self) = @_; |
309 | my ($self) = @_; |
310 | |
310 | |
|
|
311 | # we want to do this delayed... |
311 | $self->render_chld; |
312 | $self->render_chld; |
312 | $self->SUPER::update; |
313 | $self->SUPER::update; |
313 | } |
314 | } |
314 | |
315 | |
315 | sub render_chld { |
316 | sub render_chld { |
… | |
… | |
633 | our @ISA = CFClient::Widget::; |
634 | our @ISA = CFClient::Widget::; |
634 | |
635 | |
635 | use SDL::OpenGL; |
636 | use SDL::OpenGL; |
636 | |
637 | |
637 | sub new { |
638 | sub new { |
638 | my ($class, $x, $y, $z, $height, $text) = @_; |
639 | my ($class, %arg) = @_; |
639 | |
|
|
640 | $height ||= $::FONTSIZE; |
|
|
641 | |
640 | |
642 | # TODO: color, and make height, xyz etc. optional |
641 | # TODO: color, and make height, xyz etc. optional |
643 | my $self = $class->SUPER::new ( |
642 | my $self = $class->SUPER::new ( |
644 | x => $x, |
643 | color => [1, 1, 1], |
645 | y => $y, |
644 | height => $::FONTSIZE, |
646 | z => $z, |
645 | text => "", |
647 | height => $height, |
|
|
648 | layout => new CFClient::Layout, |
646 | layout => new CFClient::Layout, |
|
|
647 | %arg |
649 | ); |
648 | ); |
650 | |
649 | |
651 | $self->set_text ($text); |
650 | $self->set_text ($self->{text}); |
652 | |
651 | |
653 | $self |
652 | $self |
654 | } |
653 | } |
655 | |
654 | |
656 | sub set_text { |
655 | sub set_text { |
… | |
… | |
670 | |
669 | |
671 | sub size_request { |
670 | sub size_request { |
672 | my ($self) = @_; |
671 | my ($self) = @_; |
673 | |
672 | |
674 | $self->{layout}->set_width; |
673 | $self->{layout}->set_width; |
|
|
674 | $self->{layout}->set_height ($self->{height}); |
675 | $self->{layout}->size |
675 | $self->{layout}->size |
676 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
676 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
677 | # ( |
677 | # ( |
678 | # $self->{texture}{width}, |
678 | # $self->{texture}{width}, |
679 | # $self->{texture}{height}, |
679 | # $self->{texture}{height}, |
… | |
… | |
703 | glEnable GL_BLEND; |
703 | glEnable GL_BLEND; |
704 | glEnable GL_TEXTURE_2D; |
704 | glEnable GL_TEXTURE_2D; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
707 | |
707 | |
708 | glColor 1, 0, 0, 1; # TODO color |
708 | glColor @{$self->{color}}; |
709 | |
709 | |
710 | $tex->draw_quad (0, 0); |
710 | $tex->draw_quad (0, 0); |
711 | |
711 | |
712 | glDisable GL_BLEND; |
712 | glDisable GL_BLEND; |
713 | glDisable GL_TEXTURE_2D; |
713 | glDisable GL_TEXTURE_2D; |
… | |
… | |
782 | use SDL; |
782 | use SDL; |
783 | use SDL::OpenGL; |
783 | use SDL::OpenGL; |
784 | use SDL::OpenGL::Constants; |
784 | use SDL::OpenGL::Constants; |
785 | |
785 | |
786 | our @ISA = CFClient::Widget::; |
786 | our @ISA = CFClient::Widget::; |
|
|
787 | |
|
|
788 | sub new { |
|
|
789 | my $class = shift; |
|
|
790 | |
|
|
791 | $class->SUPER::new (z => -1, @_) |
|
|
792 | } |
787 | |
793 | |
788 | sub key_down { |
794 | sub key_down { |
789 | print "MAPKEYDOWN\n"; |
795 | print "MAPKEYDOWN\n"; |
790 | } |
796 | } |
791 | |
797 | |