]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
b6e0ae1dfcb71f3d5d7fff6a84f83c2f94b83a79
[guile-irrlicht.git] / src / gui-skin.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    guile-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht. If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <libguile.h>
24 #include "color.h"
25 #include "gsubr.h"
26 #include "gui-skin.h"
27
28
29 using namespace irr;
30
31
32 SCM
33 irr_gui_IGUISkin_getColor (SCM gui_skin,
34                            SCM color)
35 {
36   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_pointer (gui_skin);
37   video::SColor scolor = skin->getColor (scm_to_default_color (color));
38   return scm_from_color (scolor);
39 }
40
41
42 SCM
43 irr_gui_IGUISkin_getFont (SCM gui_skin,
44                           SCM which)
45 {
46   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_pointer (gui_skin);
47   gui::IGUIFont* font = skin->getFont (scm_to_default_font (which));
48   return scm_from_pointer ((void*) font, NULL);
49 }
50
51
52 SCM
53 irr_gui_IGUISkin_setColor (SCM gui_skin,
54                            SCM which,
55                            SCM new_color)
56 {
57   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_pointer (gui_skin);
58   skin->setColor (scm_to_default_color (which),
59                   scm_to_color (new_color));
60   return SCM_UNSPECIFIED;
61 }
62
63
64 SCM
65 irr_gui_IGUISkin_setFont (SCM gui_skin,
66                           SCM font,
67                           SCM which)
68 {
69   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_pointer (gui_skin);
70   skin->setFont ((gui::IGUIFont*) scm_to_pointer (font),
71                  scm_to_default_font (which));
72   return SCM_UNSPECIFIED;
73 }
74
75
76 extern "C" {
77
78   void
79   init_gui_skin (void)
80   {
81     DEFINE_GSUBR ("irr_gui_IGUISkin_getColor", 2, 0, 0, irr_gui_IGUISkin_getColor);
82     DEFINE_GSUBR ("irr_gui_IGUISkin_getFont", 2, 0, 0, irr_gui_IGUISkin_getFont);
83     DEFINE_GSUBR ("irr_gui_IGUISkin_setColor", 3, 0, 0, irr_gui_IGUISkin_setColor);
84     DEFINE_GSUBR ("irr_gui_IGUISkin_setFont", 3, 0, 0, irr_gui_IGUISkin_setFont);
85   }
86
87 }
88
89 gui::EGUI_DEFAULT_COLOR
90 scm_to_default_color (SCM default_color)
91 {
92   char* color = scm_to_utf8_stringn (scm_symbol_to_string (default_color), NULL);
93   if (!strcmp (color, "3d-dark-shadow"))
94     {
95       return gui::EGDC_3D_DARK_SHADOW;
96     }
97   else if (!strcmp (color, "3d-shadow"))
98     {
99       return gui::EGDC_3D_SHADOW;
100     }
101   else if (!strcmp (color, "3d-face"))
102     {
103       return gui::EGDC_3D_FACE;
104     }
105   else if (!strcmp (color, "3d-high-light"))
106     {
107       return gui::EGDC_3D_HIGH_LIGHT;
108     }
109   else if (!strcmp (color, "3d-light"))
110     {
111       return gui::EGDC_3D_LIGHT;
112     }
113   else if (!strcmp (color, "active-border"))
114     {
115       return gui::EGDC_ACTIVE_BORDER;
116     }
117   else if (!strcmp (color, "active-caption"))
118     {
119       return gui::EGDC_ACTIVE_CAPTION;
120     }
121   else if (!strcmp (color, "app-workspace"))
122     {
123       return gui::EGDC_APP_WORKSPACE;
124     }
125   else if (!strcmp (color, "button-text"))
126     {
127       return gui::EGDC_BUTTON_TEXT;
128     }
129   else if (!strcmp (color, "gray-text"))
130     {
131       return gui::EGDC_GRAY_TEXT;
132     }
133   else if (!strcmp (color, "high-light"))
134     {
135       return gui::EGDC_HIGH_LIGHT;
136     }
137   else if (!strcmp (color, "high-light-text"))
138     {
139       return gui::EGDC_HIGH_LIGHT_TEXT;
140     }
141   else if (!strcmp (color, "inactive-border"))
142     {
143       return gui::EGDC_INACTIVE_BORDER;
144     }
145   else if (!strcmp (color, "inactive-caption"))
146     {
147       return gui::EGDC_INACTIVE_CAPTION;
148     }
149   else if (!strcmp (color, "tooltip"))
150     {
151       return gui::EGDC_TOOLTIP;
152     }
153   else if (!strcmp (color, "tooltip-background"))
154     {
155       return gui::EGDC_TOOLTIP_BACKGROUND;
156     }
157   else if (!strcmp (color, "scrollbar"))
158     {
159       return gui::EGDC_SCROLLBAR;
160     }
161   else if (!strcmp (color, "window"))
162     {
163       return gui::EGDC_WINDOW;
164     }
165   else if (!strcmp (color, "window-symbol"))
166     {
167       return gui::EGDC_WINDOW_SYMBOL;
168     }
169   else if (!strcmp (color, "icon"))
170     {
171       return gui::EGDC_ICON;
172     }
173   else if (!strcmp (color, "icon-high-light"))
174     {
175       return gui::EGDC_ICON_HIGH_LIGHT;
176     }
177   else if (!strcmp (color, "gray-window-symbol"))
178     {
179       return gui::EGDC_GRAY_WINDOW_SYMBOL;
180     }
181   else if (!strcmp (color, "editable"))
182     {
183       return gui::EGDC_EDITABLE;
184     }
185   else if (!strcmp (color, "gray-editable"))
186     {
187       return gui::EGDC_GRAY_EDITABLE;
188     }
189   else if (!strcmp (color, "focused-editable"))
190     {
191       return gui::EGDC_FOCUSED_EDITABLE;
192     }
193   else
194     {
195       scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S",
196                  scm_list_1 (default_color), scm_list_1 (default_color));
197     }
198 }
199
200
201 gui::EGUI_DEFAULT_FONT
202 scm_to_default_font (SCM default_font)
203 {
204   char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
205   if (!strcmp (font, "default"))
206     {
207       return gui::EGDF_DEFAULT;
208     }
209   else if (!strcmp (font, "button"))
210     {
211       return gui::EGDF_BUTTON;
212     }
213   else if (!strcmp (font, "window"))
214     {
215       return gui::EGDF_WINDOW;
216     }
217   else if (!strcmp (font, "menu"))
218     {
219       return gui::EGDF_MENU;
220     }
221   else if (!strcmp (font, "tooltip"))
222     {
223       return gui::EGDF_TOOLTIP;
224     }
225   else
226     {
227       scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
228                  scm_list_1 (default_font), scm_list_1 (default_font));
229     }
230 }