Quck syntax fiex to main.cpp VideoMode.cpp
Added skeleton for SFML::Window and finished the new method I think. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1635 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
462c5723df
commit
10de308f44
@ -117,7 +117,7 @@ static VALUE VideoMode_GetDesktopMode( VALUE aKlass )
|
|||||||
|
|
||||||
static VALUE VideoMode_GetFullscreenModes( VALUE aKlass )
|
static VALUE VideoMode_GetFullscreenModes( VALUE aKlass )
|
||||||
{
|
{
|
||||||
std::vector< sf::VideoMode >& modes = sf::VideoMode::GetFullscreenModes();
|
const std::vector< sf::VideoMode >& modes = sf::VideoMode::GetFullscreenModes();
|
||||||
VALUE array = rb_ary_new();
|
VALUE array = rb_ary_new();
|
||||||
for( std::vector< sf::VideoMode >::const_iterator it = modes.begin(), end = modes.end(); it != end; it++ )
|
for( std::vector< sf::VideoMode >::const_iterator it = modes.begin(), end = modes.end(); it != end; it++ )
|
||||||
{
|
{
|
||||||
@ -138,13 +138,13 @@ static VALUE VideoMode_New( int argc, VALUE *args, VALUE aKlass )
|
|||||||
object = new sf::VideoMode();
|
object = new sf::VideoMode();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
object = new sf::VideoMode( UINT2FIX( args[0] ), UINT2FIX( args[1] ) );
|
object = new sf::VideoMode( INT2FIX( args[0] ), INT2FIX( args[1] ) );
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
object = new sf::VideoMode( UINT2FIX( args[0] ), UINT2FIX( args[1] ), UINT2FIX( args[2] ) );
|
object = new sf::VideoMode( INT2FIX( args[0] ), INT2FIX( args[1] ), INT2FIX( args[2] ) );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rb_raise( rb_eArgError, "Expected 0 2 or 3 arguments but was given %ld", arrayLength );
|
rb_raise( rb_eArgError, "Expected 0 2 or 3 arguments but was given %d", argc );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
|
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
|
||||||
|
154
bindings/ruby/sfml-window/window/Window.cpp
Normal file
154
bindings/ruby/sfml-window/window/Window.cpp
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/* 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 "Window.hpp"
|
||||||
|
#include "main.hpp"
|
||||||
|
#include <SFML/Window/Window.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
/* SFML::Window is the main class of the Window module.
|
||||||
|
*
|
||||||
|
* It defines an OS window that is able to receive an OpenGL rendering.
|
||||||
|
*
|
||||||
|
* A SFML::Window can create its own new window, or be embedded into an already existing control using the Create(handle)
|
||||||
|
* function. This can be useful for embedding an OpenGL rendering area into a view which is part of a bigger GUI with
|
||||||
|
* existing windows, controls, etc. It can also serve as embedding an OpenGL rendering area into a window created by
|
||||||
|
* another (probably richer) GUI library like Qt or wxWidgets.
|
||||||
|
*
|
||||||
|
* The SFML::Window class provides a simple interface for manipulating the window: move, resize, show/hide, control mouse
|
||||||
|
* cursor, etc. It also provides event handling through its getEvent() function, and real-time state handling with its
|
||||||
|
* attached SFML::Input object (see getInput()).
|
||||||
|
*
|
||||||
|
* Note that OpenGL experts can pass their own parameters (antialiasing level, bits for the depth and stencil buffers,
|
||||||
|
* etc.) to the OpenGL context attached to the window, with the SFML::ContextSettings structure which is passed as an
|
||||||
|
* optional argument when creating the window.
|
||||||
|
*
|
||||||
|
* Usage example:
|
||||||
|
*
|
||||||
|
* # Declare and create a new window
|
||||||
|
* window = SFML::Window.new( SFML::VideoMode.new( 800, 600 ), "SFML window" )
|
||||||
|
*
|
||||||
|
* # Limit the framerate to 60 frames per second (this step is optional)
|
||||||
|
* window.setFramerateLimit( 60 );
|
||||||
|
*
|
||||||
|
* # The main loop - ends as soon as the window is closed
|
||||||
|
* while window.open?
|
||||||
|
*
|
||||||
|
* # Event processing
|
||||||
|
* while event = window.getEvent
|
||||||
|
*
|
||||||
|
* # Request for closing the window
|
||||||
|
* if event.type == SFML::Event::Closed
|
||||||
|
* window.close()
|
||||||
|
* end
|
||||||
|
* end
|
||||||
|
*
|
||||||
|
* # Activate the window for OpenGL rendering
|
||||||
|
* window.setActive()
|
||||||
|
*
|
||||||
|
* # OpenGL drawing commands go here...
|
||||||
|
*
|
||||||
|
* # End the current frame and display its contents on screen
|
||||||
|
* window.display()
|
||||||
|
* end
|
||||||
|
*/
|
||||||
|
VALUE globalWindowClass;
|
||||||
|
extern VALUE globalVideoModeClass;
|
||||||
|
extern VALUE globalContextSettingsClass;
|
||||||
|
|
||||||
|
#define VALIDATE_CLASS( variable, type, name ) \
|
||||||
|
if( CLASS_OF( variable ) != type ) \
|
||||||
|
{ \
|
||||||
|
rb_raise( rb_eTypeError, name#" argument must be instance of %s", STR2CSTR( rb_funcall( type, rb_intern( "to_s" ), 0 ) ) ); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free a heap allocated object
|
||||||
|
* Not accessible trough ruby directly!
|
||||||
|
*/
|
||||||
|
static void Window_Free( sf::Window *anObject )
|
||||||
|
{
|
||||||
|
delete anObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE Window_New( int argc, VALUE *args, VALUE aKlass )
|
||||||
|
{
|
||||||
|
sf::Window *object = NULL;
|
||||||
|
sf::VideoMode *mode = NULL;
|
||||||
|
sf::ContextSettings *settings = NULL;
|
||||||
|
switch( argc )
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
VALIDATE_CLASS( args[0], globalVideoModeClass, first );
|
||||||
|
VALIDATE_CLASS( args[1], rb_cString, second );
|
||||||
|
Data_Get_Struct( args[0], sf::VideoMode, mode );
|
||||||
|
object = new sf::Window( mode , STR2CSTR( args[1] ) );
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
VALIDATE_CLASS( args[0], globalVideoModeClass, first );
|
||||||
|
VALIDATE_CLASS( args[1], rb_cString, second );
|
||||||
|
VALIDATE_CLASS( args[2], rb_cFixnum, second );
|
||||||
|
Data_Get_Struct( args[0], sf::VideoMode, mode );
|
||||||
|
object = new sf::VideoMode( mode, STR2CSTR( args[1] ), FIX2UINT( args[2] ) );
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
VALIDATE_CLASS( args[0], globalVideoModeClass, first );
|
||||||
|
VALIDATE_CLASS( args[1], rb_cString, second );
|
||||||
|
VALIDATE_CLASS( args[2], rb_cFixnum, second );
|
||||||
|
VALIDATE_CLASS( args[3], globalContextSettingsClass, fourth );
|
||||||
|
Data_Get_Struct( args[0], sf::VideoMode, mode );
|
||||||
|
Data_Get_Struct( args[3], sf::ContextSettings, settings );
|
||||||
|
object = new sf::VideoMode( mode, STR2CSTR( args[1] ), FIX2UINT( args[2] ), *settings );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rb_raise( rb_eArgError, "Expected 2..4 arguments but was given %d", argc );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
|
||||||
|
rb_obj_call_init( rbData, 0, 0 );
|
||||||
|
return rbData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init_VideoMode( void )
|
||||||
|
{
|
||||||
|
globalVideoModeClass = rb_define_class_under( GetNamespace(), "VideoMode", rb_cObject );
|
||||||
|
|
||||||
|
// Class methods
|
||||||
|
rb_define_singleton_method( globalVideoModeClass, "new", FUNCPTR( VideoMode_New ), -1 );
|
||||||
|
rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", FUNCPTR( VideoMode_GetDesktopMode ), 0 );
|
||||||
|
rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", FUNCPTR( VideoMode_GetFullscreenModes ), 0 );
|
||||||
|
|
||||||
|
// Instance methods
|
||||||
|
rb_define_method( globalVideoModeClass, "width", FUNCPTR( VideoMode_GetWidth ), 0 );
|
||||||
|
rb_define_method( globalVideoModeClass, "width=", FUNCPTR( VideoMode_SetWidth ), 1 );
|
||||||
|
|
||||||
|
rb_define_method( globalVideoModeClass, "height", FUNCPTR( VideoMode_GetWidth ), 0 );
|
||||||
|
rb_define_method( globalVideoModeClass, "height=", FUNCPTR( VideoMode_SetWidth ), 1 );
|
||||||
|
|
||||||
|
rb_define_method( globalVideoModeClass, "bitsPerPixel", FUNCPTR( VideoMode_GetBitsPerPixel ), 0 );
|
||||||
|
rb_define_method( globalVideoModeClass, "bitsPerPixel=", FUNCPTR( VideoMode_SetBitsPerPixel ), 1 );
|
||||||
|
|
||||||
|
// Aliases
|
||||||
|
rb_define_alias( globalVideoModeClass, "bits_per_pixel", "bitsPerPixel" );
|
||||||
|
rb_define_alias( globalVideoModeClass, "bits_per_pixel=", "bitsPerPixel=" );
|
||||||
|
rb_define_alias( globalVideoModeClass, "bpp", "bitsPerPixel" );
|
||||||
|
rb_define_alias( globalVideoModeClass, "bpp=", "bitsPerPixel=" );
|
||||||
|
}
|
31
bindings/ruby/sfml-window/window/Window.hpp
Normal file
31
bindings/ruby/sfml-window/window/Window.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SFML_RUBYEXT_WINDOW_HEADER_
|
||||||
|
#define SFML_RUBYEXT_WINDOW_HEADER_
|
||||||
|
|
||||||
|
#include "ruby.h"
|
||||||
|
|
||||||
|
// Ruby initiation function
|
||||||
|
void Init_Window( void );
|
||||||
|
|
||||||
|
#endif // SFML_RUBYEXT_WINDOW_HEADER_
|
@ -26,6 +26,8 @@
|
|||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
#include "Input.hpp"
|
#include "Input.hpp"
|
||||||
|
|
||||||
|
#include <SFML/Window.hpp>
|
||||||
|
|
||||||
VALUE globalSFMLNamespace;
|
VALUE globalSFMLNamespace;
|
||||||
VALUE globalKeyNamespace;
|
VALUE globalKeyNamespace;
|
||||||
VALUE globalMouseNamespace;
|
VALUE globalMouseNamespace;
|
||||||
@ -74,17 +76,17 @@ static const char * axisNames[] =
|
|||||||
void CreateKeyEnum( void )
|
void CreateKeyEnum( void )
|
||||||
{
|
{
|
||||||
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
|
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
|
||||||
for( sf::Key::Code index = sf::Key::A; index <= sf::Key::Z; index++ )
|
for( int index = static_cast< int >( sf::Key::A ); index <= sf::Key::Z; index++ )
|
||||||
{
|
{
|
||||||
rb_define_const( globalKeyNamespace, keyNamesLetters[ index - sf::Key::A ], INT2FIX( index ) );
|
rb_define_const( globalKeyNamespace, keyNamesLetters[ index - sf::Key::A ], INT2FIX( index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( sf::Key::Code index = sf::Key::Num0; index <= sf::Key::Num0; index++ )
|
for( int index = static_cast< int >( sf::Key::Num0 ); index <= sf::Key::Num0; index++ )
|
||||||
{
|
{
|
||||||
rb_define_const( globalKeyNamespace, keyNamesNum[ index - sf::Key::Num0 ], INT2FIX( index ) );
|
rb_define_const( globalKeyNamespace, keyNamesNum[ index - sf::Key::Num0 ], INT2FIX( index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( sf::Key::Code index = sf::Key::Escape; index <= sf::Key::Count; index++ )
|
for( int index = static_cast< int >( sf::Key::Escape ); index <= sf::Key::Count; index++ )
|
||||||
{
|
{
|
||||||
rb_define_const( globalKeyNamespace, keyNamesMisc[ index - sf::Key::Escape ], INT2FIX( index ) );
|
rb_define_const( globalKeyNamespace, keyNamesMisc[ index - sf::Key::Escape ], INT2FIX( index ) );
|
||||||
}
|
}
|
||||||
@ -93,7 +95,7 @@ void CreateKeyEnum( void )
|
|||||||
void CreateMouseEnum( void )
|
void CreateMouseEnum( void )
|
||||||
{
|
{
|
||||||
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
|
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
|
||||||
for( sf::Mouse::Button index = sf::Mouse::Left; index <= sf::Mouse::ButtonCount; index++ )
|
for( int index = static_cast< int >( sf::Mouse::Left ); index <= sf::Mouse::ButtonCount; index++ )
|
||||||
{
|
{
|
||||||
rb_define_const( globalMouseNamespace, mouseNames[ index - sf::Mouse::Left ], INT2FIX( index ) );
|
rb_define_const( globalMouseNamespace, mouseNames[ index - sf::Mouse::Left ], INT2FIX( index ) );
|
||||||
}
|
}
|
||||||
@ -102,7 +104,7 @@ void CreateMouseEnum( void )
|
|||||||
void CreateJoyEnum( void )
|
void CreateJoyEnum( void )
|
||||||
{
|
{
|
||||||
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
|
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
|
||||||
for( sf::Joy::Axis index = sf::Joy::AxisX; index <= sf::Joy::AxisCount; index++ )
|
for( int index = static_cast< int >( sf::Joy::AxisX ); index <= sf::Joy::AxisCount; index++ )
|
||||||
{
|
{
|
||||||
rb_define_const( globalJoyNamespace, axisNames[ index - sf::Joy::AxisX ], INT2FIX( index ) );
|
rb_define_const( globalJoyNamespace, axisNames[ index - sf::Joy::AxisX ], INT2FIX( index ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user