mirror of
				https://github.com/raylib-cs/raylib-cs
				synced 2025-10-31 06:04:58 -04:00 
			
		
		
		
	fix for dropfiles
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| // Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h | // Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h | ||||||
|  |  | ||||||
| using System; | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
| using System.IO; | using System.IO; | ||||||
| using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||||
|  |  | ||||||
| @@ -1192,7 +1193,43 @@ namespace Raylib | |||||||
|  |  | ||||||
|         // Get dropped files names |         // Get dropped files names | ||||||
|         [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] |         [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] | ||||||
|         public static extern string[] GetDroppedFiles(ref int count); | 		private static extern IntPtr GetDroppedFiles( ref int count); | ||||||
|  | 		// Get Dropped files Pointer translation | ||||||
|  | 		public static string[] GetDroppedFiles() | ||||||
|  | 		{ | ||||||
|  | 			int count = 0; | ||||||
|  | 			IntPtr pointer = GetDroppedFiles(ref count); | ||||||
|  |  | ||||||
|  | 			string[] s = new string[count]; | ||||||
|  | 			char[] word; | ||||||
|  | 			int i, j, size; | ||||||
|  |  | ||||||
|  | 			//TODO: this is a mess, find a better way | ||||||
|  | 			unsafe | ||||||
|  | 			{ | ||||||
|  | 				byte** str = (byte**)pointer.ToPointer(); | ||||||
|  |  | ||||||
|  | 				i = 0; | ||||||
|  | 				while (i < count) | ||||||
|  | 				{ | ||||||
|  | 					j = 0; | ||||||
|  | 					while (str[i][j] != 0) | ||||||
|  | 						j++; | ||||||
|  | 					size = j; | ||||||
|  | 					word = new char[size]; | ||||||
|  | 					j = 0; | ||||||
|  | 					while (str[i][j] != 0) | ||||||
|  | 					{ | ||||||
|  | 						word[j] = (char)str[i][j]; | ||||||
|  | 						j++; | ||||||
|  | 					} | ||||||
|  | 					s[i] = new string(word); | ||||||
|  |  | ||||||
|  | 					i++; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			return s; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|         // Clear dropped files paths buffer |         // Clear dropped files paths buffer | ||||||
|         [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] |         [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] | ||||||
|   | |||||||
| @@ -35,12 +35,14 @@ public partial class core_drop_files | |||||||
|         // Main game loop |         // Main game loop | ||||||
|         while (!WindowShouldClose())    // Detect window close button or ESC key |         while (!WindowShouldClose())    // Detect window close button or ESC key | ||||||
|         { |         { | ||||||
|             // Update | 			// Update | ||||||
|             //---------------------------------------------------------------------------------- | 			//---------------------------------------------------------------------------------- | ||||||
|             if (IsFileDropped()) | 			if (IsFileDropped()) | ||||||
|             { | 			{ | ||||||
|                 droppedFiles = GetDroppedFiles(ref count); | 				droppedFiles = GetDroppedFiles(); | ||||||
|             } | 				count = droppedFiles.Length; | ||||||
|  | 			} | ||||||
|  |              | ||||||
|             //---------------------------------------------------------------------------------- |             //---------------------------------------------------------------------------------- | ||||||
|  |  | ||||||
|             // Draw |             // Draw | ||||||
|   | |||||||
| @@ -105,9 +105,9 @@ public partial class models_material_pbr | |||||||
| 			// Send to material PBR shader camera view position | 			// Send to material PBR shader camera view position | ||||||
| 			float[] cameraPos = { camera.position.x, camera.position.y, camera.position.z }; | 			float[] cameraPos = { camera.position.x, camera.position.y, camera.position.z }; | ||||||
| 			SetShaderValue(model.material.shader, model.material.shader.locs[(int)ShaderLocationIndex.LOC_VECTOR_VIEW], cameraPos, 3); | 			SetShaderValue(model.material.shader, model.material.shader.locs[(int)ShaderLocationIndex.LOC_VECTOR_VIEW], cameraPos, 3); | ||||||
|  |  | ||||||
| 			//---------------------------------------------------------------------------------- | 			//---------------------------------------------------------------------------------- | ||||||
| 			// Draw | 			// Draw | ||||||
| 			//---------------------------------------------------------------------------------- | 			//---------------------------------------------------------------------------------- | ||||||
| 			BeginDrawing(); | 			BeginDrawing(); | ||||||
|  |  | ||||||
| @@ -138,7 +138,6 @@ public partial class models_material_pbr | |||||||
| 	 | 	 | ||||||
|  |  | ||||||
| 	// Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps) | 	// Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps) | ||||||
| 	// NOTE: PBR shader is loaded inside this function |  | ||||||
| 	// NOTE: PBR shader is loaded inside this function | 	// NOTE: PBR shader is loaded inside this function | ||||||
| 	unsafe public static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) | 	unsafe public static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) | ||||||
| 	{ | 	{ | ||||||
| @@ -152,7 +151,7 @@ public partial class models_material_pbr | |||||||
| 		// Get required locations points for PBR material | 		// Get required locations points for PBR material | ||||||
| 		// NOTE: Those location names must be available and used in the shader code | 		// NOTE: Those location names must be available and used in the shader code | ||||||
| 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler"); | 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler"); | ||||||
| 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler"); | 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler"); | ||||||
| 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler"); | 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler"); | ||||||
| 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler"); | 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler"); | ||||||
| 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); | 		mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); | ||||||
|   | |||||||
| @@ -32,20 +32,20 @@ public partial class models_mesh_picking | |||||||
|  |  | ||||||
|         // Define the camera to look into our 3d world |         // Define the camera to look into our 3d world | ||||||
|         Camera3D camera; |         Camera3D camera; | ||||||
|         camera.position = new Vector3( 20.0f, 20.0f, 20.0f );  // Camera3D position |         camera.position = new Vector3( 20.0f, 20.0f, 20.0f );	// Camera3D position | ||||||
|         camera.target = new Vector3( 0.0f, 8.0f, 0.0f );      // Camera3D looking at point |         camera.target = new Vector3( 0.0f, 8.0f, 0.0f );		// Camera3D looking at point | ||||||
|         camera.up = new Vector3( 0.0f, 1.6f, 0.0f );          // Camera3D up vector (rotation towards target) |         camera.up = new Vector3( 0.0f, 1.6f, 0.0f );			// Camera3D up vector (rotation towards target) | ||||||
|         camera.fovy = 45.0f;                                // Camera3D field-of-view Y |         camera.fovy = 45.0f;									// Camera3D field-of-view Y | ||||||
|         camera.type = CAMERA_PERSPECTIVE;                   // Camera3D mode type |         camera.type = CAMERA_PERSPECTIVE;						// Camera3D mode type | ||||||
|  |  | ||||||
|         Ray ray;        // Picking ray |         Ray ray;        // Picking ray | ||||||
|  |  | ||||||
|         Model tower = LoadModel("resources/models/turret.obj");                 // Load OBJ model |         Model tower = LoadModel("resources/models/turret.obj");						// Load OBJ model | ||||||
|         Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture |         Texture2D texture = LoadTexture("resources/models/turret_diffuse.png");		// Load model texture | ||||||
|         tower.material.maps[(int)MAP_ALBEDO].texture = texture;                     // Set model diffuse texture |         tower.material.maps[(int)MAP_ALBEDO].texture = texture;                     // Set model diffuse texture | ||||||
|  |  | ||||||
|         Vector3 towerPos = new Vector3( 0.0f, 0.0f, 0.0f );                    // Set model position |         Vector3 towerPos = new Vector3( 0.0f, 0.0f, 0.0f );		// Set model position | ||||||
|         BoundingBox towerBBox = MeshBoundingBox(tower.mesh);        // Get mesh bounding box |         BoundingBox towerBBox = MeshBoundingBox(tower.mesh);	// Get mesh bounding box | ||||||
|         bool hitMeshBBox = false; |         bool hitMeshBBox = false; | ||||||
|         bool hitTriangle = false; |         bool hitTriangle = false; | ||||||
|  |  | ||||||
| @@ -59,13 +59,16 @@ public partial class models_mesh_picking | |||||||
|         SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode |         SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode | ||||||
|  |  | ||||||
|         SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second |         SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second | ||||||
|         //-------------------------------------------------------------------------------------- |  | ||||||
|         // Main game loop | 		//---------------------------------------------------------------------------------- | ||||||
|         while (!WindowShouldClose())        // Detect window close button or ESC key | 		// Main game loop | ||||||
|  | 		//-------------------------------------------------------------------------------------- | ||||||
|  | 		while (!WindowShouldClose())        // Detect window close button or ESC key | ||||||
|         { |         { | ||||||
|             // Update | 			//---------------------------------------------------------------------------------- | ||||||
|             //---------------------------------------------------------------------------------- | 			// Update | ||||||
|             UpdateCamera(ref camera);          // Update camera | 			//---------------------------------------------------------------------------------- | ||||||
|  | 			UpdateCamera(ref camera);          // Update camera | ||||||
|  |  | ||||||
|             // Display information about closest hit |             // Display information about closest hit | ||||||
|             RayHitInfo nearestHit = new RayHitInfo(); |             RayHitInfo nearestHit = new RayHitInfo(); | ||||||
| @@ -121,7 +124,6 @@ public partial class models_mesh_picking | |||||||
|  |  | ||||||
|             } hitMeshBBox = false; |             } hitMeshBBox = false; | ||||||
|             //---------------------------------------------------------------------------------- |             //---------------------------------------------------------------------------------- | ||||||
|  |  | ||||||
|             // Draw |             // Draw | ||||||
|             //---------------------------------------------------------------------------------- |             //---------------------------------------------------------------------------------- | ||||||
|             BeginDrawing(); |             BeginDrawing(); | ||||||
|   | |||||||
| @@ -44,8 +44,7 @@ public partial class text_ttf_loading | |||||||
|         int currentFontFilter = 0;      // FILTER_POINT |         int currentFontFilter = 0;      // FILTER_POINT | ||||||
|  |  | ||||||
|         // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX |         // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX | ||||||
|         int count = 0; | 		string[] droppedFiles; | ||||||
|         string[] droppedFiles; |  | ||||||
|  |  | ||||||
|         SetTargetFPS(60); |         SetTargetFPS(60); | ||||||
|         //-------------------------------------------------------------------------------------- |         //-------------------------------------------------------------------------------------- | ||||||
| @@ -83,12 +82,13 @@ public partial class text_ttf_loading | |||||||
|             // Load a dropped TTF file dynamically (at current fontSize) |             // Load a dropped TTF file dynamically (at current fontSize) | ||||||
|             if (IsFileDropped()) |             if (IsFileDropped()) | ||||||
|             { |             { | ||||||
|                 droppedFiles = GetDroppedFiles(ref count); |                 droppedFiles = GetDroppedFiles(); | ||||||
|  | 				 | ||||||
|  |  | ||||||
|                 if (count == 1) // Only support one ttf file dropped |                 if (droppedFiles.Length == 1) // Only support one ttf file dropped | ||||||
|                 { |                 { | ||||||
|                     UnloadFont(font); |                     UnloadFont(font); | ||||||
|                     font = LoadFontEx(droppedFiles[0], (int)fontSize, 0, null); |                     font = LoadFontEx(droppedFiles[0].ToString(), (int)fontSize, 0, null); | ||||||
|                     ClearDroppedFiles(); |                     ClearDroppedFiles(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -108,11 +108,12 @@ public partial class text_ttf_loading | |||||||
|                 DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK); |                 DrawTextEx(font, msg, fontPosition, fontSize, 0, BLACK); | ||||||
|  |  | ||||||
|                 // TODO: It seems texSize measurement is not accurate due to chars offsets... |                 // TODO: It seems texSize measurement is not accurate due to chars offsets... | ||||||
|  | 				//TODO also fix the format text parts | ||||||
|                 //DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED); |                 //DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED); | ||||||
|  |  | ||||||
|                 DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY); |                 DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY); | ||||||
|                 DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY); |                // DrawText(FormatText("Font size: %02.02f", fontSize), 20, screenHeight - 50, 10, DARKGRAY); | ||||||
|                 DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY); |                // DrawText(FormatText("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY); | ||||||
|                 DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY); |                 DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY); | ||||||
|  |  | ||||||
|                 if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK); |                 if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user