]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
Some doc
[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 #include "wrapped.h"
28
29 using namespace irr;
30
31 SCM
32 IGUISkin_getColor (SCM gui_skin,
33                    SCM color)
34 {
35   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_irr_pointer (gui_skin);
36   video::SColor scolor = skin->getColor (scm_to_default_color (color));
37   return scm_from_color (scolor);
38 }
39
40 SCM
41 IGUISkin_getFont (SCM gui_skin,
42                   SCM which)
43 {
44   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_irr_pointer (gui_skin);
45   gui::IGUIFont* font = skin->getFont (scm_to_default_font (which));
46   return scm_from_irr_pointer ("<gui-font>", (void*) font);
47 }
48
49 SCM
50 IGUISkin_setColor (SCM gui_skin,
51                    SCM which,
52                    SCM new_color)
53 {
54   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_irr_pointer (gui_skin);
55   skin->setColor (scm_to_default_color (which),
56                   scm_to_color (new_color));
57   return SCM_UNSPECIFIED;
58 }
59
60 SCM
61 IGUISkin_setFont (SCM gui_skin,
62                   SCM font,
63                   SCM which)
64 {
65   gui::IGUISkin* skin = (gui::IGUISkin*) scm_to_irr_pointer (gui_skin);
66   skin->setFont ((gui::IGUIFont*) scm_to_irr_pointer (font),
67                  scm_to_default_font (which));
68   return SCM_UNSPECIFIED;
69 }
70
71 void
72 init_gui_skin (void)
73 {
74   DEFINE_GSUBR ("IGUISkin_getColor", 2, 0, 0, IGUISkin_getColor);
75   DEFINE_GSUBR ("IGUISkin_getFont", 2, 0, 0, IGUISkin_getFont);
76   DEFINE_GSUBR ("IGUISkin_setColor", 3, 0, 0, IGUISkin_setColor);
77   DEFINE_GSUBR ("IGUISkin_setFont", 3, 0, 0, IGUISkin_setFont);
78 }
79
80 gui::EGUI_DEFAULT_COLOR
81 scm_to_default_color (SCM default_color)
82 {
83   char* color_name = scm_to_utf8_string (scm_symbol_to_string (default_color));
84   gui::EGUI_DEFAULT_COLOR color;
85
86   if (!strcmp (color_name, "3d-dark-shadow"))
87     {
88       color = gui::EGDC_3D_DARK_SHADOW;
89     }
90   else if (!strcmp (color_name, "3d-shadow"))
91     {
92       color = gui::EGDC_3D_SHADOW;
93     }
94   else if (!strcmp (color_name, "3d-face"))
95     {
96       color = gui::EGDC_3D_FACE;
97     }
98   else if (!strcmp (color_name, "3d-high-light"))
99     {
100       color = gui::EGDC_3D_HIGH_LIGHT;
101     }
102   else if (!strcmp (color_name, "3d-light"))
103     {
104       color = gui::EGDC_3D_LIGHT;
105     }
106   else if (!strcmp (color_name, "active-border"))
107     {
108       color = gui::EGDC_ACTIVE_BORDER;
109     }
110   else if (!strcmp (color_name, "active-caption"))
111     {
112       color = gui::EGDC_ACTIVE_CAPTION;
113     }
114   else if (!strcmp (color_name, "app-workspace"))
115     {
116       color = gui::EGDC_APP_WORKSPACE;
117     }
118   else if (!strcmp (color_name, "button-text"))
119     {
120       color = gui::EGDC_BUTTON_TEXT;
121     }
122   else if (!strcmp (color_name, "gray-text"))
123     {
124       color = gui::EGDC_GRAY_TEXT;
125     }
126   else if (!strcmp (color_name, "high-light"))
127     {
128       color = gui::EGDC_HIGH_LIGHT;
129     }
130   else if (!strcmp (color_name, "high-light-text"))
131     {
132       color = gui::EGDC_HIGH_LIGHT_TEXT;
133     }
134   else if (!strcmp (color_name, "inactive-border"))
135     {
136       color = gui::EGDC_INACTIVE_BORDER;
137     }
138   else if (!strcmp (color_name, "inactive-caption"))
139     {
140       color = gui::EGDC_INACTIVE_CAPTION;
141     }
142   else if (!strcmp (color_name, "tooltip"))
143     {
144       color = gui::EGDC_TOOLTIP;
145     }
146   else if (!strcmp (color_name, "tooltip-background"))
147     {
148       color = gui::EGDC_TOOLTIP_BACKGROUND;
149     }
150   else if (!strcmp (color_name, "scrollbar"))
151     {
152       color = gui::EGDC_SCROLLBAR;
153     }
154   else if (!strcmp (color_name, "window"))
155     {
156       color = gui::EGDC_WINDOW;
157     }
158   else if (!strcmp (color_name, "window-symbol"))
159     {
160       color = gui::EGDC_WINDOW_SYMBOL;
161     }
162   else if (!strcmp (color_name, "icon"))
163     {
164       color = gui::EGDC_ICON;
165     }
166   else if (!strcmp (color_name, "icon-high-light"))
167     {
168       color = gui::EGDC_ICON_HIGH_LIGHT;
169     }
170   else if (!strcmp (color_name, "gray-window-symbol"))
171     {
172       color = gui::EGDC_GRAY_WINDOW_SYMBOL;
173     }
174   else if (!strcmp (color_name, "editable"))
175     {
176       color = gui::EGDC_EDITABLE;
177     }
178   else if (!strcmp (color_name, "gray-editable"))
179     {
180       color = gui::EGDC_GRAY_EDITABLE;
181     }
182   else if (!strcmp (color_name, "focused-editable"))
183     {
184       color = gui::EGDC_FOCUSED_EDITABLE;
185     }
186   else
187     {
188       scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S",
189                  scm_list_1 (default_color), scm_list_1 (default_color));
190     }
191
192   free (color_name);
193   return color;
194 }
195
196 gui::EGUI_DEFAULT_FONT
197 scm_to_default_font (SCM default_font)
198 {
199   char* font_name = scm_to_utf8_string (scm_symbol_to_string (default_font));
200   gui::EGUI_DEFAULT_FONT font;
201
202   if (!strcmp (font_name, "default"))
203     {
204       font = gui::EGDF_DEFAULT;
205     }
206   else if (!strcmp (font_name, "button"))
207     {
208       font = gui::EGDF_BUTTON;
209     }
210   else if (!strcmp (font_name, "window"))
211     {
212       font = gui::EGDF_WINDOW;
213     }
214   else if (!strcmp (font_name, "menu"))
215     {
216       font = gui::EGDF_MENU;
217     }
218   else if (!strcmp (font_name, "tooltip"))
219     {
220       font = gui::EGDF_TOOLTIP;
221     }
222   else
223     {
224       scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
225                  scm_list_1 (default_font), scm_list_1 (default_font));
226     }
227
228   free (font_name);
229   return font;
230 }