瀏覽代碼

Fixed stream args order for read and write.
Added SDL path and clipboard functions.

woollybah 10 年之前
父節點
當前提交
650aedfb12
共有 5 個文件被更改,包括 160 次插入5 次删除
  1. 15 1
      sdl.mod/common.bmx
  2. 10 0
      sdl.mod/examples/sdlstream_load.bmx
  3. 8 0
      sdl.mod/examples/shark.txt
  4. 44 1
      sdl.mod/glue.c
  5. 83 3
      sdl.mod/sdl.bmx

+ 15 - 1
sdl.mod/common.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2014 Bruce A Henderson
+' Copyright (c) 2014-2015 Bruce A Henderson
 '
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
@@ -75,6 +75,17 @@ Extern
 	Function bmx_SDL_RWwrite:Long(handle:Byte Ptr, buffer:Byte Ptr, size:Long, num:Long)
 	Function bmx_SDL_RWclose:Int(handle:Byte Ptr)
 	
+	Function bmx_SDL_GetBasePath:String()
+	Function bmx_SDL_GetPrefPath:String(org:String, app:String)
+?android
+	Function SDL_AndroidGetExternalStoragePath:Byte Ptr()
+	Function SDL_AndroidGetExternalStorageState:Int()
+	Function SDL_AndroidGetInternalStoragePath:Byte Ptr()
+?
+	Function SDL_HasClipboardText:Int()
+	Function bmx_SDL_GetClipboardText:String()
+	Function SDL_SetClipboardText:Int(text:Byte Ptr)
+	
 End Extern
 
 
@@ -126,3 +137,6 @@ about: Called on iOS in applicationDidBecomeActive().
 End Rem
 Const SDL_APP_DIDENTERFOREGROUND:Int  = $106
 
+
+Const SDL_ANDROID_EXTERNAL_STORAGE_READ:Int = $01
+Const SDL_ANDROID_EXTERNAL_STORAGE_WRITE:Int = $02

+ 10 - 0
sdl.mod/examples/sdlstream_load.bmx

@@ -0,0 +1,10 @@
+SuperStrict
+
+Framework sdl.sdl
+Import brl.standardio
+
+Local text:String = LoadText("sdl::shark.txt")
+
+Print text
+
+

+ 8 - 0
sdl.mod/examples/shark.txt

@@ -0,0 +1,8 @@
+The Smiling Shark
+
+
+ There was an old Shark with a smile
+ So broad you could see it a mile.
+     He said to his friends,
+     As he sewed up the ends,
+ "It was really too wide for the style."

+ 44 - 1
sdl.mod/glue.c

@@ -1,5 +1,5 @@
 /*
- Copyright (c) 2014 Bruce A Henderson
+ Copyright (c) 2014-2015 Bruce A Henderson
 
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
@@ -33,6 +33,11 @@ int sdl_sdl__sdl_rwops_close(BBObject *);
 void bmx_SDL_FreeRW_stream(SDL_RWops * ops);
 BBString * bmx_SDL_GetError();
 
+BBString * bmx_SDL_GetBasePath();
+BBString * bmx_SDL_GetPrefPath(BBString * org, BBString * game);
+BBString * bmx_SDL_GetClipboardText();
+
+/* ----------------------------------------------------- */
 
 BBString * bmx_SDL_GetError() {
 	return bbStringFromUTF8String(SDL_GetError());
@@ -110,3 +115,41 @@ BBLONG bmx_SDL_RWwrite(SDL_RWops* context, const void* ptr, BBLONG size, BBLONG
 int bmx_SDL_RWclose(SDL_RWops* context) {
 	return SDL_RWclose(context);
 }
+
+/* ----------------------------------------------------- */
+
+BBString * bmx_SDL_GetBasePath() {
+	BBString * path = &bbEmptyString;
+	char * p = SDL_GetBasePath();
+	if (p) {
+		path = bbStringFromUTF8String(p);
+		SDL_free(p);
+	}
+	return path;
+}
+
+BBString * bmx_SDL_GetPrefPath(BBString * org, BBString * game) {
+	BBString * path = &bbEmptyString;
+	char * o = bbStringToUTF8String(org);
+	char * g = bbStringToUTF8String(game);
+	char * p = SDL_GetPrefPath(o, g);
+	if (p) {
+		path = bbStringFromUTF8String(p);
+		SDL_free(p);
+	}
+	bbMemFree(g);
+	bbMemFree(o);
+	return path;
+}
+
+/* ----------------------------------------------------- */
+
+BBString * bmx_SDL_GetClipboardText() {
+	BBString * text = &bbEmptyString;
+	char * t = SDL_GetClipboardText();
+	if (t) {
+		text = bbStringFromUTF8String(t);
+		SDL_free(t);
+	}
+	return text;
+}

+ 83 - 3
sdl.mod/sdl.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2014 Bruce A Henderson
+' Copyright (c) 2014-2015 Bruce A Henderson
 '
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
@@ -117,11 +117,11 @@ Type TSDLStream Extends TStream
 	End Method
 
 	Method Read:Long( buf:Byte Ptr,count:Long )
-		Return bmx_SDL_RWread(filePtr, buf, count, 1)
+		Return bmx_SDL_RWread(filePtr, buf, 1, count)
 	End Method
 
 	Method Write:Long( buf:Byte Ptr,count:Long )
-		Return bmx_SDL_RWwrite(filePtr, buf, count, 1)
+		Return bmx_SDL_RWwrite(filePtr, buf, 1, count)
 	End Method
 
 	Method Close:Int()
@@ -174,6 +174,8 @@ Type TSDLStreamFactory Extends TStreamFactory
 	
 End Type
 
+New TSDLStreamFactory
+
 Function _sdl_rwops_seek:Int(stream:TStream, pos:Long, whence:Int)
 	Return stream.seek(pos, whence)
 End Function
@@ -190,3 +192,81 @@ Function _sdl_rwops_close:Int(stream:TStream)
 	Return stream.close()
 End Function
 
+Rem
+bbdoc: Get the directory where the application was run from.
+about: This is where the application data directory is.
+This is not necessarily a fast call, though, so you should call this once near startup and save the string if you need it.<br/>
+Mac OS X and iOS Specific Functionality: If the application is in a ".app" bundle, this function returns the Resource directory
+(e.g. MyApp.app/Contents/Resources/). This behaviour can be overridden by adding a property to the Info.plist file. Adding a string key with
+the name SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value will change the behaviour.
+End Rem
+Function GetBasePath:String()
+	Return bmx_SDL_GetBasePath()
+End Function
+
+Rem
+bbdoc: Returns the preferences dir.
+about: This is meant to be where the application can write personal files (Preferences and save games, etc.) that are specific to the application.
+This directory is unique per user and per application. The path will be Null if there is a problem (creating directory failed, etc.)<br/>
+The return path will be guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
+You should assume the path returned by this function is the only safe place to write files (and that GetBasePath(), while it might be writable, or even
+the parent of the returned path, aren't where you should be writing things).<br/>
+Both the org and app strings may become part of a directory name, so please follow these rules:<br/>
+* Try to use the same org string (including case-sensitivity) for all your applications that use this function.<br/>
+* Always use a unique app string for each one, and make sure it never changes for an app once you've decided on it.<br/>
+* Only use letters, numbers, and spaces. Avoid punctuation like "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
+End Rem
+Function GetPrefPath:String(org:String, app:String)
+	Return bmx_SDL_GetPrefPath(org, app)
+End Function
+?android
+Rem
+bbdoc: Gets the path used for external storage for this application.
+returns: The path used for external storage for this application on success or NULL on failure; call SDL_GetError() for more information.
+about: This path is unique to your application, but is public and can be written to by other applications.
+Your external storage path is typically: /storage/sdcard0/Android/data/your.app.package/files.
+End Rem
+Function AndroidGetExternalStoragePath:String()
+	Return String.FromUTF8String(SDL_AndroidGetExternalStoragePath())
+End Function
+
+Rem
+bbdoc: Gets the current state of external storage.
+about: The current state of external storage, a bitmask of these values: SDL_ANDROID_EXTERNAL_STORAGE_READ, SDL_ANDROID_EXTERNAL_STORAGE_WRITE.
+If external storage is currently unavailable, this will return 0.
+End Rem
+Function AndroidGetExternalStorageState:Int()
+	Return SDL_AndroidGetExternalStorageState()
+End Function
+
+Rem
+bbdoc: Gets the path used for internal storage for this application.
+returns: The path used for internal storage or NULL on failure; call SDL_GetError() for more information.
+about: This path is unique to your application and cannot be written to by other applications.
+Your internal storage path is typically: /data/data/your.app.package/files.
+End Rem
+Function AndroidGetInternalStoragePath:String()
+	Return String.FromUTF8String(SDL_AndroidGetInternalStoragePath())
+End Function
+?
+Rem
+bbdoc: Return a flag indicating whether the clipboard exists and contains a text string that is non-empty.
+End Rem
+Function HasClipboardText:Int()
+	Return SDL_HasClipboardText()
+End Function
+
+Rem
+bbdoc: Returns the clipboard text.
+End Rem
+Function GetClipboardText:String()
+	Return bmx_SDL_GetClipboardText()
+End Function
+
+Rem
+bbdoc: Puts text into the clipboard.
+returns: 0 on success or a negative error code on failure.
+End Rem
+Function SetClipboardText:Int(text:String)
+	Return SDL_SetClipboardText(text.ToUTF8String())
+End Function