mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -06:00
Add the full source of BambuStudio
using version 1.0.10
This commit is contained in:
parent
30bcadab3e
commit
1555904bef
3771 changed files with 1251328 additions and 0 deletions
119
src/slic3r/GUI/Widgets/SwitchButton.cpp
Normal file
119
src/slic3r/GUI/Widgets/SwitchButton.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
#include "SwitchButton.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "StaticBox.hpp"
|
||||
|
||||
#include "../wxExtensions.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
SwitchButton::SwitchButton(wxWindow* parent, wxWindowID id)
|
||||
: wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT)
|
||||
, m_on(this, "toggle_on", 16)
|
||||
, m_off(this, "toggle_off", 16)
|
||||
, text_color(std::pair{*wxWHITE, (int) StateColor::Checked}, std::pair{0x6B6B6B, (int) StateColor::Normal})
|
||||
, track_color(0xD9D9D9)
|
||||
, thumb_color(std::pair{0x00AE42, (int) StateColor::Checked}, std::pair{0xD9D9D9, (int) StateColor::Normal})
|
||||
{
|
||||
SetBackgroundColour(StaticBox::GetParentBackgroundColor(parent));
|
||||
Bind(wxEVT_TOGGLEBUTTON, [this](auto& e) { update(); e.Skip(); });
|
||||
SetFont(Label::Body_12);
|
||||
Rescale();
|
||||
}
|
||||
|
||||
void SwitchButton::SetLabels(wxString const& lbl_on, wxString const& lbl_off)
|
||||
{
|
||||
labels[0] = lbl_on;
|
||||
labels[1] = lbl_off;
|
||||
Rescale();
|
||||
}
|
||||
|
||||
void SwitchButton::SetTextColor(StateColor const& color)
|
||||
{
|
||||
text_color = color;
|
||||
}
|
||||
|
||||
void SwitchButton::SetTrackColor(StateColor const& color)
|
||||
{
|
||||
track_color = color;
|
||||
}
|
||||
|
||||
void SwitchButton::SetThumbColor(StateColor const& color)
|
||||
{
|
||||
thumb_color = color;
|
||||
}
|
||||
|
||||
void SwitchButton::SetValue(bool value)
|
||||
{
|
||||
if (value != GetValue())
|
||||
wxBitmapToggleButton::SetValue(value);
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchButton::Rescale()
|
||||
{
|
||||
if (labels[0].IsEmpty()) {
|
||||
m_on.msw_rescale();
|
||||
m_off.msw_rescale();
|
||||
}
|
||||
else {
|
||||
constexpr int BS = 1;
|
||||
wxSize thumbSize;
|
||||
wxSize trackSize;
|
||||
wxClientDC dc(this);
|
||||
wxSize textSize[2];
|
||||
{
|
||||
textSize[0] = dc.GetTextExtent(labels[0]);
|
||||
textSize[1] = dc.GetTextExtent(labels[1]);
|
||||
}
|
||||
{
|
||||
thumbSize = textSize[0];
|
||||
auto size = textSize[1];
|
||||
if (size.x > thumbSize.x) thumbSize.x = size.x;
|
||||
else size.x = thumbSize.x;
|
||||
thumbSize.x += 12;
|
||||
thumbSize.y += 2;
|
||||
trackSize.x = thumbSize.x + size.x + 10;
|
||||
trackSize.y = thumbSize.y + BS * 2;
|
||||
auto maxWidth = GetMaxWidth();
|
||||
if (trackSize.x > maxWidth) {
|
||||
thumbSize.x -= (trackSize.x - maxWidth) / 2;
|
||||
trackSize.x = maxWidth;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
wxMemoryDC memdc(&dc);
|
||||
wxBitmap bmp(trackSize.x, trackSize.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.SetBackground(wxBrush(GetBackgroundColour()));
|
||||
memdc.Clear();
|
||||
memdc.SetFont(GetFont());
|
||||
auto state = i == 0 ? StateColor::Enabled : (StateColor::Checked | StateColor::Enabled);
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxGCDC dc2(memdc);
|
||||
#else
|
||||
wxDC &dc2(memdc);
|
||||
#endif
|
||||
dc2.SetBrush(wxBrush(track_color.colorForStates(state)));
|
||||
dc2.SetPen(wxPen(track_color.colorForStates(state)));
|
||||
dc2.DrawRoundedRectangle(wxRect({0, 0}, trackSize), trackSize.y / 2);
|
||||
dc2.SetBrush(wxBrush(thumb_color.colorForStates(StateColor::Checked | StateColor::Enabled)));
|
||||
dc2.SetPen(wxPen(thumb_color.colorForStates(StateColor::Checked | StateColor::Enabled)));
|
||||
dc2.DrawRoundedRectangle(wxRect({ i == 0 ? BS : (trackSize.x - thumbSize.x - BS), BS}, thumbSize), thumbSize.y / 2);
|
||||
}
|
||||
memdc.SetTextForeground(text_color.colorForStates(state ^ StateColor::Checked));
|
||||
memdc.DrawText(labels[0], {BS + (thumbSize.x - textSize[0].x) / 2, BS + (thumbSize.y - textSize[0].y) / 2});
|
||||
memdc.SetTextForeground(text_color.colorForStates(state));
|
||||
memdc.DrawText(labels[1], {trackSize.x - thumbSize.x - BS + (thumbSize.x - textSize[1].x) / 2, BS + (thumbSize.y - textSize[1].y) / 2});
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
(i == 0 ? m_off : m_on).bmp() = bmp;
|
||||
}
|
||||
}
|
||||
SetSize(m_on.GetBmpSize());
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchButton::update()
|
||||
{
|
||||
SetBitmap((GetValue() ? m_on : m_off).bmp());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue