ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.58 by root, Tue Apr 11 12:21:29 2006 UTC vs.
Revision 1.63 by root, Tue Apr 11 13:29:24 2006 UTC

1package Crossfire::Client::Widget; 1package CFClient::Widget;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10use Crossfire::Client; 10use CFClient;
11 11
12our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13 13
14our $TOPLEVEL; 14our $TOPLEVEL;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
210 #$self->deactivate; 210 #$self->deactivate;
211} 211}
212 212
213############################################################################# 213#############################################################################
214 214
215package Crossfire::Client::Widget::Container; 215package CFClient::Widget::Container;
216 216
217our @ISA = Crossfire::Client::Widget::; 217our @ISA = CFClient::Widget::;
218 218
219sub new { 219sub 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
274package Crossfire::Client::Widget::Bin; 274package CFClient::Widget::Bin;
275 275
276our @ISA = Crossfire::Client::Widget::Container::; 276our @ISA = CFClient::Widget::Container::;
277 277
278sub child { $_[0]->{children}[0] } 278sub child { $_[0]->{children}[0] }
279 279
280sub size_request { 280sub 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
294package Crossfire::Client::Widget::Window; 294package CFClient::Widget::Window;
295 295
296our @ISA = Crossfire::Client::Widget::Bin::; 296our @ISA = CFClient::Widget::Bin::;
297 297
298use SDL::OpenGL; 298use SDL::OpenGL;
299 299
300sub new { 300sub new {
301 my ($class, $x, $y, $z, $w, $h) = @_; 301 my ($class, $x, $y, $z, $w, $h) = @_;
306} 306}
307 307
308sub update { 308sub 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
315sub render_chld { 316sub 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
324sub size_allocate { 325sub size_allocate {
350 glDisable GL_TEXTURE_2D; 351 glDisable GL_TEXTURE_2D;
351} 352}
352 353
353############################################################################# 354#############################################################################
354 355
355package Crossfire::Client::Widget::Frame; 356package CFClient::Widget::Frame;
356 357
357our @ISA = Crossfire::Client::Widget::Bin::; 358our @ISA = CFClient::Widget::Bin::;
358 359
359use SDL::OpenGL; 360use SDL::OpenGL;
360 361
361sub size_request { 362sub size_request {
362 my ($self) = @_; 363 my ($self) = @_;
396 $chld->draw; 397 $chld->draw;
397} 398}
398 399
399############################################################################# 400#############################################################################
400 401
401package Crossfire::Client::Widget::FancyFrame; 402package CFClient::Widget::FancyFrame;
402 403
403our @ISA = Crossfire::Client::Widget::Bin::; 404our @ISA = CFClient::Widget::Bin::;
404 405
405use SDL::OpenGL; 406use SDL::OpenGL;
406 407
407my @tex = 408my @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
411sub size_request { 412sub size_request {
412 my ($self) = @_; 413 my ($self) = @_;
413 414
479 480
480} 481}
481 482
482############################################################################# 483#############################################################################
483 484
484package Crossfire::Client::Widget::Table; 485package CFClient::Widget::Table;
485 486
486our @ISA = Crossfire::Client::Widget::Bin::; 487our @ISA = CFClient::Widget::Bin::;
487 488
488use SDL::OpenGL; 489use SDL::OpenGL;
489 490
490sub add { 491sub add {
491 my ($self, $x, $y, $chld) = @_; 492 my ($self, $x, $y, $chld) = @_;
566 } 567 }
567} 568}
568 569
569############################################################################# 570#############################################################################
570 571
571package Crossfire::Client::Widget::VBox; 572package CFClient::Widget::VBox;
572 573
573our @ISA = Crossfire::Client::Widget::Container::; 574our @ISA = CFClient::Widget::Container::;
574 575
575use SDL::OpenGL; 576use SDL::OpenGL;
576 577
577sub size_request { 578sub size_request {
578 my ($self) = @_; 579 my ($self) = @_;
626 } 627 }
627} 628}
628 629
629############################################################################# 630#############################################################################
630 631
631package Crossfire::Client::Widget::Label; 632package CFClient::Widget::Label;
632 633
633our @ISA = Crossfire::Client::Widget::; 634our @ISA = CFClient::Widget::;
634 635
635use SDL::OpenGL; 636use SDL::OpenGL;
636 637
637sub new { 638sub 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 (x => $x, y => $y, z => $z, height => $height); 644 my $self = $class->SUPER::new (
645 color => [1, 1, 1],
646 x => $x,
647 y => $y,
648 z => $z,
649 height => $height,
650 layout => new CFClient::Layout $height,
651 );
644 652
645 $self->set_text ($text); 653 $self->set_text ($text);
646 654
647 $self 655 $self
648} 656}
649 657
650sub set_text { 658sub set_text {
651 my ($self, $text) = @_; 659 my ($self, $text) = @_;
652 660
653 $self->{text} = $text; 661 $self->{text} = $text;
654 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 662 $self->{layout}->set_markup ($text);
655 663
656 $self->update; 664 delete $self->{texture};
657} 665}
658 666
659sub get_text { 667sub get_text {
660 my ($self, $text) = @_; 668 my ($self, $text) = @_;
661 669
663} 671}
664 672
665sub size_request { 673sub size_request {
666 my ($self) = @_; 674 my ($self) = @_;
667 675
676 $self->{layout}->set_width;
677 $self->{layout}->size
668 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 678# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
669 ( 679# (
670 $self->{texture}{width}, 680# $self->{texture}{width},
671 $self->{texture}{height}, 681# $self->{texture}{height},
672 ) 682# )
673 } else { 683# } else {
674 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 684# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
675 685#
676 ($w, $h) 686# ($w, $h)
677 } 687# }
688}
678 689
690sub size_allocate {
691 my ($self, $w, $h) = @_;
692
693 $self->SUPER::size_allocate ($w, $h);
694 delete $self->{texture};
679} 695}
680 696
681sub _draw { 697sub _draw {
682 my ($self) = @_; 698 my ($self) = @_;
683 699
684 my $tex = $self->{texture}; 700 my $tex = $self->{texture} ||= do {
701 $self->{layout}->set_width ($self->{w});
702 new_from_layout CFClient::Texture $self->{layout};
703 };
685 704
686 glEnable GL_BLEND; 705 glEnable GL_BLEND;
687 glEnable GL_TEXTURE_2D; 706 glEnable GL_TEXTURE_2D;
688 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 707 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
689 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 708 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
690 709
691 glColor 1, 0, 0, 1; # TODO color 710 glColor @{$self->{color}};
692 711
693 $tex->draw_quad (0, 0); 712 $tex->draw_quad (0, 0);
694 713
695 glDisable GL_BLEND; 714 glDisable GL_BLEND;
696 glDisable GL_TEXTURE_2D; 715 glDisable GL_TEXTURE_2D;
697} 716}
698 717
699############################################################################# 718#############################################################################
700 719
701package Crossfire::Client::Widget::Entry; 720package CFClient::Widget::Entry;
702 721
703our @ISA = Crossfire::Client::Widget::Label::; 722our @ISA = CFClient::Widget::Label::;
704 723
705use SDL; 724use SDL;
706use SDL::OpenGL; 725use SDL::OpenGL;
707 726
708sub key_down { 727sub key_down {
754 $self->SUPER::_draw; 773 $self->SUPER::_draw;
755} 774}
756 775
757############################################################################# 776#############################################################################
758 777
759package Crossfire::Client::Widget::MapWidget; 778package CFClient::Widget::MapWidget;
760 779
761use strict; 780use strict;
762 781
763use List::Util qw(min max); 782use List::Util qw(min max);
764 783
765use SDL; 784use SDL;
766use SDL::OpenGL; 785use SDL::OpenGL;
767use SDL::OpenGL::Constants; 786use SDL::OpenGL::Constants;
768 787
769our @ISA = Crossfire::Client::Widget::; 788our @ISA = CFClient::Widget::;
770 789
771sub key_down { 790sub key_down {
772 print "MAPKEYDOWN\n"; 791 print "MAPKEYDOWN\n";
773} 792}
774 793
850# } 869# }
851 870
852 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 871 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 872 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
854 873
855 $darkness = new Crossfire::Client::Texture 874 $darkness = new CFClient::Texture
856 width => $sw4, 875 width => $sw4,
857 height => $sh, 876 height => $sh,
858 data => $darkness, 877 data => $darkness,
859 internalformat => GL_ALPHA, 878 internalformat => GL_ALPHA,
860 format => GL_ALPHA; 879 format => GL_ALPHA;
917 } 936 }
918} 937}
919 938
920############################################################################# 939#############################################################################
921 940
922package Crossfire::Client::Widget::Animator; 941package CFClient::Widget::Animator;
923 942
924use SDL::OpenGL; 943use SDL::OpenGL;
925 944
926our @ISA = Crossfire::Client::Widget::Bin::; 945our @ISA = CFClient::Widget::Bin::;
927 946
928sub moveto { 947sub moveto {
929 my ($self, $x, $y) = @_; 948 my ($self, $x, $y) = @_;
930 949
931 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 950 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
959 glPopMatrix; 978 glPopMatrix;
960} 979}
961 980
962############################################################################# 981#############################################################################
963 982
964package Crossfire::Client::Widget::Toplevel; 983package CFClient::Widget::Toplevel;
965 984
966our @ISA = Crossfire::Client::Widget::Container::; 985our @ISA = CFClient::Widget::Container::;
967 986
968sub size_request { 987sub size_request {
969 ($::WIDTH, $::HEIGHT) 988 ($::WIDTH, $::HEIGHT)
970} 989}
971 990
1005 $self->_draw; 1024 $self->_draw;
1006} 1025}
1007 1026
1008############################################################################# 1027#############################################################################
1009 1028
1010package Crossfire::Client::Widget; 1029package CFClient::Widget;
1011 1030
1012$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1031$TOPLEVEL = new CFClient::Widget::Toplevel;
1013 1032
10141 10331
1015 1034

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines