From: Javier Sancho Date: Fri, 24 Apr 2020 07:13:46 +0000 (+0200) Subject: get-color X-Git-Url: https://git.jsancho.org/?p=guile-irrlicht.git;a=commitdiff_plain;h=61aadd8525de89016f63572fd474547a1bb932de get-color --- diff --git a/Makefile.am b/Makefile.am index 6908dc8..ca146c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ libguile_irrlicht_la_SOURCES = \ src/gui-environment.cpp \ src/gui-font.cpp \ src/gui-image.cpp \ + src/gui-in-out-fader.cpp \ src/gui-scrollbar.cpp \ src/gui-skin.cpp \ src/gui-static-text.cpp \ diff --git a/src/color.cpp b/src/color.cpp index 5ed16fe..63448b3 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -25,6 +25,15 @@ extern "C" { + SCM + scm_from_color (irr::video::SColor color) + { + return scm_list_4 (scm_from_uint32 (color.getAlpha ()), + scm_from_uint32 (color.getRed ()), + scm_from_uint32 (color.getGreen ()), + scm_from_uint32 (color.getBlue ())); + } + irr::video::SColor scm_to_color (SCM color) { diff --git a/src/color.h b/src/color.h index d85513b..3dbbfe9 100644 --- a/src/color.h +++ b/src/color.h @@ -27,6 +27,9 @@ extern "C" { + SCM + scm_from_color (irr::video::SColor color); + irr::video::SColor scm_to_color (SCM color); diff --git a/src/gui-image.h b/src/gui-image.h index 8eaf1ed..8f3d335 100644 --- a/src/gui-image.h +++ b/src/gui-image.h @@ -33,6 +33,7 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::gui::IGUIImage*, init_gui_image_type, gui_image_p, wrap_gui_image, unwrap_gui_image); + } #endif diff --git a/src/gui-in-out-fader.cpp b/src/gui-in-out-fader.cpp new file mode 100644 index 0000000..35dafe6 --- /dev/null +++ b/src/gui-in-out-fader.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-in-out-fader.h" +#include "wrapped.h" + +extern "C" { + + void + init_gui_in_out_fader (void) + { + init_gui_in_out_fader_type (); + } + + DEFINE_WRAPPED_TYPE (irr::gui::IGUIInOutFader*, "gui-in-out-fader", + init_gui_in_out_fader_type, gui_in_out_fader_p, + wrap_gui_in_out_fader, unwrap_gui_in_out_fader); + +} diff --git a/src/gui-in-out-fader.h b/src/gui-in-out-fader.h new file mode 100644 index 0000000..a6762ff --- /dev/null +++ b/src/gui-in-out-fader.h @@ -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 + . +*/ + +#ifndef __GUILE_IRRLICHT_GUI_IN_OUT_FADER_H_INCLUDED__ +#define __GUILE_IRRLICHT_GUI_IN_OUT_FADER_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_gui_in_out_fader (void); + + DECLARE_WRAPPED_TYPE (irr::gui::IGUIInOutFader*, init_gui_in_out_fader_type, + gui_in_out_fader_p, wrap_gui_in_out_fader, unwrap_gui_in_out_fader); + +} + +#endif diff --git a/src/gui-skin.cpp b/src/gui-skin.cpp index 5bbfc66..a5bfe26 100644 --- a/src/gui-skin.cpp +++ b/src/gui-skin.cpp @@ -22,6 +22,7 @@ #include #include +#include "color.h" #include "gsubr.h" #include "gui-font.h" #include "gui-skin.h" @@ -33,7 +34,6 @@ extern "C" { init_gui_skin (void) { init_gui_skin_type (); - DEFINE_GSUBR ("get-skin-font", 1, 0, 1, irr_gui_getSkinFont); DEFINE_GSUBR ("set-font!", 2, 0, 1, irr_gui_setFont); } @@ -42,18 +42,12 @@ extern "C" { wrap_gui_skin, unwrap_gui_skin); SCM - irr_gui_getSkinFont (SCM wrapped_gui_skin, - SCM rest) + irr_gui_IGUISkin_getColor (SCM wrapped_gui_skin, + SCM color) { - 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::video::SColor scolor = skin->getColor (scm_to_default_color (color)); + return scm_from_color (scolor); } SCM @@ -88,6 +82,117 @@ extern "C" { return SCM_UNSPECIFIED; } + irr::gui::EGUI_DEFAULT_COLOR + scm_to_default_color (SCM default_color) + { + char* color = scm_to_utf8_stringn (scm_symbol_to_string (default_color), NULL); + if (!strcmp (color, "3d-dark-shadow")) + { + return irr::gui::EGDC_3D_DARK_SHADOW; + } + else if (!strcmp (color, "3d-shadow")) + { + return irr::gui::EGDC_3D_SHADOW; + } + else if (!strcmp (color, "3d-face")) + { + return irr::gui::EGDC_3D_FACE; + } + else if (!strcmp (color, "3d-high-light")) + { + return irr::gui::EGDC_3D_HIGH_LIGHT; + } + else if (!strcmp (color, "3d-light")) + { + return irr::gui::EGDC_3D_LIGHT; + } + else if (!strcmp (color, "active-border")) + { + return irr::gui::EGDC_ACTIVE_BORDER; + } + else if (!strcmp (color, "active-caption")) + { + return irr::gui::EGDC_ACTIVE_CAPTION; + } + else if (!strcmp (color, "app-workspace")) + { + return irr::gui::EGDC_APP_WORKSPACE; + } + else if (!strcmp (color, "button-text")) + { + return irr::gui::EGDC_BUTTON_TEXT; + } + else if (!strcmp (color, "gray-text")) + { + return irr::gui::EGDC_GRAY_TEXT; + } + else if (!strcmp (color, "high-light")) + { + return irr::gui::EGDC_HIGH_LIGHT; + } + else if (!strcmp (color, "high-light-text")) + { + return irr::gui::EGDC_HIGH_LIGHT_TEXT; + } + else if (!strcmp (color, "inactive-border")) + { + return irr::gui::EGDC_INACTIVE_BORDER; + } + else if (!strcmp (color, "inactive-caption")) + { + return irr::gui::EGDC_INACTIVE_CAPTION; + } + else if (!strcmp (color, "tooltip")) + { + return irr::gui::EGDC_TOOLTIP; + } + else if (!strcmp (color, "tooltip-background")) + { + return irr::gui::EGDC_TOOLTIP_BACKGROUND; + } + else if (!strcmp (color, "scrollbar")) + { + return irr::gui::EGDC_SCROLLBAR; + } + else if (!strcmp (color, "window")) + { + return irr::gui::EGDC_WINDOW; + } + else if (!strcmp (color, "window-symbol")) + { + return irr::gui::EGDC_WINDOW_SYMBOL; + } + else if (!strcmp (color, "icon")) + { + return irr::gui::EGDC_ICON; + } + else if (!strcmp (color, "icon-high-light")) + { + return irr::gui::EGDC_ICON_HIGH_LIGHT; + } + else if (!strcmp (color, "gray-window-symbol")) + { + return irr::gui::EGDC_GRAY_WINDOW_SYMBOL; + } + else if (!strcmp (color, "editable")) + { + return irr::gui::EGDC_EDITABLE; + } + else if (!strcmp (color, "gray-editable")) + { + return irr::gui::EGDC_GRAY_EDITABLE; + } + else if (!strcmp (color, "focused-editable")) + { + return irr::gui::EGDC_FOCUSED_EDITABLE; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S", + scm_list_1 (default_color), scm_list_1 (default_color)); + } + } + irr::gui::EGUI_DEFAULT_FONT scm_to_default_font (SCM default_font) { diff --git a/src/gui-skin.h b/src/gui-skin.h index 9d022f9..b4ec4c5 100644 --- a/src/gui-skin.h +++ b/src/gui-skin.h @@ -35,8 +35,8 @@ extern "C" { gui_skin_p, wrap_gui_skin, unwrap_gui_skin); SCM - irr_gui_getSkinFont (SCM wrapped_gui_skin, - SCM rest); + irr_gui_IGUISkin_getColor (SCM wrapped_gui_skin, + SCM color); SCM irr_gui_IGUISkin_getFont (SCM wrapped_gui_skin, @@ -47,6 +47,9 @@ extern "C" { SCM font, SCM rest); + irr::gui::EGUI_DEFAULT_COLOR + scm_to_default_color (SCM default_color); + irr::gui::EGUI_DEFAULT_FONT scm_to_default_font (SCM default_font); diff --git a/src/gui.cpp b/src/gui.cpp index 532a786..6068f3a 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -31,6 +31,7 @@ #include "gui-environment.h" #include "gui-font.h" #include "gui-image.h" +#include "gui-in-out-fader.h" #include "gui-scrollbar.h" #include "gui-skin.h" #include "gui-static-text.h" @@ -48,6 +49,7 @@ extern "C" { init_gui_environment (); init_gui_font (); init_gui_image (); + init_gui_in_out_fader (); init_gui_scrollbar (); init_gui_skin (); init_gui_static_text (); @@ -55,6 +57,7 @@ extern "C" { // Shared procedures (used by two or more objects) DEFINE_GSUBR ("add-button!", 1, 1, 1, irr_gui_addButton); + DEFINE_GSUBR ("get-color", 1, 1, 0, irr_gui_getColor); DEFINE_GSUBR ("get-font", 1, 1, 1, irr_gui_getFont); DEFINE_GSUBR ("set-max!", 2, 0, 0, irr_gui_setMax); DEFINE_GSUBR ("set-override-color!", 2, 0, 0, irr_gui_setOverrideColor); @@ -80,6 +83,31 @@ extern "C" { } } + SCM + irr_gui_getColor (SCM wrapped_obj, + SCM color) + { +#define GET_COLOR(OBJ) scm_from_color (OBJ->getColor ()); + + if (gui_image_p (wrapped_obj)) + { + return GET_COLOR (unwrap_gui_image (wrapped_obj)); + } + else if (gui_in_out_fader_p (wrapped_obj)) + { + return GET_COLOR (unwrap_gui_in_out_fader (wrapped_obj)); + } + else if (gui_skin_p (wrapped_obj)) + { + return irr_gui_IGUISkin_getColor (wrapped_obj, color); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get color from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + SCM irr_gui_getFont (SCM wrapped_obj, SCM filename, diff --git a/src/gui.h b/src/gui.h index 29c3ee6..d7ccd7d 100644 --- a/src/gui.h +++ b/src/gui.h @@ -35,6 +35,10 @@ extern "C" { SCM rectangle, SCM rest); + SCM + irr_gui_getColor (SCM wrapped_obj, + SCM color); + SCM irr_gui_getFont (SCM wrapped_obj, SCM filename,