]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
Unwrap Irrlicht objects in C++ instead of Guile
[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_pointer ((void*) font, NULL);
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 = scm_to_utf8_stringn (scm_symbol_to_string (default_color), NULL);
84   if (!strcmp (color, "3d-dark-shadow"))
85     {
86       return gui::EGDC_3D_DARK_SHADOW;
87     }
88   else if (!strcmp (color, "3d-shadow"))
89     {
90       return gui::EGDC_3D_SHADOW;
91     }
92   else if (!strcmp (color, "3d-face"))
93     {
94       return gui::EGDC_3D_FACE;
95     }
96   else if (!strcmp (color, "3d-high-light"))
97     {
98       return gui::EGDC_3D_HIGH_LIGHT;
99     }
100   else if (!strcmp (color, "3d-light"))
101     {
102       return gui::EGDC_3D_LIGHT;
103     }
104   else if (!strcmp (color, "active-border"))
105     {
106       return gui::EGDC_ACTIVE_BORDER;
107     }
108   else if (!strcmp (color, "active-caption"))
109     {
110       return gui::EGDC_ACTIVE_CAPTION;
111     }
112   else if (!strcmp (color, "app-workspace"))
113     {
114       return gui::EGDC_APP_WORKSPACE;
115     }
116   else if (!strcmp (color, "button-text"))
117     {
118       return gui::EGDC_BUTTON_TEXT;
119     }
120   else if (!strcmp (color, "gray-text"))
121     {
122       return gui::EGDC_GRAY_TEXT;
123     }
124   else if (!strcmp (color, "high-light"))
125     {
126       return gui::EGDC_HIGH_LIGHT;
127     }
128   else if (!strcmp (color, "high-light-text"))
129     {
130       return gui::EGDC_HIGH_LIGHT_TEXT;
131     }
132   else if (!strcmp (color, "inactive-border"))
133     {
134       return gui::EGDC_INACTIVE_BORDER;
135     }
136   else if (!strcmp (color, "inactive-caption"))
137     {
138       return gui::EGDC_INACTIVE_CAPTION;
139     }
140   else if (!strcmp (color, "tooltip"))
141     {
142       return gui::EGDC_TOOLTIP;
143     }
144   else if (!strcmp (color, "tooltip-background"))
145     {
146       return gui::EGDC_TOOLTIP_BACKGROUND;
147     }
148   else if (!strcmp (color, "scrollbar"))
149     {
150       return gui::EGDC_SCROLLBAR;
151     }
152   else if (!strcmp (color, "window"))
153     {
154       return gui::EGDC_WINDOW;
155     }
156   else if (!strcmp (color, "window-symbol"))
157     {
158       return gui::EGDC_WINDOW_SYMBOL;
159     }
160   else if (!strcmp (color, "icon"))
161     {
162       return gui::EGDC_ICON;
163     }
164   else if (!strcmp (color, "icon-high-light"))
165     {
166       return gui::EGDC_ICON_HIGH_LIGHT;
167     }
168   else if (!strcmp (color, "gray-window-symbol"))
169     {
170       return gui::EGDC_GRAY_WINDOW_SYMBOL;
171     }
172   else if (!strcmp (color, "editable"))
173     {
174       return gui::EGDC_EDITABLE;
175     }
176   else if (!strcmp (color, "gray-editable"))
177     {
178       return gui::EGDC_GRAY_EDITABLE;
179     }
180   else if (!strcmp (color, "focused-editable"))
181     {
182       return gui::EGDC_FOCUSED_EDITABLE;
183     }
184   else
185     {
186       scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S",
187                  scm_list_1 (default_color), scm_list_1 (default_color));
188     }
189 }
190
191 gui::EGUI_DEFAULT_FONT
192 scm_to_default_font (SCM default_font)
193 {
194   char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
195   if (!strcmp (font, "default"))
196     {
197       return gui::EGDF_DEFAULT;
198     }
199   else if (!strcmp (font, "button"))
200     {
201       return gui::EGDF_BUTTON;
202     }
203   else if (!strcmp (font, "window"))
204     {
205       return gui::EGDF_WINDOW;
206     }
207   else if (!strcmp (font, "menu"))
208     {
209       return gui::EGDF_MENU;
210     }
211   else if (!strcmp (font, "tooltip"))
212     {
213       return gui::EGDF_TOOLTIP;
214     }
215   else
216     {
217       scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
218                  scm_list_1 (default_font), scm_list_1 (default_font));
219     }
220 }