mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 19:33:47 +00:00
Refine badged static box
This commit is contained in:
@@ -48,7 +48,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void PickDC(wxDC& dc);
|
void PickDC(wxDC& dc);
|
||||||
virtual void DrawBorderAndLabel(wxDC& dc);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StateHandler state_handler;
|
StateHandler state_handler;
|
||||||
@@ -64,6 +63,7 @@ protected:
|
|||||||
float m_scale;
|
float m_scale;
|
||||||
wxPoint m_pos;
|
wxPoint m_pos;
|
||||||
|
|
||||||
|
virtual void DrawBorderAndLabel(wxDC& dc);
|
||||||
void GetBordersForSizer(int *borderTop, int *borderOther) const override;
|
void GetBordersForSizer(int *borderTop, int *borderOther) const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,79 +1,26 @@
|
|||||||
#include "StaticGroup.hpp"
|
#include "StaticGroup.hpp"
|
||||||
|
|
||||||
StaticGroup::StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label)
|
StaticGroup::StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label)
|
||||||
: wxStaticBox(parent, id, label)
|
: LabeledStaticBox(parent, label)
|
||||||
{
|
{
|
||||||
SetBackgroundColour(*wxWHITE);
|
SetBackgroundColour(*wxWHITE);
|
||||||
SetForegroundColour("#CECECE");
|
SetForegroundColour("#CECECE");
|
||||||
borderColor_ = wxColour("#CECECE");
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
Bind(wxEVT_PAINT, &StaticGroup::OnPaint, this);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticGroup_layoutBadge(void * group, void * badge);
|
|
||||||
|
|
||||||
void StaticGroup::ShowBadge(bool show)
|
void StaticGroup::ShowBadge(bool show)
|
||||||
{
|
{
|
||||||
#ifdef __WXMSW__
|
|
||||||
if (show)
|
if (show)
|
||||||
badge = ScalableBitmap(this, "badge", 18);
|
badge = ScalableBitmap(this, "badge", 18);
|
||||||
else
|
else
|
||||||
badge = ScalableBitmap{};
|
badge = ScalableBitmap{};
|
||||||
Refresh();
|
Refresh();
|
||||||
#endif
|
|
||||||
#ifdef __WXOSX__
|
|
||||||
if (show && badge == nullptr) {
|
|
||||||
badge = new ScalableButton(this, wxID_ANY, "badge", wxEmptyString, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 18);
|
|
||||||
badge->SetSize(badge->GetBestSize());
|
|
||||||
badge->SetBackgroundColour("#F7F7F7");
|
|
||||||
StaticGroup_layoutBadge(GetHandle(), badge->GetHandle());
|
|
||||||
}
|
|
||||||
if (badge && badge->IsShown() != show)
|
|
||||||
badge->Show(show);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticGroup::SetBorderColor(const wxColour &color)
|
void StaticGroup::DrawBorderAndLabel(wxDC& dc)
|
||||||
{
|
{
|
||||||
borderColor_ = color;
|
LabeledStaticBox::DrawBorderAndLabel(dc);
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
void StaticGroup::OnPaint(wxPaintEvent &evt)
|
|
||||||
{
|
|
||||||
wxStaticBox::OnPaint(evt);
|
|
||||||
if (badge.bmp().IsOk()) {
|
if (badge.bmp().IsOk()) {
|
||||||
auto s = badge.bmp().GetScaledSize();
|
auto s = badge.bmp().GetScaledSize();
|
||||||
wxPaintDC dc(this);
|
|
||||||
dc.DrawBitmap(badge.bmp(), GetSize().x - s.x, 8);
|
dc.DrawBitmap(badge.bmp(), GetSize().x - s.x, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticGroup::PaintForeground(wxDC &dc, const struct tagRECT &rc)
|
|
||||||
{
|
|
||||||
wxStaticBox::PaintForeground(dc, rc);
|
|
||||||
auto mdc = dynamic_cast<wxMemoryDC *>(&dc);
|
|
||||||
auto image = mdc->GetSelectedBitmap().ConvertToImage();
|
|
||||||
// Found border coords
|
|
||||||
int top = 0;
|
|
||||||
int left = 0;
|
|
||||||
int right = rc.right - 1;
|
|
||||||
int bottom = rc.bottom - 1;
|
|
||||||
auto blue = GetBackgroundColour().Blue();
|
|
||||||
while (image.GetBlue(0, top) == blue && top < bottom) ++top;
|
|
||||||
while (image.GetBlue(left, top) != blue && left < right) ++left; // --left; // fix start
|
|
||||||
while (image.GetBlue(right, top) != blue && right > 0) --right;
|
|
||||||
++right;
|
|
||||||
while (image.GetBlue(0, bottom) == blue && bottom > 0) --bottom;
|
|
||||||
// Draw border with foreground color
|
|
||||||
wxPoint polygon[] = { {left, top}, {0, top}, {0, bottom}, {rc.right - 1, bottom}, {rc.right - 1, top}, {right, top} };
|
|
||||||
dc.SetPen(wxPen(borderColor_, 1));
|
|
||||||
for (int i = 1; i < 6; ++i) {
|
|
||||||
if (i == 4) // fix bottom right corner
|
|
||||||
++polygon[i - 1].y;
|
|
||||||
dc.DrawLine(polygon[i - 1], polygon[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -3,30 +3,17 @@
|
|||||||
|
|
||||||
#include "../wxExtensions.hpp"
|
#include "../wxExtensions.hpp"
|
||||||
|
|
||||||
#include <wx/statbox.h>
|
#include "LabeledStaticBox.hpp"
|
||||||
|
|
||||||
class StaticGroup : public wxStaticBox
|
class StaticGroup : public LabeledStaticBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label);
|
StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label);
|
||||||
|
|
||||||
public:
|
|
||||||
void ShowBadge(bool show);
|
void ShowBadge(bool show);
|
||||||
void SetBorderColor(const wxColour &color);
|
|
||||||
private:
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
void OnPaint(wxPaintEvent &evt);
|
|
||||||
void PaintForeground(wxDC &dc, const struct tagRECT &rc) override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef __WXMSW__
|
void DrawBorderAndLabel(wxDC& dc) override;
|
||||||
ScalableBitmap badge;
|
ScalableBitmap badge;
|
||||||
#endif
|
|
||||||
#ifdef __WXOSX__
|
|
||||||
ScalableButton * badge { nullptr };
|
|
||||||
#endif
|
|
||||||
wxColour borderColor_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !slic3r_GUI_StaticGroup_hpp_
|
#endif // !slic3r_GUI_StaticGroup_hpp_
|
||||||
|
|||||||
Reference in New Issue
Block a user