Added InputEvent::MouseWheel event. Also added onMouseWheel event for Node.

Enabled wheel scroll momentum for macOS on ecode.
This commit is contained in:
Martín Lucas Golini
2023-11-21 23:47:43 -03:00
parent 14d00ad813
commit ece0c2adde
9 changed files with 55 additions and 0 deletions
+2
View File
@@ -68,6 +68,8 @@ class EE_API EventDispatcher {
void sendMouseDown( Node* toNode, const Vector2i& pos, const Uint32 flags );
void sendMouseWheel( const Vector2f& offset, bool flipped );
const Uint32& getPressTrigger() const;
const Uint32& getLastPressTrigger() const;
+2
View File
@@ -495,6 +495,8 @@ class EE_API Node : public Transformable {
virtual Uint32 onMouseLeave( const Vector2i& position, const Uint32& flags );
virtual Uint32 onMouseWheel( const Vector2f& offset, bool flipped );
virtual Uint32 onCalculateDrag( const Vector2f& position, const Uint32& flags );
void onClose();
+10
View File
@@ -76,6 +76,14 @@ class InputEvent {
Int16 x, y; /** The X/Y coordinates of the mouse at press time */
};
struct WheelEvent {
enum Direction { Normal, Flipped };
Uint32 which;
Float x;
Float y;
Direction direction;
};
/** Touch finger motion/finger event structure */
struct FingerEvent {
Uint32 timestamp;
@@ -204,6 +212,7 @@ class InputEvent {
FileDropped,
TextDropped,
TextEditing,
MouseWheel,
EventUser,
EventCount = EventUser - 1
};
@@ -233,6 +242,7 @@ class InputEvent {
TextEditingEvent textediting;
QuitEvent quit;
UserEvent user;
WheelEvent wheel;
SysWMEvent syswm;
};
};
+14
View File
@@ -66,6 +66,11 @@ void EventDispatcher::inputCallback( InputEvent* event ) {
sendTextEditing( event->textediting.text, event->textediting.start,
event->textediting.length );
break;
case InputEvent::MouseWheel:
sendMouseWheel( { event->wheel.x, event->wheel.y },
event->wheel.direction == InputEvent::WheelEvent::Normal ? true
: false );
break;
case InputEvent::SysWM:
case InputEvent::VideoResize:
case InputEvent::VideoExpose: {
@@ -253,6 +258,15 @@ void EventDispatcher::sendKeyDown( const Keycode& keyCode, const Scancode& scanc
}
}
void EventDispatcher::sendMouseWheel( const Vector2f& offset, bool flipped ) {
Node* node = mFocusNode;
while ( NULL != node ) {
if ( node->isEnabled() && node->onMouseWheel( offset, flipped ) )
break;
node = node->getParent();
}
}
void EventDispatcher::sendMsg( Node* node, const Uint32& Msg, const Uint32& Flags ) {
NodeMessage tMsg( node, Msg, Flags );
node->messagePost( &tMsg );
+4
View File
@@ -397,6 +397,10 @@ Uint32 Node::onMouseLeave( const Vector2i& Pos, const Uint32& Flags ) {
return 1;
}
Uint32 Node::onMouseWheel( const Vector2f& offset, bool flipped ) {
return 1;
}
Uint32 Node::onCalculateDrag( const Vector2f&, const Uint32& ) {
return 1;
}
@@ -357,6 +357,22 @@ void InputSDL::sendEvent( const SDL_Event& SDLEvent ) {
event.Type = InputEvent::MouseButtonUp;
event.button.state = 0;
processEvent( &event );
event.Type = InputEvent::MouseWheel;
event.wheel.which = SDLEvent.wheel.which;
event.wheel.direction = SDLEvent.wheel.direction == SDL_MOUSEWHEEL_NORMAL
? InputEvent::WheelEvent::Normal
: InputEvent::WheelEvent::Flipped;
#if SDL_VERSION_ATLEAST( 2, 0, 18 )
event.wheel.x = SDLEvent.wheel.preciseX;
event.wheel.y = SDLEvent.wheel.preciseY;
#else
event.wheel.x = SDLEvent.wheel.x;
event.wheel.y = SDLEvent.wheel.y;
#endif
processEvent( &event );
break;
}
case SDL_FINGERMOTION: {
+1
View File
@@ -3287,6 +3287,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe
#endif
#if EE_PLATFORM == EE_PLATFORM_MACOS
macOS_CreateApplicationMenus();
macOS_EnableScrollMomentum();
mThreadPool->run( [this]() {
// Checks if the default shell path contains more paths
+2
View File
@@ -7,6 +7,8 @@ extern "C" {
void macOS_CreateApplicationMenus();
void macOS_EnableScrollMomentum();
#ifdef __cplusplus
}
#endif
+4
View File
@@ -63,3 +63,7 @@ macOS_CreateApplicationMenus(void)
[NSApp setWindowsMenu:windowMenu];
}
void macOS_EnableScrollMomentum() {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"AppleMomentumScrollSupported"];
}