OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::DailyTipsDataRenderer Class Reference
Collaboration diagram for Slic3r::GUI::DailyTipsDataRenderer:

Public Member Functions

 DailyTipsDataRenderer (DailyTipsLayout layout)
 ~DailyTipsDataRenderer ()
void update_data (const DailyTipsData &data)
void render (const ImVec2 &pos, const ImVec2 &size) const
bool has_image () const
void on_change_color_mode (bool is_dark)
void set_fade_opacity (float opacity)

Protected Member Functions

void load_texture_from_img_url (const std::string url)
void open_wiki () const
void render_img (const ImVec2 &start_pos, const ImVec2 &size) const
void render_text (const ImVec2 &start_pos, const ImVec2 &size) const

Private Attributes

DailyTipsData m_data
GLTexture * m_texture { nullptr }
GLTexture * m_placeholder_texture { nullptr }
bool m_is_dark { false }
DailyTipsLayout m_layout
float m_fade_opacity { 1.0f }

Detailed Description

Constructor & Destructor Documentation

◆ DailyTipsDataRenderer()

Slic3r::GUI::DailyTipsDataRenderer::DailyTipsDataRenderer ( DailyTipsLayout layout)
61 : m_layout(layout)
62{
63}
DailyTipsLayout m_layout
Definition DailyTips.cpp:56

References m_layout.

◆ ~DailyTipsDataRenderer()

Slic3r::GUI::DailyTipsDataRenderer::~DailyTipsDataRenderer ( )
65 {
66 if (m_texture)
67 delete m_texture;
70}
GLTexture * m_placeholder_texture
Definition DailyTips.cpp:54
GLTexture * m_texture
Definition DailyTips.cpp:53

References m_placeholder_texture, and m_texture.

Member Function Documentation

◆ has_image()

bool Slic3r::GUI::DailyTipsDataRenderer::has_image ( ) const
139{
140 return !m_data.img_url.empty();
141}
DailyTipsData m_data
Definition DailyTips.cpp:52

References m_data.

Referenced by render(), and render_img().

Here is the caller graph for this function:

◆ load_texture_from_img_url()

void Slic3r::GUI::DailyTipsDataRenderer::load_texture_from_img_url ( const std::string url)
protected
79{
80 if (m_texture) {
81 delete m_texture;
82 m_texture = nullptr;
83 }
84 if (!url.empty()) {
85 m_texture = new GLTexture();
86 m_texture->load_from_file(Slic3r::resources_dir() + "/" + url, true, GLTexture::None, false);
87 }
88 else {
90 m_placeholder_texture = new GLTexture();
91 m_placeholder_texture->load_from_file(Slic3r::resources_dir() + "/images/dailytips_placeholder.png", true, GLTexture::None, false);
92 }
93 }
94}
@ None
Definition GLTexture.hpp:72
const std::string & resources_dir()
Definition utils.cpp:296

References m_placeholder_texture, m_texture, Slic3r::GUI::GLTexture::None, and Slic3r::resources_dir().

Referenced by update_data().

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

◆ on_change_color_mode()

void Slic3r::GUI::DailyTipsDataRenderer::on_change_color_mode ( bool is_dark)
144{
146}
static bool is_dark()
Definition TextureImportDialog.cpp:85
bool m_is_dark
Definition DailyTips.cpp:55

References is_dark(), and m_is_dark.

Here is the call graph for this function:

◆ open_wiki()

void Slic3r::GUI::DailyTipsDataRenderer::open_wiki ( ) const
protected
97{
98 if (!m_data.wiki_url.empty())
99 {
100 wxGetApp().open_browser_with_warning_dialog(m_data.wiki_url);
101 }
102}

References m_data.

Referenced by render_text().

Here is the caller graph for this function:

◆ render()

