minor changes to selection widget
This commit is contained in:
@@ -22,7 +22,7 @@ igl::opengl::glfw::imgui::SelectionPlugin usage:
|
||||
}
|
||||
IGL_INLINE bool SelectionPlugin::pre_draw()
|
||||
{
|
||||
if(!visible){ return false; }
|
||||
if(mode == OFF){ return false; }
|
||||
ImGuiMenu::pre_draw();
|
||||
return false;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ IGL_INLINE bool SelectionPlugin::post_draw()
|
||||
|
||||
IGL_INLINE bool SelectionPlugin::mouse_down(int button, int modifier)
|
||||
{
|
||||
if(mode == OFF){ return false;}
|
||||
if(mode == OFF || (modifier & IGL_MOD_ALT) ){ return false;}
|
||||
is_down = true;
|
||||
has_moved_since_down = false;
|
||||
if(!is_drawing)
|
||||
@@ -143,13 +143,11 @@ IGL_INLINE bool SelectionPlugin::mouse_move(int mouse_x, int mouse_y)
|
||||
|
||||
IGL_INLINE bool SelectionPlugin::key_pressed(unsigned int key, int modifiers)
|
||||
{
|
||||
const auto clear = [&]() { M.setZero(); L.clear(); is_drawing = false; is_down = false; };
|
||||
Mode old = mode;
|
||||
if(OFF_KEY.find(char(key)) != std::string::npos)
|
||||
{
|
||||
mode = OFF;
|
||||
return true;
|
||||
}
|
||||
if(LASSO_KEY.find(char(key)) != std::string::npos)
|
||||
mode = OFF;
|
||||
}else if(LASSO_KEY.find(char(key)) != std::string::npos)
|
||||
{
|
||||
if(mode == LASSO)
|
||||
{
|
||||
@@ -158,10 +156,7 @@ IGL_INLINE bool SelectionPlugin::key_pressed(unsigned int key, int modifiers)
|
||||
{
|
||||
mode = LASSO;
|
||||
}
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
if(MARQUEE_KEY.find(char(key)) != std::string::npos)
|
||||
}else if(MARQUEE_KEY.find(char(key)) != std::string::npos)
|
||||
{
|
||||
if(mode == RECTANGULAR_MARQUEE)
|
||||
{
|
||||
@@ -170,12 +165,24 @@ IGL_INLINE bool SelectionPlugin::key_pressed(unsigned int key, int modifiers)
|
||||
{
|
||||
mode = RECTANGULAR_MARQUEE;
|
||||
}
|
||||
}
|
||||
if(old != mode)
|
||||
{
|
||||
clear();
|
||||
if(callback_post_mode_change){ callback_post_mode_change(old); }
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
IGL_INLINE void SelectionPlugin::clear()
|
||||
{
|
||||
M.setZero();
|
||||
L.clear();
|
||||
is_drawing = false;
|
||||
is_down = false;
|
||||
};
|
||||
|
||||
IGL_INLINE void SelectionPlugin::circle(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L)
|
||||
{
|
||||
L.clear();
|
||||
|
||||
@@ -13,25 +13,6 @@ namespace igl{ namespace opengl{ namespace glfw{ namespace imgui{
|
||||
class SelectionPlugin: public igl::opengl::glfw::imgui::ImGuiMenu
|
||||
{
|
||||
public:
|
||||
// callback called when slection is completed (usually on mouse_up)
|
||||
std::function<void(void)> callback;
|
||||
// whether rotating, translating or scaling
|
||||
ImGuizmo::OPERATION operation;
|
||||
// stored transformation
|
||||
Eigen::Matrix4f T;
|
||||
// Initilize with rotate operation on an identity transform (at origin)
|
||||
SelectionPlugin():operation(ImGuizmo::ROTATE),T(Eigen::Matrix4f::Identity()){};
|
||||
IGL_INLINE virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
|
||||
IGL_INLINE virtual bool pre_draw() override;
|
||||
IGL_INLINE virtual bool post_draw() override;
|
||||
IGL_INLINE virtual bool mouse_down(int button, int modifier) override;
|
||||
IGL_INLINE virtual bool mouse_up(int button, int modifier) override;
|
||||
IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) override;
|
||||
IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) override;
|
||||
// helpers
|
||||
IGL_INLINE static void circle(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
|
||||
IGL_INLINE static void rect(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
|
||||
IGL_INLINE static Eigen::RowVector2f xy(const Viewer * v);
|
||||
// customizable hotkeys
|
||||
std::string MARQUEE_KEY = "Mm";
|
||||
// leave 'L' for show_lines in viewer
|
||||
@@ -46,7 +27,6 @@ public:
|
||||
LASSO = 4,
|
||||
NUM_MODES = 5
|
||||
} mode = RECTANGULAR_MARQUEE;
|
||||
bool visible = true;
|
||||
bool is_down = false;
|
||||
bool has_moved_since_down = false;
|
||||
bool is_drawing = false;
|
||||
@@ -54,6 +34,30 @@ public:
|
||||
Eigen::Matrix<float,2,2> M = Eigen::Matrix<float,2,2>::Zero();
|
||||
// list of points of 2D lasso marquee
|
||||
std::vector<Eigen::RowVector2f> L;
|
||||
// callback called when slection is completed (usually on mouse_up)
|
||||
std::function<void(void)> callback;
|
||||
// callback called after mode is changed
|
||||
std::function<void(Mode)> callback_post_mode_change;
|
||||
// whether rotating, translating or scaling
|
||||
ImGuizmo::OPERATION operation;
|
||||
// stored transformation
|
||||
Eigen::Matrix4f T;
|
||||
// Initilize with rotate operation on an identity transform (at origin)
|
||||
SelectionPlugin():operation(ImGuizmo::ROTATE),T(Eigen::Matrix4f::Identity()){};
|
||||
IGL_INLINE virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
|
||||
IGL_INLINE virtual bool pre_draw() override;
|
||||
IGL_INLINE virtual bool post_draw() override;
|
||||
IGL_INLINE virtual bool mouse_down(int button, int modifier) override;
|
||||
IGL_INLINE virtual bool mouse_up(int button, int modifier) override;
|
||||
IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) override;
|
||||
IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) override;
|
||||
IGL_INLINE void clear();
|
||||
// helpers
|
||||
IGL_INLINE static void circle(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
|
||||
IGL_INLINE static void rect(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
|
||||
IGL_INLINE static Eigen::RowVector2f xy(const Viewer * v);
|
||||
public:
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
Reference in New Issue
Block a user