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.133 by root, Tue Apr 18 21:39:31 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) = @_;
284} 288}
285 289
286sub connect { 290sub connect {
287 my ($self, $signal, $cb) = @_; 291 my ($self, $signal, $cb) = @_;
288 292
289 push @{ $self->{cb}{$signal} }, $cb; 293 push @{ $self->{signal_cb}{$signal} }, $cb;
290} 294}
291 295
292sub emit { 296sub emit {
293 my ($self, $signal, @args) = @_; 297 my ($self, $signal, @args) = @_;
294 298
299 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
295 $_->($self, @args) 300 $cb->($self, @args);
296 for @{$self->{cb}{$signal} || []}; 301 }
297} 302}
298 303
299sub DESTROY { 304sub DESTROY {
300 my ($self) = @_; 305 my ($self) = @_;
301 306
454sub size_request { 459sub size_request {
455 $_[0]{children}[0]->size_request 460 $_[0]{children}[0]->size_request
456} 461}
457 462
458sub size_allocate { 463sub size_allocate {
459 my ($self, $x, $y, $w, $h) = @_; 464 my ($self, $w, $h) = @_;
460 465
461 $self->_size_allocate ($x, $y, $w, $h) or return;
462
463 $self->{children}[0]->size_allocate (0, 0, $w, $h); 466 $self->{children}[0]->configure (0, 0, $w, $h);
464} 467}
465 468
466############################################################################# 469#############################################################################
467 470
468package CFClient::UI::Window; 471package CFClient::UI::Window;
494 $self->child->draw; 497 $self->child->draw;
495 }; 498 };
496} 499}
497 500
498sub size_allocate { 501sub size_allocate {
499 my ($self, $x, $y, $w, $h) = @_; 502 my ($self, $w, $h) = @_;
500 503
501 $self->_size_allocate ($x, $y, $w, $h) or return;
502
503 $self->child->size_allocate (0, 0, $w, $h); 504 $self->child->configure (0, 0, $w, $h);
504 505
505 $self->render_chld; 506 $self->render_chld;
506} 507}
507 508
508sub _draw { 509sub _draw {
539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 540 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
540 541
541 @$self{qw(child_w child_h)} 542 @$self{qw(child_w child_h)}
542} 543}
543 544
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 { 545sub _draw {
551 my ($self) = @_; 546 my ($self) = @_;
552 547
553 $self->{children}[1]->draw; 548 $self->{children}[1]->draw;
554} 549}
573} 568}
574 569
575sub size_allocate { 570sub size_allocate {
576 my ($self, $x, $y, $w, $h) = @_; 571 my ($self, $x, $y, $w, $h) = @_;
577 572
578 $self->_size_allocate ($x, $y, $w, $h) or return;
579
580 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 573 $self->child->configure (2, 2, $w - 4, $h - 4);
581} 574}
582 575
583sub _draw { 576sub _draw {
584 my ($self) = @_; 577 my ($self) = @_;
585 578
635 $h + $self->{border} * 2, 628 $h + $self->{border} * 2,
636 ) 629 )
637} 630}
638 631
639sub size_allocate { 632sub size_allocate {
640 my ($self, $x, $y, $w, $h) = @_; 633 my ($self, $w, $h) = @_;
641
642 $self->_size_allocate ($x, $y, $w, $h) or return;
643 634
644 $h -= List::Util::max 0, $self->{border} * 2; 635 $h -= List::Util::max 0, $self->{border} * 2;
645 $w -= List::Util::max 0, $self->{border} * 2; 636 $w -= List::Util::max 0, $self->{border} * 2;
646 637
647 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 638 $self->child->configure ($self->{border}, $self->{border}, $w, $h);
648} 639}
649 640
650sub button_down { 641sub button_down {
651 my ($self, $ev, $x, $y) = @_; 642 my ($self, $ev, $x, $y) = @_;
652 643
661 652
662 ($x, $y) = ($ev->motion_x, $ev->motion_y); 653 ($x, $y) = ($ev->motion_x, $ev->motion_y);
663 654
664 $self->{user_w} = $bw + $x - $ox; 655 $self->{user_w} = $bw + $x - $ox;
665 $self->{user_h} = $bh + $y - $oy; 656 $self->{user_h} = $bh + $y - $oy;
666 $self->update; 657 $self->check_size;
667 }; 658 };
668 659
669 } elsif ($x >= 0 && $x < $self->{w} 660 } elsif ($x >= 0 && $x < $self->{w}
670 && $y >= 0 && $y < $self->{border}) { 661 && $y >= 0 && $y < $self->{border}) {
671 662
801 (sum @$hs), 792 (sum @$hs),
802 ) 793 )
803} 794}
804 795
805sub size_allocate { 796sub size_allocate {
806 my ($self, $x, $y, $w, $h) = @_; 797 my ($self, $w, $h) = @_;
807
808 $self->_size_allocate ($x, $y, $w, $h) or return;
809 798
810 my ($ws, $hs) = $self->get_wh; 799 my ($ws, $hs) = $self->get_wh;
811 800
812 my $req_w = sum @$ws; 801 my $req_w = sum @$ws;
813 my $req_h = sum @$hs; 802 my $req_h = sum @$hs;
835 824
836 for my $c (0 .. $#$row) { 825 for my $c (0 .. $#$row) {
837 my $col_w = $ws->[$c]; 826 my $col_w = $ws->[$c];
838 827
839 if (my $widget = $row->[$c]) { 828 if (my $widget = $row->[$c]) {
840 $widget->size_allocate ($x, $y, $col_w, $row_h); 829 $widget->configure ($x, $y, $col_w, $row_h);
841 } 830 }
842 831
843 $x += $col_w; 832 $x += $col_w;
844 } 833 }
845 834
890 (List::Util::max map $_->[1], @alloc), 879 (List::Util::max map $_->[1], @alloc),
891 ) 880 )
892} 881}
893 882
894sub size_allocate { 883sub size_allocate {
895 my ($self, $x, $y, $w, $h) = @_; 884 my ($self, $w, $h) = @_;
896
897 $self->_size_allocate ($x, $y, $w, $h) or return;
898 885
899 ($h, $w) = ($w, $h); 886 ($h, $w) = ($w, $h);
900 887
901 my $children = $self->{children}; 888 my $children = $self->{children};
902 889
924 911
925 my $y = 0; 912 my $y = 0;
926 for (0 .. $#$children) { 913 for (0 .. $#$children) {
927 my $child = $children->[$_]; 914 my $child = $children->[$_];
928 my $h = $h[$_]; 915 my $h = $h[$_];
929 $child->size_allocate ($y, 0, $h, $w); 916 $child->configure ($y, 0, $h, $w);
930 917
931 $y += $h; 918 $y += $h;
932 } 919 }
933 920
934 1 921 1
952 (List::Util::sum map $_->[1], @alloc), 939 (List::Util::sum map $_->[1], @alloc),
953 ) 940 )
954} 941}
955 942
956sub size_allocate { 943sub size_allocate {
957 my ($self, $x, $y, $w, $h) = @_; 944 my ($self, $w, $h) = @_;
958
959 $self->_size_allocate ($x, $y, $w, $h) or return;
960 945
961 my $children = $self->{children}; 946 my $children = $self->{children};
962 947
963 my @h = map +($_->size_request)[1], @$children; 948 my @h = map +($_->size_request)[1], @$children;
964 949
982 967
983 my $y = 0; 968 my $y = 0;
984 for (0 .. $#$children) { 969 for (0 .. $#$children) {
985 my $child = $children->[$_]; 970 my $child = $children->[$_];
986 my $h = $h[$_]; 971 my $h = $h[$_];
987 $child->size_allocate (0, $y, $w, $h); 972 $child->configure (0, $y, $w, $h);
988 973
989 $y += $h; 974 $y += $h;
990 } 975 }
991 976
992 1 977 1
1063 $h + $self->{padding} * 2, 1048 $h + $self->{padding} * 2,
1064 ) 1049 )
1065} 1050}
1066 1051
1067sub size_allocate { 1052sub size_allocate {
1068 my ($self, $x, $y, $w, $h) = @_; 1053 my ($self, $w, $h) = @_;
1069
1070 $self->_size_allocate ($x, $y, $w, $h) or return;
1071 1054
1072 delete $self->{texture}; 1055 delete $self->{texture};
1073} 1056}
1074 1057
1075sub update { 1058sub update {
1164 1147
1165 ($w + 1, $h) # add 1 for cursor 1148 ($w + 1, $h) # add 1 for cursor
1166} 1149}
1167 1150
1168sub size_allocate { 1151sub size_allocate {
1169 my ($self, $x, $y, $w, $h) = @_; 1152 my ($self, $w, $h) = @_;
1170
1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1172 1153
1173 $self->_set_text ($self->{text}); 1154 $self->_set_text ($self->{text});
1174} 1155}
1175 1156
1176sub set_text { 1157sub set_text {
1394 1375
1395sub size_request { 1376sub size_request {
1396 my ($self) = @_; 1377 my ($self) = @_;
1397 1378
1398 ($self->{padding} * 2 + 6) x 2 1379 ($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} 1380}
1406 1381
1407sub button_down { 1382sub button_down {
1408 my ($self, $ev, $x, $y) = @_; 1383 my ($self, $ev, $x, $y) = @_;
1409 1384
1520 my $h1 = $self->{h} - $ycut * $self->{h}; 1495 my $h1 = $self->{h} - $ycut * $self->{h};
1521 my $h2 = $ycut * $self->{h}; 1496 my $h2 = $ycut * $self->{h};
1522 1497
1523 my $yp = 0; 1498 my $yp = 0;
1524 1499
1525 glBindTexture (GL_TEXTURE_2D, $t1->{name}); 1500 glBindTexture GL_TEXTURE_2D, $t1->{name};
1526 glBegin (GL_QUADS); 1501 glBegin GL_QUADS;
1527 glTexCoord (0, 0); glVertex (0 , $yp); 1502 glTexCoord 0 , 0; glVertex 0 , $yp;
1528 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); 1503 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1529 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); 1504 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1530 glTexCoord (1, 0); glVertex (0 + $w, $yp); 1505 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1531 glEnd (); 1506 glEnd;
1532 1507
1533 $yp += $h1; 1508 $yp += $h1;
1534 1509
1535 glBindTexture (GL_TEXTURE_2D, $t2->{name}); 1510 glBindTexture GL_TEXTURE_2D, $t2->{name};
1536 glBegin (GL_QUADS); 1511 glBegin GL_QUADS;
1537 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); 1512 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1538 glTexCoord (0, 1); glVertex (0 , $yp + $h2); 1513 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1539 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); 1514 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1540 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); 1515 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1541 glEnd (); 1516 glEnd;
1542 1517
1543 glDisable GL_BLEND; 1518 glDisable GL_BLEND;
1544 glDisable GL_TEXTURE_2D; 1519 glDisable GL_TEXTURE_2D;
1545} 1520}
1546 1521
1743 1718
1744 ($self->{req_w}, $self->{req_h}) 1719 ($self->{req_w}, $self->{req_h})
1745} 1720}
1746 1721
1747sub size_allocate { 1722sub size_allocate {
1748 my ($self, $x, $y, $w, $h) = @_; 1723 my ($self, $w, $h) = @_;
1749
1750 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1751 1724
1752 $self->{layout}->set_height ($self->{fontsize}); 1725 $self->{layout}->set_height ($self->{fontsize});
1753 $self->{layout}->set_width ($self->{w}); 1726 $self->{layout}->set_width ($self->{w});
1754 1727
1755 $self->reflow; 1728 $self->reflow;
1941 glTranslate $sx0 - 32, $sy0 - 32, 0; 1914 glTranslate $sx0 - 32, $sy0 - 32, 0;
1942 1915
1943 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 1916 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1944 1917
1945 if ($::CFG->{fow_enable}) { 1918 if ($::CFG->{fow_enable}) {
1946 if ($::CFG->{fow_smooth}) { # smooth fog of war 1919 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; 1920 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1948 glConvolutionFilter2D 1921 glConvolutionFilter2D (
1949 GL_CONVOLUTION_2D, 1922 GL_CONVOLUTION_2D,
1950 GL_ALPHA, 1923 GL_ALPHA,
1951 3, 3, 1924 3, 3,
1952 GL_ALPHA, GL_FLOAT, 1925 GL_ALPHA, GL_FLOAT,
1953 pack "f*", 1926 pack "f*",
1954 0.1, 0.1, 0.1, 1927 0.1, 0.1, 0.1,
1955 0.1, 0.2, 0.1, 1928 0.1, 0.2, 0.1,
1956 0.1, 0.1, 0.1, 1929 0.1, 0.1, 0.1,
1957 ; 1930 );
1958 glEnable GL_CONVOLUTION_2D; 1931 glEnable GL_CONVOLUTION_2D;
1959 } 1932 }
1960 1933
1961 $self->{fow_texture} = new CFClient::Texture 1934 $self->{fow_texture} = new CFClient::Texture
1962 w => $w, 1935 w => $w,
1992 $self->{mapmap_texture} = 1965 $self->{mapmap_texture} =
1993 new CFClient::Texture 1966 new CFClient::Texture
1994 w => $w, 1967 w => $w,
1995 h => $h, 1968 h => $h,
1996 data => $::MAP->mapmap ($w, $h), 1969 data => $::MAP->mapmap ($w, $h),
1997 type => GL_UNSIGNED_INT_8_8_8_8_REV; 1970 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
1998 1971
1999 $self->{mapmap_texture}->draw_quad (100, 100); 1972 $self->{mapmap_texture}->draw_quad (100, 100);
2000 1973
2001 glDisable GL_TEXTURE_2D; 1974 glDisable GL_TEXTURE_2D;
2002 glDisable GL_BLEND; 1975 glDisable GL_BLEND;
2172use SDL::OpenGL; 2145use SDL::OpenGL;
2173 2146
2174sub check_size { 2147sub check_size {
2175 my ($self) = @_; 2148 my ($self) = @_;
2176 2149
2177 $self->size_allocate (0, 0, $::WITH, $::HEIGHT); 2150 $self->configure (0, 0, $::WITH, $::HEIGHT);
2178} 2151}
2179 2152
2180sub size_request { 2153sub size_request {
2181 ($::WIDTH, $::HEIGHT) 2154 ($::WIDTH, $::HEIGHT)
2182} 2155}
2183 2156
2184sub size_allocate { 2157sub configure {
2185 my ($self, $x, $y, $w, $h) = @_; 2158 my ($self, $x, $y, $w, $h) = @_;
2186 2159
2187 $self->_size_allocate ($x, $y, $w, $h); 2160 $self->SUPER::configure ($x, $y, $w, $h);
2188 2161
2189 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2162 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2190 for @{$self->{children}}; 2163 for @{$self->{children}};
2191} 2164}
2192 2165
2193sub _topleft { 2166sub _topleft {
2194 my ($self, $x, $y) = @_; 2167 my ($self, $x, $y) = @_;
2202 $self->check_size; 2175 $self->check_size;
2203 ::refresh (); 2176 ::refresh ();
2204} 2177}
2205 2178
2206sub add { 2179sub add {
2207 my ($self, $widget) = @_; 2180 my ($self, $child) = @_;
2208 2181
2209 $self->SUPER::add ($widget); 2182 $self->SUPER::add ($child);
2210
2211 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2212} 2183}
2213 2184
2214sub on_refresh { 2185sub on_refresh {
2215 my ($self, $id, $cb) = @_; 2186 my ($self, $id, $cb) = @_;
2216 2187

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines