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

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

Collaboration diagram for Slic3r::GUI::GLToolbarItem:

Classes

struct  Data

Public Types

enum  EType : unsigned char {
  Action , Separator , ActionWithText , ActionWithTextImage ,
  SeparatorLine , Num_Types
}
enum  EActionType : unsigned char { Undefined , Left , Right , Num_Action_Types }
enum  EState : unsigned char {
  Normal , Pressed , Disabled , Hover ,
  HoverPressed , HoverDisabled , Num_States
}
enum  EHighlightState : unsigned char { HighlightedShown , HighlightedHidden , Num_Rendered_Highlight_States , NotHighlighted }
typedef std::function< void()> ActionCallback
typedef std::function< bool()> VisibilityCallback
typedef std::function< bool()> EnablingCallback
typedef std::function< void(float, float, float, float)> RenderCallback

Public Member Functions

 GLToolbarItem (EType type, const Data &data)
EState get_state () const
void set_state (EState state)
EHighlightState get_highlight () const
void set_highlight (EHighlightState state)
const std::string & get_name () const
const std::string & get_icon_filename () const
void set_icon_filename (const std::string &filename)
const std::string & get_tooltip () const
const std::string & get_additional_tooltip () const
void set_additional_tooltip (const std::string &text)
void set_tooltip (const std::string &text)
void do_left_action ()
void do_right_action ()
bool is_enabled () const
bool is_disabled () const
bool is_hovered () const
bool is_pressed () const
bool is_visible () const
bool is_separator () const
bool is_left_toggable () const
bool is_right_toggable () const
bool has_left_render_callback () const
bool has_right_render_callback () const
EActionType get_last_action_type () const
void reset_last_action_type ()
bool update_visibility ()
bool update_enabled_state ()
bool is_action () const
bool is_action_with_text () const
bool is_action_with_text_image () const
const std::string & get_button_text () const
void set_button_text (const std::string &text)
float get_extra_size_ratio () const
void set_extra_size_ratio (const float ratio)
void render_text (float left, float right, float bottom, float top) const
int generate_texture (wxFont &font)
int generate_image_texture ()
void render (unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
void render_window (float left, float right, float bottom, float top) const
void render_image (unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const

Public Attributes

float render_left_pos

Static Public Attributes

static const ActionCallback Default_Action_Callback = [](){}
static const VisibilityCallback Default_Visibility_Callback = []()->bool { return true; }
static const EnablingCallback Default_Enabling_Callback = []()->bool { return true; }
static const RenderCallback Default_Render_Callback = [](float, float, float, float){}

Private Member Functions

void set_visible (bool visible)

Private Attributes

EType m_type
EState m_state
Data m_data
EActionType m_last_action_type
EHighlightState m_highlight_state

Friends

class GLToolbar

Detailed Description

Member Typedef Documentation

◆ ActionCallback

typedef std::function<void()> Slic3r::GUI::GLToolbarItem::ActionCallback

◆ EnablingCallback

typedef std::function<bool()> Slic3r::GUI::GLToolbarItem::EnablingCallback

◆ RenderCallback

typedef std::function<void(float, float, float, float)> Slic3r::GUI::GLToolbarItem::RenderCallback

◆ VisibilityCallback

typedef std::function<bool()> Slic3r::GUI::GLToolbarItem::VisibilityCallback

Member Enumeration Documentation

◆ EActionType

Enumerator
Undefined 
Left 
Right 
Num_Action_Types 
85 {
87 Left,
88 Right,
90 };
@ Left
Definition GLToolbar.hpp:87
@ Undefined
Definition GLToolbar.hpp:86
@ Num_Action_Types
Definition GLToolbar.hpp:89
@ Right
Definition GLToolbar.hpp:88

◆ EHighlightState

Enumerator
HighlightedShown 
HighlightedHidden 
Num_Rendered_Highlight_States 
NotHighlighted 
104 {
109 };
@ HighlightedShown
Definition GLToolbar.hpp:105
@ NotHighlighted
Definition GLToolbar.hpp:108
@ HighlightedHidden
Definition GLToolbar.hpp:106
@ Num_Rendered_Highlight_States
Definition GLToolbar.hpp:107

◆ EState

enum Slic3r::GUI::GLToolbarItem::EState : unsigned char
Enumerator
Normal 
Pressed 
Disabled 
Hover 
HoverPressed 
HoverDisabled 
Num_States 
93 {
94 Normal,
95 Pressed,
97 Hover,
101 };
@ Pressed
Definition GLToolbar.hpp:95
@ Disabled
Definition GLToolbar.hpp:96
@ HoverPressed
Definition GLToolbar.hpp:98
@ Normal
Definition GLToolbar.hpp:94
@ Hover
Definition GLToolbar.hpp:97
@ HoverDisabled
Definition GLToolbar.hpp:99
@ Num_States
Definition GLToolbar.hpp:100

◆ EType

enum Slic3r::GUI::GLToolbarItem::EType : unsigned char
Enumerator
Action 
Separator 
ActionWithText 
ActionWithTextImage 
SeparatorLine 
Num_Types 
74 {
75 Action,
77 //BBS: GUI refactor: GLToolbar
82 };
@ Num_Types
Definition GLToolbar.hpp:81
@ ActionWithText
Definition GLToolbar.hpp:78
@ Separator
Definition GLToolbar.hpp:76
@ ActionWithTextImage
Definition GLToolbar.hpp:79
@ SeparatorLine
Definition GLToolbar.hpp:80
@ Action
Definition GLToolbar.hpp:75

Constructor & Destructor Documentation

◆ GLToolbarItem()

Slic3r::GUI::GLToolbarItem::GLToolbarItem ( GLToolbarItem::EType type,
const Data & data )
105 : m_type(type)
106 , m_state(Normal)
107 , m_data(data)
110{
111 render_left_pos = 0.0f;
112}
EState m_state
Definition GLToolbar.hpp:175
float render_left_pos
Definition GLToolbar.hpp:181
EType m_type
Definition GLToolbar.hpp:174
Data m_data
Definition GLToolbar.hpp:176
EActionType m_last_action_type
Definition GLToolbar.hpp:177
EHighlightState m_highlight_state
Definition GLToolbar.hpp:178

References m_data, m_highlight_state, m_last_action_type, m_state, m_type, Normal, NotHighlighted, render_left_pos, and Undefined.

Member Function Documentation

◆ do_left_action()

void Slic3r::GUI::GLToolbarItem::do_left_action ( )
inline
199{ m_last_action_type = Left; m_data.left.action_callback(); }

References Left, m_data, and m_last_action_type.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ do_right_action()

void Slic3r::GUI::GLToolbarItem::do_right_action ( )
inline
200{ m_last_action_type = Right; m_data.right.action_callback(); }

References m_data, m_last_action_type, and Right.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ generate_image_texture()

int Slic3r::GUI::GLToolbarItem::generate_image_texture ( )
168{
169 int ret = 0;
170 bool result = false;
172 return -1;
173
174 /* load default texture when image is empty */
175 if (m_data.image_data.empty()) {
176 std::string default_image = resources_dir() + "/images/default_thumbnail.svg";
177 result = m_data.image_texture.load_from_svg_file(default_image, true, false, false, m_data.image_width);
178 } else {
179 result = m_data.image_texture.load_from_raw_data(m_data.image_data, m_data.image_width, m_data.image_height);
180 }
181 if (!result)
182 ret = -1;
183
184 return ret;
185}
const std::string & resources_dir()
Definition utils.cpp:296

References ActionWithTextImage, generate_image_texture(), m_data, m_type, and Slic3r::resources_dir().

Referenced by generate_image_texture(), and Slic3r::GUI::GLToolbar::generate_image_textures().

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

◆ generate_texture()

int Slic3r::GUI::GLToolbarItem::generate_texture ( wxFont & font)
152{
153 int ret = 0;
154 bool result;
155
157 return -1;
158
159 result = m_data.text_texture.generate_from_text_string(m_data.button_text, font);
160 if (!result)
161 ret = -1;
162
163 return ret;
164}

References ActionWithText, ActionWithTextImage, generate_texture(), m_data, and m_type.

Referenced by Slic3r::GUI::GLToolbar::generate_button_text_textures(), and generate_texture().

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

◆ get_additional_tooltip()

const std::string & Slic3r::GUI::GLToolbarItem::get_additional_tooltip ( ) const
inline
195{ return m_data.additional_tooltip; }

References m_data.

◆ get_button_text()

const std::string & Slic3r::GUI::GLToolbarItem::get_button_text ( ) const
inline
227{ return m_data.button_text; }

References m_data.

◆ get_extra_size_ratio()

float Slic3r::GUI::GLToolbarItem::get_extra_size_ratio ( ) const
inline
229{ return m_data.extra_size_ratio; }

References m_data.

Referenced by Slic3r::GUI::GLToolbar::contains_mouse_horizontal(), and Slic3r::GUI::GLToolbar::contains_mouse_vertical().

Here is the caller graph for this function:

◆ get_highlight()

EHighlightState Slic3r::GUI::GLToolbarItem::get_highlight ( ) const
inline
188{ return m_highlight_state; }

References m_highlight_state.

◆ get_icon_filename()

const std::string & Slic3r::GUI::GLToolbarItem::get_icon_filename ( ) const
inline
192{ return m_data.icon_filename; }

References m_data.

◆ get_last_action_type()

EActionType Slic3r::GUI::GLToolbarItem::get_last_action_type ( ) const
inline
215{ return m_last_action_type; }

References m_last_action_type.

◆ get_name()

const std::string & Slic3r::GUI::GLToolbarItem::get_name ( ) const
inline
191{ return m_data.name; }

References m_data.

Referenced by Slic3r::GUI::GLToolbar::do_action(), and Slic3r::GUI::GLToolbar::render_arrow().

Here is the caller graph for this function:

◆ get_state()

EState Slic3r::GUI::GLToolbarItem::get_state ( ) const
inline
185{ return m_state; }

References m_state.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ get_tooltip()

const std::string & Slic3r::GUI::GLToolbarItem::get_tooltip ( ) const
inline
194{ return m_data.tooltip; }

References m_data.

◆ has_left_render_callback()

bool Slic3r::GUI::GLToolbarItem::has_left_render_callback ( ) const
inline
212{ return m_data.left.render_callback != nullptr; }

References m_data.

◆ has_right_render_callback()

bool Slic3r::GUI::GLToolbarItem::has_right_render_callback ( ) const
inline
213{ return m_data.right.render_callback != nullptr; }

References m_data.

◆ is_action()

bool Slic3r::GUI::GLToolbarItem::is_action ( ) const
inline
224{ return m_type == Action; }

References Action, and m_type.

◆ is_action_with_text()

bool Slic3r::GUI::GLToolbarItem::is_action_with_text ( ) const
inline
225{ return m_type == ActionWithText; }

References ActionWithText, and m_type.

Referenced by Slic3r::GUI::GLToolbar::contains_mouse_horizontal(), Slic3r::GUI::GLToolbar::contains_mouse_vertical(), and Slic3r::GUI::GLToolbar::generate_button_text_textures().

Here is the caller graph for this function:

◆ is_action_with_text_image()

bool Slic3r::GUI::GLToolbarItem::is_action_with_text_image ( ) const
inline
226{ return m_type == ActionWithTextImage; }

References ActionWithTextImage, and m_type.

Referenced by Slic3r::GUI::GLToolbar::contains_mouse_vertical(), Slic3r::GUI::GLToolbar::generate_button_text_textures(), and Slic3r::GUI::GLToolbar::generate_image_textures().

Here is the caller graph for this function:

◆ is_disabled()

bool Slic3r::GUI::GLToolbarItem::is_disabled ( ) const
inline
203{ return (m_state == Disabled) || (m_state == HoverDisabled); }

References Disabled, HoverDisabled, and m_state.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ is_enabled()

bool Slic3r::GUI::GLToolbarItem::is_enabled ( ) const
inline
202{ return (m_state != Disabled) && (m_state != HoverDisabled); }

References Disabled, HoverDisabled, and m_state.

Referenced by update_enabled_state(), and Slic3r::GUI::GLToolbar::update_items_enabled_state().

Here is the caller graph for this function:

◆ is_hovered()

bool Slic3r::GUI::GLToolbarItem::is_hovered ( ) const
inline
204{ return (m_state == Hover) || (m_state == HoverPressed) || (m_state == HoverDisabled); }

References Hover, HoverDisabled, HoverPressed, and m_state.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ is_left_toggable()

bool Slic3r::GUI::GLToolbarItem::is_left_toggable ( ) const
inline
209{ return m_data.left.toggable; }

References m_data.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ is_pressed()

bool Slic3r::GUI::GLToolbarItem::is_pressed ( ) const
inline
205{ return (m_state == Pressed) || (m_state == HoverPressed); }

References HoverPressed, m_state, and Pressed.

Referenced by Slic3r::GUI::GLToolbar::do_action(), and render_window().

Here is the caller graph for this function:

◆ is_right_toggable()

bool Slic3r::GUI::GLToolbarItem::is_right_toggable ( ) const
inline
210{ return m_data.right.toggable; }

References m_data.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ is_separator()

bool Slic3r::GUI::GLToolbarItem::is_separator ( ) const
inline
207{ return m_type == Separator; }

References m_type, and Separator.

Referenced by Slic3r::GUI::GLToolbar::contains_mouse_horizontal(), Slic3r::GUI::GLToolbar::contains_mouse_vertical(), Slic3r::GUI::GLToolbar::do_action(), and update_visibility().

Here is the caller graph for this function:

◆ is_visible()

bool Slic3r::GUI::GLToolbarItem::is_visible ( ) const
inline
206{ return m_data.visible; }

References m_data.

Referenced by Slic3r::GUI::GLToolbar::contains_mouse_horizontal(), Slic3r::GUI::GLToolbar::contains_mouse_vertical(), and Slic3r::GUI::GLCanvas3D::highlight_toolbar_item().

Here is the caller graph for this function:

◆ render()

void Slic3r::GUI::GLToolbarItem::render ( unsigned int tex_id,
float left,
float right,
float bottom,
float top,
unsigned int tex_width,
unsigned int tex_height,
unsigned int icon_size ) const
188{
189 auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs
190 {
191 assert((tex_width != 0) && (tex_height != 0));
192 GLTexture::Quad_UVs ret;
193 // tiles in the texture are spaced by 1 pixel
194 float icon_size_px = (float)(tex_width - 1) / ((float)Num_States + (float)Num_Rendered_Highlight_States);
196 float inv_tex_width = 1.0f / (float)tex_width;
197 float inv_tex_height = 1.0f / (float)tex_height;
198 // tiles in the texture are spaced by 1 pixel
199 float u_offset = 1.0f * inv_tex_width;
200 float v_offset = 1.0f * inv_tex_height;
201 float du = icon_size_px * inv_tex_width;
202 float dv = icon_size_px * inv_tex_height;
203 float left = u_offset + (float)render_state * du;
204 float right = left + du - u_offset;
205 float top = v_offset + (float)m_data.sprite_id * dv;
206 float bottom = top + dv - v_offset;
207 ret.left_top = { left, top };
208 ret.left_bottom = { left, bottom };
209 ret.right_bottom = { right, bottom };
210 ret.right_top = { right, top };
211 return ret;
212 };
213
214 GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size));
215}
static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs &uvs)
Definition GLTexture.cpp:715
@ right
Definition MarchingSquares.hpp:190
@ left
Definition MarchingSquares.hpp:188

