mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 02:41:17 +00:00
Merge branch 'master' into SoftFever
# Conflicts: # bbl/i18n/zh_cn/BambuStudio_zh_CN.po # resources/i18n/de/BambuStudio.mo # resources/i18n/en/BambuStudio.mo # resources/i18n/es/BambuStudio.mo # resources/i18n/fr/BambuStudio.mo # resources/i18n/hu/BambuStudio.mo # resources/i18n/nl/BambuStudio.mo # resources/i18n/sv/BambuStudio.mo # resources/i18n/zh_cn/BambuStudio.mo # resources/profiles/Creality.json # resources/profiles/Voron.json # resources/web/guide/3/index.html # src/libslic3r/AppConfig.cpp # src/libslic3r/GCode.cpp # src/libslic3r/GCode/GCodeProcessor.cpp # src/libslic3r/LayerRegion.cpp # src/libslic3r/Preset.cpp # src/libslic3r/Print.cpp # src/libslic3r/PrintConfig.cpp # src/libslic3r/PrintConfig.hpp # src/libslic3r/PrintObject.cpp # src/slic3r/GUI/AboutDialog.cpp # src/slic3r/GUI/BBLTopbar.cpp # src/slic3r/GUI/ConfigManipulation.cpp # src/slic3r/GUI/ConfigWizard.cpp # src/slic3r/GUI/GCodeViewer.cpp # src/slic3r/GUI/GUI_App.cpp # src/slic3r/GUI/GUI_Factories.cpp # src/slic3r/GUI/MainFrame.cpp # src/slic3r/GUI/Plater.cpp # src/slic3r/GUI/Tab.cpp # version.inc
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "Label.hpp"
|
||||
#include "../BitmapCache.hpp"
|
||||
#include "../I18N.hpp"
|
||||
#include "../GUI_App.hpp"
|
||||
|
||||
#include <wx/simplebook.h>
|
||||
#include <wx/dcgraph.h>
|
||||
@@ -14,14 +15,14 @@ static const int UNLOAD_STEP_COUNT = 3;
|
||||
static const wxColour AMS_TRAY_DEFAULT_COL = wxColour(255, 255, 255);
|
||||
|
||||
static wxString FILAMENT_LOAD_STEP_STRING[LOAD_STEP_COUNT] = {
|
||||
_L("Heat the nozzle to target temperature"),
|
||||
_L("Heat the nozzle"),
|
||||
_L("Cut filament"),
|
||||
_L("Pull back current filament"),
|
||||
_L("Push new filament into extruder"),
|
||||
_L("Purge old filament"),
|
||||
};
|
||||
|
||||
static wxString FILAMENT_UNLOAD_STEP_STRING[UNLOAD_STEP_COUNT] = {_L("Heat the nozzle to target temperature"), _L("Cut filament"), _L("Pull back current filament")};
|
||||
static wxString FILAMENT_UNLOAD_STEP_STRING[UNLOAD_STEP_COUNT] = {_L("Heat the nozzle"), _L("Cut filament"), _L("Pull back current filament")};
|
||||
|
||||
wxDEFINE_EVENT(EVT_AMS_LOAD, SimpleEvent);
|
||||
wxDEFINE_EVENT(EVT_AMS_UNLOAD, SimpleEvent);
|
||||
@@ -34,30 +35,11 @@ wxDEFINE_EVENT(EVT_AMS_CLIBRATION_CANCEL, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_AMS_GUIDE_WIKI, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_AMS_RETRY, wxCommandEvent);
|
||||
|
||||
inline int hex_digit_to_int(const char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9') ? int(c - '0') : (c >= 'A' && c <= 'F') ? int(c - 'A') + 10 : (c >= 'a' && c <= 'f') ? int(c - 'a') + 10 : -1;
|
||||
}
|
||||
|
||||
static wxColour decode_color(const std::string &color)
|
||||
{
|
||||
std::array<int, 3> ret = {0, 0, 0};
|
||||
const char * c = color.data() + 1;
|
||||
if (color.size() == 8) {
|
||||
for (size_t j = 0; j < 3; ++j) {
|
||||
int digit1 = hex_digit_to_int(*c++);
|
||||
int digit2 = hex_digit_to_int(*c++);
|
||||
if (digit1 == -1 || digit2 == -1) break;
|
||||
ret[j] = float(digit1 * 16 + digit2);
|
||||
}
|
||||
}
|
||||
return wxColour(ret[0], ret[1], ret[2]);
|
||||
}
|
||||
|
||||
bool AMSinfo::parse_ams_info(Ams *ams)
|
||||
bool AMSinfo::parse_ams_info(Ams *ams, bool remain_flag)
|
||||
{
|
||||
if (!ams) return false;
|
||||
this->ams_id = ams->id;
|
||||
this->ams_humidity = ams->humidity;
|
||||
cans.clear();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
auto it = ams->trayList.find(std::to_string(i));
|
||||
@@ -79,6 +61,16 @@ bool AMSinfo::parse_ams_info(Ams *ams)
|
||||
} else {
|
||||
info.material_state = AMSCanType::AMS_CAN_TYPE_THIRDBRAND;
|
||||
}
|
||||
|
||||
if (!remain_flag) {
|
||||
info.material_remain = 100;
|
||||
}
|
||||
else {
|
||||
info.material_remain = it->second->remain < 0 ? 100 : it->second->remain;
|
||||
info.material_remain = it->second->remain > 100 ? 100 : info.material_remain;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
info.can_id = it->second->id;
|
||||
info.material_name = "";
|
||||
@@ -99,19 +91,19 @@ bool AMSinfo::parse_ams_info(Ams *ams)
|
||||
Description:AMSrefresh
|
||||
**************************************************/
|
||||
|
||||
AMSrefresh::AMSrefresh() { SetFont(Label::Body_10); }
|
||||
AMSrefresh::AMSrefresh() { SetFont(Label::Body_10);}
|
||||
|
||||
AMSrefresh::AMSrefresh(wxWindow *parent, wxWindowID id, wxString number, Caninfo info, const wxPoint &pos, const wxSize &size) : AMSrefresh()
|
||||
{
|
||||
m_info = info;
|
||||
m_text = number;
|
||||
m_can_id = number.ToStdString();
|
||||
create(parent, id, pos, size);
|
||||
}
|
||||
|
||||
AMSrefresh::AMSrefresh(wxWindow *parent, wxWindowID id, int number, Caninfo info, const wxPoint &pos, const wxSize &size) : AMSrefresh()
|
||||
{
|
||||
m_info = info;
|
||||
m_text = wxString::Format("%d", number);
|
||||
m_can_id = wxString::Format("%d", number).ToStdString();
|
||||
create(parent, id, pos, size);
|
||||
}
|
||||
|
||||
@@ -221,7 +213,7 @@ void AMSrefresh::paintEvent(wxPaintEvent &evt)
|
||||
wxSize size = GetSize();
|
||||
wxPaintDC dc(this);
|
||||
|
||||
auto colour = AMS_CONTROL_GRAY700;
|
||||
auto colour = StateColor::darkModeColorFor(AMS_CONTROL_GRAY700);
|
||||
if (!wxWindow::IsEnabled()) { colour = AMS_CONTROL_GRAY500; }
|
||||
|
||||
auto pot = wxPoint((size.x - m_bitmap_selected.GetBmpSize().x) / 2, (size.y - m_bitmap_selected.GetBmpSize().y) / 2);
|
||||
@@ -246,16 +238,24 @@ void AMSrefresh::paintEvent(wxPaintEvent &evt)
|
||||
|
||||
dc.SetPen(wxPen(colour));
|
||||
dc.SetBrush(wxBrush(colour));
|
||||
dc.SetFont(Label::Body_12);
|
||||
dc.SetFont(Label::Body_11);
|
||||
dc.SetTextForeground(colour);
|
||||
auto tsize = dc.GetTextExtent(m_text);
|
||||
auto tsize = dc.GetTextExtent(m_refresh_id);
|
||||
pot = wxPoint((size.x - tsize.x) / 2, (size.y - tsize.y) / 2);
|
||||
dc.DrawText(m_text, pot);
|
||||
dc.DrawText(m_refresh_id, pot);
|
||||
}
|
||||
|
||||
void AMSrefresh::Update(Caninfo info)
|
||||
void AMSrefresh::Update(std::string ams_id, Caninfo info)
|
||||
{
|
||||
m_info = info;
|
||||
m_ams_id = ams_id;
|
||||
m_info = info;
|
||||
|
||||
if (!m_ams_id.empty() && !m_can_id.empty()) {
|
||||
auto aid = atoi(m_ams_id.c_str());
|
||||
auto tid = atoi(m_can_id.c_str());
|
||||
auto tray_id = aid * 4 + tid;
|
||||
m_refresh_id = wxGetApp().transition_tridid(tray_id);
|
||||
}
|
||||
StopLoading();
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ void AMSextruderImage::doRender(wxDC &dc)
|
||||
auto size = GetSize();
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(m_colour);
|
||||
dc.DrawRectangle(0, 0, size.x, size.y - FromDIP(5));
|
||||
dc.DrawRectangle(0, FromDIP(18), size.x, size.y - FromDIP(18) - FromDIP(5));
|
||||
dc.DrawBitmap(m_ams_extruder.bmp(), wxPoint((size.x - m_ams_extruder.GetBmpSize().x) / 2, (size.y - m_ams_extruder.GetBmpSize().y) / 2));
|
||||
}
|
||||
|
||||
@@ -353,7 +353,6 @@ AMSextruderImage::AMSextruderImage(wxWindow *parent, wxWindowID id, const wxPoin
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
|
||||
m_ams_extruder = ScalableBitmap(this, "monitor_ams_extruder",55);
|
||||
|
||||
SetSize(AMS_EXTRUDER_BITMAP_SIZE);
|
||||
SetMinSize(AMS_EXTRUDER_BITMAP_SIZE);
|
||||
SetMaxSize(AMS_EXTRUDER_BITMAP_SIZE);
|
||||
@@ -388,7 +387,7 @@ void AMSextruder::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, co
|
||||
wxBoxSizer *m_sizer_body = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
m_bitmap_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, AMS_EXTRUDER_BITMAP_SIZE, wxTAB_TRAVERSAL);
|
||||
m_bitmap_panel->SetBackgroundColour(wxColour(AMS_EXTRUDER_DEF_COLOUR));
|
||||
m_bitmap_panel->SetBackgroundColour(AMS_EXTRUDER_DEF_COLOUR);
|
||||
m_bitmap_panel->SetDoubleBuffered(true);
|
||||
m_bitmap_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
@@ -521,6 +520,10 @@ void AMSLib::render(wxDC &dc)
|
||||
temp_text_colour = AMS_CONTROL_GRAY800;
|
||||
}
|
||||
|
||||
if (m_info.material_remain < 50) {
|
||||
temp_text_colour = AMS_CONTROL_GRAY800;
|
||||
}
|
||||
|
||||
//if (!wxWindow::IsEnabled()) {
|
||||
//temp_text_colour = AMS_CONTROL_DISABLE_TEXT_COLOUR;
|
||||
//}
|
||||
@@ -568,11 +571,16 @@ void AMSLib::render(wxDC &dc)
|
||||
|
||||
void AMSLib::doRender(wxDC &dc)
|
||||
{
|
||||
wxSize size = GetSize();
|
||||
auto tmp_lib_colour = m_info.material_colour;
|
||||
wxSize size = GetSize();
|
||||
auto tmp_lib_colour = m_info.material_colour;
|
||||
auto temp_bitmap_third = m_bitmap_editable_light;
|
||||
auto temp_bitmap_brand = m_bitmap_readonly_light;
|
||||
|
||||
//draw def background
|
||||
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
|
||||
dc.SetBrush(wxBrush(AMS_CONTROL_DEF_LIB_BK_COLOUR));
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius);
|
||||
|
||||
if (tmp_lib_colour.GetLuminance() < 0.5) {
|
||||
temp_bitmap_third = m_bitmap_editable_light;
|
||||
temp_bitmap_brand = m_bitmap_readonly_light;
|
||||
@@ -581,6 +589,11 @@ void AMSLib::doRender(wxDC &dc)
|
||||
temp_bitmap_brand = m_bitmap_readonly;
|
||||
}
|
||||
|
||||
if (m_info.material_remain < 50) {
|
||||
temp_bitmap_third = m_bitmap_editable;
|
||||
temp_bitmap_brand = m_bitmap_readonly;
|
||||
}
|
||||
|
||||
//if (!wxWindow::IsEnabled()) {
|
||||
//tmp_lib_colour = AMS_CONTROL_DISABLE_COLOUR;
|
||||
//}
|
||||
@@ -598,11 +611,11 @@ void AMSLib::doRender(wxDC &dc)
|
||||
|
||||
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
|
||||
dc.SetBrush(wxBrush(tmp_lib_colour));
|
||||
if (m_radius == 0) {
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
} else {
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius);
|
||||
}
|
||||
/* if (m_radius == 0) {
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
} else {
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius);
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!m_selected && m_hover) {
|
||||
@@ -610,26 +623,83 @@ void AMSLib::doRender(wxDC &dc)
|
||||
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
|
||||
if (m_radius == 0) {
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
dc.DrawRoundedRectangle(FromDIP(1), FromDIP(1), size.x - FromDIP(1), size.y - FromDIP(1), m_radius);
|
||||
}
|
||||
|
||||
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
|
||||
dc.SetBrush(wxBrush(tmp_lib_colour));
|
||||
if (m_radius == 0) {
|
||||
/* if (m_radius == 0) {
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
} else {
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius);
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
dc.SetPen(wxPen(tmp_lib_colour, 1, wxSOLID));
|
||||
dc.SetBrush(wxBrush(tmp_lib_colour));
|
||||
if (m_radius == 0) {
|
||||
/*if (m_radius == 0) {
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
} else {
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(8), size.y - FromDIP(8), m_radius);
|
||||
}*/
|
||||
}
|
||||
|
||||
//draw remain
|
||||
int height = size.y - FromDIP(8);
|
||||
int curr_height = height * float(m_info.material_remain * 1.0 / 100.0);
|
||||
|
||||
|
||||
|
||||
int top = height - curr_height;
|
||||
|
||||
if (curr_height >= FromDIP(6)) {
|
||||
#ifdef __APPLE__
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius);
|
||||
#else
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), curr_height, m_radius - 1);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (top > 2) {
|
||||
if (curr_height >= FromDIP(6)) {
|
||||
dc.DrawRectangle(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(8), FromDIP(2));
|
||||
if (tmp_lib_colour.Red() > 238 && tmp_lib_colour.Green() > 238 && tmp_lib_colour.Blue() > 238) {
|
||||
dc.SetPen(wxPen(wxColour(130, 129, 128), 1, wxSOLID));
|
||||
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
|
||||
dc.DrawLine(FromDIP(4), FromDIP(4) + top, size.x - FromDIP(4), FromDIP(4) + top);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
|
||||
if (tmp_lib_colour.Red() > 238 && tmp_lib_colour.Green() > 238 && tmp_lib_colour.Blue() > 238) {
|
||||
dc.SetPen(wxPen(wxColour(130, 129, 128), 2, wxSOLID));
|
||||
}
|
||||
else {
|
||||
dc.SetPen(wxPen(tmp_lib_colour, 2, wxSOLID));
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
dc.DrawLine(FromDIP(5), FromDIP(4) + height - FromDIP(2), size.x - FromDIP(5), FromDIP(4) + height - FromDIP(2));
|
||||
dc.DrawLine(FromDIP(6), FromDIP(4) + height - FromDIP(1), size.x - FromDIP(6), FromDIP(4) + height - FromDIP(1));
|
||||
#else
|
||||
dc.DrawLine(FromDIP(4), FromDIP(4) + height - FromDIP(2), size.x - FromDIP(4), FromDIP(4) + height - FromDIP(2));
|
||||
dc.DrawLine(FromDIP(5), FromDIP(4) + height - FromDIP(1), size.x - FromDIP(5), FromDIP(4) + height - FromDIP(1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//border
|
||||
dc.SetPen(wxPen(wxColour(130, 130, 128), 1, wxSOLID));
|
||||
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
|
||||
#ifdef __APPLE__
|
||||
dc.DrawRoundedRectangle(FromDIP(4), FromDIP(4), size.x - FromDIP(7), size.y - FromDIP(7), m_radius);
|
||||
#else
|
||||
dc.DrawRoundedRectangle(FromDIP(3), FromDIP(3), size.x - FromDIP(6), size.y - FromDIP(6), m_radius);
|
||||
#endif
|
||||
|
||||
|
||||
// edit icon
|
||||
if (m_info.material_state != AMSCanType::AMS_CAN_TYPE_EMPTY && m_info.material_state != AMSCanType::AMS_CAN_TYPE_NONE)
|
||||
@@ -696,6 +766,12 @@ AMSRoad::AMSRoad(wxWindow *parent, wxWindowID id, Caninfo info, int canindex, in
|
||||
m_rode_mode = AMSRoadMode::AMS_ROAD_MODE_LEFT;
|
||||
}
|
||||
|
||||
ams_humidity_0 = ScalableBitmap(this, "ams_humidity_0", 18);
|
||||
ams_humidity_1 = ScalableBitmap(this, "ams_humidity_1", 18);
|
||||
ams_humidity_2 = ScalableBitmap(this, "ams_humidity_2", 18);
|
||||
ams_humidity_3 = ScalableBitmap(this, "ams_humidity_3", 18);
|
||||
ams_humidity_4 = ScalableBitmap(this, "ams_humidity_4", 18);
|
||||
|
||||
create(parent, id, pos, size);
|
||||
Bind(wxEVT_PAINT, &AMSRoad::paintEvent, this);
|
||||
wxWindow::SetBackgroundColour(AMS_CONTROL_DEF_BLOCK_BK_COLOUR);
|
||||
@@ -703,8 +779,9 @@ AMSRoad::AMSRoad(wxWindow *parent, wxWindowID id, Caninfo info, int canindex, in
|
||||
|
||||
void AMSRoad::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size) { wxWindow::Create(parent, id, pos, size); }
|
||||
|
||||
void AMSRoad::Update(Caninfo info, int canindex, int maxcan)
|
||||
void AMSRoad::Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan)
|
||||
{
|
||||
m_amsinfo = amsinfo;
|
||||
m_info = info;
|
||||
m_canindex = canindex;
|
||||
if (m_canindex == 0 && maxcan == 1) {
|
||||
@@ -822,6 +899,27 @@ void AMSRoad::doRender(wxDC &dc)
|
||||
dc.SetBrush(wxBrush(m_road_def_color));
|
||||
dc.DrawRoundedRectangle(size.x * 0.37 / 2, size.y * 0.6 - size.y / 6, size.x * 0.63, size.y / 3, m_radius);
|
||||
}
|
||||
|
||||
if (m_canindex == 3) {
|
||||
if (m_amsinfo.ams_humidity == 5) {
|
||||
dc.DrawBitmap(ams_humidity_4.bmp(), wxPoint(size.x - ams_humidity_4.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_4.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
else if (m_amsinfo.ams_humidity == 4) {
|
||||
dc.DrawBitmap(ams_humidity_3.bmp(), wxPoint(size.x - ams_humidity_3.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_3.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
else if (m_amsinfo.ams_humidity == 3) {
|
||||
dc.DrawBitmap(ams_humidity_2.bmp(), wxPoint(size.x - ams_humidity_2.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_2.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
else if (m_amsinfo.ams_humidity == 2) {
|
||||
dc.DrawBitmap(ams_humidity_1.bmp(), wxPoint(size.x - ams_humidity_1.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_1.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
else if (m_amsinfo.ams_humidity == 1) {
|
||||
dc.DrawBitmap(ams_humidity_0.bmp(), wxPoint(size.x - ams_humidity_0.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_0.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
else {
|
||||
dc.DrawBitmap(ams_humidity_4.bmp(), wxPoint(size.x - ams_humidity_4.GetBmpSize().x - FromDIP(4), size.y - ams_humidity_4.GetBmpSize().y - FromDIP(8)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AMSRoad::UpdatePassRoad(int tag_index, AMSPassRoadType type, AMSPassRoadSTEP step) {}
|
||||
@@ -892,7 +990,6 @@ AMSItem::AMSItem(wxWindow *parent, wxWindowID id, AMSinfo amsinfo, const wxSize
|
||||
Bind(wxEVT_PAINT, &AMSItem::paintEvent, this);
|
||||
Bind(wxEVT_ENTER_WINDOW, &AMSItem::OnEnterWindow, this);
|
||||
Bind(wxEVT_LEAVE_WINDOW, &AMSItem::OnLeaveWindow, this);
|
||||
// Bind(wxEVT_LEFT_DOWN, &AMSItem::OnSelected, this);
|
||||
}
|
||||
|
||||
void AMSItem::Open()
|
||||
@@ -999,8 +1096,8 @@ void AMSItem::render(wxDC &dc)
|
||||
void AMSItem::doRender(wxDC &dc)
|
||||
{
|
||||
wxSize size = GetSize();
|
||||
dc.SetPen(wxPen(m_background_colour));
|
||||
dc.SetBrush(wxBrush(m_background_colour));
|
||||
dc.SetPen(wxPen(StateColor::darkModeColorFor(m_background_colour)));
|
||||
dc.SetBrush(wxBrush(StateColor::darkModeColorFor(m_background_colour)));
|
||||
dc.DrawRoundedRectangle(0, 0, size.x, size.y, 3);
|
||||
|
||||
auto left = m_padding;
|
||||
@@ -1025,12 +1122,11 @@ void AMSItem::doRender(wxDC &dc)
|
||||
dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH));
|
||||
dc.DrawLine(left, (size.y - AMS_ITEM_CUBE_SIZE.y) / 2, left, ((size.y - AMS_ITEM_CUBE_SIZE.y) / 2) + AMS_ITEM_CUBE_SIZE.y);
|
||||
|
||||
left += m_space;
|
||||
dc.SetFont(::Label::Body_13);
|
||||
dc.SetTextForeground(AMS_CONTROL_GRAY800);
|
||||
auto tsize = dc.GetTextExtent("00% RH");
|
||||
auto text = wxString::Format("%d%% RH", m_humidity);
|
||||
dc.DrawText(text, wxPoint(left, (size.y - tsize.y) / 2));
|
||||
left += m_space + m_space / 2;
|
||||
/* dc.SetFont(::Label::Body_13);
|
||||
dc.SetTextForeground(AMS_CONTROL_GRAY800);
|
||||
auto tsize = dc.GetTextExtent("00% RH");
|
||||
auto text = wxString::Format("%d%% RH", m_humidity);*/
|
||||
}
|
||||
|
||||
auto border_colour = AMS_CONTROL_BRAND_COLOUR;
|
||||
@@ -1088,7 +1184,7 @@ void AmsCans::Update(AMSinfo info)
|
||||
for (auto i = 0; i < m_can_refresh_list.GetCount(); i++) {
|
||||
Canrefreshs *refresh = m_can_refresh_list[i];
|
||||
if (i < m_can_count) {
|
||||
refresh->canrefresh->Update(info.cans[i]);
|
||||
refresh->canrefresh->Update(info.ams_id, info.cans[i]);
|
||||
refresh->canrefresh->Show();
|
||||
} else {
|
||||
refresh->canrefresh->Hide();
|
||||
@@ -1107,7 +1203,7 @@ void AmsCans::Update(AMSinfo info)
|
||||
for (auto i = 0; i < m_can_road_list.GetCount(); i++) {
|
||||
CanRoads *road = m_can_road_list[i];
|
||||
if (i < m_can_count) {
|
||||
road->canRoad->Update(info.cans[i], i, m_can_count);
|
||||
road->canRoad->Update(m_info, info.cans[i], i, m_can_count);
|
||||
road->canRoad->Show();
|
||||
} else {
|
||||
road->canRoad->Hide();
|
||||
@@ -1120,11 +1216,14 @@ void AmsCans::Update(AMSinfo info)
|
||||
void AmsCans::AddCan(Caninfo caninfo, int canindex, int maxcan)
|
||||
{
|
||||
auto amscan = new wxWindow(this, wxID_ANY);
|
||||
amscan->SetBackgroundColour(AMS_CONTROL_DEF_BLOCK_BK_COLOUR);
|
||||
wxBoxSizer *m_sizer_ams = new wxBoxSizer(wxVERTICAL);
|
||||
m_sizer_ams->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(14));
|
||||
auto m_panel_refresh = new AMSrefresh(amscan, wxID_ANY, m_can_count + 1, caninfo);
|
||||
|
||||
auto m_panel_refresh = new AMSrefresh(amscan, wxID_ANY, m_can_count, caninfo);
|
||||
m_sizer_ams->Add(m_panel_refresh, 0, wxALIGN_CENTER_HORIZONTAL, 0);
|
||||
m_sizer_ams->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(2));
|
||||
|
||||
auto m_panel_lib = new AMSLib(amscan, wxID_ANY, caninfo);
|
||||
m_panel_lib->Bind(wxEVT_LEFT_DOWN, [this, canindex](wxMouseEvent &ev) {
|
||||
m_canlib_selection = canindex;
|
||||
@@ -1346,7 +1445,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
|
||||
m_panel_can = new StaticBox(m_amswin, wxID_ANY, wxDefaultPosition, AMS_CANS_SIZE, wxBORDER_NONE);
|
||||
m_panel_can->SetMinSize(AMS_CANS_SIZE);
|
||||
m_panel_can->SetCornerRadius(FromDIP(10));
|
||||
m_panel_can->SetBackgroundColor(AMS_CONTROL_DEF_BLOCK_BK_COLOUR);
|
||||
m_panel_can->SetBackgroundColor(StateColor(std::pair<wxColour, int>(AMS_CONTROL_DEF_BLOCK_BK_COLOUR, StateColor::Normal)));
|
||||
|
||||
m_sizer_cans = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
@@ -1416,7 +1515,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
|
||||
m_button_extruder_feed = new Button(m_amswin, _L("Load Filament"));
|
||||
m_button_extruder_feed->SetBackgroundColor(btn_bg_green);
|
||||
m_button_extruder_feed->SetBorderColor(btn_bd_green);
|
||||
m_button_extruder_feed->SetTextColor(btn_text_green);
|
||||
m_button_extruder_feed->SetTextColor(wxColour("#FFFFFE"));
|
||||
m_button_extruder_feed->SetFont(Label::Body_13);
|
||||
|
||||
m_button_extruder_back = new Button(m_amswin, _L("Unload Filament"));
|
||||
@@ -1468,20 +1567,26 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
|
||||
m_simplebook_right->AddPage(m_filament_load_step, wxEmptyString, false);
|
||||
m_simplebook_right->AddPage(m_filament_unload_step, wxEmptyString, false);
|
||||
|
||||
|
||||
m_button_ams_setting_normal = ScalableBitmap(this, "ams_setting_normal", 24);
|
||||
m_button_ams_setting_hover = ScalableBitmap(this, "ams_setting_hover", 24);
|
||||
m_button_ams_setting_press = ScalableBitmap(this, "ams_setting_press", 24);
|
||||
|
||||
wxBoxSizer *m_sizer_right_bottom = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_button_ams_setting = new Button(m_amswin, "", "ams_setting_normal", wxBORDER_NONE, FromDIP(24));
|
||||
m_button_ams_setting->SetPaddingSize(wxSize(0, 0));
|
||||
m_button_ams_setting->SetBackgroundColor(m_amswin->GetBackgroundColour());
|
||||
m_button_ams_setting = new wxStaticBitmap(m_amswin, wxID_ANY, m_button_ams_setting_normal.bmp(), wxDefaultPosition, wxSize(FromDIP(24), FromDIP(24)));
|
||||
m_button_ams_setting->SetBackgroundColour(m_amswin->GetBackgroundColour());
|
||||
|
||||
m_button_guide = new Button(m_amswin, _L("Guide"));
|
||||
m_button_guide->SetFont(Label::Body_13);
|
||||
m_button_guide->SetCornerRadius(FromDIP(12));
|
||||
m_button_guide->SetBorderColor(btn_bd_white);
|
||||
m_button_guide->SetMinSize(wxSize(-1, FromDIP(24)));
|
||||
m_button_guide->SetBackgroundColor(btn_bg_white);
|
||||
|
||||
m_button_retry = new Button(m_amswin, _L("Retry"));
|
||||
m_button_retry->SetFont(Label::Body_13);
|
||||
m_button_retry->SetCornerRadius(FromDIP(12));
|
||||
m_button_retry->SetBorderColor(btn_bd_white);
|
||||
m_button_retry->SetMinSize(wxSize(-1, FromDIP(24)));
|
||||
m_button_retry->SetBackgroundColor(btn_bg_white);
|
||||
|
||||
@@ -1578,20 +1683,22 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
|
||||
|
||||
m_button_extruder_feed->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AMSControl::on_filament_load), NULL, this);
|
||||
m_button_extruder_back->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AMSControl::on_filament_unload), NULL, this);
|
||||
m_button_ams_setting->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AMSControl::on_ams_setting_click), NULL, this);
|
||||
m_button_ams_setting->Bind(wxEVT_LEFT_DOWN, &AMSControl::on_ams_setting_click, this);
|
||||
m_button_ams_setting->Bind(wxEVT_ENTER_WINDOW, [this](wxMouseEvent& e) {
|
||||
m_button_ams_setting->SetIcon("ams_setting_hover");
|
||||
m_button_ams_setting->SetBitmap(m_button_ams_setting_hover.bmp());
|
||||
e.Skip();
|
||||
});
|
||||
m_button_ams_setting->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
|
||||
m_button_ams_setting->SetIcon("ams_setting_press");
|
||||
m_button_ams_setting->SetBitmap(m_button_ams_setting_press.bmp());
|
||||
e.Skip();
|
||||
});
|
||||
m_button_ams_setting->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent&e) {
|
||||
m_button_ams_setting->SetIcon("ams_setting_normal");
|
||||
m_button_ams_setting->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& e) {
|
||||
m_button_ams_setting->SetBitmap(m_button_ams_setting_normal.bmp());
|
||||
e.Skip();
|
||||
});
|
||||
|
||||
|
||||
|
||||
m_button_guide->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {
|
||||
post_event(wxCommandEvent(EVT_AMS_GUIDE_WIKI));
|
||||
});
|
||||
@@ -1736,6 +1843,11 @@ void AMSControl::StopRridLoading(wxString amsid, wxString canid)
|
||||
|
||||
void AMSControl::msw_rescale()
|
||||
{
|
||||
m_button_ams_setting_normal.msw_rescale();
|
||||
m_button_ams_setting_hover.msw_rescale();
|
||||
m_button_ams_setting_press.msw_rescale();
|
||||
m_button_ams_setting->SetBitmap(m_button_ams_setting_normal.bmp());
|
||||
|
||||
m_extruder->msw_rescale();
|
||||
m_button_extruder_back->SetMinSize(wxSize(-1, FromDIP(24)));
|
||||
m_button_extruder_feed->SetMinSize(wxSize(-1, FromDIP(24)));
|
||||
@@ -1760,15 +1872,15 @@ void AMSControl::UpdateStepCtrl()
|
||||
|
||||
void AMSControl::CreateAms()
|
||||
{
|
||||
auto caninfo0_0 = Caninfo{"def_can_0", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_1 = Caninfo{"def_can_1", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_2 = Caninfo{"def_can_2", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_3 = Caninfo{"def_can_3", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_0 = Caninfo{"def_can_0", (""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_1 = Caninfo{"def_can_1", (""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_2 = Caninfo{"def_can_2", (""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_3 = Caninfo{"def_can_3", (""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
|
||||
AMSinfo ams1 = AMSinfo{"def_ams_0", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams2 = AMSinfo{"def_ams_1", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams3 = AMSinfo{"def_ams_2", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams4 = AMSinfo{"def_ams_3", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams1 = AMSinfo{"0", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams2 = AMSinfo{"1", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams3 = AMSinfo{"2", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams4 = AMSinfo{"3", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
std::vector<AMSinfo> ams_info{ams1, ams2, ams3, ams4};
|
||||
std::vector<AMSinfo>::iterator it;
|
||||
Freeze();
|
||||
@@ -1779,10 +1891,10 @@ void AMSControl::CreateAms()
|
||||
|
||||
void AMSControl::Reset()
|
||||
{
|
||||
auto caninfo0_0 = Caninfo{"def_can_0", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_1 = Caninfo{"def_can_1", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_2 = Caninfo{"def_can_2", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_3 = Caninfo{"def_can_3", L(""), *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_0 = Caninfo{"def_can_0", "", *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_1 = Caninfo{"def_can_1", "", *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_2 = Caninfo{"def_can_2", "", *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
auto caninfo0_3 = Caninfo{"def_can_3", "", *wxWHITE, AMSCanType::AMS_CAN_TYPE_NONE};
|
||||
|
||||
AMSinfo ams1 = AMSinfo{"def_ams_0", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
AMSinfo ams2 = AMSinfo{"def_ams_1", std::vector<Caninfo>{caninfo0_0, caninfo0_1, caninfo0_2, caninfo0_3}};
|
||||
@@ -1902,7 +2014,7 @@ void AMSControl::SwitchAms(std::string ams_id)
|
||||
//item->amsItem->HideHumidity();
|
||||
}
|
||||
m_sizer_top->Layout();
|
||||
// m_panel_top->Fit();
|
||||
m_panel_top->Fit();
|
||||
}
|
||||
|
||||
for (auto i = 0; i < m_ams_cans_list.GetCount(); i++) {
|
||||
@@ -2068,7 +2180,7 @@ void AMSControl::on_filament_unload(wxCommandEvent &event)
|
||||
post_event(SimpleEvent(EVT_AMS_UNLOAD));
|
||||
}
|
||||
|
||||
void AMSControl::on_ams_setting_click(wxCommandEvent &event)
|
||||
void AMSControl::on_ams_setting_click(wxMouseEvent &event)
|
||||
{
|
||||
post_event(SimpleEvent(EVT_AMS_SETTINGS));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define AMS_CONTROL_WHITE_COLOUR wxColour(255, 255, 255)
|
||||
#define AMS_CONTROL_BLACK_COLOUR wxColour(0, 0, 0)
|
||||
#define AMS_CONTROL_DEF_BLOCK_BK_COLOUR wxColour(238, 238, 238)
|
||||
#define AMS_CONTROL_DEF_LIB_BK_COLOUR wxColour(248, 248, 248)
|
||||
#define AMS_EXTRUDER_DEF_COLOUR wxColour(234, 234, 234)
|
||||
#define AMS_CONTROL_MAX_COUNT 4
|
||||
#define AMS_CONTRO_CALIBRATION_BUTTON_SIZE wxSize(FromDIP(150), FromDIP(28))
|
||||
@@ -94,7 +95,7 @@ enum FilamentStep {
|
||||
|
||||
#define AMS_ITEM_CUBE_SIZE wxSize(FromDIP(14), FromDIP(14))
|
||||
#define AMS_ITEM_SIZE wxSize(FromDIP(82), FromDIP(27))
|
||||
#define AMS_ITEM_HUMIDITY_SIZE wxSize(FromDIP(150), FromDIP(27))
|
||||
#define AMS_ITEM_HUMIDITY_SIZE wxSize(FromDIP(120), FromDIP(27))
|
||||
#define AMS_CAN_LIB_SIZE wxSize(FromDIP(58), FromDIP(80))
|
||||
#define AMS_CAN_ROAD_SIZE wxSize(FromDIP(66), FromDIP(60))
|
||||
#define AMS_CAN_ITEM_HEIGHT_SIZE FromDIP(27)
|
||||
@@ -111,20 +112,21 @@ struct Caninfo
|
||||
wxString material_name;
|
||||
wxColour material_colour = {*wxWHITE};
|
||||
AMSCanType material_state;
|
||||
int material_remain = 100;
|
||||
};
|
||||
|
||||
struct AMSinfo
|
||||
{
|
||||
public:
|
||||
std::string ams_id;
|
||||
std::vector<Caninfo> cans;
|
||||
std::string ams_id;
|
||||
std::vector<Caninfo> cans;
|
||||
std::string current_can_id;
|
||||
AMSPassRoadSTEP current_step;
|
||||
AMSAction current_action;
|
||||
int curreent_filamentstep;
|
||||
int ams_humidity = 0;
|
||||
|
||||
std::string current_can_id;
|
||||
AMSPassRoadSTEP current_step;
|
||||
AMSAction current_action;
|
||||
int curreent_filamentstep;
|
||||
|
||||
bool parse_ams_info(Ams *ams);
|
||||
bool parse_ams_info(Ams *ams, bool remain_flag = false);
|
||||
};
|
||||
|
||||
/*************************************************
|
||||
@@ -147,17 +149,20 @@ public:
|
||||
void OnClick(wxMouseEvent &evt);
|
||||
void post_event(wxCommandEvent &&event);
|
||||
void paintEvent(wxPaintEvent &evt);
|
||||
void Update(Caninfo info);
|
||||
void Update(std::string ams_id, Caninfo info);
|
||||
void msw_rescale();
|
||||
Caninfo m_info;
|
||||
|
||||
|
||||
protected:
|
||||
wxTimer *m_playing_timer= {nullptr};
|
||||
int m_rotation_angle = 0;
|
||||
|
||||
bool m_play_loading = {false};
|
||||
bool m_selected = {false};
|
||||
|
||||
std::string m_ams_id;
|
||||
std::string m_can_id;
|
||||
|
||||
ScalableBitmap m_bitmap_normal;
|
||||
ScalableBitmap m_bitmap_selected;
|
||||
ScalableBitmap m_bitmap_ams_rfid_0;
|
||||
@@ -170,7 +175,7 @@ protected:
|
||||
ScalableBitmap m_bitmap_ams_rfid_7;
|
||||
std::vector<ScalableBitmap> m_rfid_bitmap_list;
|
||||
|
||||
wxString m_text;
|
||||
wxString m_refresh_id;
|
||||
wxBoxSizer * m_size_body;
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
};
|
||||
@@ -268,6 +273,7 @@ public:
|
||||
void create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize);
|
||||
|
||||
public:
|
||||
AMSinfo m_amsinfo;
|
||||
Caninfo m_info;
|
||||
int m_canindex = {0};
|
||||
AMSRoadMode m_rode_mode = {AMSRoadMode::AMS_ROAD_MODE_LEFT_RIGHT};
|
||||
@@ -277,7 +283,15 @@ public:
|
||||
double m_radius = {4};
|
||||
wxColour m_road_def_color;
|
||||
wxColour m_road_color;
|
||||
void Update(Caninfo info, int canindex, int maxcan);
|
||||
void Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan);
|
||||
|
||||
ScalableBitmap ams_humidity_0;
|
||||
ScalableBitmap ams_humidity_1;
|
||||
ScalableBitmap ams_humidity_2;
|
||||
ScalableBitmap ams_humidity_3;
|
||||
ScalableBitmap ams_humidity_4;
|
||||
bool m_show_humidity = { false };
|
||||
int m_humidity = { 0 };
|
||||
|
||||
void SetPassRoadColour(wxColour col);
|
||||
void SetMode(AMSRoadMode mode);
|
||||
@@ -313,6 +327,7 @@ public:
|
||||
void HideHumidity();
|
||||
void SetHumidity(int humidity);
|
||||
virtual bool Enable(bool enable = true);
|
||||
|
||||
AMSinfo m_amsinfo;
|
||||
|
||||
protected:
|
||||
@@ -461,7 +476,10 @@ protected:
|
||||
|
||||
Button *m_button_extruder_feed = {nullptr};
|
||||
Button *m_button_extruder_back = {nullptr};
|
||||
Button* m_button_ams_setting = {nullptr};
|
||||
wxStaticBitmap* m_button_ams_setting = {nullptr};
|
||||
ScalableBitmap m_button_ams_setting_normal;
|
||||
ScalableBitmap m_button_ams_setting_hover;
|
||||
ScalableBitmap m_button_ams_setting_press;
|
||||
Button *m_button_guide = {nullptr};
|
||||
Button *m_button_retry = {nullptr};
|
||||
|
||||
@@ -499,7 +517,7 @@ public:
|
||||
void msw_rescale();
|
||||
void on_filament_load(wxCommandEvent &event);
|
||||
void on_filament_unload(wxCommandEvent &event);
|
||||
void on_ams_setting_click(wxCommandEvent &event);
|
||||
void on_ams_setting_click(wxMouseEvent &event);
|
||||
void on_clibration_again_click(wxMouseEvent &event);
|
||||
void on_clibration_cancel_click(wxMouseEvent &event);
|
||||
void Reset();
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
StateColor blank_bg(StateColor(std::make_pair(wxColour("#FFFFFF"), (int)StateColor::Normal)));
|
||||
static const wxColour BUTTON_BG_COL = wxColour("#EEEEEE");
|
||||
static const wxColour BUTTON_IN_BG_COL = wxColour("#CECECE");
|
||||
|
||||
static const wxColour bd = wxColour(0, 174, 66);
|
||||
static const wxColour BUTTON_BG_COL = wxColour(238, 238, 238);
|
||||
static const wxColour BUTTON_IN_BG_COL = wxColour(206, 206, 206);
|
||||
static const wxColour blank_bg = wxColour(0xFFFFFF);
|
||||
static const wxColour text_num_color = wxColour(0x898989);
|
||||
static const wxColour BUTTON_PRESS_COL = wxColour(172, 172, 172);
|
||||
static const double sqrt2 = std::sqrt(2);
|
||||
@@ -155,16 +156,16 @@ void AxisCtrlButton::render(wxDC& dc)
|
||||
wxGraphicsPath outer_path = gc->CreatePath();
|
||||
outer_path.AddCircle(0, 0, r_outer);
|
||||
outer_path.AddCircle(0, 0, r_inner);
|
||||
gc->SetPen(BUTTON_BG_COL);
|
||||
gc->SetBrush(BUTTON_BG_COL);
|
||||
gc->SetPen(StateColor::darkModeColorFor(BUTTON_BG_COL));
|
||||
gc->SetBrush(StateColor::darkModeColorFor(BUTTON_BG_COL));
|
||||
gc->DrawPath(outer_path);
|
||||
|
||||
//draw the inner ring
|
||||
wxGraphicsPath inner_path = gc->CreatePath();
|
||||
inner_path.AddCircle(0, 0, r_inner);
|
||||
inner_path.AddCircle(0, 0, r_blank);
|
||||
gc->SetPen(BUTTON_IN_BG_COL);
|
||||
gc->SetBrush(BUTTON_IN_BG_COL);
|
||||
gc->SetPen(StateColor::darkModeColorFor(BUTTON_IN_BG_COL));
|
||||
gc->SetBrush(StateColor::darkModeColorFor(BUTTON_IN_BG_COL));
|
||||
gc->DrawPath(inner_path);
|
||||
|
||||
//draw an arc in corresponding position
|
||||
@@ -187,8 +188,8 @@ void AxisCtrlButton::render(wxDC& dc)
|
||||
}
|
||||
|
||||
//draw rectangle gap
|
||||
gc->SetPen(blank_bg);
|
||||
gc->SetBrush(blank_bg);
|
||||
gc->SetPen(blank_bg.colorForStates(StateColor::Normal));
|
||||
gc->SetBrush(blank_bg.colorForStates(StateColor::Normal));
|
||||
gc->PushState();
|
||||
gc->Rotate(-PI / 4);
|
||||
gc->DrawRectangle(-sqrt2 * size.x / 2, -sqrt2 * gap / 2, sqrt2 * size.x, sqrt2 * gap);
|
||||
@@ -205,8 +206,8 @@ void AxisCtrlButton::render(wxDC& dc)
|
||||
gc->SetPen(wxPen(border_color.colorForStates(states), 2));
|
||||
gc->SetBrush(wxBrush(background_color.colorForStates(states)));
|
||||
} else {
|
||||
gc->SetPen(BUTTON_BG_COL);
|
||||
gc->SetBrush(BUTTON_BG_COL);
|
||||
gc->SetPen(StateColor::darkModeColorFor(BUTTON_BG_COL));
|
||||
gc->SetBrush(StateColor::darkModeColorFor(BUTTON_BG_COL));
|
||||
}
|
||||
gc->DrawPath(home_path);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ Button::Button()
|
||||
: paddingSize(10, 8)
|
||||
{
|
||||
background_color = StateColor(
|
||||
std::make_pair(0xF0F0F0, (int) StateColor::Disabled),
|
||||
std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
|
||||
std::make_pair(0x37EE7C, (int) StateColor::Hovered | StateColor::Checked),
|
||||
std::make_pair(0x00AE42, (int) StateColor::Checked),
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
|
||||
@@ -127,6 +127,14 @@ bool Button::Enable(bool enable)
|
||||
|
||||
void Button::SetCanFocus(bool canFocus) { this->canFocus = canFocus; }
|
||||
|
||||
void Button::SetValue(bool state)
|
||||
{
|
||||
if (GetValue() == state) return;
|
||||
state_handler.set_state(state ? StateHandler::Checked : 0, StateHandler::Checked);
|
||||
}
|
||||
|
||||
bool Button::GetValue() const { return state_handler.states() & StateHandler::Checked; }
|
||||
|
||||
void Button::Rescale()
|
||||
{
|
||||
if (this->active_icon.bmp().IsOk())
|
||||
@@ -237,7 +245,8 @@ void Button::mouseDown(wxMouseEvent& event)
|
||||
pressedDown = true;
|
||||
if (canFocus)
|
||||
SetFocus();
|
||||
CaptureMouse();
|
||||
if (!HasCapture())
|
||||
CaptureMouse();
|
||||
}
|
||||
|
||||
void Button::mouseReleased(wxMouseEvent& event)
|
||||
|
||||
@@ -48,6 +48,10 @@ public:
|
||||
|
||||
void SetCanFocus(bool canFocus) override;
|
||||
|
||||
void SetValue(bool state);
|
||||
|
||||
bool GetValue() const;
|
||||
|
||||
void Rescale();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -41,7 +41,7 @@ ComboBox::ComboBox(wxWindow * parent,
|
||||
TextInput::SetBorderColor(StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
|
||||
std::make_pair(0x00AE42, (int) StateColor::Hovered),
|
||||
std::make_pair(0xDBDBDB, (int) StateColor::Normal)));
|
||||
TextInput::SetBackgroundColor(StateColor(std::make_pair(0xF0F0F0, (int) StateColor::Disabled),
|
||||
TextInput::SetBackgroundColor(StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
|
||||
std::make_pair(0xEDFAF2, (int) StateColor::Focused),
|
||||
std::make_pair(*wxWHITE, (int) StateColor::Normal)));
|
||||
TextInput::SetLabelColor(StateColor(std::make_pair(0x909090, (int) StateColor::Disabled),
|
||||
@@ -185,6 +185,13 @@ void ComboBox::SetString(unsigned int n, wxString const &value)
|
||||
|
||||
wxBitmap ComboBox::GetItemBitmap(unsigned int n) { return icons[n]; }
|
||||
|
||||
void ComboBox::SetItemBitmap(unsigned int n, wxBitmap const &bitmap)
|
||||
{
|
||||
if (n >= texts.size()) return;
|
||||
icons[n] = bitmap;
|
||||
drop.Invalidate();
|
||||
}
|
||||
|
||||
int ComboBox::DoInsertItems(const wxArrayStringsAdapter &items,
|
||||
unsigned int pos,
|
||||
void ** clientData,
|
||||
@@ -218,7 +225,7 @@ void ComboBox::mouseDown(wxMouseEvent &event)
|
||||
} else if (drop.HasDismissLongTime()) {
|
||||
drop.autoPosition();
|
||||
drop_down = true;
|
||||
drop.Popup();
|
||||
drop.Popup(&drop);
|
||||
wxCommandEvent e(wxEVT_COMBOBOX_DROPDOWN);
|
||||
GetEventHandler()->ProcessEvent(e);
|
||||
}
|
||||
@@ -228,7 +235,7 @@ void ComboBox::mouseWheelMoved(wxMouseEvent &event)
|
||||
{
|
||||
event.Skip();
|
||||
if (drop_down) return;
|
||||
auto delta = (event.GetWheelRotation() < 0 == event.IsWheelInverted()) ? -1 : 1;
|
||||
auto delta = event.GetWheelRotation() < 0 ? 1 : -1;
|
||||
unsigned int n = GetSelection() + delta;
|
||||
if (n < GetCount()) {
|
||||
SetSelection((int) n);
|
||||
@@ -262,13 +269,7 @@ void ComboBox::keyDown(wxKeyEvent& event)
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
{
|
||||
wxCommandEvent e(wxEVT_COMBOBOX);
|
||||
e.SetEventObject(this);
|
||||
e.SetId(GetId());
|
||||
e.SetInt(GetSelection());
|
||||
GetEventHandler()->ProcessEvent(e);
|
||||
}
|
||||
sendComboBoxEvent();
|
||||
break;
|
||||
case WXK_TAB:
|
||||
HandleAsNavigationKey(event);
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
void SetString(unsigned int n, wxString const &value) override;
|
||||
|
||||
wxBitmap GetItemBitmap(unsigned int n);
|
||||
void SetItemBitmap(unsigned int n, wxBitmap const &bitmap);
|
||||
|
||||
protected:
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter &items,
|
||||
@@ -75,6 +76,8 @@ protected:
|
||||
|
||||
void OnEdit() override;
|
||||
|
||||
void sendComboBoxEvent();
|
||||
|
||||
#ifdef __WIN32__
|
||||
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) override;
|
||||
#endif
|
||||
@@ -86,8 +89,6 @@ private:
|
||||
void mouseWheelMoved(wxMouseEvent &event);
|
||||
void keyDown(wxKeyEvent &event);
|
||||
|
||||
void sendComboBoxEvent();
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ DropDown::DropDown(wxWindow * parent,
|
||||
void DropDown::Create(wxWindow * parent,
|
||||
long style)
|
||||
{
|
||||
wxPopupTransientWindow::Create(parent);
|
||||
wxPopupTransientWindow::Create(parent, wxPU_CONTAINS_CONTROLS);
|
||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
state_handler.attach({&border_color, &text_color, &selector_border_color, &selector_background_color});
|
||||
@@ -179,6 +179,15 @@ void DropDown::paintNow()
|
||||
Refresh();
|
||||
}
|
||||
|
||||
static wxSize GetBmpSize(wxBitmap & bmp)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
return bmp.GetScaledSize();
|
||||
#else
|
||||
return bmp.GetSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Here we do the actual rendering. I put it in a separate
|
||||
* method so that it can work no matter what type of DC
|
||||
@@ -189,7 +198,7 @@ void DropDown::render(wxDC &dc)
|
||||
if (texts.size() == 0) return;
|
||||
int states = state_handler.states();
|
||||
dc.SetPen(wxPen(border_color.colorForStates(states)));
|
||||
dc.SetBrush(wxBrush(GetBackgroundColour()));
|
||||
dc.SetBrush(wxBrush(StateColor::darkModeColorFor(GetBackgroundColour())));
|
||||
// if (GetWindowStyle() & wxBORDER_NONE)
|
||||
// dc.SetPen(wxNullPen);
|
||||
|
||||
@@ -267,18 +276,19 @@ void DropDown::render(wxDC &dc)
|
||||
}
|
||||
if (rcContent.y > size.y) break;
|
||||
wxPoint pt = rcContent.GetLeftTop();
|
||||
auto & icon = icons[i];
|
||||
auto & icon = icons[i];
|
||||
auto size2 = GetBmpSize(icon);
|
||||
if (iconSize.x > 0) {
|
||||
if (icon.IsOk()) {
|
||||
pt.y += (rcContent.height - icon.GetSize().y) / 2;
|
||||
pt.y += (rcContent.height - size2.y) / 2;
|
||||
dc.DrawBitmap(icon, pt);
|
||||
}
|
||||
pt.x += iconSize.x + 5;
|
||||
pt.y = rcContent.y;
|
||||
} else if (icon.IsOk()) {
|
||||
pt.y += (rcContent.height - icon.GetSize().y) / 2;
|
||||
pt.y += (rcContent.height - size2.y) / 2;
|
||||
dc.DrawBitmap(icon, pt);
|
||||
pt.x += icon.GetWidth() + 5;
|
||||
pt.x += size2.x + 5;
|
||||
pt.y = rcContent.y;
|
||||
}
|
||||
auto text = texts[i];
|
||||
@@ -305,7 +315,7 @@ void DropDown::messureSize()
|
||||
for (size_t i = 0; i < texts.size(); ++i) {
|
||||
wxSize size1 = text_off ? wxSize() : dc.GetMultiLineTextExtent(texts[i]);
|
||||
if (icons[i].IsOk()) {
|
||||
wxSize size2 = icons[i].GetSize();
|
||||
wxSize size2 = GetBmpSize(icons[i]);
|
||||
if (size2.x > iconSize.x) iconSize = size2;
|
||||
if (!align_icon) {
|
||||
size1.x += size2.x + (text_off ? 0 : 5);
|
||||
@@ -317,7 +327,7 @@ void DropDown::messureSize()
|
||||
wxSize szContent = textSize;
|
||||
szContent.x += 10;
|
||||
if (check_bitmap.bmp().IsOk()) {
|
||||
auto szBmp = check_bitmap.bmp().GetSize();
|
||||
auto szBmp = check_bitmap.GetBmpSize();
|
||||
szContent.x += szBmp.x + 5;
|
||||
}
|
||||
if (iconSize.x > 0) szContent.x += iconSize.x + (text_off ? 0 : 5);
|
||||
@@ -432,7 +442,7 @@ void DropDown::mouseMove(wxMouseEvent &event)
|
||||
|
||||
void DropDown::mouseWheelMoved(wxMouseEvent &event)
|
||||
{
|
||||
auto delta = event.GetWheelRotation() > 0 ? rowSize.y : -rowSize.y;
|
||||
auto delta = event.GetWheelRotation();
|
||||
wxPoint pt2 = offset + wxPoint{0, delta};
|
||||
if (pt2.y > 0)
|
||||
pt2.y = 0;
|
||||
|
||||
@@ -0,0 +1,629 @@
|
||||
#include "FanControl.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "../BitmapCache.hpp"
|
||||
#include "../I18N.hpp"
|
||||
|
||||
#include <wx/simplebook.h>
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
wxDEFINE_EVENT(EVT_FAN_SWITCH_ON, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_FAN_SWITCH_OFF, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_FAN_ADD, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_FAN_DEC, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_FAN_CHANGED, wxCommandEvent);
|
||||
|
||||
/*************************************************
|
||||
Description:Fan
|
||||
**************************************************/
|
||||
Fan::Fan(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
|
||||
{
|
||||
create(parent, id, pos, size);
|
||||
}
|
||||
|
||||
void Fan::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
|
||||
{
|
||||
m_current_speeds = 0;
|
||||
|
||||
wxWindow::Create(parent, id, pos, size, wxBORDER_NONE);
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 2.5, wxPoint(-FromDIP(16), FromDIP(11)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 2.2, wxPoint(-FromDIP(20), FromDIP(11)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 1.7, wxPoint(-FromDIP(24), FromDIP(12)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 1.2, wxPoint(-FromDIP(22), FromDIP(4)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 0.7, wxPoint(-FromDIP(17), -FromDIP(6)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 0.3, wxPoint(-FromDIP(8), -FromDIP(11)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 6.1, wxPoint(-FromDIP(0), -FromDIP(9)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 5.5, wxPoint(-FromDIP(4), -FromDIP(2)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 5.1, wxPoint(-FromDIP(3), FromDIP(5)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 4.6, wxPoint(-FromDIP(3), FromDIP(14)) });
|
||||
m_rotate_offsets.push_back(RotateOffSet{ 4.0, wxPoint(-FromDIP(2), FromDIP(11)) });
|
||||
|
||||
//auto m_bitmap_pointer = ScalableBitmap(this, "fan_pointer", FromDIP(25));
|
||||
//m_img_pointer = m_bitmap_pointer.bmp().ConvertToImage();
|
||||
|
||||
/*m_bitmap_scale_0 = ScalableBitmap(this, "fan_dash_board_level_0", FromDIP(13));
|
||||
m_bitmap_scale_1 = ScalableBitmap(this, "fan_dash_board_level_1", FromDIP(13));
|
||||
m_bitmap_scale_2 = ScalableBitmap(this, "fan_dash_board_level_2", FromDIP(13));
|
||||
m_bitmap_scale_3 = ScalableBitmap(this, "fan_dash_board_level_3", FromDIP(10));
|
||||
m_bitmap_scale_4 = ScalableBitmap(this, "fan_dash_board_level_4", FromDIP(5));
|
||||
m_bitmap_scale_5 = ScalableBitmap(this, "fan_dash_board_level_5", FromDIP(5));
|
||||
m_bitmap_scale_6 = ScalableBitmap(this, "fan_dash_board_level_6", FromDIP(10));
|
||||
m_bitmap_scale_7 = ScalableBitmap(this, "fan_dash_board_level_7", FromDIP(13));
|
||||
m_bitmap_scale_8 = ScalableBitmap(this, "fan_dash_board_level_8", FromDIP(13));
|
||||
m_bitmap_scale_9 = ScalableBitmap(this, "fan_dash_board_level_9", FromDIP(13));*/
|
||||
|
||||
m_bitmap_bk = ScalableBitmap(this, "fan_dash_bk", FromDIP(80));
|
||||
|
||||
for (auto i = 0; i <= 10; i++) {
|
||||
auto a = wxString::Format("fan_scale_%d", i);
|
||||
auto m_bitmap_scale = ScalableBitmap(this, wxString::Format("fan_scale_%d", i).ToStdString(), FromDIP(46));
|
||||
m_bitmap_scales.push_back(m_bitmap_scale);
|
||||
}
|
||||
|
||||
/* m_bitmap_scale_0 = ScalableBitmap(this, "fan_scale_0", FromDIP(60));
|
||||
m_bitmap_scale_1 = ScalableBitmap(this, "fan_scale_1", FromDIP(60));
|
||||
m_bitmap_scale_2 = ScalableBitmap(this, "fan_scale_2", FromDIP(60));
|
||||
m_bitmap_scale_3 = ScalableBitmap(this, "fan_scale_3", FromDIP(60));
|
||||
m_bitmap_scale_4 = ScalableBitmap(this, "fan_scale_4", FromDIP(60));
|
||||
m_bitmap_scale_5 = ScalableBitmap(this, "fan_scale_5", FromDIP(60));
|
||||
m_bitmap_scale_6 = ScalableBitmap(this, "fan_scale_6", FromDIP(60));
|
||||
m_bitmap_scale_7 = ScalableBitmap(this, "fan_scale_7", FromDIP(60));
|
||||
m_bitmap_scale_8 = ScalableBitmap(this, "fan_scale_8", FromDIP(60));
|
||||
m_bitmap_scale_9 = ScalableBitmap(this, "fan_scale_9", FromDIP(60));
|
||||
m_bitmap_scale_10 = ScalableBitmap(this, "fan_scale_10", FromDIP(60));*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
SetMinSize(wxSize(FromDIP(94), FromDIP(81) + FromDIP(6)));
|
||||
SetMaxSize(wxSize(FromDIP(94), FromDIP(81) + FromDIP(6)));
|
||||
#else
|
||||
SetMinSize(wxSize(m_bitmap_bk.GetBmpSize().x, m_bitmap_bk.GetBmpSize().y + FromDIP(6)));
|
||||
SetMaxSize(wxSize(m_bitmap_bk.GetBmpSize().x, m_bitmap_bk.GetBmpSize().y + FromDIP(6)));
|
||||
#endif // __APPLE__
|
||||
|
||||
Bind(wxEVT_PAINT, &Fan::paintEvent, this);
|
||||
}
|
||||
|
||||
void Fan::set_fan_speeds(int g)
|
||||
{
|
||||
m_current_speeds = g;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Fan::post_event(wxCommandEvent &&event)
|
||||
{
|
||||
/*event.SetString(m_info.can_id);
|
||||
event.SetEventObject(m_parent);
|
||||
wxPostEvent(m_parent, event);
|
||||
event.Skip();*/
|
||||
}
|
||||
|
||||
void Fan::paintEvent(wxPaintEvent& evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
render(dc);
|
||||
}
|
||||
|
||||
void Fan::render(wxDC& dc)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxSize size = GetSize();
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(size.x, size.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.Blit({ 0, 0 }, size, &dc, { 0, 0 });
|
||||
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fan::doRender(wxDC& dc)
|
||||
{
|
||||
auto rpm = wxT("rpm");
|
||||
|
||||
wxSize size = GetSize();
|
||||
dc.DrawBitmap(m_bitmap_bk.bmp(), wxPoint(0,0));
|
||||
|
||||
//fan scale
|
||||
/*auto central_point = wxPoint(size.x / 2, size.y / 2 + FromDIP(15));
|
||||
dc.DrawBitmap(m_bitmap_scale_0.bmp(), central_point.x - FromDIP(38), central_point.y);
|
||||
dc.DrawBitmap(m_bitmap_scale_1.bmp(), central_point.x - FromDIP(40), central_point.y - FromDIP(17));
|
||||
dc.DrawBitmap(m_bitmap_scale_2.bmp(), central_point.x - FromDIP(40), central_point.y - FromDIP(36));
|
||||
dc.DrawBitmap(m_bitmap_scale_3.bmp(), central_point.x - FromDIP(32), central_point.y - FromDIP(48));
|
||||
dc.DrawBitmap(m_bitmap_scale_4.bmp(), central_point.x - FromDIP(18), central_point.y - FromDIP(53));
|
||||
dc.DrawBitmap(m_bitmap_scale_5.bmp(), central_point.x - FromDIP(0), central_point.y - FromDIP(53));
|
||||
dc.DrawBitmap(m_bitmap_scale_6.bmp(), central_point.x + FromDIP(18), central_point.y - FromDIP(48));
|
||||
dc.DrawBitmap(m_bitmap_scale_7.bmp(), central_point.x + FromDIP(31), central_point.y - FromDIP(36));
|
||||
dc.DrawBitmap(m_bitmap_scale_8.bmp(), central_point.x + FromDIP(36), central_point.y - FromDIP(17));
|
||||
dc.DrawBitmap(m_bitmap_scale_9.bmp(), central_point.x + FromDIP(28), central_point.y);*/
|
||||
|
||||
//fan pointer
|
||||
//auto pointer_central_point = wxPoint((size.x - m_img_pointer.GetSize().x) / 2, (size.y - m_img_pointer.GetSize().y) / 2);
|
||||
//auto bmp = m_img_pointer.Rotate(m_rotate_offsets[m_current_speeds].rotate, wxPoint(size.x / 2,size.y / 2));
|
||||
auto central_point = wxPoint((size.x - m_bitmap_scales[m_current_speeds].GetBmpSize().x) / 2, (size.y - m_bitmap_scales[m_current_speeds].GetBmpSize().y) / 2 - FromDIP(4));
|
||||
dc.DrawBitmap(m_bitmap_scales[m_current_speeds].bmp(), central_point.x, central_point.y);
|
||||
|
||||
//fan val
|
||||
dc.SetTextForeground(DRAW_TEXT_COLOUR);
|
||||
dc.SetFont(::Label::Head_14);
|
||||
auto speeds = wxString::Format("%d%%", m_current_speeds * 10);
|
||||
dc.DrawText(speeds, (size.x - dc.GetTextExtent(speeds).x) / 2, size.y - dc.GetTextExtent(speeds).y - FromDIP(10));
|
||||
|
||||
//rpm
|
||||
dc.SetFont(::Label::Body_13);
|
||||
dc.DrawText(rpm, (size.x - dc.GetTextExtent(rpm).x) / 2, size.y - dc.GetTextExtent(rpm).y);
|
||||
}
|
||||
|
||||
void Fan::msw_rescale() {
|
||||
m_bitmap_bk.msw_rescale();
|
||||
}
|
||||
|
||||
void Fan::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:FanOperate
|
||||
**************************************************/
|
||||
FanOperate::FanOperate(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
|
||||
{
|
||||
m_current_speeds = 0;
|
||||
m_min_speeds = 1;
|
||||
m_max_speeds = 10;
|
||||
create(parent, id, pos, size);
|
||||
}
|
||||
|
||||
void FanOperate::create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
|
||||
{
|
||||
|
||||
wxWindow::Create(parent, id, pos, size, wxBORDER_NONE);
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
|
||||
m_bitmap_add = ScalableBitmap(this, "fan_control_add", FromDIP(11));
|
||||
m_bitmap_decrease = ScalableBitmap(this, "fan_control_decrease", FromDIP(11));
|
||||
|
||||
SetMinSize(wxSize(FromDIP(SIZE_OF_FAN_OPERATE.x), FromDIP(SIZE_OF_FAN_OPERATE.y)));
|
||||
Bind(wxEVT_PAINT, &FanOperate::paintEvent, this);
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto& e) { SetCursor(wxCURSOR_HAND);});
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) { SetCursor(wxCURSOR_ARROW);});
|
||||
Bind(wxEVT_LEFT_DOWN, &FanOperate::on_left_down, this);
|
||||
}
|
||||
|
||||
void FanOperate::on_left_down(wxMouseEvent& event)
|
||||
{
|
||||
auto mouse_pos = ClientToScreen(event.GetPosition());
|
||||
auto win_pos = ClientToScreen(wxPoint(0, 0));
|
||||
|
||||
auto decrease_fir = GetSize().x / 3 + win_pos.x;
|
||||
auto add_fir = GetSize().x / 3 * 2 + win_pos.x;
|
||||
|
||||
if (mouse_pos.x > win_pos.x && mouse_pos.x < decrease_fir && mouse_pos.y > win_pos.y && mouse_pos.y < (win_pos.y + GetSize().y)) {
|
||||
decrease_fan_speeds();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouse_pos.x > add_fir && mouse_pos.x < (win_pos.x + GetSize().x) && mouse_pos.y > win_pos.y && mouse_pos.y < (win_pos.y + GetSize().y)) {
|
||||
add_fan_speeds();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void FanOperate::set_fan_speeds(int g)
|
||||
{
|
||||
m_current_speeds = g;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void FanOperate::add_fan_speeds()
|
||||
{
|
||||
if (m_current_speeds + 1 > m_max_speeds) return;
|
||||
set_fan_speeds(++m_current_speeds);
|
||||
post_event(wxCommandEvent(EVT_FAN_ADD));
|
||||
post_event(wxCommandEvent(EVT_FAN_SWITCH_ON));
|
||||
}
|
||||
|
||||
void FanOperate::decrease_fan_speeds()
|
||||
{
|
||||
//turn off
|
||||
if (m_current_speeds - 1 < m_min_speeds) {
|
||||
m_current_speeds = 0;
|
||||
set_fan_speeds(m_current_speeds);
|
||||
post_event(wxCommandEvent(EVT_FAN_SWITCH_OFF));
|
||||
}
|
||||
else {
|
||||
set_fan_speeds(--m_current_speeds);
|
||||
}
|
||||
post_event(wxCommandEvent(EVT_FAN_DEC));
|
||||
|
||||
}
|
||||
|
||||
void FanOperate::post_event(wxCommandEvent &&event)
|
||||
{
|
||||
event.SetInt(m_current_speeds);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void FanOperate::paintEvent(wxPaintEvent& evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
render(dc);
|
||||
}
|
||||
|
||||
void FanOperate::render(wxDC& dc)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxSize size = GetSize();
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(size.x, size.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.Blit({ 0, 0 }, size, &dc, { 0, 0 });
|
||||
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FanOperate::doRender(wxDC& dc)
|
||||
{
|
||||
wxSize size = GetSize();
|
||||
dc.SetPen(wxPen(DRAW_OPERATE_LINE_COLOUR));
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.DrawRoundedRectangle(0,0,size.x,size.y,5);
|
||||
|
||||
//splt
|
||||
auto left_fir = size.x / 3;
|
||||
|
||||
dc.DrawLine(left_fir, FromDIP(4), left_fir, size.y - FromDIP(4));
|
||||
dc.DrawLine(left_fir * 2, FromDIP(4), left_fir * 2, size.y - FromDIP(4));
|
||||
|
||||
dc.DrawBitmap(m_bitmap_decrease.bmp(), (left_fir - m_bitmap_decrease.GetBmpSize().x) / 2, (size.y - m_bitmap_decrease.GetBmpSize().y) / 2);
|
||||
dc.DrawBitmap(m_bitmap_add.bmp(), (left_fir * 2 + (left_fir - m_bitmap_decrease.GetBmpSize().x) / 2), (size.y - m_bitmap_add.GetBmpSize().y) / 2);
|
||||
|
||||
//txt
|
||||
dc.SetFont(::Label::Body_12);
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor(wxColour(0x898989)));
|
||||
wxString text = wxString::Format("%d%%", m_current_speeds * 10);
|
||||
wxSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, wxPoint(left_fir + (left_fir- text_size.x) / 2, (size.y- text_size.y) / 2 + 2));
|
||||
}
|
||||
|
||||
void FanOperate::msw_rescale() {
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
Description:FanControl
|
||||
**************************************************/
|
||||
FanControl::FanControl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
|
||||
:wxWindow(parent, id, pos, size)
|
||||
{
|
||||
auto m_bitmap_fan = new ScalableBitmap(this, "fan_icon", 18);
|
||||
m_bitmap_toggle_off = new ScalableBitmap(this, "toggle_off", 14);
|
||||
m_bitmap_toggle_on = new ScalableBitmap(this, "toggle_on", 14);
|
||||
|
||||
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
|
||||
wxBoxSizer* m_sizer_main = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
m_fan = new Fan(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
m_sizer_main->Add(m_fan, 1, wxEXPAND | wxALL, 0);
|
||||
|
||||
|
||||
m_sizer_main->Add(0, 0, 0, wxLEFT, FromDIP(18));
|
||||
|
||||
wxBoxSizer* sizer_control = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer* sizer_control_top = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
|
||||
auto m_static_bitmap_fan = new wxStaticBitmap(this, wxID_ANY, m_bitmap_fan->bmp(), wxDefaultPosition, wxDefaultSize);
|
||||
|
||||
|
||||
m_static_name = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END|wxALIGN_CENTER_HORIZONTAL);
|
||||
m_static_name->SetForegroundColour(wxColour(DRAW_TEXT_COLOUR));
|
||||
m_static_name->SetBackgroundColour(*wxWHITE);
|
||||
m_static_name->SetMinSize(wxSize(FromDIP(50), -1));
|
||||
m_static_name->SetMaxSize(wxSize(FromDIP(50), -1));
|
||||
|
||||
|
||||
m_switch_button = new wxStaticBitmap(this, wxID_ANY, m_bitmap_toggle_off->bmp(), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_switch_button->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) { SetCursor(wxCURSOR_HAND); });
|
||||
m_switch_button->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) { SetCursor(wxCURSOR_RIGHT_ARROW); });
|
||||
m_switch_button->Bind(wxEVT_LEFT_DOWN, &FanControl::on_swith_fan, this);
|
||||
|
||||
|
||||
sizer_control_top->Add(m_static_bitmap_fan, 0, wxALIGN_CENTER, 5);
|
||||
sizer_control_top->Add(m_static_name, 0, wxALIGN_CENTER, 0);
|
||||
sizer_control_top->Add( 0, 0, 1, wxEXPAND, 0 );
|
||||
sizer_control_top->Add(m_switch_button, 0, wxALIGN_CENTER, 0);
|
||||
|
||||
|
||||
sizer_control->Add(sizer_control_top, 0, wxALIGN_CENTER, 0);
|
||||
sizer_control->Add(0, 0, 0, wxTOP, FromDIP(15));
|
||||
|
||||
m_fan_operate = new FanOperate(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
sizer_control->Add(m_fan_operate, 0, wxALIGN_CENTER, 0);
|
||||
|
||||
|
||||
m_sizer_main->Add(sizer_control, 0, wxALIGN_CENTER, 0);
|
||||
|
||||
|
||||
this->SetSizer(m_sizer_main);
|
||||
this->Layout();
|
||||
m_sizer_main->Fit(this);
|
||||
|
||||
m_fan_operate->Bind(EVT_FAN_SWITCH_ON, [this](wxCommandEvent& e) {
|
||||
m_current_speed = e.GetInt();
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_on->bmp());
|
||||
m_switch_fan = true;
|
||||
m_fan->set_fan_speeds(m_current_speed);
|
||||
});
|
||||
m_fan_operate->Bind(EVT_FAN_SWITCH_OFF, [this](wxCommandEvent& e) {
|
||||
m_current_speed = e.GetInt();
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_off->bmp());
|
||||
m_switch_fan = false;
|
||||
m_fan->set_fan_speeds(m_current_speed);
|
||||
});
|
||||
|
||||
m_fan_operate->Bind(EVT_FAN_ADD, [this](wxCommandEvent& e) {
|
||||
m_current_speed = e.GetInt();
|
||||
m_fan->set_fan_speeds(m_current_speed);
|
||||
command_control_fan();
|
||||
});
|
||||
|
||||
m_fan_operate->Bind(EVT_FAN_DEC, [this](wxCommandEvent& e) {
|
||||
m_current_speed = e.GetInt();
|
||||
m_fan->set_fan_speeds(m_current_speed);
|
||||
command_control_fan();
|
||||
});
|
||||
}
|
||||
|
||||
void FanControl::on_left_down(wxMouseEvent& evt)
|
||||
{
|
||||
auto mouse_pos = ClientToScreen(evt.GetPosition());
|
||||
auto tag_pos = m_fan_operate->ScreenToClient(mouse_pos);
|
||||
evt.SetPosition(tag_pos);
|
||||
m_fan_operate->on_left_down(evt);
|
||||
}
|
||||
|
||||
void FanControl::command_control_fan()
|
||||
{
|
||||
if (m_current_speed < 0 || m_current_speed > 10) { return; }
|
||||
int speed = floor(m_current_speed * float(25.5));
|
||||
m_obj->command_control_fan_val(m_type, speed);
|
||||
post_event(wxCommandEvent(EVT_FAN_CHANGED));
|
||||
}
|
||||
|
||||
void FanControl::on_swith_fan(wxMouseEvent& evt)
|
||||
{
|
||||
int speed = 0;
|
||||
if (m_switch_fan) {
|
||||
speed = 0;
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_off->bmp());
|
||||
m_switch_fan = false;
|
||||
}
|
||||
else {
|
||||
speed = 255;
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_on->bmp());
|
||||
m_switch_fan = true;
|
||||
}
|
||||
|
||||
set_fan_speed(speed);
|
||||
command_control_fan();
|
||||
}
|
||||
|
||||
void FanControl::on_swith_fan(bool on)
|
||||
{
|
||||
m_switch_fan = on;
|
||||
if (m_switch_fan) {
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_on->bmp());
|
||||
}
|
||||
else {
|
||||
m_switch_button->SetBitmap(m_bitmap_toggle_off->bmp());
|
||||
}
|
||||
}
|
||||
|
||||
void FanControl::set_machine_obj(MachineObject* obj)
|
||||
{
|
||||
m_obj = obj;
|
||||
}
|
||||
|
||||
void FanControl::set_type(MachineObject::FanType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
void FanControl::set_name(wxString name)
|
||||
{
|
||||
m_static_name->SetLabelText(name);
|
||||
}
|
||||
|
||||
void FanControl::set_fan_speed(int g)
|
||||
{
|
||||
if (g < 0 || g > 255) return;
|
||||
int speed = round(float(g) / float(25.5));
|
||||
|
||||
if (m_current_speed != speed) {
|
||||
m_current_speed = speed;
|
||||
m_fan->set_fan_speeds(speed);
|
||||
m_fan_operate->set_fan_speeds(m_current_speed);
|
||||
|
||||
if (m_current_speed <= 0) {
|
||||
on_swith_fan(false);
|
||||
}
|
||||
else {
|
||||
on_swith_fan(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FanControl::set_fan_switch(bool s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FanControl::post_event(wxCommandEvent&& event)
|
||||
{
|
||||
event.SetInt(m_type);
|
||||
event.SetString(wxString::Format("%d", m_current_speed));
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:FanControlPopup
|
||||
**************************************************/
|
||||
FanControlPopup::FanControlPopup(wxWindow* parent)
|
||||
:wxPopupTransientWindow(parent, wxBORDER_NONE)
|
||||
{
|
||||
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
|
||||
|
||||
m_sizer_main = new wxBoxSizer(wxVERTICAL);
|
||||
m_part_fan = new FanControl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
m_part_fan->set_type(MachineObject::FanType::COOLING_FAN);
|
||||
m_part_fan->set_name(_L("Part"));
|
||||
|
||||
m_aux_fan = new FanControl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
m_aux_fan->set_type(MachineObject::FanType::BIG_COOLING_FAN);
|
||||
m_aux_fan->set_name(_L("Aux"));
|
||||
|
||||
m_cham_fan = new FanControl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
m_cham_fan->set_type(MachineObject::FanType::CHAMBER_FAN);
|
||||
m_cham_fan->set_name(_L("Cham"));
|
||||
|
||||
m_line_top = new wxWindow(this, wxID_ANY);
|
||||
m_line_top->SetSize(wxSize(-1, 1));
|
||||
m_line_top->SetBackgroundColour(0xF1F1F1);
|
||||
|
||||
m_line_bottom = new wxWindow(this, wxID_ANY);
|
||||
m_line_bottom->SetSize(wxSize(-1, 1));
|
||||
m_line_bottom->SetBackgroundColour(0xF1F1F1);
|
||||
|
||||
|
||||
m_sizer_main->Add(m_part_fan, 0, wxALL, FromDIP(14));
|
||||
m_sizer_main->Add(m_line_top, 0, wxEXPAND|wxLEFT|wxRIGHT, FromDIP(8));
|
||||
m_sizer_main->Add(m_aux_fan, 0, wxALL, FromDIP(14));
|
||||
m_sizer_main->Add(m_line_bottom, 0, wxEXPAND|wxLEFT|wxRIGHT, FromDIP(8));
|
||||
m_sizer_main->Add(m_cham_fan, 0, wxALL, FromDIP(14));
|
||||
|
||||
|
||||
this->SetSizer(m_sizer_main);
|
||||
this->Layout();
|
||||
m_sizer_main->Fit(this);
|
||||
|
||||
this->Centre(wxBOTH);
|
||||
Bind(wxEVT_PAINT, &FanControlPopup::paintEvent, this);
|
||||
|
||||
#if __APPLE__
|
||||
Bind(wxEVT_LEFT_DOWN, &FanControlPopup::on_left_down, this);
|
||||
#endif
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
}
|
||||
|
||||
void FanControlPopup::update_fan_data(MachineObject::FanType type, MachineObject* obj)
|
||||
{
|
||||
bool is_suppt_cham_fun = obj->is_function_supported(PrinterFunction::FUNC_CHAMBER_FAN);
|
||||
if (is_suppt_cham_fun) {
|
||||
m_cham_fan->Show();
|
||||
m_line_bottom->Show();
|
||||
}
|
||||
else {
|
||||
m_cham_fan->Hide();
|
||||
m_line_bottom->Hide();
|
||||
}
|
||||
|
||||
if (type == MachineObject::FanType::COOLING_FAN && obj->cooling_fan_speed >= 0) {
|
||||
m_part_fan->set_fan_speed(obj->cooling_fan_speed);
|
||||
}
|
||||
|
||||
if (type == MachineObject::FanType::BIG_COOLING_FAN && obj->big_fan1_speed >= 0) {
|
||||
m_aux_fan->set_fan_speed(obj->big_fan1_speed);
|
||||
}
|
||||
|
||||
if (type == MachineObject::FanType::CHAMBER_FAN && obj->big_fan2_speed >= 0) {
|
||||
m_cham_fan->set_fan_speed(obj->big_fan2_speed);
|
||||
}
|
||||
|
||||
m_part_fan->set_machine_obj(obj);
|
||||
m_aux_fan->set_machine_obj(obj);
|
||||
m_cham_fan->set_machine_obj(obj);
|
||||
|
||||
Bind(EVT_FAN_CHANGED, [this](wxCommandEvent& e) {
|
||||
post_event(e.GetInt(), e.GetString());
|
||||
});
|
||||
|
||||
Layout();
|
||||
Fit();
|
||||
}
|
||||
|
||||
void FanControlPopup::on_left_down(wxMouseEvent& evt)
|
||||
{
|
||||
auto mouse_pos = ClientToScreen(evt.GetPosition());
|
||||
|
||||
auto part_tag_pos = m_part_fan->ScreenToClient(mouse_pos);
|
||||
evt.SetPosition(part_tag_pos);
|
||||
m_part_fan->on_left_down(evt);
|
||||
|
||||
auto aux_tag_pos = m_aux_fan->ScreenToClient(mouse_pos);
|
||||
evt.SetPosition(aux_tag_pos);
|
||||
m_aux_fan->on_left_down(evt);
|
||||
|
||||
auto cham_tag_pos = m_cham_fan->ScreenToClient(mouse_pos);
|
||||
evt.SetPosition(cham_tag_pos);
|
||||
m_cham_fan->on_left_down(evt);
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void FanControlPopup::OnDismiss()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FanControlPopup::post_event(int fan_type, wxString speed)
|
||||
{
|
||||
wxCommandEvent event(EVT_FAN_CHANGED);
|
||||
event.SetInt(fan_type);
|
||||
event.SetString(speed);
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
bool FanControlPopup::ProcessLeftDown(wxMouseEvent& event)
|
||||
{
|
||||
return wxPopupTransientWindow::ProcessLeftDown(event);
|
||||
}
|
||||
|
||||
void FanControlPopup::paintEvent(wxPaintEvent& evt)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
dc.SetPen(wxColour(0xAC, 0xAC, 0xAC));
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 0);
|
||||
}
|
||||
}} // namespace Slic3r::GUI
|
||||
@@ -0,0 +1,171 @@
|
||||
#ifndef slic3r_GUI_FANCONTROL_hpp_
|
||||
#define slic3r_GUI_FANCONTROL_hpp_
|
||||
|
||||
#include "../wxExtensions.hpp"
|
||||
#include "StaticBox.hpp"
|
||||
#include "StepCtrl.hpp"
|
||||
#include "Button.hpp"
|
||||
#include "../DeviceManager.hpp"
|
||||
#include "slic3r/GUI/Event.hpp"
|
||||
#include <wx/simplebook.h>
|
||||
#include <wx/hyperlink.h>
|
||||
#include <wx/animate.h>
|
||||
#include <wx/dynarray.h>
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:Fan
|
||||
**************************************************/
|
||||
#define SIZE_OF_FAN_OPERATE wxSize(100, 28)
|
||||
|
||||
#define DRAW_TEXT_COLOUR wxColour(0x898989)
|
||||
#define DRAW_OPERATE_LINE_COLOUR wxColour(0xDEDEDE)
|
||||
|
||||
struct RotateOffSet
|
||||
{
|
||||
float rotate;
|
||||
wxPoint offset;
|
||||
};
|
||||
|
||||
class Fan : public wxWindow
|
||||
{
|
||||
public:
|
||||
Fan(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
|
||||
~Fan() {};
|
||||
void post_event(wxCommandEvent&& event);
|
||||
void paintEvent(wxPaintEvent& evt);
|
||||
void render(wxDC& dc);
|
||||
void doRender(wxDC& dc);
|
||||
void msw_rescale();
|
||||
void create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size);
|
||||
void set_fan_speeds(int g);
|
||||
|
||||
private:
|
||||
int m_current_speeds;
|
||||
std::vector<RotateOffSet> m_rotate_offsets;
|
||||
|
||||
protected:
|
||||
std::vector<wxPoint> m_scale_pos_array;
|
||||
|
||||
ScalableBitmap m_bitmap_bk;
|
||||
ScalableBitmap m_bitmap_scale_0;
|
||||
ScalableBitmap m_bitmap_scale_1;
|
||||
ScalableBitmap m_bitmap_scale_2;
|
||||
ScalableBitmap m_bitmap_scale_3;
|
||||
ScalableBitmap m_bitmap_scale_4;
|
||||
ScalableBitmap m_bitmap_scale_5;
|
||||
ScalableBitmap m_bitmap_scale_6;
|
||||
ScalableBitmap m_bitmap_scale_7;
|
||||
ScalableBitmap m_bitmap_scale_8;
|
||||
ScalableBitmap m_bitmap_scale_9;
|
||||
ScalableBitmap m_bitmap_scale_10;
|
||||
|
||||
std::vector<ScalableBitmap> m_bitmap_scales;
|
||||
|
||||
wxImage m_img_pointer;
|
||||
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
};
|
||||
|
||||
/*************************************************
|
||||
Description:FanOperate
|
||||
**************************************************/
|
||||
class FanOperate : public wxWindow
|
||||
{
|
||||
public:
|
||||
FanOperate(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
|
||||
~FanOperate() {};
|
||||
void post_event(wxCommandEvent&& event);
|
||||
void paintEvent(wxPaintEvent& evt);
|
||||
void render(wxDC& dc);
|
||||
void doRender(wxDC& dc);
|
||||
void msw_rescale();
|
||||
void create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size);
|
||||
void on_left_down(wxMouseEvent& event);
|
||||
|
||||
public:
|
||||
void set_fan_speeds(int g);
|
||||
void add_fan_speeds();
|
||||
void decrease_fan_speeds();
|
||||
private:
|
||||
int m_current_speeds;
|
||||
int m_min_speeds;
|
||||
int m_max_speeds;
|
||||
ScalableBitmap m_bitmap_add;
|
||||
ScalableBitmap m_bitmap_decrease;
|
||||
};
|
||||
|
||||
/*************************************************
|
||||
Description:FanControl
|
||||
**************************************************/
|
||||
class FanControl : public wxWindow
|
||||
{
|
||||
public:
|
||||
FanControl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
|
||||
~FanControl() {};
|
||||
|
||||
protected:
|
||||
MachineObject::FanType m_type;
|
||||
MachineObject* m_obj;
|
||||
wxStaticText* m_static_name{ nullptr };
|
||||
wxStaticBitmap* m_switch_button{ nullptr };
|
||||
ScalableBitmap* m_bitmap_toggle_off{ nullptr };
|
||||
ScalableBitmap* m_bitmap_toggle_on{ nullptr };
|
||||
|
||||
Fan* m_fan{ nullptr };
|
||||
FanOperate* m_fan_operate{ nullptr };
|
||||
bool m_switch_fan{ false };
|
||||
int m_current_speed{0};
|
||||
public:
|
||||
void command_control_fan();
|
||||
void set_machine_obj(MachineObject* obj);
|
||||
void set_type(MachineObject::FanType type);
|
||||
void set_name(wxString name);
|
||||
void set_fan_speed(int g);
|
||||
void set_fan_switch(bool s);
|
||||
void post_event(wxCommandEvent&& event);
|
||||
void on_swith_fan(wxMouseEvent& evt);
|
||||
void on_swith_fan(bool on);
|
||||
void on_left_down(wxMouseEvent& event);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:FanControlPopup
|
||||
**************************************************/
|
||||
class FanControlPopup : public wxPopupTransientWindow
|
||||
{
|
||||
public:
|
||||
FanControlPopup(wxWindow* parent);
|
||||
~FanControlPopup() {};
|
||||
|
||||
private:
|
||||
wxBoxSizer* m_sizer_main;
|
||||
FanControl* m_part_fan;
|
||||
FanControl* m_aux_fan;
|
||||
FanControl* m_cham_fan;
|
||||
wxWindow* m_line_top;
|
||||
wxWindow* m_line_bottom;
|
||||
|
||||
public:
|
||||
void update_fan_data(MachineObject::FanType type, MachineObject* obj);
|
||||
void on_left_down(wxMouseEvent& evt);
|
||||
void paintEvent(wxPaintEvent& evt);
|
||||
void post_event(int fan_type, wxString speed);
|
||||
virtual void OnDismiss() wxOVERRIDE;
|
||||
virtual bool ProcessLeftDown(wxMouseEvent& event) wxOVERRIDE;
|
||||
};
|
||||
|
||||
wxDECLARE_EVENT(EVT_FAN_SWITCH_ON, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_FAN_SWITCH_OFF, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_FAN_ADD, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_FAN_DEC, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_FAN_CHANGED, wxCommandEvent);
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
@@ -50,4 +50,46 @@ private:
|
||||
StateColor text_color;
|
||||
};
|
||||
|
||||
class FanSwitchButton : public StaticBox
|
||||
{
|
||||
public:
|
||||
FanSwitchButton(wxWindow* parent, ScalableBitmap& img_on, ScalableBitmap& img_off, long style = 0);
|
||||
void SetLabels(wxString const& lbl_on, wxString const& lbl_off);
|
||||
void SetImages(ScalableBitmap& img_on, ScalableBitmap& img_off);
|
||||
void SetTextColor(StateColor const& color);
|
||||
void SetValue(bool value);
|
||||
void SetPadding(int padding);
|
||||
|
||||
bool GetValue() { return m_on_off; }
|
||||
void Rescale();
|
||||
void setFanValue(int val);
|
||||
|
||||
private:
|
||||
void messureSize();
|
||||
void paintEvent(wxPaintEvent& evt);
|
||||
void render(wxDC& dc);
|
||||
void mouseDown(wxMouseEvent& event);
|
||||
void mouseReleased(wxMouseEvent& event);
|
||||
void mouseEnterWindow(wxMouseEvent& event);
|
||||
void mouseLeaveWindow(wxMouseEvent& event);
|
||||
void sendButtonEvent();
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
ScalableBitmap m_on;
|
||||
ScalableBitmap m_off;
|
||||
bool m_on_off;
|
||||
int m_padding; // size between icon and text
|
||||
bool pressedDown = false;
|
||||
bool hover = false;
|
||||
|
||||
wxSize textSize;
|
||||
wxSize minSize;
|
||||
int m_speed;
|
||||
|
||||
wxString labels[2];
|
||||
StateColor text_color;
|
||||
};
|
||||
|
||||
#endif // !slic3r_GUI_SwitchButton_hpp_
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "StaticBox.hpp"
|
||||
|
||||
@@ -41,6 +42,18 @@ wxFont Label::Body_9;
|
||||
|
||||
void Label::initSysFont()
|
||||
{
|
||||
#ifdef __linux__
|
||||
const std::string& resource_path = Slic3r::resources_dir();
|
||||
wxString font_path = wxString::FromUTF8(resource_path+"/fonts/HarmonyOS_Sans_SC_Bold.ttf");
|
||||
bool result = wxFont::AddPrivateFont(font_path);
|
||||
//BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Bold returns %1%")%result;
|
||||
printf("add font of HarmonyOS_Sans_SC_Bold returns %d\n", result);
|
||||
font_path = wxString::FromUTF8(resource_path+"/fonts/HarmonyOS_Sans_SC_Regular.ttf");
|
||||
result = wxFont::AddPrivateFont(font_path);
|
||||
//BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Regular returns %1%")%result;
|
||||
printf("add font of HarmonyOS_Sans_SC_Regular returns %d\n", result);
|
||||
#endif
|
||||
|
||||
Head_24 = Label::sysFont(24, true);
|
||||
Head_20 = Label::sysFont(20, true);
|
||||
Head_18 = Label::sysFont(18, true);
|
||||
@@ -61,6 +74,124 @@ void Label::initSysFont()
|
||||
Body_9 = Label::sysFont(9, false);
|
||||
}
|
||||
|
||||
class WXDLLIMPEXP_CORE wxTextWrapper2
|
||||
{
|
||||
public:
|
||||
wxTextWrapper2() { m_eol = false; }
|
||||
|
||||
// win is used for getting the font, text is the text to wrap, width is the
|
||||
// max line width or -1 to disable wrapping
|
||||
void Wrap(wxWindow *win, const wxString &text, int widthMax)
|
||||
{
|
||||
const wxClientDC dc(win);
|
||||
|
||||
const wxArrayString ls = wxSplit(text, '\n', '\0');
|
||||
for (wxArrayString::const_iterator i = ls.begin(); i != ls.end(); ++i) {
|
||||
wxString line = *i;
|
||||
|
||||
if (i != ls.begin()) {
|
||||
// Do this even if the line is empty, except if it's the first one.
|
||||
OnNewLine();
|
||||
}
|
||||
|
||||
// Is this a special case when wrapping is disabled?
|
||||
if (widthMax < 0) {
|
||||
DoOutputLine(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (bool newLine = false; !line.empty(); newLine = true) {
|
||||
if (newLine) OnNewLine();
|
||||
|
||||
wxArrayInt widths;
|
||||
dc.GetPartialTextExtents(line, widths);
|
||||
|
||||
const size_t posEnd = std::lower_bound(widths.begin(), widths.end(), widthMax) - widths.begin();
|
||||
|
||||
// Does the entire remaining line fit?
|
||||
if (posEnd == line.length()) {
|
||||
DoOutputLine(line);
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the last word to chop off.
|
||||
size_t lastSpace = posEnd;
|
||||
while (lastSpace != size_t(-1)) {
|
||||
auto c = line[lastSpace];
|
||||
if (c == ' ' || c > 0x4E00)
|
||||
break;
|
||||
--lastSpace;
|
||||
}
|
||||
if (lastSpace == size_t(-1)) {
|
||||
// No spaces, so can't wrap.
|
||||
DoOutputLine(line);
|
||||
break;
|
||||
}
|
||||
|
||||
// Output the part that fits.
|
||||
DoOutputLine(line.substr(0, lastSpace));
|
||||
|
||||
// And redo the layout with the rest.
|
||||
if (line[lastSpace] == ' ') ++lastSpace;
|
||||
line = line.substr(lastSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we don't need it, but just to avoid compiler warnings
|
||||
virtual ~wxTextWrapper2() {}
|
||||
|
||||
protected:
|
||||
// line may be empty
|
||||
virtual void OnOutputLine(const wxString &line) = 0;
|
||||
|
||||
// called at the start of every new line (except the very first one)
|
||||
virtual void OnNewLine() {}
|
||||
|
||||
private:
|
||||
// call OnOutputLine() and set m_eol to true
|
||||
void DoOutputLine(const wxString &line)
|
||||
{
|
||||
OnOutputLine(line);
|
||||
|
||||
m_eol = true;
|
||||
}
|
||||
|
||||
// this function is a destructive inspector: when it returns true it also
|
||||
// resets the flag to false so calling it again wouldn't return true any
|
||||
// more
|
||||
bool IsStartOfNewLine()
|
||||
{
|
||||
if (!m_eol) return false;
|
||||
|
||||
m_eol = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool m_eol;
|
||||
};
|
||||
|
||||
class wxLabelWrapper2 : public wxTextWrapper2
|
||||
{
|
||||
public:
|
||||
void WrapLabel(wxWindow *text, int widthMax)
|
||||
{
|
||||
m_text.clear();
|
||||
Wrap(text, text->GetLabel(), widthMax);
|
||||
text->SetLabel(m_text);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void OnOutputLine(const wxString &line) wxOVERRIDE { m_text += line; }
|
||||
|
||||
virtual void OnNewLine() wxOVERRIDE { m_text += wxT('\n'); }
|
||||
|
||||
private:
|
||||
wxString m_text;
|
||||
};
|
||||
|
||||
|
||||
wxSize Label::split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text)
|
||||
{
|
||||
multiline_text = text;
|
||||
@@ -95,16 +226,24 @@ Label::Label(wxWindow *parent, wxFont const &font, wxString const &text, long st
|
||||
this->font = font;
|
||||
SetFont(font);
|
||||
SetBackgroundColour(StaticBox::GetParentBackgroundColor(parent));
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto &e) {
|
||||
if (GetWindowStyle() & LB_HYPERLINK) {
|
||||
SetFont(this->font.Underlined());
|
||||
Refresh();
|
||||
}
|
||||
});
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) {
|
||||
SetFont(this->font);
|
||||
Refresh();
|
||||
});
|
||||
if (style & LB_PROPAGATE_MOUSE_EVENT) {
|
||||
for (auto evt : {
|
||||
wxEVT_LEFT_UP, wxEVT_LEFT_DOWN})
|
||||
Bind(evt, [this] (auto & e) { GetParent()->GetEventHandler()->ProcessEventLocally(e); });
|
||||
};
|
||||
}
|
||||
|
||||
void Label::SetLabel(const wxString& label)
|
||||
{
|
||||
if (GetLabel() == label)
|
||||
return;
|
||||
wxStaticText::SetLabel(label);
|
||||
#ifdef __WXOSX__
|
||||
if ((GetWindowStyle() & LB_HYPERLINK)) {
|
||||
SetLabelMarkup(label);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Label::SetWindowStyleFlag(long style)
|
||||
@@ -115,10 +254,27 @@ void Label::SetWindowStyleFlag(long style)
|
||||
if (style & LB_HYPERLINK) {
|
||||
this->color = GetForegroundColour();
|
||||
static wxColor clr_url("#00AE42");
|
||||
SetFont(this->font.Underlined());
|
||||
SetForegroundColour(clr_url);
|
||||
SetCursor(wxCURSOR_HAND);
|
||||
#ifdef __WXOSX__
|
||||
SetLabelMarkup(GetLabel());
|
||||
#endif
|
||||
} else {
|
||||
SetForegroundColour(this->color);
|
||||
SetFont(this->font);
|
||||
SetCursor(wxCURSOR_ARROW);
|
||||
#ifdef __WXOSX__
|
||||
auto label = GetLabel();
|
||||
wxStaticText::SetLabel({});
|
||||
wxStaticText::SetLabel(label);
|
||||
#endif
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Label::Wrap(int width)
|
||||
{
|
||||
wxLabelWrapper2 wrapper;
|
||||
wrapper.WrapLabel(this, width);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include <wx/stattext.h>
|
||||
|
||||
#define LB_HYPERLINK 0x0001
|
||||
#define LB_HYPERLINK 0x0020
|
||||
#define LB_PROPAGATE_MOUSE_EVENT 0x0040
|
||||
|
||||
|
||||
class Label : public wxStaticText
|
||||
@@ -13,8 +14,12 @@ public:
|
||||
|
||||
Label(wxWindow *parent, wxFont const &font, wxString const &text = {}, long style = 0);
|
||||
|
||||
void SetLabel(const wxString& label) override;
|
||||
|
||||
void SetWindowStyleFlag(long style) override;
|
||||
|
||||
void Wrap(int width);
|
||||
|
||||
private:
|
||||
wxFont font;
|
||||
wxColour color;
|
||||
|
||||
@@ -111,10 +111,21 @@ wxString ProgressDialog::FormatString(wxString title)
|
||||
}
|
||||
} else {
|
||||
m_msg->SetLabel(title);
|
||||
Layout();
|
||||
m_msg->SetMaxSize(wxSize(PROGRESSDIALOG_SIMPLEBOOK_SIZE.x + 5, -1));
|
||||
m_msg->SetMinSize(wxSize(PROGRESSDIALOG_SIMPLEBOOK_SIZE.x + 5, -1));
|
||||
m_msg->Wrap(PROGRESSDIALOG_SIMPLEBOOK_SIZE.x + 5);
|
||||
m_msg->Layout();
|
||||
m_msg->Fit();
|
||||
|
||||
m_msg_scrolledWindow->SetSize(wxSize(FromDIP(m_msg->GetSize().x + 5), FromDIP(150)));
|
||||
m_msg_scrolledWindow->SetMinSize(wxSize(FromDIP(m_msg->GetSize().x + 5), FromDIP(150)));
|
||||
m_msg_scrolledWindow->SetMaxSize(wxSize(FromDIP(m_msg->GetSize().x + 5), FromDIP(150)));
|
||||
// m_msg_scrolledWindow->Layout();
|
||||
m_msg_scrolledWindow->Fit();
|
||||
}
|
||||
|
||||
|
||||
Fit();
|
||||
//Fit();
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -185,9 +196,8 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
|
||||
|
||||
m_sizer_main->Add(m_simplebook, 1, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(28));
|
||||
} else {
|
||||
wxScrolledWindow* m_msg_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
|
||||
m_msg_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
|
||||
m_msg_scrolledWindow->SetScrollRate(0,5);
|
||||
m_msg_scrolledWindow->SetMinSize(wxSize(FromDIP(80), FromDIP(300)));
|
||||
wxBoxSizer* m_msg_sizer= new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
m_msg = new wxStaticText(m_msg_scrolledWindow, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(PROGRESSDIALOG_SIMPLEBOOK_SIZE.x, -1), 0);
|
||||
@@ -195,7 +205,7 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
|
||||
m_msg->SetFont(::Label::Body_13);
|
||||
m_msg->SetForegroundColour(PROGRESSDIALOG_GREY_700);
|
||||
|
||||
m_msg_sizer->Add( m_msg, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(5) );
|
||||
m_msg_sizer->Add(m_msg, 0, wxEXPAND | wxALL, 0);
|
||||
m_msg_scrolledWindow->SetSizer(m_msg_sizer);
|
||||
m_msg_scrolledWindow->Layout();
|
||||
m_msg_sizer->Fit(m_msg_scrolledWindow);
|
||||
@@ -218,10 +228,10 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
|
||||
m_sizer_main->Add(m_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(28));
|
||||
|
||||
#ifdef __WXMSW__
|
||||
m_block_left = new wxWindow(m_gauge, wxID_ANY, wxPoint(0, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
||||
m_block_left->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
||||
m_block_right = new wxWindow(m_gauge, wxID_ANY, wxPoint(PROGRESSDIALOG_GAUGE_SIZE.x - 2, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
||||
m_block_right->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
||||
//m_block_left = new wxWindow(m_gauge, wxID_ANY, wxPoint(0, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
||||
//m_block_left->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
||||
//m_block_right = new wxWindow(m_gauge, wxID_ANY, wxPoint(PROGRESSDIALOG_GAUGE_SIZE.x - 2, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
||||
//m_block_right->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
||||
#endif
|
||||
wxBoxSizer *m_sizer_bottom = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
@@ -250,6 +260,8 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
|
||||
m_sizer_main->Add(m_sizer_bottom, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(28));
|
||||
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(10));
|
||||
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
|
||||
SetSizer(m_sizer_main);
|
||||
Layout();
|
||||
Fit();
|
||||
@@ -778,10 +790,10 @@ void ProgressDialog::DoSetSize(int x, int y, int width, int height, int sizeFlag
|
||||
if (m_button_cancel != nullptr) { m_button_cancel->SetMinSize(PROGRESSDIALOG_CANCEL_BUTTON_SIZE); }
|
||||
|
||||
#ifdef __WXMSW__
|
||||
if (m_block_left != nullptr && m_block_right != nullptr) {
|
||||
m_block_left->SetPosition(wxPoint(0, 0));
|
||||
m_block_right->SetPosition(wxPoint(PROGRESSDIALOG_GAUGE_SIZE.x - 2, 0));
|
||||
}
|
||||
//if (m_block_left != nullptr && m_block_right != nullptr) {
|
||||
// m_block_left->SetPosition(wxPoint(0, 0));
|
||||
// m_block_right->SetPosition(wxPoint(PROGRESSDIALOG_GAUGE_SIZE.x - 2, 0));
|
||||
//}
|
||||
#endif
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
}
|
||||
|
||||
@@ -67,15 +67,16 @@ public:
|
||||
|
||||
int m_mode = 0; // 0 is 1line mode 1 is 2line mode
|
||||
|
||||
bool m_adaptive = {false};
|
||||
wxSizer * m_sizer_main = {nullptr};
|
||||
wxPanel * m_top_line= {nullptr};
|
||||
wxSimplebook * m_simplebook= {nullptr};
|
||||
wxPanel * m_panel_2line= {nullptr};
|
||||
wxPanel * m_panel_1line= {nullptr};
|
||||
Button* m_button_cancel = {nullptr};
|
||||
wxWindow * m_block_left = {nullptr};
|
||||
wxWindow * m_block_right = {nullptr};
|
||||
bool m_adaptive = {false};
|
||||
wxSizer * m_sizer_main = {nullptr};
|
||||
wxPanel * m_top_line= {nullptr};
|
||||
wxSimplebook * m_simplebook= {nullptr};
|
||||
wxPanel * m_panel_2line= {nullptr};
|
||||
wxPanel * m_panel_1line= {nullptr};
|
||||
Button* m_button_cancel = {nullptr};
|
||||
//wxWindow * m_block_left = {nullptr};
|
||||
//wxWindow * m_block_right = {nullptr};
|
||||
wxScrolledWindow* m_msg_scrolledWindow = {nullptr};
|
||||
|
||||
protected:
|
||||
// Update just the m_maximum field, this is used by public SetRange() but,
|
||||
|
||||
@@ -14,10 +14,17 @@ SideButton::SideButton(wxWindow* parent, wxString text, wxString icon, long stly
|
||||
, state_handler(this)
|
||||
{
|
||||
radius = 12;
|
||||
#ifdef __APPLE__
|
||||
extra_size = wxSize(38 + FromDIP(20), 10);
|
||||
text_margin = 15 + FromDIP(20);
|
||||
#else
|
||||
extra_size = wxSize(38, 10);
|
||||
text_margin = 15;
|
||||
#endif
|
||||
|
||||
icon_offset = 0;
|
||||
text_orientation = HO_Left;
|
||||
text_margin = 15;
|
||||
|
||||
|
||||
|
||||
border_color.append(0x6B6B6B, StateColor::Disabled);
|
||||
@@ -26,15 +33,17 @@ SideButton::SideButton(wxWindow* parent, wxString text, wxString icon, long stly
|
||||
border_color.append(0x00AE42, StateColor::Normal);
|
||||
|
||||
text_color.append(0xACACAC, StateColor::Disabled);
|
||||
text_color.append(0xFFFFFF, StateColor::Pressed);
|
||||
text_color.append(0xFFFFFF, StateColor::Hovered);
|
||||
text_color.append(0xFFFFFF, StateColor::Normal);
|
||||
text_color.append(0xFEFEFE, StateColor::Pressed);
|
||||
text_color.append(0xFEFEFE, StateColor::Hovered);
|
||||
text_color.append(0xFEFEFE, StateColor::Normal);
|
||||
|
||||
background_color.append(0x6B6B6B, StateColor::Disabled);
|
||||
background_color.append(wxColour(23, 129, 63), StateColor::Pressed);
|
||||
background_color.append(wxColour(48, 221, 112), StateColor::Hovered);
|
||||
background_color.append(0x00AE42, StateColor::Normal);
|
||||
|
||||
SetBottomColour(wxColour("#3B4446"));
|
||||
|
||||
state_handler.attach({ &border_color, &text_color, &background_color });
|
||||
state_handler.update_binds();
|
||||
|
||||
@@ -187,7 +196,7 @@ void SideButton::dorender(wxDC& dc, wxDC& text_dc)
|
||||
|
||||
// draw background
|
||||
dc.SetPen(wxNullPen);
|
||||
dc.SetBrush(bottom_color);
|
||||
dc.SetBrush(StateColor::darkModeColorFor(bottom_color));
|
||||
dc.DrawRectangle(0, 0, size.x, size.y);
|
||||
|
||||
int states = state_handler.states();
|
||||
|
||||
@@ -42,14 +42,23 @@ bool SidePopup::Show( bool show )
|
||||
void SidePopup::Popup(wxWindow* focus)
|
||||
{
|
||||
Create();
|
||||
int screenwidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X,NULL);
|
||||
auto drect = wxDisplay(GetParent()).GetGeometry();
|
||||
int screenwidth = drect.x + drect.width;
|
||||
//int screenwidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X,NULL);
|
||||
|
||||
int max_width = 0;
|
||||
|
||||
for (auto btn : btn_list)
|
||||
{
|
||||
max_width = std::max(btn->GetMinSize().x, max_width);
|
||||
}
|
||||
if (focus) {
|
||||
wxPoint pos = focus->ClientToScreen(wxPoint(0, -6));
|
||||
|
||||
#ifdef __APPLE__
|
||||
pos.x = pos.x - FromDIP(20);
|
||||
#endif // __APPLE__
|
||||
|
||||
if (pos.x + max_width > screenwidth)
|
||||
Position({pos.x - (pos.x + max_width - screenwidth),pos.y}, {0, focus->GetSize().y + 12});
|
||||
else
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <wx/dcmemory.h>
|
||||
#include <wx/dcgraph.h>
|
||||
#include "Label.hpp"
|
||||
#include "StateColor.hpp"
|
||||
#include "../wxExtensions.hpp"
|
||||
#include "../I18N.hpp"
|
||||
#include "../GUI.hpp"
|
||||
@@ -12,7 +13,7 @@ namespace Slic3r { namespace GUI {
|
||||
wxPanel::Create(parent, id, pos, wxSize(0, FromDIP(50)));
|
||||
Bind(wxEVT_PAINT, &SideTools::OnPaint, this);
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
SetBackgroundColour(wxColour("#FEFFFF"));
|
||||
|
||||
m_printing_img = ScalableBitmap(this, "printer", 16);
|
||||
m_arrow_img = ScalableBitmap(this, "monitor_arrow", 14);
|
||||
@@ -155,11 +156,11 @@ void SideTools::doRender(wxDC &dc)
|
||||
left += (m_arrow_img.GetBmpSize().x + FromDIP(6));
|
||||
dc.SetFont(::Label::Body_14);
|
||||
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||
dc.SetTextForeground(SIDE_TOOLS_GREY900);
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor(SIDE_TOOLS_GREY900));
|
||||
|
||||
auto sizet = dc.GetTextExtent(m_dev_name);
|
||||
auto text_end = size.x - m_wifi_none_img.GetBmpSize().x - 20;
|
||||
|
||||
|
||||
std::string finally_name = m_dev_name.ToStdString();
|
||||
if (sizet.x > (text_end - left)) {
|
||||
auto limit_width = text_end - left - dc.GetTextExtent("...").x - 20;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "SpinInput.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "Button.hpp"
|
||||
#include "TextCtrl.h"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
@@ -27,7 +28,7 @@ SpinInput::SpinInput()
|
||||
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));
|
||||
background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@ void SpinInput::Create(wxWindow *parent,
|
||||
wxWindow::SetLabel(label);
|
||||
state_handler.attach({&label_color, &text_color});
|
||||
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 TextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS));
|
||||
text_ctrl->SetFont(Label::Body_14);
|
||||
text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
|
||||
text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
|
||||
@@ -230,19 +231,22 @@ Button *SpinInput::createButton(bool inc)
|
||||
delta = inc ? 1 : -1;
|
||||
SetValue(val + delta);
|
||||
text_ctrl->SetFocus();
|
||||
btn->CaptureMouse();
|
||||
if (!btn->HasCapture())
|
||||
btn->CaptureMouse();
|
||||
delta *= 8;
|
||||
timer.Start(100);
|
||||
sendSpinEvent();
|
||||
});
|
||||
btn->Bind(wxEVT_LEFT_DCLICK, [=](auto &e) {
|
||||
delta = inc ? 1 : -1;
|
||||
btn->CaptureMouse();
|
||||
if (!btn->HasCapture())
|
||||
btn->CaptureMouse();
|
||||
SetValue(val + delta);
|
||||
sendSpinEvent();
|
||||
});
|
||||
btn->Bind(wxEVT_LEFT_UP, [=](auto &e) {
|
||||
btn->ReleaseMouse();
|
||||
if (btn->HasCapture())
|
||||
btn->ReleaseMouse();
|
||||
timer.Stop();
|
||||
text_ctrl->SelectAll();
|
||||
delta = 0;
|
||||
@@ -288,7 +292,7 @@ void SpinInput::onTextEnter(wxCommandEvent &event)
|
||||
|
||||
void SpinInput::mouseWheelMoved(wxMouseEvent &event)
|
||||
{
|
||||
auto delta = (event.GetWheelRotation() < 0 == event.IsWheelInverted()) ? 1 : -1;
|
||||
auto delta = event.GetWheelRotation() < 0 ? 1 : -1;
|
||||
SetValue(val + delta);
|
||||
sendSpinEvent();
|
||||
text_ctrl->SetFocus();
|
||||
|
||||
@@ -1,5 +1,81 @@
|
||||
#include "StateColor.hpp"
|
||||
|
||||
static bool gDarkMode = false;
|
||||
|
||||
static bool operator<(wxColour const &l, wxColour const &r) { return l.GetRGBA() < r.GetRGBA(); }
|
||||
|
||||
static std::map<wxColour, wxColour> gDarkColors{
|
||||
{"#00AE42", "#21A452"},
|
||||
{"#1F8EEA", "#2778D2"},
|
||||
{"#FF6F00", "#D15B00"},
|
||||
{"#D01B1B", "#BB2A3A"},
|
||||
{"#262E30", "#EFEFF0"},
|
||||
{"#2C2C2E", "#B3B3B4"},
|
||||
{"#6B6B6B", "#818183"},
|
||||
{"#ACACAC", "#54545A"},
|
||||
{"#EEEEEE", "#4C4C55"},
|
||||
{"#E8E8E8", "#3E3E45"},
|
||||
{"#323A3D", "#E5E5E4"},
|
||||
{"#FFFFFF", "#2D2D31"},
|
||||
{"#F8F8F8", "#36363C"},
|
||||
{"#F1F1F1", "#36363B"},
|
||||
{"#3B4446", "#2D2D30"},
|
||||
{"#CECECE", "#54545B"},
|
||||
{"#DBFDD5", "#3B3B40"},
|
||||
{"#000000", "#FFFFFE"},
|
||||
{"#F4F4F4", "#36363D"},
|
||||
{"#DBDBDB", "#4A4A51"},
|
||||
{"#EDFAF2", "#283232"},
|
||||
{"#323A3C", "#E5E5E6"},
|
||||
{"#6B6B6A", "#B3B3B5"},
|
||||
{"#303A3C", "#E5E5E5"},
|
||||
{"#FEFFFF", "#242428"},
|
||||
{"#A6A9AA", "#2D2D29"},
|
||||
{"#363636", "#B2B3B5"},
|
||||
{"#F0F0F1", "#404040"},
|
||||
{"#9E9E9E", "#53545A"},
|
||||
{"#D7E8DE", "#1F2B27"},
|
||||
{"#2B3436", "#808080"},
|
||||
{"#ABABAB", "#ABABAB"},
|
||||
{"#D9D9D9", "#2D2D32"},
|
||||
//{"#F0F0F0", "#3E3E44"},
|
||||
};
|
||||
|
||||
std::map<wxColour, wxColour> const & StateColor::GetDarkMap()
|
||||
{
|
||||
return gDarkColors;
|
||||
}
|
||||
|
||||
void StateColor::SetDarkMode(bool dark) { gDarkMode = dark; }
|
||||
|
||||
inline wxColour darkModeColorFor2(wxColour const &color)
|
||||
{
|
||||
if (!gDarkMode)
|
||||
return color;
|
||||
auto iter = gDarkColors.find(color);
|
||||
wxFAIL(iter != gDarkColors.end());
|
||||
if (iter != gDarkColors.end()) return iter->second;
|
||||
return color;
|
||||
}
|
||||
|
||||
std::map<wxColour, wxColour> revert(std::map<wxColour, wxColour> const & map)
|
||||
{
|
||||
std::map<wxColour, wxColour> map2;
|
||||
for (auto &p : map) map2.emplace(p.second, p.first);
|
||||
return map2;
|
||||
}
|
||||
|
||||
wxColour StateColor::lightModeColorFor(wxColour const &color)
|
||||
{
|
||||
static std::map<wxColour, wxColour> gLightColors = revert(gDarkColors);
|
||||
auto iter = gLightColors.find(color);
|
||||
wxFAIL(iter != gLightColors.end());
|
||||
if (iter != gLightColors.end()) return iter->second;
|
||||
return color;
|
||||
}
|
||||
|
||||
wxColour StateColor::darkModeColorFor(wxColour const &color) { return darkModeColorFor2(color); }
|
||||
|
||||
StateColor::StateColor(wxColour const &color) { append(color, 0); }
|
||||
|
||||
StateColor::StateColor(wxString const &color) { append(color, 0); }
|
||||
@@ -47,6 +123,27 @@ wxColour StateColor::defaultColor() {
|
||||
}
|
||||
|
||||
wxColour StateColor::colorForStates(int states)
|
||||
{
|
||||
bool focused = takeFocusedAsHovered_ && (states & Focused);
|
||||
for (int i = 0; i < statesList_.size(); ++i) {
|
||||
int s = statesList_[i];
|
||||
int on = s & 0xffff;
|
||||
int off = s >> 16;
|
||||
if ((on & states) == on && (off & ~states) == off) {
|
||||
return darkModeColorFor2(colors_[i]);
|
||||
}
|
||||
if (focused && (on & Hovered)) {
|
||||
on |= Focused;
|
||||
on &= ~Hovered;
|
||||
if ((on & states) == on && (off & ~states) == off) {
|
||||
return darkModeColorFor2(colors_[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return wxColour(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
wxColour StateColor::colorForStatesNoDark(int states)
|
||||
{
|
||||
bool focused = takeFocusedAsHovered_ && (states & Focused);
|
||||
for (int i = 0; i < statesList_.size(); ++i) {
|
||||
@@ -90,4 +187,3 @@ bool StateColor::setColorForStates(wxColour const &color, int states)
|
||||
}
|
||||
|
||||
void StateColor::setTakeFocusedAsHovered(bool set) { takeFocusedAsHovered_ = set; }
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <wx/colour.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
class StateColor
|
||||
{
|
||||
public:
|
||||
@@ -20,6 +22,13 @@ public:
|
||||
NotPressed = 16 << 16,
|
||||
};
|
||||
|
||||
public:
|
||||
static void SetDarkMode(bool dark);
|
||||
|
||||
static std::map<wxColour, wxColour> const & GetDarkMap();
|
||||
static wxColour darkModeColorFor(wxColour const &color);
|
||||
static wxColour lightModeColorFor(wxColour const &color);
|
||||
|
||||
public:
|
||||
template<typename ...Colors>
|
||||
StateColor(std::pair<Colors, int>... colors) {
|
||||
@@ -54,6 +63,8 @@ public:
|
||||
|
||||
wxColour colorForStates(int states);
|
||||
|
||||
wxColour colorForStatesNoDark(int states);
|
||||
|
||||
int colorIndexForStates(int states);
|
||||
|
||||
bool setColorForStates(wxColour const & color, int states);
|
||||
|
||||
@@ -69,6 +69,19 @@ void StateHandler::update_binds()
|
||||
for (auto &c : children_) c->update_binds();
|
||||
}
|
||||
|
||||
void StateHandler::set_state(int state, int mask)
|
||||
{
|
||||
if (states_ & mask == state & mask) return;
|
||||
int old = states_;
|
||||
states_ = states_ & ~mask | state & mask;
|
||||
if (old != states_ && (old | states2_) != (states_ | states2_)) {
|
||||
if (parent_)
|
||||
parent_->changed(states_ | states2_);
|
||||
else
|
||||
owner_->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
StateHandler::StateHandler(StateHandler *parent, wxWindow *owner)
|
||||
: StateHandler(owner)
|
||||
{
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
|
||||
int states() const { return states_ | states2_; }
|
||||
|
||||
void set_state(int state, int mask);
|
||||
|
||||
private:
|
||||
StateHandler(StateHandler * parent, wxWindow *owner);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ StaticBox::StaticBox()
|
||||
, radius(8)
|
||||
{
|
||||
border_color = StateColor(
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled),
|
||||
std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
|
||||
std::make_pair(0x303A3C, (int) StateColor::Normal));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "StaticLine.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "StateColor.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
@@ -15,7 +16,7 @@ StaticLine::StaticLine(wxWindow *parent, bool vertical, const wxString &label, c
|
||||
, vertical(vertical)
|
||||
{
|
||||
wxWindow::SetBackgroundColour(parent->GetBackgroundColour());
|
||||
this->pen = wxPen(wxColour("#EEEEEE"));
|
||||
this->lineColor = wxColour("#EEEEEE");
|
||||
DisableFocusFromKeyboard();
|
||||
SetFont(Label::Body_14);
|
||||
wxWindow::SetLabel(label);
|
||||
@@ -39,7 +40,7 @@ void StaticLine::SetIcon(const wxString &icon)
|
||||
|
||||
void StaticLine::SetLineColour(wxColour color)
|
||||
{
|
||||
this->pen = wxPen(color);
|
||||
this->lineColor = color;
|
||||
}
|
||||
|
||||
void StaticLine::Rescale()
|
||||
@@ -98,10 +99,11 @@ void StaticLine::render(wxDC& dc)
|
||||
titleRect.x += icon.GetBmpWidth() + 5;
|
||||
}
|
||||
if (!label.IsEmpty()) {
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor(GetForegroundColour()));
|
||||
dc.DrawText(label, titleRect.x, (size.GetHeight() - textSize.GetHeight()) / 2);
|
||||
titleRect.x += textSize.GetWidth() + 5;
|
||||
}
|
||||
dc.SetPen(pen);
|
||||
dc.SetPen(wxPen(StateColor::darkModeColorFor(lineColor)));
|
||||
if (vertical) {
|
||||
size.x /= 2;
|
||||
if (titleRect.y > 0) titleRect.y += 5;
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
void Rescale();
|
||||
|
||||
private:
|
||||
wxPen pen;
|
||||
wxColour lineColor;
|
||||
bool vertical;
|
||||
ScalableBitmap icon;
|
||||
|
||||
|
||||
@@ -134,7 +134,8 @@ void StepCtrl::mouseDown(wxMouseEvent &event)
|
||||
if (rcThumb.Contains(pt)) {
|
||||
pos_thumb = wxPoint{circleX, size.y / 2};
|
||||
drag_offset = pos_thumb - pt;
|
||||
CaptureMouse();
|
||||
if (!HasCapture())
|
||||
CaptureMouse();
|
||||
} else if (rcBar.Contains(pt)) {
|
||||
if (pt.x < circleX) {
|
||||
if (step > 0) SelectItem(step - 1);
|
||||
|
||||
@@ -11,7 +11,7 @@ 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})
|
||||
, text_color(std::pair{0xfffffe, (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})
|
||||
{
|
||||
@@ -33,6 +33,11 @@ void SwitchButton::SetTextColor(StateColor const& color)
|
||||
text_color = color;
|
||||
}
|
||||
|
||||
void SwitchButton::SetTextColor2(StateColor const &color)
|
||||
{
|
||||
text_color2 = color;
|
||||
}
|
||||
|
||||
void SwitchButton::SetTrackColor(StateColor const& color)
|
||||
{
|
||||
track_color = color;
|
||||
@@ -57,6 +62,7 @@ void SwitchButton::Rescale()
|
||||
m_off.msw_rescale();
|
||||
}
|
||||
else {
|
||||
SetBackgroundColour(StaticBox::GetParentBackgroundColor(GetParent()));
|
||||
#ifdef __WXOSX__
|
||||
auto scale = Slic3r::GUI::mac_max_scaling_factor();
|
||||
int BS = (int) scale;
|
||||
@@ -115,7 +121,7 @@ void SwitchButton::Rescale()
|
||||
}
|
||||
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.SetTextForeground(text_color2.count() == 0 ? text_color.colorForStates(state) : text_color2.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);
|
||||
#ifdef __WXOSX__
|
||||
|
||||
@@ -16,7 +16,9 @@ public:
|
||||
|
||||
void SetTextColor(StateColor const &color);
|
||||
|
||||
void SetTrackColor(StateColor const &color);
|
||||
void SetTextColor2(StateColor const &color);
|
||||
|
||||
void SetTrackColor(StateColor const &color);
|
||||
|
||||
void SetThumbColor(StateColor const &color);
|
||||
|
||||
@@ -32,7 +34,8 @@ private:
|
||||
ScalableBitmap m_off;
|
||||
|
||||
wxString labels[2];
|
||||
StateColor text_color;
|
||||
StateColor text_color;
|
||||
StateColor text_color2;
|
||||
StateColor track_color;
|
||||
StateColor thumb_color;
|
||||
};
|
||||
|
||||
@@ -99,9 +99,9 @@ int TabCtrl::AppendItem(const wxString &item,
|
||||
btn->Create(this, item, "", wxBORDER_NONE);
|
||||
btn->SetFont(GetFont());
|
||||
btn->SetTextColor(StateColor(
|
||||
std::make_pair(0x6B6B6B, (int) StateColor::NotChecked),
|
||||
std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Normal)));
|
||||
btn->SetBackgroundColor(GetBackgroundColour());
|
||||
btn->SetBackgroundColor(StateColor());
|
||||
btn->SetCornerRadius(0);
|
||||
btn->SetPaddingSize({TAB_BUTTON_PADDING});
|
||||
btns.push_back(btn);
|
||||
|
||||
@@ -19,7 +19,7 @@ END_EVENT_TABLE()
|
||||
|
||||
|
||||
TempInput::TempInput()
|
||||
: label_color(std::make_pair(wxColour(0xAC,0xAC,0xAC), (int) StateColor::Disabled),std::make_pair(0x323A3D, (int) StateColor::Normal))
|
||||
: label_color(std::make_pair(wxColour(0xAC,0xAC,0xAC), (int) StateColor::Disabled),std::make_pair(0x323A3C, (int) StateColor::Normal))
|
||||
, text_color(std::make_pair(wxColour(0xAC,0xAC,0xAC), (int) StateColor::Disabled), std::make_pair(0x6B6B6B, (int) StateColor::Normal))
|
||||
{
|
||||
hover = false;
|
||||
@@ -46,6 +46,7 @@ void TempInput::Create(wxWindow *parent, wxString text, wxString label, wxString
|
||||
state_handler.attach({&label_color, &text_color});
|
||||
state_handler.update_binds();
|
||||
text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {5, 5}, wxDefaultSize, wxTE_PROCESS_ENTER | wxBORDER_NONE, wxTextValidator(wxFILTER_NUMERIC), wxTextCtrlNameStr);
|
||||
text_ctrl->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
|
||||
text_ctrl->SetMaxLength(3);
|
||||
state_handler.attach_child(text_ctrl);
|
||||
text_ctrl->Bind(wxEVT_SET_FOCUS, [this](auto &e) {
|
||||
@@ -417,6 +418,8 @@ void TempInput::render(wxDC &dc)
|
||||
} else {
|
||||
pt.y = (size.y - labelSize.y) / 2;
|
||||
}
|
||||
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor("#323A3C"));
|
||||
dc.DrawText(text, pt);
|
||||
|
||||
// separator
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifdef __WXMSW__
|
||||
class TextCtrl : public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
using wxTextCtrl::wxTextCtrl;
|
||||
WXHBRUSH DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) { return wxTextCtrl::DoMSWControlColor(pDC, wxColour(), hWnd); }
|
||||
};
|
||||
#else
|
||||
typedef wxTextCtrl TextCtrl;
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "TextInput.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "TextCtrl.h"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
@@ -25,7 +26,7 @@ TextInput::TextInput()
|
||||
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));
|
||||
background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
|
||||
SetFont(Label::Body_12);
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ void TextInput::Create(wxWindow * parent,
|
||||
style &= ~wxRIGHT;
|
||||
state_handler.attach({&label_color, & text_color});
|
||||
state_handler.update_binds();
|
||||
text_ctrl = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER);
|
||||
text_ctrl = new TextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER);
|
||||
text_ctrl->SetFont(Label::Body_14);
|
||||
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
|
||||
text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
|
||||
|
||||
@@ -67,6 +67,23 @@ class FakeWebView : public wxWebView
|
||||
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) override { }
|
||||
};
|
||||
|
||||
wxDEFINE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent);
|
||||
|
||||
static std::vector<wxWebView*> g_webviews;
|
||||
|
||||
class WebViewRef : public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
WebViewRef(wxWebView *webView) : m_webView(webView) {}
|
||||
~WebViewRef() {
|
||||
auto iter = std::find(g_webviews.begin(), g_webviews.end(), m_webView);
|
||||
assert(iter != g_webviews.end());
|
||||
if (iter != g_webviews.end())
|
||||
g_webviews.erase(iter);
|
||||
}
|
||||
wxWebView *m_webView;
|
||||
};
|
||||
|
||||
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
{
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
@@ -85,24 +102,32 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
url2.Replace("\\", "/");
|
||||
#endif
|
||||
if (!url2.empty()) { url2 = wxURI(url2).BuildURI(); }
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << url2.ToUTF8();
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": " << url2.ToUTF8();
|
||||
|
||||
auto webView = wxWebView::New();
|
||||
if (webView) {
|
||||
webView->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
|
||||
#ifdef __WIN32__
|
||||
webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s", SLIC3R_VERSION));
|
||||
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize);
|
||||
//We register the wxfs:// protocol for testing purposes
|
||||
webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52", SLIC3R_VERSION,
|
||||
Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light"));
|
||||
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
// We register the wxfs:// protocol for testing purposes
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("bbl")));
|
||||
//And the memory: file system
|
||||
// And the memory: file system
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
||||
#else
|
||||
// With WKWebView handlers need to be registered before creation
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
|
||||
// And the memory: file system
|
||||
webView->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
||||
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize);
|
||||
webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s", SLIC3R_VERSION));
|
||||
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION,
|
||||
Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light"));
|
||||
#endif
|
||||
#ifdef __WXMAC__
|
||||
WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend();
|
||||
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
|
||||
#endif
|
||||
#ifndef __WIN32__
|
||||
Slic3r::GUI::wxGetApp().CallAfter([webView] {
|
||||
@@ -121,6 +146,8 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": failed. Use fake web view.";
|
||||
webView = new FakeWebView;
|
||||
}
|
||||
webView->SetRefData(new WebViewRef(webView));
|
||||
g_webviews.push_back(webView);
|
||||
return webView;
|
||||
}
|
||||
|
||||
@@ -172,3 +199,35 @@ bool WebView::RunScript(wxWebView *webView, wxString const &javascript)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void WebView::RecreateAll()
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
auto webviews = g_webviews;
|
||||
std::vector<wxWindow*> parents;
|
||||
std::vector<wxString> urls;
|
||||
for (auto web : webviews) {
|
||||
parents.push_back(web->GetParent());
|
||||
urls.push_back(web->GetCurrentURL());
|
||||
delete web;
|
||||
}
|
||||
assert(g_webviews.empty());
|
||||
for (int i = 0; i < parents.size(); ++i) {
|
||||
auto webView = CreateWebView(parents[i], urls[i]);
|
||||
if (webView) {
|
||||
wxCommandEvent evt(EVT_WEBVIEW_RECREATED);
|
||||
evt.SetEventObject(webView);
|
||||
wxPostEvent(parents[i], evt);
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (auto webView : g_webviews) {
|
||||
webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION,
|
||||
Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light"));
|
||||
webView->Reload();
|
||||
wxCommandEvent evt(EVT_WEBVIEW_RECREATED);
|
||||
evt.SetEventObject(webView);
|
||||
wxPostEvent(webView->GetParent(), evt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <wx/webview.h>
|
||||
|
||||
wxDECLARE_EVENT(EVT_WEBVIEW_RECREATED, wxCommandEvent);
|
||||
|
||||
class WebView
|
||||
{
|
||||
public:
|
||||
@@ -11,6 +13,8 @@ public:
|
||||
static void LoadUrl(wxWebView * webView, wxString const &url);
|
||||
|
||||
static bool RunScript(wxWebView * webView, wxString const & msg);
|
||||
|
||||
static void RecreateAll();
|
||||
};
|
||||
|
||||
#endif // !slic3r_GUI_WebView_hpp_
|
||||
|
||||
Reference in New Issue
Block a user