void Slic3r::GUI::DailyTipsDataRenderer::render ( const ImVec2 & pos,
const ImVec2 & size ) const
105{
106 ImGuiWrapper& imgui = *wxGetApp().imgui();
107 ImGuiWindow* parent_window = ImGui::GetCurrentWindow();
108 int window_flags = parent_window->Flags;
109 window_flags &= ~ImGuiWindowFlags_NoScrollbar;
110 window_flags &= ~ImGuiWindowFlags_NoScrollWithMouse;
111 std::string name = "##DailyTipsDataRenderer" + std::to_string(parent_window->ID);
112 ImGui::SetNextWindowPos(pos);
113 if (ImGui::BeginChild(name.c_str(), size, false, window_flags)) {
115 ImVec2 img_size(0, 0);
116 float img_text_gap = 0.0f;
117 if (has_image()) {
118 img_size = ImVec2(size.x, 9.0f / 16.0f * size.x);
119 render_img({0, 0}, img_size);
120 img_text_gap = ImGui::CalcTextSize("A").y;
121 }
122 render_text({ 0, img_size.y + img_text_gap }, size);
123 }
125 ImVec2 img_size(0, 0);
126 float img_text_gap = 0.0f;
127 if (has_image()) {
128 img_size = ImVec2(16.0f / 9.0f * size.y, size.y);
129 render_img({0, 0}, img_size);
130 img_text_gap = ImGui::CalcTextSize("A").y;
131 }
132 render_text({img_size.x + img_text_gap, 0}, {size.x - img_size.x - img_text_gap, size.y});
133 }
134 }
135 ImGui::EndChild();
136}
void render_img(const ImVec2 &start_pos, const ImVec2 &size) const
Definition DailyTips.cpp:153
bool has_image() const
Definition DailyTips.cpp:138
void render_text(const ImVec2 &start_pos, const ImVec2 &size) const
Definition DailyTips.cpp:177
@ Vertical
Definition DailyTips.hpp:17
@ Horizontal
Definition DailyTips.hpp:16

References has_image(), Slic3r::GUI::Horizontal, m_layout, render_img(), render_text(), and Slic3r::GUI::Vertical.

Here is the call graph for this function:

◆ render_img()

void Slic3r::GUI::DailyTipsDataRenderer::render_img ( const ImVec2 & start_pos,
const ImVec2 & size ) const
protected
154{
155 if (has_image())
156 ImGui::Image((ImTextureID)(intptr_t)m_texture->get_id(), size, ImVec2(0, 0), ImVec2(1, 1), m_is_dark ? ImVec4(0.8, 0.8, 0.8, m_fade_opacity) : ImVec4(1, 1, 1, m_fade_opacity));
157 // else {
158 // ImGui::Image((ImTextureID)(intptr_t)m_placeholder_texture->get_id(), size, ImVec2(0, 0), ImVec2(1, 1), m_is_dark ? ImVec4(0.8, 0.8, 0.8, m_fade_opacity) : ImVec4(1, 1, 1, m_fade_opacity));
159 // }
160}
float m_fade_opacity
Definition DailyTips.cpp:57

References has_image(), m_fade_opacity, m_is_dark, and m_texture.

Referenced by render().

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

◆ render_text()

void Slic3r::GUI::DailyTipsDataRenderer::render_text ( const ImVec2 & start_pos,
const ImVec2 & size ) const
protected
178{
179 ImGuiWrapper& imgui = *wxGetApp().imgui();
180
181 ImGui::PushStyleColor(ImGuiCol_Text, m_is_dark ? ImVec4(1.0f, 1.0f, 1.0f, 0.88f * m_fade_opacity) : ImVec4(38 / 255.0f, 46 / 255.0f, 48 / 255.0f, m_fade_opacity));
182 // main text
183 // first line is headline (for hint notification it must be divided by \n)
184 std::string title_line;
185 std::string content_lines;
186 size_t end_pos = m_data.main_text.find_first_of('\n');
187 if (end_pos != std::string::npos) {
188 title_line = m_data.main_text.substr(0, end_pos);
189 title_line = ImGui::ColorMarkerStart + title_line + ImGui::ColorMarkerEnd;
190 content_lines = m_data.main_text.substr(end_pos + 1);
191 }
192
193 ImGui::SetCursorPos(start_pos);
194 imgui.text(title_line);
195
196 bool is_zh = has_cjk(content_lines);
197 if (!is_zh) {
198 // problem in Chinese with spaces
199 ImGui::SetCursorPosX(start_pos.x);
200 imgui.text_wrapped(content_lines, size.x);
201 }
202 else {
203 Label* wrapped_text = new Label(wxGetApp().GetTopWindow());
204 wrapped_text->Hide();
205 wrapped_text->SetLabelText(wxString::FromUTF8(content_lines));
206 float wrap_width = size.x + ImGui::CalcTextSize("A").x * 5.0f;
207#ifdef __APPLE__
208 wrap_width /= 2.0f;
209#endif
210 wrapped_text->Wrap(wrap_width);
211 std::string wrapped_content_lines = wrapped_text->GetLabel().ToUTF8().data();
212 wrapped_text->Destroy();
213 ImGui::SetCursorPosX(start_pos.x);
214 imgui.text(wrapped_content_lines);
215 }
216
217 // wiki
218 if (!m_data.wiki_url.empty()) {
219 std::string tips_line = _u8L("For more information, please check out our Wiki");
220 std::string wiki_part_text = _u8L("Wiki");
221 std::string first_part_text = tips_line.substr(0, tips_line.find(wiki_part_text));
222 ImVec2 wiki_part_size = ImGui::CalcTextSize(wiki_part_text.c_str());
223 ImVec2 first_part_size = ImGui::CalcTextSize(first_part_text.c_str());
224
225 //text
226 ImGui::SetCursorPosX(start_pos.x);
227 ImVec2 link_start_pos = ImGui::GetCursorScreenPos();
228 imgui.text(first_part_text);
229
230 ImColor HyperColor = ImColor(0, 150, 136, (int)(255 * m_fade_opacity)).Value; // ORCA match color of hyperlinks
231 ImVec2 wiki_part_rect_min = ImVec2(link_start_pos.x + first_part_size.x, link_start_pos.y);
232 ImVec2 wiki_part_rect_max = wiki_part_rect_min + wiki_part_size;
233 ImGui::PushStyleColor(ImGuiCol_Text, HyperColor.Value);
234 ImGui::SetCursorScreenPos(wiki_part_rect_min);
235 imgui.text(wiki_part_text.c_str());
236 ImGui::PopStyleColor();
237
238 //click behavior
239 if (ImGui::IsMouseHoveringRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), true))
240 {
241 //underline
242 ImVec2 lineEnd = ImGui::GetItemRectMax();
243 lineEnd.y -= 2.0f;
244 ImVec2 lineStart = lineEnd;
245 lineStart.x = ImGui::GetItemRectMin().x;
246 ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, HyperColor);
247
248 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left))
249 open_wiki();
250 }
251 }
252 ImGui::PopStyleColor();
253}
void Wrap(int width)
Definition Label.cpp:366
void open_wiki() const
Definition DailyTips.cpp:96
bool has_cjk(const std::string &text)
Definition DailyTips.cpp:162
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::GUI::has_cjk(), m_data, m_fade_opacity, m_is_dark, open_wiki(), Slic3r::GUI::ImGuiWrapper::text(), Slic3r::GUI::ImGuiWrapper::text_wrapped(), and Label::Wrap().

Referenced by render().

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

◆ set_fade_opacity()

void Slic3r::GUI::DailyTipsDataRenderer::set_fade_opacity ( float opacity)
149{
150 m_fade_opacity = opacity;
151}

References m_fade_opacity.

◆ update_data()

void Slic3r::GUI::DailyTipsDataRenderer::update_data ( const DailyTipsData & data)
73{
74 m_data = data;
76}
void load_texture_from_img_url(const std::string url)
Definition DailyTips.cpp:78

References load_texture_from_img_url(), and m_data.

Here is the call graph for this function:

Member Data Documentation

◆ m_data

DailyTipsData Slic3r::GUI::DailyTipsDataRenderer::m_data
private

◆ m_fade_opacity

float Slic3r::GUI::DailyTipsDataRenderer::m_fade_opacity { 1.0f }
private
57{ 1.0f };

Referenced by render_img(), render_text(), and set_fade_opacity().

◆ m_is_dark

bool Slic3r::GUI::DailyTipsDataRenderer::m_is_dark { false }
private
55{ false };

Referenced by on_change_color_mode(), render_img(), and render_text().

◆ m_layout

DailyTipsLayout Slic3r::GUI::DailyTipsDataRenderer::m_layout
private

Referenced by DailyTipsDataRenderer(), and render().

◆ m_placeholder_texture

GLTexture* Slic3r::GUI::DailyTipsDataRenderer::m_placeholder_texture { nullptr }
private
54{ nullptr };

Referenced by ~DailyTipsDataRenderer(), and load_texture_from_img_url().

◆ m_texture

GLTexture* Slic3r::GUI::DailyTipsDataRenderer::m_texture { nullptr }
private

The documentation for this class was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DailyTips.cpp