From 15be0323f62a228707f616c25c4b87cd1d68766f Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 22 Apr 2020 09:09:02 +0200 Subject: [PATCH] get-font set-font! --- src/gui-environment.cpp | 19 +++++++++---------- src/gui-environment.h | 8 ++++---- src/gui-skin.cpp | 25 ++++++++++++++++++++----- src/gui-skin.h | 10 +++++++--- src/gui.cpp | 21 +++++++++++++++++++++ src/gui.h | 5 +++++ 6 files changed, 66 insertions(+), 22 deletions(-) diff --git a/src/gui-environment.cpp b/src/gui-environment.cpp index 0e12e72..1ea8625 100644 --- a/src/gui-environment.cpp +++ b/src/gui-environment.cpp @@ -46,7 +46,6 @@ extern "C" { DEFINE_GSUBR ("add-image!", 3, 0, 1, irr_gui_addImage); DEFINE_GSUBR ("add-static-text!", 3, 0, 1, irr_gui_addStaticText); DEFINE_GSUBR ("get-built-in-font", 1, 0, 0, irr_gui_getBuiltInFont); - 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); } @@ -140,15 +139,6 @@ extern "C" { return wrap_gui_font (font); } - 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) { @@ -184,4 +174,13 @@ extern "C" { return wrap_gui_button (button); } + SCM + irr_gui_IGUIEnvironment_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); + } + } diff --git a/src/gui-environment.h b/src/gui-environment.h index e99e133..79853fa 100644 --- a/src/gui-environment.h +++ b/src/gui-environment.h @@ -52,10 +52,6 @@ extern "C" { SCM irr_gui_getBuiltInFont (SCM wrapped_gui_environment); - SCM - irr_gui_getFont (SCM wrapped_gui_environment, - SCM filename); - SCM irr_gui_getSkin (SCM wrapped_gui_environment); @@ -64,6 +60,10 @@ extern "C" { SCM rectangle, SCM rest); + SCM + irr_gui_IGUIEnvironment_getFont (SCM wrapped_gui_environment, + SCM filename); + } #endif diff --git a/src/gui-skin.cpp b/src/gui-skin.cpp index 4d1f0ec..5bbfc66 100644 --- a/src/gui-skin.cpp +++ b/src/gui-skin.cpp @@ -34,7 +34,7 @@ extern "C" { { init_gui_skin_type (); DEFINE_GSUBR ("get-skin-font", 1, 0, 1, irr_gui_getSkinFont); - DEFINE_GSUBR ("set-skin-font!", 2, 0, 1, irr_gui_setSkinFont); + DEFINE_GSUBR ("set-font!", 2, 0, 1, irr_gui_setFont); } DEFINE_WRAPPED_TYPE (irr::gui::IGUISkin*, "gui-skin", @@ -57,13 +57,28 @@ extern "C" { } SCM - irr_gui_setSkinFont (SCM wrapped_gui_skin, - SCM font, - SCM rest) + irr_gui_IGUISkin_getFont (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_c_bind_keyword_arguments ("get-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); + } + + SCM + irr_gui_setFont (SCM wrapped_gui_skin, + SCM font, + SCM rest) + { + SCM which = scm_from_utf8_symbol ("default"); + + scm_c_bind_keyword_arguments ("set-font!", rest, (scm_t_keyword_arguments_flags)0, scm_from_utf8_keyword ("which"), &which, SCM_UNDEFINED); diff --git a/src/gui-skin.h b/src/gui-skin.h index 529eb0c..9d022f9 100644 --- a/src/gui-skin.h +++ b/src/gui-skin.h @@ -39,9 +39,13 @@ extern "C" { SCM rest); SCM - irr_gui_setSkinFont (SCM wrapped_gui_skin, - SCM font, - SCM rest); + irr_gui_IGUISkin_getFont (SCM wrapped_gui_skin, + SCM rest); + + SCM + irr_gui_setFont (SCM wrapped_gui_skin, + SCM font, + SCM rest); irr::gui::EGUI_DEFAULT_FONT scm_to_default_font (SCM default_font); diff --git a/src/gui.cpp b/src/gui.cpp index 2f7044b..bcc1cef 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -53,6 +53,7 @@ extern "C" { // Shared procedures (used by two or more objects) DEFINE_GSUBR ("add-button!", 1, 1, 1, irr_gui_addButton); + DEFINE_GSUBR ("get-font", 1, 1, 1, irr_gui_getFont); DEFINE_GSUBR ("set-override-color!", 2, 0, 0, irr_gui_setOverrideColor); } @@ -76,6 +77,26 @@ extern "C" { } } + SCM + irr_gui_getFont (SCM wrapped_obj, + SCM filename, + SCM rest) + { + if (gui_environment_p (wrapped_obj)) + { + return irr_gui_IGUIEnvironment_getFont (wrapped_obj, filename); + } + else if (gui_skin_p (wrapped_obj)) + { + return irr_gui_IGUISkin_getFont (wrapped_obj, rest); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get font from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + SCM irr_gui_setOverrideColor (SCM wrapped_obj, SCM color) diff --git a/src/gui.h b/src/gui.h index 6cab006..f86abb3 100644 --- a/src/gui.h +++ b/src/gui.h @@ -35,6 +35,11 @@ extern "C" { SCM rectangle, SCM rest); + SCM + irr_gui_getFont (SCM wrapped_obj, + SCM filename, + SCM rest); + SCM irr_gui_setOverrideColor (SCM wrapped_obj, SCM color); -- 2.39.5