mouse-wheel scroll-able list

tdev

03-06-2008 09:43:42

This patch enables the QuickGUIScrollPane to receive and act on Mouse Wheel events. So you can for example scroll with the mouse wheel in the ComboBox:


Index: QuickGUIScrollPane.cpp
===================================================================
--- QuickGUIScrollPane.cpp (revision 1172)
+++ QuickGUIScrollPane.cpp (working copy)
@@ -139,6 +139,7 @@
mManagedWidgets.insert(w);

w->addEventHandler(EVENT_MOUSE_BUTTON_DOWN,&ScrollPane::onChildClicked,this);
+ w->addEventHandler(EVENT_MOUSE_WHEEL,&ScrollPane::onMouseWheel,this);
w->addEventHandler(EVENT_POSITION_CHANGED,&ScrollPane::onChildPositionChanged,this);
w->addEventHandler(EVENT_SIZE_CHANGED,&ScrollPane::onChildSizeChanged,this);

@@ -198,6 +199,16 @@
scrollIntoView(dynamic_cast<const WidgetEventArgs&>(args).widget);
}

+ void ScrollPane::onMouseWheel(const EventArgs& args)
+ {
+ MouseEventArgs argsm = dynamic_cast<const MouseEventArgs&>(args);
+ if(argsm.wheelChange > 0 && mRightBar && mRightBar->isVisible())
+ mRightBar->scrollUpSmall();
+ else if(argsm.wheelChange < 0 && mRightBar && mRightBar->isVisible())
+ mRightBar->scrollDownSmall();
+ }
+
void ScrollPane::onChildPositionChanged(const EventArgs& args)
{
Widget* w = dynamic_cast<const WidgetEventArgs&>(args).widget;
Index: QuickGUIScrollPane.h
===================================================================
--- QuickGUIScrollPane.h (revision 1172)
+++ QuickGUIScrollPane.h (working copy)
@@ -95,7 +95,8 @@
void onParentSizeChanged(const EventArgs& args);
void onHorizontalScroll(const EventArgs& args);
void onVerticalScroll(const EventArgs& args);
-
+ void onMouseWheel(const EventArgs& args);
+
void _showHScrollBars();
void _showVScrollBars();
void _syncBarWithParentDimensions();


i hope i added it at the right location :)
the vertical scrollbar should also get those handlers one day.

also, do not forget to inject mouse wheel changes:


bool myClass::mouseMoved(const OIS::MouseEvent &arg)
{
mGUIManager->injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
if(arg.state.Z.rel != 0)
mGUIManager->injectMouseWheelChange(arg.state.Z.rel);
return true;
}


