]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/gui-environment.cpp
Some doc
[guile-irrlicht.git] / src / gui-environment.cpp
index fb13f53d363f901f1e7b2692523c3daf4e7a4d70..c2e52726d5d516c589d45bcb6fb65d6375512690 100644 (file)
 
 #include <irrlicht/irrlicht.h>
 #include <libguile.h>
-
-#include "device.h"
-#include "gui-element.h"
+#include "gsubr.h"
 #include "gui-environment.h"
-#include "gui-static-text.h"
+#include "position2d.h"
 #include "rect.h"
 #include "wchar.h"
 #include "wrapped.h"
 
-extern "C" {
-
-  void
-  init_gui_environment (void)
-  {
-    init_gui_environment_type ();
-    scm_c_define_gsubr ("add-static-text!", 3, 0, 1, (scm_t_subr)irr_gui_addStaticText);
-    scm_c_define_gsubr ("get-gui-environment", 1, 0, 0, (scm_t_subr)irr_getGUIEnvironment);
-    scm_c_export ("add-static-text!", "get-gui-environment", NULL);
-  }
-
-  DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
-                       init_gui_environment_type, gui_environment_p,
-                       wrap_gui_environment, unwrap_gui_environment);
-
-  SCM
-  irr_getGUIEnvironment (SCM wrapped_obj)
-  {
-    irr::gui::IGUIEnvironment* gui_environment;
-    if (device_p (wrapped_obj))
-      {
-        gui_environment = unwrap_device (wrapped_obj)->getGUIEnvironment ();
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot get GUI environment from object: ~S",
-                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
-      }
-    return wrap_gui_environment (gui_environment);
-  }
-
-  SCM
-  irr_gui_addStaticText (SCM wrapped_gui_environment,
-                         SCM text,
-                         SCM rectangle,
-                         SCM rest)
-  {
-    SCM border = scm_from_bool (0);
-    SCM word_wrap = scm_from_bool (1);
-    SCM parent = scm_from_bool (0);
-    SCM id = scm_from_int32 (-1);
-    SCM fill_background = scm_from_bool (0);
-
-    scm_c_bind_keyword_arguments ("add-static-text!", rest, (scm_t_keyword_arguments_flags)0,
-                                  scm_from_utf8_keyword ("border"), &border,
-                                  scm_from_utf8_keyword ("word-wrap"), &word_wrap,
-                                  scm_from_utf8_keyword ("parent"), &parent,
-                                  scm_from_utf8_keyword ("id"), &id,
-                                  scm_from_utf8_keyword ("fill-background"), &fill_background,
-                                  SCM_UNDEFINED);
-
-    irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
-    irr::gui::IGUIStaticText* staticText =
-      guienv->addStaticText (scm_to_wide_char_string (text),
-                             scm_to_rect_s32 (rectangle),
-                             scm_to_bool (border),
-                             scm_to_bool (word_wrap),
-                             scm_is_false (parent) ? 0 : unwrap_gui_element (parent),
-                             scm_to_int32 (id),
-                             scm_to_bool (fill_background));
-    return wrap_gui_static_text (staticText);
-  }
+using namespace irr;
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addButton (SCM gui_environment,
+                           SCM rectangle,
+                           SCM parent,
+                           SCM id,
+                           SCM text,
+                           SCM tooltiptext)
+{
+  wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
+  wchar_t* wtooltiptext = (wchar_t*) scm_to_utf32_string (tooltiptext);
+
+  gui::IGUIButton* button =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addButton (scm_to_rect_s32 (rectangle),
+               (TParent)scm_to_irr_pointer (parent),
+               scm_to_int32 (id),
+               wtext,
+               wtooltiptext);
+
+  free (wtext);
+  free (wtooltiptext);
+  return scm_from_irr_pointer ("<gui-button>", (void*) button);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addEditBox (SCM gui_environment,
+                            SCM text,
+                            SCM rectangle,
+                            SCM border,
+                            SCM parent,
+                            SCM id)
+{
+  wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
+
+  gui::IGUIEditBox* editbox =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addEditBox (wtext,
+                scm_to_rect_s32 (rectangle),
+                scm_to_bool (border),
+                (TParent)scm_to_irr_pointer (parent),
+                scm_to_int32 (id));
+
+  free (wtext);
+  return scm_from_irr_pointer ("<gui-editbox>", (void*) editbox);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addFileOpenDialog (SCM gui_environment,
+                                   SCM title,
+                                   SCM modal,
+                                   SCM parent,
+                                   SCM id,
+                                   SCM restore_cwd,
+                                   SCM start_dir)
+{
+  gui::IGUIEnvironment* guienv = (gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment);
+  wchar_t* wtitle = (wchar_t*) scm_to_utf32_string (title);
+  io::path::char_type* cstartDir = scm_to_utf8_string (start_dir);
+
+  gui::IGUIFileOpenDialog* dialog =
+    guienv->addFileOpenDialog (wtitle,
+                               scm_to_bool (modal),
+                               (TParent)scm_to_irr_pointer (parent),
+                               scm_to_int32 (id),
+                               scm_to_bool (restore_cwd),
+                               cstartDir);
+
+  free (wtitle);
+  free (cstartDir);
+  return scm_from_irr_pointer ("<gui-file-open-dialog>", (void*) dialog);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addImage (SCM gui_environment,
+                          SCM image,
+                          SCM position,
+                          SCM use_alpha_channel,
+                          SCM parent,
+                          SCM id,
+                          SCM text)
+{
+  gui::IGUIEnvironment* guienv = (gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment);
+  wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
+
+  gui::IGUIImage* new_image =
+    guienv->addImage ((video::ITexture*)scm_to_irr_pointer (image),
+                      scm_to_position2d_s32 (position),
+                      scm_to_bool (use_alpha_channel),
+                      (TParent)scm_to_irr_pointer (parent),
+                      scm_to_int32 (id),
+                      wtext);
+
+  free (wtext);
+  return scm_from_irr_pointer ("<gui-image>", (void*) new_image);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addListBox (SCM gui_environment,
+                            SCM rectangle,
+                            SCM parent,
+                            SCM id,
+                            SCM draw_background)
+{
+  gui::IGUIListBox* listbox =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addListBox (scm_to_rect_s32 (rectangle),
+                (TParent)scm_to_irr_pointer (parent),
+                scm_to_int32 (id),
+                scm_to_bool (draw_background));
+  return scm_from_irr_pointer ("<gui-listbox>", (void*) listbox);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addScrollBar (SCM gui_environment,
+                              SCM horizontal,
+                              SCM rectangle,
+                              SCM parent,
+                              SCM id)
+{
+  gui::IGUIScrollBar* scrollbar =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addScrollBar (scm_to_bool (horizontal),
+                  scm_to_rect_s32 (rectangle),
+                  (TParent)scm_to_irr_pointer (parent),
+                  scm_to_int32 (id));
+  return scm_from_irr_pointer ("<gui-scrollbar>", (void*) scrollbar);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addStaticText (SCM gui_environment,
+                               SCM text,
+                               SCM rectangle,
+                               SCM border,
+                               SCM word_wrap,
+                               SCM parent,
+                               SCM id,
+                               SCM fill_background)
+{
+  wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
+
+  gui::IGUIStaticText* static_text =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addStaticText (wtext,
+                   scm_to_rect_s32 (rectangle),
+                   scm_to_bool (border),
+                   scm_to_bool (word_wrap),
+                   (TParent)scm_to_irr_pointer (parent),
+                   scm_to_int32 (id),
+                   scm_to_bool (fill_background));
+
+  free (wtext);
+  return scm_from_irr_pointer ("<gui-static-text>", (void*) static_text);
+}
+
+template <typename TParent>
+SCM
+IGUIEnvironment_addWindow (SCM gui_environment,
+                           SCM rectangle,
+                           SCM modal,
+                           SCM text,
+                           SCM parent,
+                           SCM id)
+{
+  wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
+
+  gui::IGUIWindow* window =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
+    addWindow (scm_to_rect_s32 (rectangle),
+               scm_to_bool (modal),
+               wtext,
+               (TParent)scm_to_irr_pointer (parent),
+               scm_to_int32 (id));
+
+  free (wtext);
+  return scm_from_irr_pointer ("<gui-window>", (void*) window);
+}
+
+SCM
+IGUIEnvironment_drawAll (SCM gui_environment)
+{
+  ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->drawAll ();
+  return SCM_UNSPECIFIED;
+}
+
+SCM
+IGUIEnvironment_getBuiltInFont (SCM gui_environment)
+{
+  gui::IGUIFont* font =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getBuiltInFont ();
+  return scm_from_irr_pointer ("<gui-font>", (void*) font);
+}
+
+SCM
+IGUIEnvironment_getFont (SCM gui_environment,
+                         SCM filename)
+{
+  char* cfilename = scm_to_utf8_string (filename);
+  gui::IGUIFont* font =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getFont (cfilename);
+  free (cfilename);
+  return scm_from_irr_pointer ("<gui-font>", (void*) font);
+}
+
+SCM
+IGUIEnvironment_getSkin (SCM gui_environment)
+{
+  gui::IGUISkin* skin =
+    ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getSkin ();
+  return scm_from_irr_pointer ("<gui-skin>", (void*) skin);
+}
 
+void
+init_gui_environment (void)
+{
+  DEFINE_GSUBR ("IGUIEnvironment_addButton_IGUIElement", 6, 0, 0,
+                IGUIEnvironment_addButton<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addEditBox_IGUIElement", 6, 0, 0,
+                IGUIEnvironment_addEditBox<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addFileOpenDialog_IGUIElement", 7, 0, 0,
+                IGUIEnvironment_addFileOpenDialog<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addImage_IGUIElement", 7, 0, 0,
+                IGUIEnvironment_addImage<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addListBox_IGUIElement", 5, 0, 0,
+                IGUIEnvironment_addListBox<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addScrollBar_IGUIElement", 5, 0, 0,
+                IGUIEnvironment_addScrollBar<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addStaticText_IGUIElement", 8, 0, 0,
+                IGUIEnvironment_addStaticText<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addStaticText_IGUIWindow", 8, 0, 0,
+                IGUIEnvironment_addStaticText<gui::IGUIWindow*>);
+  DEFINE_GSUBR ("IGUIEnvironment_addWindow_IGUIElement", 6, 0, 0,
+                IGUIEnvironment_addWindow<gui::IGUIElement*>);
+  DEFINE_GSUBR ("IGUIEnvironment_drawAll", 1, 0, 0, IGUIEnvironment_drawAll);
+  DEFINE_GSUBR ("IGUIEnvironment_getBuiltInFont", 1, 0, 0, IGUIEnvironment_getBuiltInFont);
+  DEFINE_GSUBR ("IGUIEnvironment_getFont", 2, 0, 0, IGUIEnvironment_getFont);
+  DEFINE_GSUBR ("IGUIEnvironment_getSkin", 1, 0, 0, IGUIEnvironment_getSkin);
 }