Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for X1 and X2 mouse buttons. #1275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/osgGA/GUIEventAdapter
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public:
enum MouseButtonMask {
LEFT_MOUSE_BUTTON = 1<<0,
MIDDLE_MOUSE_BUTTON = 1<<1,
RIGHT_MOUSE_BUTTON = 1<<2
RIGHT_MOUSE_BUTTON = 1<<2,
X1_MOUSE_BUTTON = 1<<3,
X2_MOUSE_BUTTON = 1<<4
};

enum EventType {
Expand Down
28 changes: 28 additions & 0 deletions include/osgWidget/WindowManager
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
flag |= _leftDown ? osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON : 0;
flag |= _middleDown ? osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON: 0;
flag |= _rightDown ? osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON : 0;
flag |= _x1Down ? osgGA::GUIEventAdapter::X1_MOUSE_BUTTON : 0;
flag |= _x2Down ? osgGA::GUIEventAdapter::X2_MOUSE_BUTTON : 0;

return flag;
}
Expand Down Expand Up @@ -210,6 +212,14 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
return _rightDown;
}

bool isX1MouseButtonDown() const {
return _x1Down;
}

bool isX2MouseButtonDown() const {
return _x2Down;
}

bool isMouseScrollingUp() const {
return _scrolling == osgGA::GUIEventAdapter::SCROLL_UP;
}
Expand Down Expand Up @@ -263,6 +273,14 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
return _handleMousePushed(x, y, _rightDown);
}

bool mousePushedX1(float x, float y) {
return _handleMousePushed(x, y, _x1Down);
}

bool mousePushedX2(float x, float y) {
return _handleMousePushed(x, y, _x2Down);
}

bool mouseReleasedLeft(float x, float y) {
return _handleMouseReleased(x, y, _leftDown);
}
Expand All @@ -275,6 +293,14 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
return _handleMouseReleased(x, y, _rightDown);
}

bool mouseReleasedX1(float x, float y) {
return _handleMouseReleased(x, y, _x1Down);
}

bool mouseReleasedX2(float x, float y) {
return _handleMouseReleased(x, y, _x2Down);
}

// Keyboards wrappers, as above; takes the key and key's mask code, which
// can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}.
bool keyDown (int, int);
Expand Down Expand Up @@ -320,6 +346,8 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
bool _leftDown;
bool _middleDown;
bool _rightDown;
bool _x1Down;
bool _x2Down;

osgGA::GUIEventAdapter::ScrollingMotion _scrolling;

Expand Down
24 changes: 24 additions & 0 deletions src/osgGA/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ osgGA::GUIEventAdapter* EventQueue::mouseButtonPress(float x, float y, unsigned
case(3):
_accumulateEventState->setButtonMask(GUIEventAdapter::RIGHT_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
case(4):
_accumulateEventState->setButtonMask(GUIEventAdapter::X1_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
case(5):
_accumulateEventState->setButtonMask(GUIEventAdapter::X2_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
}

GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
Expand All @@ -268,6 +274,12 @@ osgGA::GUIEventAdapter* EventQueue::mouseButtonPress(float x, float y, unsigned
case(3):
event->setButton(GUIEventAdapter::RIGHT_MOUSE_BUTTON);
break;
case(4):
event->setButton(GUIEventAdapter::X1_MOUSE_BUTTON);
break;
case(5):
event->setButton(GUIEventAdapter::X2_MOUSE_BUTTON);
break;
}

addEvent(event);
Expand All @@ -291,6 +303,12 @@ osgGA::GUIEventAdapter* EventQueue::mouseDoubleButtonPress(float x, float y, uns
case(3):
_accumulateEventState->setButtonMask(GUIEventAdapter::RIGHT_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
case(4):
_accumulateEventState->setButtonMask(GUIEventAdapter::X1_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
case(5):
_accumulateEventState->setButtonMask(GUIEventAdapter::X2_MOUSE_BUTTON | _accumulateEventState->getButtonMask());
break;
}

GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
Expand Down Expand Up @@ -331,6 +349,12 @@ osgGA::GUIEventAdapter* EventQueue::mouseButtonRelease(float x, float y, unsigne
case(3):
_accumulateEventState->setButtonMask(~GUIEventAdapter::RIGHT_MOUSE_BUTTON & _accumulateEventState->getButtonMask());
break;
case(4):
_accumulateEventState->setButtonMask(~GUIEventAdapter::X1_MOUSE_BUTTON & _accumulateEventState->getButtonMask());
break;
case(5):
_accumulateEventState->setButtonMask(~GUIEventAdapter::X2_MOUSE_BUTTON & _accumulateEventState->getButtonMask());
break;
}

GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
Expand Down
2 changes: 2 additions & 0 deletions src/osgGA/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void Widget::updateFocus(osg::NodeVisitor& nv)
if (ea->getButtonMask()&osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::X1_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::X2_MOUSE_BUTTON) ++numButtonsPressed;

if (numButtonsPressed==1)
{
Expand Down
6 changes: 6 additions & 0 deletions src/osgPlugins/osc/OscSendingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ int OscSendingDevice::getButtonNum(const osgGA::GUIEventAdapter& ea)
case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:
return 3;
break;
case osgGA::GUIEventAdapter::X1_MOUSE_BUTTON:
return 4;
break;
case osgGA::GUIEventAdapter::X2_MOUSE_BUTTON:
return 5;
break;
default:
return -1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/osgUI/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void Widget::updateFocus(osg::NodeVisitor& nv)
if (ea->getButtonMask()&osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::X1_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::X2_MOUSE_BUTTON) ++numButtonsPressed;
}

bool previousFocus = _hasEventFocus;
Expand Down
12 changes: 12 additions & 0 deletions src/osgWidget/ViewerEventHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ bool MouseHandler::_handleMousePush(float x, float y, int button) {
&WindowManager::mousePushedMiddle
);

else if(button == osgGA::GUIEventAdapter::X1_MOUSE_BUTTON) return _doMouseEvent(
x,
y,
&WindowManager::mousePushedX1
);

else if(button == osgGA::GUIEventAdapter::X2_MOUSE_BUTTON) return _doMouseEvent(
x,
y,
&WindowManager::mousePushedX2
);

else return false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/osgWidget/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ _focusMode (PFM_FOCUS),
_leftDown (false),
_middleDown (false),
_rightDown (false),
_x1Down (false),
_x2Down (false),
_scrolling (osgGA::GUIEventAdapter::SCROLL_NONE),
_styleManager (new StyleManager()) {
_name = generateRandomName("WindowManager");
Expand Down Expand Up @@ -105,6 +107,8 @@ WindowManager::WindowManager(const WindowManager& wm, const osg::CopyOp& co):
_leftDown (false),
_middleDown (false),
_rightDown (false),
_x1Down (false),
_x2Down (false),
_scrolling (osgGA::GUIEventAdapter::SCROLL_NONE),
_styleManager (new StyleManager())
{
Expand Down Expand Up @@ -517,6 +521,8 @@ bool WindowManager::pointerMove(float x, float y) {
_leftDown = 0;
_middleDown = 0;
_rightDown = 0;
_x1Down = 0;
_x2Down = 0;

return false;
}
Expand Down