* chg: New build system that uses the officially distributed binaries, bumped version to 8.0.0, simplified git workflow, removed deprecated OpenGL 1.1 functionality. * chg: Modernize CI workflow, enable SourceLink - Bump workflow actions to latest majors (Node 24); drop deprecated softprops/action-gh-release@v1 - Trigger push builds on main instead of master - Create local nuget feed dir before pack (fixes NU1301) - Enable Microsoft.SourceLink.GitHub for debugging symbols (ref PR #340) * fix: centralized version data in Directory.build.props, and fixed various interop details that had incorrect function signatures * chore: updated readme * fix: version the native extract marker and chain download via DependsOnTargets The .extracted marker now includes the raylib package name, so bumping TargetRaylibTag re-extracts the new archive instead of silently keeping (and packing/copying) the previous version's files. _PrepareNativeLibrary and _StageWasmNative now depend directly on _DownloadAndExtractInternal instead of CallTarget-ing it; dependency targets run in the same project instance, so the resolved properties (RaylibPackageName etc.) propagate naturally. * fix: let the binding build for browser-wasm on both net8.0 and net10.0 The net8-era wasm workload (Microsoft.NET.Runtime.WebAssembly.Sdk 8.0.x, auto-imported for RID browser-wasm) treats every browser-wasm project as a wasm app: it forces OutputType=Exe after project evaluation (CS5001 for a classlib) and hooks its app-bundle build after Build, which errors because a library has no assemblies to bundle. Opt Raylib-cs out via DisableAutoWasmBuildApp (props time, before the workload defaults its trigger) and pin OutputType back to Library in Directory.Build.targets (evaluated after the workload props, so the assignment wins). net10's wasm SDK needs neither workaround. * chore: readme updated * chg: simplifying build logic - a simple line in the documentation should save us the code here * fix: Wrong signature of FrameBufferComplete * chore: readme update * feat: samples default to local project reference, and can optionally use the nuget package * feat: backporting existing raylib-cs examples and new official raylib examples to WASM, adopting raylib's original code style * chore: readme, gitignore, and targets backport. * fix: Examples.csproj runs the download task when building locally * feat: backporting existing raylib-cs examples and new official raylib examples to WASM, adopting raylib's original code style * chore: readme, gitignore, and targets backport. * chore: clean up linter warnings * feat: html harness focuses the example and allows quick navigation with J/K instead. * chore: readme mentions the property to use nuget vs. the local project reference * feat: replaced the J/K navigation with good old HTML buttons * chore: run dotnet format scoped default (was previously scoped to just 'style')
180 lines
6.3 KiB
C#
180 lines
6.3 KiB
C#
/*******************************************************************************************
|
|
*
|
|
* raylib [textures] example - npatch drawing
|
|
*
|
|
* Example complexity rating: [★★★☆] 3/4
|
|
*
|
|
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
|
*
|
|
* Example originally created with raylib 2.0, last time updated with raylib 2.5
|
|
*
|
|
* Example contributed by Jorge A. Gomes (@overdev) and reviewed by Ramon Santamaria (@raysan5)
|
|
*
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
* BSD-like license that allows static linking with closed source software
|
|
*
|
|
* Copyright (c) 2018-2025 Jorge A. Gomes (@overdev) and Ramon Santamaria (@raysan5)
|
|
*
|
|
********************************************************************************************/
|
|
|
|
namespace Examples.Textures;
|
|
|
|
public partial class NpatchDrawing : IExample
|
|
{
|
|
private const int screenWidth = 800;
|
|
private const int screenHeight = 450;
|
|
|
|
public string Name => "Textures / N-patch Drawing";
|
|
|
|
public string Title => "raylib [textures] example - npatch drawing";
|
|
|
|
private Texture2D nPatchTexture;
|
|
|
|
private Vector2 mousePosition;
|
|
private Vector2 origin;
|
|
|
|
private Rectangle dstRec1;
|
|
private Rectangle dstRec2;
|
|
private Rectangle dstRecH;
|
|
private Rectangle dstRecV;
|
|
|
|
private NPatchInfo ninePatchInfo1;
|
|
private NPatchInfo ninePatchInfo2;
|
|
private NPatchInfo h3PatchInfo;
|
|
private NPatchInfo v3PatchInfo;
|
|
|
|
public void Init()
|
|
{
|
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
|
nPatchTexture = LoadTexture("resources/ninepatch_button.png");
|
|
|
|
mousePosition = new(0.0f, 0.0f);
|
|
origin = new(0.0f, 0.0f);
|
|
|
|
// Position and size of the n-patches
|
|
dstRec1 = new(480.0f, 160.0f, 32.0f, 32.0f);
|
|
dstRec2 = new(160.0f, 160.0f, 32.0f, 32.0f);
|
|
dstRecH = new(160.0f, 93.0f, 32.0f, 32.0f);
|
|
dstRecV = new(92.0f, 160.0f, 32.0f, 32.0f);
|
|
|
|
// A 9-patch (NPATCH_NINE_PATCH) changes its sizes in both axis
|
|
ninePatchInfo1 = new NPatchInfo
|
|
{
|
|
Source = new Rectangle(0.0f, 0.0f, 64.0f, 64.0f),
|
|
Left = 12,
|
|
Top = 40,
|
|
Right = 12,
|
|
Bottom = 12,
|
|
Layout = NPatchLayout.NinePatch
|
|
};
|
|
ninePatchInfo2 = new NPatchInfo
|
|
{
|
|
Source = new Rectangle(0.0f, 128.0f, 64.0f, 64.0f),
|
|
Left = 16,
|
|
Top = 16,
|
|
Right = 16,
|
|
Bottom = 16,
|
|
Layout = NPatchLayout.NinePatch
|
|
};
|
|
|
|
// A horizontal 3-patch (NPATCH_THREE_PATCH_HORIZONTAL) changes its sizes along the x axis only
|
|
h3PatchInfo = new NPatchInfo
|
|
{
|
|
Source = new Rectangle(0.0f, 64.0f, 64.0f, 64.0f),
|
|
Left = 8,
|
|
Top = 8,
|
|
Right = 8,
|
|
Bottom = 8,
|
|
Layout = NPatchLayout.ThreePatchHorizontal
|
|
};
|
|
|
|
// A vertical 3-patch (NPATCH_THREE_PATCH_VERTICAL) changes its sizes along the y axis only
|
|
v3PatchInfo = new NPatchInfo
|
|
{
|
|
Source = new Rectangle(0.0f, 192.0f, 64.0f, 64.0f),
|
|
Left = 6,
|
|
Top = 6,
|
|
Right = 6,
|
|
Bottom = 6,
|
|
Layout = NPatchLayout.ThreePatchVertical
|
|
};
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
// Update
|
|
//----------------------------------------------------------------------------------
|
|
mousePosition = GetMousePosition();
|
|
|
|
// Resize the n-patches based on mouse position
|
|
dstRec1.Width = mousePosition.X - dstRec1.X;
|
|
dstRec1.Height = mousePosition.Y - dstRec1.Y;
|
|
dstRec2.Width = mousePosition.X - dstRec2.X;
|
|
dstRec2.Height = mousePosition.Y - dstRec2.Y;
|
|
dstRecH.Width = mousePosition.X - dstRecH.X;
|
|
dstRecV.Height = mousePosition.Y - dstRecV.Y;
|
|
|
|
// Set a minimum width and/or height
|
|
dstRec1.Width = Math.Clamp(dstRec1.Width, 1.0f, 300.0f);
|
|
dstRec1.Height = MathF.Max(dstRec1.Height, 1.0f);
|
|
dstRec2.Width = Math.Clamp(dstRec2.Width, 1.0f, 300.0f);
|
|
dstRec2.Height = MathF.Max(dstRec2.Height, 1.0f);
|
|
dstRecH.Width = MathF.Max(dstRecH.Width, 1.0f);
|
|
dstRecV.Height = MathF.Max(dstRecV.Height, 1.0f);
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Draw
|
|
//----------------------------------------------------------------------------------
|
|
BeginDrawing();
|
|
ClearBackground(Color.RayWhite);
|
|
|
|
// Draw the n-patches
|
|
DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, Color.White);
|
|
DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, Color.White);
|
|
DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, Color.White);
|
|
DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, Color.White);
|
|
|
|
// Draw the source texture
|
|
DrawRectangleLines(5, 88, 74, 266, Color.Blue);
|
|
DrawTexture(nPatchTexture, 10, 93, Color.White);
|
|
DrawText("TEXTURE", 15, 360, 10, Color.DarkGray);
|
|
|
|
DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, Color.DarkGray);
|
|
|
|
EndDrawing();
|
|
//----------------------------------------------------------------------------------
|
|
}
|
|
|
|
public void Unload()
|
|
{
|
|
UnloadTexture(nPatchTexture); // Texture unloading
|
|
}
|
|
|
|
public static int Main()
|
|
{
|
|
// Initialization
|
|
//--------------------------------------------------------------------------------------
|
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - npatch drawing");
|
|
|
|
SetTargetFPS(60);
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
var game = new NpatchDrawing();
|
|
game.Init();
|
|
|
|
// Main game loop
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
{
|
|
game.Update();
|
|
}
|
|
|
|
game.Unload();
|
|
|
|
// De-Initialization
|
|
//--------------------------------------------------------------------------------------
|
|
CloseWindow(); // Close window and OpenGL context
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
return 0;
|
|
}
|
|
}
|