Moved all bindings to the "bindings" sub-directory
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0cc5563cac
commit
0e2297af28
417 changed files with 0 additions and 0 deletions
25
bindings/ruby/license.txt
Normal file
25
bindings/ruby/license.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
rbSFML
|
||||
----
|
||||
|
||||
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.
|
||||
|
26
bindings/ruby/sfml-system/extconf.rb
Normal file
26
bindings/ruby/sfml-system/extconf.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# 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.
|
||||
|
||||
require 'mkmf'
|
||||
|
||||
dir_config("system")
|
||||
have_library("sfml-system")
|
||||
create_makefile("sfml/system", "system")
|
91
bindings/ruby/sfml-system/system/Clock.cpp
Normal file
91
bindings/ruby/sfml-system/system/Clock.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* 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 "Clock.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
/* Utility class for manipulating time. */
|
||||
VALUE globalClockClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void Clock_Free( sf::Clock *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* clock.getElapsedTime() -> Float
|
||||
*
|
||||
* This function returns the time elapsed since the last call to Reset()
|
||||
* (or the construction of the instance if Reset() has not been called) in seconds.
|
||||
*/
|
||||
static VALUE Clock_GetElapsedTime( VALUE self )
|
||||
{
|
||||
sf::Clock *object = NULL;
|
||||
Data_Get_Struct( self, sf::Clock, object );
|
||||
return rb_float_new( object->GetElapsedTime() );
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* clock.reset() -> nil
|
||||
*
|
||||
* This function puts the time counter back to zero.
|
||||
*/
|
||||
static VALUE Clock_Reset( VALUE self )
|
||||
{
|
||||
sf::Clock *object = NULL;
|
||||
Data_Get_Struct( self, sf::Clock, object );
|
||||
object->Reset();
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Clock.new() -> clock
|
||||
*
|
||||
* The clock starts automatically after being constructed.
|
||||
*/
|
||||
static VALUE Clock_New( VALUE aKlass )
|
||||
{
|
||||
sf::Clock *object = new sf::Clock();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Clock_Free, object );
|
||||
rb_obj_call_init( rbData, 0, 0 );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
void Init_Clock( void )
|
||||
{
|
||||
globalClockClass = rb_define_class_under( GetNamespace(), "Clock", rb_cObject );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalClockClass, "new", FUNCPTR( Clock_New ), 0 );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalClockClass, "getElapsedTime", FUNCPTR( Clock_GetElapsedTime ), 0 );
|
||||
rb_define_method( globalClockClass, "reset", FUNCPTR( Clock_Reset ), 0 );
|
||||
|
||||
// Aliases
|
||||
rb_define_alias( globalClockClass, "elapsedTime", "getElapsedTime" );
|
||||
rb_define_alias( globalClockClass, "elapsed_time", "getElapsedTime" );
|
||||
}
|
31
bindings/ruby/sfml-system/system/Clock.hpp
Normal file
31
bindings/ruby/sfml-system/system/Clock.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_CLOCK_HEADER_
|
||||
#define SFML_RUBYEXT_CLOCK_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_Clock( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_CLOCK_HEADER_
|
263
bindings/ruby/sfml-system/system/Vector2.cpp
Normal file
263
bindings/ruby/sfml-system/system/Vector2.cpp
Normal file
|
@ -0,0 +1,263 @@
|
|||
/* 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 "Vector2.hpp"
|
||||
#include "main.hpp"
|
||||
|
||||
/* SFML::Vector2 is a simple class that defines a mathematical vector with two coordinates (x and y).
|
||||
*
|
||||
* It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc.
|
||||
*
|
||||
* This class differs from the C++ version. It will accept any value that is Numeric and both x and y must be of the same class.
|
||||
*
|
||||
* v1 = SFML::Vector2.new(16.5, 24.0)
|
||||
* v1.x = 18.2
|
||||
* y = v1.y
|
||||
*
|
||||
* v2 = v1 * v1;
|
||||
* v3 = SFML::Vector2.new
|
||||
* v3 = v1 + v2
|
||||
*
|
||||
* different = (v2 != v3);
|
||||
*/
|
||||
VALUE globalVector2Class;
|
||||
|
||||
/* Internal function
|
||||
* Forces the argument someValue to be a Vector2. IF it can convert it then it will.
|
||||
* So you can always safely asume that this function returns a Vector2 object.
|
||||
* If it fails then an exception will be thrown.
|
||||
*/
|
||||
VALUE Vector2_ForceType( VALUE someValue )
|
||||
{
|
||||
if( rb_obj_is_kind_of( someValue, rb_cArray ) == true )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someValue, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someValue, 1 );
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, arg1, arg2 );
|
||||
}
|
||||
else if( rb_obj_is_kind_of( someValue, globalVector2Class ) == true )
|
||||
{
|
||||
return someValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "expected Array or Vector2" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Internal function
|
||||
* Will copy the x and y from aSource to self.
|
||||
*/
|
||||
static void Vector2_internal_CopyFrom( VALUE self, VALUE aSource )
|
||||
{
|
||||
VALUE vectorSource = Vector2_ForceType( aSource );
|
||||
VALUE x = rb_funcall( vectorSource, rb_intern( "x" ), 0 );
|
||||
VALUE y = rb_funcall( vectorSource, rb_intern( "y" ), 0 );
|
||||
|
||||
rb_funcall( self, rb_intern( "x=" ), 1, x );
|
||||
rb_funcall( self, rb_intern( "y=" ), 1, y );
|
||||
rb_iv_set( self, "@dataType", rb_iv_get( vectorSource, "@dataType" ) );
|
||||
}
|
||||
|
||||
/* Internal function
|
||||
* Validate that the passed types are the same and numeric.
|
||||
*/
|
||||
static void Vector2_internal_ValidateTypes( VALUE aFirst, VALUE aSecond )
|
||||
{
|
||||
if( CLASS_OF( aFirst ) != CLASS_OF( aSecond ) )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "x and y must be of same type" );
|
||||
}
|
||||
|
||||
if( rb_obj_is_kind_of( aFirst, rb_cNumeric ) == Qfalse )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "x and y must be numeric!" );
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE Vector2_Negate( VALUE self )
|
||||
{
|
||||
VALUE x = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE y = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE negatedX = rb_funcall( x, rb_intern( "-@" ), 0 );
|
||||
VALUE negatedY = rb_funcall( y, rb_intern( "-@" ), 0 );
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, negatedX, negatedY );
|
||||
}
|
||||
|
||||
static VALUE Vector2_Add( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector2_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "+" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "+" ), 1, rightY );
|
||||
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY );
|
||||
}
|
||||
|
||||
static VALUE Vector2_Subtract( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector2_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "-" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "-" ), 1, rightY );
|
||||
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY );
|
||||
}
|
||||
|
||||
static VALUE Vector2_Multiply( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector2_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "*" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "*" ), 1, rightY );
|
||||
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY );
|
||||
}
|
||||
|
||||
static VALUE Vector2_Divide( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector2_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "/" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "/" ), 1, rightY );
|
||||
|
||||
return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, newX, newY );
|
||||
}
|
||||
|
||||
static VALUE Vector2_Equal( VALUE self, VALUE anArgument )
|
||||
{
|
||||
VALUE aVector = Vector2_ForceType( anArgument );
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( aVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( aVector, rb_intern( "y" ), 0 );
|
||||
|
||||
if( rb_funcall( leftX, rb_intern( "==" ), 1, rightX ) == Qtrue &&
|
||||
rb_funcall( leftY, rb_intern( "==" ), 1, rightY ) == Qtrue )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE Vector2_StrictEqual( VALUE self, VALUE anArgument )
|
||||
{
|
||||
VALUE aVector = Vector2_ForceType( anArgument );
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE rightX = rb_funcall( aVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( aVector, rb_intern( "y" ), 0 );
|
||||
|
||||
if( rb_funcall( leftX, rb_intern( "eql?" ), 1, rightX ) == Qtrue &&
|
||||
rb_funcall( leftY, rb_intern( "eql?" ), 1, rightY ) == Qtrue )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Vector2.new() -> vector
|
||||
* Vector2.new([x,y]) -> vector
|
||||
* Vector2.new(vector) -> vector
|
||||
* Vector2.new(x,y) -> vector
|
||||
*
|
||||
* Create a new vector instance.
|
||||
*/
|
||||
static VALUE Vector2_Initialize( VALUE self, VALUE someArgs )
|
||||
{
|
||||
long arrayLength = RARRAY_LEN( someArgs );
|
||||
rb_iv_set( self, "@x", INT2NUM( 0 ) );
|
||||
rb_iv_set( self, "@y", INT2NUM( 0 ) );
|
||||
|
||||
if( arrayLength == 0 )
|
||||
{
|
||||
// Nothing needs to be done
|
||||
}
|
||||
else if( arrayLength == 1 )
|
||||
{
|
||||
Vector2_internal_CopyFrom( self, rb_ary_entry( someArgs, 0 ) );
|
||||
}
|
||||
else if( arrayLength == 2 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
Vector2_internal_ValidateTypes( arg1, arg2 );
|
||||
|
||||
rb_iv_set( self, "@x", arg1 );
|
||||
rb_iv_set( self, "@y", arg2 );
|
||||
}
|
||||
|
||||
rb_iv_set( self, "@dataType", CLASS_OF( rb_iv_get( self, "@x" ) ) );
|
||||
return self;
|
||||
}
|
||||
|
||||
void Init_Vector2( void )
|
||||
{
|
||||
globalVector2Class = rb_define_class_under( GetNamespace(), "Vector2", rb_cObject );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalVector2Class, "initialize", FUNCPTR( Vector2_Initialize ), -2 );
|
||||
rb_define_method( globalVector2Class, "eql?", FUNCPTR( Vector2_Initialize ), 1 );
|
||||
|
||||
// Instance operators
|
||||
rb_define_method( globalVector2Class, "-@", FUNCPTR( Vector2_Negate ), 0 );
|
||||
rb_define_method( globalVector2Class, "+", FUNCPTR( Vector2_Add ), 1 );
|
||||
rb_define_method( globalVector2Class, "-", FUNCPTR( Vector2_Subtract ), 1 );
|
||||
rb_define_method( globalVector2Class, "*", FUNCPTR( Vector2_Multiply ), 1 );
|
||||
rb_define_method( globalVector2Class, "/", FUNCPTR( Vector2_Divide ), 1 );
|
||||
rb_define_method( globalVector2Class, "==", FUNCPTR( Vector2_Divide ), 1 );
|
||||
|
||||
// Attribute accessors
|
||||
rb_define_attr( globalVector2Class, "x", 1, 1 );
|
||||
rb_define_attr( globalVector2Class, "y", 1, 1 );
|
||||
}
|
32
bindings/ruby/sfml-system/system/Vector2.hpp
Normal file
32
bindings/ruby/sfml-system/system/Vector2.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* 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_VECTOR2_HEADER_
|
||||
#define SFML_RUBYEXT_VECTOR2_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
VALUE Vector2_ForceType( VALUE someValue );
|
||||
|
||||
void Init_Vector2( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_VECTOR2_HEADER_
|
290
bindings/ruby/sfml-system/system/Vector3.cpp
Normal file
290
bindings/ruby/sfml-system/system/Vector3.cpp
Normal file
|
@ -0,0 +1,290 @@
|
|||
/* 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 "Vector3.hpp"
|
||||
#include "main.hpp"
|
||||
|
||||
/* SFML::Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z).
|
||||
*
|
||||
* It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc.
|
||||
*
|
||||
* This class differs from the C++ version. It will accept any value that is Numeric and both x, y an z must be of the same class.
|
||||
*
|
||||
* v1 = SFML::Vector3.new(16.5, 24.0, -8.2)
|
||||
* v1.z = 18.2
|
||||
* y = v1.y
|
||||
*
|
||||
* v2 = v1 * v1;
|
||||
* v3 = SFML::Vector3.new
|
||||
* v3 = v1 + v2
|
||||
*
|
||||
* different = (v2 != v3);
|
||||
*/
|
||||
VALUE globalVector3Class;
|
||||
|
||||
/* Internal function
|
||||
* Forces the argument someValue to be a Vector3. IF it can convert it then it will.
|
||||
* So you can always safely asume that this function returns a Vector3 object.
|
||||
* If it fails then an exception will be thrown.
|
||||
*/
|
||||
VALUE Vector3_ForceType( VALUE someValue )
|
||||
{
|
||||
if( rb_obj_is_kind_of( someValue, rb_cArray ) == true )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someValue, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someValue, 1 );
|
||||
VALUE arg3 = rb_ary_entry( someValue, 2 );
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 3, arg1, arg2, arg3 );
|
||||
}
|
||||
else if( rb_obj_is_kind_of( someValue, globalVector3Class ) == true )
|
||||
{
|
||||
return someValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "expected Array or Vector3" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Internal function
|
||||
* Will copy the x, y and z from aSource to self.
|
||||
*/
|
||||
static void Vector3_internal_CopyFrom( VALUE self, VALUE aSource )
|
||||
{
|
||||
VALUE vectorSource = Vector3_ForceType( aSource );
|
||||
VALUE x = rb_funcall( vectorSource, rb_intern( "x" ), 0 );
|
||||
VALUE y = rb_funcall( vectorSource, rb_intern( "y" ), 0 );
|
||||
VALUE z = rb_funcall( vectorSource, rb_intern( "z" ), 0 );
|
||||
|
||||
rb_funcall( self, rb_intern( "x=" ), 1, x );
|
||||
rb_funcall( self, rb_intern( "y=" ), 1, y );
|
||||
rb_funcall( self, rb_intern( "z=" ), 1, z );
|
||||
rb_iv_set( self, "@dataType", rb_iv_get( vectorSource, "@dataType" ) );
|
||||
}
|
||||
|
||||
/* Internal function
|
||||
* Validate that the passed values types are the same and numeric.
|
||||
*/
|
||||
static void Vector3_internal_ValidateTypes( VALUE aFirst, VALUE aSecond, VALUE aThird )
|
||||
{
|
||||
if( CLASS_OF( aFirst ) != CLASS_OF( aSecond ) && CLASS_OF( aFirst ) != CLASS_OF( aThird ) )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "x, y and z must be of same type" );
|
||||
}
|
||||
|
||||
if( rb_obj_is_kind_of( aFirst, rb_cNumeric ) == Qfalse )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "x, y and z must be numeric!" );
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE Vector3_Negate( VALUE self )
|
||||
{
|
||||
VALUE x = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE y = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE z = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE negatedX = rb_funcall( x, rb_intern( "-@" ), 0 );
|
||||
VALUE negatedY = rb_funcall( y, rb_intern( "-@" ), 0 );
|
||||
VALUE negatedZ = rb_funcall( z, rb_intern( "-@" ), 0 );
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, negatedX, negatedY, negatedZ );
|
||||
}
|
||||
|
||||
static VALUE Vector3_Add( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector3_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( rightVector, rb_intern( "z" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "+" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "+" ), 1, rightY );
|
||||
VALUE newZ = rb_funcall( leftZ, rb_intern( "+" ), 1, rightZ );
|
||||
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ );
|
||||
}
|
||||
|
||||
static VALUE Vector3_Subtract( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector3_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( rightVector, rb_intern( "z" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "-" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "-" ), 1, rightY );
|
||||
VALUE newZ = rb_funcall( leftZ, rb_intern( "-" ), 1, rightZ );
|
||||
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ );
|
||||
}
|
||||
|
||||
static VALUE Vector3_Multiply( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector3_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( rightVector, rb_intern( "z" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "*" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "*" ), 1, rightY );
|
||||
VALUE newZ = rb_funcall( leftZ, rb_intern( "*" ), 1, rightZ );
|
||||
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ );
|
||||
}
|
||||
|
||||
static VALUE Vector3_Divide( VALUE self, VALUE aRightOperand )
|
||||
{
|
||||
VALUE rightVector = Vector3_ForceType( aRightOperand );
|
||||
// Get values
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( rightVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( rightVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( rightVector, rb_intern( "z" ), 0 );
|
||||
|
||||
// Do calculation
|
||||
VALUE newX = rb_funcall( leftX, rb_intern( "/" ), 1, rightX );
|
||||
VALUE newY = rb_funcall( leftY, rb_intern( "/" ), 1, rightY );
|
||||
VALUE newZ = rb_funcall( leftZ, rb_intern( "/" ), 1, rightZ );
|
||||
|
||||
return rb_funcall( globalVector3Class, rb_intern( "new" ), 2, newX, newY, newZ );
|
||||
}
|
||||
|
||||
static VALUE Vector3_Equal( VALUE self, VALUE anArgument )
|
||||
{
|
||||
VALUE aVector = Vector3_ForceType( anArgument );
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( aVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( aVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( aVector, rb_intern( "z" ), 0 );
|
||||
|
||||
if( rb_funcall( leftX, rb_intern( "==" ), 1, rightX ) == Qtrue &&
|
||||
rb_funcall( leftY, rb_intern( "==" ), 1, rightY ) == Qtrue &&
|
||||
rb_funcall( leftZ, rb_intern( "==" ), 1, rightZ ) == Qtrue )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE Vector3_StrictEqual( VALUE self, VALUE anArgument )
|
||||
{
|
||||
VALUE aVector = Vector3_ForceType( anArgument );
|
||||
VALUE leftX = rb_funcall( self, rb_intern( "x" ), 0 );
|
||||
VALUE leftY = rb_funcall( self, rb_intern( "y" ), 0 );
|
||||
VALUE leftZ = rb_funcall( self, rb_intern( "z" ), 0 );
|
||||
VALUE rightX = rb_funcall( aVector, rb_intern( "x" ), 0 );
|
||||
VALUE rightY = rb_funcall( aVector, rb_intern( "y" ), 0 );
|
||||
VALUE rightZ = rb_funcall( aVector, rb_intern( "z" ), 0 );
|
||||
|
||||
if( rb_funcall( leftX, rb_intern( "eql?" ), 1, rightX ) == Qtrue &&
|
||||
rb_funcall( leftY, rb_intern( "eql?" ), 1, rightY ) == Qtrue &&
|
||||
rb_funcall( leftZ, rb_intern( "eql?" ), 1, rightZ ) == Qtrue )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Vector3.new() -> vector
|
||||
* Vector3.new([x,y,z]) -> vector
|
||||
* Vector3.new(vector) -> vector
|
||||
* Vector3.new(x,y,z) -> vector
|
||||
*
|
||||
* Create a new vector instance.
|
||||
*/
|
||||
static VALUE Vector3_Initialize( VALUE self, VALUE someArgs )
|
||||
{
|
||||
long arrayLength = RARRAY_LEN( someArgs );
|
||||
rb_iv_set( self, "@x", INT2NUM( 0 ) );
|
||||
rb_iv_set( self, "@y", INT2NUM( 0 ) );
|
||||
rb_iv_set( self, "@z", INT2NUM( 0 ) );
|
||||
|
||||
if( arrayLength == 0 )
|
||||
{
|
||||
// Nothing needs to be done
|
||||
}
|
||||
else if( arrayLength == 1 )
|
||||
{
|
||||
Vector3_internal_CopyFrom( self, rb_ary_entry( someArgs, 0 ) );
|
||||
}
|
||||
else if( arrayLength == 3 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
VALUE arg3 = rb_ary_entry( someArgs, 1 );
|
||||
Vector3_internal_ValidateTypes( arg1, arg2, arg3 );
|
||||
|
||||
rb_iv_set( self, "@x", arg1 );
|
||||
rb_iv_set( self, "@y", arg2 );
|
||||
rb_iv_set( self, "@z", arg3 );
|
||||
}
|
||||
|
||||
rb_iv_set( self, "@dataType", CLASS_OF( rb_iv_get( self, "@x" ) ) );
|
||||
return self;
|
||||
}
|
||||
|
||||
void Init_Vector3( void )
|
||||
{
|
||||
globalVector3Class = rb_define_class_under( GetNamespace(), "Vector3", rb_cObject );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalVector3Class, "initialize", FUNCPTR( Vector3_Initialize ), -2 );
|
||||
rb_define_method( globalVector3Class, "eql?", FUNCPTR( Vector3_Initialize ), 1 );
|
||||
|
||||
// Instance operators
|
||||
rb_define_method( globalVector3Class, "-@", FUNCPTR( Vector3_Negate ), 0 );
|
||||
rb_define_method( globalVector3Class, "+", FUNCPTR( Vector3_Add ), 1 );
|
||||
rb_define_method( globalVector3Class, "-", FUNCPTR( Vector3_Subtract ), 1 );
|
||||
rb_define_method( globalVector3Class, "*", FUNCPTR( Vector3_Multiply ), 1 );
|
||||
rb_define_method( globalVector3Class, "/", FUNCPTR( Vector3_Divide ), 1 );
|
||||
rb_define_method( globalVector3Class, "==", FUNCPTR( Vector3_Divide ), 1 );
|
||||
|
||||
// Attribute accessors
|
||||
rb_define_attr( globalVector3Class, "x", 1, 1 );
|
||||
rb_define_attr( globalVector3Class, "y", 1, 1 );
|
||||
rb_define_attr( globalVector3Class, "z", 1, 1 );
|
||||
}
|
32
bindings/ruby/sfml-system/system/Vector3.hpp
Normal file
32
bindings/ruby/sfml-system/system/Vector3.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* 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_VECTOR3_HEADER_
|
||||
#define SFML_RUBYEXT_VECTOR3_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
VALUE Vector3_ForceType( VALUE someValue );
|
||||
|
||||
void Init_Vector3( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_VECTOR3_HEADER_
|
42
bindings/ruby/sfml-system/system/main.cpp
Normal file
42
bindings/ruby/sfml-system/system/main.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* 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"
|
||||
#include "Clock.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
|
||||
VALUE GetNamespace( void )
|
||||
{
|
||||
return globalSFMLNamespace;
|
||||
}
|
||||
|
||||
void Init_system( void )
|
||||
{
|
||||
globalSFMLNamespace = rb_define_module( "SFML" );
|
||||
rb_define_const(globalSFMLNamespace, "SystemLoaded", Qtrue);
|
||||
Init_Clock();
|
||||
Init_Vector2();
|
||||
Init_Vector3();
|
||||
}
|
37
bindings/ruby/sfml-system/system/main.hpp
Normal file
37
bindings/ruby/sfml-system/system/main.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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_MAIN_HEADER_
|
||||
#define SFML_RUBYEXT_MAIN_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
VALUE GetNamespace( void );
|
||||
|
||||
// Ruby initiation function
|
||||
extern "C" void Init_system( void );
|
||||
|
||||
typedef VALUE ( *RubyFunctionPtr )( ... );
|
||||
|
||||
#define FUNCPTR( x ) ( reinterpret_cast< RubyFunctionPtr >( x ) )
|
||||
|
||||
#endif // SFML_RUBYEXT_MAIN_HEADER_
|
26
bindings/ruby/sfml-window/extconf.rb
Normal file
26
bindings/ruby/sfml-window/extconf.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# 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.
|
||||
|
||||
require 'mkmf'
|
||||
|
||||
dir_config("window")
|
||||
have_library("sfml-window")
|
||||
create_makefile("sfml/window", "window")
|
122
bindings/ruby/sfml-window/window/Context.cpp
Normal file
122
bindings/ruby/sfml-window/window/Context.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
/* 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 "Context.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/Window/Context.hpp>
|
||||
|
||||
/* If you need to make OpenGL / graphics calls without having an active window
|
||||
* (like in a thread), you can use an instance of this class to get a valid context.
|
||||
*
|
||||
* Having a valid context is necessary for *every* OpenGL call, and for most of
|
||||
* the classes from the Graphics package.
|
||||
*
|
||||
* Note that a context is only active in its current thread, if you create a new
|
||||
* thread it will have no valid context by default.
|
||||
*
|
||||
* To use a sf::Context instance, just construct it and let it live as long as
|
||||
* you need a valid context. No explicit activation is needed, all it has to do
|
||||
* is to exist. Its destructor will take care of deactivating and freeing all
|
||||
* the attached resources.
|
||||
*/
|
||||
VALUE globalContextClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void Context_Free( sf::Context *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* context.SetActive(bool) -> nil
|
||||
*
|
||||
* Activate or deactivate explicitely the context.
|
||||
*/
|
||||
static VALUE Context_SetActive( VALUE self, VALUE anArgument )
|
||||
{
|
||||
sf::Context *object = NULL;
|
||||
Data_Get_Struct( self, sf::Context, object );
|
||||
switch( anArgument )
|
||||
{
|
||||
case Qtrue:
|
||||
object->SetActive( true );
|
||||
break;
|
||||
case Qfalse:
|
||||
object->SetActive( false );
|
||||
break;
|
||||
default:
|
||||
rb_raise( rb_eTypeError, "expected true or false" );
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Context.SetReferenceActive() -> true or false
|
||||
*
|
||||
* This function is meant to be called internally; it is used to deactivate the
|
||||
* current context by activating another one (so that we still have an active
|
||||
* context on the current thread).
|
||||
*/
|
||||
static VALUE Context_SetReferenceActive( VALUE aKlass )
|
||||
{
|
||||
if( sf::Context::SetReferenceActive() == true )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Context.new() -> context
|
||||
*
|
||||
* The constructor creates and activates the context
|
||||
*/
|
||||
static VALUE Context_New( VALUE aKlass )
|
||||
{
|
||||
sf::Context *object = new sf::Context();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Context_Free, object );
|
||||
rb_obj_call_init( rbData, 0, 0 );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
void Init_Context( void )
|
||||
{
|
||||
globalContextClass = rb_define_class_under( GetNamespace(), "Context", rb_cObject );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalContextClass, "new", FUNCPTR( Context_New ), 0 );
|
||||
rb_define_singleton_method( globalContextClass, "setReferenceActive", FUNCPTR( Context_SetReferenceActive ), 0 );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalContextClass, "setActive", FUNCPTR( Context_SetActive ), 1 );
|
||||
|
||||
// Aliases
|
||||
rb_define_alias( globalContextClass, "active=", "setActive" );
|
||||
rb_define_alias( globalContextClass, "set_active", "setActive" );
|
||||
|
||||
rb_define_alias( CLASS_OF( globalContextClass ), "set_reference_active", "setReferenceActive" );
|
||||
}
|
31
bindings/ruby/sfml-window/window/Context.hpp
Normal file
31
bindings/ruby/sfml-window/window/Context.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_CONTEXT_HEADER_
|
||||
#define SFML_RUBYEXT_CONTEXT_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_Context( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_CONTEXT_HEADER_
|
226
bindings/ruby/sfml-window/window/ContextSettings.cpp
Normal file
226
bindings/ruby/sfml-window/window/ContextSettings.cpp
Normal file
|
@ -0,0 +1,226 @@
|
|||
/* 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 "ContextSettings.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
#include <iostream>
|
||||
|
||||
/* ContextSettings allows to define several advanced settings of the OpenGL
|
||||
* context attached to a window.
|
||||
*
|
||||
* All these settings have no impact on the regular SFML rendering
|
||||
* (graphics module) -- except the anti-aliasing level, so you may need to use
|
||||
* this structure only if you're using SFML as a windowing system for custom
|
||||
* OpenGL rendering.
|
||||
*
|
||||
* The DepthBits and StencilBits members define the number of bits per pixel
|
||||
* requested for the (respectively) depth and stencil buffers.
|
||||
*
|
||||
* AntialiasingLevel represents the requested number of multisampling levels
|
||||
* for anti-aliasing.
|
||||
*
|
||||
* MajorVersion and MinorVersion define the version of the OpenGL context that
|
||||
* you want. Only versions greater or equal to 3.0 are relevant; versions
|
||||
* lesser than 3.0 are all handled the same way (i.e. you can use any version
|
||||
* < 3.0 if you don't want an OpenGL 3 context).
|
||||
*
|
||||
* Please note that these values are only a hint. No failure will be reported
|
||||
* if one or more of these values are not supported by the system; instead,
|
||||
* SFML will try to find the closest valid match. You can then retrieve the
|
||||
* settings that the window actually used to create its context, with
|
||||
* Window::GetSettings().
|
||||
*/
|
||||
VALUE globalContextSettingsClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void ContextSettings_Free( sf::ContextSettings *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_GetDepth( VALUE self )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->DepthBits );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_SetDepth( VALUE self, VALUE aValue )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->DepthBits = NUM2UINT( aValue ) );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_GetStencil( VALUE self )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->StencilBits );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_SetStencil( VALUE self, VALUE aValue )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->StencilBits = NUM2UINT( aValue ) );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_GetAntialiasing( VALUE self )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->AntialiasingLevel );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_SetAntialiasing( VALUE self, VALUE aValue )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->AntialiasingLevel = NUM2UINT( aValue ) );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_GetMajorVersion( VALUE self )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->MajorVersion );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_SetMajorVersion( VALUE self, VALUE aValue )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->MajorVersion = NUM2UINT( aValue ) );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_GetMinorVersion( VALUE self )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->MinorVersion );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_SetMinorVersion( VALUE self, VALUE aValue )
|
||||
{
|
||||
sf::ContextSettings *object = NULL;
|
||||
Data_Get_Struct( self, sf::ContextSettings, object );
|
||||
return INT2FIX( object->MinorVersion = NUM2UINT( aValue ) );
|
||||
}
|
||||
|
||||
static VALUE ContextSettings_New( VALUE aKlass, VALUE someArgs )
|
||||
{
|
||||
long arrayLength = RARRAY_LEN( someArgs );
|
||||
sf::ContextSettings *object = NULL;
|
||||
if( arrayLength == 0 )
|
||||
{
|
||||
object = new sf::ContextSettings();
|
||||
}
|
||||
else if( arrayLength == 1 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
object = new sf::ContextSettings( NUM2UINT( arg1 ) );
|
||||
}
|
||||
else if( arrayLength == 2 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
object = new sf::ContextSettings( NUM2UINT( arg1 ), NUM2UINT( arg2 ) );
|
||||
}
|
||||
|
||||
else if( arrayLength == 3 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
VALUE arg3 = rb_ary_entry( someArgs, 2 );
|
||||
object = new sf::ContextSettings( NUM2UINT( arg1 ), NUM2UINT( arg2 ), NUM2UINT( arg3 ) );
|
||||
}
|
||||
else if( arrayLength == 4 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
VALUE arg3 = rb_ary_entry( someArgs, 2 );
|
||||
VALUE arg4 = rb_ary_entry( someArgs, 3 );
|
||||
object = new sf::ContextSettings( NUM2UINT( arg1 ), NUM2UINT( arg2 ), NUM2UINT( arg3 ), NUM2UINT( arg4 ) );
|
||||
}
|
||||
else if( arrayLength == 5 )
|
||||
{
|
||||
VALUE arg1 = rb_ary_entry( someArgs, 0 );
|
||||
VALUE arg2 = rb_ary_entry( someArgs, 1 );
|
||||
VALUE arg3 = rb_ary_entry( someArgs, 2 );
|
||||
VALUE arg4 = rb_ary_entry( someArgs, 3 );
|
||||
VALUE arg5 = rb_ary_entry( someArgs, 4 );
|
||||
object = new sf::ContextSettings( NUM2UINT( arg1 ), NUM2UINT( arg2 ), NUM2UINT( arg3 ), NUM2UINT( arg4 ), NUM2UINT( arg5 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_raise( rb_eArgError, "Expected 0..5 arguments but was given %ld", arrayLength );
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, ContextSettings_Free, object );
|
||||
rb_obj_call_init( rbData, 0, 0 );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
void Init_ContextSettings( void )
|
||||
{
|
||||
globalContextSettingsClass = rb_define_class_under( GetNamespace(), "ContextSettings", rb_cObject );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalContextSettingsClass, "new", FUNCPTR( ContextSettings_New ), -2 );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalContextSettingsClass, "depthBits", FUNCPTR( ContextSettings_GetDepth ), 0 );
|
||||
rb_define_method( globalContextSettingsClass, "depthBits=", FUNCPTR( ContextSettings_SetDepth ), 1 );
|
||||
|
||||
rb_define_method( globalContextSettingsClass, "stencilBits", FUNCPTR( ContextSettings_GetStencil ), 0 );
|
||||
rb_define_method( globalContextSettingsClass, "stencilBits=", FUNCPTR( ContextSettings_SetStencil ), 1 );
|
||||
|
||||
rb_define_method( globalContextSettingsClass, "antialiasingLevel", FUNCPTR( ContextSettings_GetAntialiasing ), 0 );
|
||||
rb_define_method( globalContextSettingsClass, "antialiasingLevel=", FUNCPTR( ContextSettings_SetAntialiasing ), 1 );
|
||||
|
||||
rb_define_method( globalContextSettingsClass, "majorVersion", FUNCPTR( ContextSettings_GetMajorVersion ), 0 );
|
||||
rb_define_method( globalContextSettingsClass, "majorVersion=", FUNCPTR( ContextSettings_SetMajorVersion ), 1 );
|
||||
|
||||
rb_define_method( globalContextSettingsClass, "minorVersion", FUNCPTR( ContextSettings_GetMinorVersion ), 0 );
|
||||
rb_define_method( globalContextSettingsClass, "minorVersion=", FUNCPTR( ContextSettings_SetMinorVersion ), 1 );
|
||||
|
||||
// Aliases
|
||||
rb_define_alias( globalContextSettingsClass, "depth", "depthBits" );
|
||||
rb_define_alias( globalContextSettingsClass, "depth=", "depthBits=" );
|
||||
|
||||
rb_define_alias( globalContextSettingsClass, "stencil", "stencilBits" );
|
||||
rb_define_alias( globalContextSettingsClass, "stencil=", "stencilBits=" );
|
||||
|
||||
rb_define_alias( globalContextSettingsClass, "antialiasing", "antialiasingLevel" );
|
||||
rb_define_alias( globalContextSettingsClass, "antialiasing=", "antialiasingLevel=" );
|
||||
|
||||
rb_define_alias( globalContextSettingsClass, "major", "majorVersion" );
|
||||
rb_define_alias( globalContextSettingsClass, "major=", "majorVersion=" );
|
||||
|
||||
rb_define_alias( globalContextSettingsClass, "minor", "minorVersion" );
|
||||
rb_define_alias( globalContextSettingsClass, "minor=", "minorVersion=" );
|
||||
}
|
31
bindings/ruby/sfml-window/window/ContextSettings.hpp
Normal file
31
bindings/ruby/sfml-window/window/ContextSettings.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_CONTEXT_SETTINGS_HEADER_
|
||||
#define SFML_RUBYEXT_CONTEXT_SETTINGS_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_ContextSettings( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_CONTEXT_SETTINGS_HEADER_
|
354
bindings/ruby/sfml-window/window/Event.cpp
Normal file
354
bindings/ruby/sfml-window/window/Event.cpp
Normal file
|
@ -0,0 +1,354 @@
|
|||
/* 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 "Event.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
/* SFML::Event holds all the informations about a system event that just happened.
|
||||
*
|
||||
* Events are retrieved using the SFML::Window#GetEvent function.
|
||||
*
|
||||
* A SFML::Event instance contains the type of the event (mouse moved, key pressed, window closed, ...)
|
||||
* as well as the details about this particular event. Please note that the event parameters are
|
||||
* defined in a union, which means that only the member matching the type of the event will be properly
|
||||
* filled; all other members will have undefined values and must not be read if the type of the event
|
||||
* doesn't match. For example, if you received a KeyPressed event, then you must read the event.Key
|
||||
* member, all other members such as event.MouseMove or event.Text will have undefined values.
|
||||
*
|
||||
* The ruby version differs from C++ in that the parameters are still stored in a union but that
|
||||
* the values can be directly accessed from the event object. If you try to access any data which
|
||||
* would be considered undefined then SFML::SomeKindOfException will be thrown.
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* while event = window.getEvent()
|
||||
*
|
||||
* # Request for closing the window
|
||||
* if event.type == SFML::Event::Closed
|
||||
* window.close
|
||||
*
|
||||
* # The escape key was pressed
|
||||
* if ( event.type == sf::Event::KeyPressed ) && ( event.code == SFML::Key::Escape )
|
||||
* window.close
|
||||
*
|
||||
* # The window was resized
|
||||
* if event.type == SFML::Event::Resized
|
||||
* DoSomethingWithTheNewSize(event.size);
|
||||
*
|
||||
* # etc ...
|
||||
* end
|
||||
*/
|
||||
VALUE globalEventClass;
|
||||
|
||||
/* Joystick buttons events parameters (JoyButtonPressed, JoyButtonReleased). */
|
||||
VALUE globalJoyButtonEventClass;
|
||||
/* Joystick axis move event parameters (JoyMoved). */
|
||||
VALUE globalJoyMoveEventClass;
|
||||
/* Keyboard event parameters (KeyPressed, KeyReleased). */
|
||||
VALUE globalKeyEventClass;
|
||||
/* Mouse buttons events parameters (MouseButtonPressed, MouseButtonReleased). */
|
||||
VALUE globalMouseButtonEventClass;
|
||||
/* Mouse move event parameters (MouseMoved). */
|
||||
VALUE globalMouseMoveEventClass;
|
||||
/* Mouse wheel events parameters (MouseWheelMoved). */
|
||||
VALUE globalMouseWheelEventClass;
|
||||
/* Size events parameters (Resized). */
|
||||
VALUE globalSizeEventClass;
|
||||
/* Text event parameters (TextEntered). */
|
||||
VALUE globalTextEventClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void Event_Free( sf::Event *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
#define AXIS2NUM( x ) INT2NUM( static_cast< int > ( x ) )
|
||||
#define NUM2AXIS( x ) static_cast< sf::Joy::Axis >( NUM2INT( x ) )
|
||||
|
||||
#define KEY2NUM( x ) INT2NUM( static_cast< int > ( x ) )
|
||||
#define NUM2KEY( x ) static_cast< sf::Key::Code >( NUM2INT( x ) )
|
||||
|
||||
#define MOUSE2NUM( x ) INT2NUM( static_cast< int > ( x ) )
|
||||
#define NUM2MOUSE( x ) static_cast< sf::Mouse::Button >( NUM2INT( x ) )
|
||||
|
||||
#define EVENT_TYPE_ACCESSORS( a, b, conv1, conv2 ) \
|
||||
static VALUE a##Event_Get##b ( VALUE self ) \
|
||||
{ \
|
||||
sf::Event:: a##Event * object = NULL; \
|
||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||
return conv1 ( object-> b ); \
|
||||
} \
|
||||
\
|
||||
static VALUE a##Event_Set##b ( VALUE self, VALUE aVal ) \
|
||||
{ \
|
||||
sf::Event:: a##Event * object = NULL; \
|
||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||
return conv1 ( object-> b = conv2 ( aVal ) ); \
|
||||
}
|
||||
|
||||
#define EVENT_TYPE_BOOL_ACCESSORS( a, b ) \
|
||||
static VALUE a##Event_Get##b ( VALUE self ) \
|
||||
{ \
|
||||
sf::Event:: a##Event * object = NULL; \
|
||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||
if( object-> b == true ) \
|
||||
return Qtrue; \
|
||||
else \
|
||||
return Qfalse; \
|
||||
} \
|
||||
\
|
||||
static VALUE a##Event_Set##b ( VALUE self, VALUE aVal ) \
|
||||
{ \
|
||||
sf::Event:: a##Event * object = NULL; \
|
||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||
if( aVal == Qtrue ) \
|
||||
object-> b = true; \
|
||||
else \
|
||||
object-> b = false; \
|
||||
return aVal; \
|
||||
}
|
||||
|
||||
EVENT_TYPE_ACCESSORS( JoyButton, JoystickId, INT2NUM, NUM2UINT );
|
||||
EVENT_TYPE_ACCESSORS( JoyButton, Button, INT2NUM, NUM2UINT );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( JoyMove, JoystickId, INT2NUM, NUM2UINT );
|
||||
EVENT_TYPE_ACCESSORS( JoyMove, Axis, AXIS2NUM, NUM2AXIS );
|
||||
EVENT_TYPE_ACCESSORS( JoyMove, Position, rb_float_new, NUM2DBL );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( Key, Code, KEY2NUM, NUM2KEY );
|
||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Alt );
|
||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Control );
|
||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Shift );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( MouseButton, Button, MOUSE2NUM, NUM2MOUSE );
|
||||
EVENT_TYPE_ACCESSORS( MouseButton, X, INT2NUM, NUM2INT );
|
||||
EVENT_TYPE_ACCESSORS( MouseButton, Y, INT2NUM, NUM2INT );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( MouseMove, X, INT2NUM, NUM2INT );
|
||||
EVENT_TYPE_ACCESSORS( MouseMove, Y, INT2NUM, NUM2INT );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( MouseWheel, Delta, INT2NUM, NUM2INT );
|
||||
EVENT_TYPE_ACCESSORS( MouseWheel, X, INT2NUM, NUM2INT );
|
||||
EVENT_TYPE_ACCESSORS( MouseWheel, Y, INT2NUM, NUM2INT );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( Size, Width, INT2NUM, NUM2UINT );
|
||||
EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM, NUM2UINT );
|
||||
|
||||
EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM, NUM2UINT );
|
||||
|
||||
static VALUE Event_Initialize( VALUE self, VALUE aType )
|
||||
{
|
||||
sf::Event * object = NULL;
|
||||
Data_Get_Struct( self, sf::Event, object );
|
||||
|
||||
int typeNum = FIX2INT( aType );
|
||||
if(typeNum >= 0 && typeNum < sf::Event::Count)
|
||||
{
|
||||
rb_iv_set( self, "@type", aType );
|
||||
object->Type = static_cast< sf::Event::EventType >( typeNum );
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_raise( rb_eTypeError, "expected Fixnum in range of 0...SFML::Event::Count" );
|
||||
}
|
||||
|
||||
bool noSpecialType = false;
|
||||
VALUE eventType;
|
||||
const char * name = NULL;
|
||||
switch( object->Type )
|
||||
{
|
||||
case sf::Event::JoyButtonPressed:
|
||||
case sf::Event::JoyButtonReleased:
|
||||
eventType = Data_Wrap_Struct( globalJoyButtonEventClass, 0, 0, &object->JoyButton );
|
||||
name = "@joyButton";
|
||||
break;
|
||||
case sf::Event::JoyMoved:
|
||||
eventType = Data_Wrap_Struct( globalJoyMoveEventClass, 0, 0, &object->JoyMove );
|
||||
name = "@joyMove";
|
||||
break;
|
||||
case sf::Event::KeyPressed:
|
||||
case sf::Event::KeyReleased:
|
||||
eventType = Data_Wrap_Struct( globalKeyEventClass, 0, 0, &object->Key );
|
||||
name = "@key";
|
||||
break;
|
||||
case sf::Event::MouseButtonPressed:
|
||||
case sf::Event::MouseButtonReleased:
|
||||
eventType = Data_Wrap_Struct( globalMouseButtonEventClass, 0, 0, &object->MouseButton );
|
||||
name = "@mouseButton";
|
||||
break;
|
||||
case sf::Event::MouseMoved:
|
||||
eventType = Data_Wrap_Struct( globalMouseMoveEventClass, 0, 0, &object->MouseMove );
|
||||
name = "@mouseMove";
|
||||
break;
|
||||
case sf::Event::MouseWheelMoved:
|
||||
eventType = Data_Wrap_Struct( globalMouseWheelEventClass, 0, 0, &object->MouseWheel );
|
||||
name = "@mouseWheel";
|
||||
break;
|
||||
case sf::Event::Resized:
|
||||
eventType = Data_Wrap_Struct( globalSizeEventClass, 0, 0, &object->Size );
|
||||
name = "@resized";
|
||||
break;
|
||||
case sf::Event::TextEntered:
|
||||
eventType = Data_Wrap_Struct( globalTextEventClass, 0, 0, &object->Text );
|
||||
name = "@text";
|
||||
break;
|
||||
default:
|
||||
noSpecialType = true;
|
||||
};
|
||||
|
||||
if( noSpecialType == false )
|
||||
{
|
||||
rb_obj_call_init( eventType, 0, 0 );
|
||||
rb_iv_set( eventType, "@internal__parent_ref", self );
|
||||
rb_iv_set( self, name, eventType );
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Event.new() -> event
|
||||
*
|
||||
* The constructor creates a new event.
|
||||
*/
|
||||
static VALUE Event_New( int argc, VALUE * args, VALUE aKlass )
|
||||
{
|
||||
sf::Event *object = new sf::Event();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Event_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
void Init_Event( void )
|
||||
{
|
||||
globalEventClass = rb_define_class_under( GetNamespace(), "Event", rb_cObject );
|
||||
globalJoyButtonEventClass = rb_define_class_under( globalEventClass, "JoyButton", rb_cObject );
|
||||
globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject );
|
||||
globalKeyEventClass = rb_define_class_under( globalEventClass, "Key", rb_cObject );
|
||||
globalMouseButtonEventClass = rb_define_class_under( globalEventClass, "MouseButton", rb_cObject );
|
||||
globalMouseMoveEventClass = rb_define_class_under( globalEventClass, "MouseMove", rb_cObject );
|
||||
globalMouseWheelEventClass = rb_define_class_under( globalEventClass, "MouseWheel", rb_cObject );
|
||||
globalSizeEventClass = rb_define_class_under( globalEventClass, "Size", rb_cObject );
|
||||
globalTextEventClass = rb_define_class_under( globalEventClass, "Text", rb_cObject );
|
||||
|
||||
rb_define_const( globalEventClass, "Closed", INT2NUM( static_cast< int >( sf::Event::Closed ) ) );
|
||||
rb_define_const( globalEventClass, "Resized", INT2NUM( static_cast< int >( sf::Event::Resized ) ) );
|
||||
rb_define_const( globalEventClass, "LostFocus", INT2NUM( static_cast< int >( sf::Event::LostFocus ) ) );
|
||||
rb_define_const( globalEventClass, "GainedFocus", INT2NUM( static_cast< int >( sf::Event::GainedFocus ) ) );
|
||||
rb_define_const( globalEventClass, "TextEntered", INT2NUM( static_cast< int >( sf::Event::TextEntered ) ) );
|
||||
rb_define_const( globalEventClass, "KeyPressed", INT2NUM( static_cast< int >( sf::Event::KeyPressed ) ) );
|
||||
rb_define_const( globalEventClass, "KeyReleased", INT2NUM( static_cast< int >( sf::Event::KeyReleased ) ) );
|
||||
rb_define_const( globalEventClass, "MouseWheelMoved", INT2NUM( static_cast< int >( sf::Event::MouseWheelMoved ) ) );
|
||||
rb_define_const( globalEventClass, "MouseButtonPressed", INT2NUM( static_cast< int >( sf::Event::MouseButtonPressed ) ) );
|
||||
rb_define_const( globalEventClass, "MouseButtonReleased", INT2NUM( static_cast< int >( sf::Event::MouseButtonReleased ) ) );
|
||||
rb_define_const( globalEventClass, "MouseMoved", INT2NUM( static_cast< int >( sf::Event::MouseMoved ) ) );
|
||||
rb_define_const( globalEventClass, "MouseEntered", INT2NUM( static_cast< int >( sf::Event::MouseEntered ) ) );
|
||||
rb_define_const( globalEventClass, "MouseLeft", INT2NUM( static_cast< int >( sf::Event::MouseLeft ) ) );
|
||||
rb_define_const( globalEventClass, "JoyButtonPressed", INT2NUM( static_cast< int >( sf::Event::JoyButtonPressed ) ) );
|
||||
rb_define_const( globalEventClass, "JoyButtonReleased", INT2NUM( static_cast< int >( sf::Event::JoyButtonReleased ) ) );
|
||||
rb_define_const( globalEventClass, "JoyMoved", INT2NUM( static_cast< int >( sf::Event::JoyMoved ) ) );
|
||||
rb_define_const( globalEventClass, "Count", INT2NUM( static_cast< int >( sf::Event::Count ) ) );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalEventClass, "new", FUNCPTR( Event_New ), -1 );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalEventClass, "initialize", FUNCPTR( Event_Initialize ), 1 );
|
||||
rb_define_attr( globalEventClass, "joyButton", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "joyMove", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "key", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "mouseButton", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "mouseMove", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "mouseWheel", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "size", 1, 0 );
|
||||
rb_define_attr( globalEventClass, "text", 1, 0 );
|
||||
|
||||
// JoyButton methods
|
||||
rb_define_method( globalJoyButtonEventClass, "joystickId", FUNCPTR( JoyButtonEvent_GetJoystickId ), 0 );
|
||||
rb_define_method( globalJoyButtonEventClass, "joystickId=", FUNCPTR( JoyButtonEvent_SetJoystickId ), 1 );
|
||||
|
||||
rb_define_method( globalJoyButtonEventClass, "button", FUNCPTR( JoyButtonEvent_GetButton ), 0 );
|
||||
rb_define_method( globalJoyButtonEventClass, "button=", FUNCPTR( JoyButtonEvent_SetButton ), 1 );
|
||||
|
||||
// JoyMove methods
|
||||
rb_define_method( globalJoyMoveEventClass, "joystickId", FUNCPTR( JoyMoveEvent_GetJoystickId ), 0 );
|
||||
rb_define_method( globalJoyMoveEventClass, "joystickId=", FUNCPTR( JoyMoveEvent_SetJoystickId ), 1 );
|
||||
|
||||
rb_define_method( globalJoyMoveEventClass, "axis", FUNCPTR( JoyMoveEvent_GetAxis ), 0 );
|
||||
rb_define_method( globalJoyMoveEventClass, "axis=", FUNCPTR( JoyMoveEvent_SetAxis ), 1 );
|
||||
|
||||
rb_define_method( globalJoyMoveEventClass, "position", FUNCPTR( JoyMoveEvent_GetPosition ), 0 );
|
||||
rb_define_method( globalJoyMoveEventClass, "position=", FUNCPTR( JoyMoveEvent_SetPosition ), 1 );
|
||||
|
||||
// Key methods
|
||||
rb_define_method( globalKeyEventClass, "code", FUNCPTR( KeyEvent_GetCode ), 0 );
|
||||
rb_define_method( globalKeyEventClass, "code=", FUNCPTR( KeyEvent_SetCode ), 1 );
|
||||
|
||||
rb_define_method( globalKeyEventClass, "alt", FUNCPTR( KeyEvent_GetAlt ), 0 );
|
||||
rb_define_method( globalKeyEventClass, "alt=", FUNCPTR( KeyEvent_SetAlt ), 1 );
|
||||
|
||||
rb_define_method( globalKeyEventClass, "control", FUNCPTR( KeyEvent_GetControl ), 0 );
|
||||
rb_define_method( globalKeyEventClass, "control=", FUNCPTR( KeyEvent_SetControl ), 1 );
|
||||
|
||||
rb_define_method( globalKeyEventClass, "shift", FUNCPTR( KeyEvent_GetShift ), 0 );
|
||||
rb_define_method( globalKeyEventClass, "shift=", FUNCPTR( KeyEvent_SetShift ), 1 );
|
||||
|
||||
// MouseButton methods
|
||||
rb_define_method( globalMouseButtonEventClass, "button", FUNCPTR( MouseButtonEvent_GetButton ), 0 );
|
||||
rb_define_method( globalMouseButtonEventClass, "button=", FUNCPTR( MouseButtonEvent_SetButton ), 1 );
|
||||
|
||||
rb_define_method( globalMouseButtonEventClass, "x", FUNCPTR( MouseButtonEvent_GetX ), 0 );
|
||||
rb_define_method( globalMouseButtonEventClass, "x=", FUNCPTR( MouseButtonEvent_SetX ), 1 );
|
||||
|
||||
rb_define_method( globalMouseButtonEventClass, "y", FUNCPTR( MouseButtonEvent_GetY ), 0 );
|
||||
rb_define_method( globalMouseButtonEventClass, "y=", FUNCPTR( MouseButtonEvent_SetY ), 1 );
|
||||
|
||||
// MouseMove methods
|
||||
rb_define_method( globalMouseMoveEventClass, "x", FUNCPTR( MouseMoveEvent_GetX ), 0 );
|
||||
rb_define_method( globalMouseMoveEventClass, "x=", FUNCPTR( MouseMoveEvent_SetX ), 1 );
|
||||
|
||||
rb_define_method( globalMouseMoveEventClass, "y", FUNCPTR( MouseMoveEvent_GetY ), 0 );
|
||||
rb_define_method( globalMouseMoveEventClass, "y=", FUNCPTR( MouseMoveEvent_SetY ), 1 );
|
||||
|
||||
// MouseWheel methods
|
||||
rb_define_method( globalMouseWheelEventClass, "delta", FUNCPTR( MouseWheelEvent_GetDelta ), 0 );
|
||||
rb_define_method( globalMouseWheelEventClass, "delta=", FUNCPTR( MouseWheelEvent_SetDelta ), 1 );
|
||||
|
||||
rb_define_method( globalMouseWheelEventClass, "x", FUNCPTR( MouseWheelEvent_GetX ), 0 );
|
||||
rb_define_method( globalMouseWheelEventClass, "x=", FUNCPTR( MouseWheelEvent_SetX ), 1 );
|
||||
|
||||
rb_define_method( globalMouseWheelEventClass, "y", FUNCPTR( MouseWheelEvent_GetY ), 0 );
|
||||
rb_define_method( globalMouseWheelEventClass, "y=", FUNCPTR( MouseWheelEvent_SetY ), 1 );
|
||||
|
||||
// Size methods
|
||||
rb_define_method( globalSizeEventClass, "width", FUNCPTR( SizeEvent_GetWidth ), 0 );
|
||||
rb_define_method( globalSizeEventClass, "width=", FUNCPTR( SizeEvent_SetWidth ), 1 );
|
||||
|
||||
rb_define_method( globalSizeEventClass, "height", FUNCPTR( SizeEvent_GetWidth ), 0 );
|
||||
rb_define_method( globalSizeEventClass, "height=", FUNCPTR( SizeEvent_SetWidth ), 1 );
|
||||
|
||||
// Text methods
|
||||
rb_define_method( globalTextEventClass, "unicode", FUNCPTR( TextEvent_GetUnicode ), 0 );
|
||||
rb_define_method( globalTextEventClass, "unicode=", FUNCPTR( TextEvent_SetUnicode ), 1 );
|
||||
}
|
31
bindings/ruby/sfml-window/window/Event.hpp
Normal file
31
bindings/ruby/sfml-window/window/Event.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_EVENT_HEADER_
|
||||
#define SFML_RUBYEXT_EVENT_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_Event( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_EVENT_HEADER_
|
212
bindings/ruby/sfml-window/window/Input.cpp
Normal file
212
bindings/ruby/sfml-window/window/Input.cpp
Normal file
|
@ -0,0 +1,212 @@
|
|||
/* 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 "Input.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/Window/Input.hpp>
|
||||
|
||||
/* SFML::Input provides a way to access the state of keys, mouse buttons,
|
||||
* mouse position, joystick buttons and jostick axis.
|
||||
*
|
||||
* SFML::Input provides the same informations as the event system, but these
|
||||
* informations can be accessed at any time, which is more convenient in many
|
||||
* situations.
|
||||
*
|
||||
* For example, to move an entity you can decide to catch the
|
||||
* SFML::Event::KeyPressed event on arrow keys. But if you do so, you will only
|
||||
* receive one event when the key gets pressed (or repeated events if you
|
||||
* activated this feature), thus the entity will not move smoothly. The best
|
||||
* solution here is to use sf::Input::IsKeyDown so that you can update your
|
||||
* entity's position at every iteration of your game loop, not only when you
|
||||
* catch a KeyPressed event.
|
||||
*
|
||||
* Note that instances of sf::Input cannot be created directly, they must be
|
||||
* retrieved from a window (sf::Window) with its GetInput() function.
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* # Retrieve the input object attached to our window
|
||||
* input = window.getInput();
|
||||
*
|
||||
* # Move an entity according to the current keys state
|
||||
* offset = 5.0 * window.GetFrameTime(); # 5 pixels/sec
|
||||
* entity.move( -offset, 0 ) if input.isKeyDown?( SFML::Key::Left )
|
||||
* entity.move( offset, 0 ) if input.isKeyDown?( SFML::Key::Right )
|
||||
* entity.move( 0, -offset ) if input.isKeyDown?( SFML::Key::Up )
|
||||
* entity.move( 0, offset ) if input.isKeyDown?( SFML::Key::Down )
|
||||
*/
|
||||
VALUE globalInputClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void Input_Free( sf::Event *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.isKeyDown( keycode ) -> true or false
|
||||
*
|
||||
* Get the current state of a key (pressed or released).
|
||||
*/
|
||||
static VALUE Input_IsKeyDown( VALUE self, VALUE aKeyCode )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
sf::Key::Code rawCode = static_cast< sf::Key::Code > ( NUM2INT( aKeyCode ) );
|
||||
if( object->IsKeyDown( rawCode ) == true )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.isMouseButtonDown( keycode ) -> true or false
|
||||
*
|
||||
* Get the current state of a mouse button (pressed or released).
|
||||
*/
|
||||
static VALUE Input_IsMouseButtonDown( VALUE self, VALUE aMouseButton )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
sf::Mouse::Button rawButton = static_cast< sf::Mouse::Button > ( NUM2INT( aMouseButton ) );
|
||||
if( object->IsMouseButtonDown( rawButton ) == true )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.isJoystickButtonDown( joystick, button ) -> true or false
|
||||
*
|
||||
* Get the current state of a joystick button (pressed or released).
|
||||
*/
|
||||
static VALUE Input_IsJoystickButtonDown( VALUE self, VALUE aJoystick, VALUE aButton )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
unsigned int rawJoystick = NUM2UINT( aJoystick );
|
||||
unsigned int rawButton = NUM2UINT( aButton );
|
||||
if( object->IsJoystickButtonDown( aJoystick, rawButton ) == true )
|
||||
{
|
||||
return Qtrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.getMouseX() -> fixnum
|
||||
*
|
||||
* The returned position is relative to the left border of the owner window.
|
||||
*/
|
||||
static VALUE Input_GetMouseX( VALUE self, VALUE aMouseButton )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
return INT2FIX( object->GetMouseX() );
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.getMouseY() -> fixnum
|
||||
*
|
||||
* The returned position is relative to the top border of the owner window.
|
||||
*/
|
||||
static VALUE Input_GetMouseY( VALUE self, VALUE aMouseButton )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
return INT2FIX( object->GetMouseY() );
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* input.getJoystickAxis( joystick, axis ) -> true or false
|
||||
*
|
||||
* The returned position is in the range [-100, 100], except the POV which is an angle and is thus defined in [0, 360].
|
||||
*/
|
||||
static VALUE Input_GetJoystickAxis( VALUE self, VALUE aJoystick, VALUE anAxis )
|
||||
{
|
||||
sf::Input *object = NULL;
|
||||
Data_Get_Struct( self, sf::Input, object );
|
||||
unsigned int rawJoystick = NUM2UINT( aJoystick );
|
||||
sf::Joy::Axis rawAxis = static_cast< sf::Joy::Axis >( NUM2INT( anAxis ) );
|
||||
return rb_float_new( object->GetJoystickAxis( rawJoystick, rawAxis ) );
|
||||
}
|
||||
|
||||
/* call-seq:
|
||||
* Input.new() -> input
|
||||
*
|
||||
* The constructor creates a new input.
|
||||
*/
|
||||
static VALUE Input_New( int argc, VALUE * args, VALUE aKlass )
|
||||
{
|
||||
sf::Input *object = new sf::Input();
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Input_Free, object );
|
||||
rb_obj_call_init( rbData, argc, args );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
void Init_Input( void )
|
||||
{
|
||||
globalInputClass = rb_define_class_under( GetNamespace(), "Input", rb_cObject );
|
||||
|
||||
// Class methods
|
||||
rb_define_singleton_method( globalInputClass, "new", FUNCPTR( Input_New ), -1 );
|
||||
|
||||
// Instance methods
|
||||
rb_define_method( globalInputClass, "isKeyDown", FUNCPTR( Input_IsKeyDown ), 1 );
|
||||
rb_define_method( globalInputClass, "isMouseButtonDown", FUNCPTR( Input_IsMouseButtonDown ), 1 );
|
||||
rb_define_method( globalInputClass, "isJoystickButtonDown", FUNCPTR( Input_IsJoystickButtonDown ), 2 );
|
||||
rb_define_method( globalInputClass, "getMouseX", FUNCPTR( Input_GetMouseX ), 0 );
|
||||
rb_define_method( globalInputClass, "getMouseY", FUNCPTR( Input_GetMouseY ), 0 );
|
||||
rb_define_method( globalInputClass, "getJoystickAxis", FUNCPTR( Input_GetJoystickAxis ), 2 );
|
||||
|
||||
// Aliases
|
||||
rb_define_alias( globalInputClass, "key_down?", "isKeyDown");
|
||||
rb_define_alias( globalInputClass, "keyDown?", "isKeyDown");
|
||||
|
||||
rb_define_alias( globalInputClass, "mouse_button_down?", "isMouseButtonDown");
|
||||
rb_define_alias( globalInputClass, "mouseButtonDown?", "isMouseButtonDown");
|
||||
|
||||
rb_define_alias( globalInputClass, "joystick_button_down?", "isJoystickButtonDown");
|
||||
rb_define_alias( globalInputClass, "joystickButtonDown?", "isJoystickButtonDown");
|
||||
|
||||
rb_define_alias( globalInputClass, "mouseX", "getMouseX");
|
||||
rb_define_alias( globalInputClass, "mouse_x", "getMouseX");
|
||||
|
||||
rb_define_alias( globalInputClass, "mouseY", "getMouseY");
|
||||
rb_define_alias( globalInputClass, "mouse_y", "getMouseY");
|
||||
|
||||
rb_define_alias( globalInputClass, "joystickAxis", "getJoystickAxis");
|
||||
rb_define_alias( globalInputClass, "joystick_axis", "getJoystickAxis");
|
||||
}
|
31
bindings/ruby/sfml-window/window/Input.hpp
Normal file
31
bindings/ruby/sfml-window/window/Input.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_INPUT_HEADER_
|
||||
#define SFML_RUBYEXT_INPUT_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_Input( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_INPUT_HEADER_
|
125
bindings/ruby/sfml-window/window/VideoMode.cpp
Normal file
125
bindings/ruby/sfml-window/window/VideoMode.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
/* 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 "VideoMode.hpp"
|
||||
#include "main.hpp"
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <iostream>
|
||||
|
||||
/* A video mode is defined by a width and a height (in pixels) and a depth (in bits per pixel).
|
||||
*
|
||||
* Video modes are used to setup windows (sf::Window) at creation time.
|
||||
*
|
||||
* The main usage of video modes is for fullscreen mode: indeed you must use one of the valid
|
||||
* video modes allowed by the OS (which are defined by what the monitor and the graphics card support),
|
||||
* otherwise your window creation will just fail.
|
||||
*
|
||||
* SFML::VideoMode provides a static function for retrieving the list of all the video modes supported by
|
||||
* the system: getFullscreenModes().
|
||||
*
|
||||
* A custom video mode can also be checked directly for fullscreen compatibility with its isValid() function.
|
||||
*
|
||||
* Additionnally, SFML::VideoMode provides a static function to get the mode currently used by the desktop:
|
||||
* getDesktopMode(). This allows to build windows with the same size or pixel depth as the current resolution.
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* # Display the list of all the video modes available for fullscreen
|
||||
* modes = SFMK::VideoMode.getFullscreenModes()
|
||||
* i = 0
|
||||
* modes.each do | mode |
|
||||
* puts "Mode #" + i + ": " + mode.Width + "x" + mode.Height + " - " + mode.BitsPerPixel + " bpp"
|
||||
*
|
||||
* end
|
||||
*
|
||||
* # Create a window with the same pixel depth as the desktop
|
||||
* desktop = SFML::VideoMode.getDesktopMode()
|
||||
* window.create( SFML::VideoMode.new( 1024, 768, desktop.BitsPerPixel ), "SFML window" )
|
||||
*/
|
||||
VALUE globalVideoModeClass;
|
||||
|
||||
/* Free a heap allocated object
|
||||
* Not accessible trough ruby directly!
|
||||
*/
|
||||
static void VideoMode_Free( sf::VideoMode *anObject )
|
||||
{
|
||||
delete anObject;
|
||||
}
|
||||
|
||||
static VALUE VideoMode_GetDesktopMode( VALUE aKlass )
|
||||
{
|
||||
sf::VideoMode *object = new sf::VideoMode( sf::VideoMode::GetDesktopMode() );
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
|
||||
rb_obj_call_init( rbData, 0, 0 );
|
||||
return rbData;
|
||||
}
|
||||
|
||||
static VALUE VideoMode_GetFullscreenModes( VALUE aKlass )
|
||||
{
|
||||
std::vector< sf::VideoMode >& modes = sf::VideoMode::GetFullscreenModes();
|
||||
VALUE array = rb_ary_new();
|
||||
for( std::vector< sf::VideoMode >::const_iterator it = modes.begin(), end = modes.end(); it != end; it++ )
|
||||
{
|
||||
sf::VideoMode *object = new sf::VideoMode( *it );
|
||||
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
|
||||
rb_obj_call_init( rbData, 0, 0 );
|
||||
rb_ary_push( array, rbData );
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static VALUE VideoMode_New( int argc, VALUE *args, VALUE aKlass )
|
||||
{
|
||||
sf::VideoMode *object = NULL;
|
||||
switch( argc )
|
||||
{
|
||||
case 0:
|
||||
object = new sf::VideoMode();
|
||||
break;
|
||||
case 2:
|
||||
object = new sf::VideoMode( UINT2FIX( args[0] ), UINT2FIX( args[1] ) );
|
||||
break;
|
||||
case 3:
|
||||
object = new sf::VideoMode( UINT2FIX( args[0] ), UINT2FIX( args[1] ), UINT2FIX( args[2] ) );
|
||||
break;
|
||||
default:
|
||||
rb_raise( rb_eArgError, "Expected 0 2 or 3 arguments but was given %ld", arrayLength );
|
||||
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
|
||||
|
||||
// Aliases
|
||||
}
|
31
bindings/ruby/sfml-window/window/VideoMode.hpp
Normal file
31
bindings/ruby/sfml-window/window/VideoMode.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_VIDEO_MODE_HEADER_
|
||||
#define SFML_RUBYEXT_VIDEO_MODE_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
// Ruby initiation function
|
||||
void Init_VideoMode( void );
|
||||
|
||||
#endif // SFML_RUBYEXT_VIDEO_MODE_HEADER_
|
136
bindings/ruby/sfml-window/window/main.cpp
Normal file
136
bindings/ruby/sfml-window/window/main.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
/* 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"
|
||||
#include "Context.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
#include "Event.hpp"
|
||||
#include "Input.hpp"
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
VALUE globalKeyNamespace;
|
||||
VALUE globalMouseNamespace;
|
||||
VALUE globalJoyNamespace;
|
||||
VALUE globalStyleNamespace;
|
||||
|
||||
VALUE GetNamespace( void )
|
||||
{
|
||||
return globalSFMLNamespace;
|
||||
}
|
||||
|
||||
static const char * keyNamesLetters[] =
|
||||
{
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O"
|
||||
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
||||
};
|
||||
|
||||
static const char * keyNamesNum[] =
|
||||
{
|
||||
"Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9"
|
||||
};
|
||||
|
||||
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",
|
||||
"F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "Pause"
|
||||
"Count"
|
||||
};
|
||||
|
||||
static const char * mouseNames[] =
|
||||
{
|
||||
"Left", "Right", "Middle", "XButton1", "XButton2", "ButtonCount"
|
||||
};
|
||||
|
||||
static const char * axisNames[] =
|
||||
{
|
||||
"AxisX", "AxisY", "AxisZ", "AxisR", "AxisU", "AxisV", "AxisPOV",
|
||||
"AxisCount"
|
||||
};
|
||||
|
||||
void CreateKeyEnum( void )
|
||||
{
|
||||
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
|
||||
for( sf::Key::Code index = sf::Key::A; index <= sf::Key::Z; 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++ )
|
||||
{
|
||||
rb_define_const( globalKeyNamespace, keyNamesNum[ index - sf::Key::Num0 ], INT2FIX( index ) );
|
||||
}
|
||||
|
||||
for( sf::Key::Code index = sf::Key::Escape; index <= sf::Key::Count; index++ )
|
||||
{
|
||||
rb_define_const( globalKeyNamespace, keyNamesMisc[ index - sf::Key::Escape ], INT2FIX( index ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CreateMouseEnum( void )
|
||||
{
|
||||
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
|
||||
for( sf::Mouse::Button index = sf::Mouse::Left; index <= sf::Mouse::ButtonCount; index++ )
|
||||
{
|
||||
rb_define_const( globalMouseNamespace, mouseNames[ index - sf::Mouse::Left ], INT2FIX( index ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CreateJoyEnum( void )
|
||||
{
|
||||
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
|
||||
for( sf::Joy::Axis index = sf::Joy::AxisX; index <= sf::Joy::AxisCount; index++ )
|
||||
{
|
||||
rb_define_const( globalJoyNamespace, axisNames[ index - sf::Joy::AxisX ], INT2FIX( index ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CreateStyleEnum( void )
|
||||
{
|
||||
globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" );
|
||||
rb_define_const( globalStyleNamespace, "None", sf::Style::None );
|
||||
rb_define_const( globalStyleNamespace, "Titlebar", sf::Style::Titlebar );
|
||||
rb_define_const( globalStyleNamespace, "Resize", sf::Style::Resize );
|
||||
rb_define_const( globalStyleNamespace, "Close", sf::Style::Close );
|
||||
rb_define_const( globalStyleNamespace, "Fullscreen", sf::Style::Fullscreen );
|
||||
rb_define_const( globalStyleNamespace, "Default", sf::Style::Default );
|
||||
}
|
||||
|
||||
void Init_window( void )
|
||||
{
|
||||
globalSFMLNamespace = rb_define_module( "SFML" );
|
||||
rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue );
|
||||
|
||||
CreateKeyEnum();
|
||||
CreateMouseEnum();
|
||||
CreateJoyEnum();
|
||||
CreateStyleEnum();
|
||||
|
||||
Init_Context();
|
||||
Init_ContextSettings();
|
||||
Init_Event();
|
||||
Init_Input();
|
||||
}
|
37
bindings/ruby/sfml-window/window/main.hpp
Normal file
37
bindings/ruby/sfml-window/window/main.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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_MAIN_HEADER_
|
||||
#define SFML_RUBYEXT_MAIN_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
VALUE GetNamespace( void );
|
||||
|
||||
// Ruby initiation function
|
||||
extern "C" void Init_window( void );
|
||||
|
||||
typedef VALUE ( *RubyFunctionPtr )( ... );
|
||||
|
||||
#define FUNCPTR( x ) ( reinterpret_cast< RubyFunctionPtr >( x ) )
|
||||
|
||||
#endif // SFML_RUBYEXT_MAIN_HEADER_
|
77
bindings/ruby/testing/vector2.rb
Normal file
77
bindings/ruby/testing/vector2.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
class Vector2
|
||||
attr_accessor :x, :y
|
||||
|
||||
def initialize( *args )
|
||||
if args.size == 0
|
||||
@x = 0
|
||||
@y = 0
|
||||
elsif args.size == 1
|
||||
copyFrom( args[0] )
|
||||
elsif args.size == 2
|
||||
Vector2.valid? args[0], args[1]
|
||||
|
||||
@x = args[0]
|
||||
@y = args[1]
|
||||
else
|
||||
raise ArgumentError.new( "invalid argument list" )
|
||||
end
|
||||
|
||||
@dataType = x.class
|
||||
end
|
||||
|
||||
def copyFrom( source )
|
||||
unless source.is_a?( Array ) || source.is_a?( Vector2 )
|
||||
raise ArgumentError.new( "expected Array or Vector2" )
|
||||
end
|
||||
Vector2.valid? source[0], source[1]
|
||||
|
||||
@x = source[0]
|
||||
@y = source[1]
|
||||
end
|
||||
|
||||
def -@
|
||||
Vector2.new( -x, -y )
|
||||
end
|
||||
|
||||
def +( right )
|
||||
Vector2.new( x + right.x, y + right.y )
|
||||
end
|
||||
|
||||
def -( right )
|
||||
Vector2.new( x - right.x, y - right.y )
|
||||
end
|
||||
|
||||
def *( right )
|
||||
Vector2.new( x * right.x, y * right.y )
|
||||
end
|
||||
|
||||
def /( right )
|
||||
Vector2.new( x / right.x, y / right.y )
|
||||
end
|
||||
|
||||
def ==( right )
|
||||
x == right.x && y == right.y
|
||||
end
|
||||
|
||||
def []( index )
|
||||
if index == 0 || index == :x
|
||||
return x
|
||||
elsif index == 1 || index == :y
|
||||
return y
|
||||
end
|
||||
|
||||
raise ArgumentError.new( "Expected index to be either 0..1 or :x and :y" )
|
||||
end
|
||||
|
||||
def self.valid?( x, y )
|
||||
if x.class != y.class
|
||||
raise RuntimeError.new( "x and y must be of same type" )
|
||||
end
|
||||
|
||||
if x.is_a?( Numeric ) == false
|
||||
raise RuntimeError.new( "x and y must be numeric!" )
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue