… | |
… | |
236 | |
236 | |
237 | sub size_allocate { |
237 | sub size_allocate { |
238 | # nothing to be done |
238 | # nothing to be done |
239 | } |
239 | } |
240 | |
240 | |
|
|
241 | sub children { |
|
|
242 | } |
|
|
243 | |
241 | sub set_max_size { |
244 | sub 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 |
249 | sub _topleft { |
252 | sub _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 |
… | |
… | |
492 | sub new { |
498 | sub 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 | |
|
|
528 | sub children { |
|
|
529 | @{ $_[0]{children} } |
516 | } |
530 | } |
517 | |
531 | |
518 | sub remove { |
532 | sub 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, |
756 | can_events => 0, |
770 | can_events => 1, |
757 | @_ |
771 | @_ |
758 | ); |
772 | ); |
759 | |
773 | |
760 | $self->{title} &&= new CFClient::UI::Label |
774 | $self->{title} &&= new CFClient::UI::Label |
761 | align => 0, |
775 | align => 0, |
… | |
… | |
908 | $self->{children}[$y][$x] = $child; |
922 | $self->{children}[$y][$x] = $child; |
909 | |
923 | |
910 | $child->check_size; |
924 | $child->check_size; |
911 | } |
925 | } |
912 | |
926 | |
|
|
927 | sub children { |
|
|
928 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
929 | } |
|
|
930 | |
913 | # 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? |
914 | sub clear { |
932 | sub clear { |
915 | my ($self) = @_; |
933 | my ($self) = @_; |
916 | |
934 | |
917 | my $children = delete $self->{children}; |
935 | my @children = $self->children; |
|
|
936 | delete $self->{children}; |
918 | |
937 | |
919 | for (grep $_, map @$_, grep $_, @$children) { |
938 | for (@children) { |
920 | delete $_->{parent}; |
939 | delete $_->{parent}; |
921 | $_->hide; |
940 | $_->hide; |
922 | } |
941 | } |
923 | |
942 | |
924 | $self->update; |
943 | $self->update; |
… | |
… | |
1462 | my ($self, $ev) = @_; |
1481 | my ($self, $ev) = @_; |
1463 | |
1482 | |
1464 | my $sym = $ev->{sym}; |
1483 | my $sym = $ev->{sym}; |
1465 | |
1484 | |
1466 | 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} = ''; |
1467 | $self->emit (activate => $self->get_text); |
1490 | $self->emit (activate => $txt); |
1468 | $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 | } |
1469 | |
1514 | |
1470 | } else { |
1515 | } else { |
1471 | $self->SUPER::key_down ($ev); |
1516 | $self->SUPER::key_down ($ev); |
1472 | } |
1517 | } |
1473 | |
1518 | |
… | |
… | |
1794 | |
1839 | |
1795 | sub new { |
1840 | sub new { |
1796 | my ($class, %arg) = @_; |
1841 | my ($class, %arg) = @_; |
1797 | |
1842 | |
1798 | my $self = $class->SUPER::new ( |
1843 | my $self = $class->SUPER::new ( |
1799 | tooltip => $arg{type}, |
1844 | tooltip => $arg{type}, |
1800 | can_hover => 1, |
1845 | can_hover => 1, |
|
|
1846 | can_events => 1, |
1801 | %arg, |
1847 | %arg, |
1802 | ); |
1848 | ); |
1803 | |
1849 | |
1804 | $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"); |
1805 | $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); |
… | |
… | |
2120 | my ($self) = @_; |
2166 | my ($self) = @_; |
2121 | |
2167 | |
2122 | if ($self->{texture}) { |
2168 | if ($self->{texture}) { |
2123 | glEnable GL_TEXTURE_2D; |
2169 | glEnable GL_TEXTURE_2D; |
2124 | 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; |
2125 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2172 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2126 | glDisable GL_TEXTURE_2D; |
2173 | glDisable GL_TEXTURE_2D; |
2127 | } |
2174 | } |
2128 | |
2175 | |
2129 | $self->{children}[1]->draw; |
2176 | $self->{children}[1]->draw; |