2018-07-23 11:49:48 +00:00
|
|
|
#ifndef slic3r_GLToolbar_hpp_
|
|
|
|
#define slic3r_GLToolbar_hpp_
|
|
|
|
|
|
|
|
#include "../../slic3r/GUI/GLTexture.hpp"
|
2018-07-27 10:08:33 +00:00
|
|
|
#include "../../libslic3r/Utils.hpp"
|
2018-07-23 11:49:48 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class Pointf;
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class GLCanvas3D;
|
|
|
|
|
|
|
|
class GLToolbarItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum EType : unsigned char
|
|
|
|
{
|
|
|
|
Action,
|
|
|
|
Separator,
|
|
|
|
Num_Types
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EState : unsigned char
|
|
|
|
{
|
|
|
|
Normal,
|
|
|
|
Hover,
|
|
|
|
Pressed,
|
2018-07-27 10:08:33 +00:00
|
|
|
HoverPressed,
|
2018-07-23 11:49:48 +00:00
|
|
|
Disabled,
|
|
|
|
Num_States
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
// icon textures are assumed to be square and all with the same size in pixels, no internal check is done
|
|
|
|
GLTexture m_icon_textures[Num_States];
|
|
|
|
|
|
|
|
EType m_type;
|
|
|
|
EState m_state;
|
|
|
|
|
|
|
|
std::string m_name;
|
|
|
|
std::string m_tooltip;
|
|
|
|
|
2018-07-27 10:08:33 +00:00
|
|
|
bool m_is_toggable;
|
|
|
|
PerlCallback* m_action_callback;
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
public:
|
2018-07-27 10:08:33 +00:00
|
|
|
GLToolbarItem(EType type, const std::string& name, const std::string& tooltip, bool is_toggable, PerlCallback* action_callback);
|
2018-07-23 11:49:48 +00:00
|
|
|
|
|
|
|
bool load_textures(const std::string* filenames);
|
|
|
|
|
|
|
|
EState get_state() const;
|
|
|
|
void set_state(EState state);
|
|
|
|
|
|
|
|
const std::string& get_name() const;
|
|
|
|
|
2018-07-25 08:01:17 +00:00
|
|
|
const std::string& get_tooltip() const;
|
2018-07-23 11:49:48 +00:00
|
|
|
|
|
|
|
unsigned int get_icon_texture_id() const;
|
|
|
|
int get_icon_textures_size() const;
|
|
|
|
|
2018-07-27 10:08:33 +00:00
|
|
|
void do_action();
|
|
|
|
|
|
|
|
bool is_enabled() const;
|
|
|
|
bool is_toggable() const;
|
2018-07-23 11:49:48 +00:00
|
|
|
bool is_separator() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLToolbar
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct ItemCreationData
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string tooltip;
|
2018-07-27 10:08:33 +00:00
|
|
|
bool is_toggable;
|
|
|
|
PerlCallback* action_callback;
|
2018-07-23 11:49:48 +00:00
|
|
|
std::string textures[GLToolbarItem::Num_States];
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::vector<GLToolbarItem*> ItemsList;
|
|
|
|
|
|
|
|
bool m_enabled;
|
|
|
|
ItemsList m_items;
|
|
|
|
|
|
|
|
float m_textures_scale;
|
|
|
|
float m_offset_y;
|
|
|
|
float m_gap_x;
|
|
|
|
float m_separator_x;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLToolbar();
|
|
|
|
|
|
|
|
bool is_enabled() const;
|
|
|
|
void set_enabled(bool enable);
|
|
|
|
|
|
|
|
void set_textures_scale(float scale);
|
|
|
|
void set_offset_y(float offset);
|
|
|
|
void set_gap_x(float gap);
|
|
|
|
void set_separator_x(float separator);
|
|
|
|
|
|
|
|
bool add_item(const ItemCreationData& data);
|
|
|
|
bool add_separator();
|
|
|
|
|
|
|
|
void enable_item(const std::string& name);
|
|
|
|
void disable_item(const std::string& name);
|
|
|
|
|
2018-07-27 10:08:33 +00:00
|
|
|
bool is_item_pressed(const std::string& name) const;
|
|
|
|
|
2018-07-25 08:01:17 +00:00
|
|
|
void update_hover_state(GLCanvas3D& canvas, const Pointf& mouse_pos);
|
2018-07-23 11:49:48 +00:00
|
|
|
|
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 GLCanvas3D& canvas, const Pointf& mouse_pos) const;
|
|
|
|
|
|
|
|
void do_action(unsigned int item_id, GLCanvas3D& canvas);
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
void render(const GLCanvas3D& canvas, const Pointf& mouse_pos) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
float _get_total_width() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLToolbar_hpp_
|