OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
AxisCtrlButton Class Reference

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

Inheritance diagram for AxisCtrlButton:
Collaboration diagram for AxisCtrlButton:

Public Member Functions

 AxisCtrlButton (wxWindow *parent, ScalableBitmap &icon, long style=0)
void SetMinSize (const wxSize &size) override
void SetTextColor (StateColor const &color)
void SetBorderColor (StateColor const &color)
void SetBackgroundColor (StateColor const &color)
void SetInnerBackgroundColor (StateColor const &color)
void SetBitmap (ScalableBitmap &bmp)
void Rescale ()

Private Types

enum  CurrentPos {
  OUTER_UP = 0 , OUTER_LEFT = 1 , OUTER_DOWN = 2 , OUTER_RIGHT = 3 ,
  INNER_UP = 4 , INNER_LEFT = 5 , INNER_DOWN = 6 , INNER_RIGHT = 7 ,
  INNER_HOME = 8 , UNDEFINED = 9
}

Private Member Functions

void updateParams ()
void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void mouseDown (wxMouseEvent &event)
void mouseReleased (wxMouseEvent &event)
void mouseMoving (wxMouseEvent &event)
void sendButtonEvent ()

Private Attributes

wxSize minSize
double stretch
double r_outer
double r_inner
double r_home
double r_blank
double gap
wxPoint center
StateHandler state_handler
StateColor text_color
StateColor border_color
StateColor background_color
StateColor inner_background_color
ScalableBitmap m_icon
bool pressedDown = false
unsigned char last_pos
unsigned char current_pos

Detailed Description

Member Enumeration Documentation

◆ CurrentPos

Enumerator
OUTER_UP 
OUTER_LEFT 
OUTER_DOWN 
OUTER_RIGHT 
INNER_UP 
INNER_LEFT 
INNER_DOWN 
INNER_RIGHT 
INNER_HOME 
UNDEFINED 
40 {
41 OUTER_UP = 0,
42 OUTER_LEFT = 1,
43 OUTER_DOWN = 2,
44 OUTER_RIGHT = 3,
45 INNER_UP = 4,
46 INNER_LEFT = 5,
47 INNER_DOWN = 6,
48 INNER_RIGHT = 7,
49 INNER_HOME = 8,
50 UNDEFINED = 9
51 };
@ UNDEFINED
Definition AxisCtrlButton.hpp:50
@ OUTER_DOWN
Definition AxisCtrlButton.hpp:43
@ INNER_DOWN
Definition AxisCtrlButton.hpp:47
@ OUTER_RIGHT
Definition AxisCtrlButton.hpp:44
@ OUTER_UP
Definition AxisCtrlButton.hpp:41
@ INNER_HOME
Definition AxisCtrlButton.hpp:49
@ OUTER_LEFT
Definition AxisCtrlButton.hpp:42
@ INNER_UP
Definition AxisCtrlButton.hpp:45
@ INNER_LEFT
Definition AxisCtrlButton.hpp:46
@ INNER_RIGHT
Definition AxisCtrlButton.hpp:48

Constructor & Destructor Documentation

◆ AxisCtrlButton()

AxisCtrlButton::AxisCtrlButton ( wxWindow * parent,
ScalableBitmap & icon,
long style = 0 )
44 : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, stlye)
49 , gap(GAP_SIZE)
51 , current_pos(UNDEFINED) // don't change init value
52 , text_color(std::make_pair(0x6B6B6B, (int) StateColor::Disabled), std::make_pair(*wxBLACK, (int) StateColor::Normal))
53 , state_handler(this)
54{
55 m_icon = icon;
56 wxWindow::SetBackgroundColour(parent->GetBackgroundColour());
57
59
65
71
73 state_handler.update_binds();
74}
static const wxColour BUTTON_PRESS_COL
Definition AxisCtrlButton.cpp:27
#define INNER_SIZE
Definition AxisCtrlButton.cpp:38
#define GAP_SIZE
Definition AxisCtrlButton.cpp:41
#define BLANK_SIZE
Definition AxisCtrlButton.cpp:40
static const wxColour BUTTON_IN_BG_COL
Definition AxisCtrlButton.cpp:23
#define HOME_SIZE
Definition AxisCtrlButton.cpp:39
#define OUTER_SIZE
Definition AxisCtrlButton.cpp:37
static const wxColour BUTTON_BG_COL
Definition AxisCtrlButton.cpp:22
static const wxColour bd
Definition AxisCtrlButton.cpp:25
double gap
Definition AxisCtrlButton.hpp:25
StateColor inner_background_color
Definition AxisCtrlButton.hpp:32
double r_blank
Definition AxisCtrlButton.hpp:24
ScalableBitmap m_icon
Definition AxisCtrlButton.hpp:34
double r_inner
Definition AxisCtrlButton.hpp:22
StateColor text_color
Definition AxisCtrlButton.hpp:29
StateColor background_color
Definition AxisCtrlButton.hpp:31
unsigned char last_pos
Definition AxisCtrlButton.hpp:38
unsigned char current_pos
Definition AxisCtrlButton.hpp:39
StateHandler state_handler
Definition AxisCtrlButton.hpp:28
double r_outer
Definition AxisCtrlButton.hpp:21
double r_home
Definition AxisCtrlButton.hpp:23
StateColor border_color
Definition AxisCtrlButton.hpp:30
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Disabled
Definition StateColor.hpp:22
@ Pressed
Definition StateColor.hpp:21
@ Enabled
Definition StateColor.hpp:17

References background_color, bd, BLANK_SIZE, border_color, BUTTON_BG_COL, BUTTON_IN_BG_COL, BUTTON_PRESS_COL, current_pos, StateColor::Disabled, StateColor::Enabled, gap, GAP_SIZE, HOME_SIZE, StateColor::Hovered, inner_background_color, INNER_SIZE, last_pos, m_icon, StateColor::Normal, OUTER_SIZE, StateColor::Pressed, r_blank, r_home, r_inner, r_outer, state_handler, text_color, and UNDEFINED.

Member Function Documentation

◆ mouseDown()

void AxisCtrlButton::mouseDown ( wxMouseEvent & event)
private
301{
302 event.Skip();
303 pressedDown = true;
304 SetFocus();
305 CaptureMouse();
306}
bool pressedDown
Definition AxisCtrlButton.hpp:36

References pressedDown.

◆ mouseMoving()

void AxisCtrlButton::mouseMoving ( wxMouseEvent & event)
private
320{
321 if (pressedDown)
322 return;
323 wxPoint mouse_pos(event.GetX(), event.GetY());
324 wxPoint transformed_mouse_pos = mouse_pos - center;
325 double r_temp = transformed_mouse_pos.x * transformed_mouse_pos.x + transformed_mouse_pos.y * transformed_mouse_pos.y;
326 if (r_temp > r_outer * r_outer) {
328 }
329 else if (r_temp > r_inner * r_inner) {
330 if (transformed_mouse_pos.y < transformed_mouse_pos.x - gap && transformed_mouse_pos.y < -transformed_mouse_pos.x - gap)
331 {
333 }
334 else if (transformed_mouse_pos.y > transformed_mouse_pos.x + gap && transformed_mouse_pos.y < -transformed_mouse_pos.x - gap)
335 {
337 }
338 else if (transformed_mouse_pos.y > transformed_mouse_pos.x + gap && transformed_mouse_pos.y > -transformed_mouse_pos.x + gap)
339 {
341 }
342 else if (transformed_mouse_pos.y < transformed_mouse_pos.x - gap && transformed_mouse_pos.y > -transformed_mouse_pos.x + gap)
343 {
345 }
346 else {
348 }
349 }
350 else if (r_temp > r_blank * r_blank) {
351 if (transformed_mouse_pos.y < transformed_mouse_pos.x - gap && transformed_mouse_pos.y < -transformed_mouse_pos.x - gap)
352 {
354 }
355 else if (transformed_mouse_pos.y > transformed_mouse_pos.x + gap && transformed_mouse_pos.y < -transformed_mouse_pos.x - gap)
356 {
358 }
359 else if (transformed_mouse_pos.y > transformed_mouse_pos.x + gap && transformed_mouse_pos.y > -transformed_mouse_pos.x + gap)
360 {
362 }
363 else if (transformed_mouse_pos.y < transformed_mouse_pos.x - gap && transformed_mouse_pos.y > -transformed_mouse_pos.x + gap)
364 {
366 }
367 else {
369 }
370 } else if (r_temp <= r_home * r_home) {
372 }
373 if (last_pos != current_pos) {
375 Refresh();
376 }
377}
wxPoint center
Definition AxisCtrlButton.hpp:26

References center, current_pos, gap, INNER_DOWN, INNER_HOME, INNER_LEFT, INNER_RIGHT, INNER_UP, last_pos, OUTER_DOWN, OUTER_LEFT, OUTER_RIGHT, OUTER_UP, pressedDown, r_blank, r_home, r_inner, r_outer, and UNDEFINED.

◆ mouseReleased()

void AxisCtrlButton::mouseReleased ( wxMouseEvent & event)
private
309{
310 event.Skip();
311 if (pressedDown) {
312 pressedDown = false;
313 ReleaseMouse();
314 if (wxRect({ 0, 0 }, GetSize()).Contains(event.GetPosition()))
316 }
317}
void sendButtonEvent()
Definition AxisCtrlButton.cpp:379

References pressedDown, and sendButtonEvent().

Here is the call graph for this function:

◆ paintEvent()

void AxisCtrlButton::paintEvent ( wxPaintEvent & evt)
private
150{
151 // depending on your system you may need to look at double-buffered dcs
152 wxPaintDC dc(this);
153 wxGCDC gcdc(dc);
154 render(gcdc);
155}
void render(wxDC &dc)
Definition AxisCtrlButton.cpp:162

References render().

Here is the call graph for this function:

◆ render()

void AxisCtrlButton::render ( wxDC & dc)
private
163{
164 wxGraphicsContext* gc = dc.GetGraphicsContext();
165
166 int states = state_handler.states();
167 wxSize size = GetSize();
168
169 gc->PushState();
170 gc->Translate(center.x, center.y);
171
172 //draw the outer ring
173 wxGraphicsPath outer_path = gc->CreatePath();
174 outer_path.AddCircle(0, 0, r_outer);
175 outer_path.AddCircle(0, 0, r_inner);
178 gc->DrawPath(outer_path);
179
180 //draw the inner ring
181 wxGraphicsPath inner_path = gc->CreatePath();
182 inner_path.AddCircle(0, 0, r_inner);
183 inner_path.AddCircle(0, 0, r_blank);
186 gc->DrawPath(inner_path);
187
188 //draw an arc in corresponding position
190 wxGraphicsPath path = gc->CreatePath();
191 if (current_pos < 4) {
192 path.AddArc(0, 0, r_outer, (5 - 2 * current_pos) * PI / 4, (7 - 2 * current_pos) * PI / 4, true);
193 path.AddArc(0, 0, r_inner, (7 - 2 * current_pos) * PI / 4, (5 - 2 * current_pos) * PI / 4, false);
194 path.CloseSubpath();
195 gc->SetBrush(wxBrush(background_color.colorForStates(states)));
196 }
197 else if (current_pos < 8) {
198 path.AddArc(0, 0, r_inner, (5 - 2 * current_pos) * PI / 4, (7 - 2 * current_pos) * PI / 4, true);
199 path.AddArc(0, 0, r_blank, (7 - 2 * current_pos) * PI / 4, (5 - 2 * current_pos) * PI / 4, false);
200 path.CloseSubpath();
201 gc->SetBrush(wxBrush(inner_background_color.colorForStates(states)));
202 }
203 gc->SetPen(wxPen(border_color.colorForStates(states),2));
204 gc->DrawPath(path);
205 }
206
207 //draw rectangle gap
210 gc->PushState();
211 gc->Rotate(-PI / 4);
212 gc->DrawRectangle(-sqrt2 * size.x / 2, -sqrt2 * gap / 2, sqrt2 * size.x, sqrt2 * gap);
213 gc->Rotate(-PI / 2);
214 gc->DrawRectangle(-sqrt2 * size.x / 2, -sqrt2 * gap / 2, sqrt2 * size.x, sqrt2 * gap);
215 gc->PopState();
216
217 // draw the home circle
218 wxGraphicsPath home_path = gc->CreatePath();
219 home_path.AddCircle(0, 0, r_home);
220 home_path.CloseSubpath();
221 gc->PushState();
222 if (current_pos == 8) {
223 gc->SetPen(wxPen(border_color.colorForStates(states), 2));
224 gc->SetBrush(wxBrush(background_color.colorForStates(states)));
225 } else {
228 }
229 gc->DrawPath(home_path);
230
231 if (m_icon.bmp().IsOk()) {
232 gc->DrawBitmap(m_icon.bmp(), -1 * m_icon.GetBmpWidth() / 2, -1 * m_icon.GetBmpHeight() / 2, m_icon.GetBmpWidth(), m_icon.GetBmpHeight());
233 }
234 gc->PopState();
235
236 //draw linear border of the arc
238 gc->PushState();
239 gc->SetPen(wxPen(border_color.colorForStates(states), 2));
240
241 if (current_pos == 8) {
242 wxGraphicsPath line_path = gc->CreatePath();
243 line_path.AddCircle(0, 0, r_home);
244 gc->StrokePath(line_path);
245 } else {
246 wxGraphicsPath line_path1 = gc->CreatePath();
247 wxGraphicsPath line_path2 = gc->CreatePath();
248 if (current_pos < 4) {
249 line_path1.MoveToPoint(r_inner, -sqrt2 * gap / 2);
250 line_path1.AddLineToPoint(r_outer, -sqrt2 * gap / 2);
251 line_path2.MoveToPoint(-r_inner, -sqrt2 * gap / 2);
252 line_path2.AddLineToPoint(-r_outer, -sqrt2 * gap / 2);
253 } else if (current_pos < 8) {
254 line_path1.MoveToPoint(r_blank, -sqrt2 * gap / 2);
255 line_path1.AddLineToPoint(r_inner, -sqrt2 * gap / 2);
256 line_path2.MoveToPoint(-r_blank, -sqrt2 * gap / 2);
257 line_path2.AddLineToPoint(-r_inner, -sqrt2 * gap / 2);
258 }
259 gc->Rotate(-(1 + 2 * current_pos) * PI / 4);
260 gc->StrokePath(line_path1);
261 gc->Rotate(PI / 2);
262 gc->StrokePath(line_path2);
263 }
264 gc->PopState();
265 }
266
267 //draw text
268 if (!IsEnabled())
269 gc->SetFont(Label::Body_12, text_color.colorForStates(StateColor::Disabled));
270 else
271 gc->SetFont(Label::Head_12, text_color.colorForStates(states));
272 wxDouble w, h;
273 gc->GetTextExtent("Y", &w, &h);
274 gc->DrawText(wxT("Y"), -w / 2, -r_outer + (r_outer - r_inner) / 2 - h / 2);
275 gc->GetTextExtent("-X", &w, &h);
276 gc->DrawText(wxT("-X"), -r_outer + (r_outer - r_inner) / 2 - w / 2, - h / 2);
277 gc->GetTextExtent("-Y", &w, &h);
278 gc->DrawText(wxT("-Y"), -w / 2, r_outer - (r_outer - r_inner) / 2 - h / 2);
279 gc->GetTextExtent("X", &w, &h);
280 gc->DrawText(wxT("X"), r_outer - (r_outer - r_inner) / 2 - w / 2, -h / 2);
281
282 gc->SetFont(Label::Body_12, text_num_color);
283
284 gc->PushState();
285 gc->Rotate(PI / 4);
286 gc->GetTextExtent("+10", &w, &h);
287 gc->DrawText(wxT("+10"), sqrt2 * gap, -r_outer + (r_outer - r_inner) / 2 - h / 2);
288 gc->GetTextExtent("+1", &w, &h);
289 gc->DrawText(wxT("+1"), sqrt2 * gap, -r_inner + (r_inner - r_blank) / 2 - h / 2);
290 gc->GetTextExtent("-1", &w, &h);
291 gc->DrawText(wxT("-1"), sqrt2 * gap, r_inner - (r_inner - r_blank) / 2 - h / 2);
292 gc->GetTextExtent("-10", &w, &h);
293 gc->DrawText(wxT("-10"), sqrt2 * gap, r_outer - (r_outer - r_inner) / 2 - h / 2);
294 gc->PopState();
295
296
297 gc->PopState();
298}
static const wxColour text_num_color
Definition AxisCtrlButton.cpp:26
static const double sqrt2
Definition AxisCtrlButton.cpp:28
StateColor blank_bg(StateColor(std::make_pair(wxColour("#FFFFFF"),(int) StateColor::Normal)))
static wxFont Head_12
Definition Label.hpp:47
static wxFont Body_12
Definition Label.hpp:55
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
wxColour colorForStates(int states)
Definition StateColor.cpp:267
static constexpr double PI
Definition libslic3r.h:81
bool IsEnabled()
Definition dark_mode.cpp:32

References background_color, blank_bg, Label::Body_12, border_color, BUTTON_BG_COL, BUTTON_IN_BG_COL, center, current_pos, StateColor::darkModeColorFor(), StateColor::Disabled, gap, Label::Head_12, inner_background_color, m_icon, StateColor::Normal, PI, r_blank, r_home, r_inner, r_outer, sqrt2, state_handler, text_color, text_num_color, and UNDEFINED.

Referenced by paintEvent().

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

◆ Rescale()

void AxisCtrlButton::Rescale ( )
145 {
146 Refresh();
147}

◆ sendButtonEvent()

void AxisCtrlButton::sendButtonEvent ( )
private
380{
381 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
382 event.SetEventObject(this);
383 event.SetInt(current_pos);
384 GetEventHandler()->ProcessEvent(event);
385}

References current_pos.

Referenced by mouseReleased().

Here is the caller graph for this function:

◆ SetBackgroundColor()

void AxisCtrlButton::SetBackgroundColor ( StateColor const & color)
125{
126 background_color = color;
127 state_handler.update_binds();
128 Refresh();
129}

References background_color, and state_handler.

◆ SetBitmap()

void AxisCtrlButton::SetBitmap ( ScalableBitmap & bmp)
139{
140 if (bmp.bmp().IsOk()) {
141 m_icon = bmp;
142 }
143}
const wxBitmap & bmp() const
Definition wxExtensions.hpp:189

References ScalableBitmap::bmp(), and m_icon.

Here is the call graph for this function:

◆ SetBorderColor()

void AxisCtrlButton::SetBorderColor ( StateColor const & color)
118{
119 border_color = color;
120 state_handler.update_binds();
121 Refresh();
122}

References border_color, and state_handler.

◆ SetInnerBackgroundColor()

void AxisCtrlButton::SetInnerBackgroundColor ( StateColor const & color)
132{
134 state_handler.update_binds();
135 Refresh();
136}

References inner_background_color, and state_handler.

◆ SetMinSize()

void AxisCtrlButton::SetMinSize ( const wxSize & size)
override
85{
86 wxSize cur_size = GetSize();
87 if (size.GetWidth() > 0 && size.GetHeight() > 0) {
88 stretch = std::min((double)size.GetWidth() / cur_size.x,(double)size.GetHeight() / cur_size.y);
89 minSize = size;
91 }
92 else if (size.GetWidth() > 0) {
93 stretch = (double)size.GetWidth() / cur_size.x;
94 minSize.x = size.x;
96 }
97 else if (size.GetHeight() > 0) {
98 stretch = (double)size.GetHeight() / cur_size.y;
99 minSize.y = size.y;
100 updateParams();
101 }
102 else {
103 stretch = 1.0;
104 minSize = wxSize(228, 228);
105 }
106 wxWindow::SetMinSize(minSize);
107 center = wxPoint(minSize.x / 2, minSize.y / 2);
108}
double stretch
Definition AxisCtrlButton.hpp:20
void updateParams()
Definition AxisCtrlButton.cpp:76
wxSize minSize
Definition AxisCtrlButton.hpp:19

References center, minSize, stretch, and updateParams().

Here is the call graph for this function:

◆ SetTextColor()

void AxisCtrlButton::SetTextColor ( StateColor const & color)
111{
112 text_color = color;
113 state_handler.update_binds();
114 Refresh();
115}

References state_handler, and text_color.

◆ updateParams()

void AxisCtrlButton::updateParams ( )
private

References BLANK_SIZE, gap, GAP_SIZE, HOME_SIZE, INNER_SIZE, OUTER_SIZE, r_blank, r_home, r_inner, and r_outer.

Referenced by SetMinSize().

Here is the caller graph for this function:

Member Data Documentation

◆ background_color

StateColor AxisCtrlButton::background_color
private

◆ border_color

StateColor AxisCtrlButton::border_color
private

◆ center

wxPoint AxisCtrlButton::center
private

Referenced by mouseMoving(), render(), and SetMinSize().

◆ current_pos

unsigned char AxisCtrlButton::current_pos
private

◆ gap

double AxisCtrlButton::gap
private

◆ inner_background_color

StateColor AxisCtrlButton::inner_background_color
private

◆ last_pos

unsigned char AxisCtrlButton::last_pos
private

Referenced by AxisCtrlButton(), and mouseMoving().

◆ m_icon

ScalableBitmap AxisCtrlButton::m_icon
private

Referenced by AxisCtrlButton(), render(), and SetBitmap().

◆ minSize

wxSize AxisCtrlButton::minSize
private

Referenced by SetMinSize().

◆ pressedDown

bool AxisCtrlButton::pressedDown = false
private

◆ r_blank

double AxisCtrlButton::r_blank
private

◆ r_home

double AxisCtrlButton::r_home
private

◆ r_inner

double AxisCtrlButton::r_inner
private

◆ r_outer

double AxisCtrlButton::r_outer
private

◆ state_handler

◆ stretch

double AxisCtrlButton::stretch
private

Referenced by SetMinSize().

◆ text_color

StateColor AxisCtrlButton::text_color
private

The documentation for this class was generated from the following files: