OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
BitmapChoiceRenderer Class Reference

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

Inheritance diagram for BitmapChoiceRenderer:
Collaboration diagram for BitmapChoiceRenderer:

Public Member Functions

 BitmapChoiceRenderer (wxDataViewCellMode mode=wxDATAVIEW_CELL_EDITABLE, int align=wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL)
bool SetValue (const wxVariant &value) override
bool GetValue (wxVariant &value) const override
virtual bool Render (wxRect cell, wxDC *dc, int state) override
virtual wxSize GetSize () const override
bool HasEditorCtrl () const override
wxWindow * CreateEditorCtrl (wxWindow *parent, wxRect labelRect, const wxVariant &value) override
bool GetValueFromEditorCtrl (wxWindow *ctrl, wxVariant &value) override
void set_can_create_editor_ctrl_function (std::function< bool()> can_create_fn)
void set_default_extruder_idx (std::function< int()> default_extruder_idx_fn)
void set_has_default_extruder (std::function< bool()> has_default_extruder_fn)

Private Attributes

DataViewBitmapText m_value
std::function< bool()> can_create_editor_ctrl { nullptr }
std::function< int()> get_default_extruder_idx { nullptr }
std::function< bool()> has_default_extruder { nullptr }

Detailed Description

Constructor & Destructor Documentation

◆ BitmapChoiceRenderer()

BitmapChoiceRenderer::BitmapChoiceRenderer ( wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int align = wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL )
inline
156 : wxDataViewCustomRenderer(wxT("DataViewBitmapText"), mode, align) {}

Member Function Documentation

◆ CreateEditorCtrl()

wxWindow * BitmapChoiceRenderer::CreateEditorCtrl ( wxWindow * parent,
wxRect labelRect,
const wxVariant & value )
override
314{
316 return nullptr;
317
318 std::vector<wxBitmap*> icons = get_extruder_color_icons();
319 if (icons.empty())
320 return nullptr;
321
322 DataViewBitmapText data;
323 data << value;
324
325 ::ComboBox *c_editor = new ::ComboBox(parent, wxID_ANY, wxEmptyString,
326 labelRect.GetTopLeft(), wxSize(labelRect.GetWidth(), -1),
327 0, nullptr, wxCB_READONLY | CB_NO_DROP_ICON | CB_NO_TEXT);
328 c_editor->GetDropDown().SetUseContentWidth(true);
329
331 c_editor->Append(_L("default"), *get_default_extruder_color_icon());
332
333 for (size_t i = 0; i < icons.size(); i++)
334 c_editor->Append(wxString::Format("%d", i+1), *icons[i]);
335
337 c_editor->SetSelection(atoi(data.GetText().c_str()));
338 else
339 c_editor->SetSelection(atoi(data.GetText().c_str()) - 1);
340
341 c_editor->Bind(wxEVT_SET_FOCUS, [c_editor](wxFocusEvent& evt) {
342#ifdef __WXGTK__
343 // On wxGTK the data-view editor may receive focus before its native
344 // window is mapped. Opening the popup one event later avoids creating
345 // the GTK popup without a valid toplevel parent.
346 c_editor->CallAfter([c_editor]() {
347 if (c_editor->IsShownOnScreen())
348 c_editor->ForceDropdownOpen();
349 });
350#else
351 c_editor->ForceDropdownOpen();
352#endif
353 evt.Skip();
354 });
355
356 // Close editor after selection is made
357 c_editor->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) {
358 evt.StopPropagation();
359 // FinishEditing grabs new selection and triggers config update. We better call
360 // it explicitly, automatic update on KILL_FOCUS didn't work on Linux.
361 this->FinishEditing();
362 });
363
364 return c_editor;
365}
#define CB_NO_TEXT
Definition ComboBox.hpp:18
#define CB_NO_DROP_ICON
Definition ComboBox.hpp:17
#define _L(s)
Definition OBJ.cpp:34
std::function< bool()> can_create_editor_ctrl
Definition ExtraRenderers.hpp:174
std::function< bool()> has_default_extruder
Definition ExtraRenderers.hpp:176
void SetSelection(int n) override
Definition ComboBox.cpp:102
void ForceDropdownOpen()
Definition ComboBox.cpp:288
int Append(const wxString &item, const wxBitmap &bitmap=wxNullBitmap, int item_style=0)
Definition ComboBox.cpp:227
DropDown & GetDropDown()
Definition ComboBox.hpp:43
wxString GetText() const
Definition ExtraRenderers.hpp:50
void SetUseContentWidth(bool use, bool limit_max_content_width=false)
Definition DropDown.cpp:165
wxBitmap * get_default_extruder_color_icon(bool thin_icon)
Definition wxExtensions.cpp:527
std::vector< wxBitmap * > get_extruder_color_icons(bool thin_icon)
Definition wxExtensions.cpp:572

References _L, ComboBox::Append(), can_create_editor_ctrl, CB_NO_DROP_ICON, CB_NO_TEXT, ComboBox::ForceDropdownOpen(), get_default_extruder_color_icon(), get_extruder_color_icons(), ComboBox::GetDropDown(), DataViewBitmapText::GetText(), has_default_extruder, ComboBox::SetSelection(), and DropDown::SetUseContentWidth().

Here is the call graph for this function:

◆ GetSize()

wxSize BitmapChoiceRenderer::GetSize ( ) const
overridevirtual
302{
303 wxSize sz;// = GetTextExtent(m_value.GetText());
304
305 if (m_value.GetBitmap().IsOk()) {
306 sz.x += m_value.GetBitmap().GetWidth() + 4;
307 sz.y = m_value.GetBitmap().GetHeight() + 4;
308 }
309
310 return sz;
311}
DataViewBitmapText m_value
Definition ExtraRenderers.hpp:173

References m_value.

◆ GetValue()

bool BitmapChoiceRenderer::GetValue ( wxVariant & value) const
override
275{
276 value << m_value;
277 return true;
278}

References m_value.

◆ GetValueFromEditorCtrl()

bool BitmapChoiceRenderer::GetValueFromEditorCtrl ( wxWindow * ctrl,
wxVariant & value )
override
368{
369 auto* c = dynamic_cast<::ComboBox*>(ctrl);
370 if (!c)
371 return false;
372
373 int selection = c->GetSelection();
374 if (selection < 0)
375 return false;
376
377 DataViewBitmapText bmpText;
378
379 bmpText.SetText(c->GetString(selection));
380 bmpText.SetBitmap(c->GetItemBitmap(selection));
381
382 value << bmpText;
383 return true;
384}
void SetBitmap(const wxBitmap &bmp)
Definition ExtraRenderers.hpp:51
void SetText(const wxString &text)
Definition ExtraRenderers.hpp:49

References ComboBox::GetSelection(), DataViewBitmapText::SetBitmap(), and DataViewBitmapText::SetText().

Here is the call graph for this function:

◆ HasEditorCtrl()

bool BitmapChoiceRenderer::HasEditorCtrl ( ) const
inlineoverride
164{ return true; }

◆ Render()

bool BitmapChoiceRenderer::Render ( wxRect cell,
wxDC * dc,
int state )
overridevirtual
281{
282 const wxBitmap& icon = m_value.GetBitmap();
283 if (icon.IsOk())
284 {
285 dc->DrawBitmap(icon, rect.x, rect.y + (rect.height - icon.GetHeight()) / 2);
286
287 if (rect.height == 0)
288 rect.height = icon.GetHeight();
289 }
290
291#ifdef _WIN32
292 // workaround for Windows DarkMode : Don't respect to the state & wxDATAVIEW_CELL_SELECTED to avoid update of the text color
293// RenderText(m_value.GetText(), xoffset, rect, dc, state & wxDATAVIEW_CELL_SELECTED ? 0 : state);
294#else
295// RenderText(m_value.GetText(), xoffset, rect, dc, state);
296#endif
297
298 return true;
299}

References m_value.

◆ set_can_create_editor_ctrl_function()

void BitmapChoiceRenderer::set_can_create_editor_ctrl_function ( std::function< bool()> can_create_fn)
inline
168{ can_create_editor_ctrl = can_create_fn; }

References can_create_editor_ctrl.

Referenced by Slic3r::GUI::ObjectList::create_objects_ctrl().

Here is the caller graph for this function:

◆ set_default_extruder_idx()

void BitmapChoiceRenderer::set_default_extruder_idx ( std::function< int()> default_extruder_idx_fn)
inline
169{ get_default_extruder_idx = default_extruder_idx_fn; }
std::function< int()> get_default_extruder_idx
Definition ExtraRenderers.hpp:175

References get_default_extruder_idx.

Referenced by Slic3r::GUI::ObjectList::create_objects_ctrl().

Here is the caller graph for this function:

◆ set_has_default_extruder()

void BitmapChoiceRenderer::set_has_default_extruder ( std::function< bool()> has_default_extruder_fn)
inline
170{ has_default_extruder = has_default_extruder_fn; }

References has_default_extruder.

Referenced by Slic3r::GUI::ObjectList::create_objects_ctrl().

Here is the caller graph for this function:

◆ SetValue()

bool BitmapChoiceRenderer::SetValue ( const wxVariant & value)
override
269{
270 m_value << value;
271 return true;
272}

References m_value.

Member Data Documentation

◆ can_create_editor_ctrl

std::function<bool()> BitmapChoiceRenderer::can_create_editor_ctrl { nullptr }
private
174{ nullptr };

Referenced by CreateEditorCtrl(), and set_can_create_editor_ctrl_function().

◆ get_default_extruder_idx

std::function<int()> BitmapChoiceRenderer::get_default_extruder_idx { nullptr }
private
175{ nullptr };

Referenced by set_default_extruder_idx().

◆ has_default_extruder

std::function<bool()> BitmapChoiceRenderer::has_default_extruder { nullptr }
private
176{ nullptr };

Referenced by CreateEditorCtrl(), and set_has_default_extruder().

◆ m_value

DataViewBitmapText BitmapChoiceRenderer::m_value
private

Referenced by GetSize(), GetValue(), Render(), and SetValue().


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