Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / sdl2 / events.nit
index 8eb14f2..2ca18aa 100644 (file)
@@ -47,8 +47,10 @@ extern class SDLEventBuffer `{SDL_Event *`}
                if is_mouse_motion then return to_mouse_motion
                if is_mouse_button_down then return to_mouse_button_down
                if is_mouse_button_up then return to_mouse_button_up
+               if is_mouse_wheel then return to_mouse_wheel
                if is_keydown then return to_keydown
                if is_keyup then return to_keyup
+               if is_window then return to_window
                return to_event_direct
        end
 
@@ -86,6 +88,14 @@ extern class SDLEventBuffer `{SDL_Event *`}
        # Require: `is_mouse_button_up`
        fun to_mouse_button_up: SDLMouseButtonUpEvent `{ return self; `}
 
+       # Is this a mouse wheel event?
+       fun is_mouse_wheel: Bool `{ return self->type == SDL_MOUSEWHEEL; `}
+
+       # Get a reference to data at `self` as a `SDLMouseWheelEvent`
+       #
+       # Require: `is_mouse_wheel`
+       fun to_mouse_wheel: SDLMouseWheelEvent `{ return self; `}
+
        # Is this a key presse event?
        fun is_keydown: Bool `{ return self->type == SDL_KEYDOWN; `}
 
@@ -102,13 +112,20 @@ extern class SDLEventBuffer `{SDL_Event *`}
        # Require: `is_keyup`
        fun to_keyup: SDLKeyboardUpEvent `{ return self; `}
 
+       #  Is this a window event?
+       fun is_window: Bool `{ return self->type == SDL_WINDOWEVENT; `}
+
+       # Get a reference to data at `self` as a `SDLWindowEvent`
+       #
+       # Require: `is_window`
+       fun to_window: SDLWindowEvent `{ return self; `}
+
        # TODO other SDL events:
        #
        # SDL_CommonEvent common
        # SDL_WindowEvent window
        # SDL_TextEditingEvent edit
        # SDL_TextInputEvent text
-       # SDL_MouseWheelEvent wheel
        # SDL_JoyAxisEvent jaxis
        # SDL_JoyBallEvent jball
        # SDL_JoyHatEvent jhat;
@@ -214,6 +231,17 @@ extern class SDLMouseButtonDownEvent
        super SDLMouseButtonEvent
 end
 
+# Mouse wheel event
+extern class SDLMouseWheelEvent
+       super SDLEvent
+
+       # Horizontal scroll amount
+       fun x: Int `{ return self->wheel.x; `}
+
+       # Vertical scroll amount
+       fun y: Int `{ return self->wheel.y; `}
+end
+
 # Keyboard button event
 extern class SDLKeyboardEvent
        super SDLEvent
@@ -258,3 +286,23 @@ extern class SDLKeysym `{ SDL_Keysym * `}
        fun mod: Int `{ return self->mod; `}
        # TODO related masks
 end
+
+# Window event
+extern class SDLWindowEvent
+       super SDLEvent
+
+       # Window identifier
+       fun id: Int `{ return self->window.windowID; `}
+
+       # Is `self` a resized event?
+       fun is_resized: Bool `{ return self->window.event == SDL_WINDOWEVENT_RESIZED; `}
+
+       # Is `self` a size changed event?
+       fun is_size_changed: Bool `{ return self->window.event == SDL_WINDOWEVENT_SIZE_CHANGED; `}
+
+       # `data1` field, depends on the event kind
+       fun data1: Int `{ return self->window.data1; `}
+
+       # `data2` field, depends on the event kind
+       fun data2: Int `{ return self->window.data2; `}
+end