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.127 by root, Mon Apr 17 21:03:31 2006 UTC

260 my ($self, $parent) = @_; 260 my ($self, $parent) = @_;
261 261
262 Scalar::Util::weaken ($self->{parent} = $parent); 262 Scalar::Util::weaken ($self->{parent} = $parent);
263} 263}
264 264
265sub check_size {
266 my ($self) = @_;
267
268 my ($w, $h) = $self->size_request;
269
270 if ($w != $self->{req_w} || $h != $self->{req_h}) {
271 $self->{req_w} = $w;
272 $self->{req_h} = $h;
273
274 $self->{parent}->check_size
275 if $self->{parent};
276 }
277}
278
265sub update { 279sub update {
266 my ($self) = @_; 280 my ($self) = @_;
267 281
268 $self->{parent}->update 282 $self->{parent}->update
269 if $self->{parent}; 283 if $self->{parent};
368 sort { $a->{z} <=> $b->{z} } 382 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 383 @{$self->{children}}, $child
370 ]; 384 ];
371 385
372 $self->{w} = $self->{h} = -1; 386 $self->{w} = $self->{h} = -1;
373 $self->update; 387
388 $child->check_size;
374} 389}
375 390
376sub remove { 391sub remove {
377 my ($self, $widget) = @_; 392 my ($self, $widget) = @_;
378 393
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 394 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
380 395
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 396 $self->check_size;
382} 397}
383 398
384sub find_widget { 399sub find_widget {
385 my ($self, $x, $y) = @_; 400 my ($self, $x, $y) = @_;
386 401
506 $tex->draw_quad (0, 0, $w, $h); 521 $tex->draw_quad (0, 0, $w, $h);
507 522
508 glDisable GL_BLEND; 523 glDisable GL_BLEND;
509 glDisable GL_TEXTURE_2D; 524 glDisable GL_TEXTURE_2D;
510} 525}
526
527#############################################################################
528
529package CFClient::UI::ViewPort;
530
531our @ISA = CFClient::UI::Window::;
532
533sub new { die }
534
535sub size_request {
536 my ($self) = @_;
537
538 @$self{qw(child_w child_h)} = $self->child->size_request;
539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
540
541 @$self{qw(child_w child_h)}
542}
543
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 {
551 my ($self) = @_;
552
553 $self->{children}[1]->draw;
554}
555
511 556
512############################################################################# 557#############################################################################
513 558
514package CFClient::UI::Frame; 559package CFClient::UI::Frame;
515 560
710 755
711 $child->set_parent ($self); 756 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 757 $self->{children}[$y][$x] = $child;
713 758
714 $self->{w} = $self->{h} = -1; 759 $self->{w} = $self->{h} = -1;
715 $self->update; 760
761 $child->check_size;
716} 762}
717 763
718# TODO: move to container class maybe? send childs a signal on removal? 764# TODO: move to container class maybe? send childs a signal on removal?
719sub clear { 765sub clear {
720 my ($self) = @_; 766 my ($self) = @_;
846} 892}
847 893
848sub size_allocate { 894sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 895 my ($self, $x, $y, $w, $h) = @_;
850 896
851 $self->_size_allocate ($x, $y, $w, $h); 897 $self->_size_allocate ($x, $y, $w, $h) or return;
852 898
853 ($h, $w) = ($w, $h); 899 ($h, $w) = ($w, $h);
854 900
855 my $children = $self->{children}; 901 my $children = $self->{children};
856 902
882 my $h = $h[$_]; 928 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 929 $child->size_allocate ($y, 0, $h, $w);
884 930
885 $y += $h; 931 $y += $h;
886 } 932 }
933
934 1
887} 935}
888 936
889############################################################################# 937#############################################################################
890 938
891package CFClient::UI::VBox; 939package CFClient::UI::VBox;
906} 954}
907 955
908sub size_allocate { 956sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 957 my ($self, $x, $y, $w, $h) = @_;
910 958
911 $self->_size_allocate ($x, $y, $w, $h); 959 $self->_size_allocate ($x, $y, $w, $h) or return;
912 960
913 my $children = $self->{children}; 961 my $children = $self->{children};
914 962
915 my @h = map +($_->size_request)[1], @$children; 963 my @h = map +($_->size_request)[1], @$children;
916 964
938 my $h = $h[$_]; 986 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 987 $child->size_allocate (0, $y, $w, $h);
940 988
941 $y += $h; 989 $y += $h;
942 } 990 }
991
992 1
943} 993}
944 994
945############################################################################# 995#############################################################################
946 996
947package CFClient::UI::Label; 997package CFClient::UI::Label;
1116} 1166}
1117 1167
1118sub size_allocate { 1168sub size_allocate {
1119 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $x, $y, $w, $h) = @_;
1120 1170
1121 $self->SUPER::size_allocate ($x, $y, $w, $h); 1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1122 1172
1123 $self->_set_text ($self->{text}); 1173 $self->_set_text ($self->{text});
1124} 1174}
1125 1175
1126sub set_text { 1176sub set_text {
1276 padding => 4, 1326 padding => 4,
1277 fg => [1, 1, 1], 1327 fg => [1, 1, 1],
1278 bg => [1, 1, 1, 0.2], 1328 bg => [1, 1, 1, 0.2],
1279 active_fg => [0, 0, 1], 1329 active_fg => [0, 0, 1],
1280 can_hover => 1, 1330 can_hover => 1,
1331 align => 0,
1332 valign => 0,
1281 @_ 1333 @_
1282 ) 1334 )
1283} 1335}
1284 1336
1285sub button_up { 1337sub button_up {
1347} 1399}
1348 1400
1349sub size_allocate { 1401sub size_allocate {
1350 my ($self, $x, $y, $w, $h) = @_; 1402 my ($self, $x, $y, $w, $h) = @_;
1351 1403
1352 $self->_size_allocate ($x, $y, $w, $h); 1404 $self->_size_allocate ($x, $y, $w, $h) or return;
1353} 1405}
1354 1406
1355sub button_down { 1407sub button_down {
1356 my ($self, $ev, $x, $y) = @_; 1408 my ($self, $ev, $x, $y) = @_;
1357 1409
1422} 1474}
1423 1475
1424sub size_request { 1476sub size_request {
1425 my ($self) = @_; 1477 my ($self) = @_;
1426 1478
1427 ($self->{w}, $self->{h}) 1479 my $tex = $tex{$self->{gauge}}[0];
1480
1481 @$tex{qw(w h)}
1428} 1482}
1429 1483
1430sub set_max { 1484sub set_max {
1431 my ($self, $max) = @_; 1485 my ($self, $max) = @_;
1486
1432 $self->{max_val} = $max; 1487 $self->{max_val} = $max;
1433} 1488}
1434 1489
1435sub set_value { 1490sub set_value {
1436 my ($self, $val, $max) = @_; 1491 my ($self, $val, $max) = @_;
1690} 1745}
1691 1746
1692sub size_allocate { 1747sub size_allocate {
1693 my ($self, $x, $y, $w, $h) = @_; 1748 my ($self, $x, $y, $w, $h) = @_;
1694 1749
1695 $self->SUPER::size_allocate ($x, $y, $w, $h); 1750 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1696 1751
1697 $self->{layout}->set_height ($self->{fontsize}); 1752 $self->{layout}->set_height ($self->{fontsize});
1698 $self->{layout}->set_width ($self->{w}); 1753 $self->{layout}->set_width ($self->{w});
1699 1754
1700 $self->reflow; 1755 $self->reflow;
1756 $self->update;
1701} 1757}
1702 1758
1703sub add_paragraph { 1759sub add_paragraph {
1704 my ($self, $color, $text) = @_; 1760 my ($self, $color, $text) = @_;
1705 1761
2113 2169
2114our @ISA = CFClient::UI::Container::; 2170our @ISA = CFClient::UI::Container::;
2115 2171
2116use SDL::OpenGL; 2172use SDL::OpenGL;
2117 2173
2174sub check_size {
2175 my ($self) = @_;
2176
2177 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2178}
2179
2118sub size_request { 2180sub size_request {
2119 ($::WIDTH, $::HEIGHT) 2181 ($::WIDTH, $::HEIGHT)
2120} 2182}
2121 2183
2122sub size_allocate { 2184sub size_allocate {
2135} 2197}
2136 2198
2137sub update { 2199sub update {
2138 my ($self) = @_; 2200 my ($self) = @_;
2139 2201
2140 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2202 $self->check_size;
2141 ::refresh (); 2203 ::refresh ();
2142} 2204}
2143 2205
2144sub add { 2206sub add {
2145 my ($self, $widget) = @_; 2207 my ($self, $widget) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines