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.127 by root, Mon Apr 17 21:03:31 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) = @_;
284} 300}
285 301
286sub connect { 302sub connect {
287 my ($self, $signal, $cb) = @_; 303 my ($self, $signal, $cb) = @_;
288 304
289 push @{ $self->{cb}{$signal} }, $cb; 305 push @{ $self->{signal_cb}{$signal} }, $cb;
290} 306}
291 307
292sub emit { 308sub emit {
293 my ($self, $signal, @args) = @_; 309 my ($self, $signal, @args) = @_;
294 310
311 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
295 $_->($self, @args) 312 $cb->($self, @args);
296 for @{$self->{cb}{$signal} || []}; 313 }
297} 314}
298 315
299sub DESTROY { 316sub DESTROY {
300 my ($self) = @_; 317 my ($self) = @_;
301 318
381 $self->{children} = [ 398 $self->{children} = [
382 sort { $a->{z} <=> $b->{z} } 399 sort { $a->{z} <=> $b->{z} }
383 @{$self->{children}}, $child 400 @{$self->{children}}, $child
384 ]; 401 ];
385 402
386 $self->{w} = $self->{h} = -1;
387
388 $child->check_size; 403 $child->check_size;
389} 404}
390 405
391sub remove { 406sub remove {
392 my ($self, $widget) = @_; 407 my ($self, $child) = @_;
393 408
409 delete $child->{parent};
410
394 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
395 412
396 $self->check_size; 413 $self->check_size;
397} 414}
398 415
399sub find_widget { 416sub find_widget {
431 448
432 $class->SUPER::new (children => [$child], %arg) 449 $class->SUPER::new (children => [$child], %arg)
433} 450}
434 451
435sub add { 452sub add {
436 my ($self, $widget) = @_; 453 my ($self, $child) = @_;
437 454
438 $self->{children} = []; 455 $self->{children} = [];
439 456
440 $self->SUPER::add ($widget); 457 $self->SUPER::add ($child);
441} 458}
442 459
443sub remove { 460sub remove {
444 my ($self, $widget) = @_; 461 my ($self, $widget) = @_;
445 462
454sub size_request { 471sub size_request {
455 $_[0]{children}[0]->size_request 472 $_[0]{children}[0]->size_request
456} 473}
457 474
458sub size_allocate { 475sub size_allocate {
459 my ($self, $x, $y, $w, $h) = @_; 476 my ($self, $w, $h) = @_;
460 477
461 $self->_size_allocate ($x, $y, $w, $h) or return;
462
463 $self->{children}[0]->size_allocate (0, 0, $w, $h); 478 $self->{children}[0]->configure (0, 0, $w, $h);
464} 479}
465 480
466############################################################################# 481#############################################################################
467 482
468package CFClient::UI::Window; 483package CFClient::UI::Window;
494 $self->child->draw; 509 $self->child->draw;
495 }; 510 };
496} 511}
497 512
498sub size_allocate { 513sub size_allocate {
499 my ($self, $x, $y, $w, $h) = @_; 514 my ($self, $w, $h) = @_;
500 515
501 $self->_size_allocate ($x, $y, $w, $h) or return;
502
503 $self->child->size_allocate (0, 0, $w, $h); 516 $self->child->configure (0, 0, $w, $h);
504 517
505 $self->render_chld; 518 $self->render_chld;
506} 519}
507 520
508sub _draw { 521sub _draw {
539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 552 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
540 553
541 @$self{qw(child_w child_h)} 554 @$self{qw(child_w child_h)}
542} 555}
543 556
544sub size_allocate {
545 my ($self, $x, $y, $w, $h) = @_;
546
547 $self->_size_allocate ($x, $y, $w, $h) or return;
548}
549
550sub _draw { 557sub _draw {
551 my ($self) = @_; 558 my ($self) = @_;
552 559
553 $self->{children}[1]->draw; 560 $self->{children}[1]->draw;
554} 561}
573} 580}
574 581
575sub size_allocate { 582sub size_allocate {
576 my ($self, $x, $y, $w, $h) = @_; 583 my ($self, $x, $y, $w, $h) = @_;
577 584
578 $self->_size_allocate ($x, $y, $w, $h) or return;
579
580 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 585 $self->child->configure (2, 2, $w - 4, $h - 4);
581} 586}
582 587
583sub _draw { 588sub _draw {
584 my ($self) = @_; 589 my ($self) = @_;
585 590
616 # TODO: user_x, user_y, overwrite moveto? 621 # TODO: user_x, user_y, overwrite moveto?
617 622
618 $class->SUPER::new ( 623 $class->SUPER::new (
619 bg => [1, 1, 1, 1], 624 bg => [1, 1, 1, 1],
620 border_bg => [1, 1, 1, 1], 625 border_bg => [1, 1, 1, 1],
621 border => int $::FONTSIZE * 0.8, 626 border => 0.8,
622 @_ 627 @_
623 ) 628 )
624} 629}
625 630
631sub border {
632 int $_[0]{border} * $::FONTSIZE
633}
634
626sub size_request { 635sub size_request {
627 my ($self) = @_; 636 my ($self) = @_;
628 637
629 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};
630 639
631 my ($w, $h) = $self->SUPER::size_request; 640 my ($w, $h) = $self->SUPER::size_request;
632 641
633 ( 642 (
634 $w + $self->{border} * 2, 643 $w + $self->border * 2,
635 $h + $self->{border} * 2, 644 $h + $self->border * 2,
636 ) 645 )
637} 646}
638 647
639sub size_allocate { 648sub size_allocate {
640 my ($self, $x, $y, $w, $h) = @_; 649 my ($self, $w, $h) = @_;
641 650
642 $self->_size_allocate ($x, $y, $w, $h) or return;
643
644 $h -= List::Util::max 0, $self->{border} * 2; 651 $h -= List::Util::max 0, $self->border * 2;
645 $w -= List::Util::max 0, $self->{border} * 2; 652 $w -= List::Util::max 0, $self->border * 2;
646 653
647 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 654 $self->child->configure ($self->border, $self->border, $w, $h);
648} 655}
649 656
650sub button_down { 657sub button_down {
651 my ($self, $ev, $x, $y) = @_; 658 my ($self, $ev, $x, $y) = @_;
652 659
660 my $border = $self->border;
661
653 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 662 if ($x < $self->{w} && $x >= $self->{w} - $border
654 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
655 664
656 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
657 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
658 667
659 $self->{motion} = sub { 668 $self->{motion} = sub {
661 670
662 ($x, $y) = ($ev->motion_x, $ev->motion_y); 671 ($x, $y) = ($ev->motion_x, $ev->motion_y);
663 672
664 $self->{user_w} = $bw + $x - $ox; 673 $self->{user_w} = $bw + $x - $ox;
665 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
666 $self->update; 675 $self->check_size;
667 }; 676 };
668 677
669 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
670 && $y >= 0 && $y < $self->{border}) { 679 && $y >= 0 && $y < $border) {
671 680
672 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
673 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
674 683
675 $self->{motion} = sub { 684 $self->{motion} = sub {
704 glEnable GL_BLEND; 713 glEnable GL_BLEND;
705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 714 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
706 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
707 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
708 717
718 my $border = $self->border;
719
709 glColor @{ $self->{border_bg} }; 720 glColor @{ $self->{border_bg} };
710 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 721 $tex[1]->draw_quad (0, 0, $w, $border);
711 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 722 $tex[3]->draw_quad (0, $border, $border, $ch);
712 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 723 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
713 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 724 $tex[4]->draw_quad (0, $h - $border, $w, $border);
714 725
715 my $bg = $tex[0]; 726 my $bg = $tex[0];
716 727
717 # TODO: repeat texture not scale 728 # TODO: repeat texture not scale
718 my $rep_x = $cw / $bg->{w}; 729 my $rep_x = $cw / $bg->{w};
721 glColor @{ $self->{bg} }; 732 glColor @{ $self->{bg} };
722 733
723 $bg->{s} = $rep_x; 734 $bg->{s} = $rep_x;
724 $bg->{t} = $rep_y; 735 $bg->{t} = $rep_y;
725 $bg->{wrap_mode} = 1; 736 $bg->{wrap_mode} = 1;
726 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 737 $bg->draw_quad ($border, $border, $cw, $ch);
727 738
728 glDisable GL_TEXTURE_2D; 739 glDisable GL_TEXTURE_2D;
729 glDisable GL_BLEND; 740 glDisable GL_BLEND;
730 741
731 $self->child->draw; 742 $self->child->draw;
754 my ($self, $x, $y, $child) = @_; 765 my ($self, $x, $y, $child) = @_;
755 766
756 $child->set_parent ($self); 767 $child->set_parent ($self);
757 $self->{children}[$y][$x] = $child; 768 $self->{children}[$y][$x] = $child;
758 769
759 $self->{w} = $self->{h} = -1;
760
761 $child->check_size; 770 $child->check_size;
762} 771}
763 772
764# 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?
765sub clear { 774sub clear {
801 (sum @$hs), 810 (sum @$hs),
802 ) 811 )
803} 812}
804 813
805sub size_allocate { 814sub size_allocate {
806 my ($self, $x, $y, $w, $h) = @_; 815 my ($self, $w, $h) = @_;
807
808 $self->_size_allocate ($x, $y, $w, $h) or return;
809 816
810 my ($ws, $hs) = $self->get_wh; 817 my ($ws, $hs) = $self->get_wh;
811 818
812 my $req_w = sum @$ws; 819 my $req_w = sum @$ws;
813 my $req_h = sum @$hs; 820 my $req_h = sum @$hs;
835 842
836 for my $c (0 .. $#$row) { 843 for my $c (0 .. $#$row) {
837 my $col_w = $ws->[$c]; 844 my $col_w = $ws->[$c];
838 845
839 if (my $widget = $row->[$c]) { 846 if (my $widget = $row->[$c]) {
840 $widget->size_allocate ($x, $y, $col_w, $row_h); 847 $widget->configure ($x, $y, $col_w, $row_h);
841 } 848 }
842 849
843 $x += $col_w; 850 $x += $col_w;
844 } 851 }
845 852
890 (List::Util::max map $_->[1], @alloc), 897 (List::Util::max map $_->[1], @alloc),
891 ) 898 )
892} 899}
893 900
894sub size_allocate { 901sub size_allocate {
895 my ($self, $x, $y, $w, $h) = @_; 902 my ($self, $w, $h) = @_;
896
897 $self->_size_allocate ($x, $y, $w, $h) or return;
898 903
899 ($h, $w) = ($w, $h); 904 ($h, $w) = ($w, $h);
900 905
901 my $children = $self->{children}; 906 my $children = $self->{children};
902 907
924 929
925 my $y = 0; 930 my $y = 0;
926 for (0 .. $#$children) { 931 for (0 .. $#$children) {
927 my $child = $children->[$_]; 932 my $child = $children->[$_];
928 my $h = $h[$_]; 933 my $h = $h[$_];
929 $child->size_allocate ($y, 0, $h, $w); 934 $child->configure ($y, 0, $h, $w);
930 935
931 $y += $h; 936 $y += $h;
932 } 937 }
933 938
934 1 939 1
952 (List::Util::sum map $_->[1], @alloc), 957 (List::Util::sum map $_->[1], @alloc),
953 ) 958 )
954} 959}
955 960
956sub size_allocate { 961sub size_allocate {
957 my ($self, $x, $y, $w, $h) = @_; 962 my ($self, $w, $h) = @_;
958
959 $self->_size_allocate ($x, $y, $w, $h) or return;
960 963
961 my $children = $self->{children}; 964 my $children = $self->{children};
962 965
963 my @h = map +($_->size_request)[1], @$children; 966 my @h = map +($_->size_request)[1], @$children;
964 967
982 985
983 my $y = 0; 986 my $y = 0;
984 for (0 .. $#$children) { 987 for (0 .. $#$children) {
985 my $child = $children->[$_]; 988 my $child = $children->[$_];
986 my $h = $h[$_]; 989 my $h = $h[$_];
987 $child->size_allocate (0, $y, $w, $h); 990 $child->configure (0, $y, $w, $h);
988 991
989 $y += $h; 992 $y += $h;
990 } 993 }
991 994
992 1 995 1
1003sub new { 1006sub new {
1004 my ($class, %arg) = @_; 1007 my ($class, %arg) = @_;
1005 1008
1006 my $self = $class->SUPER::new ( 1009 my $self = $class->SUPER::new (
1007 fg => [1, 1, 1], 1010 fg => [1, 1, 1],
1008 fontsize => $::FONTSIZE, 1011 fontsize => 1,
1009 text => "", 1012 text => "",
1010 align => -1, 1013 align => -1,
1011 valign => -1, 1014 valign => -1,
1012 padding => 2, 1015 padding => 2,
1013 layout => new CFClient::Layout, 1016 layout => new CFClient::Layout,
1052 1055
1053sub size_request { 1056sub size_request {
1054 my ($self) = @_; 1057 my ($self) = @_;
1055 1058
1056 $self->{layout}->set_width; 1059 $self->{layout}->set_width;
1057 $self->{layout}->set_height ($self->{fontsize}); 1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1058 1061
1059 my ($w, $h) = $self->{layout}->size; 1062 my ($w, $h) = $self->{layout}->size;
1060 1063
1061 ( 1064 (
1062 $w + $self->{padding} * 2, 1065 $w + $self->{padding} * 2,
1063 $h + $self->{padding} * 2, 1066 $h + $self->{padding} * 2,
1064 ) 1067 )
1065} 1068}
1066 1069
1067sub size_allocate { 1070sub size_allocate {
1068 my ($self, $x, $y, $w, $h) = @_; 1071 my ($self, $w, $h) = @_;
1069
1070 $self->_size_allocate ($x, $y, $w, $h) or return;
1071 1072
1072 delete $self->{texture}; 1073 delete $self->{texture};
1073}
1074
1075sub update {
1076 my ($self) = @_;
1077
1078 delete $self->{texture};
1079 $self->SUPER::update;
1080} 1074}
1081 1075
1082sub _draw { 1076sub _draw {
1083 my ($self) = @_; 1077 my ($self) = @_;
1084 1078
1085 my $tex = $self->{texture} ||= do { 1079 my $tex = $self->{texture} ||= do {
1086 $self->{layout}->set_width ($self->{w}); 1080 $self->{layout}->set_width ($self->{w});
1087 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1088 new_from_layout CFClient::Texture $self->{layout} 1082 new_from_layout CFClient::Texture $self->{layout}
1089 }; 1083 };
1090 1084
1091 glEnable GL_BLEND; 1085 glEnable GL_BLEND;
1092 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1086 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1142 1136
1143 delete $self->{cur_h}; 1137 delete $self->{cur_h};
1144 1138
1145 return if $self->{text} eq $text; 1139 return if $self->{text} eq $text;
1146 1140
1141 delete $self->{texture};
1142
1147 $self->{last_activity} = $::NOW; 1143 $self->{last_activity} = $::NOW;
1148 $self->{text} = $text; 1144 $self->{text} = $text;
1149 1145
1150 $text =~ s/./*/g if $self->{hidden}; 1146 $text =~ s/./*/g if $self->{hidden};
1151 $self->{layout}->set_text ("$text "); 1147 $self->{layout}->set_text ("$text ");
1164 1160
1165 ($w + 1, $h) # add 1 for cursor 1161 ($w + 1, $h) # add 1 for cursor
1166} 1162}
1167 1163
1168sub size_allocate { 1164sub size_allocate {
1169 my ($self, $x, $y, $w, $h) = @_; 1165 my ($self, $w, $h) = @_;
1170
1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1172 1166
1173 $self->_set_text ($self->{text}); 1167 $self->_set_text ($self->{text});
1174} 1168}
1175 1169
1176sub set_text { 1170sub set_text {
1394 1388
1395sub size_request { 1389sub size_request {
1396 my ($self) = @_; 1390 my ($self) = @_;
1397 1391
1398 ($self->{padding} * 2 + 6) x 2 1392 ($self->{padding} * 2 + 6) x 2
1399}
1400
1401sub size_allocate {
1402 my ($self, $x, $y, $w, $h) = @_;
1403
1404 $self->_size_allocate ($x, $y, $w, $h) or return;
1405} 1393}
1406 1394
1407sub button_down { 1395sub button_down {
1408 my ($self, $ev, $x, $y) = @_; 1396 my ($self, $ev, $x, $y) = @_;
1409 1397
1520 my $h1 = $self->{h} - $ycut * $self->{h}; 1508 my $h1 = $self->{h} - $ycut * $self->{h};
1521 my $h2 = $ycut * $self->{h}; 1509 my $h2 = $ycut * $self->{h};
1522 1510
1523 my $yp = 0; 1511 my $yp = 0;
1524 1512
1525 glBindTexture (GL_TEXTURE_2D, $t1->{name}); 1513 glBindTexture GL_TEXTURE_2D, $t1->{name};
1526 glBegin (GL_QUADS); 1514 glBegin GL_QUADS;
1527 glTexCoord (0, 0); glVertex (0 , $yp); 1515 glTexCoord 0 , 0; glVertex 0 , $yp;
1528 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); 1516 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1529 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); 1517 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1530 glTexCoord (1, 0); glVertex (0 + $w, $yp); 1518 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1531 glEnd (); 1519 glEnd;
1532 1520
1533 $yp += $h1; 1521 $yp += $h1;
1534 1522
1535 glBindTexture (GL_TEXTURE_2D, $t2->{name}); 1523 glBindTexture GL_TEXTURE_2D, $t2->{name};
1536 glBegin (GL_QUADS); 1524 glBegin GL_QUADS;
1537 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); 1525 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1538 glTexCoord (0, 1); glVertex (0 , $yp + $h2); 1526 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1539 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); 1527 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1540 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); 1528 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1541 glEnd (); 1529 glEnd;
1542 1530
1543 glDisable GL_BLEND; 1531 glDisable GL_BLEND;
1544 glDisable GL_TEXTURE_2D; 1532 glDisable GL_TEXTURE_2D;
1545} 1533}
1546 1534
1568 # TODO: calculations are off 1556 # TODO: calculations are off
1569 my $self = $class->SUPER::new ( 1557 my $self = $class->SUPER::new (
1570 fg => [1, 1, 1], 1558 fg => [1, 1, 1],
1571 active_fg => [0, 0, 0], 1559 active_fg => [0, 0, 0],
1572 range => [0, 0, 100, 10], 1560 range => [0, 0, 100, 10],
1573 req_w => 40, 1561 req_w => 20,
1574 req_h => 13, 1562 req_h => 20,
1575 vertical => 0, 1563 vertical => 0,
1576 can_hover => 1, 1564 can_hover => 1,
1577 inner_pad => 5, 1565 inner_pad => 5,
1578 @_ 1566 @_
1579 ); 1567 );
1689 1677
1690sub new { 1678sub new {
1691 my $class = shift; 1679 my $class = shift;
1692 1680
1693 my $self = $class->SUPER::new ( 1681 my $self = $class->SUPER::new (
1694 req_w => $::WIDTH / 6,
1695 req_h => $::HEIGHT / 6,
1696 fontsize => $::FONTSIZE, 1682 fontsize => 1,
1697 @_, 1683 @_,
1698 1684
1699 layout => (new CFClient::Layout), 1685 layout => (new CFClient::Layout),
1700 par => [], 1686 par => [],
1701 height => 0, 1687 height => 0,
1722sub text_height { 1708sub text_height {
1723 my ($self, $text) = @_; 1709 my ($self, $text) = @_;
1724 1710
1725 my $layout = $self->{layout}; 1711 my $layout = $self->{layout};
1726 1712
1727 $layout->set_height ($self->{fontsize}); 1713 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1728 $layout->set_width ($self->{w}); 1714 $layout->set_width ($self->{w});
1729 $layout->set_text ($text); 1715 $layout->set_text ($text);
1730 1716
1731 ($layout->size)[1] 1717 ($layout->size)[1]
1732} 1718}
1736 1722
1737 $self->{need_reflow}++; 1723 $self->{need_reflow}++;
1738 $self->update; 1724 $self->update;
1739} 1725}
1740 1726
1741sub size_request {
1742 my ($self) = @_;
1743
1744 ($self->{req_w}, $self->{req_h})
1745}
1746
1747sub size_allocate { 1727sub size_allocate {
1748 my ($self, $x, $y, $w, $h) = @_; 1728 my ($self, $w, $h) = @_;
1749 1729
1750 $self->SUPER::size_allocate ($x, $y, $w, $h) or return; 1730 $self->SUPER::size_allocate ($w, $h);
1751 1731
1752 $self->{layout}->set_height ($self->{fontsize}); 1732 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1753 $self->{layout}->set_width ($self->{w}); 1733 $self->{layout}->set_width ($self->{children}[0]{w});
1754 1734
1755 $self->reflow; 1735 $self->reflow;
1756 $self->update;
1757} 1736}
1758 1737
1759sub add_paragraph { 1738sub add_paragraph {
1760 my ($self, $color, $text) = @_; 1739 my ($self, $color, $text) = @_;
1761 1740
1941 glTranslate $sx0 - 32, $sy0 - 32, 0; 1920 glTranslate $sx0 - 32, $sy0 - 32, 0;
1942 1921
1943 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);
1944 1923
1945 if ($::CFG->{fow_enable}) { 1924 if ($::CFG->{fow_enable}) {
1946 if ($::CFG->{fow_smooth}) { # smooth fog of war 1925 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
1947 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1926 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1948 glConvolutionFilter2D 1927 glConvolutionFilter2D (
1949 GL_CONVOLUTION_2D, 1928 GL_CONVOLUTION_2D,
1950 GL_ALPHA, 1929 GL_ALPHA,
1951 3, 3, 1930 3, 3,
1952 GL_ALPHA, GL_FLOAT, 1931 GL_ALPHA, GL_FLOAT,
1953 pack "f*", 1932 pack "f*",
1954 0.1, 0.1, 0.1, 1933 0.1, 0.1, 0.1,
1955 0.1, 0.2, 0.1, 1934 0.1, 0.2, 0.1,
1956 0.1, 0.1, 0.1, 1935 0.1, 0.1, 0.1,
1957 ; 1936 );
1958 glEnable GL_CONVOLUTION_2D; 1937 glEnable GL_CONVOLUTION_2D;
1959 } 1938 }
1960 1939
1961 $self->{fow_texture} = new CFClient::Texture 1940 $self->{fow_texture} = new CFClient::Texture
1962 w => $w, 1941 w => $w,
1992 $self->{mapmap_texture} = 1971 $self->{mapmap_texture} =
1993 new CFClient::Texture 1972 new CFClient::Texture
1994 w => $w, 1973 w => $w,
1995 h => $h, 1974 h => $h,
1996 data => $::MAP->mapmap ($w, $h), 1975 data => $::MAP->mapmap ($w, $h),
1997 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;
1998 1977
1999 $self->{mapmap_texture}->draw_quad (100, 100); 1978 $self->{mapmap_texture}->draw_quad (100, 100);
2000 1979
2001 glDisable GL_TEXTURE_2D; 1980 glDisable GL_TEXTURE_2D;
2002 glDisable GL_BLEND; 1981 glDisable GL_BLEND;
2172use SDL::OpenGL; 2151use SDL::OpenGL;
2173 2152
2174sub check_size { 2153sub check_size {
2175 my ($self) = @_; 2154 my ($self) = @_;
2176 2155
2177 $self->size_allocate (0, 0, $::WITH, $::HEIGHT); 2156 $self->configure (0, 0, $::WITH, $::HEIGHT);
2178} 2157}
2179 2158
2180sub size_request { 2159sub size_request {
2181 ($::WIDTH, $::HEIGHT) 2160 ($::WIDTH, $::HEIGHT)
2182} 2161}
2183 2162
2184sub size_allocate { 2163sub configure {
2185 my ($self, $x, $y, $w, $h) = @_; 2164 my ($self, $x, $y, $w, $h) = @_;
2186 2165
2187 $self->_size_allocate ($x, $y, $w, $h); 2166 $self->SUPER::configure ($x, $y, $w, $h);
2188 2167
2189 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2168 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2190 for @{$self->{children}}; 2169 for @{$self->{children}};
2191} 2170}
2192 2171
2193sub _topleft { 2172sub _topleft {
2194 my ($self, $x, $y) = @_; 2173 my ($self, $x, $y) = @_;
2202 $self->check_size; 2181 $self->check_size;
2203 ::refresh (); 2182 ::refresh ();
2204} 2183}
2205 2184
2206sub add { 2185sub add {
2207 my ($self, $widget) = @_; 2186 my ($self, $child) = @_;
2208 2187
2209 $self->SUPER::add ($widget); 2188 $self->SUPER::add ($child);
2210
2211 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2212} 2189}
2213 2190
2214sub on_refresh { 2191sub on_refresh {
2215 my ($self, $id, $cb) = @_; 2192 my ($self, $id, $cb) = @_;
2216 2193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines