From 55e6476fba279b10b7732170a72b31426f973ef5 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 20 Apr 2020 08:37:45 +0200 Subject: [PATCH] get-font get-skin-font --- Makefile.am | 1 + src/gui-environment.cpp | 11 ++++++++++ src/gui-environment.h | 4 ++++ src/gui-font.cpp | 40 ++++++++++++++++++++++++++++++++++ src/gui-font.h | 38 ++++++++++++++++++++++++++++++++ src/gui-skin.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ src/gui-skin.h | 8 +++++++ src/gui.cpp | 15 +++++++++++++ src/guile-irrlicht.cpp | 10 --------- 9 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 src/gui-font.cpp create mode 100644 src/gui-font.h diff --git a/Makefile.am b/Makefile.am index 498cc78..48c67f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ libguile_irrlicht_la_SOURCES = \ src/gui-edit-box.cpp \ src/gui-element.cpp \ src/gui-environment.cpp \ + src/gui-font.cpp \ src/gui-image.cpp \ src/gui-skin.cpp \ src/gui-static-text.cpp \ diff --git a/src/gui-environment.cpp b/src/gui-environment.cpp index 6a46191..692075f 100644 --- a/src/gui-environment.cpp +++ b/src/gui-environment.cpp @@ -26,6 +26,7 @@ #include "gsubr.h" #include "gui-element.h" #include "gui-environment.h" +#include "gui-font.h" #include "gui-image.h" #include "gui-skin.h" #include "gui-static-text.h" @@ -43,6 +44,7 @@ extern "C" { init_gui_environment_type (); DEFINE_GSUBR ("add-image!", 3, 0, 1, irr_gui_addImage); DEFINE_GSUBR ("add-static-text!", 3, 0, 1, irr_gui_addStaticText); + DEFINE_GSUBR ("get-font", 2, 0, 0, irr_gui_getFont); DEFINE_GSUBR ("get-gui-environment", 1, 0, 0, irr_getGUIEnvironment); DEFINE_GSUBR ("get-skin", 1, 0, 0, irr_gui_getSkin); } @@ -128,6 +130,15 @@ extern "C" { return wrap_gui_static_text (staticText); } + SCM + irr_gui_getFont (SCM wrapped_gui_environment, + SCM filename) + { + irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment); + irr::gui::IGUIFont* font = guienv->getFont (scm_to_utf8_stringn (filename, NULL)); + return wrap_gui_font (font); + } + SCM irr_gui_getSkin (SCM wrapped_gui_environment) { diff --git a/src/gui-environment.h b/src/gui-environment.h index c1e80d8..1cc5cc6 100644 --- a/src/gui-environment.h +++ b/src/gui-environment.h @@ -49,6 +49,10 @@ extern "C" { SCM rectangle, SCM rest); + SCM + irr_gui_getFont (SCM wrapped_gui_environment, + SCM filename); + SCM irr_gui_getSkin (SCM wrapped_gui_environment); diff --git a/src/gui-font.cpp b/src/gui-font.cpp new file mode 100644 index 0000000..a3a844f --- /dev/null +++ b/src/gui-font.cpp @@ -0,0 +1,40 @@ +/* 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 "gui-font.h" +#include "wrapped.h" + +extern "C" { + + void + init_gui_font (void) + { + init_gui_font_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIFont*, "gui-font", + init_gui_font_type, gui_font_p, + wrap_gui_font, unwrap_gui_font); + +} diff --git a/src/gui-font.h b/src/gui-font.h new file mode 100644 index 0000000..7f1f5c9 --- /dev/null +++ b/src/gui-font.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_GUI_FONT_H_INCLUDED__ +#define __GUILE_IRRLICHT_GUI_FONT_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_gui_font (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIFont*, init_gui_font_type, + gui_font_p, wrap_gui_font, unwrap_gui_font); +} + +#endif diff --git a/src/gui-skin.cpp b/src/gui-skin.cpp index 6dc6139..cfc9edb 100644 --- a/src/gui-skin.cpp +++ b/src/gui-skin.cpp @@ -22,6 +22,8 @@ #include #include +#include "gsubr.h" +#include "gui-font.h" #include "gui-skin.h" #include "wrapped.h" @@ -31,10 +33,56 @@ extern "C" { init_gui_skin (void) { init_gui_skin_type (); + DEFINE_GSUBR ("get-skin-font", 1, 0, 1, irr_gui_getSkinFont); } DEFINE_WRAPPED_TYPE (irr::gui::IGUISkin*, "gui-skin", init_gui_skin_type, gui_skin_p, wrap_gui_skin, unwrap_gui_skin); + SCM + irr_gui_getSkinFont (SCM wrapped_gui_skin, + SCM rest) + { + SCM which = scm_from_utf8_symbol ("default"); + + scm_c_bind_keyword_arguments ("get-skin-font", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("which"), &which, + SCM_UNDEFINED); + + irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin); + irr::gui::IGUIFont* font = skin->getFont (scm_to_default_font (which)); + return wrap_gui_font (font); + } + + irr::gui::EGUI_DEFAULT_FONT + scm_to_default_font (SCM default_font) + { + char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL); + if (!strcmp (font, "default")) + { + return irr::gui::EGDF_DEFAULT; + } + else if (!strcmp (font, "button")) + { + return irr::gui::EGDF_BUTTON; + } + else if (!strcmp (font, "window")) + { + return irr::gui::EGDF_WINDOW; + } + else if (!strcmp (font, "menu")) + { + return irr::gui::EGDF_MENU; + } + else if (!strcmp (font, "tooltip")) + { + return irr::gui::EGDF_TOOLTIP; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S", + scm_list_1 (default_font), scm_list_1 (default_font)); + } + } } diff --git a/src/gui-skin.h b/src/gui-skin.h index ca43d2b..5a86bb1 100644 --- a/src/gui-skin.h +++ b/src/gui-skin.h @@ -33,6 +33,14 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::gui::IGUISkin*, init_gui_skin_type, gui_skin_p, wrap_gui_skin, unwrap_gui_skin); + + SCM + irr_gui_getSkinFont (SCM wrapped_gui_skin, + SCM rest); + + irr::gui::EGUI_DEFAULT_FONT + scm_to_default_font (SCM default_font); + } #endif diff --git a/src/gui.cpp b/src/gui.cpp index bb4f9e9..313a83b 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -26,6 +26,11 @@ #include "gsubr.h" #include "gui.h" #include "gui-edit-box.h" +#include "gui-element.h" +#include "gui-environment.h" +#include "gui-font.h" +#include "gui-image.h" +#include "gui-skin.h" #include "gui-static-text.h" extern "C" { @@ -33,6 +38,16 @@ extern "C" { void init_gui (void) { + // Init objects + init_gui_edit_box (); + init_gui_element (); + init_gui_environment (); + init_gui_font (); + init_gui_image (); + init_gui_skin (); + init_gui_static_text (); + + // Shared procedures (used by two or more objects) DEFINE_GSUBR ("set-override-color!", 2, 0, 0, irr_gui_setOverrideColor); } diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index 1be3a39..bc76b72 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -32,12 +32,8 @@ #include "file-system.h" #include "gsubr.h" #include "gui.h" -#include "gui-edit-box.h" #include "gui-element.h" #include "gui-environment.h" -#include "gui-image.h" -#include "gui-skin.h" -#include "gui-static-text.h" #include "guile-irrlicht.h" #include "keymap.h" #include "material.h" @@ -69,12 +65,6 @@ extern "C" { init_file_archive (); init_file_system (); init_gui (); - init_gui_edit_box (); - init_gui_element (); - init_gui_environment (); - init_gui_image (); - init_gui_skin (); - init_gui_static_text (); init_keymap (); init_material (); init_mesh (); -- 2.39.2