Implemented BitmapChoiseRenderer
This commit is contained in:
parent
904bbcc006
commit
c07a193b4e
@ -521,12 +521,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
|
|||||||
const std::vector<double> &init_matrix = (project_config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
|
const std::vector<double> &init_matrix = (project_config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
|
||||||
const std::vector<double> &init_extruders = (project_config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
|
const std::vector<double> &init_extruders = (project_config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
|
||||||
|
|
||||||
const DynamicPrintConfig* config = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||||
std::vector<std::string> extruder_colours = (config->option<ConfigOptionStrings>("extruder_colour"))->values;
|
|
||||||
const std::vector<std::string>& filament_colours = (wxGetApp().plater()->get_plater_config()->option<ConfigOptionStrings>("filament_colour"))->values;
|
|
||||||
for (size_t i=0; i<extruder_colours.size(); ++i)
|
|
||||||
if (extruder_colours[i] == "" && i < filament_colours.size())
|
|
||||||
extruder_colours[i] = filament_colours[i];
|
|
||||||
|
|
||||||
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours);
|
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours);
|
||||||
|
|
||||||
@ -4891,6 +4886,18 @@ const DynamicPrintConfig* Plater::get_plater_config() const
|
|||||||
return p->config;
|
return p->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Plater::get_extruder_colors_from_plater_config() const
|
||||||
|
{
|
||||||
|
const Slic3r::DynamicPrintConfig* config = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||||
|
std::vector<std::string> extruder_colors = (config->option<ConfigOptionStrings>("extruder_colour"))->values;
|
||||||
|
const std::vector<std::string>& filament_colours = (p->config->option<ConfigOptionStrings>("filament_colour"))->values;
|
||||||
|
for (size_t i = 0; i < extruder_colors.size(); ++i)
|
||||||
|
if (extruder_colors[i] == "" && i < filament_colours.size())
|
||||||
|
extruder_colors[i] = filament_colours[i];
|
||||||
|
|
||||||
|
return extruder_colors;
|
||||||
|
}
|
||||||
|
|
||||||
wxString Plater::get_project_filename(const wxString& extension) const
|
wxString Plater::get_project_filename(const wxString& extension) const
|
||||||
{
|
{
|
||||||
return p->get_project_filename(extension);
|
return p->get_project_filename(extension);
|
||||||
|
@ -215,6 +215,7 @@ public:
|
|||||||
// On activating the parent window.
|
// On activating the parent window.
|
||||||
void on_activate();
|
void on_activate();
|
||||||
const DynamicPrintConfig* get_plater_config() const;
|
const DynamicPrintConfig* get_plater_config() const;
|
||||||
|
std::vector<std::string> get_extruder_colors_from_plater_config() const;
|
||||||
|
|
||||||
void update_object_menu();
|
void update_object_menu();
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
|
#include <wx/bmpcbox.h>
|
||||||
#include <wx/statline.h>
|
#include <wx/statline.h>
|
||||||
#include <wx/dcclient.h>
|
#include <wx/dcclient.h>
|
||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
@ -20,6 +21,7 @@
|
|||||||
#include "libslic3r/GCode/PreviewData.hpp"
|
#include "libslic3r/GCode/PreviewData.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
#include "GUI_Utils.hpp"
|
#include "GUI_Utils.hpp"
|
||||||
|
#include "PresetBundle.hpp"
|
||||||
#include "../Utils/MacDarkMode.hpp"
|
#include "../Utils/MacDarkMode.hpp"
|
||||||
|
|
||||||
using Slic3r::GUI::from_u8;
|
using Slic3r::GUI::from_u8;
|
||||||
@ -1840,7 +1842,7 @@ void ObjectDataViewModel::DeleteWarningIcon(const wxDataViewItem& item, const bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// PrusaDataViewBitmapText
|
// DataViewBitmapText
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxIMPLEMENT_DYNAMIC_CLASS(DataViewBitmapText, wxObject)
|
wxIMPLEMENT_DYNAMIC_CLASS(DataViewBitmapText, wxObject)
|
||||||
@ -1966,6 +1968,138 @@ bool BitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// BitmapChoiseRenderer
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool BitmapChoiseRenderer::SetValue(const wxVariant& value)
|
||||||
|
{
|
||||||
|
m_value << value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool BitmapChoiseRenderer::GetValue(wxVariant& value) const
|
||||||
|
{
|
||||||
|
value << m_value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool BitmapChoiseRenderer::Render(wxRect rect, wxDC* dc, int state)
|
||||||
|
{
|
||||||
|
int xoffset = 0;
|
||||||
|
|
||||||
|
const wxBitmap& icon = m_value.GetBitmap();
|
||||||
|
if (icon.IsOk())
|
||||||
|
{
|
||||||
|
dc->DrawBitmap(icon, rect.x, rect.y + (rect.height - icon.GetHeight()) / 2);
|
||||||
|
xoffset = icon.GetWidth() + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderText(m_value.GetText(), xoffset, rect, dc, state);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize BitmapChoiseRenderer::GetSize() const
|
||||||
|
{
|
||||||
|
if (!m_value.GetText().empty())
|
||||||
|
{
|
||||||
|
wxSize size = GetTextExtent(m_value.GetText());
|
||||||
|
|
||||||
|
if (m_value.GetBitmap().IsOk())
|
||||||
|
size.x += m_value.GetBitmap().GetWidth() + 4;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
return wxSize(80, 20);
|
||||||
|
|
||||||
|
/* from wxDataViewChoiceRenderer
|
||||||
|
wxSize sz;
|
||||||
|
|
||||||
|
for ( wxArrayString::const_iterator i = m_choices.begin(); i != m_choices.end(); ++i )
|
||||||
|
sz.IncTo(GetTextExtent(*i));
|
||||||
|
|
||||||
|
// Allow some space for the right-side button, which is approximately the
|
||||||
|
// size of a scrollbar (and getting pixel-exact value would be complicated).
|
||||||
|
// Also add some whitespace between the text and the button:
|
||||||
|
sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
||||||
|
sz.x += GetTextExtent("M").x;
|
||||||
|
|
||||||
|
return sz;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_extruder_color_icons_in_cache()
|
||||||
|
{
|
||||||
|
// Create the bitmap with color bars.
|
||||||
|
std::vector<wxBitmap*> bmps;
|
||||||
|
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||||
|
|
||||||
|
unsigned char rgb[3];
|
||||||
|
|
||||||
|
/* It's supposed that standard size of an icon is 36px*16px for 100% scaled display.
|
||||||
|
* So set sizes for solid_colored icons used for filament preset
|
||||||
|
* and scale them in respect to em_unit value
|
||||||
|
*/
|
||||||
|
const double em = Slic3r::GUI::wxGetApp().em_unit();
|
||||||
|
const int icon_width = lround(3.6 * em);
|
||||||
|
const int icon_height = lround(1.6 * em);
|
||||||
|
|
||||||
|
for (const std::string& color : colors)
|
||||||
|
{
|
||||||
|
wxBitmap* bitmap = m_bitmap_cache->find(color);
|
||||||
|
if (bitmap == nullptr) {
|
||||||
|
// Paint the color icon.
|
||||||
|
Slic3r::PresetBundle::parse_color(color, rgb);
|
||||||
|
bitmap = m_bitmap_cache->insert(color, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
|
||||||
|
}
|
||||||
|
bmps.emplace_back(bitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxWindow* BitmapChoiseRenderer::CreateEditorCtrl(wxWindow* parent, wxRect labelRect, const wxVariant& value)
|
||||||
|
{
|
||||||
|
wxDataViewCtrl* const dv_ctrl = GetOwner()->GetOwner();
|
||||||
|
ObjectDataViewModel* const model = dynamic_cast<ObjectDataViewModel*>(dv_ctrl->GetModel());
|
||||||
|
|
||||||
|
if (!(model->GetItemType(dv_ctrl->GetSelection()) & (itVolume | itObject)))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
DataViewBitmapText data;
|
||||||
|
data << value;
|
||||||
|
|
||||||
|
// m_was_unusable_symbol = false;
|
||||||
|
|
||||||
|
wxPoint position = labelRect.GetPosition();
|
||||||
|
if (data.GetBitmap().IsOk()) {
|
||||||
|
const int bmp_width = data.GetBitmap().GetWidth();
|
||||||
|
position.x += bmp_width;
|
||||||
|
labelRect.SetWidth(labelRect.GetWidth() - bmp_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto c_editor = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, //data.GetText(),
|
||||||
|
labelRect.GetTopLeft(), wxSize(labelRect.GetWidth(), -1),
|
||||||
|
0, nullptr , wxCB_READONLY);
|
||||||
|
|
||||||
|
c_editor->Move(labelRect.GetRight() - c_editor->GetRect().width, wxDefaultCoord);
|
||||||
|
c_editor->SetStringSelection(data.GetText());
|
||||||
|
return c_editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BitmapChoiseRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value)
|
||||||
|
{
|
||||||
|
wxBitmapComboBox* c = (wxBitmapComboBox*)ctrl;
|
||||||
|
int selection = c->GetSelection();
|
||||||
|
if (selection < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DataViewBitmapText bmpText;
|
||||||
|
|
||||||
|
bmpText.SetText(c->GetString(selection));
|
||||||
|
bmpText.SetBitmap(c->GetItemBitmap(selection));
|
||||||
|
|
||||||
|
value << bmpText;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// DoubleSlider
|
// DoubleSlider
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -563,6 +563,40 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// BitmapChoiseRenderer
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class BitmapChoiseRenderer : public wxDataViewCustomRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BitmapChoiseRenderer(wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT
|
||||||
|
|
||||||
|
, int align = wxDVR_DEFAULT_ALIGNMENT
|
||||||
|
) : wxDataViewCustomRenderer(wxT("DataViewBitmapText"), mode, align) {}
|
||||||
|
|
||||||
|
bool SetValue(const wxVariant& value);
|
||||||
|
bool GetValue(wxVariant& value) const;
|
||||||
|
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING && wxUSE_ACCESSIBILITY
|
||||||
|
virtual wxString GetAccessibleDescription() const override;
|
||||||
|
#endif // wxUSE_ACCESSIBILITY && ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
|
||||||
|
|
||||||
|
virtual bool Render(wxRect cell, wxDC* dc, int state);
|
||||||
|
virtual wxSize GetSize() const;
|
||||||
|
|
||||||
|
bool HasEditorCtrl() const override { return true; }
|
||||||
|
wxWindow* CreateEditorCtrl(wxWindow* parent,
|
||||||
|
wxRect labelRect,
|
||||||
|
const wxVariant& value) override;
|
||||||
|
bool GetValueFromEditorCtrl(wxWindow* ctrl,
|
||||||
|
wxVariant& value) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DataViewBitmapText m_value;
|
||||||
|
wxArrayString m_choices;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyCustomRenderer
|
// MyCustomRenderer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user