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>
|
|
|
|
|
2018-10-03 09:34:39 +00:00
|
|
|
#include "GLTexture.hpp"
|
|
|
|
#include "Event.hpp"
|
2019-03-20 13:36:36 +00:00
|
|
|
#include "libslic3r/Point.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;
|
|
|
|
|
2018-10-03 09:34:39 +00:00
|
|
|
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);
|
2019-04-11 11:20:34 +00:00
|
|
|
wxDECLARE_EVENT(EVT_GLTOOLBAR_COPY, SimpleEvent);
|
|
|
|
wxDECLARE_EVENT(EVT_GLTOOLBAR_PASTE, SimpleEvent);
|
2018-10-03 09:34:39 +00:00
|
|
|
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);
|
2018-10-03 09:34:39 +00:00
|
|
|
wxDECLARE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent);
|
2018-09-17 10:15:11 +00:00
|
|
|
|
2018-12-06 09:38:19 +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:
|
2019-03-14 12:54:05 +00:00
|
|
|
typedef std::function<void()> ActionCallback;
|
|
|
|
typedef std::function<bool()> VisibilityCallback;
|
|
|
|
typedef std::function<bool()> EnabledStateCallback;
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
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;
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
2019-02-26 09:40:00 +00:00
|
|
|
std::string icon_filename;
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-07-31 10:25:00 +00:00
|
|
|
std::string tooltip;
|
|
|
|
unsigned int sprite_id;
|
|
|
|
bool is_toggable;
|
2019-01-31 12:19:26 +00:00
|
|
|
bool visible;
|
2019-03-14 12:54:05 +00:00
|
|
|
ActionCallback action_callback;
|
|
|
|
VisibilityCallback visibility_callback;
|
|
|
|
EnabledStateCallback enabled_state_callback;
|
2018-07-31 10:25:00 +00:00
|
|
|
|
|
|
|
Data();
|
|
|
|
};
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
static const ActionCallback Default_Action_Callback;
|
|
|
|
static const VisibilityCallback Default_Visibility_Callback;
|
|
|
|
static const EnabledStateCallback Default_Enabled_State_Callback;
|
|
|
|
|
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
|
|
|
|
2019-01-31 12:19:26 +00:00
|
|
|
EState get_state() const { return m_state; }
|
|
|
|
void set_state(EState state) { m_state = state; }
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2019-01-31 12:19:26 +00:00
|
|
|
const std::string& get_name() const { return m_data.name; }
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
2019-02-26 09:40:00 +00:00
|
|
|
const std::string& get_icon_filename() const { return m_data.icon_filename; }
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2019-01-31 12:19:26 +00:00
|
|
|
const std::string& get_tooltip() const { return m_data.tooltip; }
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
void do_action() { m_data.action_callback(); }
|
2018-07-27 10:08:33 +00:00
|
|
|
|
2019-01-31 12:19:26 +00:00
|
|
|
bool is_enabled() const { return m_state != Disabled; }
|
|
|
|
bool is_disabled() const { return m_state == Disabled; }
|
|
|
|
bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); }
|
|
|
|
bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); }
|
2018-07-27 12:38:19 +00:00
|
|
|
|
2019-01-31 12:19:26 +00:00
|
|
|
bool is_toggable() const { return m_data.is_toggable; }
|
|
|
|
bool is_visible() const { return m_data.visible; }
|
|
|
|
bool is_separator() const { return m_type == Separator; }
|
2018-07-31 10:25:00 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
// returns true if the state changes
|
|
|
|
bool update_visibility();
|
|
|
|
// returns true if the state changes
|
|
|
|
bool update_enabled_state();
|
|
|
|
|
2019-02-26 09:40:00 +00:00
|
|
|
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;
|
2018-07-31 10:25:00 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-26 09:40:00 +00:00
|
|
|
GLTexture::Quad_UVs get_uvs(unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const;
|
2019-03-14 12:54:05 +00:00
|
|
|
void set_visible(bool visible) { m_data.visible = visible; }
|
|
|
|
|
|
|
|
friend class GLToolbar;
|
2018-07-23 11:49:48 +00:00
|
|
|
};
|
|
|
|
|
2019-02-26 08:56:23 +00:00
|
|
|
#if !ENABLE_SVG_ICONS
|
2018-12-06 09:38:19 +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
|
|
|
struct Metadata
|
|
|
|
{
|
|
|
|
// path of the file containing the icons' texture
|
|
|
|
std::string filename;
|
|
|
|
// size of the square icons, in pixels
|
|
|
|
unsigned int icon_size;
|
|
|
|
|
|
|
|
Metadata();
|
|
|
|
};
|
2019-01-02 15:26:22 +00:00
|
|
|
|
2018-12-06 09:38:19 +00:00
|
|
|
GLTexture texture;
|
2018-12-17 09:55:14 +00:00
|
|
|
Metadata metadata;
|
|
|
|
};
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // !ENABLE_SVG_ICONS
|
2018-12-17 09:55:14 +00:00
|
|
|
|
|
|
|
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-06 09:38:19 +00:00
|
|
|
};
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
class GLToolbar
|
|
|
|
{
|
|
|
|
public:
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
static const float Default_Icons_Size;
|
|
|
|
#endif // ENABLE_SVG_ICONS
|
|
|
|
|
2018-12-17 09:55:14 +00:00
|
|
|
enum EType : unsigned char
|
|
|
|
{
|
|
|
|
Normal,
|
|
|
|
Radio,
|
|
|
|
Num_Types
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
EOrientation orientation;
|
2018-07-31 10:25:00 +00:00
|
|
|
float top;
|
|
|
|
float left;
|
2018-12-17 09:55:14 +00:00
|
|
|
float border;
|
2018-07-31 10:25:00 +00:00
|
|
|
float separator_size;
|
|
|
|
float gap_size;
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
float icons_size;
|
|
|
|
float scale;
|
|
|
|
#else
|
2018-12-17 10:11:49 +00:00
|
|
|
float icons_scale;
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-07-31 10:25:00 +00:00
|
|
|
|
2018-12-17 09:55:14 +00:00
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
bool dirty;
|
|
|
|
|
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
|
|
|
EType m_type;
|
2019-02-26 11:56:13 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
std::string m_name;
|
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-07-23 11:49:48 +00:00
|
|
|
bool m_enabled;
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
mutable GLTexture m_icons_texture;
|
|
|
|
mutable bool m_icons_texture_dirty;
|
|
|
|
#else
|
2018-07-31 10:25:00 +00:00
|
|
|
ItemsIconsTexture m_icons_texture;
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-12-17 09:55:14 +00:00
|
|
|
BackgroundTexture m_background_texture;
|
|
|
|
mutable Layout m_layout;
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2018-07-31 10:25:00 +00:00
|
|
|
ItemsList m_items;
|
2019-03-20 08:33:30 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
struct MouseCapture
|
|
|
|
{
|
|
|
|
bool left;
|
|
|
|
bool middle;
|
|
|
|
bool right;
|
2019-03-20 14:30:03 +00:00
|
|
|
GLCanvas3D* parent;
|
2019-03-14 12:54:05 +00:00
|
|
|
|
2019-03-25 07:48:41 +00:00
|
|
|
MouseCapture() { reset(); }
|
2019-03-22 13:35:26 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
bool any() const { return left || middle || right; }
|
2019-03-20 14:30:03 +00:00
|
|
|
void reset() { left = middle = right = false; parent = nullptr; }
|
2019-03-14 12:54:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MouseCapture m_mouse_capture;
|
|
|
|
std::string m_tooltip;
|
2018-07-23 11:49:48 +00:00
|
|
|
|
|
|
|
public:
|
2019-02-26 11:56:13 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
GLToolbar(EType type, const std::string& name);
|
|
|
|
#else
|
2018-12-17 09:55:14 +00:00
|
|
|
explicit GLToolbar(EType type);
|
2019-02-26 11:56:13 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-10-24 08:55:35 +00:00
|
|
|
~GLToolbar();
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
bool init(const BackgroundTexture::Metadata& background_texture);
|
|
|
|
#else
|
2018-12-17 09:55:14 +00:00
|
|
|
bool init(const ItemsIconsTexture::Metadata& icons_texture, const BackgroundTexture::Metadata& background_texture);
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
2018-12-17 09:55:14 +00:00
|
|
|
|
|
|
|
Layout::EType get_layout_type() const;
|
|
|
|
void set_layout_type(Layout::EType type);
|
|
|
|
Layout::EOrientation get_layout_orientation() const;
|
|
|
|
void set_layout_orientation(Layout::EOrientation orientation);
|
2018-07-31 10:25:00 +00:00
|
|
|
|
|
|
|
void set_position(float top, float left);
|
2018-12-17 09:55:14 +00:00
|
|
|
void set_border(float border);
|
2018-07-31 10:25:00 +00:00
|
|
|
void set_separator_size(float size);
|
|
|
|
void set_gap_size(float size);
|
2019-02-26 08:56:23 +00:00
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
void set_icons_size(float size);
|
|
|
|
void set_scale(float scale);
|
|
|
|
#else
|
2018-12-17 10:11:49 +00:00
|
|
|
void set_icons_scale(float scale);
|
2019-02-26 08:56:23 +00:00
|
|
|
#endif // ENABLE_SVG_ICONS
|
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-12-17 09:55:14 +00:00
|
|
|
void select_item(const std::string& name);
|
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
|
|
|
bool is_item_disabled(const std::string& name) const;
|
2019-01-31 12:19:26 +00:00
|
|
|
bool is_item_visible(const std::string& name) const;
|
2019-03-14 12:54:05 +00:00
|
|
|
|
|
|
|
const std::string& get_tooltip() const { return m_tooltip; }
|
|
|
|
|
|
|
|
|
|
|
|
// returns true if any item changed its state
|
|
|
|
bool update_items_state();
|
2018-07-27 10:08:33 +00:00
|
|
|
|
2018-12-17 09:55:14 +00:00
|
|
|
void render(const GLCanvas3D& parent) const;
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2019-03-14 12:54:05 +00:00
|
|
|
bool on_mouse(wxMouseEvent& evt, GLCanvas3D& parent);
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
private:
|
2018-12-17 09:55:14 +00:00
|
|
|
void calc_layout() const;
|
2018-08-24 10:32:14 +00:00
|
|
|
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;
|
2019-03-14 12:54:05 +00:00
|
|
|
void do_action(unsigned int item_id, GLCanvas3D& parent);
|
|
|
|
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
2018-12-17 09:55:14 +00:00
|
|
|
std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
|
|
|
std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
2019-03-14 12:54:05 +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 GLCanvas3D& parent) const;
|
2018-12-17 09:55:14 +00:00
|
|
|
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;
|
2019-02-26 08:56:23 +00:00
|
|
|
|
|
|
|
#if ENABLE_SVG_ICONS
|
|
|
|
bool generate_icons_texture() const;
|
|
|
|
#endif // ENABLE_SVG_ICONS
|
2019-03-14 12:54:05 +00:00
|
|
|
|
|
|
|
// returns true if any item changed its state
|
|
|
|
bool update_items_visibility();
|
|
|
|
// returns true if any item changed its state
|
|
|
|
bool update_items_enabled_state();
|
2018-12-06 09:38:19 +00:00
|
|
|
};
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLToolbar_hpp_
|