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.165 by root, Mon Apr 24 08:22:22 2006 UTC vs.
Revision 1.172 by root, Tue Apr 25 09:52:04 2006 UTC

236 236
237sub size_allocate { 237sub size_allocate {
238 # nothing to be done 238 # nothing to be done
239} 239}
240 240
241sub children {
242}
243
241sub set_max_size { 244sub set_max_size {
242 my ($self, $w, $h) = @_; 245 my ($self, $w, $h) = @_;
243 246
244 delete $self->{max_w}; $self->{max_w} = $w if $w; 247 delete $self->{max_w}; $self->{max_w} = $w if $w;
245 delete $self->{max_h}; $self->{max_h} = $h if $h; 248 delete $self->{max_h}; $self->{max_h} = $h if $h;
246} 249}
247 250
248# return top left coordinates 251# return top left coordinates
249sub _topleft { 252sub _topleft {
250 my ($self, $x, $y) = @_; 253 my ($self, $x, $y) = @_;
254
255 $self->{parent}
256 or Carp::confess "no parent widget in _topleft\n";#d#
251 257
252 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); 258 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
253} 259}
254 260
255# translate global coordinates to local coordinate system 261# translate global coordinates to local coordinate system
492sub new { 498sub new {
493 my ($class, %arg) = @_; 499 my ($class, %arg) = @_;
494 500
495 my $children = delete $arg{children} || []; 501 my $children = delete $arg{children} || [];
496 502
497 my $self = $class->SUPER::new (children => [], can_events => 0, %arg); 503 my $self = $class->SUPER::new (
504 children => [],
505 can_events => 0,
506 %arg,
507 );
498 $self->add ($_) for @$children; 508 $self->add ($_) for @$children;
499 509
500 $self 510 $self
501} 511}
502 512
511 sort { $a->{z} <=> $b->{z} } 521 sort { $a->{z} <=> $b->{z} }
512 @{$self->{children}}, $child 522 @{$self->{children}}, $child
513 ]; 523 ];
514 524
515 $child->check_size; 525 $child->check_size;
526}
527
528sub children {
529 @{ $_[0]{children} }
516} 530}
517 531
518sub remove { 532sub remove {
519 my ($self, $child) = @_; 533 my ($self, $child) = @_;
520 534
751 765
752 my $self = $class->SUPER::new ( 766 my $self = $class->SUPER::new (
753 bg => [1, 1, 1, 1], 767 bg => [1, 1, 1, 1],
754 border_bg => [1, 1, 1, 1], 768 border_bg => [1, 1, 1, 1],
755 border => 0.8, 769 border => 0.8,
770 can_events => 1,
756 @_ 771 @_
757 ); 772 );
758 773
759 $self->{title} &&= new CFClient::UI::Label 774 $self->{title} &&= new CFClient::UI::Label
760 align => 0, 775 align => 0,
907 $self->{children}[$y][$x] = $child; 922 $self->{children}[$y][$x] = $child;
908 923
909 $child->check_size; 924 $child->check_size;
910} 925}
911 926
927sub children {
928 grep $_, map @$_, grep $_, @{ $_[0]{children} }
929}
930
912# TODO: move to container class maybe? send childs a signal on removal? 931# TODO: move to container class maybe? send childs a signal on removal?
913sub clear { 932sub clear {
914 my ($self) = @_; 933 my ($self) = @_;
915 934
916 my $children = delete $self->{children}; 935 my @children = $self->children;
936 delete $self->{children};
917 937
918 for (grep $_, map @$_, grep $_, @$children) { 938 for (@children) {
919 delete $_->{parent}; 939 delete $_->{parent};
920 $_->hide; 940 $_->hide;
921 } 941 }
922 942
923 $self->update; 943 $self->update;
1461 my ($self, $ev) = @_; 1481 my ($self, $ev) = @_;
1462 1482
1463 my $sym = $ev->{sym}; 1483 my $sym = $ev->{sym};
1464 1484
1465 if ($sym == 13) { 1485 if ($sym == 13) {
1486 unshift @{$self->{history}},
1487 my $txt = $self->get_text;
1488 $self->{history_pointer} = -1;
1489 $self->{history_saveback} = '';
1466 $self->emit (activate => $self->get_text); 1490 $self->emit (activate => $txt);
1467 $self->update; 1491 $self->update;
1492
1493 } elsif ($sym == CFClient::SDLK_UP) {
1494 if ($self->{history_pointer} < 0) {
1495 $self->{history_saveback} = $self->get_text;
1496 }
1497 if (@{$self->{history} || []} > 0) {
1498 $self->{history_pointer}++;
1499 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1500 $self->{history_pointer} = @{$self->{history} || []} - 1;
1501 }
1502 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1503 }
1504
1505 } elsif ($sym == CFClient::SDLK_DOWN) {
1506 $self->{history_pointer}--;
1507 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1508
1509 if ($self->{history_pointer} >= 0) {
1510 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1511 } else {
1512 $self->set_text ($self->{history_saveback});
1513 }
1468 1514
1469 } else { 1515 } else {
1470 $self->SUPER::key_down ($ev); 1516 $self->SUPER::key_down ($ev);
1471 } 1517 }
1472 1518
1793 1839
1794sub new { 1840sub new {
1795 my ($class, %arg) = @_; 1841 my ($class, %arg) = @_;
1796 1842
1797 my $self = $class->SUPER::new ( 1843 my $self = $class->SUPER::new (
1798 tooltip => $arg{type}, 1844 tooltip => $arg{type},
1799 can_hover => 1, 1845 can_hover => 1,
1846 can_events => 1,
1800 %arg, 1847 %arg,
1801 ); 1848 );
1802 1849
1803 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1850 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1804 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1851 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2119 my ($self) = @_; 2166 my ($self) = @_;
2120 2167
2121 if ($self->{texture}) { 2168 if ($self->{texture}) {
2122 glEnable GL_TEXTURE_2D; 2169 glEnable GL_TEXTURE_2D;
2123 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2170 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2171 glColor 1, 1, 1, 1;
2124 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2172 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2125 glDisable GL_TEXTURE_2D; 2173 glDisable GL_TEXTURE_2D;
2126 } 2174 }
2127 2175
2128 $self->{children}[1]->draw; 2176 $self->{children}[1]->draw;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines