Merge pull request #95 from xzebra/new-functions

ScissorMode and Text functions
This commit is contained in:
Milan Nikolic 2020-05-04 18:00:05 +02:00 committed by GitHub
commit efd3445362
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 0 deletions

View file

@ -269,6 +269,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()

View file

@ -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)