OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::DragCanvas Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DragCanvas.hpp>

Inheritance diagram for Slic3r::GUI::DragCanvas:
Collaboration diagram for Slic3r::GUI::DragCanvas:

Public Member Functions

 DragCanvas (wxWindow *parent, const std::vector< std::string > &colors, const std::vector< int > &order)
 ~DragCanvas ()
void set_shape_list (const std::vector< std::string > &colors, const std::vector< int > &order)
std::vector< int > get_shape_list_order ()
std::vector< DragShape * > get_ordered_shape_list ()

Protected Member Functions

void on_paint (wxPaintEvent &event)
void on_erase (wxEraseEvent &event)
void on_mouse (wxMouseEvent &event)
DragShape * find_shape (const wxPoint &pt) const

Private Attributes

std::vector< DragShape * > m_dragshape_list
DragMode m_drag_mode
DragShape * m_dragging_shape { nullptr }
DragShape * m_slot_shape { nullptr }
wxDragImage * m_drag_image { nullptr }
wxPoint m_drag_start_pos
wxBitmap m_arrow_bmp
wxPoint m_max_shape_pos
wxColour m_background_color
wxColour m_border_color

Detailed Description

Constructor & Destructor Documentation

◆ DragCanvas()

Slic3r::GUI::DragCanvas::DragCanvas ( wxWindow * parent,
const std::vector< std::string > & colors,
const std::vector< int > & order )
26 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
28 , m_max_shape_pos(wxPoint(0, 0))
29{
30 SetBackgroundColour(*wxWHITE);
31
34
35 m_arrow_bmp = create_scaled_bitmap("plate_settings_arrow", this, 16);
36
37 set_shape_list(colors, order);
38
39 Bind(wxEVT_PAINT, &DragCanvas::on_paint, this);
40 Bind(wxEVT_ERASE_BACKGROUND, &DragCanvas::on_erase, this);
41 Bind(wxEVT_LEFT_DOWN, &DragCanvas::on_mouse, this);
42 Bind(wxEVT_LEFT_UP, &DragCanvas::on_mouse, this);
43 Bind(wxEVT_MOTION, &DragCanvas::on_mouse, this);
44 Bind(wxEVT_ENTER_WINDOW, &DragCanvas::on_mouse, this);
45 Bind(wxEVT_LEAVE_WINDOW, &DragCanvas::on_mouse, this);
46}
void on_paint(wxPaintEvent &event)
Definition DragCanvas.cpp:125
DragMode m_drag_mode
Definition DragCanvas.hpp:67
void on_erase(wxEraseEvent &event)
Definition DragCanvas.cpp:142
wxPoint m_max_shape_pos
Definition DragCanvas.hpp:73
void on_mouse(wxMouseEvent &event)
Definition DragCanvas.cpp:161
wxColour m_border_color
Definition DragCanvas.hpp:75
wxBitmap m_arrow_bmp
Definition DragCanvas.hpp:72
wxColour m_background_color
Definition DragCanvas.hpp:74
void set_shape_list(const std::vector< std::string > &colors, const std::vector< int > &order)
Definition DragCanvas.cpp:59
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
@ NONE
Definition DragCanvas.hpp:47
wxBitmap create_scaled_bitmap(const std::string &bmp_name_in, wxWindow *win, const int px_cnt, const bool grayscale, const std::string &new_color, const bool menu_bitmap, const bool resize, const bool bitmap2, const std::vector< std::string > &array_new_color)
Definition wxExtensions.cpp:448

References create_scaled_bitmap(), StateColor::darkModeColorFor(), m_arrow_bmp, m_background_color, m_border_color, m_drag_mode, m_max_shape_pos, Slic3r::GUI::NONE, on_erase(), on_mouse(), on_paint(), and set_shape_list().

Here is the call graph for this function:

◆ ~DragCanvas()

Slic3r::GUI::DragCanvas::~DragCanvas ( )
49{
50 for (int i = 0; i < m_dragshape_list.size(); i++) {
51 delete m_dragshape_list[i];
52 }
53 m_dragshape_list.clear();
54
55 if (m_drag_image)
56 delete m_drag_image;
57}
wxDragImage * m_drag_image
Definition DragCanvas.hpp:70
std::vector< DragShape * > m_dragshape_list
Definition DragCanvas.hpp:66

References m_drag_image, and m_dragshape_list.

Member Function Documentation

◆ find_shape()

DragShape * Slic3r::GUI::DragCanvas::find_shape ( const wxPoint & pt) const
protected
232{
233 for (auto& shape : m_dragshape_list) {
234 if (shape->hit_test(pt))
235 return shape;
236 }
237 return nullptr;
238}

References find_shape(), and m_dragshape_list.

Referenced by find_shape(), and on_mouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ordered_shape_list()

std::vector< DragShape * > Slic3r::GUI::DragCanvas::get_ordered_shape_list ( )
110{
111 std::vector<DragShape*> ordered_list = m_dragshape_list;
112 std::sort(ordered_list.begin(), ordered_list.end(), [](const DragShape* l, const DragShape* r) {
113 if (l->GetPosition().y < r->GetPosition().y)
114 return true;
115 else if (l->GetPosition().y == r->GetPosition().y) {
116 return l->GetPosition().x < r->GetPosition().x;
117 }
118 else {
119 return false;
120 }
121 });
122 return ordered_list;
123}

References m_dragshape_list.

Referenced by get_shape_list_order().

Here is the caller graph for this function:

◆ get_shape_list_order()

std::vector< int > Slic3r::GUI::DragCanvas::get_shape_list_order ( )
99{
100 std::vector<int> res;
101 std::vector<DragShape*> ordered_list = get_ordered_shape_list();
102 res.reserve(ordered_list.size());
103 for (auto& item : ordered_list) {
104 res.push_back(item->get_index());
105 }
106 return res;
107}
std::vector< DragShape * > get_ordered_shape_list()
Definition DragCanvas.cpp:109

References get_ordered_shape_list().

Here is the call graph for this function:

◆ on_erase()

void Slic3r::GUI::DragCanvas::on_erase ( wxEraseEvent & event)
protected
143{
144 wxSize size = GetSize();
145 if (event.GetDC())
146 {
147 auto& dc = *(event.GetDC());
148 dc.SetPen( m_border_color); // ORCA
149 dc.SetBrush(m_background_color); // ORCA
150 dc.DrawRectangle({ 0,0 }, size);
151 }
152 else
153 {
154 wxClientDC dc(this);
155 dc.SetPen( m_border_color); // ORCA
156 dc.SetBrush(m_background_color); // ORCA
157 dc.DrawRectangle({ 0,0 }, size);
158 }
159}

References m_background_color, m_border_color, and on_erase().

Referenced by DragCanvas(), and on_erase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_mouse()

void Slic3r::GUI::DragCanvas::on_mouse ( wxMouseEvent & event)
protected
162{
163 if (event.LeftDown())
164 {
165 DragShape* shape = find_shape(event.GetPosition());
166 if (shape)
167 {
169 m_drag_start_pos = event.GetPosition();
170 m_dragging_shape = shape;
171
172 if (m_drag_image) {
173 delete m_drag_image;
174 m_drag_image = nullptr;
175 }
176 m_drag_image = new wxDragImage(m_dragging_shape->GetBitmap());
177
178 wxPoint offset = m_drag_start_pos - m_dragging_shape->GetPosition();
179 bool success = m_drag_image->BeginDrag(offset, this);
180 if (!success)
181 {
182 delete m_drag_image;
183 m_drag_image = nullptr;
185 }
186 }
187 }
188 else if (event.Dragging() && m_drag_mode == DragMode::DRAGGING)
189 {
190 DragShape* shape = find_shape(event.GetPosition());
191
192 if (shape) {
193 if (shape != m_dragging_shape) {
194 m_slot_shape = shape;
195 Refresh();
196 Update();
197 }
198 }
199 else {
200 if (m_slot_shape) {
201 m_slot_shape = nullptr;
202 Refresh();
203 Update();
204 }
205 }
206 m_drag_image->Move(event.GetPosition());
207 m_drag_image->Show();
208 }
209 else if (event.LeftUp() && m_drag_mode != DragMode::NONE)
210 {
212
213 if (m_drag_image) {
214 m_drag_image->Hide();
215 m_drag_image->EndDrag();
216
217 // swap position
219 auto highlighted_pos = m_slot_shape->GetPosition();
220 m_slot_shape->SetPosition(m_dragging_shape->GetPosition());
221 m_dragging_shape->SetPosition(highlighted_pos);
222 m_slot_shape = nullptr;
223 m_dragging_shape = nullptr;
224 }
225 }
226 Refresh();
227 Update();
228 }
229}
wxPoint m_drag_start_pos
Definition DragCanvas.hpp:71
DragShape * m_slot_shape
Definition DragCanvas.hpp:69
DragShape * m_dragging_shape
Definition DragCanvas.hpp:68
DragShape * find_shape(const wxPoint &pt) const
Definition DragCanvas.cpp:231
@ DRAGGING
Definition DragCanvas.hpp:48
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582

References Slic3r::GUI::DRAGGING, find_shape(), m_drag_image, m_drag_mode, m_drag_start_pos, m_dragging_shape, m_slot_shape, Slic3r::GUI::NONE, Slic3r::offset(), on_mouse(), and Slic3r::GUI::wxMouseEvent.

Referenced by DragCanvas(), and on_mouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_paint()

void Slic3r::GUI::DragCanvas::on_paint ( wxPaintEvent & event)
protected
126{
127 wxPaintDC dc(this);
128
129 for (int i = 0; i < m_dragshape_list.size(); i++) {
131
132 auto arrow_pos = m_dragshape_list[i]->GetPosition() - wxSize(SHAPE_GAP - SHAPE_SIZE, 0);
133 if (arrow_pos.x < 0) {
134 arrow_pos.x = m_max_shape_pos.x;
135 arrow_pos.y -= LINE_HEIGHT;
136 }
137 arrow_pos += wxSize((SHAPE_GAP - SHAPE_SIZE - m_arrow_bmp.GetWidth() / dc.GetContentScaleFactor()) / 2, (SHAPE_SIZE - m_arrow_bmp.GetHeight() / dc.GetContentScaleFactor()) / 2);
138 dc.DrawBitmap(m_arrow_bmp, arrow_pos);
139 }
140}
#define SHAPE_SIZE
Definition DragCanvas.cpp:20
#define LINE_HEIGHT
Definition DragCanvas.cpp:22
#define SHAPE_GAP
Definition DragCanvas.cpp:21

References LINE_HEIGHT, m_arrow_bmp, m_dragshape_list, m_max_shape_pos, m_slot_shape, on_paint(), SHAPE_GAP, and SHAPE_SIZE.

Referenced by DragCanvas(), and on_paint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_shape_list()

void Slic3r::GUI::DragCanvas::set_shape_list ( const std::vector< std::string > & colors,
const std::vector< int > & order )
60{
61 m_dragshape_list.clear();
62
63 for (int i = 0; i < order.size(); i++) {
64 wxBitmap* bmp = get_extruder_color_icon(colors[order[i] - 1], std::to_string(order[i]), SHAPE_SIZE, SHAPE_SIZE);
65 DragShape* shape = new DragShape(*bmp, order[i]);
66 m_dragshape_list.push_back(shape);
67 }
68
69 // wrapping lines
70 for (int i = 0; i < order.size(); i++) {
71 int shape_pos_x = FromDIP(10) + i * SHAPE_GAP;
72 int shape_pos_y = FromDIP(5);
73 while (shape_pos_x + SHAPE_SIZE > CANVAS_WIDTH) {
74 shape_pos_x -= CANVAS_WIDTH;
75 shape_pos_y += LINE_HEIGHT;
76
77 int row = shape_pos_y / LINE_HEIGHT + 1;
78 if (row > 1) {
79 if (row % 2 == 0) {
80 shape_pos_x += (SHAPE_GAP - SHAPE_SIZE);
81 }
82 else {
83 shape_pos_x -= (SHAPE_GAP - SHAPE_SIZE);
84 shape_pos_x += SHAPE_GAP;
85 }
86 }
87 }
88
89 m_max_shape_pos.x = std::max(m_max_shape_pos.x, shape_pos_x);
90 m_max_shape_pos.y = std::max(m_max_shape_pos.y, shape_pos_y);
91 m_dragshape_list[i]->SetPosition(wxPoint(shape_pos_x, shape_pos_y));
92 }
93
94 int rows = m_max_shape_pos.y / LINE_HEIGHT + 1;
95 SetMinSize(wxSize(CANVAS_WIDTH, LINE_HEIGHT * rows + FromDIP(5)));
96}
#define CANVAS_WIDTH
Definition DragCanvas.cpp:19
size_t rows(const T &raster)
Definition MarchingSquares.hpp:171
wxBitmap * get_extruder_color_icon(std::vector< std::string > colors, bool is_gradient, std::string label, int icon_width, int icon_height, const std::vector< wxColour > *ramp)
Definition wxExtensions.cpp:633

References CANVAS_WIDTH, get_extruder_color_icon(), LINE_HEIGHT, m_dragshape_list, m_max_shape_pos, SHAPE_GAP, and SHAPE_SIZE.

Referenced by DragCanvas().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_arrow_bmp

wxBitmap Slic3r::GUI::DragCanvas::m_arrow_bmp
private

Referenced by DragCanvas(), and on_paint().

◆ m_background_color

wxColour Slic3r::GUI::DragCanvas::m_background_color
private

Referenced by DragCanvas(), and on_erase().

◆ m_border_color

wxColour Slic3r::GUI::DragCanvas::m_border_color
private

Referenced by DragCanvas(), and on_erase().

◆ m_drag_image

wxDragImage* Slic3r::GUI::DragCanvas::m_drag_image { nullptr }
private
70{ nullptr };

Referenced by ~DragCanvas(), and on_mouse().

◆ m_drag_mode

DragMode Slic3r::GUI::DragCanvas::m_drag_mode
private

Referenced by DragCanvas(), and on_mouse().

◆ m_drag_start_pos

wxPoint Slic3r::GUI::DragCanvas::m_drag_start_pos
private

Referenced by on_mouse().

◆ m_dragging_shape

DragShape* Slic3r::GUI::DragCanvas::m_dragging_shape { nullptr }
private
68{ nullptr };

Referenced by on_mouse().

◆ m_dragshape_list

std::vector<DragShape*> Slic3r::GUI::DragCanvas::m_dragshape_list
private

◆ m_max_shape_pos

wxPoint Slic3r::GUI::DragCanvas::m_max_shape_pos
private

◆ m_slot_shape

DragShape* Slic3r::GUI::DragCanvas::m_slot_shape { nullptr }
private
69{ nullptr }; // The shape that's being highlighted

Referenced by on_mouse(), and on_paint().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DragCanvas.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DragCanvas.cpp