mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 08:00:40 +08:00
Staged more of mouse_down()
This commit is contained in:
parent
21da567d43
commit
062e0fa7dc
@ -159,7 +159,52 @@ void Plate2D::mouse_drag(wxMouseEvent& e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plate2D::mouse_down(wxMouseEvent& e) {
|
void Plate2D::mouse_down(wxMouseEvent& e) {
|
||||||
|
this->SetFocus(); // Focus needed to move selected instance with keyboard arrows
|
||||||
|
|
||||||
|
const auto& pos = e.GetPosition();
|
||||||
|
const auto point = this->point_to_model_units(pos);
|
||||||
|
this->on_select_object(-1);
|
||||||
|
this->selected_instance = {-1, -1};
|
||||||
|
|
||||||
|
Slic3r::Log::info(LogChannel, LOG_WSTRING("Mouse down at scaled point " << point.x << ", " << point.y));
|
||||||
|
|
||||||
|
// Iterate through the list backwards to catch the highest object (last placed/drawn), which
|
||||||
|
// is usually what the user wants.
|
||||||
|
for (auto obj = this->objects.rbegin(); obj != this->objects.rend(); obj++) {
|
||||||
|
const auto& obj_idx {obj->identifier};
|
||||||
|
for (auto thumbnail = obj->instance_thumbnails.crbegin(); thumbnail != obj->instance_thumbnails.crend(); thumbnail++) {
|
||||||
|
Slic3r::Log::info(LogChannel, LOG_WSTRING("First point: " << thumbnail->contours()[0].points[0].x << "," << thumbnail->contours()[0].points[0].y));
|
||||||
|
if (thumbnail->contains(point)) {
|
||||||
|
const auto& instance_idx {std::distance(thumbnail, obj->instance_thumbnails.crend()) - 1};
|
||||||
|
Slic3r::Log::info(LogChannel, LOG_WSTRING(instance_idx << " contains this point"));
|
||||||
|
this->on_select_object(obj_idx);
|
||||||
|
if (e.LeftDown()) {
|
||||||
|
// start dragging
|
||||||
|
auto& instance {this->model->objects.at(obj_idx)->instances.at(instance_idx)};
|
||||||
|
auto instance_origin { Point::new_scale(instance->offset) };
|
||||||
|
|
||||||
|
this->drag_start_pos { Slic3r::Point(
|
||||||
|
point.x - instance_origin.x,
|
||||||
|
point.y - instance_origin.y,
|
||||||
|
)};
|
||||||
|
|
||||||
|
this->drag_object = { obj_idx, instance_idx };
|
||||||
|
this->selected_instance = this->drag_object;
|
||||||
|
|
||||||
|
obj->selected_instance = instance_idx;
|
||||||
|
|
||||||
|
} else if(e.RightDown()) {
|
||||||
|
this->on_right_click(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
void Plate2D::on_select_object(int i) {
|
||||||
|
}
|
||||||
|
|
||||||
void Plate2D::mouse_up(wxMouseEvent& e) {
|
void Plate2D::mouse_up(wxMouseEvent& e) {
|
||||||
}
|
}
|
||||||
void Plate2D::mouse_dclick(wxMouseEvent& e) {
|
void Plate2D::mouse_dclick(wxMouseEvent& e) {
|
||||||
|
@ -29,6 +29,12 @@ enum class MoveDirection {
|
|||||||
Up, Down, Left, Right
|
Up, Down, Left, Right
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// simple POD to make referencing this pair of identifiers easy
|
||||||
|
struct InstanceIdx {
|
||||||
|
long obj;
|
||||||
|
long inst;
|
||||||
|
};
|
||||||
|
|
||||||
class Plate2D : public wxPanel {
|
class Plate2D : public wxPanel {
|
||||||
public:
|
public:
|
||||||
Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
|
Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
|
||||||
@ -58,7 +64,10 @@ private:
|
|||||||
wxPen dark_pen {};
|
wxPen dark_pen {};
|
||||||
|
|
||||||
bool user_drawn_background {(the_os == OS::Mac ? false : true)};
|
bool user_drawn_background {(the_os == OS::Mac ? false : true)};
|
||||||
size_t selected_instance;
|
|
||||||
|
/// The object id and selected
|
||||||
|
InstanceIdx selected_instance;
|
||||||
|
InstanceIdx drag_object;
|
||||||
|
|
||||||
/// Handle mouse-move events
|
/// Handle mouse-move events
|
||||||
void mouse_drag(wxMouseEvent& e);
|
void mouse_drag(wxMouseEvent& e);
|
||||||
@ -66,6 +75,11 @@ private:
|
|||||||
void mouse_up(wxMouseEvent& e);
|
void mouse_up(wxMouseEvent& e);
|
||||||
void mouse_dclick(wxMouseEvent& e);
|
void mouse_dclick(wxMouseEvent& e);
|
||||||
|
|
||||||
|
wxPoint drag_start_pos {};
|
||||||
|
|
||||||
|
/// Do something on right-clicks.
|
||||||
|
void on_right_click(const wxPoint& pos) { }
|
||||||
|
|
||||||
/// Handle repaint events
|
/// Handle repaint events
|
||||||
void repaint(wxPaintEvent& e);
|
void repaint(wxPaintEvent& e);
|
||||||
|
|
||||||
@ -119,6 +133,7 @@ private:
|
|||||||
/// Remove all instance thumbnails.
|
/// Remove all instance thumbnails.
|
||||||
void clean_instance_thumbnails();
|
void clean_instance_thumbnails();
|
||||||
|
|
||||||
|
void on_select_object(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // Namespace Slic3r::GUI
|
} } // Namespace Slic3r::GUI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user