소스 검색

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
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
 ' 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_RWwrite:Long(handle:Byte Ptr, buffer:Byte Ptr, size:Long, num:Long)
 	Function bmx_SDL_RWclose:Int(handle:Byte Ptr)
 	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
 End Extern
 
 
 
 
@@ -126,3 +137,6 @@ about: Called on iOS in applicationDidBecomeActive().
 End Rem
 End Rem
 Const SDL_APP_DIDENTERFOREGROUND:Int  = $106
 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
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  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);
 void bmx_SDL_FreeRW_stream(SDL_RWops * ops);
 BBString * bmx_SDL_GetError();
 BBString * bmx_SDL_GetError();
 
 
+BBString * bmx_SDL_GetBasePath();
+BBString * bmx_SDL_GetPrefPath(BBString * org, BBString * game);
+BBString * bmx_SDL_GetClipboardText();
+
+/* ----------------------------------------------------- */
 
 
 BBString * bmx_SDL_GetError() {
 BBString * bmx_SDL_GetError() {
 	return bbStringFromUTF8String(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) {
 int bmx_SDL_RWclose(SDL_RWops* context) {
 	return SDL_RWclose(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
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
 ' warranty. In no event will the authors be held liable for any damages
@@ -117,11 +117,11 @@ Type TSDLStream Extends TStream
 	End Method
 	End Method
 
 
 	Method Read:Long( buf:Byte Ptr,count:Long )
 	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
 	End Method
 
 
 	Method Write:Long( buf:Byte Ptr,count:Long )
 	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
 	End Method
 
 
 	Method Close:Int()
 	Method Close:Int()
@@ -174,6 +174,8 @@ Type TSDLStreamFactory Extends TStreamFactory
 	
 	
 End Type
 End Type
 
 
+New TSDLStreamFactory
+
 Function _sdl_rwops_seek:Int(stream:TStream, pos:Long, whence:Int)
 Function _sdl_rwops_seek:Int(stream:TStream, pos:Long, whence:Int)
 	Return stream.seek(pos, whence)
 	Return stream.seek(pos, whence)
 End Function
 End Function
@@ -190,3 +192,81 @@ Function _sdl_rwops_close:Int(stream:TStream)
 	Return stream.close()
 	Return stream.close()
 End Function
 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