use mouse wheel to scroll through scroll list
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7838 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 4892590c361ed8f40d9b2f925f1d68a50ec4afc1 Former-commit-id: c723ee506124056a6a4b1ea34b22db37b2c35526
This commit is contained in:
parent
6ea9cf4c33
commit
0a1266e415
7 changed files with 112 additions and 31 deletions
|
@ -593,6 +593,14 @@ gfuiMousePassiveMotion(int x, int y)
|
|||
GfuiApp().eventLoop().postRedisplay();
|
||||
}
|
||||
|
||||
static void
|
||||
gfuiMouseWheel(int x, int y, unsigned int direction)
|
||||
{
|
||||
gfuiUpdateFocus();
|
||||
gfuiMouseWheelAction(x, y, direction);
|
||||
GfuiApp().eventLoop().postRedisplay();
|
||||
}
|
||||
|
||||
/** Tell if the screen is active or not.
|
||||
@ingroup gui
|
||||
@param screen Screen to activate
|
||||
|
@ -635,6 +643,7 @@ GfuiScreenActivate(void *screen)
|
|||
GfuiApp().eventLoop().setMouseButtonCB(gfuiMouseButton);
|
||||
GfuiApp().eventLoop().setMouseMotionCB(gfuiMouseMotion);
|
||||
GfuiApp().eventLoop().setMousePassiveMotionCB(gfuiMousePassiveMotion);
|
||||
GfuiApp().eventLoop().setMouseWheelCB(gfuiMouseWheel);
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
|
||||
if (GfuiScreen->onlyCallback == 0)
|
||||
|
@ -692,6 +701,7 @@ GfuiScreenDeactivate(void)
|
|||
GfuiApp().eventLoop().setMouseButtonCB(0);
|
||||
GfuiApp().eventLoop().setMouseMotionCB(0);
|
||||
GfuiApp().eventLoop().setMousePassiveMotionCB(0);
|
||||
GfuiApp().eventLoop().setMouseWheelCB(0);
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
GfuiApp().eventLoop().setRedisplayCB(GfuiDisplayNothing);
|
||||
}
|
||||
|
|
|
@ -364,6 +364,7 @@ extern void GfuiDraw(tGfuiObject *obj);;
|
|||
extern void gfuiUpdateFocus();
|
||||
extern void gfuiDrawString(int x, int y, GfuiFontClass *font, const char *string);
|
||||
extern void gfuiMouseAction(void *action);
|
||||
extern void gfuiMouseWheelAction(int x, int y, unsigned int direction);
|
||||
extern void gfuiSelectNext(void *);
|
||||
extern void gfuiSelectPrev(void *);
|
||||
extern void gfuiSelectId(void *scr, int id);
|
||||
|
@ -376,6 +377,7 @@ extern void gfuiButtonAction(int action);
|
|||
extern void gfuiEditboxAction(int action);
|
||||
extern void gfuiGrButtonAction(int action);
|
||||
extern void gfuiScrollListAction(int mouse);
|
||||
extern void gfuiScrollListWheelAction(int x, int y, unsigned int direction);
|
||||
extern void gfuiComboboxAction(int mouse);
|
||||
|
||||
extern void gfuiDrawLabel(tGfuiObject *obj);
|
||||
|
@ -423,6 +425,9 @@ extern void gfuiEditboxKey(tGfuiObject *obj, int key, int modifier);
|
|||
extern void gfuiScrollListNextElt (tGfuiObject *object);
|
||||
extern void gfuiScrollListPrevElt (tGfuiObject *object);
|
||||
|
||||
extern void gfuiScrollBarPlus(tGfuiObject *object);
|
||||
extern void gfuiScrollBarMinus(tGfuiObject *object);
|
||||
|
||||
extern void gfuiReleaseImage(tGfuiObject *obj);
|
||||
extern void gfuiDrawImage(tGfuiObject *obj);
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ class GfuiEventLoop::Private
|
|||
void (*cbMouseButton)(int button, int state, int x, int y);
|
||||
void (*cbMouseMotion)(int x, int y);
|
||||
void (*cbMousePassiveMotion)(int x, int y);
|
||||
void (*cbMouseWheel)(int x, int y, unsigned int direction);
|
||||
#if SDL_JOYSTICK
|
||||
void (*cbJoystickAxis)(int joy, int axis, float value);
|
||||
void (*cbJoystickButton)(int joy, int button, int value);
|
||||
|
@ -56,7 +57,7 @@ class GfuiEventLoop::Private
|
|||
};
|
||||
|
||||
GfuiEventLoop::Private::Private()
|
||||
: cbMouseButton(0), cbMouseMotion(0), cbMousePassiveMotion(0),
|
||||
: cbMouseButton(0), cbMouseMotion(0), cbMousePassiveMotion(0), cbMouseWheel(0),
|
||||
#if SDL_JOYSTICK
|
||||
cbJoystickAxis(0), cbJoystickButton(0),
|
||||
#endif
|
||||
|
@ -118,6 +119,13 @@ void GfuiEventLoop::injectMouseButtonEvent(int button, int state, int x, int y)
|
|||
if (_pPrivate->cbMouseButton)
|
||||
_pPrivate->cbMouseButton(button, state, x, y);
|
||||
}
|
||||
|
||||
void GfuiEventLoop::injectMouseWheelEvent(int x, int y, unsigned int direction)
|
||||
{
|
||||
if (_pPrivate->cbMouseWheel)
|
||||
_pPrivate->cbMouseWheel(x, y, direction);
|
||||
}
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
void GfuiEventLoop::injectJoystickAxisEvent(int joy, int axis, float value)
|
||||
{
|
||||
|
@ -188,13 +196,16 @@ void GfuiEventLoop::operator()()
|
|||
injectMouseMotionEvent(event.motion.state, event.motion.x, event.motion.y);
|
||||
break;
|
||||
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
injectMouseButtonEvent(event.button.button, event.button.state,
|
||||
event.button.x, event.button.y);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
injectMouseWheelEvent(event.wheel.x, event.wheel.y, event.wheel.direction);
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
postQuit();
|
||||
break;
|
||||
|
@ -241,6 +252,11 @@ void GfuiEventLoop::setMouseMotionCB(void (*func)(int x, int y))
|
|||
_pPrivate->cbMouseMotion = func;
|
||||
}
|
||||
|
||||
void GfuiEventLoop::setMouseWheelCB(void (*func)(int x, int y, unsigned int direction))
|
||||
{
|
||||
_pPrivate->cbMouseWheel = func;
|
||||
}
|
||||
|
||||
void GfuiEventLoop::setMousePassiveMotionCB(void (*func)(int x, int y))
|
||||
{
|
||||
_pPrivate->cbMousePassiveMotion = func;
|
||||
|
|
|
@ -578,6 +578,21 @@ gfuiMouseAction(void *vaction)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfuiMouseWheelAction(int x, int y, unsigned int direction)
|
||||
{
|
||||
tGfuiObject *curObject;
|
||||
|
||||
curObject = GfuiScreen->hasFocus;
|
||||
if (curObject != NULL) {
|
||||
switch (curObject->widget) {
|
||||
case GFUI_SCROLLIST:
|
||||
gfuiScrollListWheelAction(x, y, direction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfuiAddObject(tGfuiScreen *screen, tGfuiObject *object)
|
||||
{
|
||||
|
|
|
@ -36,14 +36,11 @@ gfuiInitScrollBar(void)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gfuiScrollPlus(void *idv)
|
||||
void gfuiScrollBarPlus(tGfuiObject *object)
|
||||
{
|
||||
tGfuiObject *object;
|
||||
tGfuiScrollBar *scrollbar;
|
||||
tScrollBarInfo info;
|
||||
|
||||
object = gfuiGetObject(GfuiScreen, (long)idv);
|
||||
if (object == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,21 +48,19 @@ gfuiScrollPlus(void *idv)
|
|||
scrollbar->pos++;
|
||||
if (scrollbar->pos > scrollbar->max) {
|
||||
scrollbar->pos = scrollbar->max;
|
||||
} else if (scrollbar->onScroll != NULL) {
|
||||
}
|
||||
else if (scrollbar->onScroll != NULL) {
|
||||
info.pos = scrollbar->pos;
|
||||
info.userData = scrollbar->userData;
|
||||
scrollbar->onScroll(&info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gfuiScrollMinus(void *idv)
|
||||
void gfuiScrollBarMinus(tGfuiObject *object)
|
||||
{
|
||||
tGfuiObject *object;
|
||||
tGfuiScrollBar *scrollbar;
|
||||
tScrollBarInfo info;
|
||||
|
||||
object = gfuiGetObject(GfuiScreen, (long)idv);
|
||||
if (object == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -73,13 +68,26 @@ gfuiScrollMinus(void *idv)
|
|||
scrollbar->pos--;
|
||||
if (scrollbar->pos < scrollbar->min) {
|
||||
scrollbar->pos = scrollbar->min;
|
||||
} else if (scrollbar->onScroll != NULL) {
|
||||
}
|
||||
else if (scrollbar->onScroll != NULL) {
|
||||
info.pos = scrollbar->pos;
|
||||
info.userData = scrollbar->userData;
|
||||
scrollbar->onScroll(&info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gfuiScrollPlus(void *idv)
|
||||
{
|
||||
gfuiScrollBarPlus(gfuiGetObject(GfuiScreen, (long)idv));
|
||||
}
|
||||
|
||||
static void
|
||||
gfuiScrollMinus(void *idv)
|
||||
{
|
||||
gfuiScrollBarMinus(gfuiGetObject(GfuiScreen, (long)idv));
|
||||
}
|
||||
|
||||
/** Create a new scroll bar.
|
||||
@ingroup gui
|
||||
@param scr Screen where to create the scroll bar
|
||||
|
|
|
@ -698,6 +698,27 @@ gfuiScrollListAction(int mouse)
|
|||
scrollist->onSelect(scrollist->userDataOnSelect);
|
||||
}
|
||||
|
||||
void
|
||||
gfuiScrollListWheelAction(int x, int y, unsigned int direction)
|
||||
{
|
||||
tGfuiObject *object = GfuiScreen->hasFocus;
|
||||
tGfuiObject *scrollBarObj = gfuiGetObject(GfuiScreen, object->u.scrollist.scrollBar);
|
||||
|
||||
if (!scrollBarObj)
|
||||
return;
|
||||
|
||||
if (y != 0)
|
||||
{
|
||||
// flip direction if needed
|
||||
if (direction == SDL_MOUSEWHEEL_FLIPPED)
|
||||
y *= -1;
|
||||
if (y > 0)
|
||||
gfuiScrollBarMinus(scrollBarObj);
|
||||
else
|
||||
gfuiScrollBarPlus(scrollBarObj);
|
||||
}
|
||||
}
|
||||
|
||||
/** Move the selected element within the scroll list.
|
||||
@ingroup gui
|
||||
@param scr Current screen
|
||||
|
|
|
@ -731,6 +731,9 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
|
|||
//! Set the "mouse motion without button pressed" callback function.
|
||||
void setMousePassiveMotionCB(void (*func)(int x, int y));
|
||||
|
||||
//! Set the "mouse wheel moved" callback function.
|
||||
void setMouseWheelCB(void (*func)(int x, int y, unsigned int direction));
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
//! Set the "joystick axis moved" callback function.
|
||||
void setJoystickAxisCB(void (*func)(int joy, int axis, float value));
|
||||
|
@ -763,6 +766,9 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
|
|||
//! Process a mouse button event.
|
||||
void injectMouseButtonEvent(int button, int state, int x, int y);
|
||||
|
||||
//! Process a mouse wheel event.
|
||||
void injectMouseWheelEvent(int x, int y, unsigned int direction);
|
||||
|
||||
#if SDL_JOYSTICK
|
||||
//! Process a joystick axis event.
|
||||
void injectJoystickAxisEvent(int joy, int axis, float value);
|
||||
|
|
Loading…
Reference in a new issue