From: Javier Sancho Date: Sat, 21 Mar 2020 11:34:48 +0000 (+0100) Subject: set-position! X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=2cdd08f70b0a58b2f00b341df5b73704d3febd47;p=guile-irrlicht.git set-position! --- diff --git a/Makefile.am b/Makefile.am index 6b42a54..474823b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ libguile_irrlicht_la_SOURCES = \ src/animated-mesh-scene-node.cpp \ src/camera-scene-node.cpp \ src/color.cpp \ + src/cursor-control.cpp \ src/device.cpp \ src/dimension2d.cpp \ src/driver-types.cpp \ @@ -41,6 +42,7 @@ libguile_irrlicht_la_SOURCES = \ src/mesh.cpp \ src/mesh-scene-node.cpp \ src/misc.cpp \ + src/position2d.cpp \ src/rect.cpp \ src/reference-counted.cpp \ src/scene-manager.cpp \ diff --git a/src/cursor-control.cpp b/src/cursor-control.cpp new file mode 100644 index 0000000..4a870e8 --- /dev/null +++ b/src/cursor-control.cpp @@ -0,0 +1,56 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "cursor-control.h" +#include "position2d.h" +#include "wrapped.h" + +extern "C" { + + void + init_cursor_control (void) + { + init_cursor_control_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::ICursorControl*, "cursor-control", + init_cursor_control_type, cursor_control_p, + wrap_cursor_control, unwrap_cursor_control); + + SCM + irr_gui_setPosition (SCM wrapped_cursor_control, + SCM position) + { + irr::gui::ICursorControl* control = unwrap_cursor_control (wrapped_cursor_control); + if (scm_is_integer (scm_car (position)) && scm_is_integer (scm_cadr (position))) + { + control->setPosition (scm_to_position2d_s32 (position)); + } + else + { + control->setPosition (scm_to_position2d_f32 (position)); + } + return SCM_UNSPECIFIED; + } + +} diff --git a/src/cursor-control.h b/src/cursor-control.h new file mode 100644 index 0000000..9191881 --- /dev/null +++ b/src/cursor-control.h @@ -0,0 +1,43 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_CURSOR_CONTROL_H_INCLUDED__ +#define __GUILE_IRRLICHT_CURSOR_CONTROL_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_cursor_control (void); + + DECLARE_WRAPPED_TYPE (irr::gui::ICursorControl*, init_cursor_control_type, + cursor_control_p, wrap_cursor_control, unwrap_cursor_control); + + SCM + irr_gui_setPosition (SCM wrapped_cursor_control, + SCM position); + +} + +#endif diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index 4846b69..dad52c2 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -24,6 +24,7 @@ #include "animated-mesh.h" #include "animated-mesh-scene-node.h" #include "camera-scene-node.h" +#include "cursor-control.h" #include "device.h" #include "file-archive.h" #include "file-system.h" @@ -48,6 +49,7 @@ extern "C" { init_animated_mesh (); init_animated_mesh_scene_node (); init_camera_scene_node (); + init_cursor_control (); init_device (); init_file_archive (); init_file_system (); diff --git a/src/misc.cpp b/src/misc.cpp index e030979..9997fdd 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -21,7 +21,11 @@ #include #include + +#include "cursor-control.h" +#include "mesh-scene-node.h" #include "misc.h" +#include "scene-node.h" #include "video-driver.h" #include "wchar.h" @@ -31,7 +35,8 @@ extern "C" { init_misc (void) { scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); - scm_c_export ("get-name", NULL); + scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition); + scm_c_export ("get-name", "set-position!", NULL); } SCM @@ -48,4 +53,23 @@ extern "C" { } } + SCM + irr_setPosition (SCM wrapped_obj, + SCM position) + { + if (cursor_control_p (wrapped_obj)) + { + return irr_gui_setPosition (wrapped_obj, position); + } + else if (scene_node_p (wrapped_obj) || mesh_scene_node_p (wrapped_obj)) + { + return irr_scene_setPosition (wrapped_obj, position); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set position for object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + } diff --git a/src/misc.h b/src/misc.h index b81fd9b..6fb1d11 100644 --- a/src/misc.h +++ b/src/misc.h @@ -33,6 +33,10 @@ extern "C" { SCM irr_getName (SCM wrapped_obj); + SCM + irr_setPosition (SCM wrapped_obj, + SCM position); + } #endif diff --git a/src/position2d.cpp b/src/position2d.cpp new file mode 100644 index 0000000..16c44bc --- /dev/null +++ b/src/position2d.cpp @@ -0,0 +1,44 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "position2d.h" + +extern "C" { + + irr::core::position2d + scm_to_position2d_f32 (SCM position2d) + { + return irr::core::position2d + (scm_to_double (scm_car (position2d)), + scm_to_double (scm_cadr (position2d))); + } + + irr::core::position2d + scm_to_position2d_s32 (SCM position2d) + { + return irr::core::position2d + (scm_to_int32 (scm_car (position2d)), + scm_to_int32 (scm_cadr (position2d))); + } + +} diff --git a/src/position2d.h b/src/position2d.h new file mode 100644 index 0000000..2874998 --- /dev/null +++ b/src/position2d.h @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_POSITION_2D_H_INCLUDED__ +#define __GUILE_IRRLICHT_POSITION_2D_H_INCLUDED__ + +#include +#include + +extern "C" { + + irr::core::position2d + scm_to_position2d_f32 (SCM position2d); + + irr::core::position2d + scm_to_position2d_s32 (SCM position2d); + +} + +#endif diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 859fbc8..d7b5e36 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -21,9 +21,12 @@ #include #include + #include "animated-mesh-scene-node.h" +#include "mesh-scene-node.h" #include "scene-node.h" #include "texture.h" +#include "vector3d.h" #include "wrapped.h" extern "C" { @@ -65,4 +68,26 @@ extern "C" { return SCM_UNSPECIFIED; } + SCM + irr_scene_setPosition (SCM wrapped_scene_node, + SCM position) + { + if (scene_node_p (wrapped_scene_node)) + { + unwrap_scene_node (wrapped_scene_node)-> + setPosition (scm_to_vector3df (position)); + } + else if (mesh_scene_node_p (wrapped_scene_node)) + { + unwrap_mesh_scene_node (wrapped_scene_node)-> + setPosition (scm_to_vector3df (position)); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S", + scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); + } + return SCM_UNSPECIFIED; + } + } diff --git a/src/scene-node.h b/src/scene-node.h index c41d3cc..afb6973 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -39,6 +39,10 @@ extern "C" { SCM texture_layer, SCM texture); + SCM + irr_scene_setPosition (SCM wrapped_scene_node, + SCM position); + } #endif