FIX: use StaticBox for background

Change-Id: I2bba259c53eaf987662a97dd93eac4fb8f73d47b
This commit is contained in:
chunmao.guo 2022-08-02 16:32:09 +08:00 committed by Lane.Wei
parent c4ec127b3a
commit a35ecc4fba
8 changed files with 54 additions and 154 deletions

View file

@ -744,6 +744,7 @@ wxBoxSizer *StatusBasePanel::create_bed_control(wxWindow *parent)
bSizer_z_ctrl->AddStretchSpacer(); bSizer_z_ctrl->AddStretchSpacer();
m_bpButton_z_10 = new Button(panel, wxString("10"), "monitor_bed_up", 0, FromDIP(15)); m_bpButton_z_10 = new Button(panel, wxString("10"), "monitor_bed_up", 0, FromDIP(15));
m_bpButton_z_10->SetFont(::Label::Body_13); m_bpButton_z_10->SetFont(::Label::Body_13);
m_bpButton_z_10->SetBorderWidth(2);
m_bpButton_z_10->SetBackgroundColor(z_10_ctrl_bg); m_bpButton_z_10->SetBackgroundColor(z_10_ctrl_bg);
m_bpButton_z_10->SetBorderColor(z_10_ctrl_bd); m_bpButton_z_10->SetBorderColor(z_10_ctrl_bd);
m_bpButton_z_10->SetTextColor(StateColor(std::make_pair(DISCONNECT_TEXT_COL, (int) StateColor::Disabled), std::make_pair(NORMAL_TEXT_COL, (int) StateColor::Normal))); m_bpButton_z_10->SetTextColor(StateColor(std::make_pair(DISCONNECT_TEXT_COL, (int) StateColor::Disabled), std::make_pair(NORMAL_TEXT_COL, (int) StateColor::Normal)));
@ -754,6 +755,7 @@ wxBoxSizer *StatusBasePanel::create_bed_control(wxWindow *parent)
m_bpButton_z_1 = new Button(panel, wxString(" 1"), "monitor_bed_up", 0, FromDIP(15)); m_bpButton_z_1 = new Button(panel, wxString(" 1"), "monitor_bed_up", 0, FromDIP(15));
m_bpButton_z_1->SetFont(::Label::Body_13); m_bpButton_z_1->SetFont(::Label::Body_13);
m_bpButton_z_1->SetBorderWidth(2);
m_bpButton_z_1->SetBackgroundColor(z_1_ctrl_bg); m_bpButton_z_1->SetBackgroundColor(z_1_ctrl_bg);
m_bpButton_z_1->SetBorderColor(z_1_ctrl_bd); m_bpButton_z_1->SetBorderColor(z_1_ctrl_bd);
m_bpButton_z_1->SetMinSize(Z_BUTTON_SIZE); m_bpButton_z_1->SetMinSize(Z_BUTTON_SIZE);
@ -765,6 +767,7 @@ wxBoxSizer *StatusBasePanel::create_bed_control(wxWindow *parent)
m_bpButton_z_down_1 = new Button(panel, wxString(" 1"), "monitor_bed_down", 0, FromDIP(15)); m_bpButton_z_down_1 = new Button(panel, wxString(" 1"), "monitor_bed_down", 0, FromDIP(15));
m_bpButton_z_down_1->SetFont(::Label::Body_13); m_bpButton_z_down_1->SetFont(::Label::Body_13);
m_bpButton_z_down_1->SetBorderWidth(2);
m_bpButton_z_down_1->SetBackgroundColor(z_1_ctrl_bg); m_bpButton_z_down_1->SetBackgroundColor(z_1_ctrl_bg);
m_bpButton_z_down_1->SetBorderColor(z_1_ctrl_bd); m_bpButton_z_down_1->SetBorderColor(z_1_ctrl_bd);
m_bpButton_z_down_1->SetMinSize(Z_BUTTON_SIZE); m_bpButton_z_down_1->SetMinSize(Z_BUTTON_SIZE);
@ -774,6 +777,7 @@ wxBoxSizer *StatusBasePanel::create_bed_control(wxWindow *parent)
m_bpButton_z_down_10 = new Button(panel, wxString("10"), "monitor_bed_down", 0, FromDIP(15)); m_bpButton_z_down_10 = new Button(panel, wxString("10"), "monitor_bed_down", 0, FromDIP(15));
m_bpButton_z_down_10->SetFont(::Label::Body_13); m_bpButton_z_down_10->SetFont(::Label::Body_13);
m_bpButton_z_down_10->SetBorderWidth(2);
m_bpButton_z_down_10->SetBackgroundColor(z_10_ctrl_bg); m_bpButton_z_down_10->SetBackgroundColor(z_10_ctrl_bg);
m_bpButton_z_down_10->SetBorderColor(z_10_ctrl_bd); m_bpButton_z_down_10->SetBorderColor(z_10_ctrl_bd);
m_bpButton_z_down_10->SetMinSize(Z_BUTTON_SIZE); m_bpButton_z_down_10->SetMinSize(Z_BUTTON_SIZE);
@ -811,6 +815,7 @@ wxBoxSizer *StatusBasePanel::create_extruder_control(wxWindow *parent)
StateColor e_ctrl_bg(std::pair<wxColour, int>(BUTTON_PRESS_COL, StateColor::Pressed), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal)); StateColor e_ctrl_bg(std::pair<wxColour, int>(BUTTON_PRESS_COL, StateColor::Pressed), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal));
StateColor e_ctrl_bd(std::pair<wxColour, int>(BUTTON_HOVER_COL, StateColor::Hovered), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal)); StateColor e_ctrl_bd(std::pair<wxColour, int>(BUTTON_HOVER_COL, StateColor::Hovered), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal));
m_bpButton_e_10 = new Button(panel, "", "monitor_extruder_up", 0, FromDIP(22)); m_bpButton_e_10 = new Button(panel, "", "monitor_extruder_up", 0, FromDIP(22));
m_bpButton_e_10->SetBorderWidth(2);
m_bpButton_e_10->SetBackgroundColor(e_ctrl_bg); m_bpButton_e_10->SetBackgroundColor(e_ctrl_bg);
m_bpButton_e_10->SetBorderColor(e_ctrl_bd); m_bpButton_e_10->SetBorderColor(e_ctrl_bd);
m_bpButton_e_10->SetMinSize(wxSize(FromDIP(40), FromDIP(40))); m_bpButton_e_10->SetMinSize(wxSize(FromDIP(40), FromDIP(40)));
@ -825,6 +830,7 @@ wxBoxSizer *StatusBasePanel::create_extruder_control(wxWindow *parent)
bSizer_e_ctrl->Add(m_bitmap_extruder_img, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM, FromDIP(5)); bSizer_e_ctrl->Add(m_bitmap_extruder_img, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM, FromDIP(5));
bSizer_e_ctrl->Add(0, FromDIP(7), 0, 0, 0); bSizer_e_ctrl->Add(0, FromDIP(7), 0, 0, 0);
m_bpButton_e_down_10 = new Button(panel, "", "monitor_extruder_down", 0, FromDIP(22)); m_bpButton_e_down_10 = new Button(panel, "", "monitor_extruder_down", 0, FromDIP(22));
m_bpButton_e_down_10->SetBorderWidth(2);
m_bpButton_e_down_10->SetBackgroundColor(e_ctrl_bg); m_bpButton_e_down_10->SetBackgroundColor(e_ctrl_bg);
m_bpButton_e_down_10->SetBorderColor(e_ctrl_bd); m_bpButton_e_down_10->SetBorderColor(e_ctrl_bd);
m_bpButton_e_down_10->SetMinSize(wxSize(FromDIP(40), FromDIP(40))); m_bpButton_e_down_10->SetMinSize(wxSize(FromDIP(40), FromDIP(40)));

View file

@ -38,7 +38,6 @@ ComboBox::ComboBox(wxWindow * parent,
GetTextCtrl()->Hide(); GetTextCtrl()->Hide();
TextInput::SetFont(Label::Body_14); TextInput::SetFont(Label::Body_14);
TextInput::SetBorderColor(StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), TextInput::SetBorderColor(StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
std::make_pair(0xEDFAF2, (int) StateColor::Focused),
std::make_pair(0x00AE42, (int) StateColor::Hovered), std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal))); std::make_pair(0xDBDBDB, (int) StateColor::Normal)));
TextInput::SetBackgroundColor(StateColor(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), TextInput::SetBackgroundColor(StateColor(std::make_pair(0xF0F0F0, (int) StateColor::Disabled),

View file

@ -6,14 +6,9 @@
BEGIN_EVENT_TABLE(SpinInput, wxPanel) BEGIN_EVENT_TABLE(SpinInput, wxPanel)
EVT_MOTION(SpinInput::mouseMoved)
EVT_ENTER_WINDOW(SpinInput::mouseEnterWindow)
EVT_LEAVE_WINDOW(SpinInput::mouseLeaveWindow)
EVT_KEY_DOWN(SpinInput::keyPressed) EVT_KEY_DOWN(SpinInput::keyPressed)
EVT_KEY_UP(SpinInput::keyReleased)
EVT_MOUSEWHEEL(SpinInput::mouseWheelMoved) EVT_MOUSEWHEEL(SpinInput::mouseWheelMoved)
// catch paint events
EVT_PAINT(SpinInput::paintEvent) EVT_PAINT(SpinInput::paintEvent)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -25,16 +20,14 @@ END_EVENT_TABLE()
*/ */
SpinInput::SpinInput() SpinInput::SpinInput()
: state_handler(this) : label_color(std::make_pair(0x909090, (int) StateColor::Disabled), std::make_pair(0x6B6B6B, (int) StateColor::Normal))
, border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal))
, label_color(std::make_pair(0x909090, (int) StateColor::Disabled), std::make_pair(0x6B6B6B, (int) StateColor::Normal))
, text_color(std::make_pair(0x909090, (int) StateColor::Disabled), std::make_pair(0x262E30, (int) StateColor::Normal)) , text_color(std::make_pair(0x909090, (int) StateColor::Disabled), std::make_pair(0x262E30, (int) StateColor::Normal))
, background_color(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal))
{ {
hover = false;
radius = 0; radius = 0;
border_width = 1;
border_color = StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal));
background_color = StateColor(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
} }
@ -58,10 +51,10 @@ void SpinInput::Create(wxWindow *parent,
long style, long style,
int min, int max, int initial) int min, int max, int initial)
{ {
wxWindow::Create(parent, wxID_ANY, pos, size); StaticBox::Create(parent, wxID_ANY, pos, size);
SetFont(Label::Body_12); SetFont(Label::Body_12);
wxWindow::SetLabel(label); wxWindow::SetLabel(label);
state_handler.attach({&border_color, &label_color, &text_color, &background_color}); state_handler.attach({&label_color, &text_color});
state_handler.update_binds(); state_handler.update_binds();
text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS)); text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS));
text_ctrl->SetFont(Label::Body_14); text_ctrl->SetFont(Label::Body_14);
@ -121,12 +114,6 @@ void SpinInput::SetTextColor(StateColor const &color)
state_handler.update_binds(); state_handler.update_binds();
} }
void SpinInput::SetBackgroundColor(StateColor const& color)
{
background_color = color;
state_handler.update_binds();
}
void SpinInput::SetSize(wxSize const &size) void SpinInput::SetSize(wxSize const &size)
{ {
wxWindow::SetSize(size); wxWindow::SetSize(size);
@ -201,24 +188,22 @@ void SpinInput::paintEvent(wxPaintEvent& evt)
*/ */
void SpinInput::render(wxDC& dc) void SpinInput::render(wxDC& dc)
{ {
StaticBox::render(dc);
int states = state_handler.states(); int states = state_handler.states();
wxSize size = GetSize(); wxSize size = GetSize();
dc.SetPen(wxPen(border_color.colorForStates(states))); // draw seperator of buttons
dc.SetBrush(wxBrush(background_color.colorForStates(states)));
dc.DrawRoundedRectangle(0, 0, size.x, size.y, radius);
wxPoint pt = button_inc->GetPosition(); wxPoint pt = button_inc->GetPosition();
pt.y = size.y / 2; pt.y = size.y / 2;
dc.SetPen(wxPen(border_color.defaultColor())); dc.SetPen(wxPen(border_color.defaultColor()));
dc.DrawLine(pt, pt + wxSize{button_inc->GetSize().x - 2, 0}); dc.DrawLine(pt, pt + wxSize{button_inc->GetSize().x - 2, 0});
dc.SetBrush(*wxTRANSPARENT_BRUSH); // draw label
// start draw auto label = GetLabel();
auto text = GetLabel(); if (!label.IsEmpty()) {
if (!text.IsEmpty()) {
pt.x = size.x - labelSize.x - 5; pt.x = size.x - labelSize.x - 5;
pt.y = (size.y - labelSize.y) / 2; pt.y = (size.y - labelSize.y) / 2;
dc.SetFont(GetFont()); dc.SetFont(GetFont());
dc.SetTextForeground(label_color.colorForStates(states)); dc.SetTextForeground(label_color.colorForStates(states));
dc.DrawText(text, pt); dc.DrawText(label, pt);
} }
} }
@ -275,24 +260,6 @@ Button *SpinInput::createButton(bool inc)
return btn; return btn;
} }
void SpinInput::mouseEnterWindow(wxMouseEvent& event)
{
if (!hover)
{
hover = true;
Refresh();
}
}
void SpinInput::mouseLeaveWindow(wxMouseEvent& event)
{
if (hover)
{
hover = false;
Refresh();
}
}
void SpinInput::onTimer(wxTimerEvent &evnet) { void SpinInput::onTimer(wxTimerEvent &evnet) {
if (delta < -1 || delta > 1) { if (delta < -1 || delta > 1) {
delta /= 2; delta /= 2;
@ -336,9 +303,6 @@ void SpinInput::mouseWheelMoved(wxMouseEvent &event)
text_ctrl->SetFocus(); text_ctrl->SetFocus();
} }
// currently unused events
void SpinInput::mouseMoved(wxMouseEvent& event) {}
void SpinInput::keyPressed(wxKeyEvent &event) void SpinInput::keyPressed(wxKeyEvent &event)
{ {
switch (event.GetKeyCode()) { switch (event.GetKeyCode()) {
@ -359,7 +323,6 @@ void SpinInput::keyPressed(wxKeyEvent &event)
default: event.Skip(); break; default: event.Skip(); break;
} }
} }
void SpinInput::keyReleased(wxKeyEvent &event) {}
void SpinInput::sendSpinEvent() void SpinInput::sendSpinEvent()
{ {

View file

@ -2,22 +2,15 @@
#define slic3r_GUI_SpinInput_hpp_ #define slic3r_GUI_SpinInput_hpp_
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include "../wxExtensions.hpp" #include "StaticBox.hpp"
#include "StateHandler.hpp"
class Button; class Button;
class SpinInput : public wxNavigationEnabled<wxWindow> class SpinInput : public wxNavigationEnabled<StaticBox>
{ {
bool hover;
wxSize labelSize; wxSize labelSize;
double radius;
StateHandler state_handler;
StateColor label_color; StateColor label_color;
StateColor text_color; StateColor text_color;
StateColor border_color;
StateColor background_color;
wxTextCtrl * text_ctrl; wxTextCtrl * text_ctrl;
Button * button_inc; Button * button_inc;
Button * button_dec; Button * button_dec;
@ -60,8 +53,6 @@ public:
void SetTextColor(StateColor const &color); void SetTextColor(StateColor const &color);
void SetBackgroundColor(StateColor const & color);
void SetSize(wxSize const &size); void SetSize(wxSize const &size);
void Rescale(); void Rescale();
@ -91,12 +82,8 @@ private:
Button *createButton(bool inc); Button *createButton(bool inc);
// some useful events // some useful events
void mouseMoved(wxMouseEvent& event);
void mouseWheelMoved(wxMouseEvent& event); void mouseWheelMoved(wxMouseEvent& event);
void mouseEnterWindow(wxMouseEvent& event);
void mouseLeaveWindow(wxMouseEvent& event);
void keyPressed(wxKeyEvent& event); void keyPressed(wxKeyEvent& event);
void keyReleased(wxKeyEvent& event);
void onTimer(wxTimerEvent &evnet); void onTimer(wxTimerEvent &evnet);
void onTextLostFocus(wxEvent &event); void onTextLostFocus(wxEvent &event);
void onTextEnter(wxCommandEvent &event); void onTextEnter(wxCommandEvent &event);

View file

@ -35,9 +35,6 @@ StaticBox::StaticBox(wxWindow* parent,
bool StaticBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) bool StaticBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{ {
wxWindow::Create(parent, id, pos, size, style); wxWindow::Create(parent, id, pos, size, style);
#ifdef __WXMSW__
SetBackgroundStyle(wxBG_STYLE_PAINT);
#endif
state_handler.attach({&border_color, &background_color, &background_color2}); state_handler.attach({&border_color, &background_color, &background_color2});
state_handler.update_binds(); state_handler.update_binds();
SetBackgroundColour(GetParentBackgroundColor(parent)); SetBackgroundColour(GetParentBackgroundColor(parent));
@ -122,6 +119,11 @@ void StaticBox::paintEvent(wxPaintEvent& evt)
void StaticBox::render(wxDC& dc) void StaticBox::render(wxDC& dc)
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__
if (radius == 0) {
doRender(dc);
return;
}
wxSize size = GetSize(); wxSize size = GetSize();
wxMemoryDC memdc; wxMemoryDC memdc;
wxBitmap bmp(size.x, size.y); wxBitmap bmp(size.x, size.y);
@ -149,10 +151,20 @@ void StaticBox::doRender(wxDC& dc)
if ((border_width && border_color.count() > 0) || background_color.count() > 0) { if ((border_width && border_color.count() > 0) || background_color.count() > 0) {
wxRect rc(0, 0, size.x, size.y); wxRect rc(0, 0, size.x, size.y);
if (border_width && border_color.count() > 0 && (GetWindowStyle() & wxBORDER_NONE) == 0) { if (border_width && border_color.count() > 0 && (GetWindowStyle() & wxBORDER_NONE) == 0) {
#ifdef __WXOSX__ if (dc.GetContentScaleFactor() == 1.0) {
int d = ceil(border_width / 2.0); int d = floor(border_width / 2.0);
rc.Deflate(d, d); int d2 = floor(border_width - 1);
#endif rc.x += d;
rc.width -= d2;
rc.y += d;
rc.height -= d2;
} else {
int d = 1;
rc.x += d;
rc.width -= d;
rc.y += d;
rc.height -= d;
}
dc.SetPen(wxPen(border_color.colorForStates(states), border_width)); dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
} else { } else {
dc.SetPen(wxPen(background_color.colorForStates(states))); dc.SetPen(wxPen(background_color.colorForStates(states)));

View file

@ -31,6 +31,7 @@ TabCtrl::TabCtrl(wxWindow * parent,
#else #else
radius = 1; radius = 1;
#endif #endif
border_width = 1;
SetBorderColor(0xcecece); SetBorderColor(0xcecece);
sizer = new wxBoxSizer(wxHORIZONTAL); sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->AddSpacer(10); sizer->AddSpacer(10);
@ -251,9 +252,6 @@ void TabCtrl::doRender(wxDC& dc)
{ {
wxSize size = GetSize(); wxSize size = GetSize();
int states = state_handler.states(); int states = state_handler.states();
dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
if (sel < 0) { return; } if (sel < 0) { return; }
auto x1 = btns[sel]->GetPosition().x; auto x1 = btns[sel]->GetPosition().x;
@ -262,6 +260,8 @@ void TabCtrl::doRender(wxDC& dc)
const int BS2 = (1 + border_width) / 2; const int BS2 = (1 + border_width) / 2;
#if 0 #if 0
x1 -= TAB_BUTTON_SPACE; x2 += TAB_BUTTON_SPACE; x1 -= TAB_BUTTON_SPACE; x2 += TAB_BUTTON_SPACE;
dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawLine(0, size.y - BS2, x1 - radius + BS2, size.y - BS2); dc.DrawLine(0, size.y - BS2, x1 - radius + BS2, size.y - BS2);
dc.DrawArc(x1 - radius, size.y, x1, size.y - radius, x1 - radius, size.y - radius); dc.DrawArc(x1 - radius, size.y, x1, size.y - radius, x1 - radius, size.y - radius);
dc.DrawLine(x1, size.y - radius, x1, radius); dc.DrawLine(x1, size.y - radius, x1, radius);
@ -272,6 +272,7 @@ void TabCtrl::doRender(wxDC& dc)
dc.DrawArc(x2, size.y - radius, x2 + radius, size.y, x2 + radius, size.y - radius); dc.DrawArc(x2, size.y - radius, x2 + radius, size.y, x2 + radius, size.y - radius);
dc.DrawLine(x2 + radius - BS2, size.y - BS2, size.x, size.y - BS2); dc.DrawLine(x2 + radius - BS2, size.y - BS2, size.x, size.y - BS2);
#else #else
dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
dc.DrawLine(0, size.y - BS2, size.x, size.y - BS2); dc.DrawLine(0, size.y - BS2, size.x, size.y - BS2);
wxColor c(0x42AE00); wxColor c(0x42AE00);
dc.SetPen(wxPen(c, 0)); dc.SetPen(wxPen(c, 0));

View file

@ -5,14 +5,6 @@
BEGIN_EVENT_TABLE(TextInput, wxPanel) BEGIN_EVENT_TABLE(TextInput, wxPanel)
EVT_MOTION(TextInput::mouseMoved)
EVT_ENTER_WINDOW(TextInput::mouseEnterWindow)
EVT_LEAVE_WINDOW(TextInput::mouseLeaveWindow)
EVT_KEY_DOWN(TextInput::keyPressed)
EVT_KEY_UP(TextInput::keyReleased)
EVT_MOUSEWHEEL(TextInput::mouseWheelMoved)
// catch paint events
EVT_PAINT(TextInput::paintEvent) EVT_PAINT(TextInput::paintEvent)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -24,19 +16,16 @@ END_EVENT_TABLE()
*/ */
TextInput::TextInput() TextInput::TextInput()
: state_handler(this) : label_color(std::make_pair(0x909090, (int) StateColor::Disabled),
, border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal))
, label_color(std::make_pair(0x909090, (int) StateColor::Disabled),
std::make_pair(0x6B6B6B, (int) StateColor::Normal)) std::make_pair(0x6B6B6B, (int) StateColor::Normal))
, text_color(std::make_pair(0x909090, (int) StateColor::Disabled), , text_color(std::make_pair(0x909090, (int) StateColor::Disabled),
std::make_pair(0x262E30, (int) StateColor::Normal)) std::make_pair(0x262E30, (int) StateColor::Normal))
, background_color(std::make_pair(0xF0F0F0, (int) StateColor::Disabled),
std::make_pair(*wxWHITE, (int) StateColor::Normal))
{ {
hover = false;
radius = 0; radius = 0;
border_width = 1;
border_color = StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal));
background_color = StateColor(std::make_pair(0xF0F0F0, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
SetFont(Label::Body_12); SetFont(Label::Body_12);
} }
@ -61,10 +50,10 @@ void TextInput::Create(wxWindow * parent,
long style) long style)
{ {
text_ctrl = nullptr; text_ctrl = nullptr;
wxWindow::Create(parent, wxID_ANY, pos, size, style); StaticBox::Create(parent, wxID_ANY, pos, size, style);
wxWindow::SetLabel(label); wxWindow::SetLabel(label);
style &= ~wxRIGHT; style &= ~wxRIGHT;
state_handler.attach({&border_color, &label_color, & text_color, &background_color}); state_handler.attach({&label_color, & text_color});
state_handler.update_binds(); state_handler.update_binds();
text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE); text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE);
text_ctrl->SetFont(Label::Body_14); text_ctrl->SetFont(Label::Body_14);
@ -119,12 +108,6 @@ void TextInput::SetIcon(const wxBitmap &icon)
Rescale(); Rescale();
} }
void TextInput::SetBorderColor(StateColor const& color)
{
border_color = color;
state_handler.update_binds();
}
void TextInput::SetLabelColor(StateColor const &color) void TextInput::SetLabelColor(StateColor const &color)
{ {
label_color = color; label_color = color;
@ -137,12 +120,6 @@ void TextInput::SetTextColor(StateColor const& color)
state_handler.update_binds(); state_handler.update_binds();
} }
void TextInput::SetBackgroundColor(StateColor const& color)
{
background_color = color;
state_handler.update_binds();
}
void TextInput::Rescale() void TextInput::Rescale()
{ {
if (!this->icon.name().empty()) if (!this->icon.name().empty())
@ -217,13 +194,10 @@ void TextInput::paintEvent(wxPaintEvent &evt)
*/ */
void TextInput::render(wxDC& dc) void TextInput::render(wxDC& dc)
{ {
StaticBox::render(dc);
int states = state_handler.states(); int states = state_handler.states();
wxSize size = GetSize(); wxSize size = GetSize();
bool align_right = GetWindowStyle() & wxRIGHT; bool align_right = GetWindowStyle() & wxRIGHT;
dc.SetPen(wxPen(border_color.colorForStates(states)));
dc.SetBrush(wxBrush(background_color.colorForStates(states)));
dc.DrawRoundedRectangle(0, 0, size.x, size.y, radius);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
// start draw // start draw
wxPoint pt = {5, 0}; wxPoint pt = {5, 0};
if (icon.bmp().IsOk()) { if (icon.bmp().IsOk()) {
@ -264,27 +238,3 @@ void TextInput::messureSize()
SetMinSize(minSize); SetMinSize(minSize);
SetSize(size); SetSize(size);
} }
void TextInput::mouseEnterWindow(wxMouseEvent& event)
{
if (!hover)
{
hover = true;
Refresh();
}
}
void TextInput::mouseLeaveWindow(wxMouseEvent& event)
{
if (hover)
{
hover = false;
Refresh();
}
}
// currently unused events
void TextInput::mouseMoved(wxMouseEvent& event) {}
void TextInput::mouseWheelMoved(wxMouseEvent& event) {}
void TextInput::keyPressed(wxKeyEvent& event) {}
void TextInput::keyReleased(wxKeyEvent& event) {}

View file

@ -2,21 +2,15 @@
#define slic3r_GUI_TextInput_hpp_ #define slic3r_GUI_TextInput_hpp_
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include "../wxExtensions.hpp" #include "StaticBox.hpp"
#include "StateHandler.hpp"
class TextInput : public wxNavigationEnabled<wxWindow> class TextInput : public wxNavigationEnabled<StaticBox>
{ {
bool hover;
wxSize labelSize; wxSize labelSize;
ScalableBitmap icon; ScalableBitmap icon;
double radius;
StateHandler state_handler;
StateColor label_color; StateColor label_color;
StateColor text_color; StateColor text_color;
StateColor border_color;
StateColor background_color;
wxTextCtrl * text_ctrl; wxTextCtrl * text_ctrl;
static const int TextInputWidth = 200; static const int TextInputWidth = 200;
@ -48,14 +42,10 @@ public:
void SetIcon(const wxBitmap & icon); void SetIcon(const wxBitmap & icon);
void SetBorderColor(StateColor const & color);
void SetLabelColor(StateColor const &color); void SetLabelColor(StateColor const &color);
void SetTextColor(StateColor const &color); void SetTextColor(StateColor const &color);
void SetBackgroundColor(StateColor const &color);
virtual void Rescale(); virtual void Rescale();
virtual bool Enable(bool enable = true) override; virtual bool Enable(bool enable = true) override;
@ -81,14 +71,6 @@ private:
void messureSize(); void messureSize();
// some useful events
void mouseMoved(wxMouseEvent& event);
void mouseWheelMoved(wxMouseEvent& event);
void mouseEnterWindow(wxMouseEvent& event);
void mouseLeaveWindow(wxMouseEvent& event);
void keyPressed(wxKeyEvent& event);
void keyReleased(wxKeyEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };