2009-01-29 00:18:34 +08:00
|
|
|
/*
|
2010-04-21 01:35:30 +08:00
|
|
|
* DSFML - SFML Library wrapper for the D programming language.
|
|
|
|
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
|
|
|
* Copyright (C) 2010 Andreas Hollandt
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or
|
|
|
|
* implied warranty. In no event will the authors be held
|
|
|
|
* liable for any damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute
|
|
|
|
* it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented;
|
|
|
|
* you must not claim that you wrote the original software.
|
|
|
|
* If you use this software in a product, an acknowledgment
|
|
|
|
* in the product documentation would be appreciated but
|
|
|
|
* is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such,
|
|
|
|
* and must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any
|
|
|
|
* source distribution.
|
|
|
|
*/
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
module dsfml.window.input;
|
|
|
|
|
|
|
|
import dsfml.system.common;
|
|
|
|
|
|
|
|
import dsfml.window.event;
|
|
|
|
|
|
|
|
/**
|
2010-04-21 01:35:30 +08:00
|
|
|
* Input handles real-time input from keyboard and mouse.
|
|
|
|
* Use it instead of events to handle continuous moves and more
|
|
|
|
* game-friendly inputs
|
|
|
|
*/
|
2009-01-29 00:18:34 +08:00
|
|
|
class Input : DSFMLObject
|
|
|
|
{
|
2010-04-21 01:35:30 +08:00
|
|
|
public: // TODO: try to fix this, doesn't work with package
|
|
|
|
this(SFMLClass input)
|
|
|
|
{
|
|
|
|
super(input, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
override void dispose()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-04-21 01:35:30 +08:00
|
|
|
* Get the state of a key
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* key = Key to check
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if key is down, false if key is up
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
bool isKeyDown(KeyCode key)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
return cast(bool)sfInput_IsKeyDown(m_ptr, key);
|
|
|
|
}
|
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-04-21 01:35:30 +08:00
|
|
|
* Get the state of a mouse button
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* button = Button to check
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if button is down, false if button is up
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
bool isMouseButtonDown(MouseButtons button)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
return cast(bool)sfInput_IsMouseButtonDown(m_ptr, button);
|
|
|
|
}
|
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-04-21 01:35:30 +08:00
|
|
|
* Get the state of a joystick button
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* joyId = Identifier of the joystick to check (0 or 1)
|
|
|
|
* button = Button to check
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if button is down, false if button is up
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
bool isJoystickButtonDown(uint joyId, uint button)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
return cast(bool)sfInput_IsJoystickButtonDown(m_ptr, joyId, button);
|
|
|
|
}
|
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-04-21 01:35:30 +08:00
|
|
|
* Get a joystick axis position
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* joyId = Identifier of the joystick to check (0 or 1)
|
|
|
|
* axis = Axis to get
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
float getJoystickAxis(uint joyId, JoyAxis axis)
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
return sfInput_GetJoystickAxis(m_ptr, joyId, axis);
|
|
|
|
}
|
|
|
|
|
2010-04-21 01:35:30 +08:00
|
|
|
@property
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get the mouse X position
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Current mouse left position, relative to owner window
|
|
|
|
*/
|
|
|
|
int mouseX()
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
2010-04-21 01:35:30 +08:00
|
|
|
return sfInput_GetMouseX(m_ptr);
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
2010-04-21 01:35:30 +08:00
|
|
|
/**
|
|
|
|
* Get the mouse Y position
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Current mouse top position, relative to owner window
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int mouseY()
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
2010-04-21 01:35:30 +08:00
|
|
|
return sfInput_GetMouseY(m_ptr);
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
2010-04-21 01:35:30 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// External ====================================================================
|
|
|
|
|
2010-01-13 03:56:38 +08:00
|
|
|
static extern (C)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
2010-03-16 07:35:53 +08:00
|
|
|
int function(SFMLClass, KeyCode) sfInput_IsKeyDown;
|
|
|
|
int function(SFMLClass, MouseButtons) sfInput_IsMouseButtonDown;
|
|
|
|
int function(SFMLClass, uint, uint) sfInput_IsJoystickButtonDown;
|
|
|
|
int function(SFMLClass) sfInput_GetMouseX;
|
|
|
|
int function(SFMLClass) sfInput_GetMouseY;
|
|
|
|
float function(SFMLClass, uint, JoyAxis) sfInput_GetJoystickAxis;
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-04-21 01:35:30 +08:00
|
|
|
mixin(loadFromSharedLib2("csfml-window", "sfInput",
|
|
|
|
"IsKeyDown", "IsMouseButtonDown", "IsJoystickButtonDown", "GetMouseX", "GetMouseY", "GetJoystickAxis"));
|
2010-01-13 03:56:38 +08:00
|
|
|
}
|