When testing for a key press, rather check for the modifier keys

(alt, ctrl) always. Also if a key event is not processed, pass it
for further processing.
This commit is contained in:
bubnikv 2017-06-06 19:14:52 +02:00
parent 53d08d1883
commit dabcff1c07
3 changed files with 50 additions and 33 deletions

View File

@ -52,18 +52,24 @@ sub new {
}); });
EVT_KEY_DOWN($canvas, sub { EVT_KEY_DOWN($canvas, sub {
my ($s, $event) = @_; my ($s, $event) = @_;
my $key = $event->GetKeyCode; if ($event->HasModifiers) {
if ($key == ord('D') || $key == WXK_LEFT) { $event->Skip;
# Keys: 'D' or WXK_LEFT } else {
$slider->SetValue($slider->GetValue - 1); my $key = $event->GetKeyCode;
$self->set_z($self->{layers_z}[$slider->GetValue]); if ($key == ord('D') || $key == WXK_LEFT) {
} elsif ($key == ord('U') || $key == WXK_RIGHT) { # Keys: 'D' or WXK_LEFT
# Keys: 'U' or WXK_RIGHT $slider->SetValue($slider->GetValue - 1);
$slider->SetValue($slider->GetValue + 1); $self->set_z($self->{layers_z}[$slider->GetValue]);
$self->set_z($self->{layers_z}[$slider->GetValue]); } elsif ($key == ord('U') || $key == WXK_RIGHT) {
} elsif ($key >= ord('1') && $key <= ord('3')) { # Keys: 'U' or WXK_RIGHT
# Keys: '1' to '3' $slider->SetValue($slider->GetValue + 1);
$canvas->set_simulation_mode($key - ord('1')); $self->set_z($self->{layers_z}[$slider->GetValue]);
} elsif ($key >= ord('1') && $key <= ord('3')) {
# Keys: '1' to '3'
$canvas->set_simulation_mode($key - ord('1'));
} else {
$event->Skip;
}
} }
}); });

View File

@ -89,20 +89,26 @@ sub new {
EVT_KEY_DOWN($canvas, sub { EVT_KEY_DOWN($canvas, sub {
my ($s, $event) = @_; my ($s, $event) = @_;
my $key = $event->GetKeyCode; my $key = $event->GetKeyCode;
if ($key == ord('U') || $key == WXK_RIGHT) { if ($event->HasModifiers) {
$slider_high->SetValue($slider_high->GetValue + 1); $event->Skip;
$slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown()); } else {
$self->set_z_idx_high($slider_high->GetValue); if ($key == ord('U') || $key == WXK_RIGHT) {
} elsif ($key == ord('D') || $key == WXK_LEFT) { $slider_high->SetValue($slider_high->GetValue + 1);
$slider_high->SetValue($slider_high->GetValue - 1); $slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
$slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
$self->set_z_idx_high($slider_high->GetValue);
} elsif ($key == ord('S')) {
$checkbox_singlelayer->SetValue(! $checkbox_singlelayer->GetValue());
$self->single_layer($checkbox_singlelayer->GetValue());
if ($self->single_layer) {
$slider_low->SetValue($slider_high->GetValue);
$self->set_z_idx_high($slider_high->GetValue); $self->set_z_idx_high($slider_high->GetValue);
} elsif ($key == ord('D') || $key == WXK_LEFT) {
$slider_high->SetValue($slider_high->GetValue - 1);
$slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
$self->set_z_idx_high($slider_high->GetValue);
} elsif ($key == ord('S')) {
$checkbox_singlelayer->SetValue(! $checkbox_singlelayer->GetValue());
$self->single_layer($checkbox_singlelayer->GetValue());
if ($self->single_layer) {
$slider_low->SetValue($slider_high->GetValue);
$self->set_z_idx_high($slider_high->GetValue);
}
} else {
$event->Skip;
} }
} }
}); });

View File

@ -50,14 +50,19 @@ sub new {
}); });
EVT_KEY_DOWN($canvas, sub { EVT_KEY_DOWN($canvas, sub {
my ($s, $event) = @_; my ($s, $event) = @_;
if ($event->HasModifiers) {
my $key = $event->GetKeyCode; $event->Skip;
if ($key == 85 || $key == 315) { } else {
$slider->SetValue($slider->GetValue + 1); my $key = $event->GetKeyCode;
$self->set_z($self->{layers_z}[$slider->GetValue]); if ($key == 85 || $key == 315) {
} elsif ($key == 68 || $key == 317) { $slider->SetValue($slider->GetValue + 1);
$slider->SetValue($slider->GetValue - 1); $self->set_z($self->{layers_z}[$slider->GetValue]);
$self->set_z($self->{layers_z}[$slider->GetValue]); } elsif ($key == 68 || $key == 317) {
$slider->SetValue($slider->GetValue - 1);
$self->set_z($self->{layers_z}[$slider->GetValue]);
} else {
$event->Skip;
}
} }
}); });