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