1 | package Crossfire::Client::Widget; |
1 | package CFClient::Widget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
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 | use Crossfire::Client; |
10 | use CFClient; |
11 | |
11 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
13 | |
14 | our $TOPLEVEL; |
14 | our $TOPLEVEL; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
… | |
… | |
210 | #$self->deactivate; |
210 | #$self->deactivate; |
211 | } |
211 | } |
212 | |
212 | |
213 | ############################################################################# |
213 | ############################################################################# |
214 | |
214 | |
215 | package Crossfire::Client::Widget::Container; |
215 | package CFClient::Widget::Container; |
216 | |
216 | |
217 | our @ISA = Crossfire::Client::Widget::; |
217 | our @ISA = CFClient::Widget::; |
218 | |
218 | |
219 | sub new { |
219 | sub new { |
220 | my ($class, @widgets) = @_; |
220 | my ($class, @widgets) = @_; |
221 | |
221 | |
222 | my $self = $class->SUPER::new (children => []); |
222 | my $self = $class->SUPER::new (children => []); |
… | |
… | |
269 | $_->draw for @{$self->{children}}; |
269 | $_->draw for @{$self->{children}}; |
270 | } |
270 | } |
271 | |
271 | |
272 | ############################################################################# |
272 | ############################################################################# |
273 | |
273 | |
274 | package Crossfire::Client::Widget::Bin; |
274 | package CFClient::Widget::Bin; |
275 | |
275 | |
276 | our @ISA = Crossfire::Client::Widget::Container::; |
276 | our @ISA = CFClient::Widget::Container::; |
277 | |
277 | |
278 | sub child { $_[0]->{children}[0] } |
278 | sub child { $_[0]->{children}[0] } |
279 | |
279 | |
280 | sub size_request { |
280 | sub size_request { |
281 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
281 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
… | |
… | |
289 | if $self->{children}[0] |
289 | if $self->{children}[0] |
290 | } |
290 | } |
291 | |
291 | |
292 | ############################################################################# |
292 | ############################################################################# |
293 | |
293 | |
294 | package Crossfire::Client::Widget::Window; |
294 | package CFClient::Widget::Window; |
295 | |
295 | |
296 | our @ISA = Crossfire::Client::Widget::Bin::; |
296 | our @ISA = CFClient::Widget::Bin::; |
297 | |
297 | |
298 | use SDL::OpenGL; |
298 | use SDL::OpenGL; |
299 | |
299 | |
300 | sub new { |
300 | sub new { |
301 | my ($class, $x, $y, $z, $w, $h) = @_; |
301 | my ($class, $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 { |
316 | my ($self) = @_; |
317 | my ($self) = @_; |
317 | |
318 | |
318 | $self->{texture} = |
319 | $self->{texture} = |
319 | Crossfire::Client::Texture->new_from_opengl ( |
320 | CFClient::Texture->new_from_opengl ( |
320 | $self->{w}, $self->{h}, sub { $self->child->draw } |
321 | $self->{w}, $self->{h}, sub { $self->child->draw } |
321 | ); |
322 | ); |
322 | } |
323 | } |
323 | |
324 | |
324 | sub size_allocate { |
325 | sub size_allocate { |
… | |
… | |
350 | glDisable GL_TEXTURE_2D; |
351 | glDisable GL_TEXTURE_2D; |
351 | } |
352 | } |
352 | |
353 | |
353 | ############################################################################# |
354 | ############################################################################# |
354 | |
355 | |
355 | package Crossfire::Client::Widget::Frame; |
356 | package CFClient::Widget::Frame; |
356 | |
357 | |
357 | our @ISA = Crossfire::Client::Widget::Bin::; |
358 | our @ISA = CFClient::Widget::Bin::; |
358 | |
359 | |
359 | use SDL::OpenGL; |
360 | use SDL::OpenGL; |
360 | |
361 | |
361 | sub size_request { |
362 | sub size_request { |
362 | my ($self) = @_; |
363 | my ($self) = @_; |
… | |
… | |
396 | $chld->draw; |
397 | $chld->draw; |
397 | } |
398 | } |
398 | |
399 | |
399 | ############################################################################# |
400 | ############################################################################# |
400 | |
401 | |
401 | package Crossfire::Client::Widget::FancyFrame; |
402 | package CFClient::Widget::FancyFrame; |
402 | |
403 | |
403 | our @ISA = Crossfire::Client::Widget::Bin::; |
404 | our @ISA = CFClient::Widget::Bin::; |
404 | |
405 | |
405 | use SDL::OpenGL; |
406 | use SDL::OpenGL; |
406 | |
407 | |
407 | my @tex = |
408 | my @tex = |
408 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
409 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
409 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
410 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
410 | |
411 | |
411 | sub size_request { |
412 | sub size_request { |
412 | my ($self) = @_; |
413 | my ($self) = @_; |
413 | |
414 | |
… | |
… | |
479 | |
480 | |
480 | } |
481 | } |
481 | |
482 | |
482 | ############################################################################# |
483 | ############################################################################# |
483 | |
484 | |
484 | package Crossfire::Client::Widget::Table; |
485 | package CFClient::Widget::Table; |
485 | |
486 | |
486 | our @ISA = Crossfire::Client::Widget::Bin::; |
487 | our @ISA = CFClient::Widget::Bin::; |
487 | |
488 | |
488 | use SDL::OpenGL; |
489 | use SDL::OpenGL; |
489 | |
490 | |
490 | sub add { |
491 | sub add { |
491 | my ($self, $x, $y, $chld) = @_; |
492 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
566 | } |
567 | } |
567 | } |
568 | } |
568 | |
569 | |
569 | ############################################################################# |
570 | ############################################################################# |
570 | |
571 | |
571 | package Crossfire::Client::Widget::VBox; |
572 | package CFClient::Widget::VBox; |
572 | |
573 | |
573 | our @ISA = Crossfire::Client::Widget::Container::; |
574 | our @ISA = CFClient::Widget::Container::; |
574 | |
575 | |
575 | use SDL::OpenGL; |
576 | use SDL::OpenGL; |
576 | |
577 | |
577 | sub size_request { |
578 | sub size_request { |
578 | my ($self) = @_; |
579 | my ($self) = @_; |
… | |
… | |
626 | } |
627 | } |
627 | } |
628 | } |
628 | |
629 | |
629 | ############################################################################# |
630 | ############################################################################# |
630 | |
631 | |
631 | package Crossfire::Client::Widget::Label; |
632 | package CFClient::Widget::Label; |
632 | |
633 | |
633 | our @ISA = Crossfire::Client::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, $x, $y, $z, $height, $text) = @_; |
639 | |
640 | |
640 | $height ||= $::FONTSIZE; |
641 | $height ||= $::FONTSIZE; |
641 | |
642 | |
642 | # TODO: color, and make height, xyz etc. optional |
643 | # TODO: color, and make height, xyz etc. optional |
643 | my $self = $class->SUPER::new ( |
644 | my $self = $class->SUPER::new ( |
|
|
645 | color => [1, 1, 1], |
644 | x => $x, |
646 | x => $x, |
645 | y => $y, |
647 | y => $y, |
646 | z => $z, |
648 | z => $z, |
647 | height => $height, |
649 | height => $height, |
648 | layout => new Crossfire::Client::Layout, |
650 | layout => new CFClient::Layout $height, |
649 | ); |
651 | ); |
650 | |
652 | |
651 | $self->set_text ($text); |
653 | $self->set_text ($text); |
652 | |
654 | |
653 | $self |
655 | $self |
… | |
… | |
677 | # ( |
679 | # ( |
678 | # $self->{texture}{width}, |
680 | # $self->{texture}{width}, |
679 | # $self->{texture}{height}, |
681 | # $self->{texture}{height}, |
680 | # ) |
682 | # ) |
681 | # } else { |
683 | # } else { |
682 | # my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
684 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
683 | # |
685 | # |
684 | # ($w, $h) |
686 | # ($w, $h) |
685 | # } |
687 | # } |
686 | } |
688 | } |
687 | |
689 | |
… | |
… | |
695 | sub _draw { |
697 | sub _draw { |
696 | my ($self) = @_; |
698 | my ($self) = @_; |
697 | |
699 | |
698 | my $tex = $self->{texture} ||= do { |
700 | my $tex = $self->{texture} ||= do { |
699 | $self->{layout}->set_width ($self->{w}); |
701 | $self->{layout}->set_width ($self->{w}); |
700 | new_from_layout Crossfire::Client::Texture $self->{layout}; |
702 | new_from_layout CFClient::Texture $self->{layout}; |
701 | }; |
703 | }; |
702 | |
704 | |
703 | glEnable GL_BLEND; |
705 | glEnable GL_BLEND; |
704 | glEnable GL_TEXTURE_2D; |
706 | glEnable GL_TEXTURE_2D; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
707 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
708 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
707 | |
709 | |
708 | glColor 1, 0, 0, 1; # TODO color |
710 | glColor @{$self->{color}}; |
709 | |
711 | |
710 | $tex->draw_quad (0, 0); |
712 | $tex->draw_quad (0, 0); |
711 | |
713 | |
712 | glDisable GL_BLEND; |
714 | glDisable GL_BLEND; |
713 | glDisable GL_TEXTURE_2D; |
715 | glDisable GL_TEXTURE_2D; |
714 | } |
716 | } |
715 | |
717 | |
716 | ############################################################################# |
718 | ############################################################################# |
717 | |
719 | |
718 | package Crossfire::Client::Widget::Entry; |
720 | package CFClient::Widget::Entry; |
719 | |
721 | |
720 | our @ISA = Crossfire::Client::Widget::Label::; |
722 | our @ISA = CFClient::Widget::Label::; |
721 | |
723 | |
722 | use SDL; |
724 | use SDL; |
723 | use SDL::OpenGL; |
725 | use SDL::OpenGL; |
724 | |
726 | |
725 | sub key_down { |
727 | sub key_down { |
… | |
… | |
771 | $self->SUPER::_draw; |
773 | $self->SUPER::_draw; |
772 | } |
774 | } |
773 | |
775 | |
774 | ############################################################################# |
776 | ############################################################################# |
775 | |
777 | |
776 | package Crossfire::Client::Widget::MapWidget; |
778 | package CFClient::Widget::MapWidget; |
777 | |
779 | |
778 | use strict; |
780 | use strict; |
779 | |
781 | |
780 | use List::Util qw(min max); |
782 | use List::Util qw(min max); |
781 | |
783 | |
782 | use SDL; |
784 | use SDL; |
783 | use SDL::OpenGL; |
785 | use SDL::OpenGL; |
784 | use SDL::OpenGL::Constants; |
786 | use SDL::OpenGL::Constants; |
785 | |
787 | |
786 | our @ISA = Crossfire::Client::Widget::; |
788 | our @ISA = CFClient::Widget::; |
787 | |
789 | |
788 | sub key_down { |
790 | sub key_down { |
789 | print "MAPKEYDOWN\n"; |
791 | print "MAPKEYDOWN\n"; |
790 | } |
792 | } |
791 | |
793 | |
… | |
… | |
867 | # } |
869 | # } |
868 | |
870 | |
869 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
871 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
870 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
872 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
871 | |
873 | |
872 | $darkness = new Crossfire::Client::Texture |
874 | $darkness = new CFClient::Texture |
873 | width => $sw4, |
875 | width => $sw4, |
874 | height => $sh, |
876 | height => $sh, |
875 | data => $darkness, |
877 | data => $darkness, |
876 | internalformat => GL_ALPHA, |
878 | internalformat => GL_ALPHA, |
877 | format => GL_ALPHA; |
879 | format => GL_ALPHA; |
… | |
… | |
934 | } |
936 | } |
935 | } |
937 | } |
936 | |
938 | |
937 | ############################################################################# |
939 | ############################################################################# |
938 | |
940 | |
939 | package Crossfire::Client::Widget::Animator; |
941 | package CFClient::Widget::Animator; |
940 | |
942 | |
941 | use SDL::OpenGL; |
943 | use SDL::OpenGL; |
942 | |
944 | |
943 | our @ISA = Crossfire::Client::Widget::Bin::; |
945 | our @ISA = CFClient::Widget::Bin::; |
944 | |
946 | |
945 | sub moveto { |
947 | sub moveto { |
946 | my ($self, $x, $y) = @_; |
948 | my ($self, $x, $y) = @_; |
947 | |
949 | |
948 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
950 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
976 | glPopMatrix; |
978 | glPopMatrix; |
977 | } |
979 | } |
978 | |
980 | |
979 | ############################################################################# |
981 | ############################################################################# |
980 | |
982 | |
981 | package Crossfire::Client::Widget::Toplevel; |
983 | package CFClient::Widget::Toplevel; |
982 | |
984 | |
983 | our @ISA = Crossfire::Client::Widget::Container::; |
985 | our @ISA = CFClient::Widget::Container::; |
984 | |
986 | |
985 | sub size_request { |
987 | sub size_request { |
986 | ($::WIDTH, $::HEIGHT) |
988 | ($::WIDTH, $::HEIGHT) |
987 | } |
989 | } |
988 | |
990 | |
… | |
… | |
1022 | $self->_draw; |
1024 | $self->_draw; |
1023 | } |
1025 | } |
1024 | |
1026 | |
1025 | ############################################################################# |
1027 | ############################################################################# |
1026 | |
1028 | |
1027 | package Crossfire::Client::Widget; |
1029 | package CFClient::Widget; |
1028 | |
1030 | |
1029 | $TOPLEVEL = new Crossfire::Client::Widget::Toplevel; |
1031 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
1030 | |
1032 | |
1031 | 1 |
1033 | 1 |
1032 | |
1034 | |