From da89e12dbf35ce6452e6a6e2eeb3f83eaeb94c97 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 22 Apr 2020 08:40:23 +0200 Subject: [PATCH] add-button! --- Makefile.am | 2 ++ src/gui-button.cpp | 40 +++++++++++++++++++++ src/gui-button.h | 38 ++++++++++++++++++++ src/gui-environment.cpp | 28 +++++++++++++++ src/gui-environment.h | 7 +++- src/gui-toolbar.cpp | 77 +++++++++++++++++++++++++++++++++++++++++ src/gui-toolbar.h | 43 +++++++++++++++++++++++ src/gui.cpp | 25 +++++++++++++ src/gui.h | 5 +++ 9 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 src/gui-button.cpp create mode 100644 src/gui-button.h create mode 100644 src/gui-toolbar.cpp create mode 100644 src/gui-toolbar.h diff --git a/Makefile.am b/Makefile.am index 48c67f1..3a1e9f4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,6 +37,7 @@ libguile_irrlicht_la_SOURCES = \ src/file-archive.cpp \ src/file-system.cpp \ src/gui.cpp \ + src/gui-button.cpp \ src/gui-edit-box.cpp \ src/gui-element.cpp \ src/gui-environment.cpp \ @@ -44,6 +45,7 @@ libguile_irrlicht_la_SOURCES = \ src/gui-image.cpp \ src/gui-skin.cpp \ src/gui-static-text.cpp \ + src/gui-toolbar.cpp \ src/guile-irrlicht.cpp \ src/keycodes.cpp \ src/keymap.cpp \ diff --git a/src/gui-button.cpp b/src/gui-button.cpp new file mode 100644 index 0000000..e8ff726 --- /dev/null +++ b/src/gui-button.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-button.h" +#include "wrapped.h" + +extern "C" { + + void + init_gui_button (void) + { + init_gui_button_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIButton*, "gui-button", + init_gui_button_type, gui_button_p, + wrap_gui_button, unwrap_gui_button); + +} diff --git a/src/gui-button.h b/src/gui-button.h new file mode 100644 index 0000000..95e442e --- /dev/null +++ b/src/gui-button.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_BUTTON_H_INCLUDED__ +#define __GUILE_IRRLICHT_GUI_BUTTON_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_gui_button (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIButton*, init_gui_button_type, + gui_button_p, wrap_gui_button, unwrap_gui_button); +} + +#endif diff --git a/src/gui-environment.cpp b/src/gui-environment.cpp index 6244147..0e12e72 100644 --- a/src/gui-environment.cpp +++ b/src/gui-environment.cpp @@ -24,6 +24,7 @@ #include "device.h" #include "gsubr.h" +#include "gui-button.h" #include "gui-element.h" #include "gui-environment.h" #include "gui-font.h" @@ -156,4 +157,31 @@ extern "C" { return wrap_gui_skin (skin); } + SCM + irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment, + SCM rectangle, + SCM rest) + { + SCM parent = SCM_BOOL_F; + SCM id = scm_from_int32 (-1); + SCM text = SCM_BOOL_F; + SCM tooltiptext = SCM_BOOL_F; + + scm_c_bind_keyword_arguments ("add-button!", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("parent"), &parent, + scm_from_utf8_keyword ("id"), &id, + scm_from_utf8_keyword ("text"), &text, + scm_from_utf8_keyword ("tooltiptext"), &tooltiptext, + SCM_UNDEFINED); + + irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment); + irr::gui::IGUIButton* button = + guienv->addButton (scm_to_rect_s32 (rectangle), + scm_is_false (parent) ? 0 : unwrap_gui_element (parent), + scm_to_int32 (id), + scm_is_false (text) ? 0 : scm_to_wide_char_string (text), + scm_is_false (tooltiptext) ? 0 : scm_to_wide_char_string (tooltiptext)); + return wrap_gui_button (button); + } + } diff --git a/src/gui-environment.h b/src/gui-environment.h index b03aac4..e99e133 100644 --- a/src/gui-environment.h +++ b/src/gui-environment.h @@ -59,6 +59,11 @@ extern "C" { SCM irr_gui_getSkin (SCM wrapped_gui_environment); -} + SCM + irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment, + SCM rectangle, + SCM rest); + + } #endif diff --git a/src/gui-toolbar.cpp b/src/gui-toolbar.cpp new file mode 100644 index 0000000..cc571e8 --- /dev/null +++ b/src/gui-toolbar.cpp @@ -0,0 +1,77 @@ +/* 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-button.h" +#include "gui-toolbar.h" +#include "texture.h" +#include "wchar.h" +#include "wrapped.h" + +extern "C" { + + void + init_gui_toolbar (void) + { + init_gui_toolbar_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIToolBar*, "gui-toolbar", + init_gui_toolbar_type, gui_toolbar_p, + wrap_gui_toolbar, unwrap_gui_toolbar); + + SCM + irr_gui_IGUIToolBar_addButton (SCM wrapped_gui_toolbar, + SCM rest) + { + SCM id = scm_from_int32 (-1); + SCM text = SCM_BOOL_F; + SCM tooltiptext = SCM_BOOL_F; + SCM img = SCM_BOOL_F; + SCM pressedimg = SCM_BOOL_F; + SCM is_push_button = SCM_BOOL_F; + SCM use_alpha_channel = SCM_BOOL_F; + + scm_c_bind_keyword_arguments ("add-button!", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("id"), &id, + scm_from_utf8_keyword ("text"), &text, + scm_from_utf8_keyword ("tooltiptext"), &tooltiptext, + scm_from_utf8_keyword ("img"), &img, + scm_from_utf8_keyword ("pressedimg"), &pressedimg, + scm_from_utf8_keyword ("is_push_button"), &is_push_button, + scm_from_utf8_keyword ("use_alpha_channel"), &use_alpha_channel, + SCM_UNDEFINED); + + irr::gui::IGUIToolBar* toolbar = unwrap_gui_toolbar (wrapped_gui_toolbar); + irr::gui::IGUIButton* button = + toolbar->addButton (scm_to_int32 (id), + scm_is_false (text) ? 0 : scm_to_wide_char_string (text), + scm_is_false (tooltiptext) ? 0 : scm_to_wide_char_string (tooltiptext), + scm_is_false (img) ? 0 : unwrap_texture (img), + scm_is_false (pressedimg) ? 0 : unwrap_texture (pressedimg), + scm_to_bool (is_push_button), + scm_to_bool (use_alpha_channel)); + return wrap_gui_button (button); + } + +} diff --git a/src/gui-toolbar.h b/src/gui-toolbar.h new file mode 100644 index 0000000..4d09b6c --- /dev/null +++ b/src/gui-toolbar.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_GUI_TOOLBAR_H_INCLUDED__ +#define __GUILE_IRRLICHT_GUI_TOOLBAR_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_gui_toolbar (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIToolBar*, init_gui_toolbar_type, + gui_toolbar_p, wrap_gui_toolbar, unwrap_gui_toolbar); + + SCM + irr_gui_IGUIToolBar_addButton (SCM wrapped_gui_toolbar, + SCM rest); + +} + +#endif diff --git a/src/gui.cpp b/src/gui.cpp index 313a83b..2f7044b 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -25,6 +25,7 @@ #include "color.h" #include "gsubr.h" #include "gui.h" +#include "gui-button.h" #include "gui-edit-box.h" #include "gui-element.h" #include "gui-environment.h" @@ -32,6 +33,7 @@ #include "gui-image.h" #include "gui-skin.h" #include "gui-static-text.h" +#include "gui-toolbar.h" extern "C" { @@ -39,6 +41,7 @@ extern "C" { init_gui (void) { // Init objects + init_gui_button (); init_gui_edit_box (); init_gui_element (); init_gui_environment (); @@ -46,11 +49,33 @@ extern "C" { init_gui_image (); init_gui_skin (); init_gui_static_text (); + init_gui_toolbar (); // Shared procedures (used by two or more objects) + DEFINE_GSUBR ("add-button!", 1, 1, 1, irr_gui_addButton); DEFINE_GSUBR ("set-override-color!", 2, 0, 0, irr_gui_setOverrideColor); } + SCM + irr_gui_addButton (SCM wrapped_obj, + SCM rectangle, + SCM rest) + { + if (gui_toolbar_p (wrapped_obj)) + { + return irr_gui_IGUIToolBar_addButton (wrapped_obj, rest); + } + else if (gui_environment_p (wrapped_obj)) + { + return irr_gui_IGUIEnvironment_addButton (wrapped_obj, rectangle, rest); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot add button to 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 aac54a5..6cab006 100644 --- a/src/gui.h +++ b/src/gui.h @@ -30,6 +30,11 @@ extern "C" { void init_gui (void); + SCM + irr_gui_addButton (SCM wrapped_obj, + SCM rectangle, + SCM rest); + SCM irr_gui_setOverrideColor (SCM wrapped_obj, SCM color); -- 2.39.2