References Slic3r::GUI::GLTexture::Quad_UVs::left_bottom, Slic3r::GUI::GLTexture::Quad_UVs::left_top, m_data, m_highlight_state, m_state, NotHighlighted, Num_Rendered_Highlight_States, Num_States, render(), Slic3r::GUI::GLTexture::render_sub_texture(), Slic3r::GUI::GLTexture::Quad_UVs::right_bottom, and Slic3r::GUI::GLTexture::Quad_UVs::right_top.

Referenced by render().

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

◆ render_image()

void Slic3r::GUI::GLToolbarItem::render_image ( unsigned int tex_id,
float left,
float right,
float bottom,
float top,
unsigned int tex_width,
unsigned int tex_height,
unsigned int icon_size ) const
229{
230 GLTexture::Quad_UVs image_uvs = { { 0.0f, 0.0f }, { 1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 1.0f } };
231 //GLTexture::Quad_UVs image_uvs = { { 0.0f, 1.0f }, { 1.0f, 1.0f }, { 1.0f, 0.0f }, { 0.0f, 0.0f } };
232
233 GLTexture::render_sub_texture(tex_id, left, right, bottom, top, image_uvs);
234}

References render_image(), and Slic3r::GUI::GLTexture::render_sub_texture().

Referenced by render_image().

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

