TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Input.InputManager Class Reference

Input manager interfacing with input methods provided by a GameWindow. More...

Inheritance diagram for TriDevs.TriEngine.Input.InputManager:
[legend]
Collaboration diagram for TriDevs.TriEngine.Input.InputManager:
[legend]

Public Member Functions

 InputManager ()
 Creates a new InputManager with only basic low-level input support. More...
 
 InputManager (GameWindow window)
 Creates a new InputManager associated with the specified GameWindow. More...
 
void Update ()
 Updates the input manager, refreshing all current and previous states. More...
 
bool IsKeyUp (Key key)
 Returns whether or not the specified key is currently unpressed. More...
 
bool IsKeyDown (Key key)
 Returns whether or not the specified key is currently being pressed. More...
 
bool KeyPressed (Key key)
 Returns whether or not the specified key has been pressed. More...
 
bool KeyReleased (Key key)
 Returns whether or not the specified key has been released. More...
 
bool IsMouseUp (MouseButton button)
 Returns whether or not the specified mouse button is currently unpressed. More...
 
bool IsMouseDown (MouseButton button)
 Returns whether or not the specified mouse button is currently being pressed. More...
 
bool MousePressed (MouseButton button)
 Returns whether or not the specified mouse button has been pressed. More...
 
bool MouseReleased (MouseButton button)
 Returns whether or not the specified mouse button has been released. More...
 
bool IsWheelUp ()
 Returns whether the mouse wheel was scrolled up. More...
 
bool IsWheelDown ()
 Returns whether the mouse wheel was scrolled down. More...
 
bool IsWheelChanged ()
 Returns whether the mouse wheel scrolled at all. More...
 
int WheelChange ()
 Returns the mouse wheel's change in value. More...
 

Properties

int MouseX [get]
 
int MouseY [get]
 
Point< int > MousePosition [get]
 
int MouseWheelValue [get]
 
bool this[Key key] [get]
 
bool this[MouseButton button] [get]
 
- Properties inherited from TriDevs.TriEngine.Input.IInputManager
int MouseX [get]
 Gets the absolute X position of the pointer, in window pixel coordinates. More...
 
int MouseY [get]
 Gets the absolute Y position of the pointer, in window pixel coordinates. More...
 
Point< int > MousePosition [get]
 Gets a Point representing the position of the mouse pointer, in window pixel coordinates. More...
 
int MouseWheelValue [get]
 Gets the current value of the mouse wheel. More...
 
bool this[Key key] [get]
 Gets a boolean value indicating whether the specified OpenTK.Input.Key is pressed. More...
 
bool this[MouseButton button] [get]
 Gets a boolean value indicating whether the specified OpenTK.Input.MouseButton is pressed. More...
 

Events

KeyDownEventHandler KeyDown
 Raised when a key is pressed down. More...
 
KeyUpEventHandler KeyUp
 Raised when a key is released. More...
 
KeyPressEventHandler KeyPress
 Raised when a character is typed. More...
 
MouseDownEventHandler MouseDown
 Raised when a mouse button is pressed down. More...
 
MouseUpEventHandler MouseUp
 Raised when a mouse button is released. More...
 
MouseWheelChangedEventHandler WheelChanged
 Raised when the mouse wheel value changes. More...
 
MouseWheelDownEventHandler WheelDown
 Raised when the mouse wheel is scrolled downwards. More...
 
MouseWheelUpEventHandler WheelUp
 Raised when the mouse wheel is scrolled upwards. More...
 
- Events inherited from TriDevs.TriEngine.Input.IInputManager
KeyDownEventHandler KeyDown
 Raised when a key is pressed down. More...
 
KeyUpEventHandler KeyUp
 Raised when a key is released. More...
 
KeyPressEventHandler KeyPress
 Raised when a character is typed. More...
 
MouseDownEventHandler MouseDown
 Raised when a mouse button is pressed down. More...
 
MouseUpEventHandler MouseUp
 Raised when a mouse button is released. More...
 
MouseWheelChangedEventHandler WheelChanged
 Raised when the mouse wheel value changes. More...
 
MouseWheelDownEventHandler WheelDown
 Raised when the mouse wheel is scrolled downwards. More...
 
MouseWheelUpEventHandler WheelUp
 Raised when the mouse wheel is scrolled upwards. More...
 

Detailed Description

Input manager interfacing with input methods provided by a GameWindow.

Constructor & Destructor Documentation

TriDevs.TriEngine.Input.InputManager.InputManager ( )

Creates a new InputManager with only basic low-level input support.

Creating InputManager without a driver container will cause the events to be useless and never be raised, only the methods on this class will return any useful info. If you want event support, construct the InputManager with a GameWindow or other supported driver providers (NYI).

109  {
110  // We're assigning an empty mouse device.
111  // This will make position functions return a constant 0.
112  // Instead of being null and causing exceptions.
113  _mouse = new MouseDevice();
114  // We don't have to assign an empty keyboard device,
115  // since we don't have any code that directly relies on it being present.
116  }
TriDevs.TriEngine.Input.InputManager.InputManager ( GameWindow  window)

Creates a new InputManager associated with the specified GameWindow.

Parameters
windowThe GameWindow this InputManager will interface with.
123  {
124  _keyboard = window.Keyboard;
125  _mouse = window.Mouse;
126  _keyboard.KeyDown += OnKeyDown;
127  _keyboard.KeyUp += OnKeyUp;
128  window.KeyPress += OnKeyPress;
129  _mouse.ButtonDown += OnMouseDown;
130  _mouse.ButtonUp += OnMouseUp;
131  _mouse.WheelChanged += OnMouseWheelChanged;
132  }

Member Function Documentation

bool TriDevs.TriEngine.Input.InputManager.IsKeyDown ( Key  key)

Returns whether or not the specified key is currently being pressed.

Parameters
keyKey to query for.
Returns
True if key is currently being pressed, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

201  {
202  return _keyboardState[key];
203  }
bool TriDevs.TriEngine.Input.InputManager.IsKeyUp ( Key  key)

Returns whether or not the specified key is currently unpressed.

Parameters
keyKey to query for.
Returns
True if the key is currently up (not pressed), false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

196  {
197  return !_keyboardState[key];
198  }
bool TriDevs.TriEngine.Input.InputManager.IsMouseDown ( MouseButton  button)

Returns whether or not the specified mouse button is currently being pressed.

Parameters
buttonThe button to query for.
Returns
True if button is currently being pressed, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

221  {
222  return _mouseState[button];
223  }
bool TriDevs.TriEngine.Input.InputManager.IsMouseUp ( MouseButton  button)

Returns whether or not the specified mouse button is currently unpressed.

Parameters
buttonButton to query for.
Returns
True if the button is currently up (not pressed), false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

216  {
217  return !_mouseState[button];
218  }
bool TriDevs.TriEngine.Input.InputManager.IsWheelChanged ( )

Returns whether the mouse wheel scrolled at all.

Returns
True if the mouse wheel scrolled, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

246  {
247  return _mouseState.Wheel != _lastMouseState.Wheel;
248  }
bool TriDevs.TriEngine.Input.InputManager.IsWheelDown ( )

Returns whether the mouse wheel was scrolled down.

Returns
True if mouse wheel was scrolled down, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

241  {
242  return _mouseState.Wheel < _lastMouseState.Wheel;
243  }
bool TriDevs.TriEngine.Input.InputManager.IsWheelUp ( )

Returns whether the mouse wheel was scrolled up.

Returns
True if mouse wheel was scrolled up, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

236  {
237  return _mouseState.Wheel > _lastMouseState.Wheel;
238  }
bool TriDevs.TriEngine.Input.InputManager.KeyPressed ( Key  key)

Returns whether or not the specified key has been pressed.

Only returns true if the last state of the key was not pressed.

Parameters
keyKey to query for.
Returns
True if key was pressed, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

206  {
207  return _keyboardState[key] && !_lastKeyboardState[key];
208  }
bool TriDevs.TriEngine.Input.InputManager.KeyReleased ( Key  key)

Returns whether or not the specified key has been released.

Only returns true if the last state of the key was pressed.

Parameters
keyKey to query for.
Returns
True if key was released, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

211  {
212  return !_keyboardState[key] && _lastKeyboardState[key];
213  }
bool TriDevs.TriEngine.Input.InputManager.MousePressed ( MouseButton  button)

Returns whether or not the specified mouse button has been pressed.

Only returns true if the last state of the mouse button was not pressed.

Parameters
buttonButton to query for.
Returns
True if button was pressed, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

226  {
227  return _mouseState[button] && !_lastMouseState[button];
228  }
bool TriDevs.TriEngine.Input.InputManager.MouseReleased ( MouseButton  button)

Returns whether or not the specified mouse button has been released.

Only returns true if the last state of the button was pressed.

Parameters
buttonThe button to query for.
Returns
True if the button was released, false otherwise.

Implements TriDevs.TriEngine.Input.IInputManager.

231  {
232  return !_mouseState[button] && _lastMouseState[button];
233  }
void TriDevs.TriEngine.Input.InputManager.Update ( )

Updates the input manager, refreshing all current and previous states.

Implements TriDevs.TriEngine.Input.IInputManager.

187  {
188  _lastKeyboardState = _keyboardState;
189  _keyboardState = Keyboard.GetState();
190 
191  _lastMouseState = _mouseState;
192  _mouseState = Mouse.GetState();
193  }
int TriDevs.TriEngine.Input.InputManager.WheelChange ( )

Returns the mouse wheel's change in value.

Returns
Negative value if wheel scrolled down, positive value if scrolled up, zero if not scrolled.

Implements TriDevs.TriEngine.Input.IInputManager.

251  {
252  return _mouseState.Wheel - _lastMouseState.Wheel;
253  }

Property Documentation

Point<int> TriDevs.TriEngine.Input.InputManager.MousePosition
get
int TriDevs.TriEngine.Input.InputManager.MouseWheelValue
get
int TriDevs.TriEngine.Input.InputManager.MouseX
get
int TriDevs.TriEngine.Input.InputManager.MouseY
get
bool TriDevs.TriEngine.Input.InputManager.this[Key key]
get
bool TriDevs.TriEngine.Input.InputManager.this[MouseButton button]
get

Event Documentation

KeyDownEventHandler TriDevs.TriEngine.Input.InputManager.KeyDown

Raised when a key is pressed down.

KeyPressEventHandler TriDevs.TriEngine.Input.InputManager.KeyPress

Raised when a character is typed.

KeyUpEventHandler TriDevs.TriEngine.Input.InputManager.KeyUp

Raised when a key is released.

MouseDownEventHandler TriDevs.TriEngine.Input.InputManager.MouseDown

Raised when a mouse button is pressed down.

MouseUpEventHandler TriDevs.TriEngine.Input.InputManager.MouseUp

Raised when a mouse button is released.

MouseWheelChangedEventHandler TriDevs.TriEngine.Input.InputManager.WheelChanged

Raised when the mouse wheel value changes.

MouseWheelDownEventHandler TriDevs.TriEngine.Input.InputManager.WheelDown

Raised when the mouse wheel is scrolled downwards.

MouseWheelUpEventHandler TriDevs.TriEngine.Input.InputManager.WheelUp

Raised when the mouse wheel is scrolled upwards.


The documentation for this class was generated from the following file: