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.125 by root, Mon Apr 17 20:52:15 2006 UTC vs.
Revision 1.130 by root, Tue Apr 18 01:51:06 2006 UTC

112 $self 112 $self
113} 113}
114 114
115sub move { 115sub move {
116 my ($self, $x, $y, $z) = @_; 116 my ($self, $x, $y, $z) = @_;
117
117 $self->{x} = int $x; 118 $self->{x} = int $x;
118 $self->{y} = int $y; 119 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 120 $self->{z} = $z if defined $z;
121
122 $self->update;
120} 123}
121 124
122sub needs_redraw { 125sub needs_redraw {
123 0 126 0
124} 127}
126sub size_request { 129sub size_request {
127 require Carp; 130 require Carp;
128 Carp::confess "size_request is abtract"; 131 Carp::confess "size_request is abtract";
129} 132}
130 133
131sub _size_allocate { 134sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 135 my ($self, $x, $y, $w, $h) = @_;
133 136
134 $self->{x} = $x; 137 $self->{x} = $x;
135 $self->{y} = $y; 138 $self->{y} = $y;
136 139
137 return unless $self->{w} != $w || $self->{h} != $h; 140 return unless $self->{w} != $w || $self->{h} != $h;
138 141
139 $self->{w} = $w; 142 $self->{w} = $w;
140 $self->{h} = $h; 143 $self->{h} = $h;
141 144
142 1 145 $self->size_allocate ($w, $h);
143} 146}
144 147
145sub size_allocate { 148sub size_allocate {
146 my ($self, $x, $y, $w, $h) = @_; 149 # nothing to be done
147
148 $self->_size_allocate ($x, $y, $w, $h);
149} 150}
150 151
151# return top left coordinates 152# return top left coordinates
152sub _topleft { 153sub _topleft {
153 my ($self, $x, $y) = @_; 154 my ($self, $x, $y) = @_;
271 $self->{req_w} = $w; 272 $self->{req_w} = $w;
272 $self->{req_h} = $h; 273 $self->{req_h} = $h;
273 274
274 $self->{parent}->check_size 275 $self->{parent}->check_size
275 if $self->{parent}; 276 if $self->{parent};
277
278 $self->size_allocate ($w, $h);
279 $self->update;
276 } 280 }
277} 281}
278 282
279sub update { 283sub update {
280 my ($self) = @_; 284 my ($self) = @_;
382 sort { $a->{z} <=> $b->{z} } 386 sort { $a->{z} <=> $b->{z} }
383 @{$self->{children}}, $child 387 @{$self->{children}}, $child
384 ]; 388 ];
385 389
386 $self->{w} = $self->{h} = -1; 390 $self->{w} = $self->{h} = -1;
387 $self->update; 391
392 $child->check_size;
388} 393}
389 394
390sub remove { 395sub remove {
391 my ($self, $widget) = @_; 396 my ($self, $widget) = @_;
392 397
453sub size_request { 458sub size_request {
454 $_[0]{children}[0]->size_request 459 $_[0]{children}[0]->size_request
455} 460}
456 461
457sub size_allocate { 462sub size_allocate {
458 my ($self, $x, $y, $w, $h) = @_; 463 my ($self, $w, $h) = @_;
459 464
460 $self->_size_allocate ($x, $y, $w, $h) or return;
461
462 $self->{children}[0]->size_allocate (0, 0, $w, $h); 465 $self->{children}[0]->configure (0, 0, $w, $h);
463} 466}
464 467
465############################################################################# 468#############################################################################
466 469
467package CFClient::UI::Window; 470package CFClient::UI::Window;
493 $self->child->draw; 496 $self->child->draw;
494 }; 497 };
495} 498}
496 499
497sub size_allocate { 500sub size_allocate {
498 my ($self, $x, $y, $w, $h) = @_; 501 my ($self, $w, $h) = @_;
499 502
500 $self->_size_allocate ($x, $y, $w, $h) or return;
501
502 $self->child->size_allocate (0, 0, $w, $h); 503 $self->child->configure (0, 0, $w, $h);
503 504
504 $self->render_chld; 505 $self->render_chld;
505} 506}
506 507
507sub _draw { 508sub _draw {
538 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
539 540
540 @$self{qw(child_w child_h)} 541 @$self{qw(child_w child_h)}
541} 542}
542 543
543sub size_allocate {
544 my ($self, $x, $y, $w, $h) = @_;
545
546 $self->_size_allocate ($x, $y, $w, $h) or return;
547}
548
549sub _draw { 544sub _draw {
550 my ($self) = @_; 545 my ($self) = @_;
551 546
552 $self->{children}[1]->draw; 547 $self->{children}[1]->draw;
553} 548}
572} 567}
573 568
574sub size_allocate { 569sub size_allocate {
575 my ($self, $x, $y, $w, $h) = @_; 570 my ($self, $x, $y, $w, $h) = @_;
576 571
577 $self->_size_allocate ($x, $y, $w, $h) or return;
578
579 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 572 $self->child->configure (2, 2, $w - 4, $h - 4);
580} 573}
581 574
582sub _draw { 575sub _draw {
583 my ($self) = @_; 576 my ($self) = @_;
584 577
634 $h + $self->{border} * 2, 627 $h + $self->{border} * 2,
635 ) 628 )
636} 629}
637 630
638sub size_allocate { 631sub size_allocate {
639 my ($self, $x, $y, $w, $h) = @_; 632 my ($self, $w, $h) = @_;
640
641 $self->_size_allocate ($x, $y, $w, $h) or return;
642 633
643 $h -= List::Util::max 0, $self->{border} * 2; 634 $h -= List::Util::max 0, $self->{border} * 2;
644 $w -= List::Util::max 0, $self->{border} * 2; 635 $w -= List::Util::max 0, $self->{border} * 2;
645 636
646 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 637 $self->child->configure ($self->{border}, $self->{border}, $w, $h);
647} 638}
648 639
649sub button_down { 640sub button_down {
650 my ($self, $ev, $x, $y) = @_; 641 my ($self, $ev, $x, $y) = @_;
651 642
660 651
661 ($x, $y) = ($ev->motion_x, $ev->motion_y); 652 ($x, $y) = ($ev->motion_x, $ev->motion_y);
662 653
663 $self->{user_w} = $bw + $x - $ox; 654 $self->{user_w} = $bw + $x - $ox;
664 $self->{user_h} = $bh + $y - $oy; 655 $self->{user_h} = $bh + $y - $oy;
665 $self->update; 656 $self->check_size;
666 }; 657 };
667 658
668 } elsif ($x >= 0 && $x < $self->{w} 659 } elsif ($x >= 0 && $x < $self->{w}
669 && $y >= 0 && $y < $self->{border}) { 660 && $y >= 0 && $y < $self->{border}) {
670 661
754 745
755 $child->set_parent ($self); 746 $child->set_parent ($self);
756 $self->{children}[$y][$x] = $child; 747 $self->{children}[$y][$x] = $child;
757 748
758 $self->{w} = $self->{h} = -1; 749 $self->{w} = $self->{h} = -1;
759 $self->update; 750
751 $child->check_size;
760} 752}
761 753
762# TODO: move to container class maybe? send childs a signal on removal? 754# TODO: move to container class maybe? send childs a signal on removal?
763sub clear { 755sub clear {
764 my ($self) = @_; 756 my ($self) = @_;
799 (sum @$hs), 791 (sum @$hs),
800 ) 792 )
801} 793}
802 794
803sub size_allocate { 795sub size_allocate {
804 my ($self, $x, $y, $w, $h) = @_; 796 my ($self, $w, $h) = @_;
805
806 $self->_size_allocate ($x, $y, $w, $h) or return;
807 797
808 my ($ws, $hs) = $self->get_wh; 798 my ($ws, $hs) = $self->get_wh;
809 799
810 my $req_w = sum @$ws; 800 my $req_w = sum @$ws;
811 my $req_h = sum @$hs; 801 my $req_h = sum @$hs;
833 823
834 for my $c (0 .. $#$row) { 824 for my $c (0 .. $#$row) {
835 my $col_w = $ws->[$c]; 825 my $col_w = $ws->[$c];
836 826
837 if (my $widget = $row->[$c]) { 827 if (my $widget = $row->[$c]) {
838 $widget->size_allocate ($x, $y, $col_w, $row_h); 828 $widget->configure ($x, $y, $col_w, $row_h);
839 } 829 }
840 830
841 $x += $col_w; 831 $x += $col_w;
842 } 832 }
843 833
888 (List::Util::max map $_->[1], @alloc), 878 (List::Util::max map $_->[1], @alloc),
889 ) 879 )
890} 880}
891 881
892sub size_allocate { 882sub size_allocate {
893 my ($self, $x, $y, $w, $h) = @_; 883 my ($self, $w, $h) = @_;
894
895 $self->_size_allocate ($x, $y, $w, $h) or return;
896 884
897 ($h, $w) = ($w, $h); 885 ($h, $w) = ($w, $h);
898 886
899 my $children = $self->{children}; 887 my $children = $self->{children};
900 888
922 910
923 my $y = 0; 911 my $y = 0;
924 for (0 .. $#$children) { 912 for (0 .. $#$children) {
925 my $child = $children->[$_]; 913 my $child = $children->[$_];
926 my $h = $h[$_]; 914 my $h = $h[$_];
927 $child->size_allocate ($y, 0, $h, $w); 915 $child->configure ($y, 0, $h, $w);
928 916
929 $y += $h; 917 $y += $h;
930 } 918 }
931 919
932 1 920 1
950 (List::Util::sum map $_->[1], @alloc), 938 (List::Util::sum map $_->[1], @alloc),
951 ) 939 )
952} 940}
953 941
954sub size_allocate { 942sub size_allocate {
955 my ($self, $x, $y, $w, $h) = @_; 943 my ($self, $w, $h) = @_;
956
957 $self->_size_allocate ($x, $y, $w, $h) or return;
958 944
959 my $children = $self->{children}; 945 my $children = $self->{children};
960 946
961 my @h = map +($_->size_request)[1], @$children; 947 my @h = map +($_->size_request)[1], @$children;
962 948
980 966
981 my $y = 0; 967 my $y = 0;
982 for (0 .. $#$children) { 968 for (0 .. $#$children) {
983 my $child = $children->[$_]; 969 my $child = $children->[$_];
984 my $h = $h[$_]; 970 my $h = $h[$_];
985 $child->size_allocate (0, $y, $w, $h); 971 $child->configure (0, $y, $w, $h);
986 972
987 $y += $h; 973 $y += $h;
988 } 974 }
989 975
990 1 976 1
1061 $h + $self->{padding} * 2, 1047 $h + $self->{padding} * 2,
1062 ) 1048 )
1063} 1049}
1064 1050
1065sub size_allocate { 1051sub size_allocate {
1066 my ($self, $x, $y, $w, $h) = @_; 1052 my ($self, $w, $h) = @_;
1067
1068 $self->_size_allocate ($x, $y, $w, $h) or return;
1069 1053
1070 delete $self->{texture}; 1054 delete $self->{texture};
1071} 1055}
1072 1056
1073sub update { 1057sub update {
1162 1146
1163 ($w + 1, $h) # add 1 for cursor 1147 ($w + 1, $h) # add 1 for cursor
1164} 1148}
1165 1149
1166sub size_allocate { 1150sub size_allocate {
1167 my ($self, $x, $y, $w, $h) = @_; 1151 my ($self, $w, $h) = @_;
1168
1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1170 1152
1171 $self->_set_text ($self->{text}); 1153 $self->_set_text ($self->{text});
1172} 1154}
1173 1155
1174sub set_text { 1156sub set_text {
1324 padding => 4, 1306 padding => 4,
1325 fg => [1, 1, 1], 1307 fg => [1, 1, 1],
1326 bg => [1, 1, 1, 0.2], 1308 bg => [1, 1, 1, 0.2],
1327 active_fg => [0, 0, 1], 1309 active_fg => [0, 0, 1],
1328 can_hover => 1, 1310 can_hover => 1,
1311 align => 0,
1312 valign => 0,
1329 @_ 1313 @_
1330 ) 1314 )
1331} 1315}
1332 1316
1333sub button_up { 1317sub button_up {
1390 1374
1391sub size_request { 1375sub size_request {
1392 my ($self) = @_; 1376 my ($self) = @_;
1393 1377
1394 ($self->{padding} * 2 + 6) x 2 1378 ($self->{padding} * 2 + 6) x 2
1395}
1396
1397sub size_allocate {
1398 my ($self, $x, $y, $w, $h) = @_;
1399
1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1401} 1379}
1402 1380
1403sub button_down { 1381sub button_down {
1404 my ($self, $ev, $x, $y) = @_; 1382 my ($self, $ev, $x, $y) = @_;
1405 1383
1470} 1448}
1471 1449
1472sub size_request { 1450sub size_request {
1473 my ($self) = @_; 1451 my ($self) = @_;
1474 1452
1475 ($self->{w}, $self->{h}) 1453 my $tex = $tex{$self->{gauge}}[0];
1454
1455 @$tex{qw(w h)}
1476} 1456}
1477 1457
1478sub set_max { 1458sub set_max {
1479 my ($self, $max) = @_; 1459 my ($self, $max) = @_;
1460
1480 $self->{max_val} = $max; 1461 $self->{max_val} = $max;
1481} 1462}
1482 1463
1483sub set_value { 1464sub set_value {
1484 my ($self, $val, $max) = @_; 1465 my ($self, $val, $max) = @_;
1736 1717
1737 ($self->{req_w}, $self->{req_h}) 1718 ($self->{req_w}, $self->{req_h})
1738} 1719}
1739 1720
1740sub size_allocate { 1721sub size_allocate {
1741 my ($self, $x, $y, $w, $h) = @_; 1722 my ($self, $w, $h) = @_;
1742
1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1744 1723
1745 $self->{layout}->set_height ($self->{fontsize}); 1724 $self->{layout}->set_height ($self->{fontsize});
1746 $self->{layout}->set_width ($self->{w}); 1725 $self->{layout}->set_width ($self->{w});
1747 1726
1748 $self->reflow; 1727 $self->reflow;
1935 1914
1936 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 1915 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1937 1916
1938 if ($::CFG->{fow_enable}) { 1917 if ($::CFG->{fow_enable}) {
1939 if ($::CFG->{fow_smooth}) { # smooth fog of war 1918 if ($::CFG->{fow_smooth}) { # smooth fog of war
1940 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1919 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1941 glConvolutionFilter2D 1920 glConvolutionFilter2D (
1942 GL_CONVOLUTION_2D, 1921 GL_CONVOLUTION_2D,
1943 GL_ALPHA, 1922 GL_ALPHA,
1944 3, 3, 1923 3, 3,
1945 GL_ALPHA, GL_FLOAT, 1924 GL_ALPHA, GL_FLOAT,
1946 pack "f*", 1925 pack "f*",
1947 0.1, 0.1, 0.1, 1926 0.1, 0.1, 0.1,
1948 0.1, 0.2, 0.1, 1927 0.1, 0.2, 0.1,
1949 0.1, 0.1, 0.1, 1928 0.1, 0.1, 0.1,
1950 ; 1929 );
1951 glEnable GL_CONVOLUTION_2D; 1930 glEnable GL_CONVOLUTION_2D;
1952 } 1931 }
1953 1932
1954 $self->{fow_texture} = new CFClient::Texture 1933 $self->{fow_texture} = new CFClient::Texture
1955 w => $w, 1934 w => $w,
1985 $self->{mapmap_texture} = 1964 $self->{mapmap_texture} =
1986 new CFClient::Texture 1965 new CFClient::Texture
1987 w => $w, 1966 w => $w,
1988 h => $h, 1967 h => $h,
1989 data => $::MAP->mapmap ($w, $h), 1968 data => $::MAP->mapmap ($w, $h),
1990 type => GL_UNSIGNED_INT_8_8_8_8_REV; 1969 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
1991 1970
1992 $self->{mapmap_texture}->draw_quad (100, 100); 1971 $self->{mapmap_texture}->draw_quad (100, 100);
1993 1972
1994 glDisable GL_TEXTURE_2D; 1973 glDisable GL_TEXTURE_2D;
1995 glDisable GL_BLEND; 1974 glDisable GL_BLEND;
2165use SDL::OpenGL; 2144use SDL::OpenGL;
2166 2145
2167sub check_size { 2146sub check_size {
2168 my ($self) = @_; 2147 my ($self) = @_;
2169 2148
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT); 2149 $self->configure (0, 0, $::WITH, $::HEIGHT);
2171} 2150}
2172 2151
2173sub size_request { 2152sub size_request {
2174 ($::WIDTH, $::HEIGHT) 2153 ($::WIDTH, $::HEIGHT)
2175} 2154}
2176 2155
2177sub size_allocate { 2156sub configure {
2178 my ($self, $x, $y, $w, $h) = @_; 2157 my ($self, $x, $y, $w, $h) = @_;
2179 2158
2180 $self->_size_allocate ($x, $y, $w, $h); 2159 $self->SUPER::configure ($x, $y, $w, $h);
2181 2160
2182 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2161 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2183 for @{$self->{children}}; 2162 for @{$self->{children}};
2184} 2163}
2185 2164
2186sub _topleft { 2165sub _topleft {
2187 my ($self, $x, $y) = @_; 2166 my ($self, $x, $y) = @_;
2195 $self->check_size; 2174 $self->check_size;
2196 ::refresh (); 2175 ::refresh ();
2197} 2176}
2198 2177
2199sub add { 2178sub add {
2200 my ($self, $widget) = @_; 2179 my ($self, $child) = @_;
2201 2180
2202 $self->SUPER::add ($widget); 2181 $self->SUPER::add ($child);
2203
2204 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2205} 2182}
2206 2183
2207sub on_refresh { 2184sub on_refresh {
2208 my ($self, $id, $cb) = @_; 2185 my ($self, $id, $cb) = @_;
2209 2186

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines