Browse Source

Add event::DoubleClick. Change ParamWidget reset to double-click.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
3830667543
7 changed files with 36 additions and 10 deletions
  1. +1
    -0
      include/app/ParamWidget.hpp
  2. +1
    -0
      include/app/Switch.hpp
  3. +9
    -0
      include/event.hpp
  4. +1
    -0
      include/widget/Widget.hpp
  5. +6
    -10
      src/app/ParamWidget.cpp
  6. +4
    -0
      src/app/Switch.cpp
  7. +14
    -0
      src/event.cpp

+ 1
- 0
include/app/ParamWidget.hpp View File

@@ -19,6 +19,7 @@ struct ParamWidget : widget::OpaqueWidget {
void step() override;
void draw(const widget::DrawContext &ctx) override;
void onButton(const event::Button &e) override;
void onDoubleClick(const event::DoubleClick &e) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;



+ 1
- 0
include/app/Switch.hpp View File

@@ -16,6 +16,7 @@ struct Switch : ParamWidget {
bool momentaryReleased = false;

void step() override;
void onDoubleClick(const event::DoubleClick &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
};


+ 9
- 0
include/event.hpp View File

@@ -86,6 +86,12 @@ struct Button : Event, Position {
};


/** Occurs when the left mouse button is pressed the second time within a time and position window.
*/
struct DoubleClick : Event {
};


/** Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget.
Recurses until consumed.
*/
@@ -246,6 +252,9 @@ struct State {
widget::Widget *selectedWidget = NULL;
/** For middle-click dragging */
widget::Widget *scrollWidget = NULL;
/** For double-clicking */
double lastClickTime = -INFINITY;
math::Vec lastClickPos;

void setHovered(widget::Widget *w);
void setDragged(widget::Widget *w);


+ 1
- 0
include/widget/Widget.hpp View File

@@ -122,6 +122,7 @@ struct Widget {
*/
virtual void onHover(const event::Hover &e) {recursePositionEvent(&Widget::onHover, e);}
virtual void onButton(const event::Button &e) {recursePositionEvent(&Widget::onButton, e);}
virtual void onDoubleClick(const event::DoubleClick &e) {}
virtual void onHoverKey(const event::HoverKey &e) {recursePositionEvent(&Widget::onHoverKey, e);}
virtual void onHoverText(const event::HoverText &e) {recursePositionEvent(&Widget::onHoverText, e);}
virtual void onHoverScroll(const event::HoverScroll &e) {recursePositionEvent(&Widget::onHoverScroll, e);}


+ 6
- 10
src/app/ParamWidget.cpp View File

@@ -90,7 +90,7 @@ struct ParamResetItem : ui::MenuItem {
ParamWidget *paramWidget;
ParamResetItem() {
text = "Initialize";
rightText = WINDOW_MOD_SHIFT_NAME "+Click";
rightText = "Double-click";
}
void onAction(const event::Action &e) override {
paramWidget->resetAction();
@@ -101,7 +101,7 @@ struct ParamResetItem : ui::MenuItem {
struct ParamFineItem : ui::MenuItem {
ParamFineItem() {
text = "Fine adjust";
rightText = WINDOW_MOD_CTRL_NAME "+Drag";
rightText = WINDOW_MOD_CTRL_NAME "+drag";
disabled = true;
}
};
@@ -149,18 +149,14 @@ void ParamWidget::onButton(const event::Button &e) {
e.consume(this);
}

// Shift-click to reset
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT) {
resetAction();
// HACK so that dragging won't occur
e.consume(NULL);
return;
}

if (!e.getConsumed())
widget::OpaqueWidget::onButton(e);
}

void ParamWidget::onDoubleClick(const event::DoubleClick &e) {
resetAction();
}

void ParamWidget::onEnter(const event::Enter &e) {
if (settings::paramTooltip && !tooltip && paramQuantity) {
ParamTooltip *paramTooltip = new ParamTooltip;


+ 4
- 0
src/app/Switch.cpp View File

@@ -23,6 +23,10 @@ void Switch::step() {
ParamWidget::step();
}

void Switch::onDoubleClick(const event::DoubleClick &e) {
// Don't reset parameter on double-click
}

void Switch::onDragStart(const event::DragStart &e) {
if (momentary) {
if (paramQuantity) {


+ 14
- 0
src/event.cpp View File

@@ -133,6 +133,20 @@ void State::handleButton(math::Vec pos, int button, int action, int mods) {
if (action == GLFW_PRESS) {
setSelected(clickedWidget);
}

if (action == GLFW_PRESS) {
const double doubleClickDuration = 0.5;
const float doubleClickDistance = 10;
double clickTime = glfwGetTime();
if (clickTime - lastClickTime <= doubleClickDuration && pos.minus(lastClickPos).norm() <= doubleClickDistance) {

// event::DoubleClick
event::DoubleClick eDoubleClick;
clickedWidget->onDoubleClick(eDoubleClick);
}
lastClickTime = clickTime;
lastClickPos = pos;
}
}

// if (button == GLFW_MOUSE_BUTTON_MIDDLE) {


Loading…
Cancel
Save