]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-scrollbar.cpp
gui
[guile-irrlicht.git] / src / gui-scrollbar.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
25 #include "gui-element.h"
26 #include "gui-scrollbar.h"
27 #include "gsubr.h"
28 #include "wrapped.h"
29
30 extern "C" {
31
32   void
33   init_gui_scrollbar (void)
34   {
35     init_gui_scrollbar_type ();
36     DEFINE_GSUBR ("get-pos", 1, 0, 0, irr_gui_getPos);
37     DEFINE_GSUBR ("set-pos!", 2, 0, 0, irr_gui_setPos);
38   }
39
40   DEFINE_WRAPPED_TYPE (irr::gui::IGUIScrollBar*, "gui-scrollbar",
41                        init_gui_scrollbar_type, gui_scrollbar_p,
42                        wrap_gui_scrollbar, unwrap_gui_scrollbar);
43
44   SCM
45   irr_gui_setMax (SCM wrapped_obj,
46                   SCM max)
47   {
48 #define SET_MAX(OBJ) OBJ->setMax (scm_to_int32 (max));
49
50     if (gui_editbox_p (wrapped_obj))
51       {
52         SET_MAX (unwrap_gui_editbox (wrapped_obj));
53       }
54     else if (gui_scrollbar_p (wrapped_obj))
55       {
56         SET_MAX (unwrap_gui_scrollbar (wrapped_obj));
57       }
58     else
59       {
60         scm_error (scm_arg_type_key, NULL, "Cannot set max to object: ~S",
61                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
62       }
63     return SCM_UNSPECIFIED;
64   }
65
66   SCM
67   irr_gui_getPos (SCM wrapped_scrollbar)
68   {
69     irr::gui::IGUIScrollBar* scrollbar;
70     if (gui_element_p (wrapped_scrollbar))
71       {
72         scrollbar = (irr::gui::IGUIScrollBar*)unwrap_gui_element (wrapped_scrollbar);
73       }
74     else {
75       scrollbar = unwrap_gui_scrollbar (wrapped_scrollbar);
76     }
77     return scm_from_int32 (scrollbar->getPos ());
78   }
79
80   SCM
81   irr_gui_setPos (SCM wrapped_scrollbar,
82                   SCM pos)
83   {
84     irr::gui::IGUIScrollBar* scrollbar;
85     if (gui_element_p (wrapped_scrollbar))
86       {
87         scrollbar = (irr::gui::IGUIScrollBar*)unwrap_gui_element (wrapped_scrollbar);
88       }
89     else {
90       scrollbar = unwrap_gui_scrollbar (wrapped_scrollbar);
91     }
92     scrollbar->setPos (scm_to_int32 (pos));
93     return SCM_UNSPECIFIED;
94   }
95
96 }