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.124 by elmex, Mon Apr 17 20:29:37 2006 UTC vs.
Revision 1.134 by root, Wed Apr 19 06:06:45 2006 UTC

96 96
97 my $self = bless { 97 my $self = bless {
98 x => 0, 98 x => 0,
99 y => 0, 99 y => 0,
100 z => 0, 100 z => 0,
101 w => -1,
102 h => -1,
103 @_ 101 @_
104 }, $class; 102 }, $class;
105 103
106 for (keys %$self) { 104 for (keys %$self) {
107 if (/^connect_(.*)$/) { 105 if (/^connect_(.*)$/) {
110 } 108 }
111 109
112 $self 110 $self
113} 111}
114 112
113sub show {
114 my ($self) = @_;
115
116 return if $self->{parent};
117
118 $CFClient::UI::ROOT->add ($self);
119}
120
121sub hide {
122 my ($self) = @_;
123
124 return unless $self->{parent};
125
126 $self->{parent}->remove ($self);
127}
128
115sub move { 129sub move {
116 my ($self, $x, $y, $z) = @_; 130 my ($self, $x, $y, $z) = @_;
131
117 $self->{x} = int $x; 132 $self->{x} = int $x;
118 $self->{y} = int $y; 133 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 134 $self->{z} = $z if defined $z;
135
136 $self->update;
120} 137}
121 138
122sub needs_redraw { 139sub needs_redraw {
123 0 140 0
124} 141}
126sub size_request { 143sub size_request {
127 require Carp; 144 require Carp;
128 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abtract";
129} 146}
130 147
131sub _size_allocate { 148sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
133 150
134 $self->{x} = $x; 151 $self->{x} = $x;
135 $self->{y} = $y; 152 $self->{y} = $y;
136 153
137 return unless $self->{w} != $w || $self->{h} != $h; 154 return unless $self->{w} != $w || $self->{h} != $h;
138 155
139 $self->{w} = $w; 156 $self->{w} = $w;
140 $self->{h} = $h; 157 $self->{h} = $h;
141 158
142 1 159 $self->size_allocate ($w, $h);
160 $self->update;
143} 161}
144 162
145sub size_allocate { 163sub size_allocate {
146 my ($self, $x, $y, $w, $h) = @_; 164 # nothing to be done
147
148 $self->_size_allocate ($x, $y, $w, $h);
149} 165}
150 166
151# return top left coordinates 167# return top left coordinates
152sub _topleft { 168sub _topleft {
153 my ($self, $x, $y) = @_; 169 my ($self, $x, $y) = @_;
260 my ($self, $parent) = @_; 276 my ($self, $parent) = @_;
261 277
262 Scalar::Util::weaken ($self->{parent} = $parent); 278 Scalar::Util::weaken ($self->{parent} = $parent);
263} 279}
264 280
281sub check_size {
282 my ($self) = @_;
283
284 my ($w, $h) = $self->size_request;
285
286 if ($w != $self->{req_w} || $h != $self->{req_h}) {
287 $self->{req_w} = $w;
288 $self->{req_h} = $h;
289
290 $self->{parent}->check_size
291 if $self->{parent};
292 }
293}
294
265sub update { 295sub update {
266 my ($self) = @_; 296 my ($self) = @_;
267 297
268 $self->{parent}->update 298 $self->{parent}->update
269 if $self->{parent}; 299 if $self->{parent};
270} 300}
271 301
272sub connect { 302sub connect {
273 my ($self, $signal, $cb) = @_; 303 my ($self, $signal, $cb) = @_;
274 304
275 push @{ $self->{cb}{$signal} }, $cb; 305 push @{ $self->{signal_cb}{$signal} }, $cb;
276} 306}
277 307
278sub emit { 308sub emit {
279 my ($self, $signal, @args) = @_; 309 my ($self, $signal, @args) = @_;
280 310
311 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
281 $_->($self, @args) 312 $cb->($self, @args);
282 for @{$self->{cb}{$signal} || []}; 313 }
283} 314}
284 315
285sub DESTROY { 316sub DESTROY {
286 my ($self) = @_; 317 my ($self) = @_;
287 318
367 $self->{children} = [ 398 $self->{children} = [
368 sort { $a->{z} <=> $b->{z} } 399 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 400 @{$self->{children}}, $child
370 ]; 401 ];
371 402
372 $self->{w} = $self->{h} = -1; 403 $child->check_size;
373 $self->update;
374} 404}
375 405
376sub remove { 406sub remove {
377 my ($self, $widget) = @_; 407 my ($self, $child) = @_;
378 408
409 delete $child->{parent};
410
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
380 412
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 413 $self->check_size;
382} 414}
383 415
384sub find_widget { 416sub find_widget {
385 my ($self, $x, $y) = @_; 417 my ($self, $x, $y) = @_;
386 418
416 448
417 $class->SUPER::new (children => [$child], %arg) 449 $class->SUPER::new (children => [$child], %arg)
418} 450}
419 451
420sub add { 452sub add {
421 my ($self, $widget) = @_; 453 my ($self, $child) = @_;
422 454
423 $self->{children} = []; 455 $self->{children} = [];
424 456
425 $self->SUPER::add ($widget); 457 $self->SUPER::add ($child);
426} 458}
427 459
428sub remove { 460sub remove {
429 my ($self, $widget) = @_; 461 my ($self, $widget) = @_;
430 462
439sub size_request { 471sub size_request {
440 $_[0]{children}[0]->size_request 472 $_[0]{children}[0]->size_request
441} 473}
442 474
443sub size_allocate { 475sub size_allocate {
444 my ($self, $x, $y, $w, $h) = @_; 476 my ($self, $w, $h) = @_;
445 477
446 $self->_size_allocate ($x, $y, $w, $h) or return;
447
448 $self->{children}[0]->size_allocate (0, 0, $w, $h); 478 $self->{children}[0]->configure (0, 0, $w, $h);
449} 479}
450 480
451############################################################################# 481#############################################################################
452 482
453package CFClient::UI::Window; 483package CFClient::UI::Window;
479 $self->child->draw; 509 $self->child->draw;
480 }; 510 };
481} 511}
482 512
483sub size_allocate { 513sub size_allocate {
484 my ($self, $x, $y, $w, $h) = @_; 514 my ($self, $w, $h) = @_;
485 515
486 $self->_size_allocate ($x, $y, $w, $h) or return;
487
488 $self->child->size_allocate (0, 0, $w, $h); 516 $self->child->configure (0, 0, $w, $h);
489 517
490 $self->render_chld; 518 $self->render_chld;
491} 519}
492 520
493sub _draw { 521sub _draw {
509 glDisable GL_TEXTURE_2D; 537 glDisable GL_TEXTURE_2D;
510} 538}
511 539
512############################################################################# 540#############################################################################
513 541
542package CFClient::UI::ViewPort;
543
544our @ISA = CFClient::UI::Window::;
545
546sub new { die }
547
548sub size_request {
549 my ($self) = @_;
550
551 @$self{qw(child_w child_h)} = $self->child->size_request;
552 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
553
554 @$self{qw(child_w child_h)}
555}
556
557sub _draw {
558 my ($self) = @_;
559
560 $self->{children}[1]->draw;
561}
562
563
564#############################################################################
565
514package CFClient::UI::Frame; 566package CFClient::UI::Frame;
515 567
516our @ISA = CFClient::UI::Bin::; 568our @ISA = CFClient::UI::Bin::;
517 569
518use SDL::OpenGL; 570use SDL::OpenGL;
528} 580}
529 581
530sub size_allocate { 582sub size_allocate {
531 my ($self, $x, $y, $w, $h) = @_; 583 my ($self, $x, $y, $w, $h) = @_;
532 584
533 $self->_size_allocate ($x, $y, $w, $h) or return;
534
535 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 585 $self->child->configure (2, 2, $w - 4, $h - 4);
536} 586}
537 587
538sub _draw { 588sub _draw {
539 my ($self) = @_; 589 my ($self) = @_;
540 590
571 # TODO: user_x, user_y, overwrite moveto? 621 # TODO: user_x, user_y, overwrite moveto?
572 622
573 $class->SUPER::new ( 623 $class->SUPER::new (
574 bg => [1, 1, 1, 1], 624 bg => [1, 1, 1, 1],
575 border_bg => [1, 1, 1, 1], 625 border_bg => [1, 1, 1, 1],
576 border => int $::FONTSIZE * 0.8, 626 border => 0.8,
577 @_ 627 @_
578 ) 628 )
579} 629}
580 630
631sub border {
632 int $_[0]{border} * $::FONTSIZE
633}
634
581sub size_request { 635sub size_request {
582 my ($self) = @_; 636 my ($self) = @_;
583 637
584 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; 638 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
585 639
586 my ($w, $h) = $self->SUPER::size_request; 640 my ($w, $h) = $self->SUPER::size_request;
587 641
588 ( 642 (
589 $w + $self->{border} * 2, 643 $w + $self->border * 2,
590 $h + $self->{border} * 2, 644 $h + $self->border * 2,
591 ) 645 )
592} 646}
593 647
594sub size_allocate { 648sub size_allocate {
595 my ($self, $x, $y, $w, $h) = @_; 649 my ($self, $w, $h) = @_;
596 650
597 $self->_size_allocate ($x, $y, $w, $h) or return;
598
599 $h -= List::Util::max 0, $self->{border} * 2; 651 $h -= List::Util::max 0, $self->border * 2;
600 $w -= List::Util::max 0, $self->{border} * 2; 652 $w -= List::Util::max 0, $self->border * 2;
601 653
602 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 654 $self->child->configure ($self->border, $self->border, $w, $h);
603} 655}
604 656
605sub button_down { 657sub button_down {
606 my ($self, $ev, $x, $y) = @_; 658 my ($self, $ev, $x, $y) = @_;
607 659
660 my $border = $self->border;
661
608 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 662 if ($x < $self->{w} && $x >= $self->{w} - $border
609 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
610 664
611 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
612 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
613 667
614 $self->{motion} = sub { 668 $self->{motion} = sub {
616 670
617 ($x, $y) = ($ev->motion_x, $ev->motion_y); 671 ($x, $y) = ($ev->motion_x, $ev->motion_y);
618 672
619 $self->{user_w} = $bw + $x - $ox; 673 $self->{user_w} = $bw + $x - $ox;
620 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
621 $self->update; 675 $self->check_size;
622 }; 676 };
623 677
624 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
625 && $y >= 0 && $y < $self->{border}) { 679 && $y >= 0 && $y < $border) {
626 680
627 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
628 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
629 683
630 $self->{motion} = sub { 684 $self->{motion} = sub {
659 glEnable GL_BLEND; 713 glEnable GL_BLEND;
660 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 714 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
661 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
662 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
663 717
718 my $border = $self->border;
719
664 glColor @{ $self->{border_bg} }; 720 glColor @{ $self->{border_bg} };
665 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 721 $tex[1]->draw_quad (0, 0, $w, $border);
666 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 722 $tex[3]->draw_quad (0, $border, $border, $ch);
667 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 723 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
668 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 724 $tex[4]->draw_quad (0, $h - $border, $w, $border);
669 725
670 my $bg = $tex[0]; 726 my $bg = $tex[0];
671 727
672 # TODO: repeat texture not scale 728 # TODO: repeat texture not scale
673 my $rep_x = $cw / $bg->{w}; 729 my $rep_x = $cw / $bg->{w};
676 glColor @{ $self->{bg} }; 732 glColor @{ $self->{bg} };
677 733
678 $bg->{s} = $rep_x; 734 $bg->{s} = $rep_x;
679 $bg->{t} = $rep_y; 735 $bg->{t} = $rep_y;
680 $bg->{wrap_mode} = 1; 736 $bg->{wrap_mode} = 1;
681 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 737 $bg->draw_quad ($border, $border, $cw, $ch);
682 738
683 glDisable GL_TEXTURE_2D; 739 glDisable GL_TEXTURE_2D;
684 glDisable GL_BLEND; 740 glDisable GL_BLEND;
685 741
686 $self->child->draw; 742 $self->child->draw;
709 my ($self, $x, $y, $child) = @_; 765 my ($self, $x, $y, $child) = @_;
710 766
711 $child->set_parent ($self); 767 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 768 $self->{children}[$y][$x] = $child;
713 769
714 $self->{w} = $self->{h} = -1; 770 $child->check_size;
715 $self->update;
716} 771}
717 772
718# TODO: move to container class maybe? send childs a signal on removal? 773# TODO: move to container class maybe? send childs a signal on removal?
719sub clear { 774sub clear {
720 my ($self) = @_; 775 my ($self) = @_;
755 (sum @$hs), 810 (sum @$hs),
756 ) 811 )
757} 812}
758 813
759sub size_allocate { 814sub size_allocate {
760 my ($self, $x, $y, $w, $h) = @_; 815 my ($self, $w, $h) = @_;
761
762 $self->_size_allocate ($x, $y, $w, $h) or return;
763 816
764 my ($ws, $hs) = $self->get_wh; 817 my ($ws, $hs) = $self->get_wh;
765 818
766 my $req_w = sum @$ws; 819 my $req_w = sum @$ws;
767 my $req_h = sum @$hs; 820 my $req_h = sum @$hs;
789 842
790 for my $c (0 .. $#$row) { 843 for my $c (0 .. $#$row) {
791 my $col_w = $ws->[$c]; 844 my $col_w = $ws->[$c];
792 845
793 if (my $widget = $row->[$c]) { 846 if (my $widget = $row->[$c]) {
794 $widget->size_allocate ($x, $y, $col_w, $row_h); 847 $widget->configure ($x, $y, $col_w, $row_h);
795 } 848 }
796 849
797 $x += $col_w; 850 $x += $col_w;
798 } 851 }
799 852
844 (List::Util::max map $_->[1], @alloc), 897 (List::Util::max map $_->[1], @alloc),
845 ) 898 )
846} 899}
847 900
848sub size_allocate { 901sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 902 my ($self, $w, $h) = @_;
850
851 $self->_size_allocate ($x, $y, $w, $h);
852 903
853 ($h, $w) = ($w, $h); 904 ($h, $w) = ($w, $h);
854 905
855 my $children = $self->{children}; 906 my $children = $self->{children};
856 907
878 929
879 my $y = 0; 930 my $y = 0;
880 for (0 .. $#$children) { 931 for (0 .. $#$children) {
881 my $child = $children->[$_]; 932 my $child = $children->[$_];
882 my $h = $h[$_]; 933 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 934 $child->configure ($y, 0, $h, $w);
884 935
885 $y += $h; 936 $y += $h;
886 } 937 }
938
939 1
887} 940}
888 941
889############################################################################# 942#############################################################################
890 943
891package CFClient::UI::VBox; 944package CFClient::UI::VBox;
904 (List::Util::sum map $_->[1], @alloc), 957 (List::Util::sum map $_->[1], @alloc),
905 ) 958 )
906} 959}
907 960
908sub size_allocate { 961sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 962 my ($self, $w, $h) = @_;
910
911 $self->_size_allocate ($x, $y, $w, $h);
912 963
913 my $children = $self->{children}; 964 my $children = $self->{children};
914 965
915 my @h = map +($_->size_request)[1], @$children; 966 my @h = map +($_->size_request)[1], @$children;
916 967
934 985
935 my $y = 0; 986 my $y = 0;
936 for (0 .. $#$children) { 987 for (0 .. $#$children) {
937 my $child = $children->[$_]; 988 my $child = $children->[$_];
938 my $h = $h[$_]; 989 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 990 $child->configure (0, $y, $w, $h);
940 991
941 $y += $h; 992 $y += $h;
942 } 993 }
994
995 1
943} 996}
944 997
945############################################################################# 998#############################################################################
946 999
947package CFClient::UI::Label; 1000package CFClient::UI::Label;
953sub new { 1006sub new {
954 my ($class, %arg) = @_; 1007 my ($class, %arg) = @_;
955 1008
956 my $self = $class->SUPER::new ( 1009 my $self = $class->SUPER::new (
957 fg => [1, 1, 1], 1010 fg => [1, 1, 1],
958 fontsize => $::FONTSIZE, 1011 fontsize => 1,
959 text => "", 1012 text => "",
960 align => -1, 1013 align => -1,
961 valign => -1, 1014 valign => -1,
962 padding => 2, 1015 padding => 2,
963 layout => new CFClient::Layout, 1016 layout => new CFClient::Layout,
1002 1055
1003sub size_request { 1056sub size_request {
1004 my ($self) = @_; 1057 my ($self) = @_;
1005 1058
1006 $self->{layout}->set_width; 1059 $self->{layout}->set_width;
1007 $self->{layout}->set_height ($self->{fontsize}); 1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1008 1061
1009 my ($w, $h) = $self->{layout}->size; 1062 my ($w, $h) = $self->{layout}->size;
1010 1063
1011 ( 1064 (
1012 $w + $self->{padding} * 2, 1065 $w + $self->{padding} * 2,
1013 $h + $self->{padding} * 2, 1066 $h + $self->{padding} * 2,
1014 ) 1067 )
1015} 1068}
1016 1069
1017sub size_allocate { 1070sub size_allocate {
1018 my ($self, $x, $y, $w, $h) = @_; 1071 my ($self, $w, $h) = @_;
1019
1020 $self->_size_allocate ($x, $y, $w, $h) or return;
1021 1072
1022 delete $self->{texture}; 1073 delete $self->{texture};
1023}
1024
1025sub update {
1026 my ($self) = @_;
1027
1028 delete $self->{texture};
1029 $self->SUPER::update;
1030} 1074}
1031 1075
1032sub _draw { 1076sub _draw {
1033 my ($self) = @_; 1077 my ($self) = @_;
1034 1078
1035 my $tex = $self->{texture} ||= do { 1079 my $tex = $self->{texture} ||= do {
1036 $self->{layout}->set_width ($self->{w}); 1080 $self->{layout}->set_width ($self->{w});
1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1038 new_from_layout CFClient::Texture $self->{layout} 1082 new_from_layout CFClient::Texture $self->{layout}
1039 }; 1083 };
1040 1084
1041 glEnable GL_BLEND; 1085 glEnable GL_BLEND;
1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1086 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1092 1136
1093 delete $self->{cur_h}; 1137 delete $self->{cur_h};
1094 1138
1095 return if $self->{text} eq $text; 1139 return if $self->{text} eq $text;
1096 1140
1141 delete $self->{texture};
1142
1097 $self->{last_activity} = $::NOW; 1143 $self->{last_activity} = $::NOW;
1098 $self->{text} = $text; 1144 $self->{text} = $text;
1099 1145
1100 $text =~ s/./*/g if $self->{hidden}; 1146 $text =~ s/./*/g if $self->{hidden};
1101 $self->{layout}->set_text ("$text "); 1147 $self->{layout}->set_text ("$text ");
1114 1160
1115 ($w + 1, $h) # add 1 for cursor 1161 ($w + 1, $h) # add 1 for cursor
1116} 1162}
1117 1163
1118sub size_allocate { 1164sub size_allocate {
1119 my ($self, $x, $y, $w, $h) = @_; 1165 my ($self, $w, $h) = @_;
1120
1121 $self->SUPER::size_allocate ($x, $y, $w, $h);
1122 1166
1123 $self->_set_text ($self->{text}); 1167 $self->_set_text ($self->{text});
1124} 1168}
1125 1169
1126sub set_text { 1170sub set_text {
1276 padding => 4, 1320 padding => 4,
1277 fg => [1, 1, 1], 1321 fg => [1, 1, 1],
1278 bg => [1, 1, 1, 0.2], 1322 bg => [1, 1, 1, 0.2],
1279 active_fg => [0, 0, 1], 1323 active_fg => [0, 0, 1],
1280 can_hover => 1, 1324 can_hover => 1,
1325 align => 0,
1326 valign => 0,
1281 @_ 1327 @_
1282 ) 1328 )
1283} 1329}
1284 1330
1285sub button_up { 1331sub button_up {
1342 1388
1343sub size_request { 1389sub size_request {
1344 my ($self) = @_; 1390 my ($self) = @_;
1345 1391
1346 ($self->{padding} * 2 + 6) x 2 1392 ($self->{padding} * 2 + 6) x 2
1347}
1348
1349sub size_allocate {
1350 my ($self, $x, $y, $w, $h) = @_;
1351
1352 $self->_size_allocate ($x, $y, $w, $h);
1353} 1393}
1354 1394
1355sub button_down { 1395sub button_down {
1356 my ($self, $ev, $x, $y) = @_; 1396 my ($self, $ev, $x, $y) = @_;
1357 1397
1422} 1462}
1423 1463
1424sub size_request { 1464sub size_request {
1425 my ($self) = @_; 1465 my ($self) = @_;
1426 1466
1427 ($self->{w}, $self->{h}) 1467 my $tex = $tex{$self->{gauge}}[0];
1468
1469 @$tex{qw(w h)}
1428} 1470}
1429 1471
1430sub set_max { 1472sub set_max {
1431 my ($self, $max) = @_; 1473 my ($self, $max) = @_;
1474
1432 $self->{max_val} = $max; 1475 $self->{max_val} = $max;
1433} 1476}
1434 1477
1435sub set_value { 1478sub set_value {
1436 my ($self, $val, $max) = @_; 1479 my ($self, $val, $max) = @_;
1465 my $h1 = $self->{h} - $ycut * $self->{h}; 1508 my $h1 = $self->{h} - $ycut * $self->{h};
1466 my $h2 = $ycut * $self->{h}; 1509 my $h2 = $ycut * $self->{h};
1467 1510
1468 my $yp = 0; 1511 my $yp = 0;
1469 1512
1470 glBindTexture (GL_TEXTURE_2D, $t1->{name}); 1513 glBindTexture GL_TEXTURE_2D, $t1->{name};
1471 glBegin (GL_QUADS); 1514 glBegin GL_QUADS;
1472 glTexCoord (0, 0); glVertex (0 , $yp); 1515 glTexCoord 0 , 0; glVertex 0 , $yp;
1473 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); 1516 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1474 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); 1517 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1475 glTexCoord (1, 0); glVertex (0 + $w, $yp); 1518 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1476 glEnd (); 1519 glEnd;
1477 1520
1478 $yp += $h1; 1521 $yp += $h1;
1479 1522
1480 glBindTexture (GL_TEXTURE_2D, $t2->{name}); 1523 glBindTexture GL_TEXTURE_2D, $t2->{name};
1481 glBegin (GL_QUADS); 1524 glBegin GL_QUADS;
1482 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); 1525 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1483 glTexCoord (0, 1); glVertex (0 , $yp + $h2); 1526 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1484 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); 1527 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1485 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); 1528 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1486 glEnd (); 1529 glEnd;
1487 1530
1488 glDisable GL_BLEND; 1531 glDisable GL_BLEND;
1489 glDisable GL_TEXTURE_2D; 1532 glDisable GL_TEXTURE_2D;
1490} 1533}
1491 1534
1513 # TODO: calculations are off 1556 # TODO: calculations are off
1514 my $self = $class->SUPER::new ( 1557 my $self = $class->SUPER::new (
1515 fg => [1, 1, 1], 1558 fg => [1, 1, 1],
1516 active_fg => [0, 0, 0], 1559 active_fg => [0, 0, 0],
1517 range => [0, 0, 100, 10], 1560 range => [0, 0, 100, 10],
1518 req_w => 40, 1561 req_w => 20,
1519 req_h => 13, 1562 req_h => 20,
1520 vertical => 0, 1563 vertical => 0,
1521 can_hover => 1, 1564 can_hover => 1,
1522 inner_pad => 5, 1565 inner_pad => 5,
1523 @_ 1566 @_
1524 ); 1567 );
1634 1677
1635sub new { 1678sub new {
1636 my $class = shift; 1679 my $class = shift;
1637 1680
1638 my $self = $class->SUPER::new ( 1681 my $self = $class->SUPER::new (
1639 req_w => $::WIDTH / 6,
1640 req_h => $::HEIGHT / 6,
1641 fontsize => $::FONTSIZE, 1682 fontsize => 1,
1642 @_, 1683 @_,
1643 1684
1644 layout => (new CFClient::Layout), 1685 layout => (new CFClient::Layout),
1645 par => [], 1686 par => [],
1646 height => 0, 1687 height => 0,
1667sub text_height { 1708sub text_height {
1668 my ($self, $text) = @_; 1709 my ($self, $text) = @_;
1669 1710
1670 my $layout = $self->{layout}; 1711 my $layout = $self->{layout};
1671 1712
1672 $layout->set_height ($self->{fontsize}); 1713 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1673 $layout->set_width ($self->{w}); 1714 $layout->set_width ($self->{w});
1674 $layout->set_text ($text); 1715 $layout->set_text ($text);
1675 1716
1676 ($layout->size)[1] 1717 ($layout->size)[1]
1677} 1718}
1681 1722
1682 $self->{need_reflow}++; 1723 $self->{need_reflow}++;
1683 $self->update; 1724 $self->update;
1684} 1725}
1685 1726
1686sub size_request {
1687 my ($self) = @_;
1688
1689 ($self->{req_w}, $self->{req_h})
1690}
1691
1692sub size_allocate { 1727sub size_allocate {
1693 my ($self, $x, $y, $w, $h) = @_; 1728 my ($self, $w, $h) = @_;
1694 1729
1695 $self->SUPER::size_allocate ($x, $y, $w, $h); 1730 $self->SUPER::size_allocate ($w, $h);
1696 1731
1697 $self->{layout}->set_height ($self->{fontsize}); 1732 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1698 $self->{layout}->set_width ($self->{w}); 1733 $self->{layout}->set_width ($self->{children}[0]{w});
1699 1734
1700 $self->reflow; 1735 $self->reflow;
1701} 1736}
1702 1737
1703sub add_paragraph { 1738sub add_paragraph {
1885 glTranslate $sx0 - 32, $sy0 - 32, 0; 1920 glTranslate $sx0 - 32, $sy0 - 32, 0;
1886 1921
1887 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 1922 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1888 1923
1889 if ($::CFG->{fow_enable}) { 1924 if ($::CFG->{fow_enable}) {
1890 if ($::CFG->{fow_smooth}) { # smooth fog of war 1925 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
1891 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1926 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1892 glConvolutionFilter2D 1927 glConvolutionFilter2D (
1893 GL_CONVOLUTION_2D, 1928 GL_CONVOLUTION_2D,
1894 GL_ALPHA, 1929 GL_ALPHA,
1895 3, 3, 1930 3, 3,
1896 GL_ALPHA, GL_FLOAT, 1931 GL_ALPHA, GL_FLOAT,
1897 pack "f*", 1932 pack "f*",
1898 0.1, 0.1, 0.1, 1933 0.1, 0.1, 0.1,
1899 0.1, 0.2, 0.1, 1934 0.1, 0.2, 0.1,
1900 0.1, 0.1, 0.1, 1935 0.1, 0.1, 0.1,
1901 ; 1936 );
1902 glEnable GL_CONVOLUTION_2D; 1937 glEnable GL_CONVOLUTION_2D;
1903 } 1938 }
1904 1939
1905 $self->{fow_texture} = new CFClient::Texture 1940 $self->{fow_texture} = new CFClient::Texture
1906 w => $w, 1941 w => $w,
1936 $self->{mapmap_texture} = 1971 $self->{mapmap_texture} =
1937 new CFClient::Texture 1972 new CFClient::Texture
1938 w => $w, 1973 w => $w,
1939 h => $h, 1974 h => $h,
1940 data => $::MAP->mapmap ($w, $h), 1975 data => $::MAP->mapmap ($w, $h),
1941 type => GL_UNSIGNED_INT_8_8_8_8_REV; 1976 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
1942 1977
1943 $self->{mapmap_texture}->draw_quad (100, 100); 1978 $self->{mapmap_texture}->draw_quad (100, 100);
1944 1979
1945 glDisable GL_TEXTURE_2D; 1980 glDisable GL_TEXTURE_2D;
1946 glDisable GL_BLEND; 1981 glDisable GL_BLEND;
2113 2148
2114our @ISA = CFClient::UI::Container::; 2149our @ISA = CFClient::UI::Container::;
2115 2150
2116use SDL::OpenGL; 2151use SDL::OpenGL;
2117 2152
2153sub check_size {
2154 my ($self) = @_;
2155
2156 $self->configure (0, 0, $::WITH, $::HEIGHT);
2157}
2158
2118sub size_request { 2159sub size_request {
2119 ($::WIDTH, $::HEIGHT) 2160 ($::WIDTH, $::HEIGHT)
2120} 2161}
2121 2162
2122sub size_allocate { 2163sub configure {
2123 my ($self, $x, $y, $w, $h) = @_; 2164 my ($self, $x, $y, $w, $h) = @_;
2124 2165
2125 $self->_size_allocate ($x, $y, $w, $h); 2166 $self->SUPER::configure ($x, $y, $w, $h);
2126 2167
2127 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2168 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2128 for @{$self->{children}}; 2169 for @{$self->{children}};
2129} 2170}
2130 2171
2131sub _topleft { 2172sub _topleft {
2132 my ($self, $x, $y) = @_; 2173 my ($self, $x, $y) = @_;
2135} 2176}
2136 2177
2137sub update { 2178sub update {
2138 my ($self) = @_; 2179 my ($self) = @_;
2139 2180
2140 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2181 $self->check_size;
2141 ::refresh (); 2182 ::refresh ();
2142} 2183}
2143 2184
2144sub add { 2185sub add {
2145 my ($self, $widget) = @_; 2186 my ($self, $child) = @_;
2146 2187
2147 $self->SUPER::add ($widget); 2188 $self->SUPER::add ($child);
2148
2149 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2150} 2189}
2151 2190
2152sub on_refresh { 2191sub on_refresh {
2153 my ($self, $id, $cb) = @_; 2192 my ($self, $id, $cb) = @_;
2154 2193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines