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.59 by root, Tue Apr 11 13:05:12 2006 UTC vs.
Revision 1.62 by root, Tue Apr 11 13:27:48 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) = @_;
314 314
315sub render_chld { 315sub render_chld {
316 my ($self) = @_; 316 my ($self) = @_;
317 317
318 $self->{texture} = 318 $self->{texture} =
319 Crossfire::Client::Texture->new_from_opengl ( 319 CFClient::Texture->new_from_opengl (
320 $self->{w}, $self->{h}, sub { $self->child->draw } 320 $self->{w}, $self->{h}, sub { $self->child->draw }
321 ); 321 );
322} 322}
323 323
324sub size_allocate { 324sub size_allocate {
350 glDisable GL_TEXTURE_2D; 350 glDisable GL_TEXTURE_2D;
351} 351}
352 352
353############################################################################# 353#############################################################################
354 354
355package Crossfire::Client::Widget::Frame; 355package CFClient::Widget::Frame;
356 356
357our @ISA = Crossfire::Client::Widget::Bin::; 357our @ISA = CFClient::Widget::Bin::;
358 358
359use SDL::OpenGL; 359use SDL::OpenGL;
360 360
361sub size_request { 361sub size_request {
362 my ($self) = @_; 362 my ($self) = @_;
396 $chld->draw; 396 $chld->draw;
397} 397}
398 398
399############################################################################# 399#############################################################################
400 400
401package Crossfire::Client::Widget::FancyFrame; 401package CFClient::Widget::FancyFrame;
402 402
403our @ISA = Crossfire::Client::Widget::Bin::; 403our @ISA = CFClient::Widget::Bin::;
404 404
405use SDL::OpenGL; 405use SDL::OpenGL;
406 406
407my @tex = 407my @tex =
408 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 408 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); 409 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
410 410
411sub size_request { 411sub size_request {
412 my ($self) = @_; 412 my ($self) = @_;
413 413
479 479
480} 480}
481 481
482############################################################################# 482#############################################################################
483 483
484package Crossfire::Client::Widget::Table; 484package CFClient::Widget::Table;
485 485
486our @ISA = Crossfire::Client::Widget::Bin::; 486our @ISA = CFClient::Widget::Bin::;
487 487
488use SDL::OpenGL; 488use SDL::OpenGL;
489 489
490sub add { 490sub add {
491 my ($self, $x, $y, $chld) = @_; 491 my ($self, $x, $y, $chld) = @_;
566 } 566 }
567} 567}
568 568
569############################################################################# 569#############################################################################
570 570
571package Crossfire::Client::Widget::VBox; 571package CFClient::Widget::VBox;
572 572
573our @ISA = Crossfire::Client::Widget::Container::; 573our @ISA = CFClient::Widget::Container::;
574 574
575use SDL::OpenGL; 575use SDL::OpenGL;
576 576
577sub size_request { 577sub size_request {
578 my ($self) = @_; 578 my ($self) = @_;
626 } 626 }
627} 627}
628 628
629############################################################################# 629#############################################################################
630 630
631package Crossfire::Client::Widget::Label; 631package CFClient::Widget::Label;
632 632
633our @ISA = Crossfire::Client::Widget::; 633our @ISA = CFClient::Widget::;
634 634
635use SDL::OpenGL; 635use SDL::OpenGL;
636 636
637sub new { 637sub new {
638 my ($class, $x, $y, $z, $height, $text) = @_; 638 my ($class, $x, $y, $z, $height, $text) = @_;
639 639
640 $height ||= $::FONTSIZE; 640 $height ||= $::FONTSIZE;
641 641
642 # TODO: color, and make height, xyz etc. optional 642 # TODO: color, and make height, xyz etc. optional
643 my $self = $class->SUPER::new ( 643 my $self = $class->SUPER::new (
644 color => [1, 1, 1],
644 x => $x, 645 x => $x,
645 y => $y, 646 y => $y,
646 z => $z, 647 z => $z,
647 height => $height, 648 height => $height,
648 layout => new Crossfire::Client::Layout, 649 layout => new CFClient::Layout $height,
649 ); 650 );
650 651
651 $self->set_text ($text); 652 $self->set_text ($text);
652 653
653 $self 654 $self
677# ( 678# (
678# $self->{texture}{width}, 679# $self->{texture}{width},
679# $self->{texture}{height}, 680# $self->{texture}{height},
680# ) 681# )
681# } else { 682# } else {
682# my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 683# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
683# 684#
684# ($w, $h) 685# ($w, $h)
685# } 686# }
686} 687}
687 688
695sub _draw { 696sub _draw {
696 my ($self) = @_; 697 my ($self) = @_;
697 698
698 my $tex = $self->{texture} ||= do { 699 my $tex = $self->{texture} ||= do {
699 $self->{layout}->set_width ($self->{w}); 700 $self->{layout}->set_width ($self->{w});
700 new_from_layout Crossfire::Client::Texture $self->{layout}; 701 new_from_layout CFClient::Texture $self->{layout};
701 }; 702 };
702 703
703 glEnable GL_BLEND; 704 glEnable GL_BLEND;
704 glEnable GL_TEXTURE_2D; 705 glEnable GL_TEXTURE_2D;
705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 706 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 707 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
707 708
708 glColor 1, 0, 0, 1; # TODO color 709 glColor @{$self->{color}};
709 710
710 $tex->draw_quad (0, 0); 711 $tex->draw_quad (0, 0);
711 712
712 glDisable GL_BLEND; 713 glDisable GL_BLEND;
713 glDisable GL_TEXTURE_2D; 714 glDisable GL_TEXTURE_2D;
714} 715}
715 716
716############################################################################# 717#############################################################################
717 718
718package Crossfire::Client::Widget::Entry; 719package CFClient::Widget::Entry;
719 720
720our @ISA = Crossfire::Client::Widget::Label::; 721our @ISA = CFClient::Widget::Label::;
721 722
722use SDL; 723use SDL;
723use SDL::OpenGL; 724use SDL::OpenGL;
724 725
725sub key_down { 726sub key_down {
771 $self->SUPER::_draw; 772 $self->SUPER::_draw;
772} 773}
773 774
774############################################################################# 775#############################################################################
775 776
776package Crossfire::Client::Widget::MapWidget; 777package CFClient::Widget::MapWidget;
777 778
778use strict; 779use strict;
779 780
780use List::Util qw(min max); 781use List::Util qw(min max);
781 782
782use SDL; 783use SDL;
783use SDL::OpenGL; 784use SDL::OpenGL;
784use SDL::OpenGL::Constants; 785use SDL::OpenGL::Constants;
785 786
786our @ISA = Crossfire::Client::Widget::; 787our @ISA = CFClient::Widget::;
787 788
788sub key_down { 789sub key_down {
789 print "MAPKEYDOWN\n"; 790 print "MAPKEYDOWN\n";
790} 791}
791 792
867# } 868# }
868 869
869 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 870 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
870 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 871 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
871 872
872 $darkness = new Crossfire::Client::Texture 873 $darkness = new CFClient::Texture
873 width => $sw4, 874 width => $sw4,
874 height => $sh, 875 height => $sh,
875 data => $darkness, 876 data => $darkness,
876 internalformat => GL_ALPHA, 877 internalformat => GL_ALPHA,
877 format => GL_ALPHA; 878 format => GL_ALPHA;
934 } 935 }
935} 936}
936 937
937############################################################################# 938#############################################################################
938 939
939package Crossfire::Client::Widget::Animator; 940package CFClient::Widget::Animator;
940 941
941use SDL::OpenGL; 942use SDL::OpenGL;
942 943
943our @ISA = Crossfire::Client::Widget::Bin::; 944our @ISA = CFClient::Widget::Bin::;
944 945
945sub moveto { 946sub moveto {
946 my ($self, $x, $y) = @_; 947 my ($self, $x, $y) = @_;
947 948
948 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 949 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
976 glPopMatrix; 977 glPopMatrix;
977} 978}
978 979
979############################################################################# 980#############################################################################
980 981
981package Crossfire::Client::Widget::Toplevel; 982package CFClient::Widget::Toplevel;
982 983
983our @ISA = Crossfire::Client::Widget::Container::; 984our @ISA = CFClient::Widget::Container::;
984 985
985sub size_request { 986sub size_request {
986 ($::WIDTH, $::HEIGHT) 987 ($::WIDTH, $::HEIGHT)
987} 988}
988 989
1022 $self->_draw; 1023 $self->_draw;
1023} 1024}
1024 1025
1025############################################################################# 1026#############################################################################
1026 1027
1027package Crossfire::Client::Widget; 1028package CFClient::Widget;
1028 1029
1029$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1030$TOPLEVEL = new CFClient::Widget::Toplevel;
1030 1031
10311 10321
1032 1033

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines