Skip to content

Ramming dialog improvements & add step control for SpinInput class #9651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions src/slic3r/GUI/RammingChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,34 @@ wxDEFINE_EVENT(EVT_WIPE_TOWER_CHART_CHANGED, wxCommandEvent);
void Chart::draw() {
wxAutoBufferedPaintDC dc(this); // unbuffered DC caused flickering on win

// scaling button and tick line from text size gives better result compared to dc.GetContentScale
int text_width, text_height;
dc.GetTextExtent("m",&text_width,&text_height);
side = text_width;
int tick_w = text_width / 2;

dc.SetBrush(GetBackgroundColour());
dc.SetPen(GetBackgroundColour());
dc.DrawRectangle(GetClientRect()); // otherwise the background would end up black on windows

#ifdef _WIN32
dc.SetPen(wxPen(GetForegroundColour()));
dc.SetBrush(wxBrush(Slic3r::GUI::wxGetApp().get_highlight_default_clr()));
#else
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
#endif
dc.SetPen( wxPen(StateColor::darkModeColorFor(wxColour("#DBDBDB")), 1)); // input box border color
dc.SetBrush(wxBrush(StateColor::darkModeColorFor(wxColour("#F1F1F1")))); // sidebar titlebar bg color
dc.DrawRectangle(m_rect);

if (visible_area.m_width < 0.499) {
dc.SetTextForeground(StateColor::darkModeColorFor(wxColour("#FF6F00"))); // Use orange color for warning
dc.DrawText(_(L("NO RAMMING AT ALL")),wxPoint(m_rect.GetLeft()+m_rect.GetWidth()/2-legend_side,m_rect.GetBottom()-m_rect.GetHeight()/2));
return;
}


if (!m_line_to_draw.empty()) {
for (unsigned int i=0;i<m_line_to_draw.size()-2;++i) {
int color = 510*((m_rect.GetBottom()-(m_line_to_draw)[i])/double(m_rect.GetHeight()));
dc.SetPen( wxPen( wxColor(std::min(255,color),255-std::max(color-255,0),0), 1 ) );
int color = 444*((m_rect.GetBottom()-(m_line_to_draw)[i])/double(m_rect.GetHeight()));
dc.SetPen( wxPen( wxColor(std::min(222,color), 222-std::max(color-222,0), 60), 1) ); // adding blue color sligtly gives a bit more modern look instead using raw red & green
dc.DrawLine(m_rect.GetLeft()+1+i,(m_line_to_draw)[i],m_rect.GetLeft()+1+i,m_rect.GetBottom());
}
#ifdef _WIN32
dc.SetPen(wxPen(GetForegroundColour()));
#else
dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
#endif
dc.SetPen(wxPen(StateColor::darkModeColorFor(wxColour("#363636")), 1));
for (unsigned int i=0;i<m_line_to_draw.size()-2;++i) {
if (splines)
dc.DrawLine(m_rect.GetLeft()+i,(m_line_to_draw)[i],m_rect.GetLeft()+i+1,(m_line_to_draw)[i+1]);
Expand All @@ -55,25 +53,25 @@ void Chart::draw() {
}

// draw draggable buttons
dc.SetBrush(*wxBLUE_BRUSH);
#ifdef _WIN32
dc.SetPen(wxPen(GetForegroundColour()));
#else
dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
#endif
dc.SetBrush(StateColor::darkModeColorFor(wxColour("#009688"))); // orca color for draggable circles
dc.SetPen(wxPen(StateColor::darkModeColorFor(wxColour("#363636")), 1));
for (auto& button : m_buttons)
//dc.DrawRectangle(math_to_screen(button.get_pos())-wxPoint(side/2.,side/2.), wxSize(side,side));
dc.DrawCircle(math_to_screen(button.get_pos()),side/2.);
//dc.DrawRectangle(math_to_screen(button.get_pos()-wxPoint2DDouble(0.125,0))-wxPoint(0,5),wxSize(50,10));

dc.SetTextForeground(StateColor::darkModeColorFor(wxColour("#363636"))); // Label color

// draw x-axis:
float last_mark = -10000;
for (float math_x=int(visible_area.m_x*10)/10 ; math_x < (visible_area.m_x+visible_area.m_width) ; math_x+=0.1f) {
int x = math_to_screen(wxPoint2DDouble(math_x,visible_area.m_y)).x;
int y = m_rect.GetBottom();
if (x-last_mark < legend_side) continue;
dc.DrawLine(x,y+3,x,y-3);
dc.DrawText(wxString().Format(wxT("%.1f"), math_x),wxPoint(x-scale_unit,y+0.5*scale_unit));
dc.DrawLine(x,y+tick_w+1,x,y-tick_w); // +1 for border; make sure drawn on both size
auto label = math_x == 0 ? "0" : wxString().Format(wxT("%.1f") , math_x); // prefer "0" to match text with Y "0"
dc.GetTextExtent(label,&text_width,&text_height);// center text with lines
dc.DrawText(label ,wxPoint(x - text_width * .5, y + .8 * scale_unit));
last_mark = x;
}

Expand All @@ -83,17 +81,17 @@ void Chart::draw() {
int y = math_to_screen(wxPoint2DDouble(visible_area.m_x,math_y)).y;
int x = m_rect.GetLeft();
if (last_mark-y < legend_side) continue;
dc.DrawLine(x-3,y,x+3,y);
dc.DrawText(wxString()<<math_y,wxPoint(x-2*scale_unit,y-0.5*scale_unit));
dc.DrawLine(x-tick_w,y,x+tick_w+1,y); // +1 for border; make sure drawn on both size
auto label = wxString()<<math_y;
dc.GetTextExtent(label,&text_width,&text_height);// center text with lines & make it right aligned
dc.DrawText(label ,wxPoint(x - scale_unit - text_width, y - .5 * text_height + 1));
last_mark = y;
}

// axis labels:
wxString label = _(L("Time")) + " ("+_(L("s"))+")";
int text_width = 0;
int text_height = 0;
dc.GetTextExtent(label,&text_width,&text_height);
dc.DrawText(label,wxPoint(0.5*(m_rect.GetRight()+m_rect.GetLeft())-text_width/2.f, m_rect.GetBottom()+0.5*legend_side));
dc.DrawText(label,wxPoint(0.5*(m_rect.GetRight()+m_rect.GetLeft())-text_width/2.f, m_rect.GetBottom()+0.6*legend_side));
label = _(L("Volumetric speed")) + " (" + _(L("mm³/s")) + ")";
dc.GetTextExtent(label,&text_width,&text_height);
dc.DrawRotatedText(label,wxPoint(0,0.5*(m_rect.GetBottom()+m_rect.GetTop())+text_width/2.f),90);
Expand Down Expand Up @@ -124,9 +122,13 @@ void Chart::mouse_clicked(wxMouseEvent& event) {


void Chart::mouse_moved(wxMouseEvent& event) {
if (!event.Dragging() || !m_dragged) return;
wxPoint pos = event.GetPosition();
wxRect rect = m_rect;
if (!event.Dragging() || !m_dragged){
// change cursor while button hovered && drag
SetCursor((which_button_is_clicked(pos) != -1) ? wxCursor(wxCURSOR_SIZENS) : wxNullCursor);
return;
}
rect.Deflate(side/2.);
if (!(rect.Contains(pos))) { // the mouse left chart area
mouse_left_window(event);
Expand Down
7 changes: 4 additions & 3 deletions src/slic3r/GUI/RammingChart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Chart : public wxWindow {
wxWindow(parent,wxID_ANY,rect.GetTopLeft(),rect.GetSize()),
scale_unit(scale_unit), legend_side(5*scale_unit)
{
SetBackgroundColour(*wxWHITE);
SetBackgroundStyle(wxBG_STYLE_PAINT);
m_rect = wxRect(wxPoint(legend_side,0),rect.GetSize()-wxSize(legend_side,legend_side));
visible_area = wxRect2DDouble(0.0, 0.0, sampling*ramming_speed_size, 20.);
Expand Down Expand Up @@ -46,8 +47,8 @@ class Chart : public wxWindow {
void mouse_right_button_clicked(wxMouseEvent& event);
void mouse_moved(wxMouseEvent& event);
void mouse_double_clicked(wxMouseEvent& event);
void mouse_left_window(wxMouseEvent&) { m_dragged = nullptr; }
void mouse_released(wxMouseEvent&) { m_dragged = nullptr; }
void mouse_left_window(wxMouseEvent&) { m_dragged = nullptr; SetCursor(wxNullCursor);}
void mouse_released(wxMouseEvent&) { m_dragged = nullptr; SetCursor(wxNullCursor);}
void paint_event(wxPaintEvent&) { draw(); }
DECLARE_EVENT_TABLE()

Expand All @@ -58,7 +59,7 @@ class Chart : public wxWindow {
static const bool fixed_x = true;
static const bool splines = true;
static const bool manual_points_manipulation = false;
static const int side = 10; // side of draggable button
int side = 10; // side of draggable button

const int scale_unit;
int legend_side;
Expand Down
23 changes: 12 additions & 11 deletions src/slic3r/GUI/Widgets/SpinInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ SpinInput::SpinInput(wxWindow *parent,
const wxPoint &pos,
const wxSize & size,
long style,
int min, int max, int initial)
int min, int max, int initial, const int& step)
: SpinInput()
{
Create(parent, text, label, pos, size, style, min, max, initial);
Create(parent, text, label, pos, size, style, min, max, initial, step);
}

void SpinInput::Create(wxWindow *parent,
Expand All @@ -50,7 +50,7 @@ void SpinInput::Create(wxWindow *parent,
const wxPoint &pos,
const wxSize & size,
long style,
int min, int max, int initial)
int min, int max, int initial, int step)
{
StaticBox::Create(parent, wxID_ANY, pos, size);
SetFont(Label::Body_12);
Expand All @@ -76,6 +76,7 @@ void SpinInput::Create(wxWindow *parent,
if (text.ToLong(&initialFromText)) initial = initialFromText;
SetRange(min, max);
SetValue(initial);
SetStep(step);
messureSize();
}

Expand Down Expand Up @@ -229,7 +230,7 @@ Button *SpinInput::createButton(bool inc)
btn->DisableFocusFromKeyboard();
btn->Bind(wxEVT_LEFT_DOWN, [=](auto &e) {
delta = inc ? 1 : -1;
SetValue(val + delta);
SetValue(val + delta * step);
text_ctrl->SetFocus();
if (!btn->HasCapture())
btn->CaptureMouse();
Expand All @@ -241,7 +242,7 @@ Button *SpinInput::createButton(bool inc)
delta = inc ? 1 : -1;
if (!btn->HasCapture())
btn->CaptureMouse();
SetValue(val + delta);
SetValue(val + delta * step);
sendSpinEvent();
});
btn->Bind(wxEVT_LEFT_UP, [=](auto &e) {
Expand All @@ -259,7 +260,7 @@ void SpinInput::onTimer(wxTimerEvent &evnet) {
delta /= 2;
return;
}
SetValue(val + delta);
SetValue(val + delta * step);
sendSpinEvent();
}

Expand Down Expand Up @@ -293,7 +294,7 @@ void SpinInput::onTextEnter(wxCommandEvent &event)
void SpinInput::mouseWheelMoved(wxMouseEvent &event)
{
auto delta = event.GetWheelRotation() < 0 ? 1 : -1;
SetValue(val + delta);
SetValue(val + delta * step);
sendSpinEvent();
text_ctrl->SetFocus();
}
Expand All @@ -305,10 +306,10 @@ void SpinInput::keyPressed(wxKeyEvent &event)
case WXK_DOWN:
long value;
if (!text_ctrl->GetValue().ToLong(&value)) { value = val; }
if (event.GetKeyCode() == WXK_DOWN && value > min) {
--value;
} else if (event.GetKeyCode() == WXK_UP && value + 1 < max) {
++value;
if (event.GetKeyCode() == WXK_DOWN && value - step >= min) {
value = value - step;
} else if (event.GetKeyCode() == WXK_UP && value + step <= max) {
value = value + step;
}
if (value != val) {
SetValue(value);
Expand Down
10 changes: 8 additions & 2 deletions src/slic3r/GUI/Widgets/SpinInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SpinInput : public wxNavigationEnabled<StaticBox>
int min;
int max;
int delta;
int step;

static const int SpinInputWidth = 200;
static const int SpinInputHeight = 50;
Expand All @@ -36,7 +37,7 @@ class SpinInput : public wxNavigationEnabled<StaticBox>
const wxPoint &pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0,
int min = 0, int max = 100, int initial = 0);
int min = 0, int max = 100, int initial = 0, const int& step = 1);

void Create(wxWindow * parent,
wxString text,
Expand All @@ -46,7 +47,8 @@ class SpinInput : public wxNavigationEnabled<StaticBox>
long style = 0,
int min = 0,
int max = 100,
int initial = 0);
int initial = 0,
int step = 1);

void SetCornerRadius(double radius);

Expand All @@ -70,6 +72,10 @@ class SpinInput : public wxNavigationEnabled<StaticBox>

int GetValue () const;

void SetStep(int value) { step = value; };

int GetStep() { return step; };

void SetRange(int min, int max);

protected:
Expand Down
Loading