]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_SDL.c
Gacela as Guile module.
[gacela.git] / src / gacela_SDL.c
index 07ab34799965feb91908b8fb1f03305deccc696a..f9500021399d3827cab8575037a95d1585fde64f 100644 (file)
@@ -20,6 +20,7 @@
 #include <SDL/SDL_events.h>
 #include <SDL/SDL_image.h>
 #include <SDL/SDL_mixer.h>
+#include <SDL/SDL_rotozoom.h>
 #include "gacela_SDL.h"
 
 struct surface
@@ -59,6 +60,16 @@ get_surface_address (SCM surface_smob)
   return surface->surface_address;
 }
 
+SCM
+get_surface_filename (SCM surface_smob)
+{
+  struct surface *surface;
+
+  scm_assert_smob_type (surface_tag, surface_smob);
+  surface = (struct surface *) SCM_SMOB_DATA (surface_smob);
+  return surface->filename;
+}
+
 SCM
 get_surface_width (SCM surface_smob)
 {
@@ -75,6 +86,22 @@ get_surface_height (SCM surface_smob)
   return scm_from_int (surface->h);
 }
 
+SCM
+get_surface_pixels (SCM surface_smob)
+{
+  SDL_Surface *surface = get_surface_address (surface_smob);
+
+  return scm_from_int ((int)surface->pixels);
+}
+
+SCM
+get_surface_format_BytesPerPixel (SCM surface_smob)
+{
+  SDL_Surface *surface = get_surface_address (surface_smob);
+
+  return scm_from_int (surface->format->BytesPerPixel);
+}
+
 SCM
 mark_surface (SCM surface_smob)
 {
@@ -133,10 +160,16 @@ gacela_SDL_SetVideoMode (SCM width, SCM height, SCM bpp, SCM flags)
     return make_surface (scm_from_locale_string ("screen"), screen);
   }
   else {
-    return SCM_UNSPECIFIED;
+    return SCM_BOOL_F;
   }
 }
 
+SCM
+gacela_SDL_FreeSurface (SCM surface)
+{
+  return scm_from_int (free_surface (surface));
+}
+
 SCM
 gacela_SDL_WM_SetCaption (SCM title, SCM icon)
 {
@@ -166,7 +199,27 @@ gacela_SDL_GetTicks (void)
 SCM
 gacela_SDL_DisplayFormat (SCM surface)
 {
-  return scm_from_int ((int)SDL_DisplayFormat (get_surface_address (surface)));
+  SDL_Surface *new = SDL_DisplayFormat (get_surface_address (surface));
+
+  if (new) {
+    return make_surface (get_surface_filename (surface), new);
+  }
+  else {
+    return SCM_BOOL_F;
+  }
+}
+
+SCM
+gacela_SDL_DisplayFormatAlpha (SCM surface)
+{
+  SDL_Surface *new = SDL_DisplayFormatAlpha (get_surface_address (surface));
+
+  if (new) {
+    return make_surface (get_surface_filename (surface), new);
+  }
+  else {
+    return SCM_BOOL_F;
+  }
 }
 
 SCM
@@ -181,6 +234,12 @@ gacela_SDL_SetColorKey (SCM surface, SCM flag, SCM key)
   return scm_from_int (SDL_SetColorKey (get_surface_address (surface), scm_to_int (flag), scm_to_int (key)));
 }
 
+SCM
+gacela_SDL_SetAlpha (SCM surface, SCM flag, SCM alpha)
+{
+  return scm_from_int (SDL_SetAlpha (get_surface_address (surface), scm_to_int (flag), scm_to_int (alpha)));
+}
+
 SCM
 gacela_SDL_LoadBMP (SCM file)
 {
@@ -190,7 +249,7 @@ gacela_SDL_LoadBMP (SCM file)
     return make_surface (file, image);
   }
   else {
-    return SCM_UNSPECIFIED;
+    return SCM_BOOL_F;
   }
 }
 
@@ -203,7 +262,7 @@ gacela_IMG_Load (SCM filename)
     return make_surface (filename, image);
   }
   else {
-    return SCM_UNSPECIFIED;
+    return SCM_BOOL_F;
   }
 }
 
@@ -262,6 +321,19 @@ gacela_SDL_EnableKeyRepeat (SCM delay, SCM interval)
   return scm_from_int (SDL_EnableKeyRepeat (scm_to_int (delay), scm_to_int (interval)));
 }
 
+SCM
+gacela_zoomSurface (SCM src, SCM zoomx, SCM zoomy, SCM smooth)
+{
+  SDL_Surface *image = zoomSurface (get_surface_address (src), scm_to_double (zoomx), scm_to_double (zoomy), scm_to_int (smooth));
+
+  if (image) {
+    return make_surface (get_surface_filename (src), image);
+  }
+  else {
+    return SCM_BOOL_F;
+  }
+}
+
 SCM
 gacela_Mix_OpenAudio (SCM frequency, SCM format, SCM channels, SCM chunksize)
 {
@@ -346,15 +418,18 @@ gacela_Mix_CloseAudio (void)
 }
 
 
