| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- Namespace mojo.input
- #rem monkeydoc Global instance of the MouseDevice class.
- #end
- Const Mouse:=New MouseDevice
- #rem monkeydoc Mouse buttons.
- | MouseButton | Description
- |:--------------|------------
- | Left | Left mouse button.
- | Middle | Middle mouse button.
- | Right | Right mouse button.
- #end
- Enum MouseButton
- None=0
- Left=1
- Middle=2
- Right=3
- End
- #rem monkeydoc The MouseDevice class.
- To access the mouse device, use the global [[Mouse]] constant.
- The mouse device should only used after a new [[app.AppInstance]] is created.
- #end
- Class MouseDevice Extends InputDevice
- #rem monkeydoc Pointer visiblity state.
- #end
- Property PointerVisible:Bool()
-
- Return SDL_ShowCursor( -1 )=SDL_ENABLE
-
- Setter( pointerVisible:Bool )
-
- SDL_ShowCursor( pointerVisible ? SDL_ENABLE Else SDL_DISABLE )
-
- End
-
- #rem monkeydoc X coordinate of the mouse location.
- #end
- Property X:Int()
- Return Location.x
- End
-
- #rem monkeydoc Y coordinate of the mouse location.
- #end
- Property Y:Int()
- Return Location.y
- End
- #rem monkeydoc The mouse location.
- #end
- Property Location:Vec2i()
- Return _location
- End
-
- #rem monkeydoc The mouse wheel delta x value since the last app update.
- #end
- Property WheelX:Int()
- Return Wheel.x
- End
-
- #rem monkeydoc The mouse wheel delta y value since the last app update.
- #end
- Property WheelY:Int()
- Return Wheel.y
- End
-
- #rem monkeydoc The mouse wheel delta value since the last app update.
- #end
- Property Wheel:Vec2i()
- Return _wheel
- End
-
- #rem monkeydoc Checks the current up/down state of a mouse button.
-
- Returns true if `button` is currently held down.
-
- @param button Button to checl.
- #end
- Method ButtonDown:Bool( button:MouseButton )
- DebugAssert( button>=0 And button<4,"Mouse button out of range" )
- Return _down[button]
- End
- #rem monkeydoc Checks if a mouse button was pressed.
-
- Returns true if `button` was pressed since the last app update.
- @param button Button to check.
-
- #end
- Method ButtonPressed:Bool( button:MouseButton )
- DebugAssert( button>=0 And button<4,"Mouse button out of range" )
- Return _pressed[button]
- End
-
- #rem monkeydoc Checks if a mouse button was released.
-
- Returns true if `button` was released since the last app update.
-
- @param button Button to check.
-
- #end
- Method ButtonReleased:Bool( button:MouseButton )
- DebugAssert( button>=0 And button<4,"Mouse button out of range" )
- Return _released[button]
- End
-
- #rem monkeydoc @hidden
- #end
- Method ButtonHit:Bool( button:MouseButton )
- Return ButtonPressed( button )
- End
- '***** Internal *****
- #rem monkeydoc @hidden
- #end
- Method Init()
- End
-
- #rem monkeydoc @hidden
- #end
- Method Update()
-
- Local mask:=SDL_GetMouseState( Varptr _location.x,Varptr _location.y )
- If App.ActiveWindow _location=App.ActiveWindow.TransformPointFromView( App.ActiveWindow.MouseScale * _location,Null )
-
- UpdateButton( MouseButton.Left,mask & 1 )
- UpdateButton( MouseButton.Middle,mask & 2 )
- UpdateButton( MouseButton.Right,mask & 4)
-
- _wheel=Null
- End
-
- #rem monkeydoc @hidden
- #end
- Method SendEvent( event:SDL_Event Ptr )
-
- Select event->type
-
- Case SDL_MOUSEWHEEL
-
- Local mevent:=Cast<SDL_MouseWheelEvent Ptr>( event )
-
- Local window:=Window.WindowForID( mevent->windowID )
- If Not window Return
-
- _wheel+=New Vec2i( mevent->x,mevent->y )
-
- End
- End
-
- Private
- Field _init:Bool
- Field _location:Vec2i
- Field _wheel:Vec2i
- Field _down:=New Bool[4]
- Field _pressed:=New Bool[4]
- Field _released:=New Bool[4]
-
- Method New()
- End
-
- Method UpdateButton( button:MouseButton,down:Bool )
- _pressed[button]=False
- _released[button]=False
- If down=_down[button] Return
- If down _pressed[button]=True Else _released[button]=True
- _down[button]=down
- End
-
- End
|