mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-16 12:21:11 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
271 lines
7.5 KiB
C++
271 lines
7.5 KiB
C++
#include "StaticBox.hpp"
|
|
#include "../GUI.hpp"
|
|
#include <utility>
|
|
#include <wx/anybutton.h>
|
|
#include <wx/checklst.h>
|
|
#include <wx/colour.h>
|
|
#include <wx/dc.h>
|
|
#include <cmath>
|
|
#include <wx/dcclient.h>
|
|
#include <wx/dcgraph.h>
|
|
#include <wx/gdicmn.h>
|
|
#include <wx/peninfobase.h>
|
|
#include <wx/event.h>
|
|
#include "slic3r/GUI/Widgets/StateColor.hpp"
|
|
#include "slic3r/GUI/Widgets/StateHandler.hpp"
|
|
#include "slic3r/GUI/wxExtensions.hpp"
|
|
|
|
BEGIN_EVENT_TABLE(StaticBox, wxWindow)
|
|
|
|
// catch paint events
|
|
//EVT_ERASE_BACKGROUND(StaticBox::eraseEvent)
|
|
EVT_SIZE(StaticBox::sizeEvent)
|
|
EVT_PAINT(StaticBox::paintEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
/*
|
|
* Called by the system of by wxWidgets when the panel needs
|
|
* to be redrawn. You can also trigger this call by
|
|
* calling Refresh()/Update().
|
|
*/
|
|
|
|
StaticBox::StaticBox()
|
|
: state_handler(this)
|
|
, radius(8)
|
|
{
|
|
border_color = StateColor(
|
|
std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
|
|
std::make_pair(0xCECECE, (int) StateColor::Normal));
|
|
}
|
|
|
|
StaticBox::StaticBox(wxWindow* parent,
|
|
wxWindowID id,
|
|
const wxPoint & pos,
|
|
const wxSize & size, long style)
|
|
: StaticBox()
|
|
{
|
|
Create(parent, id, pos, size, style);
|
|
}
|
|
|
|
bool StaticBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
|
|
{
|
|
if (style & wxBORDER_NONE)
|
|
border_width = 0;
|
|
wxWindow::Create(parent, id, pos, size, style);
|
|
state_handler.attach({&border_color, &background_color, &background_color2});
|
|
state_handler.update_binds();
|
|
SetBackgroundColour(GetParentBackgroundColor(parent));
|
|
return true;
|
|
}
|
|
|
|
void StaticBox::SetCornerRadius(double radius)
|
|
{
|
|
this->radius = radius;
|
|
Refresh();
|
|
}
|
|
|
|
// ORCA use when adding widgets to top to show it like LabeledStaticBox
|
|
void StaticBox::SetTopMargin(int margin)
|
|
{
|
|
this->top_margin = margin;
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBorderStyle(wxPenStyle style)
|
|
{
|
|
border_style = style;
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBorderWidth(int width)
|
|
{
|
|
border_width = width;
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBorderColor(StateColor const &color)
|
|
{
|
|
if (border_color != color) {
|
|
border_color = color;
|
|
state_handler.update_binds();
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
void StaticBox::SetBorderColorNormal(wxColor const &color)
|
|
{
|
|
border_color.setColorForStates(color, 0);
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBackgroundColor(StateColor const &color)
|
|
{
|
|
background_color = color;
|
|
state_handler.update_binds();
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBackgroundColorNormal(wxColor const &color)
|
|
{
|
|
background_color.setColorForStates(color, 0);
|
|
Refresh();
|
|
}
|
|
|
|
void StaticBox::SetBackgroundColor2(StateColor const &color)
|
|
{
|
|
background_color2 = color;
|
|
state_handler.update_binds();
|
|
Refresh();
|
|
}
|
|
|
|
wxColor StaticBox::GetParentBackgroundColor(wxWindow* parent)
|
|
{
|
|
if (auto box = dynamic_cast<StaticBox*>(parent)) {
|
|
if (box->background_color.count() > 0) {
|
|
if (box->background_color2.count() == 0)
|
|
return box->background_color.defaultColor();
|
|
auto s = box->background_color.defaultColor();
|
|
auto e = box->background_color2.defaultColor();
|
|
int r = (s.Red() + e.Red()) / 2;
|
|
int g = (s.Green() + e.Green()) / 2;
|
|
int b = (s.Blue() + e.Blue()) / 2;
|
|
return wxColor(r, g, b);
|
|
}
|
|
}
|
|
if (parent)
|
|
return parent->GetBackgroundColour();
|
|
return *wxWHITE;
|
|
}
|
|
|
|
void StaticBox::ShowBadge(bool show)
|
|
{
|
|
if (show && badge.name() != "badge") {
|
|
badge = ScalableBitmap(this, "badge", 18);
|
|
Refresh();
|
|
} else if (!show && !badge.name().empty()) {
|
|
badge = ScalableBitmap {};
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
void StaticBox::eraseEvent(wxEraseEvent& evt)
|
|
{
|
|
// for transparent background, but not work
|
|
#ifdef __WXMSW__
|
|
wxDC *dc = evt.GetDC();
|
|
wxSize size = GetSize();
|
|
wxClientDC dc2(GetParent());
|
|
dc->Blit({0, 0}, size, &dc2, GetPosition());
|
|
#endif
|
|
}
|
|
|
|
void StaticBox::sizeEvent(wxSizeEvent& evt)
|
|
{
|
|
Refresh();
|
|
evt.Skip();
|
|
}
|
|
|
|
void StaticBox::paintEvent(wxPaintEvent& evt)
|
|
{
|
|
// depending on your system you may need to look at double-buffered dcs
|
|
wxPaintDC dc(this);
|
|
render(dc);
|
|
}
|
|
|
|
/*
|
|
* Here we do the actual rendering. I put it in a separate
|
|
* method so that it can work no matter what type of DC
|
|
* (e.g. wxPaintDC or wxClientDC) is used.
|
|
*/
|
|
void StaticBox::render(wxDC& dc)
|
|
{
|
|
#ifdef __WXMSW__
|
|
if (radius == 0) {
|
|
doRender(dc);
|
|
return;
|
|
}
|
|
|
|
wxSize size = GetSize();
|
|
if (size.x <= 0 || size.y <= 0)
|
|
return;
|
|
wxMemoryDC memdc(&dc);
|
|
if (!memdc.IsOk()) {
|
|
doRender(dc);
|
|
return;
|
|
}
|
|
wxBitmap bmp(size.x, size.y);
|
|
memdc.SelectObject(bmp);
|
|
//memdc.Blit({0, 0}, size, &dc, {0, 0});
|
|
memdc.SetBackground(wxBrush(GetBackgroundColour()));
|
|
memdc.Clear();
|
|
{
|
|
wxGCDC dc2(memdc);
|
|
doRender(dc2);
|
|
}
|
|
|
|
memdc.SelectObject(wxNullBitmap);
|
|
dc.DrawBitmap(bmp, 0, 0);
|
|
#else
|
|
doRender(dc);
|
|
#endif
|
|
}
|
|
|
|
void StaticBox::doRender(wxDC& dc)
|
|
{
|
|
wxSize size = GetSize();
|
|
int states = state_handler.states();
|
|
if (background_color2.count() == 0) {
|
|
if ((border_width && border_color.count() > 0) || background_color.count() > 0) {
|
|
int topM = top_margin > 0 ? top_margin : 0;
|
|
wxRect rc(0, topM, size.x, size.y - topM);
|
|
if (border_width && border_color.count() > 0) {
|
|
const double scale = dc.GetContentScaleFactor();
|
|
|
|
// Snap rect edges to physical pixel boundaries so the 1px pen doesn't straddle a pixel boundary
|
|
auto snap = [&](int logical) -> int {
|
|
return (int)(ceil(logical * scale) / scale);
|
|
};
|
|
|
|
int deflate = snap(border_width / 2.0); // at 175%: snap(0.5) = snap→1/1.75 ≈ 1
|
|
rc.x += deflate;
|
|
rc.y += deflate;
|
|
rc.width -= deflate * 2;
|
|
rc.height -= deflate * 2;
|
|
dc.SetPen(wxPen(border_color.colorForStates(states), border_width, border_style));
|
|
} else {
|
|
dc.SetPen(wxPen(background_color.colorForStates(states)));
|
|
}
|
|
if (background_color.count() > 0)
|
|
dc.SetBrush(wxBrush(background_color.colorForStates(states)));
|
|
else
|
|
dc.SetBrush(wxBrush(GetBackgroundColour()));
|
|
if (radius == 0) {
|
|
dc.DrawRectangle(rc);
|
|
}
|
|
else {
|
|
dc.DrawRoundedRectangle(rc, radius - border_width);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
wxColor start = background_color.colorForStates(states);
|
|
wxColor stop = background_color2.colorForStates(states);
|
|
int r = start.Red(), g = start.Green(), b = start.Blue();
|
|
int dr = (int) stop.Red() - r, dg = (int) stop.Green() - g, db = (int) stop.Blue() - b;
|
|
int lr = 0, lg = 0, lb = 0;
|
|
for (int y = 0; y < size.y; ++y) {
|
|
dc.SetPen(wxPen(wxColor(r, g, b)));
|
|
dc.DrawLine(0, y, size.x, y);
|
|
lr += dr; while (lr >= size.y) { ++r, lr -= size.y; } while (lr <= -size.y) { --r, lr += size.y; }
|
|
lg += dg; while (lg >= size.y) { ++g, lg -= size.y; } while (lg <= -size.y) { --g, lg += size.y; }
|
|
lb += db; while (lb >= size.y) { ++b, lb -= size.y; } while (lb <= -size.y) { --b, lb += size.y; }
|
|
}
|
|
}
|
|
|
|
if (badge.bmp().IsOk()) {
|
|
auto s = badge.bmp().GetScaledSize();
|
|
dc.DrawBitmap(badge.bmp(), size.x - s.x, top_margin > 0 ? top_margin : 0);
|
|
}
|
|
}
|