3DScene layers editing mouse containment methods moved to c++
This commit is contained in:
parent
994222c317
commit
aacdcd4add
@ -409,19 +409,19 @@ sub _variable_layer_thickness_reset_rect_viewport {
|
||||
#==============================================================================================================================
|
||||
}
|
||||
|
||||
sub _variable_layer_thickness_bar_rect_mouse_inside {
|
||||
my ($self, $mouse_evt) = @_;
|
||||
my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_bar_rect_screen;
|
||||
return $mouse_evt->GetX >= $bar_left && $mouse_evt->GetX <= $bar_right && $mouse_evt->GetY >= $bar_top && $mouse_evt->GetY <= $bar_bottom;
|
||||
}
|
||||
|
||||
sub _variable_layer_thickness_reset_rect_mouse_inside {
|
||||
my ($self, $mouse_evt) = @_;
|
||||
my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_reset_rect_screen;
|
||||
return $mouse_evt->GetX >= $bar_left && $mouse_evt->GetX <= $bar_right && $mouse_evt->GetY >= $bar_top && $mouse_evt->GetY <= $bar_bottom;
|
||||
}
|
||||
|
||||
#==============================================================================================================================
|
||||
#sub _variable_layer_thickness_bar_rect_mouse_inside {
|
||||
# my ($self, $mouse_evt) = @_;
|
||||
# my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_bar_rect_screen;
|
||||
# return $mouse_evt->GetX >= $bar_left && $mouse_evt->GetX <= $bar_right && $mouse_evt->GetY >= $bar_top && $mouse_evt->GetY <= $bar_bottom;
|
||||
#}
|
||||
#
|
||||
#sub _variable_layer_thickness_reset_rect_mouse_inside {
|
||||
# my ($self, $mouse_evt) = @_;
|
||||
# my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_reset_rect_screen;
|
||||
# return $mouse_evt->GetX >= $bar_left && $mouse_evt->GetX <= $bar_right && $mouse_evt->GetY >= $bar_top && $mouse_evt->GetY <= $bar_bottom;
|
||||
#}
|
||||
#
|
||||
#sub _variable_layer_thickness_bar_mouse_cursor_z_relative {
|
||||
# my ($self) = @_;
|
||||
# my $mouse_pos = $self->ScreenToClientPoint(Wx::GetMousePosition());
|
||||
@ -513,7 +513,10 @@ sub mouse_event {
|
||||
$self->SetFocus;
|
||||
$self->_drag_start_xy(undef);
|
||||
} elsif ($e->LeftDClick) {
|
||||
if ($object_idx_selected != -1 && $self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
if ($object_idx_selected != -1 && Slic3r::GUI::_3DScene::bar_rect_contains($self, $e->GetX, $e->GetY)) {
|
||||
# if ($object_idx_selected != -1 && $self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
} elsif ($self->on_double_click) {
|
||||
$self->on_double_click->();
|
||||
}
|
||||
@ -525,12 +528,18 @@ sub mouse_event {
|
||||
# my $volume_idx = $self->_hover_volume_idx // -1;
|
||||
#==============================================================================================================================
|
||||
$self->_layer_height_edited(0);
|
||||
if ($object_idx_selected != -1 && $self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
if ($object_idx_selected != -1 && Slic3r::GUI::_3DScene::bar_rect_contains($self, $e->GetX, $e->GetY)) {
|
||||
# if ($object_idx_selected != -1 && $self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
# A volume is selected and the mouse is hovering over a layer thickness bar.
|
||||
# Start editing the layer height.
|
||||
$self->_layer_height_edited(1);
|
||||
$self->_variable_layer_thickness_action($e);
|
||||
} elsif ($object_idx_selected != -1 && $self->_variable_layer_thickness_reset_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
} elsif ($object_idx_selected != -1 && Slic3r::GUI::_3DScene::reset_rect_contains($self, $e->GetX, $e->GetY)) {
|
||||
# } elsif ($object_idx_selected != -1 && $self->_variable_layer_thickness_reset_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
$self->{print}->get_object($object_idx_selected)->reset_layer_height_profile;
|
||||
# Index 2 means no editing, just wait for mouse up event.
|
||||
$self->_layer_height_edited(2);
|
||||
@ -738,7 +747,10 @@ sub mouse_wheel_event {
|
||||
#==============================================================================================================================
|
||||
if ($object_idx_selected != -1) {
|
||||
# A volume is selected. Test, whether hovering over a layer thickness bar.
|
||||
if ($self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
if (Slic3r::GUI::_3DScene::bar_rect_contains($self, $e->GetX, $e->GetY)) {
|
||||
# if ($self->_variable_layer_thickness_bar_rect_mouse_inside($e)) {
|
||||
#==============================================================================================================================
|
||||
# Adjust the width of the selection.
|
||||
#==============================================================================================================================
|
||||
Slic3r::GUI::_3DScene::set_layers_editing_band_width($self, max(min(Slic3r::GUI::_3DScene::get_layers_editing_band_width($self) * (1 + 0.1 * $e->GetWheelRotation() / $e->GetWheelDelta()), 10.), 1.5));
|
||||
|
@ -2080,6 +2080,16 @@ int _3DScene::get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, un
|
||||
return s_canvas_mgr.get_layers_editing_first_selected_object_id(canvas, objects_count);
|
||||
}
|
||||
|
||||
bool _3DScene::bar_rect_contains(wxGLCanvas* canvas, float x, float y)
|
||||
{
|
||||
return s_canvas_mgr.bar_rect_contains(canvas, x, y);
|
||||
}
|
||||
|
||||
bool _3DScene::reset_rect_contains(wxGLCanvas* canvas, float x, float y)
|
||||
{
|
||||
return s_canvas_mgr.reset_rect_contains(canvas, x, y);
|
||||
}
|
||||
|
||||
void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
|
||||
{
|
||||
s_canvas_mgr.zoom_to_bed(canvas);
|
||||
|
@ -638,6 +638,8 @@ public:
|
||||
|
||||
static float get_layers_editing_cursor_z_relative(wxGLCanvas* canvas);
|
||||
static int get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count);
|
||||
static bool bar_rect_contains(wxGLCanvas* canvas, float x, float y);
|
||||
static bool reset_rect_contains(wxGLCanvas* canvas, float x, float y);
|
||||
|
||||
static void zoom_to_bed(wxGLCanvas* canvas);
|
||||
static void zoom_to_volumes(wxGLCanvas* canvas);
|
||||
|
@ -775,58 +775,23 @@ int GLCanvas3D::LayersEditing::get_first_selected_object_id(const GLVolumeCollec
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool GLCanvas3D::LayersEditing::bar_rect_contains(const GLCanvas3D& canvas, float x, float y)
|
||||
{
|
||||
const Rect& rect = _get_bar_rect_screen(canvas);
|
||||
return (rect.get_left() <= x) && (x <= rect.get_right()) && (rect.get_top() <= y) && (y <= rect.get_bottom());
|
||||
}
|
||||
|
||||
bool GLCanvas3D::LayersEditing::reset_rect_contains(const GLCanvas3D& canvas, float x, float y)
|
||||
{
|
||||
const Rect& rect = _get_reset_rect_screen(canvas);
|
||||
return (rect.get_left() <= x) && (x <= rect.get_right()) && (rect.get_top() <= y) && (y <= rect.get_bottom());
|
||||
}
|
||||
|
||||
bool GLCanvas3D::LayersEditing::_is_initialized() const
|
||||
{
|
||||
return m_shader.is_initialized();
|
||||
}
|
||||
|
||||
GLCanvas3D::LayersEditing::GLTextureData GLCanvas3D::LayersEditing::_load_texture_from_file(const std::string& filename) const
|
||||
{
|
||||
const std::string& path = resources_dir() + "/icons/";
|
||||
|
||||
// Load a PNG with an alpha channel.
|
||||
wxImage image;
|
||||
if (!image.LoadFile(path + filename, wxBITMAP_TYPE_PNG))
|
||||
return GLTextureData();
|
||||
|
||||
int width = image.GetWidth();
|
||||
int height = image.GetHeight();
|
||||
int n_pixels = width * height;
|
||||
|
||||
if (n_pixels <= 0)
|
||||
return GLTextureData();
|
||||
|
||||
// Get RGB & alpha raw data from wxImage, pack them into an array.
|
||||
unsigned char* img_rgb = image.GetData();
|
||||
if (img_rgb == nullptr)
|
||||
return GLTextureData();
|
||||
|
||||
unsigned char* img_alpha = image.GetAlpha();
|
||||
|
||||
std::vector<unsigned char> data(n_pixels * 4, 0);
|
||||
for (int i = 0; i < n_pixels; ++i)
|
||||
{
|
||||
int data_id = i * 4;
|
||||
int img_id = i * 3;
|
||||
data[data_id + 0] = img_rgb[img_id + 0];
|
||||
data[data_id + 1] = img_rgb[img_id + 1];
|
||||
data[data_id + 2] = img_rgb[img_id + 2];
|
||||
data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255;
|
||||
}
|
||||
|
||||
// sends data to gpu
|
||||
GLuint tex_id;
|
||||
::glGenTextures(1, &tex_id);
|
||||
::glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
::glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return GLTextureData((unsigned int)tex_id, width, height);
|
||||
}
|
||||
|
||||
void GLCanvas3D::LayersEditing::_render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const
|
||||
{
|
||||
if (m_tooltip_texture.id == 0)
|
||||
@ -957,6 +922,53 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object,
|
||||
}
|
||||
}
|
||||
|
||||
GLCanvas3D::LayersEditing::GLTextureData GLCanvas3D::LayersEditing::_load_texture_from_file(const std::string& filename)
|
||||
{
|
||||
const std::string& path = resources_dir() + "/icons/";
|
||||
|
||||
// Load a PNG with an alpha channel.
|
||||
wxImage image;
|
||||
if (!image.LoadFile(path + filename, wxBITMAP_TYPE_PNG))
|
||||
return GLTextureData();
|
||||
|
||||
int width = image.GetWidth();
|
||||
int height = image.GetHeight();
|
||||
int n_pixels = width * height;
|
||||
|
||||
if (n_pixels <= 0)
|
||||
return GLTextureData();
|
||||
|
||||
// Get RGB & alpha raw data from wxImage, pack them into an array.
|
||||
unsigned char* img_rgb = image.GetData();
|
||||
if (img_rgb == nullptr)
|
||||
return GLTextureData();
|
||||
|
||||
unsigned char* img_alpha = image.GetAlpha();
|
||||
|
||||
std::vector<unsigned char> data(n_pixels * 4, 0);
|
||||
for (int i = 0; i < n_pixels; ++i)
|
||||
{
|
||||
int data_id = i * 4;
|
||||
int img_id = i * 3;
|
||||
data[data_id + 0] = img_rgb[img_id + 0];
|
||||
data[data_id + 1] = img_rgb[img_id + 1];
|
||||
data[data_id + 2] = img_rgb[img_id + 2];
|
||||
data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255;
|
||||
}
|
||||
|
||||
// sends data to gpu
|
||||
GLuint tex_id;
|
||||
::glGenTextures(1, &tex_id);
|
||||
::glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
::glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return GLTextureData((unsigned int)tex_id, width, height);
|
||||
}
|
||||
|
||||
Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas)
|
||||
{
|
||||
const Size& cnv_size = canvas.get_canvas_size();
|
||||
@ -1664,9 +1676,9 @@ GLShader* GLCanvas3D::get_layers_editing_shader()
|
||||
return m_layers_editing.get_shader();
|
||||
}
|
||||
|
||||
float GLCanvas3D::get_layers_editing_cursor_z_relative(const GLCanvas3D& canvas) const
|
||||
float GLCanvas3D::get_layers_editing_cursor_z_relative() const
|
||||
{
|
||||
return m_layers_editing.get_cursor_z_relative(canvas);
|
||||
return m_layers_editing.get_cursor_z_relative(*this);
|
||||
}
|
||||
|
||||
int GLCanvas3D::get_layers_editing_first_selected_object_id(unsigned int objects_count) const
|
||||
@ -1674,6 +1686,16 @@ int GLCanvas3D::get_layers_editing_first_selected_object_id(unsigned int objects
|
||||
return (m_volumes != nullptr) ? m_layers_editing.get_first_selected_object_id(*m_volumes, objects_count) : -1;
|
||||
}
|
||||
|
||||
bool GLCanvas3D::bar_rect_contains(float x, float y) const
|
||||
{
|
||||
return m_layers_editing.bar_rect_contains(*this, x, y);
|
||||
}
|
||||
|
||||
bool GLCanvas3D::reset_rect_contains(float x, float y) const
|
||||
{
|
||||
return m_layers_editing.reset_rect_contains(*this, x, y);
|
||||
}
|
||||
|
||||
void GLCanvas3D::render_bed() const
|
||||
{
|
||||
m_bed.render();
|
||||
|
@ -258,14 +258,16 @@ public:
|
||||
|
||||
static float get_cursor_z_relative(const GLCanvas3D& canvas);
|
||||
static int get_first_selected_object_id(const GLVolumeCollection& volumes, unsigned int objects_count);
|
||||
static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y);
|
||||
static bool reset_rect_contains(const GLCanvas3D& canvas, float x, float y);
|
||||
|
||||
private:
|
||||
bool _is_initialized() const;
|
||||
GLTextureData _load_texture_from_file(const std::string& filename) const;
|
||||
void _render_tooltip_texture(const GLCanvas3D& canvas, const Rect& bar_rect, const Rect& reset_rect) const;
|
||||
void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const;
|
||||
void _render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const;
|
||||
void _render_profile(const PrintObject& print_object, const Rect& bar_rect) const;
|
||||
static GLTextureData _load_texture_from_file(const std::string& filename);
|
||||
static Rect _get_bar_rect_screen(const GLCanvas3D& canvas);
|
||||
static Rect _get_reset_rect_screen(const GLCanvas3D& canvas);
|
||||
static Rect _get_bar_rect_viewport(const GLCanvas3D& canvas);
|
||||
@ -416,8 +418,10 @@ public:
|
||||
|
||||
GLShader* get_layers_editing_shader();
|
||||
|
||||
float get_layers_editing_cursor_z_relative(const GLCanvas3D& canvas) const;
|
||||
float get_layers_editing_cursor_z_relative() const;
|
||||
int get_layers_editing_first_selected_object_id(unsigned int objects_count) const;
|
||||
bool bar_rect_contains(float x, float y) const;
|
||||
bool reset_rect_contains(float x, float y) const;
|
||||
|
||||
void zoom_to_bed();
|
||||
void zoom_to_volumes();
|
||||
|
@ -553,7 +553,7 @@ GLShader* GLCanvas3DManager::get_layers_editing_shader(wxGLCanvas* canvas)
|
||||
float GLCanvas3DManager::get_layers_editing_cursor_z_relative(wxGLCanvas* canvas) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->get_layers_editing_cursor_z_relative(*it->second) : 0.0f;
|
||||
return (it != m_canvases.end()) ? it->second->get_layers_editing_cursor_z_relative() : 0.0f;
|
||||
}
|
||||
|
||||
int GLCanvas3DManager::get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count) const
|
||||
@ -562,6 +562,18 @@ int GLCanvas3DManager::get_layers_editing_first_selected_object_id(wxGLCanvas* c
|
||||
return (it != m_canvases.end()) ? it->second->get_layers_editing_first_selected_object_id(objects_count) : 0.;
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::bar_rect_contains(wxGLCanvas* canvas, float x, float y) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->bar_rect_contains(x, y) : false;
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::reset_rect_contains(wxGLCanvas* canvas, float x, float y) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->reset_rect_contains(x, y) : false;
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
|
||||
float get_layers_editing_cursor_z_relative(wxGLCanvas* canvas) const;
|
||||
int get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count) const;
|
||||
bool bar_rect_contains(wxGLCanvas* canvas, float x, float y) const;
|
||||
bool reset_rect_contains(wxGLCanvas* canvas, float x, float y) const;
|
||||
|
||||
void zoom_to_bed(wxGLCanvas* canvas);
|
||||
void zoom_to_volumes(wxGLCanvas* canvas);
|
||||
|
@ -679,6 +679,25 @@ get_layers_editing_first_selected_object_id(canvas, objects_count)
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
bool
|
||||
bar_rect_contains(canvas, x, y)
|
||||
SV *canvas;
|
||||
float x;
|
||||
float y;
|
||||
CODE:
|
||||
RETVAL = _3DScene::bar_rect_contains((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), x, y);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
bool
|
||||
reset_rect_contains(canvas, x, y)
|
||||
SV *canvas;
|
||||
float x;
|
||||
float y;
|
||||
CODE:
|
||||
RETVAL = _3DScene::reset_rect_contains((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), x, y);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
zoom_to_bed(canvas)
|
||||
|
Loading…
Reference in New Issue
Block a user