From: Javier Sancho Date: Fri, 6 Mar 2020 16:11:58 +0000 (+0100) Subject: add-static-text! X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=56de371557044d3b7acc14cb94cc46641be906d9;p=guile-irrlicht.git add-static-text! --- diff --git a/Makefile.am b/Makefile.am index 88b5268..485bc37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,10 +4,14 @@ libguile_irrlicht_la_SOURCES = \ src/dimension2d.cpp \ src/EDriverTypes.cpp \ src/GuileIrrlicht.cpp \ + src/IGUIElement.cpp \ src/IGUIEnvironment.cpp \ + src/IGUIStaticText.cpp \ src/IrrlichtDevice.cpp \ src/ISceneManager.cpp \ - src/IVideoDriver.cpp + src/IVideoDriver.cpp \ + src/rect.cpp \ + src/util.cpp libguile_irrlicht_la_CPPFLAGS = @GUILE_CFLAGS@ libguile_irrlicht_la_LDFLAGS = \ -version-info 0:1 \ diff --git a/irrlicht.scm b/irrlicht.scm index 97bad7e..6c4025f 100644 --- a/irrlicht.scm +++ b/irrlicht.scm @@ -23,7 +23,8 @@ (eval-when (eval load compile) ;; load public symbols into current module (let ((public-modules - '((irrlicht device))) + '((irrlicht device) + (irrlicht gui))) (current-interface (module-public-interface (current-module)))) (for-each diff --git a/irrlicht/device.scm b/irrlicht/device.scm index f5f8b61..e07a812 100644 --- a/irrlicht/device.scm +++ b/irrlicht/device.scm @@ -27,7 +27,7 @@ (load-extension "libguile-irrlicht" "init_guile_irrlicht") -(define irrlicht-create-device create-device) +(define irr-create-device create-device) (define* (create-device #:key (device-type 'software) (window-size '(640 480)) @@ -36,10 +36,10 @@ (stencilbuffer #f) (vsync #f) (receiver 0)) - (irrlicht-create-device device-type - window-size - bits - fullscreen - stencilbuffer - vsync - receiver)) + (irr-create-device device-type + window-size + bits + fullscreen + stencilbuffer + vsync + receiver)) diff --git a/irrlicht/gui.scm b/irrlicht/gui.scm new file mode 100644 index 0000000..2299574 --- /dev/null +++ b/irrlicht/gui.scm @@ -0,0 +1,41 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 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 +;;; . + + +(define-module (irrlicht gui) + #:export (add-static-text!)) + +(load-extension "libguile-irrlicht" "init_guile_irrlicht") + +(define irr-add-static-text! add-static-text!) +(define* (add-static-text! guienv text rectangle + #:key + (border #f) + (word-wrap #t) + (parent #f) + (id -1) + (fill-background #f)) + (irr-add-static-text! guienv + text + rectangle + border + word-wrap + parent + id + fill-background)) diff --git a/src/GuileIrrlicht.cpp b/src/GuileIrrlicht.cpp index 5f8691c..32fd4ac 100644 --- a/src/GuileIrrlicht.cpp +++ b/src/GuileIrrlicht.cpp @@ -20,7 +20,9 @@ */ #include +#include "IGUIElement.h" #include "IGUIEnvironment.h" +#include "IGUIStaticText.h" #include "IrrlichtDevice.h" #include "ISceneManager.h" #include "IVideoDriver.h" @@ -31,7 +33,9 @@ extern "C" { init_guile_irrlicht (void) { init_device (); + init_gui_element (); init_gui_environment (); + init_gui_static_text (); init_scene_manager (); init_video_driver (); } diff --git a/src/IGUIElement.cpp b/src/IGUIElement.cpp new file mode 100644 index 0000000..80d7676 --- /dev/null +++ b/src/IGUIElement.cpp @@ -0,0 +1,39 @@ +/* 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 "IGUIElement.h" +#include "util.h" + +extern "C" { + + void + init_gui_element (void) + { + init_gui_element_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIElement*, "gui-element", + init_gui_element_type, + wrap_gui_element, unwrap_gui_element); + +} diff --git a/src/IGUIElement.h b/src/IGUIElement.h new file mode 100644 index 0000000..659dcbc --- /dev/null +++ b/src/IGUIElement.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_I_GUI_ELEMENT_INCLUDED__ +#define __GUILE_I_GUI_ELEMENT_INCLUDED__ + +#include +#include +#include "util.h" + +extern "C" { + + void + init_gui_element (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIElement*, init_gui_element_type, + wrap_gui_element, unwrap_gui_element); +} + +#endif diff --git a/src/IGUIEnvironment.cpp b/src/IGUIEnvironment.cpp index c0a2a06..de4f9f6 100644 --- a/src/IGUIEnvironment.cpp +++ b/src/IGUIEnvironment.cpp @@ -21,7 +21,10 @@ #include #include +#include "IGUIElement.h" #include "IGUIEnvironment.h" +#include "IGUIStaticText.h" +#include "rect.h" #include "util.h" extern "C" { @@ -30,10 +33,33 @@ extern "C" { init_gui_environment (void) { init_gui_environment_type (); + scm_c_define_gsubr ("add-static-text!", 8, 0, 0, (scm_t_subr)irr_gui_addStaticText); } DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment", init_gui_environment_type, wrap_gui_environment, unwrap_gui_environment); + SCM + irr_gui_addStaticText (SCM wrappedGUIEnvironment, + SCM text, + SCM rectangle, + SCM border, + SCM wordWrap, + SCM parent, + SCM id, + SCM fillBackground) + { + irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrappedGUIEnvironment); + irr::gui::IGUIStaticText* staticText = + guienv->addStaticText (scm_to_wide_char_string (text), + scm_to_rect_s32 (rectangle), + scm_to_bool (border), + scm_to_bool (wordWrap), + scm_is_false (parent) ? 0 : unwrap_gui_element (parent), + scm_to_int32 (id), + scm_to_bool (fillBackground)); + return wrap_gui_static_text (staticText); + } + } diff --git a/src/IGUIEnvironment.h b/src/IGUIEnvironment.h index 2ce45e5..6e28bfe 100644 --- a/src/IGUIEnvironment.h +++ b/src/IGUIEnvironment.h @@ -33,6 +33,17 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, init_gui_environment_type, wrap_gui_environment, unwrap_gui_environment); + + SCM + irr_gui_addStaticText (SCM guienv, + SCM text, + SCM rectangle, + SCM border, + SCM wordWrap, + SCM parent, + SCM id, + SCM fillBackground); + } #endif diff --git a/src/IGUIStaticText.cpp b/src/IGUIStaticText.cpp new file mode 100644 index 0000000..4a66db5 --- /dev/null +++ b/src/IGUIStaticText.cpp @@ -0,0 +1,39 @@ +/* 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 "IGUIStaticText.h" +#include "util.h" + +extern "C" { + + void + init_gui_static_text (void) + { + init_gui_static_text_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIStaticText*, "gui-static-text", + init_gui_static_text_type, + wrap_gui_static_text, unwrap_gui_static_text); + +} diff --git a/src/IGUIStaticText.h b/src/IGUIStaticText.h new file mode 100644 index 0000000..39e2fbd --- /dev/null +++ b/src/IGUIStaticText.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_I_GUI_STATIC_TEXT_INCLUDED__ +#define __GUILE_I_GUI_STATIC_TEXT_INCLUDED__ + +#include +#include +#include "util.h" + +extern "C" { + + void + init_gui_static_text (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIStaticText*, init_gui_static_text_type, + wrap_gui_static_text, unwrap_gui_static_text); +} + +#endif diff --git a/src/IrrlichtDevice.cpp b/src/IrrlichtDevice.cpp index 026df21..82b729d 100644 --- a/src/IrrlichtDevice.cpp +++ b/src/IrrlichtDevice.cpp @@ -21,7 +21,6 @@ #include #include -#include #include "dimension2d.h" #include "EDriverTypes.h" @@ -95,14 +94,7 @@ extern "C" { SCM text) { irr::IrrlichtDevice* device = unwrap_device (device_obj); - char* ctext; - wchar_t* wtext; - - ctext = scm_to_utf8_stringn (text, NULL); - wtext = (wchar_t*)malloc ((strlen (ctext) + 1) * sizeof (wchar_t)); - mbstowcs (wtext, ctext, strlen (ctext) + 1); - - device->setWindowCaption (wtext); + device->setWindowCaption (scm_to_wide_char_string (text)); return SCM_UNSPECIFIED; } diff --git a/src/rect.cpp b/src/rect.cpp new file mode 100644 index 0000000..9da526b --- /dev/null +++ b/src/rect.cpp @@ -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 + . +*/ + +#include +#include +#include "rect.h" + +extern "C" { + + irr::core::rect + scm_to_rect_s32 (SCM rect) + { + return irr::core::rect + (scm_to_int32 (scm_car (rect)), + scm_to_int32 (scm_cadr (rect)), + scm_to_int32 (scm_caddr (rect)), + scm_to_int32 (scm_cadddr (rect))); + } + +} diff --git a/src/rect.h b/src/rect.h new file mode 100644 index 0000000..bad7aae --- /dev/null +++ b/src/rect.h @@ -0,0 +1,35 @@ +/* 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_RECT_INCLUDED__ +#define __GUILE_IRRLICHT_RECT_INCLUDED__ + +#include +#include + +extern "C" { + + irr::core::rect + scm_to_rect_s32 (SCM rect); + +} + +#endif diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..eb5b8a8 --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,33 @@ +/* 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 "util.h" + +wchar_t* +scm_to_wide_char_string (SCM text) +{ + char* ctext = scm_to_utf8_stringn (text, NULL); + wchar_t* wtext = (wchar_t*)malloc ((strlen (ctext) + 1) * sizeof (wchar_t)); + mbstowcs (wtext, ctext, strlen (ctext) + 1); + return wtext; +} diff --git a/src/util.h b/src/util.h index 6397b37..3ce84a4 100644 --- a/src/util.h +++ b/src/util.h @@ -19,6 +19,8 @@ . */ +#include +#include #define DECLARE_WRAPPED_TYPE(TYPE, INIT, WRAP, UNWRAP) \ void \ @@ -60,3 +62,6 @@ scm_assert_foreign_object_type (wrapped_type, wrapped_obj); \ return (TYPE)scm_foreign_object_ref (wrapped_obj, 0); \ } + +wchar_t* +scm_to_wide_char_string (SCM text);