-void*
-SDL_register_functions (void* data)
+void
+init_guile_SDL ()
 {
   surface_tag = scm_make_smob_type ("surface", sizeof (struct surface));
   scm_set_smob_mark (surface_tag, mark_surface);
   scm_set_smob_free (surface_tag, free_surface);
   scm_set_smob_print (surface_tag, print_surface);
+  scm_c_define_gsubr ("surface-file", 1, 0, 0, get_surface_filename);
   scm_c_define_gsubr ("surface-w", 1, 0, 0, get_surface_width);
   scm_c_define_gsubr ("surface-h", 1, 0, 0, get_surface_height);
+  scm_c_define_gsubr ("surface-pixels", 1, 0, 0, get_surface_pixels);
+  scm_c_define_gsubr ("surface-format-BytesPerPixel", 1, 0, 0, get_surface_format_BytesPerPixel);
 
   scm_c_define ("SDL_INIT_TIMER", scm_from_int (SDL_INIT_TIMER));
   scm_c_define ("SDL_INIT_AUDIO", scm_from_int (SDL_INIT_AUDIO));
@@ -422,13 +497,16 @@ SDL_register_functions (void* data)
   scm_c_define_gsubr ("SDL_Init", 1, 0, 0, gacela_SDL_Init);
   scm_c_define_gsubr ("SDL_Quit", 0, 0, 0, gacela_SDL_Quit);
   scm_c_define_gsubr ("SDL_SetVideoMode", 4, 0, 0, gacela_SDL_SetVideoMode);
+  scm_c_define_gsubr ("SDL_FreeSurface", 1, 0, 0, gacela_SDL_FreeSurface);
   scm_c_define_gsubr ("SDL_WM_SetCaption", 2, 0, 0, gacela_SDL_WM_SetCaption);
   scm_c_define_gsubr ("SDL_Flip", 1, 0, 0, gacela_SDL_Flip);
   scm_c_define_gsubr ("SDL_Delay", 1, 0, 0, gacela_SDL_Delay);
   scm_c_define_gsubr ("SDL_GetTicks", 0, 0, 0, gacela_SDL_GetTicks);
   scm_c_define_gsubr ("SDL_DisplayFormat", 1, 0, 0, gacela_SDL_DisplayFormat);
+  scm_c_define_gsubr ("SDL_DisplayFormatAlpha", 1, 0, 0, gacela_SDL_DisplayFormatAlpha);
   scm_c_define_gsubr ("SDL_MapRGB", 4, 0, 0, gacela_SDL_MapRGB);
   scm_c_define_gsubr ("SDL_SetColorKey", 3, 0, 0, gacela_SDL_SetColorKey);
+  scm_c_define_gsubr ("SDL_SetAlpha", 3, 0, 0, gacela_SDL_SetAlpha);
   scm_c_define_gsubr ("SDL_LoadBMP", 1, 0, 0, gacela_SDL_LoadBMP);
   scm_c_define_gsubr ("IMG_Load", 1, 0, 0, gacela_IMG_Load);
   scm_c_define_gsubr ("SDL_GetVideoInfo", 0, 0, 0, gacela_SDL_GetVideoInfo);
@@ -436,6 +514,7 @@ SDL_register_functions (void* data)
   scm_c_define_gsubr ("SDL_PollEvent", 0, 0, 0, gacela_SDL_PollEvent);
   scm_c_define_gsubr ("SDL_GL_SwapBuffers", 0, 0, 0, gacela_SDL_GL_SwapBuffers);
   scm_c_define_gsubr ("SDL_EnableKeyRepeat", 2, 0, 0, gacela_SDL_EnableKeyRepeat);
+  scm_c_define_gsubr ("zoomSurface", 4, 0, 0, gacela_zoomSurface);
   scm_c_define_gsubr ("Mix_OpenAudio", 4, 0, 0, gacela_Mix_OpenAudio);
   scm_c_define_gsubr ("Mix_LoadMUS", 1, 0, 0, gacela_Mix_LoadMUS);
   scm_c_define_gsubr ("Mix_LoadWAV", 1, 0, 0, gacela_Mix_LoadWAV);
@@ -449,6 +528,4 @@ SDL_register_functions (void* data)
   scm_c_define_gsubr ("Mix_FreeMusic", 1, 0, 0, gacela_Mix_FreeMusic);
   scm_c_define_gsubr ("Mix_FreeChunk", 1, 0, 0, gacela_Mix_FreeChunk);
   scm_c_define_gsubr ("Mix_CloseAudio", 0, 0, 0, gacela_Mix_CloseAudio);
-
-  return NULL;
 }