From 635c63d7cc3345d74e3f0e9a16c1a137563a3ad1 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Wed, 8 Nov 2023 19:34:50 +0100 Subject: [PATCH] Add new shapes functions --- raylib/cgo.go | 2 +- raylib/config.h | 2 +- raylib/rshapes.go | 36 +++++++++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/raylib/cgo.go b/raylib/cgo.go index 60e7130..ffa6eb5 100644 --- a/raylib/cgo.go +++ b/raylib/cgo.go @@ -1,6 +1,6 @@ package rl /* -#cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result -Wno-implicit-function-declaration +#cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result -Wno-implicit-function-declaration -Wno-discarded-qualifiers */ import "C" diff --git a/raylib/config.h b/raylib/config.h index 7191f82..4017e62 100644 --- a/raylib/config.h +++ b/raylib/config.h @@ -157,7 +157,7 @@ //#define SUPPORT_FILEFORMAT_ASTC 1 //#define SUPPORT_FILEFORMAT_PKM 1 //#define SUPPORT_FILEFORMAT_PVR 1 -#define SUPPORT_FILEFORMAT_SVG 1 +//#define SUPPORT_FILEFORMAT_SVG 1 // Support image export functionality (.png, .bmp, .tga, .jpg, .qoi) #define SUPPORT_IMAGE_EXPORT 1 diff --git a/raylib/rshapes.go b/raylib/rshapes.go index 6c60040..c5de17b 100644 --- a/raylib/rshapes.go +++ b/raylib/rshapes.go @@ -10,6 +10,13 @@ import ( "unsafe" ) +// SetShapesTexture - Define default texture used to draw shapes +func SetShapesTexture(texture Texture2D, source Rectangle) { + ctexture := texture.cptr() + csource := source.cptr() + C.SetShapesTexture(*ctexture, *csource) +} + // DrawPixel - Draw a pixel func DrawPixel(posX, posY int32, col color.RGBA) { cposX := (C.int)(posX) @@ -82,6 +89,24 @@ func DrawLineBezierCubic(startPos Vector2, endPos Vector2, startControlPos Vecto C.DrawLineBezierCubic(*cstartPos, *cendPos, *cstartControlPos, *cendControlPos, cthick, *ccolor) } +// DrawLineBSpline - Draw a B-Spline line, minimum 4 points +func DrawLineBSpline(points []Vector2, pointCount int32, thick float32, col color.RGBA) { + cpoints := (*C.Vector2)(unsafe.Pointer(&points[0])) + cpointCount := (C.int)(pointCount) + cthick := (C.float)(thick) + ccolor := colorCptr(col) + C.DrawLineBSpline(cpoints, cpointCount, cthick, *ccolor) +} + +// DrawLineCatmullRom - Draw a Catmull Rom spline line, minimum 4 points +func DrawLineCatmullRom(points []Vector2, pointCount int32, thick float32, col color.RGBA) { + cpoints := (*C.Vector2)(unsafe.Pointer(&points[0])) + cpointCount := (C.int)(pointCount) + cthick := (C.float)(thick) + ccolor := colorCptr(col) + C.DrawLineCatmullRom(cpoints, cpointCount, cthick, *ccolor) +} + // DrawLineStrip - Draw lines sequence func DrawLineStrip(points []Vector2, pointCount int32, col color.RGBA) { cpoints := (*C.Vector2)(unsafe.Pointer(&points[0])) @@ -168,7 +193,7 @@ func DrawEllipseLines(centerX, centerY int32, radiusH, radiusV float32, col colo C.DrawEllipseLines(ccenterX, ccenterY, cradiusH, cradiusV, *ccolor) } -// DrawRing - +// DrawRing - Draw ring func DrawRing(center Vector2, innerRadius, outerRadius, startAngle, endAngle float32, segments int32, col color.RGBA) { ccenter := center.cptr() cinnerRadius := (C.float)(innerRadius) @@ -180,7 +205,7 @@ func DrawRing(center Vector2, innerRadius, outerRadius, startAngle, endAngle flo C.DrawRing(*ccenter, cinnerRadius, couterRadius, cstartAngle, cendAngle, csegments, *ccolor) } -// DrawRingLines - +// DrawRingLines - Draw ring outline func DrawRingLines(center Vector2, innerRadius, outerRadius, startAngle, endAngle float32, segments int32, col color.RGBA) { ccenter := center.cptr() cinnerRadius := (C.float)(innerRadius) @@ -463,10 +488,3 @@ func GetCollisionRec(rec1, rec2 Rectangle) Rectangle { v := newRectangleFromPointer(unsafe.Pointer(&ret)) return v } - -// SetShapesTexture - Define default texture used to draw shapes -func SetShapesTexture(texture Texture2D, source Rectangle) { - ctexture := texture.cptr() - csource := source.cptr() - C.SetShapesTexture(*ctexture, *csource) -}