OSDN Git Service

SDL.blitSurfaceの実装
authorRoNor <ronoru@users.sourceforge.jp>
Mon, 17 May 2010 14:56:42 +0000 (23:56 +0900)
committerRoNor <ronoru@users.sourceforge.jp>
Mon, 17 May 2010 14:56:42 +0000 (23:56 +0900)
getSDL_SurfacePointerの戻り値の型をSDL_Surface*にキャストするよう変更。

build/sdl/SDL$.class
build/sdl/SDL.class
src/SDL.c
src/SDL.scala
src/sdl_SDL.h

index 6b8043a..ddb727e 100644 (file)
Binary files a/build/sdl/SDL$.class and b/build/sdl/SDL$.class differ
index 119eb1f..a9de2da 100644 (file)
Binary files a/build/sdl/SDL.class and b/build/sdl/SDL.class differ
index 704fec1..853710c 100644 (file)
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -28,12 +28,12 @@ jclass getSDL_VideoInfo(JNIEnv *env){
   return (*env)->FindClass(env, "Lsdl/VideoInfo;");
 }
 
-jint getSDL_SurfacePointer(JNIEnv *env, jobject surface){
+SDL_Surface* getSDL_SurfacePointer(JNIEnv *env, jobject surface){
   jobject sdl_surface_obj = (*env)->GetObjectClass(env, surface);
   jclass sdl_surface = getSDL_Surface(env);
   jfieldID fld_pointer = (*env)->GetFieldID(env, sdl_surface, "pointer", "I");
   jint pointer = (*env)->GetIntField(env, surface, fld_pointer);
-  return pointer;
+  return (SDL_Surface*)pointer;
 
 }
 
@@ -300,7 +300,8 @@ JNIEXPORT jstring JNICALL Java_sdl_SDL_videoDriverName(JNIEnv *env, jobject obj)
   return driver_name;
 }
 
-JNIEXPORT jobject JNICALL Java_sdl_SDL_listModes(JNIEnv *env, jobject obj){
+JNIEXPORT jobjectArray JNICALL Java_sdl_SDL_listModes(JNIEnv *env, jobject obj, jobject format, jint flags){
+  
 }
 
 JNIEXPORT jint JNICALL Java_sdl_SDL_videoModeOK(JNIEnv *env, jobject obj, jint width, jint height, jint bpp, jlong flags){
@@ -325,13 +326,13 @@ JNIEXPORT jint JNICALL Java_sdl_SDL_flip(JNIEnv *env, jobject obj, jobject surfa
   jobject sdl_surface_obj = (*env)->GetObjectClass(env, surface);
   jclass sdl_surface = getSDL_Surface(env);
   jfieldID fld_pointer = (*env)->GetFieldID(env, sdl_surface, "pointer", "I");
-  jint surface_pointer = (*env)->GetIntField(env, surface, fld_pointer);
+  SDL_Surface* surface_pointer = (SDL_Surface*)(*env)->GetIntField(env, surface, fld_pointer);
 
-  return SDL_Flip((SDL_Surface*)surface_pointer);
+  return SDL_Flip(surface_pointer);
 }
 
 JNIEXPORT jint JNICALL Java_sdl_SDL_setColors(JNIEnv *env, jobject obj, jobject surface, jobjectArray colors, jint firstcolor, jint ncolors){
-  jint surface_pointer = getSDL_SurfacePointer(env, surface);
+  SDL_Surface* surface_pointer = getSDL_SurfacePointer(env, surface);
   jclass color_class = getSDL_Color(env);
 
   jfieldID fld_r = (*env)->GetFieldID(env, color_class, "r", "I");
@@ -350,11 +351,11 @@ JNIEXPORT jint JNICALL Java_sdl_SDL_setColors(JNIEnv *env, jobject obj, jobject
     sdl_colors[i].g = color_g;
     sdl_colors[i].b = color_b;
   }
-  return SDL_SetColors((SDL_Surface*)surface_pointer, sdl_colors, firstcolor, ncolors);
+  return SDL_SetColors(surface_pointer, sdl_colors, firstcolor, ncolors);
 }
 
 JNIEXPORT jint JNICALL Java_sdl_SDL_setPalette(JNIEnv *env, jobject obj, jobject surface, jint flags, jobjectArray colors, jint firstcolor, jint ncolors){
-  jint surface_pointer = getSDL_SurfacePointer(env, surface);
+  SDL_Surface* surface_pointer = getSDL_SurfacePointer(env, surface);
   jclass color_class = getSDL_Color(env);
 
   jfieldID fld_r = (*env)->GetFieldID(env, color_class, "r", "I");
@@ -379,7 +380,7 @@ JNIEXPORT jint JNICALL Java_sdl_SDL_setPalette(JNIEnv *env, jobject obj, jobject
     sdl_colors[i].b = color_b;
   }
 
-  return SDL_SetPalette((SDL_Surface*)surface_pointer, flags, sdl_colors, firstcolor, ncolors);
+  return SDL_SetPalette(surface_pointer, flags, sdl_colors, firstcolor, ncolors);
 }
 
 
@@ -396,19 +397,51 @@ JNIEXPORT jint JNICALL Java_sdl_SDL_lockSurface(JNIEnv *env, jobject obj, jobjec
   jobject sdl_surface_obj = (*env)->GetObjectClass(env, surface);
   jclass sdl_surface = getSDL_Surface(env);
   jfieldID fld_pointer = (*env)->GetFieldID(env, sdl_surface, "pointer", "I");
-  jint surface_pointer = (*env)->GetIntField(env, surface, fld_pointer);
-  return SDL_LockSurface((SDL_Surface*)surface_pointer);
+  SDL_Surface* surface_pointer = (SDL_Surface*)(*env)->GetIntField(env, surface, fld_pointer);
+  return SDL_LockSurface(surface_pointer);
 }
 
 JNIEXPORT void JNICALL Java_sdl_SDL_unlockSurface(JNIEnv *env, jobject obj, jobject surface){
   jobject sdl_surface_obj = (*env)->GetObjectClass(env, surface);
   jclass sdl_surface = getSDL_Surface(env);
   jfieldID fld_pointer = (*env)->GetFieldID(env, sdl_surface, "pointer", "I");
-  jint surface_pointer = (*env)->GetIntField(env, surface, fld_pointer);
-  SDL_UnlockSurface((SDL_Surface*)surface_pointer);
+  SDL_Surface* surface_pointer = (SDL_Surface*)(*env)->GetIntField(env, surface, fld_pointer);
+  SDL_UnlockSurface(surface_pointer);
   return;
 }
 
+SDL_Rect* createSDL_Rect(JNIEnv* env, jobject rect_obj){
+  jclass sdl_rect = getSDL_Rect(env);
+  jfieldID fld_x = (*env)->GetFieldID(env, sdl_rect, "x", "I");
+  jfieldID fld_y = (*env)->GetFieldID(env, sdl_rect, "y", "I");
+  jfieldID fld_w = (*env)->GetFieldID(env, sdl_rect, "w", "I");
+  jfieldID fld_h = (*env)->GetFieldID(env, sdl_rect, "h", "I");
+
+  jint rect_x = (*env)->GetIntField(env, rect_obj, fld_x);
+  jint rect_y = (*env)->GetIntField(env, rect_obj, fld_y);
+  jint rect_w = (*env)->GetIntField(env, rect_obj, fld_w);
+  jint rect_h = (*env)->GetIntField(env, rect_obj, fld_h);
+
+  SDL_Rect* ret_rect;
+  ret_rect->x = rect_x;
+  ret_rect->y = rect_y;
+  ret_rect->w = rect_w;
+  ret_rect->h = rect_h;
+
+  return ret_rect;
+}
+
+JNIEXPORT jint JNICALL Java_sdl_SDL_blitSurface(JNIEnv *env, jobject obj, jobject src, jobject srcrect, jobject dst, jobject dstrect){
+  jclass sdl_surface = getSDL_Surface(env);
+  
+  SDL_Rect* srcrect2 = createSDL_Rect(env, srcrect);
+  SDL_Rect* dstrect2 = createSDL_Rect(env, dstrect);
+  SDL_Surface* src2 = getSDL_SurfacePointer(env, src);
+  SDL_Surface* dst2 = getSDL_SurfacePointer(env, dst);
+
+  return SDL_BlitSurface(src2, srcrect2, dst2, dstrect2);
+}
+
 
 /**
  * Window Management
index ec10663..e125742 100644 (file)
@@ -83,7 +83,8 @@ package sdl {
     def getVideoSurface():Surface = return sdl.getVideoSurface()
     def getVideoInfo():VideoInfo = return sdl.getVideoInfo()
     def videoDriverName():String = return sdl.videoDriverName()
-    def listModes(format:PixelFormat, flags:Int):Rect = return sdl.listModes(format, flags)
+    def listModes(format:PixelFormat, flags:Int):Array[Rect] = return sdl.listModes(format, flags)
+    def videoModeOK(width:Int, height:Int, bpp:Int, flags:Int):Int = return sdl.videoModeOK(width,height,bpp,flags)
     def setVideoMode(width:Int, height:Int, bitsperpixel:Int, flags:Int):Surface = return sdl.setVideoMode(width, height, bitsperpixel, flags)
     def flip(surface:Surface):Int = sdl.flip(surface)
     def setColors(surface:Surface, colors:Array[Color], firstcolor:Int, ncolor:Int):Int = return sdl.setColors(surface, colors, firstcolor, ncolor)
@@ -144,7 +145,7 @@ package sdl {
     //char* SDL_VideoDriverName(char* namebuf, int maxlen)
     @native def videoDriverName():String
     //SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Unit32 flags)
-    @native def listModes(format:PixelFormat, flags:Int):Rect
+    @native def listModes(format:PixelFormat, flags:Int):Array[Rect]
     //int SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
     @native def videoModeOK(width:Int, height:Int, bpp:Int, flags:Long):Int
     //SDL_Surface* setVideoMode(int width, int height, int bitsperpixel, Uint32 flags)
@@ -186,8 +187,12 @@ package sdl {
     //SDL_Surface *SDL_ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags)
     //SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface)
     //SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
+    //SDL_Surface *SDL_LoadBMP(const char *file)
+    @native def loadBMP(file:String):Surface
     //int SDL_SaveBMP(SDL_Surface *surface, const char *file)
+    @native def saveBMP(surface:Surface, file:String):Int
     //int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
+    @native def setColorKey(surface:Surface, flag:Int, key:Int):Int
     //int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha)
     //void SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect)
     //void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
index 00e085a..362e7a4 100644 (file)
@@ -146,10 +146,10 @@ JNIEXPORT jstring JNICALL Java_sdl_SDL_videoDriverName
 /*
  * Class:     sdl_SDL
  * Method:    listModes
- * Signature: ()Lsdl/Rect;
+ * Signature: (Lsdl/PixelFormat;I)[Lsdl/Rect;
  */
-JNIEXPORT jobject JNICALL Java_sdl_SDL_listModes
-  (JNIEnv *, jobject);
+JNIEXPORT jobjectArray JNICALL Java_sdl_SDL_listModes
+  (JNIEnv *, jobject, jobject, jint);
 
 /*
  * Class:     sdl_SDL
@@ -233,6 +233,14 @@ JNIEXPORT void JNICALL Java_sdl_SDL_unlockSurface
 
 /*
  * Class:     sdl_SDL
+ * Method:    blitSurface
+ * Signature: (Lsdl/Surface;Lsdl/Rect;Lsdl/Surface;Lsdl/Rect;)I
+ */
+JNIEXPORT jint JNICALL Java_sdl_SDL_blitSurface
+  (JNIEnv *, jobject, jobject, jobject, jobject, jobject);
+
+/*
+ * Class:     sdl_SDL
  * Method:    setCaption
  * Signature: (Ljava/lang/String;I)V
  */