mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-06-30 19:03:42 -04:00
4.0 (#100)
* Fix formatting/update doc comments in Raylib.cs * Update types in Raylib.cs to 4.0 * Remove app.config * Update Raylib.cs functions * Split Enums, Structs & Classes into own files * Testing utils for Raylib.cs * Update Raylib-cs.csproj * Reorganize types - Move into types folder - Group types based on usage * Fix parameter names * Rename CloseAudioStream to UnloadAudioStream * Remove ref SetShaderValue overloads * Remove some constants from Raylib.cs * Include README.md in package * Replace old version of GetDroppedUtils * Update README.md * Remove Physac-cs and Raygui-cs - Not actively maintained and a pain for users to setup... * Update comments to xmldoc * Rename Gestures enum to Gesture * Minor fixes - Rename Gestures enum to Gesture - Update tests to net6.0 * Testing CBool type instead of bool * Update XmlDoc comments * Update build.yml to net6.0 for tests * Remove Easings.cs - Easings used to be part of raylib. It is now a separate extra library so I am removing it from the main bindings. * Update rlgl * More XmlDoc comments * Use CBool in structs * Big unsafe update * Fix typos and change refs to pointers in Rlgl * Update LoggingUtils and Material * Fix typo in Rlgl * Update build.yml * Rename RaylibUtils.cs to Raylib.Utils now a partial class * Convert some RLGL consts to Enums Also added helper methods/overloads for related methods * Make class Raylib partial * Convert some text functions to not use ref I dont think they will work. need testing * Testing fixes for Text functions * Create rlMultMatrixf safe overload * Implement safe ModelAnimation * Testing fix for ModelAnimation using wrapper struct * Added TODOs * Fix rlMultMatrixf - Add missing ToFloatV functions to Raymath - Fix rlMultMatrixf overload to use MatrixToFloatV * Fix IsGestureDetected and formatting * Add a few text tests * Move wrapper functions into Raylib.Utils * Remove ref from raylib bindings * Multi-target net5.0 * Testing string approaches * Fixing more util and unsafe functions * Testing TraceLogCallback fix Set lang version to C# 10 * Replace managed callbacks with unsafe delegates * Update default LogConsole callback * Setup unsafe/safe functions for math types in Raylib.cs * Replace string in Rlgl with sbyte* * Yet more string changes - Use sbyte/byte correctly in Raylib.cs - Using Marshal.StringToCoTaskMemUTF8 - Update utils string usage * Fix typo bug and whitespace * Fix DrawTextPro and more whitespace * Remove unused ToString * Add file functions back into Raylib * Test paths filter for pull requests * Change to paths-ignore filter * Redo partial change * Move binding functions into interop folder Co-authored-by: Ben Parsons <9parsonsb@gmail.com>
This commit is contained in:
31
Raylib-cs/types/native/CBool.cs
Normal file
31
Raylib-cs/types/native/CBool.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly struct CBool
|
||||
{
|
||||
private readonly byte value;
|
||||
|
||||
private CBool(bool value)
|
||||
{
|
||||
this.value = Convert.ToByte(value);
|
||||
}
|
||||
|
||||
public static implicit operator CBool(bool value)
|
||||
{
|
||||
return new CBool(value);
|
||||
}
|
||||
|
||||
public static implicit operator bool(CBool x)
|
||||
{
|
||||
return Convert.ToBoolean(x.value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Convert.ToBoolean(value).ToString();
|
||||
}
|
||||
}
|
||||
}
|
64
Raylib-cs/types/native/UTF8Buffer.cs
Normal file
64
Raylib-cs/types/native/UTF8Buffer.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts text to a UTF8 buffer for passing to native code.<br/>
|
||||
/// Uses ArrayPool to reduce memory allocation.
|
||||
/// </summary>
|
||||
public ref struct UTF8Buffer
|
||||
{
|
||||
private IntPtr data;
|
||||
|
||||
public UTF8Buffer(string text)
|
||||
{
|
||||
data = Marshal.StringToCoTaskMemUTF8(text);
|
||||
}
|
||||
|
||||
public unsafe sbyte* AsPointer()
|
||||
{
|
||||
return (sbyte*)data.ToPointer();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Utf8StringUtils
|
||||
{
|
||||
public static UTF8Buffer ToUTF8Buffer(this string text)
|
||||
{
|
||||
return new UTF8Buffer(text);
|
||||
}
|
||||
|
||||
public static byte[] ToUtf8String(this string text)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var length = Encoding.UTF8.GetByteCount(text);
|
||||
|
||||
var byteArray = new byte[length + 1];
|
||||
var wrote = Encoding.UTF8.GetBytes(text, 0, text.Length, byteArray, 0);
|
||||
byteArray[wrote] = 0;
|
||||
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
public static unsafe string GetUTF8String(sbyte* bytes)
|
||||
{
|
||||
return Marshal.PtrToStringUTF8((IntPtr)bytes);
|
||||
}
|
||||
|
||||
public static byte[] GetUTF8Bytes(this string text)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(text);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user