there is a visual artifact when you scroll: the highlight get not updated. I tried to solve that by back propagating the wheel event, but no luck so far :(

tdev

03-06-2008 10:48:30

updated, improved mouse wheel usage, so you can now hover the mouse on the entry and scroll through the entries. It also includes the patch from above. Highlighting on scroll not fixed :(


Index: QuickGUIComboBox.cpp
===================================================================
--- QuickGUIComboBox.cpp (revision 1172)
+++ QuickGUIComboBox.cpp (working copy)
@@ -23,6 +23,7 @@
addEventHandler(EVENT_MOUSE_LEAVE,&ComboBox::onMouseLeaves,this);
addEventHandler(EVENT_MOUSE_BUTTON_UP,&ComboBox::onMouseButtonUp,this);
addEventHandler(EVENT_MOUSE_BUTTON_DOWN,&ComboBox::onMouseButtonDown,this);
+ addEventHandler(EVENT_MOUSE_WHEEL,&ComboBox::onMouseWheel,this);

mTextHelper = new TextHelper();

@@ -42,6 +43,7 @@
mList->setPropagateEventFiring(EVENT_MOUSE_BUTTON_DOWN,true);
mList->setPropagateEventFiring(EVENT_MOUSE_ENTER,true);
mList->setPropagateEventFiring(EVENT_MOUSE_LEAVE,true);
+ mList->setPropagateEventFiring(EVENT_MOUSE_WHEEL,true);

mMenuLabel = dynamic_cast<MenuLabel*>(_createComponent(mInstanceName+".SelectedItem",TYPE_MENULABEL));
mMenuLabel->setSize(mSize.width - mSize.height,mSize.height);
@@ -51,6 +53,8 @@
mMenuLabel->setPropagateEventFiring(EVENT_LOSE_FOCUS,true);
mMenuLabel->setPropagateEventFiring(EVENT_MOUSE_ENTER,true);
mMenuLabel->setPropagateEventFiring(EVENT_MOUSE_LEAVE,true);
+ mMenuLabel->setPropagateEventFiring(EVENT_MOUSE_WHEEL,true);
+ mMenuLabel->setHorizontalAlignment(QuickGUI::Label::HA_LEFT);

mButton = dynamic_cast<Button*>(_createComponent(mInstanceName+".DropDownButton",TYPE_BUTTON));
mButton->setSkinComponent(".combobox.button");
@@ -73,7 +77,52 @@
// offset + 3, to be able to show over ListItems with Images and Buttons and Text
mHighlightPanel->setOffset(mOffset+3);
mHighlightPanel->_notifyQuadContainer(mQuadContainer);
+ mHighlightPanel->setClipMode(Quad::CLIPMODE_NONE);
}
+
+ void ComboBox::onMouseWheel(const EventArgs& args)
+ {
+ const MouseEventArgs& mea = dynamic_cast<const MouseEventArgs&>(args);
+ if(mea.widget->getInstanceName() == mInstanceName+".SelectedItem")
+ {
+ int i = getSelectedItemIndex();
+ if(mea.wheelChange > 0)
+ {
+ if(i == 0)
+ i = getNumberOfItems()-1;
+ else
+ i--;
+ selectItem(i);
+ EventHandlerArray::iterator it;
+ for( it = mOnSelectUserEventHandlers.begin(); it != mOnSelectUserEventHandlers.end(); ++it )
+ (*it)->execute(args);
+ } else
+ {
+ if(i == getNumberOfItems()-1)
+ i = 0;
+ else
+ i++;
+ selectItem(i);
+ EventHandlerArray::iterator it;
+ for( it = mOnSelectUserEventHandlers.begin(); it != mOnSelectUserEventHandlers.end(); ++it )
+ (*it)->execute(args);
+ }
+ }
+ highlightListItem(dynamic_cast<MenuLabel*>(mea.widget));
+ }
+
+ void ComboBox::setSkinComponent(const std::string& skinComponent)
+ {
+ Widget::setSkinComponent(skinComponent);
+ mMenuLabel->setSkinComponent(skinComponent);
+ mList->setSkinComponent(skinComponent+".list");
+ mButton->setSkinComponent(skinComponent+".button");
+
+ // mHighlightPanel skin
+ SkinSet* ss = SkinSetManager::getSingleton().getSkinSet(mSkinName);
+ mHighlightPanel->setMaterial(ss->getMaterialName());
+ mHighlightPanel->setTextureCoordinates(ss->getTextureCoordinates(mSkinName + skinComponent + ".highlight" + ss->getImageExtension()));
+ }

ComboBox::~ComboBox()
{
Index: ../include/QuickGUIComboBox.h
===================================================================
--- ../include/QuickGUIComboBox.h (revision 1172)
+++ ../include/QuickGUIComboBox.h (working copy)
@@ -80,7 +80,7 @@
virtual void setSize(const Size& pixelSize);
virtual void setSkin(const std::string& skinName, bool recursive = false);
void setVerticalPixelPadHeight(unsigned int height);
-
+ void setSkinComponent(const std::string& skinComponent);
protected:
virtual ~ComboBox();

@@ -101,6 +101,7 @@
void onMouseButtonDown(const EventArgs& args);
void onMouseEnters(const EventArgs& args);
void onMouseLeaves(const EventArgs& args);
+ void onMouseWheel(const EventArgs& args);
/**
* Specific Handler for the ComboBox Widget. Called when the user selects a ListItem
*/