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.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 ( 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
695sub _draw { 697sub _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
718package Crossfire::Client::Widget::Entry; 720package CFClient::Widget::Entry;
719 721
720our @ISA = Crossfire::Client::Widget::Label::; 722our @ISA = CFClient::Widget::Label::;
721 723
722use SDL; 724use SDL;
723use SDL::OpenGL; 725use SDL::OpenGL;
724 726
725sub key_down { 727sub key_down {
771 $self->SUPER::_draw; 773 $self->SUPER::_draw;
772} 774}
773 775
774############################################################################# 776#############################################################################
775 777
776package Crossfire::Client::Widget::MapWidget; 778package CFClient::Widget::MapWidget;
777 779
778use strict; 780use strict;
779 781
780use List::Util qw(min max); 782use List::Util qw(min max);
781 783
782use SDL; 784use SDL;
783use SDL::OpenGL; 785use SDL::OpenGL;
784use SDL::OpenGL::Constants; 786use SDL::OpenGL::Constants;
785 787
786our @ISA = Crossfire::Client::Widget::; 788our @ISA = CFClient::Widget::;
787 789
788sub key_down { 790sub 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
939package Crossfire::Client::Widget::Animator; 941package CFClient::Widget::Animator;
940 942
941use SDL::OpenGL; 943use SDL::OpenGL;
942 944
943our @ISA = Crossfire::Client::Widget::Bin::; 945our @ISA = CFClient::Widget::Bin::;
944 946
945sub moveto { 947sub 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
981package Crossfire::Client::Widget::Toplevel; 983package CFClient::Widget::Toplevel;
982 984
983our @ISA = Crossfire::Client::Widget::Container::; 985our @ISA = CFClient::Widget::Container::;
984 986
985sub size_request { 987sub 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
1027package Crossfire::Client::Widget; 1029package CFClient::Widget;
1028 1030
1029$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1031$TOPLEVEL = new CFClient::Widget::Toplevel;
1030 1032
10311 10331
1032 1034

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines