3DScene mouse event handler partially moved to c++ - part 2

This commit is contained in:
Enrico Turri 2018-05-31 16:04:59 +02:00
parent 276533e236
commit 6bf009edee
12 changed files with 257 additions and 173 deletions

View file

@ -37,8 +37,6 @@ use Slic3r::Geometry qw(PI);
__PACKAGE__->mk_accessors( qw(_quat init __PACKAGE__->mk_accessors( qw(_quat init
on_viewport_changed on_viewport_changed
on_select on_select
on_move
on_model_update
volumes volumes
_drag_volume_idx _drag_volume_idx

View file

@ -143,7 +143,8 @@ sub new {
$cfg->set('wipe_tower_y', $new_pos_3f->y); $cfg->set('wipe_tower_y', $new_pos_3f->y);
$self->GetFrame->{options_tabs}{print}->load_config($cfg); $self->GetFrame->{options_tabs}{print}->load_config($cfg);
}); });
$self->{canvas3D}->set_on_model_update(sub { #==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_model_update_callback($self->{canvas3D}, sub {
if (wxTheApp->{app_config}->get("background_processing")) { if (wxTheApp->{app_config}->get("background_processing")) {
$self->schedule_background_process; $self->schedule_background_process;
} else { } else {
@ -151,6 +152,16 @@ sub new {
$self->{"print_info_box_show"}->(0); $self->{"print_info_box_show"}->(0);
} }
}); });
# $self->{canvas3D}->set_on_model_update(sub {
# if (wxTheApp->{app_config}->get("background_processing")) {
# $self->schedule_background_process;
# } else {
# # Hide the print info box, it is no more valid.
# $self->{"print_info_box_show"}->(0);
# }
# });
#==============================================================================================================================
$self->{canvas3D}->on_viewport_changed(sub { $self->{canvas3D}->on_viewport_changed(sub {
#============================================================================================================================== #==============================================================================================================================
Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D});

View file

@ -50,9 +50,19 @@ sub new {
#============================================================================================================================== #==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_select_callback($self, $self->on_select); Slic3r::GUI::_3DScene::register_on_select_callback($self, $self->on_select);
#============================================================================================================================== #==============================================================================================================================
$self->on_move(sub {
#==============================================================================================================================
Slic3r::GUI::_3DScene::register_on_move_callback($self, sub {
# $self->on_move(sub {
#==============================================================================================================================
my @volume_idxs = @_; my @volume_idxs = @_;
#==============================================================================================================================
print "cucu";
#==============================================================================================================================
my %done = (); # prevent moving instances twice my %done = (); # prevent moving instances twice
my $object_moved; my $object_moved;
my $wipe_tower_moved; my $wipe_tower_moved;
@ -186,10 +196,12 @@ sub set_on_wipe_tower_moved {
$self->{on_wipe_tower_moved} = $cb; $self->{on_wipe_tower_moved} = $cb;
} }
sub set_on_model_update { #==============================================================================================================================
my ($self, $cb) = @_; #sub set_on_model_update {
$self->on_model_update($cb); # my ($self, $cb) = @_;
} # $self->on_model_update($cb);
#}
#==============================================================================================================================
sub set_on_enable_action_buttons { sub set_on_enable_action_buttons {
my ($self, $cb) = @_; my ($self, $cb) = @_;

View file

@ -95,7 +95,7 @@ public:
void call() const; void call() const;
void call(int i) const; void call(int i) const;
void call(int i, int j) const; void call(int i, int j) const;
// void call(const std::vector<int> &ints); void call(const std::vector<int>& ints) const;
// void call(); // void call();
// void call(int i); // void call(int i);
// void call(int i, int j); // void call(int i, int j);

View file

@ -238,9 +238,8 @@ void PerlCallback::call(int i, int j) const
LEAVE; LEAVE;
} }
/*
//############################################################################################################## //##############################################################################################################
void PerlCallback::call(const std::vector<int> &ints) const void PerlCallback::call(const std::vector<int>& ints) const
//void PerlCallback::call(const std::vector<int> &ints) //void PerlCallback::call(const std::vector<int> &ints)
//############################################################################################################## //##############################################################################################################
{ {
@ -250,16 +249,22 @@ void PerlCallback::call(const std::vector<int> &ints) const
ENTER; ENTER;
SAVETMPS; SAVETMPS;
PUSHMARK(SP); PUSHMARK(SP);
AV* av = newAV(); //##############################################################################################################
for (int i : ints) for (int i : ints)
av_push(av, newSViv(i)); {
XPUSHs(av); XPUSHs(sv_2mortal(newSViv(i)));
}
// AV* av = newAV();
// for (int i : ints)
// av_push(av, newSViv(i));
// XPUSHs(av);
//##############################################################################################################
PUTBACK; PUTBACK;
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD); perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
FREETMPS; FREETMPS;
LEAVE; LEAVE;
} }
*/
#ifdef WIN32 #ifdef WIN32
#ifndef NOMINMAX #ifndef NOMINMAX

View file

@ -1999,17 +1999,6 @@ void _3DScene::set_mouse_dragging(wxGLCanvas* canvas, bool dragging)
s_canvas_mgr.set_mouse_dragging(canvas, dragging); s_canvas_mgr.set_mouse_dragging(canvas, dragging);
} }
Pointf _3DScene::get_mouse_position(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_mouse_position(canvas);
}
void _3DScene::set_mouse_position(wxGLCanvas* canvas, const Pointf* position)
{
if (position != nullptr)
s_canvas_mgr.set_mouse_position(canvas, *position);
}
int _3DScene::get_hover_volume_id(wxGLCanvas* canvas) int _3DScene::get_hover_volume_id(wxGLCanvas* canvas)
{ {
return s_canvas_mgr.get_hover_volume_id(canvas); return s_canvas_mgr.get_hover_volume_id(canvas);
@ -2195,6 +2184,16 @@ void _3DScene::register_on_select_callback(wxGLCanvas* canvas, void* callback)
s_canvas_mgr.register_on_select_callback(canvas, callback); s_canvas_mgr.register_on_select_callback(canvas, callback);
} }
void _3DScene::register_on_model_update_callback(wxGLCanvas* canvas, void* callback)
{
s_canvas_mgr.register_on_model_update_callback(canvas, callback);
}
void _3DScene::register_on_move_callback(wxGLCanvas* canvas, void* callback)
{
s_canvas_mgr.register_on_move_callback(canvas, callback);
}
//void _3DScene::_glew_init() //void _3DScene::_glew_init()
//{ //{
// glewInit(); // glewInit();

View file

@ -613,9 +613,6 @@ public:
static bool is_mouse_dragging(wxGLCanvas* canvas); static bool is_mouse_dragging(wxGLCanvas* canvas);
static void set_mouse_dragging(wxGLCanvas* canvas, bool dragging); static void set_mouse_dragging(wxGLCanvas* canvas, bool dragging);
static Pointf get_mouse_position(wxGLCanvas* canvas);
static void set_mouse_position(wxGLCanvas* canvas, const Pointf* position);
static int get_hover_volume_id(wxGLCanvas* canvas); static int get_hover_volume_id(wxGLCanvas* canvas);
static void set_hover_volume_id(wxGLCanvas* canvas, int id); static void set_hover_volume_id(wxGLCanvas* canvas, int id);
@ -668,6 +665,8 @@ public:
static void register_on_double_click_callback(wxGLCanvas* canvas, void* callback); static void register_on_double_click_callback(wxGLCanvas* canvas, void* callback);
static void register_on_right_click_callback(wxGLCanvas* canvas, void* callback); static void register_on_right_click_callback(wxGLCanvas* canvas, void* callback);
static void register_on_select_callback(wxGLCanvas* canvas, void* callback); static void register_on_select_callback(wxGLCanvas* canvas, void* callback);
static void register_on_model_update_callback(wxGLCanvas* canvas, void* callback);
static void register_on_move_callback(wxGLCanvas* canvas, void* callback);
// static void _glew_init(); // static void _glew_init();
//################################################################################################################## //##################################################################################################################

View file

@ -301,6 +301,16 @@ const BoundingBoxf3& GLCanvas3D::Bed::get_bounding_box() const
return m_bounding_box; return m_bounding_box;
} }
bool GLCanvas3D::Bed::contains(const Point& point) const
{
return m_polygon.contains(point);
}
Point GLCanvas3D::Bed::point_projection(const Point& point) const
{
return m_polygon.point_projection(point);
}
void GLCanvas3D::Bed::render() const void GLCanvas3D::Bed::render() const
{ {
unsigned int triangles_vcount = m_triangles.get_data_size() / 3; unsigned int triangles_vcount = m_triangles.get_data_size() / 3;
@ -1049,19 +1059,19 @@ void GLCanvas3D::Mouse::set_position(const Pointf& position)
} }
GLCanvas3D::Drag::Drag() GLCanvas3D::Drag::Drag()
: m_start_mouse_position(DBL_MAX, DBL_MAX) : m_start_position_2D(INT_MAX, INT_MAX)
, m_volume_idx(-1) , m_volume_idx(-1)
{ {
} }
const Point& GLCanvas3D::Drag::get_start_mouse_position() const const Point& GLCanvas3D::Drag::get_start_position_2D() const
{ {
return m_start_mouse_position; return m_start_position_2D;
} }
void GLCanvas3D::Drag::set_start_mouse_position(const Point& position) void GLCanvas3D::Drag::set_start_position_2D(const Point& position)
{ {
m_start_mouse_position = position; m_start_position_2D = position;
} }
const Pointf3& GLCanvas3D::Drag::get_start_position_3D() const const Pointf3& GLCanvas3D::Drag::get_start_position_3D() const
@ -1843,6 +1853,18 @@ void GLCanvas3D::register_on_select_callback(void* callback)
m_on_select_callback.register_callback(callback); m_on_select_callback.register_callback(callback);
} }
void GLCanvas3D::register_on_model_update_callback(void* callback)
{
if (callback != nullptr)
m_on_model_update_callback.register_callback(callback);
}
void GLCanvas3D::register_on_move_callback(void* callback)
{
if (callback != nullptr)
m_on_move_callback.register_callback(callback);
}
void GLCanvas3D::on_size(wxSizeEvent& evt) void GLCanvas3D::on_size(wxSizeEvent& evt)
{ {
set_dirty(true); set_dirty(true);
@ -1954,14 +1976,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
int selected_object_idx = (is_layers_editing_enabled() && (m_print != nullptr)) ? get_layers_editing_first_selected_object_id(m_print->objects.size()) : -1; int selected_object_idx = (is_layers_editing_enabled() && (m_print != nullptr)) ? get_layers_editing_first_selected_object_id(m_print->objects.size()) : -1;
set_layers_editing_last_object_id(selected_object_idx); set_layers_editing_last_object_id(selected_object_idx);
set_mouse_dragging(evt.Dragging()); // set_mouse_dragging(false);
if (evt.Entering()) if (evt.Entering())
{ {
#if defined(__WXMSW__) || defined(__WXGTK__) #if defined(__WXMSW__) || defined(__WXGTK__)
// On Windows and Linux needs focus in order to catch key events // On Windows and Linux needs focus in order to catch key events
m_canvas->SetFocus(); m_canvas->SetFocus();
m_drag.set_start_mouse_position(Point(INT_MAX, INT_MAX)); m_drag.set_start_position_2D(Point(INT_MAX, INT_MAX));
#endif #endif
} }
else if (evt.LeftDClick()) else if (evt.LeftDClick())
@ -1979,7 +2001,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// A volume is selected and the mouse is inside the layer thickness bar. // A volume is selected and the mouse is inside the layer thickness bar.
// Start editing the layer height. // Start editing the layer height.
set_layers_editing_state(1); set_layers_editing_state(1);
perform_layer_editing_action(evt.GetY(), evt.ShiftDown(), evt.RightDown()); perform_layer_editing_action(pos.y, evt.ShiftDown(), evt.RightDown());
} }
else if ((selected_object_idx != -1) && reset_rect_contains(pos.x, pos.y)) else if ((selected_object_idx != -1) && reset_rect_contains(pos.x, pos.y))
{ {
@ -2056,105 +2078,136 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
} }
} }
// } elsif($e->Dragging && $e->LeftIsDown && (Slic3r::GUI::_3DScene::get_layers_editing_state($self) == 0) && defined($self->_drag_volume_idx)) { else if (evt.Dragging() && evt.LeftIsDown() && (get_layers_editing_state() == 0) && (m_drag.get_volume_idx() != -1))
// # Get new position at the same Z of the initial click point. {
// my $cur_pos = Slic3r::Linef3->new( // Get new position at the same Z of the initial click point.
// $self->mouse_to_3d($e->GetX, $e->GetY, 0), float z0 = 0.0f;
// $self->mouse_to_3d($e->GetX, $e->GetY, 1)) float z1 = 1.0f;
// ->intersect_plane($self->_drag_start_pos->z); Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_drag.get_start_position_3D().z);
//
// # Clip the new position, so the object center remains close to the bed. // Clip the new position, so the object center remains close to the bed.
// { cur_pos.translate(m_drag.get_volume_center_offset());
// $cur_pos->translate(@{$self->_drag_volume_center_offset}); Point cur_pos2(scale_(cur_pos.x), scale_(cur_pos.y));
// my $cur_pos2 = Slic3r::Point->new(scale($cur_pos->x), scale($cur_pos->y)); if (!m_bed.contains(cur_pos2))
// if (!$self->bed_polygon->contains_point($cur_pos2)) { {
// my $ip = $self->bed_polygon->point_projection($cur_pos2); Point ip = m_bed.point_projection(cur_pos2);
// $cur_pos->set_x(unscale($ip->x)); cur_pos.x = unscale(ip.x);
// $cur_pos->set_y(unscale($ip->y)); cur_pos.y = unscale(ip.y);
// } }
// $cur_pos->translate(@{$self->_drag_volume_center_offset->negative}); cur_pos.translate(m_drag.get_volume_center_offset().negative());
// }
// // Calculate the translation vector.
// # Calculate the translation vector. Vectorf3 vector = m_drag.get_start_position_3D().vector_to(cur_pos);
// my $vector = $self->_drag_start_pos->vector_to($cur_pos); // Get the volume being dragged.
// # Get the volume being dragged. GLVolume* volume = m_volumes->volumes[m_drag.get_volume_idx()];
// my $volume = $self->volumes->[$self->_drag_volume_idx]; // Get all volumes belonging to the same group, if any.
// # Get all volumes belonging to the same group, if any. std::vector<GLVolume*> volumes;
// my @volumes = ($volume->drag_group_id == -1) ? if (volume->drag_group_id == -1)
// ($volume) : volumes.push_back(volume);
// grep $_->drag_group_id == $volume->drag_group_id, @{$self->volumes}; else
// # Apply new temporary volume origin and ignore Z. {
// $_->translate($vector->x, $vector->y, 0) for @volumes; for (GLVolume* v : m_volumes->volumes)
// $self->_drag_start_pos($cur_pos); {
// $self->_dragged(1); if ((v != nullptr) && (v->drag_group_id == volume->drag_group_id))
// $self->Refresh; volumes.push_back(v);
// $self->Update; }
// } elsif($e->Dragging) { }
// if ((Slic3r::GUI::_3DScene::get_layers_editing_state($self) > 0) && ($object_idx_selected != -1)) {
// Slic3r::GUI::_3DScene::perform_layer_editing_action($self, $e->GetY, $e->ShiftDown, $e->RightIsDown) if (Slic3r::GUI::_3DScene::get_layers_editing_state($self) == 1); // Apply new temporary volume origin and ignore Z.
// } elsif($e->LeftIsDown) { for (GLVolume* v : volumes)
//# if dragging over blank area with left button, rotate {
// if (defined $self->_drag_start_pos) { v->origin.translate(vector.x, vector.y, 0.0);
// my $orig = $self->_drag_start_pos; }
// if (TURNTABLE_MODE) {
// # Turntable mode is enabled by default. m_drag.set_start_position_3D(cur_pos);
// Slic3r::GUI::_3DScene::set_camera_phi($self, Slic3r::GUI::_3DScene::get_camera_phi($self) + ($pos->x - $orig->x) * TRACKBALLSIZE); set_mouse_dragging(true);
// Slic3r::GUI::_3DScene::set_camera_theta($self, Slic3r::GUI::_3DScene::get_camera_theta($self) - ($pos->y - $orig->y) * TRACKBALLSIZE); m_canvas->Refresh();
// } m_canvas->Update();
// else { }
// my $size = $self->GetClientSize; else if (evt.Dragging())
// my @quat = trackball( {
// $orig->x / ($size->width / 2) - 1, if ((get_layers_editing_state() > 0) && (selected_object_idx != -1))
// 1 - $orig->y / ($size->height / 2), # / {
// $pos->x / ($size->width / 2) - 1, if (get_layers_editing_state() == 1)
// 1 - $pos->y / ($size->height / 2), # / perform_layer_editing_action(pos.y, evt.ShiftDown(), evt.RightIsDown());
// ); }
// $self->_quat(mulquats($self->_quat, \@quat)); // } elsif($e->LeftIsDown) {
// } //# if dragging over blank area with left button, rotate
// $self->on_viewport_changed->() if $self->on_viewport_changed; // if (defined $self->_drag_start_pos) {
// $self->Refresh; // my $orig = $self->_drag_start_pos;
// $self->Update; // if (TURNTABLE_MODE) {
// } // # Turntable mode is enabled by default.
// $self->_drag_start_pos($pos); // Slic3r::GUI::_3DScene::set_camera_phi($self, Slic3r::GUI::_3DScene::get_camera_phi($self) + ($pos->x - $orig->x) * TRACKBALLSIZE);
// } elsif($e->MiddleIsDown || $e->RightIsDown) { // Slic3r::GUI::_3DScene::set_camera_theta($self, Slic3r::GUI::_3DScene::get_camera_theta($self) - ($pos->y - $orig->y) * TRACKBALLSIZE);
// # If dragging over blank area with right button, pan. // }
// if (defined $self->_drag_start_xy) { // else {
// # get point in model space at Z = 0 // my $size = $self->GetClientSize;
// my $cur_pos = $self->mouse_to_3d($e->GetX, $e->GetY, 0); // my @quat = trackball(
// my $orig = $self->mouse_to_3d($self->_drag_start_xy->x, $self->_drag_start_xy->y, 0); // $orig->x / ($size->width / 2) - 1,
// my $camera_target = Slic3r::GUI::_3DScene::get_camera_target($self); // 1 - $orig->y / ($size->height / 2), # /
// $camera_target->translate(@{$orig->vector_to($cur_pos)->negative}); // $pos->x / ($size->width / 2) - 1,
// Slic3r::GUI::_3DScene::set_camera_target($self, $camera_target); // 1 - $pos->y / ($size->height / 2), # /
// $self->on_viewport_changed->() if $self->on_viewport_changed; // );
// $self->Refresh; // $self->_quat(mulquats($self->_quat, \@quat));
// $self->Update; // }
// } // $self->on_viewport_changed->() if $self->on_viewport_changed;
// $self->_drag_start_xy($pos); // $self->Refresh;
// } // $self->Update;
// } elsif($e->LeftUp || $e->MiddleUp || $e->RightUp) { // }
// if (Slic3r::GUI::_3DScene::get_layers_editing_state($self) > 0) { // $self->_drag_start_pos($pos);
// Slic3r::GUI::_3DScene::set_layers_editing_state($self, 0); // } elsif($e->MiddleIsDown || $e->RightIsDown) {
// Slic3r::GUI::_3DScene::stop_timer($self); // # If dragging over blank area with right button, pan.
// $self->on_model_update->() // if (defined $self->_drag_start_xy) {
// if ($object_idx_selected != -1 && $self->on_model_update); // # get point in model space at Z = 0
// } elsif($self->on_move && defined($self->_drag_volume_idx) && $self->_dragged) { // my $cur_pos = $self->mouse_to_3d($e->GetX, $e->GetY, 0);
// # get all volumes belonging to the same group, if any // my $orig = $self->mouse_to_3d($self->_drag_start_xy->x, $self->_drag_start_xy->y, 0);
// my @volume_idxs; // my $camera_target = Slic3r::GUI::_3DScene::get_camera_target($self);
// my $group_id = $self->volumes->[$self->_drag_volume_idx]->drag_group_id; // $camera_target->translate(@{$orig->vector_to($cur_pos)->negative});
// if ($group_id == -1) { // Slic3r::GUI::_3DScene::set_camera_target($self, $camera_target);
// @volume_idxs = ($self->_drag_volume_idx); // $self->on_viewport_changed->() if $self->on_viewport_changed;
// } // $self->Refresh;
// else { // $self->Update;
// @volume_idxs = grep $self->volumes->[$_]->drag_group_id == $group_id, // }
// 0..$#{$self->volumes}; // $self->_drag_start_xy($pos);
// } // }
// $self->on_move->(@volume_idxs); }
// } else if (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())
// $self->_drag_volume_idx(undef); {
// $self->_drag_start_pos(undef); if (get_layers_editing_state() > 0)
// $self->_drag_start_xy(undef); {
// $self->_dragged(undef); set_layers_editing_state(0);
// } stop_timer();
if (selected_object_idx != -1)
m_on_model_update_callback.call();
}
else if ((m_drag.get_volume_idx() != -1) && m_mouse.is_dragging())
{
// get all volumes belonging to the same group, if any
std::vector<int> volume_idxs;
int vol_id = m_drag.get_volume_idx();
int group_id = m_volumes->volumes[vol_id]->drag_group_id;
if (group_id == -1)
{
volume_idxs.push_back(vol_id);
}
else
{
for (int i = 0; i < m_volumes->volumes.size(); ++i)
{
if (m_volumes->volumes[i]->drag_group_id == group_id)
volume_idxs.push_back(i);
}
}
m_on_move_callback.call(volume_idxs);
}
m_drag.set_volume_idx(-1);
m_drag.set_start_position_3D(Pointf3(DBL_MAX, DBL_MAX, DBL_MAX));
m_drag.set_start_position_2D(Point(INT_MAX, INT_MAX));
set_mouse_dragging(false);
}
else if (evt.Moving()) else if (evt.Moving())
{ {
set_mouse_position(Pointf((coordf_t)pos.x, (coordf_t)pos.y)); set_mouse_position(Pointf((coordf_t)pos.x, (coordf_t)pos.y));
@ -2300,6 +2353,8 @@ void GLCanvas3D::_deregister_callbacks()
m_on_double_click_callback.deregister_callback(); m_on_double_click_callback.deregister_callback();
m_on_right_click_callback.deregister_callback(); m_on_right_click_callback.deregister_callback();
m_on_select_callback.deregister_callback(); m_on_select_callback.deregister_callback();
m_on_model_update_callback.deregister_callback();
m_on_move_callback.deregister_callback();
} }
void GLCanvas3D::_mark_volumes_for_layer_height() const void GLCanvas3D::_mark_volumes_for_layer_height() const
@ -2655,12 +2710,12 @@ Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
GLint y = viewport[3] - (GLint)mouse_pos.y; GLint y = viewport[3] - (GLint)mouse_pos.y;
GLfloat mouse_z; GLfloat mouse_z;
if (z == nullptr) if (z == nullptr)
::glReadPixels((GLint)mouse_pos.x, (GLint)mouse_pos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); ::glReadPixels((GLint)mouse_pos.x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z);
else else
mouse_z = *z; mouse_z = *z;
GLdouble out_x, out_y, out_z; GLdouble out_x, out_y, out_z;
::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)mouse_pos.y, mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); ::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)y, mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z);
return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z); return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z);
} }

View file

@ -136,6 +136,8 @@ public:
void set_shape(const Pointfs& shape); void set_shape(const Pointfs& shape);
const BoundingBoxf3& get_bounding_box() const; const BoundingBoxf3& get_bounding_box() const;
bool contains(const Point& point) const;
Point point_projection(const Point& point) const;
void render() const; void render() const;
@ -308,7 +310,7 @@ public:
class Drag class Drag
{ {
Point m_start_mouse_position; Point m_start_position_2D;
Pointf3 m_start_position_3D; Pointf3 m_start_position_3D;
Vectorf3 m_volume_center_offset; Vectorf3 m_volume_center_offset;
int m_volume_idx; int m_volume_idx;
@ -316,8 +318,8 @@ public:
public: public:
Drag(); Drag();
const Point& get_start_mouse_position() const; const Point& get_start_position_2D() const;
void set_start_mouse_position(const Point& mouse_position); void set_start_position_2D(const Point& position);
const Pointf3& get_start_position_3D() const; const Pointf3& get_start_position_3D() const;
void set_start_position_3D(const Pointf3& position); void set_start_position_3D(const Pointf3& position);
@ -360,6 +362,8 @@ private:
PerlCallback m_on_double_click_callback; PerlCallback m_on_double_click_callback;
PerlCallback m_on_right_click_callback; PerlCallback m_on_right_click_callback;
PerlCallback m_on_select_callback; PerlCallback m_on_select_callback;
PerlCallback m_on_model_update_callback;
PerlCallback m_on_move_callback;
public: public:
GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context); GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context);
@ -492,6 +496,8 @@ public:
void register_on_double_click_callback(void* callback); void register_on_double_click_callback(void* callback);
void register_on_right_click_callback(void* callback); void register_on_right_click_callback(void* callback);
void register_on_select_callback(void* callback); void register_on_select_callback(void* callback);
void register_on_model_update_callback(void* callback);
void register_on_move_callback(void* callback);
void on_size(wxSizeEvent& evt); void on_size(wxSizeEvent& evt);
void on_idle(wxIdleEvent& evt); void on_idle(wxIdleEvent& evt);

View file

@ -476,19 +476,6 @@ void GLCanvas3DManager::set_mouse_dragging(wxGLCanvas* canvas, bool dragging)
it->second->set_mouse_dragging(dragging); it->second->set_mouse_dragging(dragging);
} }
Pointf GLCanvas3DManager::get_mouse_position(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->get_mouse_position() : Pointf();
}
void GLCanvas3DManager::set_mouse_position(wxGLCanvas* canvas, const Pointf& position)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_mouse_position(position);
}
int GLCanvas3DManager::get_hover_volume_id(wxGLCanvas* canvas) const int GLCanvas3DManager::get_hover_volume_id(wxGLCanvas* canvas) const
{ {
CanvasesMap::const_iterator it = _get_canvas(canvas); CanvasesMap::const_iterator it = _get_canvas(canvas);
@ -738,6 +725,20 @@ void GLCanvas3DManager::register_on_select_callback(wxGLCanvas* canvas, void* ca
it->second->register_on_select_callback(callback); it->second->register_on_select_callback(callback);
} }
void GLCanvas3DManager::register_on_model_update_callback(wxGLCanvas* canvas, void* callback)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->register_on_model_update_callback(callback);
}
void GLCanvas3DManager::register_on_move_callback(wxGLCanvas* canvas, void* callback)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->register_on_move_callback(callback);
}
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas) GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
{ {
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas); return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);

View file

@ -113,9 +113,6 @@ public:
bool is_mouse_dragging(wxGLCanvas* canvas) const; bool is_mouse_dragging(wxGLCanvas* canvas) const;
void set_mouse_dragging(wxGLCanvas* canvas, bool dragging); void set_mouse_dragging(wxGLCanvas* canvas, bool dragging);
Pointf get_mouse_position(wxGLCanvas* canvas) const;
void set_mouse_position(wxGLCanvas* canvas, const Pointf& position);
int get_hover_volume_id(wxGLCanvas* canvas) const; int get_hover_volume_id(wxGLCanvas* canvas) const;
void set_hover_volume_id(wxGLCanvas* canvas, int id); void set_hover_volume_id(wxGLCanvas* canvas, int id);
@ -168,6 +165,8 @@ public:
void register_on_double_click_callback(wxGLCanvas* canvas, void* callback); void register_on_double_click_callback(wxGLCanvas* canvas, void* callback);
void register_on_right_click_callback(wxGLCanvas* canvas, void* callback); void register_on_right_click_callback(wxGLCanvas* canvas, void* callback);
void register_on_select_callback(wxGLCanvas* canvas, void* callback); void register_on_select_callback(wxGLCanvas* canvas, void* callback);
void register_on_model_update_callback(wxGLCanvas* canvas, void* callback);
void register_on_move_callback(wxGLCanvas* canvas, void* callback);
private: private:
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas); CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);

View file

@ -555,21 +555,6 @@ set_mouse_dragging(canvas, dragging)
CODE: CODE:
_3DScene::set_mouse_dragging((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), dragging); _3DScene::set_mouse_dragging((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), dragging);
Clone<Pointf>
get_mouse_position(canvas)
SV *canvas;
CODE:
RETVAL = _3DScene::get_mouse_position((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
OUTPUT:
RETVAL
void
set_mouse_position(canvas, position)
SV *canvas;
Pointf *position;
CODE:
_3DScene::set_mouse_position((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), position);
int int
get_hover_volume_id(canvas) get_hover_volume_id(canvas)
SV *canvas; SV *canvas;
@ -846,7 +831,21 @@ register_on_select_callback(canvas, callback)
SV *callback; SV *callback;
CODE: CODE:
_3DScene::register_on_select_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); _3DScene::register_on_select_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
void
register_on_model_update_callback(canvas, callback)
SV *canvas;
SV *callback;
CODE:
_3DScene::register_on_model_update_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
void
register_on_move_callback(canvas, callback)
SV *canvas;
SV *callback;
CODE:
_3DScene::register_on_move_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
unsigned int unsigned int
finalize_legend_texture() finalize_legend_texture()