PrusaSlicer-NonPlainar/src/slic3r/GUI/GLToolbar.hpp

433 lines
12 KiB
C++
Raw Normal View History

2018-07-23 11:49:48 +00:00
#ifndef slic3r_GLToolbar_hpp_
#define slic3r_GLToolbar_hpp_
2018-09-17 10:15:11 +00:00
#include <functional>
2018-07-23 11:49:48 +00:00
#include <string>
#include <vector>
#include "GLTexture.hpp"
#include "Event.hpp"
2018-09-17 10:15:11 +00:00
class wxEvtHandler;
2018-07-23 11:49:48 +00:00
namespace Slic3r {
namespace GUI {
class GLCanvas3D;
wxDECLARE_EVENT(EVT_GLTOOLBAR_ADD, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_DELETE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_DELETE_ALL, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_ARRANGE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_MORE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent);
2018-10-24 10:55:38 +00:00
wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT_OBJECTS, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT_VOLUMES, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent);
2018-09-17 10:15:11 +00:00
wxDECLARE_EVENT(EVT_GLVIEWTOOLBAR_3D, SimpleEvent);
wxDECLARE_EVENT(EVT_GLVIEWTOOLBAR_PREVIEW, SimpleEvent);
2018-07-23 11:49:48 +00:00
class GLToolbarItem
{
public:
enum EType : unsigned char
{
Action,
Separator,
Num_Types
};
enum EState : unsigned char
{
Normal,
Pressed,
Disabled,
2018-07-31 10:25:00 +00:00
Hover,
HoverPressed,
2018-07-23 11:49:48 +00:00
Num_States
};
2018-07-31 10:25:00 +00:00
struct Data
{
std::string name;
std::string tooltip;
unsigned int sprite_id;
bool is_toggable;
2018-09-17 10:15:11 +00:00
wxEventType action_event;
2018-07-31 10:25:00 +00:00
Data();
};
2018-07-23 11:49:48 +00:00
2018-07-31 10:25:00 +00:00
private:
2018-07-23 11:49:48 +00:00
EType m_type;
EState m_state;
2018-07-31 10:25:00 +00:00
Data m_data;
2018-07-27 10:08:33 +00:00
2018-07-23 11:49:48 +00:00
public:
2018-07-31 10:25:00 +00:00
GLToolbarItem(EType type, const Data& data);
2018-07-23 11:49:48 +00:00
EState get_state() const;
void set_state(EState state);
const std::string& get_name() const;
const std::string& get_tooltip() const;
2018-07-23 11:49:48 +00:00
2018-09-17 10:15:11 +00:00
void do_action(wxEvtHandler *target);
2018-07-27 10:08:33 +00:00
bool is_enabled() const;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_disabled() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-27 12:38:19 +00:00
bool is_hovered() const;
bool is_pressed() const;
2018-07-27 10:08:33 +00:00
bool is_toggable() const;
2018-07-23 11:49:48 +00:00
bool is_separator() const;
2018-07-31 10:25:00 +00:00
void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;
private:
GLTexture::Quad_UVs get_uvs(unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;
2018-07-23 11:49:48 +00:00
};
// items icon textures are assumed to be square and all with the same size in pixels, no internal check is done
// icons are layed-out into the texture starting from the top-left corner in the same order as enum GLToolbarItem::EState
// from left to right
struct ItemsIconsTexture
{
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
struct Metadata
{
// path of the file containing the icons' texture
std::string filename;
// size of the square icons, in pixels
unsigned int icon_size;
// size of the border, in pixels
unsigned int icon_border_size;
// distance between two adjacent icons (to avoid filtering artifacts), in pixels
unsigned int icon_gap_size;
Metadata();
};
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
GLTexture texture;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Metadata metadata;
#else
// size of the square icons, in pixels
unsigned int items_icon_size;
// distance from the border, in pixels
unsigned int items_icon_border_size;
// distance between two adjacent icons (to avoid filtering artifacts), in pixels
unsigned int items_icon_gap_size;
ItemsIconsTexture();
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
};
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
struct BackgroundTexture
{
struct Metadata
{
// path of the file containing the background texture
std::string filename;
// size of the left edge, in pixels
unsigned int left;
// size of the right edge, in pixels
unsigned int right;
// size of the top edge, in pixels
unsigned int top;
// size of the bottom edge, in pixels
unsigned int bottom;
Metadata();
};
GLTexture texture;
Metadata metadata;
};
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
class GLToolbar
{
public:
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
enum EType : unsigned char
{
Normal,
Radio,
Num_Types
};
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
struct Layout
{
2018-12-17 09:55:14 +00:00
enum EType : unsigned char
2018-07-31 10:25:00 +00:00
{
Horizontal,
Vertical,
Num_Types
};
2018-12-17 09:55:14 +00:00
enum EOrientation : unsigned int
{
Top,
Bottom,
Left,
Right,
Center,
Num_Locations
};
EType type;
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
EOrientation orientation;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
float top;
float left;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float border;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
float separator_size;
float gap_size;
2018-12-17 10:11:49 +00:00
float icons_scale;
2018-07-31 10:25:00 +00:00
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float width;
float height;
bool dirty;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
Layout();
2018-07-23 11:49:48 +00:00
};
private:
typedef std::vector<GLToolbarItem*> ItemsList;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
EType m_type;
#else
2018-07-27 12:38:19 +00:00
GLCanvas3D& m_parent;
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
bool m_enabled;
2018-07-31 10:25:00 +00:00
ItemsIconsTexture m_icons_texture;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
BackgroundTexture m_background_texture;
mutable Layout m_layout;
#else
2018-07-31 10:25:00 +00:00
Layout m_layout;
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
2018-07-31 10:25:00 +00:00
ItemsList m_items;
2018-07-23 11:49:48 +00:00
public:
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
explicit GLToolbar(EType type);
#else
2018-07-27 12:38:19 +00:00
explicit GLToolbar(GLCanvas3D& parent);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-10-24 08:55:35 +00:00
~GLToolbar();
2018-07-23 11:49:48 +00:00
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool init(const ItemsIconsTexture::Metadata& icons_texture, const BackgroundTexture::Metadata& background_texture);
#else
2018-07-31 10:25:00 +00:00
bool init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Layout::EType get_layout_type() const;
void set_layout_type(Layout::EType type);
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
Layout::EOrientation get_layout_orientation() const;
void set_layout_orientation(Layout::EOrientation orientation);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
void set_position(float top, float left);
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void set_border(float border);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-31 10:25:00 +00:00
void set_separator_size(float size);
void set_gap_size(float size);
2018-12-17 10:11:49 +00:00
void set_icons_scale(float scale);
2018-07-31 10:25:00 +00:00
2018-07-23 11:49:48 +00:00
bool is_enabled() const;
void set_enabled(bool enable);
2018-07-31 10:25:00 +00:00
bool add_item(const GLToolbarItem::Data& data);
2018-07-23 11:49:48 +00:00
bool add_separator();
2018-07-31 10:25:00 +00:00
float get_width() const;
float get_height() const;
2018-07-23 11:49:48 +00:00
void enable_item(const std::string& name);
void disable_item(const std::string& name);
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void select_item(const std::string& name);
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
2018-07-27 10:08:33 +00:00
bool is_item_pressed(const std::string& name) const;
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
bool is_item_disabled(const std::string& name) const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-27 10:08:33 +00:00
#if ENABLE_REMOVE_TABS_FROM_PLATER
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
std::string update_hover_state(const Vec2d& mouse_pos);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#else
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
void update_hover_state(const Vec2d& mouse_pos);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
2018-07-23 11:49:48 +00:00
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
void do_action(unsigned int item_id, GLCanvas3D& parent);
#else
2018-07-27 10:08:33 +00:00
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos) const;
2018-07-27 10:08:33 +00:00
2018-07-27 12:38:19 +00:00
void do_action(unsigned int item_id);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-27 10:08:33 +00:00
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void render(const GLCanvas3D& parent) const;
#else
2018-07-31 10:25:00 +00:00
void render() const;
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
private:
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void calc_layout() const;
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
float get_width_horizontal() const;
float get_width_vertical() const;
float get_height_horizontal() const;
float get_height_vertical() const;
float get_main_size() const;
#if ENABLE_REMOVE_TABS_FROM_PLATER
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
std::string update_hover_state_horizontal(const Vec2d& mouse_pos);
std::string update_hover_state_vertical(const Vec2d& mouse_pos);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#else
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
void update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
void update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
#else
void update_hover_state_horizontal(const Vec2d& mouse_pos);
void update_hover_state_vertical(const Vec2d& mouse_pos);
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
2018-12-17 09:55:14 +00:00
#if ENABLE_TOOLBAR_BACKGROUND_TEXTURE
int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
void render_horizontal(const GLCanvas3D& parent) const;
void render_vertical(const GLCanvas3D& parent) const;
#else
int contains_mouse_horizontal(const Vec2d& mouse_pos) const;
int contains_mouse_vertical(const Vec2d& mouse_pos) const;
void render_horizontal() const;
void render_vertical() const;
2018-12-17 09:55:14 +00:00
#endif // ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
};
2018-12-17 09:55:14 +00:00
#if !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
class GLRadioToolbarItem
{
public:
struct Data
{
std::string name;
std::string tooltip;
unsigned int sprite_id;
wxEventType action_event;
Data();
};
enum EState : unsigned char
{
Normal,
Pressed,
Hover,
HoverPressed,
Num_States
};
private:
EState m_state;
Data m_data;
public:
GLRadioToolbarItem(const Data& data);
EState get_state() const;
void set_state(EState state);
const std::string& get_name() const;
const std::string& get_tooltip() const;
bool is_hovered() const;
bool is_pressed() const;
void do_action(wxEvtHandler *target);
void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;
private:
GLTexture::Quad_UVs get_uvs(unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;
};
class GLRadioToolbar
{
typedef std::vector<GLRadioToolbarItem*> ItemsList;
ItemsIconsTexture m_icons_texture;
ItemsList m_items;
float m_top;
float m_left;
public:
GLRadioToolbar();
~GLRadioToolbar();
bool init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size);
bool add_item(const GLRadioToolbarItem::Data& data);
float get_height() const;
void set_position(float top, float left);
void set_selection(const std::string& name);
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const;
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
void do_action(unsigned int item_id, GLCanvas3D& parent);
void render(const GLCanvas3D& parent) const;
};
2018-12-17 09:55:14 +00:00
#endif // !ENABLE_TOOLBAR_BACKGROUND_TEXTURE
2018-07-23 11:49:48 +00:00
} // namespace GUI
} // namespace Slic3r
#endif // slic3r_GLToolbar_hpp_