◆ render_text()

void Slic3r::GUI::GLToolbarItem::render_text ( float left,
float right,
float bottom,
float top ) const
136{
137 float tex_width = (float)m_data.text_texture.get_width();
138 float tex_height = (float)m_data.text_texture.get_height();
139 //float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f;
140 //float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f;
141
142 float internal_left_uv = 0.0f;
143 float internal_right_uv = (float)m_data.text_texture.m_original_width / tex_width;
144 float internal_top_uv = 0.0f;
145 float internal_bottom_uv = (float)m_data.text_texture.m_original_height / tex_height;
146
147 GLTexture::render_sub_texture(m_data.text_texture.get_id(), left, right, bottom, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } });
148}

References m_data, and Slic3r::GUI::GLTexture::render_sub_texture().

Here is the call graph for this function:

◆ render_window()

void Slic3r::GUI::GLToolbarItem::render_window ( float left,
float right,
float bottom,
float top ) const
218{
219 if (is_pressed())
220 {
221 if ((m_last_action_type == Left) && m_data.left.can_render())
222 m_data.left.render_callback(left, right, bottom, top);
223 else if ((m_last_action_type == Right) && m_data.right.can_render())
224 m_data.right.render_callback(left, right, bottom, top);
225 }
226}
bool is_pressed() const
Definition GLToolbar.hpp:205

References is_pressed(), Left, m_data, m_last_action_type, render_window(), and Right.

Referenced by render_window().

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

◆ reset_last_action_type()

void Slic3r::GUI::GLToolbarItem::reset_last_action_type ( )
inline

References m_last_action_type, and Undefined.

Referenced by Slic3r::GUI::GLToolbar::do_action().

Here is the caller graph for this function:

◆ set_additional_tooltip()

void Slic3r::GUI::GLToolbarItem::set_additional_tooltip ( const std::string & text)
inline
196{ m_data.additional_tooltip = text; }

References m_data.

◆ set_button_text()

void Slic3r::GUI::GLToolbarItem::set_button_text ( const std::string & text)
inline
228{ m_data.button_text = text; }

References m_data.

◆ set_extra_size_ratio()

void Slic3r::GUI::GLToolbarItem::set_extra_size_ratio ( const float ratio)
inline
230{ m_data.extra_size_ratio = ratio; }

References m_data.

◆ set_highlight()

void Slic3r::GUI::GLToolbarItem::set_highlight ( EHighlightState state)
inline
189{ m_highlight_state = state; }

References m_highlight_state.

◆ set_icon_filename()

void Slic3r::GUI::GLToolbarItem::set_icon_filename ( const std::string & filename)
inline
193{ m_data.icon_filename = filename; }

