OSDN Git Service

fcc0381a19c63686734369da944d5397b8f4ee51
[scala-sdl/scalasdl-1.0.git.git] / src / SDL.scala
1 /*************************************************
2 * ScalaSDL
3 *
4 *  /|/|
5 * (- - )
6 * (    )~
7 *
8 * RoNor
9 * ronor.u@gmail.com
10 * -----------------------------------------------
11 * SDL.scala
12 * SDLクラス及びそのコンパニオンクラスは、
13 * SDLのネイティブAPIと1対1で対応するメソッドを提供します。
14 *
15 * 参考資料
16 * http://www.libsdl.org/cgi/docwiki.cgi/SDL_API
17 *************************************************/
18 package sdl {
19   
20   object SDL {
21     System.loadLibrary("SDL")
22     //flags for init
23     val INIT_TIMER = 0x00000001
24     val INIT_AUDIO = 0x00000010
25     val INIT_VIDEO = 0x00000020
26     val INIT_CDROM = 0x00000100
27     val INIT_JOYSTICK = 0x00000200
28     val INIT_NOPARACHUTE = 0x00100000
29     val INIT_EVENTTHREAD = 0x01000000
30     val INIT_EVERYTHING = 0x0000FFFF
31
32     //flags for sdl_surface
33     val SWSURFACE = 0x00000000 //system memory
34     val HWSURFACE = 0x00000001 //video memory
35     val ASYNCBLIT = 0x00000004 //use async blits
36     val ANYFORMAT = 0x10000000
37     val HWPALETTE = 0x20000000
38     val DOUBLEBUF = 0x40000000
39     val FULLSCREEN = 0x80000000
40     val OPENGL = 0x00000002
41     val OPENGLBLIT = 0x0000000A
42     val RESIZABLE = 0x00000010
43     val NOFRAME = 0x00000020
44     val HWACCEL = 0x00000100
45     val SRCCOLORKEY = 0x00001000
46     val RLEACCELOK = 0x00002000
47     val SRCALPHA = 0x00010000
48     val PREALLOC = 0x01000000
49
50     //flags for setPalette()
51     val LOGPAL = 0x01
52     val PHYSPAL = 0x02
53    
54     //overlay formats
55     val YV12_OVERLAY = 0x32315659
56     val IYUV_OVERLAY = 0x56555949
57     val YUY2_OVERLAY = 0x32595559
58     val YVYU_OVERLAY = 0x55595659
59
60     private val sdl = new SDL()
61
62     //-------------------------------------------------
63     // General
64     //-------------------------------------------------
65     def init(flags:Int):Int = return sdl.init(flags) 
66     def initSubSystem(flags:Int):Int = return sdl.initSubSystem(flags)
67     def quitSubSystem(flags:Int):Unit = return sdl.quitSubSystem(flags)
68     def quit():Unit = return sdl.quit()
69     def wasInit(flags:Int):Int = return sdl.wasInit(flags)
70     def getError():String = return sdl.getError()
71     def setError():Unit = return sdl.setError()
72     def error():Unit = return sdl.error()
73     def clearError():Unit = return sdl.clearError()
74     def loadObject(sofile:String):Int = return sdl.loadObject(sofile)
75     def loadFunction(handle:Int, name:String):Int = return sdl.loadFunction(handle, name)
76     def unloadObject(handle:Int):Unit = return sdl.unloadObject(handle)
77     def getVersion():Version = return sdl.getVersion()
78     def getLinkedVersion():Version = return sdl.getLinkedVersion()
79
80     //-------------------------------------------------
81     // Video
82     //-------------------------------------------------
83     def getVideoSurface():Surface = return sdl.getVideoSurface()
84     def getVideoInfo():VideoInfo = return sdl.getVideoInfo()
85
86     def setVideoMode(width:Int, height:Int, bitsperpixel:Int, flags:Int):Surface = return sdl.setVideoMode(width, height, bitsperpixel, flags)
87     def flip(surface:Surface):Int = sdl.flip(surface)
88     def setColors(surface:Surface, colors:Array[Color], firstcolor:Int, ncolor:Int):Int = return sdl.setColors(surface, colors, firstcolor, ncolor)
89     def setPalette(surface:Surface, flags:Int, colors:Array[Color], firstcolor:Int, ncolors:Int):Int = return sdl.setPalette(surface, flags, colors, firstcolor, ncolors)
90     def mapRGB(fmt:PixelFormat, r:Int, g:Int, b:Int):Long = return sdl.mapRGB(fmt, r, g, b);
91     def lockSurface(surface:Surface):Int = return sdl.lockSurface(surface)
92     def unlockSurface(surface:Surface):Unit = return sdl.unlockSurface(surface)
93
94     //-------------------------------------------------
95     // Window Management
96     //-------------------------------------------------
97     def setCaption(title:String, icon:Int):Unit = return sdl.setCaption(title, icon)
98     def getTicks():Long = return sdl.getTicks()
99     def delay(ms:Long):Unit = return sdl.delay(ms)
100   }
101
102   class SDL {
103     //-------------------------------------------------
104     // General
105     //-------------------------------------------------
106     //int SDL_Init(Uint32 flags)
107     @native def init(flags:Int):Int
108     //int SDL_InitSubSystem(Uint32 flags)
109     @native def initSubSystem(flags:Int):Int
110     //void SDL_QuitSubSystem(Uint32 flags)
111     @native def quitSubSystem(flags:Int):Unit
112     //void SDL_Quit()
113     @native def quit():Unit
114     //int SDL_WasInit(Uint32 flags)
115     @native def wasInit(flags:Int):Int
116     //char* SDL_GetError()
117     @native def getError():String
118     //void SDL_SetError(const char *fmt, ...)
119     @native def setError():Unit
120     //void SDL_Error(SDL_errorcode code)
121     @native def error():Unit
122     //void SDL_ClearError()
123     @native def clearError():Unit
124     //void* SDL_LoadObject(const char* sofile)
125     @native def loadObject(sofile:String):Int
126     //void* SDL_LoadFunction(void* handle, const char* name)
127     @native def loadFunction(handle:Int, name:String):Int
128     //void SDL_UnloadObject(void* handle)
129     @native def unloadObject(handle:Int):Unit
130     //コンパイル時のSDLライブラリのバージョンを取得
131     @native def getVersion():Version
132     //動的にリンクしているSDLライブラリのバージョンを取得
133     @native def getLinkedVersion():Version
134
135     //-------------------------------------------------
136     // Video
137     //-------------------------------------------------
138     //SDL_Surface* SDL_GetVideoSurface()
139     @native def getVideoSurface():Surface
140     //const SDL_VideoInfo* SDL_GetVideoInfo()
141     @native def getVideoInfo():VideoInfo
142     //char* SDL_VideoDriverName(char* namebuf, int maxlen)
143     @native def videoDriverName(namebuf:String, maxlen:Int):String
144     //SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Unit32 flags)
145     @native def listModes():Rect
146     //int SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
147     @native def videoModeOK(width:Int, height:Int, bpp:Int, flags:Long):Int
148     //SDL_Surface* setVideoMode(int width, int height, int bitsperpixel, Uint32 flags)
149     @native def setVideoMode(width:Int, height:Int, bitsperpixel:Int, flags:Int):Surface
150     //void SDL_UpdateRect(SDL_Surface* screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
151     @native def updateRect(screen:Int, x:Int, y:Int, w:Int, h:Int):Unit
152     //void SDL_UpdateRects(SDL_Surface* screen, int numrects, SDL_Rect* rects)
153     @native def updateRects(screen:Int, numrects:Int, rects:Rect):Unit
154     //int SDL_Flip(SDL_Surface* screen)
155     @native def flip(screen:Surface):Int
156     //int SDL_SetColors(SDL_Surface* surface, SDL_Color *colors, int firstcolor, int ncolor)
157     @native def setColors(surface:Surface, colors:Array[Color], firstcolor:Int, ncolor:Int):Int
158     //int SDL_SetPalette(SDL_Surface* surface, int flags, SDL_Color* colors, int firstcolor, int ncolors)
159     @native def setPalette(surface:Surface, flags:Int, colors:Array[Color], firstcolor:Int, ncolors:Int):Int
160     //int SDL_SetGamma(float redgamma, float greengamma, float bluegamma)
161     
162     //int SDL_GetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable)
163     
164     //int SDL_SetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable)
165
166     //Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b)
167     @native def mapRGB(fmt:PixelFormat, r:Int, g:Int, b:Int):Long
168     //Uint32 SDL_MapRGBA(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
169     
170     //void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b)
171     
172     //void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) 
173    
174     //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
175     
176     //SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels,int width, int height, int depth, int pitch,Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
177     
178     //void SDL_FreeSurface(SDL_Surface* surface)
179     
180     //int SDL_LockSurface(SDL_Surface* surface)
181     @native def lockSurface(surface:Surface):Int
182     //void SDL_UnlockSurface(SDL_Surface* surface)
183     @native def unlockSurface(surface:Surface):Unit    
184     //SDL_Surface *SDL_ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags)
185     //SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface)
186     //SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
187     //int SDL_SaveBMP(SDL_Surface *surface, const char *file)
188     //int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
189     //int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha)
190     //void SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect)
191     //void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
192     //int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
193     //int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
194     
195     //---GL---
196     //int SDL_GL_LoadLibrary(const char *path)
197     //void *SDL_GL_GetProcAddress(const char* proc)
198     //int SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
199     //int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
200     //void SDL_GL_SwapBuffers(void)
201     
202     //---YUV---
203     //SDL_Overlay *SDL_CreateYUVOverlay(int width, int height, Uint32 format, SDL_Surface *display)
204     //int SDL_LockYUVOverlay(SDL_Overlay *overlay)
205     //void SDL_UnlockYUVOverlay(SDL_Overlay *overlay)
206     //int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
207     //void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
208     
209     //-------------------------------------------------
210     // Window Management
211     //-------------------------------------------------
212     //int SDL_GetWMInfo(SDL_SysWMinfo *info)
213     //void SDL_WM_SetCaption(const char *title, const char *icon)
214     @native def setCaption(title:String, icon:Int):Unit
215     //void SDL_WM_GetCaption(char **title, char **icon)
216     //void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
217     //int SDL_WM_IconifyWindow(void)
218     //int SDL_WM_ToggleFullScreen(SDL_Surface *surface)
219     //SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
220     
221     //-------------------------------------------------
222     // Events
223     //-------------------------------------------------
224     
225     //-------------------------------------------------
226     // Mouse
227     //-------------------------------------------------
228
229     //-------------------------------------------------
230     // Joystick
231     //-------------------------------------------------
232     
233     //-------------------------------------------------
234     // Audio
235     //-------------------------------------------------
236     
237     //-------------------------------------------------
238     // CD-ROM
239     //-------------------------------------------------
240     
241     //-------------------------------------------------
242     // Multi-threaded programming
243     //-------------------------------------------------
244
245     //-------------------------------------------------
246     // TIME
247     //-------------------------------------------------
248     //Uint32 SDL_GetTicks(void)
249     @native def getTicks():Long
250     //void SDL_Delay(Uint32 ms)
251     @native def delay(ms:Long):Unit
252     //SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void* param)
253     //SDL_bool SDL_RemoveTimer(SDL_TimerID id)
254     //int SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback)
255     
256     //-------------------------------------------------
257     // Files
258     //-------------------------------------------------
259     //SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
260     //SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
261     //SDL_RWops *SDL_RWFromMem(void *mem, int size)
262     //SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
263     //SDL_RWops *SDL_AllocRW(void)
264     //void SDL_FreeRW(SDL_RWops *context)
265     //#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
266     //#define SDL_RWtell(ctx)                 (ctx)->seek(ctx, 0, RW_SEEK_CUR)
267     //#define SDL_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
268     //#define SDL_RWwrite(ctx, ptr, size, n)  (ctx)->write(ctx, ptr, size, n)
269     //#define SDL_RWclose(ctx)                (ctx)->close(ctx)
270   }
271 }