2010-11-03 18:24:14 +08:00
|
|
|
/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.hpp"
|
2010-11-04 00:53:48 +08:00
|
|
|
#include "Context.hpp"
|
2010-11-04 04:01:20 +08:00
|
|
|
#include "ContextSettings.hpp"
|
2010-11-06 23:38:26 +08:00
|
|
|
#include "Event.hpp"
|
2010-11-07 08:08:50 +08:00
|
|
|
#include "Input.hpp"
|
2010-11-15 16:33:41 +08:00
|
|
|
#include "VideoMode.hpp"
|
|
|
|
#include "Window.hpp"
|
2010-11-03 18:24:14 +08:00
|
|
|
|
2010-11-12 04:43:18 +08:00
|
|
|
#include <SFML/Window.hpp>
|
|
|
|
|
2010-11-15 16:32:08 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
/* SFML Namespace which contains all classes in this module. */
|
2010-11-03 18:24:14 +08:00
|
|
|
VALUE globalSFMLNamespace;
|
2010-11-08 02:10:17 +08:00
|
|
|
VALUE globalKeyNamespace;
|
|
|
|
VALUE globalMouseNamespace;
|
|
|
|
VALUE globalJoyNamespace;
|
|
|
|
VALUE globalStyleNamespace;
|
2010-11-03 18:24:14 +08:00
|
|
|
|
2010-11-16 17:04:35 +08:00
|
|
|
/* External classes */
|
|
|
|
VALUE globalVector2Class;
|
|
|
|
|
2010-11-08 02:10:17 +08:00
|
|
|
static const char * keyNamesMisc[] =
|
|
|
|
{
|
|
|
|
"Escape", "LControl", "LShift", "LAlt", "LSystem", "RControl", "RShift", "RAlt", "RSystem",
|
|
|
|
"Menu", "LBracket", "RBracket", "SemiColon", "Comma", "Period", "Quote", "Slash",
|
|
|
|
"BackSlash", "Tilde", "Equal", "Dash", "Space", "Return", "Back", "Tab", "PageUp",
|
|
|
|
"PageDown", "End", "Home", "Insert", "Delete", "Add", "Subtract", "Multiply",
|
|
|
|
"Divide", "Left", "Right", "Up", "Down", "Numpad0", "Numpad1", "Numpad2", "Numpad3",
|
|
|
|
"Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9", "F1", "F2", "F3",
|
2010-11-15 16:32:08 +08:00
|
|
|
"F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "Pause",
|
2010-11-08 02:10:17 +08:00
|
|
|
"Count"
|
|
|
|
};
|
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
/* Definition of key codes for keyboard events.
|
|
|
|
*
|
|
|
|
* All SFML::Key constants exists, I just haven't written them all so Rdoc can interpret them yet.
|
|
|
|
*/
|
2010-11-08 02:10:17 +08:00
|
|
|
void CreateKeyEnum( void )
|
|
|
|
{
|
|
|
|
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
|
2010-11-17 00:03:50 +08:00
|
|
|
rb_define_const( globalKeyNamespace, "A", INT2FIX( sf::Key::A ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "B", INT2FIX( sf::Key::B ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "C", INT2FIX( sf::Key::C ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "D", INT2FIX( sf::Key::D ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "E", INT2FIX( sf::Key::E ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "F", INT2FIX( sf::Key::F ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "G", INT2FIX( sf::Key::G ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "H", INT2FIX( sf::Key::H ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "I", INT2FIX( sf::Key::I ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "J", INT2FIX( sf::Key::J ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "K", INT2FIX( sf::Key::K ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "L", INT2FIX( sf::Key::L ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "M", INT2FIX( sf::Key::M ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "N", INT2FIX( sf::Key::N ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "O", INT2FIX( sf::Key::O ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "P", INT2FIX( sf::Key::P ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Q", INT2FIX( sf::Key::Q ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "R", INT2FIX( sf::Key::R ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "S", INT2FIX( sf::Key::S ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "T", INT2FIX( sf::Key::T ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "U", INT2FIX( sf::Key::U ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "V", INT2FIX( sf::Key::V ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "X", INT2FIX( sf::Key::X ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Y", INT2FIX( sf::Key::Y ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Z", INT2FIX( sf::Key::Z ) );
|
2010-11-08 02:10:17 +08:00
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
rb_define_const( globalKeyNamespace, "Num0", INT2FIX( sf::Key::Num0 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num1", INT2FIX( sf::Key::Num1 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num2", INT2FIX( sf::Key::Num2 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num3", INT2FIX( sf::Key::Num3 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num4", INT2FIX( sf::Key::Num4 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num5", INT2FIX( sf::Key::Num5 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num6", INT2FIX( sf::Key::Num6 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num7", INT2FIX( sf::Key::Num7 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num8", INT2FIX( sf::Key::Num8 ) );
|
|
|
|
rb_define_const( globalKeyNamespace, "Num9", INT2FIX( sf::Key::Num9 ) );
|
2010-11-08 02:10:17 +08:00
|
|
|
|
2010-11-12 04:43:18 +08:00
|
|
|
for( int index = static_cast< int >( sf::Key::Escape ); index <= sf::Key::Count; index++ )
|
2010-11-08 02:10:17 +08:00
|
|
|
{
|
|
|
|
rb_define_const( globalKeyNamespace, keyNamesMisc[ index - sf::Key::Escape ], INT2FIX( index ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
/* Definition of button codes for mouse events. */
|
2010-11-08 02:10:17 +08:00
|
|
|
void CreateMouseEnum( void )
|
|
|
|
{
|
|
|
|
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
|
2010-11-17 00:03:50 +08:00
|
|
|
rb_define_const( globalMouseNamespace, "Left", INT2FIX( sf::Mouse::Left ) );
|
|
|
|
rb_define_const( globalMouseNamespace, "Right", INT2FIX( sf::Mouse::Right ) );
|
|
|
|
rb_define_const( globalMouseNamespace, "Middle", INT2FIX( sf::Mouse::Middle ) );
|
|
|
|
rb_define_const( globalMouseNamespace, "XButton1", INT2FIX( sf::Mouse::XButton1 ) );
|
|
|
|
rb_define_const( globalMouseNamespace, "XButton2", INT2FIX( sf::Mouse::XButton2 ) );
|
|
|
|
rb_define_const( globalMouseNamespace, "ButtonCount", INT2FIX( sf::Mouse::ButtonCount ) );
|
2010-11-08 02:10:17 +08:00
|
|
|
}
|
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
/* Definition of joystick axis for joystick events. */
|
2010-11-08 02:10:17 +08:00
|
|
|
void CreateJoyEnum( void )
|
|
|
|
{
|
|
|
|
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
|
2010-11-17 00:03:50 +08:00
|
|
|
rb_define_const( globalJoyNamespace, "AxisX", INT2FIX( sf::Joy::AxisX ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisY", INT2FIX( sf::Joy::AxisY ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisZ", INT2FIX( sf::Joy::AxisZ ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisR", INT2FIX( sf::Joy::AxisR ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisU", INT2FIX( sf::Joy::AxisU ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisV", INT2FIX( sf::Joy::AxisV ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisPOV", INT2FIX( sf::Joy::AxisPOV ) );
|
|
|
|
rb_define_const( globalJoyNamespace, "AxisCount", INT2FIX( sf::Joy::AxisCount ) );
|
2010-11-08 02:10:17 +08:00
|
|
|
}
|
|
|
|
|
2010-11-17 00:03:50 +08:00
|
|
|
/* Enumeration of the window styles. */
|
2010-11-08 02:10:17 +08:00
|
|
|
void CreateStyleEnum( void )
|
|
|
|
{
|
|
|
|
globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" );
|
2010-11-17 00:03:50 +08:00
|
|
|
rb_define_const( globalStyleNamespace, "None", INT2FIX( sf::Style::None ) );
|
|
|
|
rb_define_const( globalStyleNamespace, "Titlebar", INT2FIX( sf::Style::Titlebar ) );
|
|
|
|
rb_define_const( globalStyleNamespace, "Resize", INT2FIX( sf::Style::Resize ) );
|
|
|
|
rb_define_const( globalStyleNamespace, "Close", INT2FIX( sf::Style::Close ) );
|
|
|
|
rb_define_const( globalStyleNamespace, "Fullscreen", INT2FIX( sf::Style::Fullscreen ) );
|
|
|
|
rb_define_const( globalStyleNamespace, "Default", INT2FIX( sf::Style::Default ) );
|
2010-11-08 02:10:17 +08:00
|
|
|
}
|
|
|
|
|
2010-11-16 16:09:41 +08:00
|
|
|
bool CheckDependencies( void )
|
|
|
|
{
|
|
|
|
if( rb_cvar_defined( globalSFMLNamespace, rb_intern( "SystemLoaded" ) ) == Qtrue )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-16 17:04:35 +08:00
|
|
|
VALUE RetrieveSFMLClass( const char * aName )
|
|
|
|
{
|
|
|
|
ID name = rb_intern( aName );
|
|
|
|
if( rb_cvar_defined( globalSFMLNamespace, name ) == Qfalse )
|
|
|
|
{
|
|
|
|
rb_raise( rb_eRuntimeError, "This module depends on SFML::%s", aName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rb_cvar_get( globalSFMLNamespace, name );
|
|
|
|
}
|
|
|
|
|
|
|
|
void RetrieveVector2Class( void )
|
|
|
|
{
|
|
|
|
globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
|
|
|
}
|
|
|
|
|
2010-11-03 18:24:14 +08:00
|
|
|
void Init_window( void )
|
|
|
|
{
|
2010-11-17 00:03:50 +08:00
|
|
|
/* SFML namespace which contains the classes of this module. */
|
2010-11-03 18:24:14 +08:00
|
|
|
globalSFMLNamespace = rb_define_module( "SFML" );
|
2010-11-16 16:09:41 +08:00
|
|
|
if( CheckDependencies() == false )
|
|
|
|
{
|
|
|
|
rb_raise( rb_eRuntimeError, "This module depends on sfml-system" );
|
|
|
|
}
|
|
|
|
|
2010-11-16 17:04:35 +08:00
|
|
|
RetrieveVector2Class();
|
|
|
|
|
2010-11-08 02:10:17 +08:00
|
|
|
rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue );
|
|
|
|
|
|
|
|
CreateKeyEnum();
|
|
|
|
CreateMouseEnum();
|
|
|
|
CreateJoyEnum();
|
|
|
|
CreateStyleEnum();
|
|
|
|
|
2010-11-04 00:53:48 +08:00
|
|
|
Init_Context();
|
2010-11-04 04:01:20 +08:00
|
|
|
Init_ContextSettings();
|
2010-11-06 23:38:26 +08:00
|
|
|
Init_Event();
|
2010-11-07 08:08:50 +08:00
|
|
|
Init_Input();
|
2010-11-15 16:33:41 +08:00
|
|
|
Init_VideoMode();
|
|
|
|
Init_Window();
|
2010-11-03 18:24:14 +08:00
|
|
|
}
|