References m_data.

Referenced by Slic3r::GUI::GLCanvas3D::_switch_toolbars_icon_filename().

Here is the caller graph for this function:

◆ set_state()

void Slic3r::GUI::GLToolbarItem::set_state ( EState state)
inline
186{ m_state = state; }

References m_state.

Referenced by Slic3r::GUI::GLToolbar::do_action(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_variable_layer_height_dialog(), and Slic3r::GUI::GLToolbar::update_items_enabled_state().

Here is the caller graph for this function:

◆ set_tooltip()

void Slic3r::GUI::GLToolbarItem::set_tooltip ( const std::string & text)
inline
197{ m_data.tooltip = text; }

References m_data.

◆ set_visible()

void Slic3r::GUI::GLToolbarItem::set_visible ( bool visible)
inlineprivate
240{ m_data.visible = visible; }

References m_data.

◆ update_enabled_state()

bool Slic3r::GUI::GLToolbarItem::update_enabled_state ( )
125{
126 bool enabled = m_data.enabling_callback();
127 bool ret = (is_enabled() != enabled);
128 if (ret)
130
131 return ret;
132}
bool is_enabled() const
Definition GLToolbar.hpp:202

References Disabled, is_enabled(), m_data, m_state, and Normal.

Referenced by Slic3r::GUI::GLToolbar::update_items_enabled_state().

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

◆ update_visibility()

bool Slic3r::GUI::GLToolbarItem::update_visibility ( )
115{
116 bool visible = m_data.visibility_callback();
117 bool ret = (m_data.visible != visible);
118 if (ret)
119 m_data.visible = visible;
120 // Return false for separator as it would always return true.
121 return is_separator() ? false : ret;
122}
bool is_separator() const
Definition GLToolbar.hpp:207

References is_separator(), and m_data.

Here is the call graph for this function:

◆ GLToolbar

friend class GLToolbar
friend

References GLToolbar.

Referenced by GLToolbar.

Member Data Documentation

◆ Default_Action_Callback

const GLToolbarItem::ActionCallback Slic3r::GUI::GLToolbarItem::Default_Action_Callback = [](){}
static

◆ Default_Enabling_Callback

const GLToolbarItem::EnablingCallback Slic3r::GUI::GLToolbarItem::Default_Enabling_Callback = []()->bool { return true; }
static

◆ Default_Render_Callback

const GLToolbarItem::RenderCallback Slic3r::GUI::GLToolbarItem::Default_Render_Callback = [](float, float, float, float){}
static

◆ Default_Visibility_Callback

const GLToolbarItem::VisibilityCallback Slic3r::GUI::GLToolbarItem::Default_Visibility_Callback = []()->bool { return true; }
static

◆ m_data

◆ m_highlight_state

EHighlightState Slic3r::GUI::GLToolbarItem::m_highlight_state
private

◆ m_last_action_type

EActionType Slic3r::GUI::GLToolbarItem::m_last_action_type
private

◆ m_state

EState Slic3r::GUI::GLToolbarItem::m_state
private

◆ m_type

◆ render_left_pos

float Slic3r::GUI::GLToolbarItem::render_left_pos
mutable

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