OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::TextureProjectorFrame Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/TextureProjectorFrame.hpp>

Inheritance diagram for Slic3r::GUI::TextureProjectorFrame:
Collaboration diagram for Slic3r::GUI::TextureProjectorFrame:

Public Member Functions

 TextureProjectorFrame (wxWindow *parent)
void set_texture (const std::vector< unsigned char > &grayscale_pixels, int width, int height)
void set_opacity (int alpha)
int opacity () const
wxRect client_rect_on_screen () const

Private Member Functions

void on_paint (wxPaintEvent &)

Private Attributes

wxBitmap m_bitmap
int m_alpha = 140

Detailed Description

Constructor & Destructor Documentation

◆ TextureProjectorFrame()

Slic3r::GUI::TextureProjectorFrame::TextureProjectorFrame ( wxWindow * parent)
explicit
23 : wxFrame(parent, wxID_ANY, _L("Projection frame - drag over the model, then Apply"), wxDefaultPosition,
24 wxSize(360, 360),
25 // Caption and resize border so moving and sizing are the native gestures the user
26 // already knows - "align it by moving the window" only works if the window moves the
27 // ordinary way. FLOAT_ON_PARENT keeps it above the 3D view without the antisocial
28 // always-on-top-of-everything behaviour of wxSTAY_ON_TOP.
29 wxCAPTION | wxRESIZE_BORDER | wxCLOSE_BOX | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT)
30{
31 SetBackgroundStyle(wxBG_STYLE_PAINT);
32 Bind(wxEVT_PAINT, &TextureProjectorFrame::on_paint, this);
33 // A resize changes the gate, so the texture has to be re-stretched under it.
34 Bind(wxEVT_SIZE, [this](wxSizeEvent &evt) { Refresh(); evt.Skip(); });
35 SetTransparent(wxByte(m_alpha));
36
37 // Hide rather than destroy: the gizmo owns this window's lifetime, and reopening should keep the
38 // frame exactly where it was left - its position is the placement.
39 Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent &evt) {
40 if (evt.CanVeto()) {
41 evt.Veto();
42 Hide();
43 } else
44 evt.Skip();
45 });
46}
#define _L(s)
Definition OBJ.cpp:34
int m_alpha
Definition TextureProjectorFrame.hpp:54
void on_paint(wxPaintEvent &)
Definition TextureProjectorFrame.cpp:81

References _L, m_alpha, and on_paint().

Here is the call graph for this function:

Member Function Documentation

◆ client_rect_on_screen()

wxRect Slic3r::GUI::TextureProjectorFrame::client_rect_on_screen ( ) const
76{
77 const wxSize sz = GetClientSize();
78 return wxRect(ClientToScreen(wxPoint(0, 0)), sz);
79}

◆ on_paint()

void Slic3r::GUI::TextureProjectorFrame::on_paint ( wxPaintEvent & )
private
82{
83 wxPaintDC dc(this);
84 const wxSize sz = GetClientSize();
85 if (sz.x <= 0 || sz.y <= 0)
86 return;
87
88 dc.SetBackground(wxBrush(wxColour(20, 20, 20)));
89 dc.Clear();
90
91 if (m_bitmap.IsOk()) {
92 // Stretched to fill the client area rather than kept at its own aspect: the gate maps to the
93 // uv unit square whatever its shape, so a non-square window genuinely does project a
94 // stretched texture. Showing it any other way would misrepresent the bake.
95 wxImage scaled = m_bitmap.ConvertToImage().Scale(sz.x, sz.y, wxIMAGE_QUALITY_NORMAL);
96 dc.DrawBitmap(wxBitmap(scaled), 0, 0, false);
97 }
98
99 // The border is the projection's hard edge, so it is drawn explicitly - with the window
100 // translucent, the native frame alone reads poorly against a busy 3D scene.
101 dc.SetPen(wxPen(wxColour(0, 200, 180), 2));
102 dc.SetBrush(*wxTRANSPARENT_BRUSH);
103 dc.DrawRectangle(0, 0, sz.x, sz.y);
104}
wxBitmap m_bitmap
Definition TextureProjectorFrame.hpp:53
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:284

References m_bitmap, and Slic3r::scaled().

Referenced by TextureProjectorFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ opacity()

int Slic3r::GUI::TextureProjectorFrame::opacity ( ) const
inline
45{ return m_alpha; }

References m_alpha.

◆ set_opacity()

void Slic3r::GUI::TextureProjectorFrame::set_opacity ( int alpha)
69{
70 m_alpha = std::clamp(alpha, 20, 255);
71 SetTransparent(wxByte(m_alpha));
72 Refresh();
73}

References m_alpha.

◆ set_texture()

void Slic3r::GUI::TextureProjectorFrame::set_texture ( const std::vector< unsigned char > & grayscale_pixels,
int width,
int height )
49{
50 if (width <= 0 || height <= 0 || gray.size() < size_t(width) * size_t(height)) {
51 m_bitmap = wxBitmap();
52 Refresh();
53 return;
54 }
55
56 wxImage img(width, height);
57 unsigned char *dst = img.GetData();
58 for (size_t i = 0, n = size_t(width) * size_t(height); i < n; ++i) {
59 const unsigned char v = gray[i];
60 dst[i * 3 + 0] = v;
61 dst[i * 3 + 1] = v;
62 dst[i * 3 + 2] = v;
63 }
64 m_bitmap = wxBitmap(img);
65 Refresh();
66}

References m_bitmap.

Member Data Documentation

◆ m_alpha

int Slic3r::GUI::TextureProjectorFrame::m_alpha = 140
private

◆ m_bitmap

wxBitmap Slic3r::GUI::TextureProjectorFrame::m_bitmap
private

Referenced by on_paint(), and set_texture().


The documentation for this class was generated from the following files: