… | |
… | |
246 | } |
246 | } |
247 | |
247 | |
248 | # return top left coordinates |
248 | # return top left coordinates |
249 | sub _topleft { |
249 | sub _topleft { |
250 | my ($self, $x, $y) = @_; |
250 | my ($self, $x, $y) = @_; |
|
|
251 | |
|
|
252 | $self->{parent} |
|
|
253 | or Carp::confess "no parent widget in _topleft\n";#d# |
251 | |
254 | |
252 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
255 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
253 | } |
256 | } |
254 | |
257 | |
255 | # translate global coordinates to local coordinate system |
258 | # translate global coordinates to local coordinate system |
… | |
… | |
492 | sub new { |
495 | sub new { |
493 | my ($class, %arg) = @_; |
496 | my ($class, %arg) = @_; |
494 | |
497 | |
495 | my $children = delete $arg{children} || []; |
498 | my $children = delete $arg{children} || []; |
496 | |
499 | |
497 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
500 | my $self = $class->SUPER::new ( |
|
|
501 | children => [], |
|
|
502 | can_events => 0, |
|
|
503 | %arg, |
|
|
504 | ); |
498 | $self->add ($_) for @$children; |
505 | $self->add ($_) for @$children; |
499 | |
506 | |
500 | $self |
507 | $self |
501 | } |
508 | } |
502 | |
509 | |
… | |
… | |
751 | |
758 | |
752 | my $self = $class->SUPER::new ( |
759 | my $self = $class->SUPER::new ( |
753 | bg => [1, 1, 1, 1], |
760 | bg => [1, 1, 1, 1], |
754 | border_bg => [1, 1, 1, 1], |
761 | border_bg => [1, 1, 1, 1], |
755 | border => 0.8, |
762 | border => 0.8, |
756 | can_events => 0, |
763 | can_events => 1, |
757 | @_ |
764 | @_ |
758 | ); |
765 | ); |
759 | |
766 | |
760 | $self->{title} &&= new CFClient::UI::Label |
767 | $self->{title} &&= new CFClient::UI::Label |
761 | align => 0, |
768 | align => 0, |
… | |
… | |
1462 | my ($self, $ev) = @_; |
1469 | my ($self, $ev) = @_; |
1463 | |
1470 | |
1464 | my $sym = $ev->{sym}; |
1471 | my $sym = $ev->{sym}; |
1465 | |
1472 | |
1466 | if ($sym == 13) { |
1473 | if ($sym == 13) { |
|
|
1474 | unshift @{$self->{history}}, |
|
|
1475 | my $txt = $self->get_text; |
|
|
1476 | $self->{history_pointer} = -1; |
|
|
1477 | $self->{history_saveback} = ''; |
1467 | $self->emit (activate => $self->get_text); |
1478 | $self->emit (activate => $txt); |
1468 | $self->update; |
1479 | $self->update; |
|
|
1480 | |
|
|
1481 | } elsif ($sym == CFClient::SDLK_UP) { |
|
|
1482 | if ($self->{history_pointer} < 0) { |
|
|
1483 | $self->{history_saveback} = $self->get_text; |
|
|
1484 | } |
|
|
1485 | if (@{$self->{history} || []} > 0) { |
|
|
1486 | $self->{history_pointer}++; |
|
|
1487 | if ($self->{history_pointer} >= @{$self->{history} || []}) { |
|
|
1488 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
|
|
1489 | } |
|
|
1490 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1491 | } |
|
|
1492 | |
|
|
1493 | } elsif ($sym == CFClient::SDLK_DOWN) { |
|
|
1494 | $self->{history_pointer}--; |
|
|
1495 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
|
|
1496 | |
|
|
1497 | if ($self->{history_pointer} >= 0) { |
|
|
1498 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1499 | } else { |
|
|
1500 | $self->set_text ($self->{history_saveback}); |
|
|
1501 | } |
1469 | |
1502 | |
1470 | } else { |
1503 | } else { |
1471 | $self->SUPER::key_down ($ev); |
1504 | $self->SUPER::key_down ($ev); |
1472 | } |
1505 | } |
1473 | |
1506 | |