From 1abd3bd6ceeb1b90a49be8b422771fb62fb383ea Mon Sep 17 00:00:00 2001 From: Zebra Date: Sun, 19 Jan 2020 22:48:00 +0100 Subject: [PATCH 1/3] Added ScissorMode functions --- raylib/core.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/raylib/core.go b/raylib/core.go index 783a45a..0dcd9c4 100644 --- a/raylib/core.go +++ b/raylib/core.go @@ -231,6 +231,20 @@ func EndTextureMode() { C.EndTextureMode() } +// BeginScissorMode - Begins scissor mode (define screen area for following drawing) +func BeginScissorMode(x, y, width, height int32) { + cx := (C.int)(x) + cy := (C.int)(y) + cwidth := (C.int)(width) + cheight := (C.int)(height) + C.BeginScissorMode(cx, cy, cwidth, cheight) +} + +// EndScissorMode - Ends scissor mode +func EndScissorMode() { + C.EndScissorMode() +} + // GetMouseRay - Returns a ray trace from mouse position func GetMouseRay(mousePosition Vector2, camera Camera) Ray { cmousePosition := mousePosition.cptr() From 56ea7050a6a57be7e4cb3c954c08b2ed7cb01f02 Mon Sep 17 00:00:00 2001 From: Zebra Date: Mon, 20 Jan 2020 00:07:08 +0100 Subject: [PATCH 2/3] text functions --- raylib/text.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/raylib/text.go b/raylib/text.go index 06afc8f..11ab62a 100644 --- a/raylib/text.go +++ b/raylib/text.go @@ -45,6 +45,29 @@ func LoadFontEx(fileName string, fontSize int32, fontChars *int32, charsCount in return v } +// LoadFontFromImage - Loads an Image font file (XNA style) +func LoadFontFromImage(image Image, key Color, firstChar int32) Font { + cimage := image.cptr() + ckey := key.cptr() + cfirstChar := (C.int)(firstChar) + ret := C.LoadFontFromImage(*cimage, *ckey, cfirstChar) + v := newFontFromPointer(unsafe.Pointer(&ret)) + return v +} + +// LoadFontData - Load font data for further use +func LoadFontData(fileName string, fontSize int32, fontChars *int32, charsCount, typ int32) *CharInfo { + cfileName := C.CString(fileName) + defer C.free(unsafe.Pointer(cfileName)) + cfontSize := (C.int)(fontSize) + cfontChars := (*C.int)(unsafe.Pointer(fontChars)) + ccharsCount := (C.int)(charsCount) + ctype := (C.int)(typ) + ret := C.LoadFontData(cfileName, cfontSize, cfontChars, ccharsCount, ctype) + v := newCharInfoFromPointer(unsafe.Pointer(&ret)) + return &v +} + // UnloadFont - Unload Font from GPU memory (VRAM) func UnloadFont(font Font) { cfont := font.cptr() @@ -74,6 +97,36 @@ func DrawTextEx(font Font, text string, position Vector2, fontSize float32, spac C.DrawTextEx(*cfont, ctext, *cposition, cfontSize, cspacing, *ctint) } +// DrawTextRec - Draw text using font inside rectangle limits +func DrawTextRec(font Font, text string, rec Rectangle, fontSize, spacing float32, wordWrap bool, tint Color) { + cfont := font.cptr() + ctext := C.CString(text) + defer C.free(unsafe.Pointer(ctext)) + crec := rec.cptr() + cfontSize := (C.float)(fontSize) + cspacing := (C.float)(spacing) + cwordWrap := (C.bool)(wordWrap) + ctint := tint.cptr() + C.DrawTextRec(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint) +} + +// DrawTextRecEx - Draw text using font inside rectangle limits with support for text selection +func DrawTextRecEx(font Font, text string, rec Rectangle, fontSize, spacing float32, wordWrap bool, tint Color, selectStart, selectLength int32, selectText, selectBack Color) { + cfont := font.cptr() + ctext := C.CString(text) + defer C.free(unsafe.Pointer(ctext)) + crec := rec.cptr() + cfontSize := (C.float)(fontSize) + cspacing := (C.float)(spacing) + cwordWrap := (C.bool)(wordWrap) + ctint := tint.cptr() + cselectStart := (C.int)(selectStart) + cselectLength := (C.int)(selectLength) + cselectText := selectText.cptr() + cselectBack := selectBack.cptr() + C.DrawTextRecEx(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint, cselectStart, cselectLength, *cselectText, *cselectBack) +} + // MeasureText - Measure string width for default font func MeasureText(text string, fontSize int32) int32 { ctext := C.CString(text) @@ -96,6 +149,15 @@ func MeasureTextEx(font Font, text string, fontSize float32, spacing float32) Ve return v } +// GetGlyphIndex - Returns index position for a unicode character on spritefont +func GetGlyphIndex(font Font, character int32) int32 { + cfont := font.cptr() + ccharacter := (C.int)(character) + ret := C.GetGlyphIndex(*cfont, ccharacter) + v := (int32)(ret) + return v +} + // DrawFPS - Shows current FPS func DrawFPS(posX int32, posY int32) { cposX := (C.int)(posX) From 4c9ba69910ec9b01e15a6cb073a9b6f4a547b35c Mon Sep 17 00:00:00 2001 From: Zebra Date: Mon, 20 Jan 2020 00:14:49 +0100 Subject: [PATCH 3/3] gofmt --- raylib/core.go | 12 ++++++------ raylib/text.go | 42 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/raylib/core.go b/raylib/core.go index 0dcd9c4..9e9089a 100644 --- a/raylib/core.go +++ b/raylib/core.go @@ -233,16 +233,16 @@ func EndTextureMode() { // BeginScissorMode - Begins scissor mode (define screen area for following drawing) func BeginScissorMode(x, y, width, height int32) { - cx := (C.int)(x) - cy := (C.int)(y) - cwidth := (C.int)(width) - cheight := (C.int)(height) - C.BeginScissorMode(cx, cy, cwidth, cheight) + cx := (C.int)(x) + cy := (C.int)(y) + cwidth := (C.int)(width) + cheight := (C.int)(height) + C.BeginScissorMode(cx, cy, cwidth, cheight) } // EndScissorMode - Ends scissor mode func EndScissorMode() { - C.EndScissorMode() + C.EndScissorMode() } // GetMouseRay - Returns a ray trace from mouse position diff --git a/raylib/text.go b/raylib/text.go index 11ab62a..93fe417 100644 --- a/raylib/text.go +++ b/raylib/text.go @@ -47,25 +47,25 @@ func LoadFontEx(fileName string, fontSize int32, fontChars *int32, charsCount in // LoadFontFromImage - Loads an Image font file (XNA style) func LoadFontFromImage(image Image, key Color, firstChar int32) Font { - cimage := image.cptr() - ckey := key.cptr() - cfirstChar := (C.int)(firstChar) - ret := C.LoadFontFromImage(*cimage, *ckey, cfirstChar) - v := newFontFromPointer(unsafe.Pointer(&ret)) - return v + cimage := image.cptr() + ckey := key.cptr() + cfirstChar := (C.int)(firstChar) + ret := C.LoadFontFromImage(*cimage, *ckey, cfirstChar) + v := newFontFromPointer(unsafe.Pointer(&ret)) + return v } // LoadFontData - Load font data for further use func LoadFontData(fileName string, fontSize int32, fontChars *int32, charsCount, typ int32) *CharInfo { - cfileName := C.CString(fileName) - defer C.free(unsafe.Pointer(cfileName)) + cfileName := C.CString(fileName) + defer C.free(unsafe.Pointer(cfileName)) cfontSize := (C.int)(fontSize) cfontChars := (*C.int)(unsafe.Pointer(fontChars)) ccharsCount := (C.int)(charsCount) - ctype := (C.int)(typ) - ret := C.LoadFontData(cfileName, cfontSize, cfontChars, ccharsCount, ctype) - v := newCharInfoFromPointer(unsafe.Pointer(&ret)) - return &v + ctype := (C.int)(typ) + ret := C.LoadFontData(cfileName, cfontSize, cfontChars, ccharsCount, ctype) + v := newCharInfoFromPointer(unsafe.Pointer(&ret)) + return &v } // UnloadFont - Unload Font from GPU memory (VRAM) @@ -102,12 +102,12 @@ func DrawTextRec(font Font, text string, rec Rectangle, fontSize, spacing float3 cfont := font.cptr() ctext := C.CString(text) defer C.free(unsafe.Pointer(ctext)) - crec := rec.cptr() + crec := rec.cptr() cfontSize := (C.float)(fontSize) cspacing := (C.float)(spacing) cwordWrap := (C.bool)(wordWrap) ctint := tint.cptr() - C.DrawTextRec(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint) + C.DrawTextRec(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint) } // DrawTextRecEx - Draw text using font inside rectangle limits with support for text selection @@ -115,16 +115,16 @@ func DrawTextRecEx(font Font, text string, rec Rectangle, fontSize, spacing floa cfont := font.cptr() ctext := C.CString(text) defer C.free(unsafe.Pointer(ctext)) - crec := rec.cptr() + crec := rec.cptr() cfontSize := (C.float)(fontSize) cspacing := (C.float)(spacing) cwordWrap := (C.bool)(wordWrap) ctint := tint.cptr() cselectStart := (C.int)(selectStart) cselectLength := (C.int)(selectLength) - cselectText := selectText.cptr() - cselectBack := selectBack.cptr() - C.DrawTextRecEx(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint, cselectStart, cselectLength, *cselectText, *cselectBack) + cselectText := selectText.cptr() + cselectBack := selectBack.cptr() + C.DrawTextRecEx(*cfont, ctext, *crec, cfontSize, cspacing, cwordWrap, *ctint, cselectStart, cselectLength, *cselectText, *cselectBack) } // MeasureText - Measure string width for default font @@ -151,9 +151,9 @@ func MeasureTextEx(font Font, text string, fontSize float32, spacing float32) Ve // GetGlyphIndex - Returns index position for a unicode character on spritefont func GetGlyphIndex(font Font, character int32) int32 { - cfont := font.cptr() - ccharacter := (C.int)(character) - ret := C.GetGlyphIndex(*cfont, ccharacter) + cfont := font.cptr() + ccharacter := (C.int)(character) + ret := C.GetGlyphIndex(*cfont, ccharacter) v := (int32)(ret) return v }