One more refactoring in 3DScene (select group/drag group)
This commit is contained in:
parent
9c8f8f8ded
commit
d46d5c955b
4 changed files with 71 additions and 38 deletions
|
@ -27,7 +27,7 @@ sub new {
|
|||
$self->{on_select_object} = sub {};
|
||||
$self->{on_double_click} = sub {};
|
||||
$self->{on_right_click} = sub {};
|
||||
$self->{on_instance_moved} = sub {};
|
||||
$self->{on_instances_moved} = sub {};
|
||||
|
||||
$self->{objects_brush} = Wx::Brush->new(Wx::Colour->new(210,210,210), wxSOLID);
|
||||
$self->{selected_brush} = Wx::Brush->new(Wx::Colour->new(255,128,128), wxSOLID);
|
||||
|
@ -63,9 +63,9 @@ sub on_right_click {
|
|||
$self->{on_right_click} = $cb;
|
||||
}
|
||||
|
||||
sub on_instance_moved {
|
||||
sub on_instances_moved {
|
||||
my ($self, $cb) = @_;
|
||||
$self->{on_instance_moved} = $cb;
|
||||
$self->{on_instances_moved} = $cb;
|
||||
}
|
||||
|
||||
sub repaint {
|
||||
|
@ -211,7 +211,7 @@ sub mouse_event {
|
|||
}
|
||||
$self->Refresh;
|
||||
} elsif ($event->LeftUp) {
|
||||
$self->{on_instance_moved}->(@{ $self->{drag_object} })
|
||||
$self->{on_instances_moved}->()
|
||||
if $self->{drag_object};
|
||||
$self->{drag_start_pos} = undef;
|
||||
$self->{drag_object} = undef;
|
||||
|
|
|
@ -17,12 +17,14 @@ sub new {
|
|||
my $self = $class->SUPER::new($parent);
|
||||
$self->enable_picking(1);
|
||||
$self->enable_moving(1);
|
||||
$self->select_by('object');
|
||||
$self->drag_by('instance');
|
||||
|
||||
$self->{objects} = $objects;
|
||||
$self->{model} = $model;
|
||||
$self->{config} = $config;
|
||||
$self->{on_select_object} = sub {};
|
||||
$self->{on_instance_moved} = sub {};
|
||||
$self->{on_instances_moved} = sub {};
|
||||
|
||||
$self->on_select(sub {
|
||||
my ($volume_idx) = @_;
|
||||
|
@ -30,33 +32,27 @@ sub new {
|
|||
my $obj_idx = undef;
|
||||
if ($volume_idx != -1) {
|
||||
$obj_idx = $self->object_idx($volume_idx);
|
||||
$self->volumes->[$_]->selected(1) for @{$self->volumes_by_object->{$obj_idx}};
|
||||
$self->Refresh;
|
||||
}
|
||||
$self->{on_select_object}->($obj_idx)
|
||||
if $self->{on_select_object};
|
||||
});
|
||||
$self->on_hover(sub {
|
||||
my ($volume_idx) = @_;
|
||||
|
||||
my $obj_idx = $self->object_idx($volume_idx);
|
||||
$self->volumes->[$_]->hover(1) for @{$self->volumes_by_object->{$obj_idx}};
|
||||
});
|
||||
$self->on_move(sub {
|
||||
my ($volume_idx) = @_;
|
||||
my @volume_idxs = @_;
|
||||
|
||||
my $volume = $self->volumes->[$volume_idx];
|
||||
my $obj_idx = $self->object_idx($volume_idx);
|
||||
my $instance_idx = $self->instance_idx($volume_idx);
|
||||
my $model_object = $self->{model}->get_object($obj_idx);
|
||||
$model_object
|
||||
->instances->[$instance_idx]
|
||||
->offset
|
||||
->translate($volume->origin->x, $volume->origin->y); #))
|
||||
$model_object->invalidate_bounding_box;
|
||||
foreach my $volume_idx (@volume_idxs) {
|
||||
my $volume = $self->volumes->[$volume_idx];
|
||||
my $obj_idx = $self->object_idx($volume_idx);
|
||||
my $instance_idx = $self->instance_idx($volume_idx);
|
||||
my $model_object = $self->{model}->get_object($obj_idx);
|
||||
$model_object
|
||||
->instances->[$instance_idx]
|
||||
->offset
|
||||
->translate($volume->origin->x, $volume->origin->y); #))
|
||||
$model_object->invalidate_bounding_box;
|
||||
}
|
||||
|
||||
$self->{on_instance_moved}->($obj_idx, $instance_idx)
|
||||
if $self->{on_instance_moved};
|
||||
$self->{on_instances_moved}->()
|
||||
if $self->{on_instances_moved};
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -77,9 +73,9 @@ sub set_on_right_click {
|
|||
$self->on_right_click($cb);
|
||||
}
|
||||
|
||||
sub set_on_instance_moved {
|
||||
sub set_on_instances_moved {
|
||||
my ($self, $cb) = @_;
|
||||
$self->{on_instance_moved} = $cb;
|
||||
$self->{on_instances_moved} = $cb;
|
||||
}
|
||||
|
||||
sub update {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue