mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 15:07:31 -06:00
NEW:add fan control
Change-Id: I3b5c7cf638306aaac81459c2f25e37008a5a8a2f
This commit is contained in:
parent
59773eee02
commit
b61da88d51
24 changed files with 1240 additions and 28 deletions
|
@ -15,6 +15,16 @@ EVT_PAINT(ImageSwitchButton::paintEvent)
|
|||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(FanSwitchButton, StaticBox)
|
||||
|
||||
EVT_LEFT_DOWN(FanSwitchButton::mouseDown)
|
||||
EVT_ENTER_WINDOW(FanSwitchButton::mouseEnterWindow)
|
||||
EVT_LEAVE_WINDOW(FanSwitchButton::mouseLeaveWindow)
|
||||
EVT_LEFT_UP(FanSwitchButton::mouseReleased)
|
||||
EVT_PAINT(FanSwitchButton::paintEvent)
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
static const wxColour DEFAULT_HOVER_COL = wxColour(0, 174, 66);
|
||||
static const wxColour DEFAULT_PRESS_COL = wxColour(238, 238, 238);
|
||||
|
||||
|
@ -171,6 +181,188 @@ void ImageSwitchButton::mouseLeaveWindow(wxMouseEvent &event)
|
|||
}
|
||||
|
||||
void ImageSwitchButton::sendButtonEvent()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
|
||||
event.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
FanSwitchButton::FanSwitchButton(wxWindow* parent, ScalableBitmap& img_on, ScalableBitmap& img_off, long style)
|
||||
: text_color(std::make_pair(0x6B6B6B, (int)StateColor::Disabled), std::make_pair(*wxBLACK, (int)StateColor::Normal))
|
||||
{
|
||||
radius = 0;
|
||||
m_padding = 0;
|
||||
m_speed = 0;
|
||||
m_on = img_on;
|
||||
m_off = img_off;
|
||||
background_color = StateColor(std::make_pair(*wxWHITE, (int)StateColor::Disabled), std::make_pair(DEFAULT_PRESS_COL, (int)StateColor::Pressed),
|
||||
std::make_pair(*wxWHITE, (int)StateColor::Normal));
|
||||
border_color = StateColor(std::make_pair(*wxWHITE, (int)StateColor::Disabled), std::make_pair(DEFAULT_HOVER_COL, (int)StateColor::Focused),
|
||||
std::make_pair(DEFAULT_HOVER_COL, (int)StateColor::Hovered), std::make_pair(*wxWHITE, (int)StateColor::Normal));
|
||||
|
||||
StaticBox::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
|
||||
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::SetLabels(wxString const& lbl_on, wxString const& lbl_off)
|
||||
{
|
||||
labels[0] = lbl_on;
|
||||
labels[1] = lbl_off;
|
||||
auto fina_txt = GetValue() ? labels[0] : labels[1];
|
||||
SetToolTip(fina_txt);
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::SetImages(ScalableBitmap& img_on, ScalableBitmap& img_off)
|
||||
{
|
||||
m_on = img_on;
|
||||
m_off = img_off;
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::SetTextColor(StateColor const& color)
|
||||
{
|
||||
text_color = color;
|
||||
state_handler.update_binds();
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::SetValue(bool value)
|
||||
{
|
||||
m_on_off = value;
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::SetPadding(int padding)
|
||||
{
|
||||
m_padding = padding;
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::messureSize()
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
dc.SetFont(GetFont());
|
||||
textSize = dc.GetTextExtent(GetValue() ? labels[0] : labels[1]);
|
||||
}
|
||||
|
||||
void FanSwitchButton::paintEvent(wxPaintEvent& evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
render(dc);
|
||||
}
|
||||
|
||||
void FanSwitchButton::render(wxDC& dc)
|
||||
{
|
||||
StaticBox::render(dc);
|
||||
int states = state_handler.states();
|
||||
wxSize size = GetSize();
|
||||
|
||||
wxSize szIcon;
|
||||
wxSize szContent = textSize;
|
||||
ScalableBitmap& icon = GetValue() ? m_on : m_off;
|
||||
|
||||
//int content_height = icon.GetBmpHeight() + textSize.y + m_padding;
|
||||
int content_height = m_padding;
|
||||
|
||||
wxPoint pt = wxPoint((size.x - icon.GetBmpWidth()) / 2, (size.y - content_height) / 2);
|
||||
|
||||
pt.x = (size.x - textSize.x) / 2;
|
||||
dc.SetFont(GetFont());
|
||||
if (!IsEnabled())
|
||||
dc.SetTextForeground(text_color.colorForStates(StateColor::Disabled));
|
||||
else
|
||||
dc.SetTextForeground(text_color.colorForStates(states));
|
||||
|
||||
auto fina_txt = GetValue() ? labels[0] : labels[1];
|
||||
if (dc.GetTextExtent(fina_txt).x > size.x) {
|
||||
wxString forment_txt = wxEmptyString;
|
||||
for (auto i = 0; i < fina_txt.length(); i++) {
|
||||
forment_txt = fina_txt.SubString(0, i) + "...";
|
||||
if (dc.GetTextExtent(forment_txt).x > size.x) {
|
||||
pt.x = (size.x - dc.GetTextExtent(forment_txt).x) / 2;
|
||||
dc.DrawText(forment_txt, wxPoint(pt.x, content_height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
dc.DrawText(fina_txt, wxPoint(pt.x, content_height));
|
||||
}
|
||||
|
||||
pt = wxPoint((size.x - icon.GetBmpWidth()) / 2, content_height + textSize.y);
|
||||
if (icon.bmp().IsOk()) {
|
||||
dc.DrawBitmap(icon.bmp(), pt);
|
||||
pt.y += m_padding + icon.GetBmpHeight();
|
||||
}
|
||||
|
||||
auto speed = wxString::Format("%d%%", m_speed);
|
||||
|
||||
dc.SetFont(GetFont());
|
||||
if (!IsEnabled())
|
||||
dc.SetTextForeground(text_color.colorForStates(StateColor::Disabled));
|
||||
else
|
||||
dc.SetTextForeground(text_color.colorForStates(states));
|
||||
|
||||
pt.x = (size.x - dc.GetTextExtent(speed).x) / 2;
|
||||
dc.DrawText(speed, pt);
|
||||
}
|
||||
|
||||
void FanSwitchButton::Rescale()
|
||||
{
|
||||
messureSize();
|
||||
}
|
||||
|
||||
void FanSwitchButton::setFanValue(int val)
|
||||
{
|
||||
m_speed = val;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanSwitchButton::mouseDown(wxMouseEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
pressedDown = true;
|
||||
SetFocus();
|
||||
CaptureMouse();
|
||||
}
|
||||
|
||||
void FanSwitchButton::mouseReleased(wxMouseEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
if (pressedDown) {
|
||||
pressedDown = false;
|
||||
ReleaseMouse();
|
||||
//m_on_off = !m_on_off;
|
||||
Refresh();
|
||||
sendButtonEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void FanSwitchButton::mouseEnterWindow(wxMouseEvent& event)
|
||||
{
|
||||
if (!hover) {
|
||||
hover = true;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void FanSwitchButton::mouseLeaveWindow(wxMouseEvent& event)
|
||||
{
|
||||
if (hover) {
|
||||
hover = false;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void FanSwitchButton::sendButtonEvent()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
|
||||
event.SetEventObject(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue