OSDN Git Service

fe273d276a272cc5fcafe95a0929aedf6838e2d0
[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 setVideoMode(width:Int, height:Int, bitsperpixel:Int, flags:Int):Surface = return sdl.setVideoMode(width, height, bitsperpixel, flags)
85     def flip(surface:Surface):Int = sdl.flip(surface)
86     def setColors(surface:Surface, colors:Array[Color], firstcolor:Int, ncolor:Int):Int = return sdl.setColors(surface, colors, firstcolor, ncolor)
87     def setPalette(surface:Surface, flags:Int, colors:Array[Color], firstcolor:Int, ncolors:Int):Int = return sdl.setPalette(surface, flags, colors, firstcolor, ncolors)
88     def mapRGB(fmt:PixelFormat, r:Int, g:Int, b:Int):Long = return sdl.mapRGB(fmt, r, g, b);
89     def lockSurface(surface:Surface):Int = return sdl.lockSurface(surface)
90     def unlockSurface(surface:Surface):Unit = return sdl.unlockSurface(surface)
91
92     //-------------------------------------------------
93     // Window Management
94     //-------------------------------------------------
95     def setCaption(title:String, icon:Int):Unit = return sdl.setCaption(title, icon)
96     def getTicks():Long = return sdl.getTicks()
97     def delay(ms:Long):Unit = return sdl.delay(ms)
98   }
99
100   class SDL {
101     //-------------------------------------------------
102     // General
103     //-------------------------------------------------
104     //int SDL_Init(Uint32 flags)
105     @native def init(flags:Int):Int
106     //int SDL_InitSubSystem(Uint32 flags)
107     @native def initSubSystem(flags:Int):Int
108     //void SDL_QuitSubSystem(Uint32 flags)
109     @native def quitSubSystem(flags:Int):Unit
110     //void SDL_Quit()
111     @native def quit():Unit
112     //int SDL_WasInit(Uint32 flags)
113     @native def wasInit(flags:Int):Int
114     //char* SDL_GetError()
115     @native def getError():String
116     //void SDL_SetError(const char *fmt, ...)
117     @native def setError():Unit
118     //void SDL_Error(SDL_errorcode code)
119     @native def error():Unit
120     //void SDL_ClearError()
121     @native def clearError():Unit
122     //void* SDL_LoadObject(const char* sofile)
123     @native def loadObject(sofile:String):Int
124     //void* SDL_LoadFunction(void* handle, const char* name)
125     @native def loadFunction(handle:Int, name:String):Int
126     //void SDL_UnloadObject(void* handle)
127     @native def unloadObject(handle:Int):Unit
128     //コンパイル時のSDLライブラリのバージョンを取得
129     @native def getVersion():Version
130     //動的にリンクしているSDLライブラリのバージョンを取得
131     @native def getLinkedVersion():Version
132
133     //-------------------------------------------------
134     // Video
135     //-------------------------------------------------
136     //SDL_Surface* SDL_GetVideoSurface()
137     @native def getVideoSurface():Surface
138     //const SDL_VideoInfo* SDL_GetVideoInfo()
139     @native def getVideoInfo():VideoInfo
140     //char* SDL_VideoDriverName(char* namebuf, int maxlen)
141     @native def videoDriverName(namebuf:String, maxlen:Int):String
142     //SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Unit32 flags)
143     @native def listModes():Rect
144     //int SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
145     @native def videoModeOK(width:Int, height:Int, bpp:Int, flags:Long):Int
146     //SDL_Surface* setVideoMode(int width, int height, int bitsperpixel, Uint32 flags)
147     @native def setVideoMode(width:Int, height:Int, bitsperpixel:Int, flags:Int):Surface
148     //void SDL_UpdateRect(SDL_Surface* screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
149     @native def updateRect(screen:Int, x:Int, y:Int, w:Int, h:Int):Unit
150     //void SDL_UpdateRects(SDL_Surface* screen, int numrects, SDL_Rect* rects)
151     @native def updateRects(screen:Int, numrects:Int, rects:Rect):Unit
152     //int SDL_Flip(SDL_Surface* screen)
153     @native def flip(screen:Surface):Int
154     //int SDL_SetColors(SDL_Surface* surface, SDL_Color *colors, int firstcolor, int ncolor)
155     @native def setColors(surface:Surface, colors:Array[Color], firstcolor:Int, ncolor:Int):Int
156     //int SDL_SetPalette(SDL_Surface* surface, int flags, SDL_Color* colors, int firstcolor, int ncolors)
157     @native def setPalette(surface:Surface, flags:Int, colors:Array[Color], firstcolor:Int, ncolors:Int):Int
158     //int SDL_SetGamma(float redgamma, float greengamma, float bluegamma)
159     
160     //int SDL_GetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable)
161     
162     //int SDL_SetGammaRamp(Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable)
163
164     //Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b)
165     @native def mapRGB(fmt:PixelFormat, r:Int, g:Int, b:Int):Long
166     //Uint32 SDL_MapRGBA(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
167     
168     //void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b)
169     
170     //void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) 
171    
172     //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
173     
174     //SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels,int width, int height, int depth, int pitch,Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
175     
176     //void SDL_FreeSurface(SDL_Surface* surface)
177     
178     //int SDL_LockSurface(SDL_Surface* surface)
179     @native def lockSurface(surface:Surface):Int
180     //void SDL_UnlockSurface(SDL_Surface* surface)
181     @native def unlockSurface(surface:Surface):Unit    
182     //SDL_Surface *SDL_ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags)
183     //SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface)
184     //SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface)
185     //int SDL_SaveBMP(SDL_Surface *surface, const char *file)
186     //int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
187     //int SDL_SetAlpha(SDL_Surface *surface, Uint32 flags, Uint8 alpha)
188     //void SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect)
189     //void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
190     //int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
191     //int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
192     
193     //---GL---
194     //int SDL_GL_LoadLibrary(const char *path)
195     //void *SDL_GL_GetProcAddress(const char* proc)
196     //int SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
197     //int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
198     //void SDL_GL_SwapBuffers(void)
199     
200     //---YUV---
201     //SDL_Overlay *SDL_CreateYUVOverlay(int width, int height, Uint32 format, SDL_Surface *display)
202     //int SDL_LockYUVOverlay(SDL_Overlay *overlay)
203     //void SDL_UnlockYUVOverlay(SDL_Overlay *overlay)
204     //int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
205     //void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
206     
207     //-------------------------------------------------
208     // Window Management
209     //-------------------------------------------------
210     //int SDL_GetWMInfo(SDL_SysWMinfo *info)
211     //void SDL_WM_SetCaption(const char *title, const char *icon)
212     @native def setCaption(title:String, icon:Int):Unit
213     //void SDL_WM_GetCaption(char **title, char **icon)
214     //void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
215     //int SDL_WM_IconifyWindow(void)
216     //int SDL_WM_ToggleFullScreen(SDL_Surface *surface)
217     //SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
218     
219     //-------------------------------------------------
220     // Events
221     //-------------------------------------------------
222     
223     //-------------------------------------------------
224     // Mouse
225     //-------------------------------------------------
226
227     //-------------------------------------------------
228     // Joystick
229     //-------------------------------------------------
230     
231     //-------------------------------------------------
232     // Audio
233     //-------------------------------------------------
234     
235     //-------------------------------------------------
236     // CD-ROM
237     //-------------------------------------------------
238     
239     //-------------------------------------------------
240     // Multi-threaded programming
241     //-------------------------------------------------
242
243     //-------------------------------------------------
244     // TIME
245     //-------------------------------------------------
246     //Uint32 SDL_GetTicks(void)
247     @native def getTicks():Long
248     //void SDL_Delay(Uint32 ms)
249     @native def delay(ms:Long):Unit
250     //SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void* param)
251     //SDL_bool SDL_RemoveTimer(SDL_TimerID id)
252     //int SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback)
253     
254     //-------------------------------------------------
255     // Files
256     //-------------------------------------------------
257     //SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
258     //SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
259     //SDL_RWops *SDL_RWFromMem(void *mem, int size)
260     //SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
261     //SDL_RWops *SDL_AllocRW(void)
262     //void SDL_FreeRW(SDL_RWops *context)
263     //#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
264     //#define SDL_RWtell(ctx)                 (ctx)->seek(ctx, 0, RW_SEEK_CUR)
265     //#define SDL_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
266     //#define SDL_RWwrite(ctx, ptr, size, n)  (ctx)->write(ctx, ptr, size, n)
267     //#define SDL_RWclose(ctx)                (ctx)->close(ctx)
268   }
269 }