Merging
Added new extension "byte.Lerp". Added new extension "Log" for "TraceLogLevel". Constructors on Color no longer just truncate the float value, but also round it (+ 0.5f). New static method on Color, "Color.Lerp". Added static method "FromHSV" to Color. Added new getter method "GetHSV" on Color. Added index security on the FilePathList indexer. Merged Rectangle extensions with the type itself as read-only methods. Merged Image extensions with the type itself. Merged Texture2D extensions with the type itself. New file "Raymath.Utils" with some useful methods taken from Unity. Added "MoveTowards" extensions to RaylibExtensions. Added "TranslateLocal" and "TranslateGlobal" to Transform. Added "Load", "Export", "ExportAsCode", "Format", "Crop", and "Unload" shortcut methods to Wave. Added "IsValid" property to Wave, Texture2D, Sound, Shader, RenderTexture2D, Music, Image, Model, Material, Font, and AudioStream. Added "IsPlaying" and "IsProcessed" properties to AudioStream. Added "Load", "Play", "Stop", "Pause", "Resume", "SetBufferSizeDefault", "SetPan", "SetPitch", "SetVolume", and "Unload" shortcut methods to AudioStream. Added "Load", "Export", and "Unload" methods to AutomationEventList. Added "Default" property to Font. Added "Load", "GetMaterial", "GetTexture", "SetTexture", "SetShader", and "Unload" methods to material. Added "Draw", "DrawInstanced", "Export", "ExportAsCode", "Upload", and "Unload" methods to Mesh. Added "Load", "LoadFromMesh", "Unload", and a lot of "Draw" overloads. Added "Load", "Play", "Pause", "Stop", "SetPan", "SetPitch", "SetVolume", "Seek", and "Unload" methods to Music. Added "Load" and "Unload" methods to RenderTexture2D. Added "Load", "LoadFromMemory", "GetLocationAttrib", "SetValue", "SetTexture", "SetMatrix", and "Unload" methods to Shader. Removed unnecessary "partial" declarations.
This commit is contained in:
parent
9811c0d129
commit
b84a0d4f12
31 changed files with 1090 additions and 395 deletions
|
|
@ -1,367 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
using static Raylib_cs.Raylib;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Raylib_cs;
|
||||
|
||||
public static class RaylibExtensions
|
||||
{
|
||||
#region Rectangle
|
||||
|
||||
public static void Draw(this Rectangle rectangle, Color color)
|
||||
{
|
||||
DrawRectangleRec(rectangle, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Rectangle rec, Vector2 origin, Color color)
|
||||
{
|
||||
rec.Draw(origin, 0.0f, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Rectangle rec, Vector2 origin, float rotation, Color color)
|
||||
{
|
||||
DrawRectanglePro(rec, origin, rotation, color);
|
||||
}
|
||||
|
||||
public static void GetIntegerPosition(this Rectangle rec, out int x, out int y)
|
||||
{
|
||||
x = (int)rec.X;
|
||||
y = (int)rec.Y;
|
||||
}
|
||||
|
||||
public static void GetIntegerDimentions(this Rectangle rec, out int width, out int height)
|
||||
{
|
||||
width = (int)rec.Width;
|
||||
height = (int)rec.Height;
|
||||
}
|
||||
|
||||
public static void GetIntegerValues(this Rectangle rec, out int x, out int y, out int width, out int height)
|
||||
{
|
||||
x = (int)rec.X;
|
||||
y = (int)rec.Y;
|
||||
width = (int)rec.Width;
|
||||
height = (int)rec.Height;
|
||||
}
|
||||
|
||||
public static void DrawLines(this Rectangle rectangle, Color color)
|
||||
{
|
||||
rectangle.GetIntegerValues(out int x, out int y, out int w, out int h);
|
||||
DrawRectangleLines(x, y, w, h, color);
|
||||
}
|
||||
|
||||
public static void DrawLines(this Rectangle rectangle, float thickness, Color color)
|
||||
{
|
||||
DrawRectangleLinesEx(rectangle, thickness, color);
|
||||
}
|
||||
|
||||
public static void DrawGradient(this Rectangle rec, Color topLeft, Color bottomLeft, Color topRight, Color bottomRight)
|
||||
{
|
||||
DrawRectangleGradientEx(rec, topLeft, bottomLeft, topRight, bottomRight);
|
||||
}
|
||||
|
||||
public static void DrawGradientV(this Rectangle rectangle, Color top, Color bottom)
|
||||
{
|
||||
rectangle.GetIntegerValues(out int x, out int y, out int w, out int h);
|
||||
DrawRectangleGradientV(x, y, w, h, top, bottom);
|
||||
}
|
||||
|
||||
public static void DrawGradientH(this Rectangle rec, Color left, Color right)
|
||||
{
|
||||
rec.GetIntegerValues(out int x, out int y, out int w, out int h);
|
||||
DrawRectangleGradientH(x, y, w, h, left, right);
|
||||
}
|
||||
|
||||
public static void DrawRounded(this Rectangle rec, float roundness, Color color)
|
||||
{
|
||||
DrawRectangleRounded(rec, roundness, 10, color);
|
||||
}
|
||||
|
||||
public static void DrawRounded(this Rectangle rec, float roundness, int segments, Color color)
|
||||
{
|
||||
DrawRectangleRounded(rec, roundness, segments, color);
|
||||
}
|
||||
|
||||
public static void DrawRoundedLines(this Rectangle rec, float roundness, Color color)
|
||||
{
|
||||
DrawRectangleRoundedLines(rec, roundness, 10, color);
|
||||
}
|
||||
|
||||
public static void DrawRoundedLines(this Rectangle rec, float roundness, int segments, Color color)
|
||||
{
|
||||
DrawRectangleRoundedLines(rec, roundness, segments, color);
|
||||
}
|
||||
|
||||
public static void DrawRoundedLines(this Rectangle rec, float roundness, float thickness, Color color)
|
||||
{
|
||||
DrawRectangleRoundedLinesEx(rec, roundness, 10, thickness, color);
|
||||
}
|
||||
|
||||
public static void DrawRoundedLines(this Rectangle rec, float roundness, int segments, float thickness, Color color)
|
||||
{
|
||||
DrawRectangleRoundedLinesEx(rec, roundness, segments, thickness, color);
|
||||
}
|
||||
|
||||
public static CBool CheckCollision(this Rectangle rec, Rectangle rectangle)
|
||||
{
|
||||
return CheckCollisionRecs(rec, rectangle);
|
||||
}
|
||||
|
||||
public static CBool CheckCollision(this Rectangle rec, Vector2 point)
|
||||
{
|
||||
return CheckCollisionPointRec(point, rec);
|
||||
}
|
||||
|
||||
public static CBool CheckCircleCollision(this Rectangle rec, Vector2 center, float radius)
|
||||
{
|
||||
return CheckCollisionCircleRec(center, radius, rec);
|
||||
}
|
||||
|
||||
public static CBool CheckColllisionCircle(this Rectangle rec, Vector2 position, float radius)
|
||||
{
|
||||
return CheckCollisionCircleRec(position, radius, rec);
|
||||
}
|
||||
|
||||
public static Rectangle GetCollisionRectangle(this Rectangle rectangle, Rectangle rectangle2)
|
||||
{
|
||||
return GetCollisionRec(rectangle, rectangle2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void DrawLines(this IEnumerable<Vector2> points, Color color)
|
||||
{
|
||||
Vector2[] pointArray = System.Linq.Enumerable.ToArray<Vector2>(points);
|
||||
DrawLineStrip(pointArray, pointArray.Length, color);
|
||||
Raylib.DrawLineStrip(pointArray, pointArray.Length, color);
|
||||
}
|
||||
|
||||
#region Image
|
||||
|
||||
public static void Load(this ref Image image, string fileName)
|
||||
public static void Log(this TraceLogLevel logLevel, string message)
|
||||
{
|
||||
image = LoadImage(fileName);
|
||||
Raylib.TraceLog(logLevel, message);
|
||||
}
|
||||
|
||||
public static void Load(this ref Image image, string fileType, byte[] data)
|
||||
public static byte Lerp(this byte a, byte b, float t)
|
||||
{
|
||||
image = LoadImageFromMemory(fileType, data);
|
||||
return (byte)(a + (b - a) * t);
|
||||
}
|
||||
|
||||
public static void Load(this ref Image image, Texture2D texture)
|
||||
{
|
||||
image = LoadImageFromTexture(texture);
|
||||
}
|
||||
|
||||
public static void Load(this ref Image image, string fileName, int width, int height, PixelFormat format, int headerSize)
|
||||
{
|
||||
image = LoadImageRaw(fileName, width, height, format, headerSize);
|
||||
}
|
||||
|
||||
public static void Unload(this Image image)
|
||||
{
|
||||
UnloadImage(image);
|
||||
}
|
||||
|
||||
public static unsafe Color[] GetPalette(this Image image, int maxPaletteSize)
|
||||
{
|
||||
int colorCount = 0;
|
||||
Color* colors = LoadImagePalette(image, maxPaletteSize, &colorCount);
|
||||
Color[] palette = new Color[colorCount];
|
||||
for (int i = 0; i < colorCount; i++)
|
||||
{
|
||||
palette[i] = colors[i];
|
||||
}
|
||||
UnloadImagePalette(colors);
|
||||
return palette;
|
||||
}
|
||||
|
||||
public static void LoadFromScreen(this ref Image image)
|
||||
{
|
||||
image = LoadImageFromScreen();
|
||||
}
|
||||
|
||||
public static void DrawLine(this ref Image image, Vector2 start, Vector2 end, Color color)
|
||||
{
|
||||
ImageDrawLineV(ref image, start, end, color);
|
||||
}
|
||||
|
||||
public static void DrawLine(this ref Image image, Vector2 start, Vector2 end, int thickness, Color color)
|
||||
{
|
||||
ImageDrawLineEx(ref image, start, end, thickness, color);
|
||||
}
|
||||
|
||||
public static void DrawCircle(this ref Image image, Vector2 position, float radius, Color color)
|
||||
{
|
||||
ImageDrawCircle(ref image, (int)position.X, (int)position.Y, (int)radius, color);
|
||||
}
|
||||
|
||||
public static void Draw(this ref Image image, Rectangle rectangle, Color color)
|
||||
{
|
||||
ImageDrawRectangleRec(ref image, rectangle, color);
|
||||
}
|
||||
|
||||
public static void Draw(this ref Image image, string text, Vector2 position, int fontSize, Color color)
|
||||
{
|
||||
ImageDrawText(ref image, text, (int)position.X, (int)position.Y, fontSize, color);
|
||||
}
|
||||
|
||||
public static void Draw(this ref Image image, Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
|
||||
{
|
||||
ImageDrawTextEx(ref image, font, text, position, fontSize, spacing, color);
|
||||
}
|
||||
|
||||
public static unsafe void DrawCircleLines(this ref Image image, Vector2 position, float radius, Color color)
|
||||
{
|
||||
ImageDrawCircleLinesV(ref image, position, (int)radius, color);
|
||||
}
|
||||
|
||||
public static void DrawTriangle(this ref Image image, Vector2 p1, Vector2 p2, Vector2 p3, Color color)
|
||||
{
|
||||
ImageDrawTriangle(ref image, p1, p2, p3, color);
|
||||
}
|
||||
|
||||
public static void DrawTriangle(this ref Image image, Vector2 p1, Vector2 p2, Vector2 p3, Color c1, Color c2, Color c3)
|
||||
{
|
||||
ImageDrawTriangleEx(ref image, p1, p2, p3, c1, c2, c3);
|
||||
}
|
||||
|
||||
public static void DrawLines(this ref Image image, Rectangle rectangle, Color color)
|
||||
{
|
||||
ImageDrawRectangleLines(ref image, rectangle, 1, color);
|
||||
}
|
||||
|
||||
public static void DrawLines(this ref Image image, Rectangle rectangle, int thickness, Color color)
|
||||
{
|
||||
ImageDrawRectangleLines(ref image, rectangle, thickness, color);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Texture2D
|
||||
|
||||
public static void Load(this ref Texture2D texture, string fileName)
|
||||
{
|
||||
texture = LoadTexture(fileName);
|
||||
}
|
||||
|
||||
public static void Load(this ref Texture2D texture, Image image)
|
||||
{
|
||||
texture = LoadTextureFromImage(image);
|
||||
}
|
||||
|
||||
public static void Load(this ref Texture2D texture, string fileType, byte[] fileData)
|
||||
{
|
||||
Image img = LoadImageFromMemory(fileType, fileData);
|
||||
texture.Load(img);
|
||||
UnloadImage(img);
|
||||
}
|
||||
|
||||
public static void Unload(this Texture2D texture)
|
||||
{
|
||||
UnloadTexture(texture);
|
||||
}
|
||||
|
||||
public static void SetFilter(this Texture2D texture, TextureFilter filter)
|
||||
{
|
||||
SetTextureFilter(texture, filter);
|
||||
}
|
||||
|
||||
public static void SetWrap(this Texture2D texture, TextureWrap wrap)
|
||||
{
|
||||
SetTextureWrap(texture, wrap);
|
||||
}
|
||||
|
||||
public static void Update<T>(this Texture2D texture, T[] pixels) where T : unmanaged
|
||||
{
|
||||
UpdateTexture(texture, pixels);
|
||||
}
|
||||
|
||||
public static Rectangle GetSourceRectangle(this Texture2D texture)
|
||||
{
|
||||
return new Rectangle(Vector2.Zero, texture.Width, texture.Height);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, int x, int y)
|
||||
{
|
||||
DrawTexture(texture, x, y, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, int x, int y, Color color)
|
||||
{
|
||||
DrawTexture(texture, x, y, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position)
|
||||
{
|
||||
DrawTexture(texture, (int)position.X, (int)position.Y, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, Vector2 origin)
|
||||
{
|
||||
Vector2 size = texture.Dimensions;
|
||||
Rectangle source = new Rectangle(Vector2.Zero, size);
|
||||
Rectangle target = new Rectangle(position, size);
|
||||
DrawTexturePro(texture, source, target, origin, 0, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, Vector2 origin, Color color)
|
||||
{
|
||||
Vector2 size = texture.Dimensions;
|
||||
Rectangle source = new Rectangle(Vector2.Zero, size);
|
||||
Rectangle target = new Rectangle(position, size);
|
||||
DrawTexturePro(texture, source, target, origin, 0, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, Color color)
|
||||
{
|
||||
DrawTexture(texture, (int)position.X, (int)position.Y, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, float rotation, float scale)
|
||||
{
|
||||
DrawTextureEx(texture, position, rotation, scale, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, float rotation, float scale, Color color)
|
||||
{
|
||||
DrawTextureEx(texture, position, rotation, scale, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, float rotation, Vector2 scale)
|
||||
{
|
||||
Draw(texture, position, rotation, scale, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Vector2 position, float rotation, Vector2 scale, Color color)
|
||||
{
|
||||
Vector2 size = new Vector2(texture.Width, texture.Height);
|
||||
Rectangle source = new Rectangle(Vector2.Zero, size);
|
||||
Rectangle target = new Rectangle(position, size);
|
||||
target.Size *= scale;
|
||||
DrawTexturePro(texture, source, target, Vector2.Zero, rotation, color);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest)
|
||||
{
|
||||
DrawTexturePro(texture, source, dest, Vector2.Zero, 0, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin)
|
||||
{
|
||||
DrawTexturePro(texture, source, dest, origin, 0, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation)
|
||||
{
|
||||
DrawTexturePro(texture, source, dest, origin, rotation, Color.White);
|
||||
}
|
||||
|
||||
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color color)
|
||||
{
|
||||
DrawTexturePro(texture, source, dest, origin, rotation, color);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Vector
|
||||
|
||||
public static void Normalize(this ref Vector2 vector)
|
||||
|
|
@ -414,5 +73,15 @@ public static class RaylibExtensions
|
|||
return Raymath.Vector3Lerp(v1, v2, amount);
|
||||
}
|
||||
|
||||
public static Vector2 MoveTowards(this Vector2 v1, Vector2 v2, float t)
|
||||
{
|
||||
return Raymath.Vector2MoveTowards(v1, v2, t);
|
||||
}
|
||||
|
||||
public static Vector3 MoveTowards(this Vector3 v1, Vector3 v2, float t)
|
||||
{
|
||||
return Raymath.Vector3MoveTowards(v1, v2, t);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,12 +37,9 @@ public static unsafe partial class Raymath
|
|||
|
||||
/// <summary>Remap input value within input range to output range</summary>
|
||||
[DllImport(NativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern float Remap(
|
||||
float value,
|
||||
float inputStart,
|
||||
float inputEnd,
|
||||
float outputStart,
|
||||
float outputEnd
|
||||
public static extern float Remap(float value,
|
||||
float inputStart, float inputEnd,
|
||||
float outputStart, float outputEnd
|
||||
);
|
||||
|
||||
/// <summary>Wrap input value from min to max</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue