Skip to content

Commit

Permalink
Adding mouse wheel events, sent as a mouse down event mimmicking prev…
Browse files Browse the repository at this point in the history
…ious version of nme, value 3 and 4 as value.
  • Loading branch information
ruby0x1 committed Sep 17, 2013
1 parent 9279915 commit 267c456
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions project/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ class SDLStage : public Stage
this->SetCursor(mCurrentCursor);
}
}

void ConstrainCursorToWindowFrame(bool inLock)
{
if (inLock != mLockCursor)
{
mLockCursor = inLock;
SDL_SetRelativeMouseMode( inLock ? SDL_FALSE : SDL_TRUE );
}
}

//Note that this fires a mouse event, see the SDL_WarpMouseInWindow docs
void SetCursorPositionInWindow(int inX, int inY)
{
SDL_WarpMouseInWindow( mSDLWindow, inX, inY );
}


void EnablePopupKeyboard(bool enabled)
Expand Down Expand Up @@ -466,6 +481,7 @@ class SDLStage : public Stage
bool mIsOpenGL;
Cursor mCurrentCursor;
bool mShowCursor;
bool mLockCursor;
bool mIsFullscreen;
unsigned int mWindowFlags;
int mWidth;
Expand Down Expand Up @@ -741,6 +757,22 @@ void ProcessEvent(SDL_Event &inEvent)
sgSDLFrame->ProcessEvent(mouse);
break;
}
case SDL_MOUSEWHEEL:
{
//previous behavior in nme was 3 for down, 4 for up
int event_dir = (inEvent.wheel.y > 0) ? 3 : 4;
//space to get the current mouse position, to make sure the values are sane
int _x = 0;
int _y = 0;
//fetch the mouse position
SDL_GetMouseState(&_x,&_y);
//create the event
Event mouse(etMouseDown, _x, _y, event_dir);

This comment has been minimized.

Copy link
@codeservice

codeservice Sep 26, 2013

Contributor

Should be: etMouseUp not etMouseDown:
Event mouse(etMouseUp, _x, _y, event_dir);

Check Stage.hx:
...
else if (inType == MouseEvent.MOUSE_UP)
{
if (button > 2)
{
type = MouseEvent.MOUSE_WHEEL;
wheel = button == 3 ? 1 : -1;
...

//add flags for modifier keys
AddModStates(mouse.flags);
//and done.
sgSDLFrame->ProcessEvent(mouse);
}
case SDL_KEYDOWN:
case SDL_KEYUP:
{
Expand Down

4 comments on commit 267c456

@ruby0x1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I included the mouse constrain and position in this commit.

Note : This doesn't appear to be working properly with SDL2 yet, SDL_SetRelativeMouseMode (SDL_TRUE) is meant to hide, constrain, and reset the cursor each frame (the intended behavior) but it appears that SDL_FALSE provides this instead... passing true causes the mouse to be constrained to the window borders and set to invisible. It should remove the behavior entirely instead?

@ruby0x1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codeservice are you sure that's how it worked before? I was using the mouse wheel in my GUI and in a couple games and I mimicked existing behavior, if so that's cool! - I just always only saw them on down event

@codeservice
Copy link
Contributor

@codeservice codeservice commented on 267c456 Sep 27, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruby0x1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Please sign in to comment.