Update/add Go functions

This commit is contained in:
Milan Nikolic 2021-11-11 16:34:15 +01:00
parent 607adace28
commit 2013bc4628
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
17 changed files with 268 additions and 211 deletions

View file

@ -4,7 +4,7 @@ import rl "github.com/gen2brain/raylib-go/raylib"
// Label - Label element, show text // Label - Label element, show text
func Label(bounds rl.Rectangle, text string) { func Label(bounds rl.Rectangle, text string) {
LabelEx(bounds, text, rl.GetColor(int32(style[LabelTextColor])), rl.NewColor(0, 0, 0, 0), rl.NewColor(0, 0, 0, 0)) LabelEx(bounds, text, rl.GetColor(uint(style[LabelTextColor])), rl.NewColor(0, 0, 0, 0), rl.NewColor(0, 0, 0, 0))
} }
// LabelEx - Label element extended, configurable colors // LabelEx - Label element extended, configurable colors
@ -12,7 +12,7 @@ func LabelEx(bounds rl.Rectangle, text string, textColor, border, inner rl.Color
textHeight := GetStyle32(GlobalTextFontsize) textHeight := GetStyle32(GlobalTextFontsize)
textWidth := rl.MeasureText(text, textHeight) textWidth := rl.MeasureText(text, textHeight)
ConstrainRectangle(&bounds, textWidth, textWidth + GetStyle32(LabelTextPadding), textHeight, textHeight + GetStyle32(LabelTextPadding) / 2) ConstrainRectangle(&bounds, textWidth, textWidth+GetStyle32(LabelTextPadding), textHeight, textHeight+GetStyle32(LabelTextPadding)/2)
// Draw control // Draw control
b := bounds.ToInt32() b := bounds.ToInt32()

View file

@ -1,6 +1,6 @@
package raygui package raygui
import "github.com/gen2brain/raylib-go/raylib" import rl "github.com/gen2brain/raylib-go/raylib"
// Slider - Slider element, returns selected value // Slider - Slider element, returns selected value
func Slider(bounds rl.Rectangle, value, minValue, maxValue float32) float32 { func Slider(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
@ -55,18 +55,18 @@ func Slider(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
} }
// Draw control // Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderBorderColor]))) rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(uint(style[SliderBorderColor])))
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderInsideColor]))) rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(uint(style[SliderInsideColor])))
switch state { switch state {
case Normal: case Normal:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderDefaultColor]))) rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(uint(style[SliderDefaultColor])))
break break
case Focused: case Focused:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderHoverColor]))) rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(uint(style[SliderHoverColor])))
break break
case Pressed: case Pressed:
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderActiveColor]))) rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(uint(style[SliderActiveColor])))
break break
default: default:
break break

View file

@ -1,6 +1,6 @@
package raygui package raygui
import "github.com/gen2brain/raylib-go/raylib" import rl "github.com/gen2brain/raylib-go/raylib"
// SliderBar - Slider Bar element, returns selected value // SliderBar - Slider Bar element, returns selected value
func SliderBar(bounds rl.Rectangle, value, minValue, maxValue float32) float32 { func SliderBar(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
@ -51,25 +51,25 @@ func SliderBar(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
fixedValue = (float32(sliderBar.Width) * (maxValue - fixedMinValue)) / (float32(b.Width) - 2*float32(style[SliderBorderWidth])) fixedValue = (float32(sliderBar.Width) * (maxValue - fixedMinValue)) / (float32(b.Width) - 2*float32(style[SliderBorderWidth]))
// Draw control // Draw control
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderbarBorderColor]))) rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(uint(style[SliderbarBorderColor])))
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderbarInsideColor]))) rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(uint(style[SliderbarInsideColor])))
switch state { switch state {
case Normal: case Normal:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarDefaultColor]))) rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(uint(style[SliderbarDefaultColor])))
break break
case Focused: case Focused:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarHoverColor]))) rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(uint(style[SliderbarHoverColor])))
break break
case Pressed: case Pressed:
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarActiveColor]))) rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(uint(style[SliderbarActiveColor])))
break break
default: default:
break break
} }
if minValue < 0 && maxValue > 0 { if minValue < 0 && maxValue > 0 {
rl.DrawRectangle((b.X+int32(style[SliderBorderWidth]))-int32(minValue*(float32(b.Width-(int32(style[SliderBorderWidth])*2))/maxValue)), sliderBar.Y, 1, sliderBar.Height, rl.GetColor(int32(style[SliderbarZeroLineColor]))) rl.DrawRectangle((b.X+int32(style[SliderBorderWidth]))-int32(minValue*(float32(b.Width-(int32(style[SliderBorderWidth])*2))/maxValue)), sliderBar.Y, 1, sliderBar.Height, rl.GetColor(uint(style[SliderbarZeroLineColor])))
} }
return fixedValue + minValue return fixedValue + minValue

View file

@ -2,7 +2,8 @@ package raygui
import ( import (
"fmt" "fmt"
"github.com/gen2brain/raylib-go/raylib"
rl "github.com/gen2brain/raylib-go/raylib"
) )
// For spinner // For spinner
@ -102,71 +103,71 @@ func Spinner(bounds rl.Rectangle, value, minValue, maxValue int) int {
// Draw control // Draw control
switch state { switch state {
case Normal: case Normal:
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor]))) rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(uint(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor]))) rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(uint(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultTextColor]))) rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultTextColor])))
break break
case Focused: case Focused:
if buttonSide == 1 { if buttonSide == 1 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor]))) rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(uint(style[SpinnerHoverButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor]))) rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(uint(style[SpinnerHoverButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerHoverSymbolColor]))) rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerHoverSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
} else if buttonSide == 2 { } else if buttonSide == 2 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor]))) rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(uint(style[SpinnerHoverButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor]))) rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(uint(style[SpinnerHoverButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerHoverSymbolColor]))) rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerHoverSymbolColor])))
} }
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor]))) rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(uint(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor]))) rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(uint(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerHoverTextColor]))) rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerHoverTextColor])))
break break
case Pressed: case Pressed:
if buttonSide == 1 { if buttonSide == 1 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor]))) rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(uint(style[SpinnerPressedButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor]))) rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(uint(style[SpinnerPressedButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerPressedSymbolColor]))) rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerPressedSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
} else if buttonSide == 2 { } else if buttonSide == 2 {
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor]))) rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(uint(style[SpinnerDefaultButtonBorderColor])))
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor]))) rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(uint(style[SpinnerDefaultButtonInsideColor])))
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor]))) rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(uint(style[SpinnerPressedButtonBorderColor])))
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor]))) rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(uint(style[SpinnerPressedButtonInsideColor])))
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerDefaultSymbolColor]))) rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", textHeight))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerDefaultSymbolColor])))
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerPressedSymbolColor]))) rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", textHeight))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerPressedSymbolColor])))
} }
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor]))) rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(uint(style[SpinnerLabelBorderColor])))
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor]))) rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(uint(style[SpinnerLabelInsideColor])))
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(int32(style[SpinnerPressedTextColor]))) rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(textHeight/2)), textHeight, rl.GetColor(uint(style[SpinnerPressedTextColor])))
break break
default: default:
break break

View file

@ -5,10 +5,11 @@ package raygui
import ( import (
"bufio" "bufio"
"fmt" "fmt"
rl "github.com/gen2brain/raylib-go/raylib"
"io/ioutil" "io/ioutil"
"strconv" "strconv"
"strings" "strings"
rl "github.com/gen2brain/raylib-go/raylib"
) )
// Property - GUI property // Property - GUI property
@ -394,17 +395,17 @@ func GetStyleProperty(guiProperty Property) int64 {
// BackgroundColor will return the current background color // BackgroundColor will return the current background color
func BackgroundColor() rl.Color { func BackgroundColor() rl.Color {
return rl.GetColor(int32(style[GlobalBackgroundColor])) return rl.GetColor(uint(style[GlobalBackgroundColor]))
} }
// LinesColor will return the current color for lines // LinesColor will return the current color for lines
func LinesColor() rl.Color { func LinesColor() rl.Color {
return rl.GetColor(int32(style[GlobalLinesColor])) return rl.GetColor(uint(style[GlobalLinesColor]))
} }
// TextColor will return the current color for normal state // TextColor will return the current color for normal state
func TextColor() rl.Color { func TextColor() rl.Color {
return rl.GetColor(int32(style[GlobalTextColor])) return rl.GetColor(uint(style[GlobalTextColor]))
} }
// GetStyle32 will return the int32 for a given property of the current style // GetStyle32 will return the int32 for a given property of the current style
@ -414,5 +415,5 @@ func GetStyle32(property Property) int32 {
// GetPropColor will return the Color value for a given property of the current style // GetPropColor will return the Color value for a given property of the current style
func GetStyleColor(property Property) rl.Color { func GetStyleColor(property Property) rl.Color {
return rl.GetColor(int32(style[property])) return rl.GetColor(uint(style[property]))
} }

View file

@ -2,8 +2,9 @@ package raygui
import ( import (
"fmt" "fmt"
"github.com/gen2brain/raylib-go/raylib"
"time" "time"
rl "github.com/gen2brain/raylib-go/raylib"
) )
var backspaceHeld = false var backspaceHeld = false
@ -11,6 +12,7 @@ var nextBackspace = time.Now()
// BackspaceRepeatDelay controls the time backspace must be held down before it will repeat. // BackspaceRepeatDelay controls the time backspace must be held down before it will repeat.
var BackspaceRepeatDelay = 300 * time.Millisecond var BackspaceRepeatDelay = 300 * time.Millisecond
// BackspaceRepeatInterval controls how frequently backspace registers after the initial delay. // BackspaceRepeatInterval controls how frequently backspace registers after the initial delay.
var BackspaceRepeatInterval = 60 * time.Millisecond var BackspaceRepeatInterval = 60 * time.Millisecond
@ -54,7 +56,7 @@ func TextBox(bounds rl.Rectangle, text string) string {
if state == Focused || state == Pressed { if state == Focused || state == Pressed {
// Draw a cursor, when focused. // Draw a cursor, when focused.
if (framesCounter2/20)%2 == 0 { if (framesCounter2/20)%2 == 0 {
rl.DrawRectangle(b.X+4+rl.MeasureText(text, int32(style[GlobalTextFontsize])), b.Y+2, 1, b.Height-4, rl.GetColor(int32(style[TextboxLineColor]))) rl.DrawRectangle(b.X+4+rl.MeasureText(text, int32(style[GlobalTextFontsize])), b.Y+2, 1, b.Height-4, rl.GetColor(uint(style[TextboxLineColor])))
} }
} }

View file

@ -1,6 +1,6 @@
package rl package rl
/* /*
#cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result #cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result -Wno-implicit-function-declaration
*/ */
import "C" import "C"

View file

@ -1,3 +1,4 @@
//go:build !noaudio
// +build !noaudio // +build !noaudio
package rl package rl
@ -9,8 +10,10 @@ package rl
#include <stdlib.h> #include <stdlib.h>
*/ */
import "C" import "C"
import "unsafe" import (
import "reflect" "reflect"
"unsafe"
)
// cptr returns C pointer // cptr returns C pointer
func (w *Wave) cptr() *C.Wave { func (w *Wave) cptr() *C.Wave {
@ -120,6 +123,12 @@ func PlaySound(sound Sound) {
C.PlaySound(*csound) C.PlaySound(*csound)
} }
// StopSound - Stop playing a sound
func StopSound(sound Sound) {
csound := sound.cptr()
C.StopSound(*csound)
}
// PauseSound - Pause a sound // PauseSound - Pause a sound
func PauseSound(sound Sound) { func PauseSound(sound Sound) {
csound := sound.cptr() csound := sound.cptr()
@ -132,10 +141,22 @@ func ResumeSound(sound Sound) {
C.ResumeSound(*csound) C.ResumeSound(*csound)
} }
// StopSound - Stop playing a sound // PlaySoundMulti - Play a sound (using multichannel buffer pool)
func StopSound(sound Sound) { func PlaySoundMulti(sound Sound) {
csound := sound.cptr() csound := sound.cptr()
C.StopSound(*csound) C.PlaySoundMulti(*csound)
}
// StopSoundMulti - Stop any sound playing (using multichannel buffer pool)
func StopSoundMulti() {
C.StopSoundMulti()
}
// GetSoundsPlaying - Get number of sounds playing in the multichannel
func GetSoundsPlaying() int {
ret := C.GetSoundsPlaying()
v := int(ret)
return v
} }
// IsSoundPlaying - Check if a sound is currently playing // IsSoundPlaying - Check if a sound is currently playing
@ -199,6 +220,11 @@ func LoadWaveSamples(wave Wave) []float32 {
return data return data
} }
// UnloadWaveSamples - Unload samples data loaded with LoadWaveSamples()
func UnloadWaveSamples(samples []float32) {
C.UnloadWaveSamples((*C.float)(unsafe.Pointer(&samples[0])))
}
// LoadMusicStream - Load music stream from file // LoadMusicStream - Load music stream from file
func LoadMusicStream(fileName string) Music { func LoadMusicStream(fileName string) Music {
cfileName := C.CString(fileName) cfileName := C.CString(fileName)
@ -231,6 +257,14 @@ func PlayMusicStream(music Music) {
C.PlayMusicStream(cmusic) C.PlayMusicStream(cmusic)
} }
// IsMusicStreamPlaying - Check if music is playing
func IsMusicStreamPlaying(music Music) bool {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
ret := C.IsMusicStreamPlaying(cmusic)
v := bool(ret)
return v
}
// UpdateMusicStream - Updates buffers for music streaming // UpdateMusicStream - Updates buffers for music streaming
func UpdateMusicStream(music Music) { func UpdateMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music)) cmusic := *(*C.Music)(unsafe.Pointer(&music))
@ -255,12 +289,11 @@ func ResumeMusicStream(music Music) {
C.ResumeMusicStream(cmusic) C.ResumeMusicStream(cmusic)
} }
// IsMusicStreamPlaying - Check if music is playing // SeekMusicStream - Seek music to a position (in seconds)
func IsMusicStreamPlaying(music Music) bool { func SeekMusicStream(music Music, position float32) {
cmusic := *(*C.Music)(unsafe.Pointer(&music)) cmusic := *(*C.Music)(unsafe.Pointer(&music))
ret := C.IsMusicStreamPlaying(cmusic) cposition := (C.float)(position)
v := bool(ret) C.SeekMusicStream(cmusic, cposition)
return v
} }
// SetMusicVolume - Set volume for music (1.0 is max level) // SetMusicVolume - Set volume for music (1.0 is max level)
@ -293,16 +326,22 @@ func GetMusicTimePlayed(music Music) float32 {
return v return v
} }
// InitAudioStream - Init audio stream (to stream raw audio pcm data) // LoadAudioStream - Load audio stream (to stream raw audio pcm data)
func InitAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) AudioStream { func LoadAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) AudioStream {
csampleRate := (C.uint)(sampleRate) csampleRate := (C.uint)(sampleRate)
csampleSize := (C.uint)(sampleSize) csampleSize := (C.uint)(sampleSize)
cchannels := (C.uint)(channels) cchannels := (C.uint)(channels)
ret := C.InitAudioStream(csampleRate, csampleSize, cchannels) ret := C.LoadAudioStream(csampleRate, csampleSize, cchannels)
v := newAudioStreamFromPointer(unsafe.Pointer(&ret)) v := newAudioStreamFromPointer(unsafe.Pointer(&ret))
return v return v
} }
//UnloadAudioStream - Unload audio stream and free memory
func UnloadAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.UnloadAudioStream(*cstream)
}
// UpdateAudioStream - Update audio stream buffers with data // UpdateAudioStream - Update audio stream buffers with data
func UpdateAudioStream(stream AudioStream, data []float32, samplesCount int32) { func UpdateAudioStream(stream AudioStream, data []float32, samplesCount int32) {
cstream := stream.cptr() cstream := stream.cptr()
@ -311,12 +350,6 @@ func UpdateAudioStream(stream AudioStream, data []float32, samplesCount int32) {
C.UpdateAudioStream(*cstream, cdata, csamplesCount) C.UpdateAudioStream(*cstream, cdata, csamplesCount)
} }
// CloseAudioStream - Close audio stream and free memory
func CloseAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.CloseAudioStream(*cstream)
}
// IsAudioStreamProcessed - Check if any audio stream buffers requires refill // IsAudioStreamProcessed - Check if any audio stream buffers requires refill
func IsAudioStreamProcessed(stream AudioStream) bool { func IsAudioStreamProcessed(stream AudioStream) bool {
cstream := stream.cptr() cstream := stream.cptr()
@ -343,26 +376,36 @@ func ResumeAudioStream(stream AudioStream) {
C.ResumeAudioStream(*cstream) C.ResumeAudioStream(*cstream)
} }
// IsAudioStreamPlaying - Check if audio stream is playing
func IsAudioStreamPlaying(stream AudioStream) bool {
cstream := stream.cptr()
ret := C.IsAudioStreamPlaying(*cstream)
v := bool(ret)
return v
}
// StopAudioStream - Stop audio stream // StopAudioStream - Stop audio stream
func StopAudioStream(stream AudioStream) { func StopAudioStream(stream AudioStream) {
cstream := stream.cptr() cstream := stream.cptr()
C.StopAudioStream(*cstream) C.StopAudioStream(*cstream)
} }
// PlaySoundMulti - Play a sound (using multichannel buffer pool) // SetAudioStreamVolume - Set volume for audio stream (1.0 is max level)
func PlaySoundMulti(sound Sound) { func SetAudioStreamVolume(stream AudioStream, volume float32) {
csound := sound.cptr() cstream := stream.cptr()
C.PlaySoundMulti(*csound) cvolume := (C.float)(volume)
C.SetAudioStreamVolume(*cstream, cvolume)
} }
// GetSoundsPlaying - Get number of sounds playing in the multichannel // SetAudioStreamPitch - Set pitch for audio stream (1.0 is base level)
func GetSoundsPlaying() int { func SetAudioStreamPitch(stream AudioStream, pitch float32) {
ret := C.GetSoundsPlaying() cstream := stream.cptr()
v := int(ret) cpitch := (C.float)(pitch)
return v C.SetAudioStreamPitch(*cstream, cpitch)
} }
// StopSoundMulti - Stop any sound playing (using multichannel buffer pool) // SetAudioStreamBufferSizeDefault - Default size for new audio streams
func StopSoundMulti() { func SetAudioStreamBufferSizeDefault(size int32) {
C.StopSoundMulti() csize := (C.int)(size)
C.SetAudioStreamBufferSizeDefault(csize)
} }

View file

@ -894,6 +894,24 @@ func newRayFromPointer(ptr unsafe.Pointer) Ray {
return *(*Ray)(ptr) return *(*Ray)(ptr)
} }
// RayCollision type - ray hit information
type RayCollision struct {
Hit bool
Distance float32
Point Vector3
Normal Vector3
}
// NewRayCollision - Returns new RayCollision
func NewRayCollision(hit bool, distance float32, point, normal Vector3) RayCollision {
return RayCollision{hit, distance, point, normal}
}
// newRayCollisionFromPointer - Returns new RayCollision from pointer
func newRayCollisionFromPointer(ptr unsafe.Pointer) RayCollision {
return *(*RayCollision)(ptr)
}
// BlendMode type // BlendMode type
type BlendMode int32 type BlendMode int32
@ -935,8 +953,8 @@ func (sh Shader) UpdateLocation(index int32, loc int32) {
*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(sh.Locs)) + uintptr(index*4))) = loc *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(sh.Locs)) + uintptr(index*4))) = loc
} }
// CharInfo - Font character info // GlyphInfo - Font character info
type CharInfo struct { type GlyphInfo struct {
// Character value (Unicode) // Character value (Unicode)
Value int32 Value int32
// Character offset X when drawing // Character offset X when drawing
@ -949,14 +967,14 @@ type CharInfo struct {
Image Image Image Image
} }
// NewCharInfo - Returns new CharInfo // NewGlyphInfo - Returns new CharInfo
func NewCharInfo(value int32, offsetX, offsetY, advanceX int32, image Image) CharInfo { func NewGlyphInfo(value int32, offsetX, offsetY, advanceX int32, image Image) GlyphInfo {
return CharInfo{value, offsetX, offsetY, advanceX, image} return GlyphInfo{value, offsetX, offsetY, advanceX, image}
} }
// newCharInfoFromPointer - Returns new CharInfo from pointer // newGlyphInfoFromPointer - Returns new GlyphInfo from pointer
func newCharInfoFromPointer(ptr unsafe.Pointer) CharInfo { func newGlyphInfoFromPointer(ptr unsafe.Pointer) GlyphInfo {
return *(*CharInfo)(ptr) return *(*GlyphInfo)(ptr)
} }
// Font type, includes texture and charSet array data // Font type, includes texture and charSet array data
@ -972,7 +990,7 @@ type Font struct {
// Characters rectangles in texture // Characters rectangles in texture
Recs *Rectangle Recs *Rectangle
// Characters info data // Characters info data
Chars *CharInfo Chars *GlyphInfo
} }
// newFontFromPointer - Returns new Font from pointer // newFontFromPointer - Returns new Font from pointer

View file

@ -520,8 +520,8 @@ func ColorAlphaBlend(src, dst, tint Color) Color {
} }
// GetColor - Returns a Color struct from hexadecimal value // GetColor - Returns a Color struct from hexadecimal value
func GetColor(hexValue int32) Color { func GetColor(hexValue uint) Color {
chexValue := (C.int)(hexValue) chexValue := (C.uint)(hexValue)
ret := C.GetColor(chexValue) ret := C.GetColor(chexValue)
v := newColorFromPointer(unsafe.Pointer(&ret)) v := newColorFromPointer(unsafe.Pointer(&ret))
return v return v
@ -668,16 +668,6 @@ func IsGamepadAvailable(gamepad int32) bool {
return v return v
} }
// IsGamepadName - Check gamepad name (if available)
func IsGamepadName(gamepad int32, name string) bool {
cgamepad := (C.int)(gamepad)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
ret := C.IsGamepadName(cgamepad, cname)
v := bool(ret)
return v
}
// GetGamepadName - Return gamepad internal name id // GetGamepadName - Return gamepad internal name id
func GetGamepadName(gamepad int32) string { func GetGamepadName(gamepad int32) string {
cgamepad := (C.int)(gamepad) cgamepad := (C.int)(gamepad)

View file

@ -27,9 +27,9 @@ func GetGestureDetected() Gestures {
return v return v
} }
// GetTouchPointsCount - Get touch points count // GetTouchPointCount - Get number of touch points
func GetTouchPointsCount() int32 { func GetTouchPointCount() int32 {
ret := C.GetTouchPointsCount() ret := C.GetTouchPointCount()
v := (int32)(ret) v := (int32)(ret)
return v return v
} }

View file

@ -6,8 +6,10 @@ package rl
#include <stdlib.h> #include <stdlib.h>
*/ */
import "C" import "C"
import "unsafe" import (
import "reflect" "reflect"
"unsafe"
)
// cptr returns C pointer // cptr returns C pointer
func (s *Shader) cptr() *C.Shader { func (s *Shader) cptr() *C.Shader {
@ -54,20 +56,6 @@ func UnloadShader(shader Shader) {
C.UnloadShader(*cshader) C.UnloadShader(*cshader)
} }
// GetShaderDefault - Get default shader
func GetShaderDefault() Shader {
ret := C.rlGetShaderDefault()
v := newShaderFromPointer(unsafe.Pointer(&ret))
return v
}
// GetTextureDefault - Get default texture
func GetTextureDefault() *Texture2D {
ret := C.rlGetTextureDefault()
v := newTexture2DFromPointer(unsafe.Pointer(&ret))
return &v
}
// GetShaderLocation - Get shader uniform location // GetShaderLocation - Get shader uniform location
func GetShaderLocation(shader Shader, uniformName string) int32 { func GetShaderLocation(shader Shader, uniformName string) int32 {
cshader := shader.cptr() cshader := shader.cptr()

View file

@ -35,6 +35,13 @@ func DrawLine3D(startPos Vector3, endPos Vector3, color Color) {
C.DrawLine3D(*cstartPos, *cendPos, *ccolor) C.DrawLine3D(*cstartPos, *cendPos, *ccolor)
} }
// DrawPoint3D - Draw a point in 3D space, actually a small line
func DrawPoint3D(position Vector3, color Color) {
cposition := position.cptr()
ccolor := color.cptr()
C.DrawPoint3D(*cposition, *ccolor)
}
// DrawCircle3D - Draw a circle in 3D world space // DrawCircle3D - Draw a circle in 3D world space
func DrawCircle3D(center Vector3, radius float32, rotationAxis Vector3, rotationAngle float32, color Color) { func DrawCircle3D(center Vector3, radius float32, rotationAxis Vector3, rotationAngle float32, color Color) {
ccenter := center.cptr() ccenter := center.cptr()
@ -73,6 +80,14 @@ func DrawCubeWires(position Vector3, width float32, height float32, length float
C.DrawCubeWires(*cposition, cwidth, cheight, clength, *ccolor) C.DrawCubeWires(*cposition, cwidth, cheight, clength, *ccolor)
} }
// DrawCubeWiresV - Draw cube wires (Vector version)
func DrawCubeWiresV(position Vector3, size Vector3, color Color) {
cposition := position.cptr()
csize := size.cptr()
ccolor := color.cptr()
C.DrawCubeWiresV(*cposition, *csize, *ccolor)
}
// DrawCubeTexture - Draw cube textured // DrawCubeTexture - Draw cube textured
func DrawCubeTexture(texture Texture2D, position Vector3, width float32, height float32, length float32, color Color) { func DrawCubeTexture(texture Texture2D, position Vector3, width float32, height float32, length float32, color Color) {
ctexture := texture.cptr() ctexture := texture.cptr()
@ -448,32 +463,63 @@ func CheckCollisionBoxSphere(box BoundingBox, centerSphere Vector3, radiusSphere
return v return v
} }
// CheckCollisionRaySphere - Detect collision between ray and sphere // GetRayCollisionSphere - Get collision info between ray and sphere
func CheckCollisionRaySphere(ray Ray, spherePosition Vector3, sphereRadius float32) bool { func GetRayCollisionSphere(ray Ray, center Vector3, radius float32) RayCollision {
cray := ray.cptr() cray := ray.cptr()
cspherePosition := spherePosition.cptr() ccenter := center.cptr()
csphereRadius := (C.float)(sphereRadius) cradius := (C.float)(radius)
ret := C.CheckCollisionRaySphere(*cray, *cspherePosition, csphereRadius) ret := C.GetRayCollisionSphere(*cray, *ccenter, cradius)
v := bool(ret) v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v return v
} }
// CheckCollisionRaySphereEx - Detect collision between ray and sphere with extended parameters and collision point detection // GetRayCollisionBox - Get collision info between ray and box
func CheckCollisionRaySphereEx(ray Ray, spherePosition Vector3, sphereRadius float32, collisionPoint Vector3) bool { func GetRayCollisionBox(ray Ray, box BoundingBox) RayCollision {
cray := ray.cptr()
cspherePosition := spherePosition.cptr()
csphereRadius := (C.float)(sphereRadius)
ccollisionPoint := collisionPoint.cptr()
ret := C.CheckCollisionRaySphereEx(*cray, *cspherePosition, csphereRadius, ccollisionPoint)
v := bool(ret)
return v
}
// CheckCollisionRayBox - Detect collision between ray and box
func CheckCollisionRayBox(ray Ray, box BoundingBox) bool {
cray := ray.cptr() cray := ray.cptr()
cbox := box.cptr() cbox := box.cptr()
ret := C.CheckCollisionRayBox(*cray, *cbox) ret := C.GetRayCollisionBox(*cray, *cbox)
v := bool(ret) v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v
}
// GetRayCollisionModel - Get collision info between ray and model
func GetRayCollisionModel(ray Ray, model Model) RayCollision {
cray := ray.cptr()
cmodel := model.cptr()
ret := C.GetRayCollisionModel(*cray, *cmodel)
v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v
}
// GetRayCollisionMesh - Get collision info between ray and mesh
func GetRayCollisionMesh(ray Ray, mesh Mesh, transform Matrix) RayCollision {
cray := ray.cptr()
cmesh := mesh.cptr()
ctransform := transform.cptr()
ret := C.GetRayCollisionMesh(*cray, *cmesh, *ctransform)
v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v
}
// GetRayCollisionTriangle - Get collision info between ray and triangle
func GetRayCollisionTriangle(ray Ray, p1, p2, p3 Vector3) RayCollision {
cray := ray.cptr()
cp1 := p1.cptr()
cp2 := p2.cptr()
cp3 := p3.cptr()
ret := C.GetRayCollisionTriangle(*cray, *cp1, *cp2, *cp3)
v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v
}
// GetRayCollisionQuad - Get collision info between ray and quad
func GetRayCollisionQuad(ray Ray, p1, p2, p3, p4 Vector3) RayCollision {
cray := ray.cptr()
cp1 := p1.cptr()
cp2 := p2.cptr()
cp3 := p3.cptr()
cp4 := p4.cptr()
ret := C.GetRayCollisionQuad(*cray, *cp1, *cp2, *cp3, *cp4)
v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
return v return v
} }

View file

@ -178,11 +178,11 @@ func DrawRectangleRec(rec Rectangle, color Color) {
} }
// DrawRectanglePro - Draw a color-filled rectangle with pro parameters // DrawRectanglePro - Draw a color-filled rectangle with pro parameters
func DrawRectanglePro(rec Rectangle, origin Vector2, rotation float32, colors []Color) { func DrawRectanglePro(rec Rectangle, origin Vector2, rotation float32, color Color) {
crec := rec.cptr() crec := rec.cptr()
corigin := origin.cptr() corigin := origin.cptr()
crotation := (C.float)(rotation) crotation := (C.float)(rotation)
ccolor := (*C.Color)(unsafe.Pointer(&colors[0])) ccolor := color.cptr()
C.DrawRectanglePro(*crec, *corigin, crotation, *ccolor) C.DrawRectanglePro(*crec, *corigin, crotation, *ccolor)
} }
@ -389,6 +389,17 @@ func CheckCollisionLines(startPos1, endPos1, startPos2, endPos2 Vector2, point *
return v return v
} }
// CheckCollisionPointLine - Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
func CheckCollisionPointLine(point, p1, p2 Vector2, threshold int32) bool {
cpoint := point.cptr()
cp1 := p1.cptr()
cp2 := p2.cptr()
cthreshold := (C.int)(threshold)
ret := C.CheckCollisionPointLine(*cpoint, *cp1, *cp2, cthreshold)
v := bool(ret)
return v
}
// GetCollisionRec - Get collision rectangle for two rectangles collision // GetCollisionRec - Get collision rectangle for two rectangles collision
func GetCollisionRec(rec1, rec2 Rectangle) Rectangle { func GetCollisionRec(rec1, rec2 Rectangle) Rectangle {
crec1 := rec1.cptr() crec1 := rec1.cptr()

View file

@ -8,8 +8,8 @@ import "C"
import "unsafe" import "unsafe"
// cptr returns C pointer // cptr returns C pointer
func (c *CharInfo) cptr() *C.CharInfo { func (c *GlyphInfo) cptr() *C.GlyphInfo {
return (*C.CharInfo)(unsafe.Pointer(c)) return (*C.GlyphInfo)(unsafe.Pointer(c))
} }
// cptr returns C pointer // cptr returns C pointer
@ -70,7 +70,7 @@ func LoadFontFromMemory(fileType string, fileData []byte, dataSize int32, fontSi
} }
// LoadFontData - Load font data for further use // LoadFontData - Load font data for further use
func LoadFontData(fileData []byte, dataSize int32, fontSize int32, fontChars *int32, charsCount, typ int32) *CharInfo { func LoadFontData(fileData []byte, dataSize int32, fontSize int32, fontChars *int32, charsCount, typ int32) *GlyphInfo {
cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0]))
cdataSize := (C.int)(dataSize) cdataSize := (C.int)(dataSize)
cfontSize := (C.int)(fontSize) cfontSize := (C.int)(fontSize)
@ -78,7 +78,7 @@ func LoadFontData(fileData []byte, dataSize int32, fontSize int32, fontChars *in
ccharsCount := (C.int)(charsCount) ccharsCount := (C.int)(charsCount)
ctype := (C.int)(typ) ctype := (C.int)(typ)
ret := C.LoadFontData(cfileData, cdataSize, cfontSize, cfontChars, ccharsCount, ctype) ret := C.LoadFontData(cfileData, cdataSize, cfontSize, cfontChars, ccharsCount, ctype)
v := newCharInfoFromPointer(unsafe.Pointer(&ret)) v := newGlyphInfoFromPointer(unsafe.Pointer(&ret))
return &v return &v
} }
@ -111,36 +111,6 @@ func DrawTextEx(font Font, text string, position Vector2, fontSize float32, spac
C.DrawTextEx(*cfont, ctext, *cposition, cfontSize, cspacing, *ctint) 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 // MeasureText - Measure string width for default font
func MeasureText(text string, fontSize int32) int32 { func MeasureText(text string, fontSize int32) int32 {
ctext := C.CString(text) ctext := C.CString(text)

View file

@ -22,7 +22,7 @@ func (i *Image) ToImage() image.Image {
// Get pixel data from image (RGBA 32bit) // Get pixel data from image (RGBA 32bit)
cimg := i.cptr() cimg := i.cptr()
ret := C.GetImageData(*cimg) ret := C.LoadImageColors(*cimg)
pixels := (*[1 << 24]uint8)(unsafe.Pointer(ret))[0 : i.Width*i.Height*4] pixels := (*[1 << 24]uint8)(unsafe.Pointer(ret))[0 : i.Width*i.Height*4]
img.Pix = pixels img.Pix = pixels
@ -127,17 +127,17 @@ func UnloadRenderTexture(target RenderTexture2D) {
C.UnloadRenderTexture(*ctarget) C.UnloadRenderTexture(*ctarget)
} }
// GetImageData - Get pixel data from image as a Color slice // LoadImageColors - Get pixel data from image as a Color slice
func GetImageData(img *Image) []Color { func LoadImageColors(img *Image) []Color {
cimg := img.cptr() cimg := img.cptr()
ret := C.GetImageData(*cimg) ret := C.LoadImageColors(*cimg)
return (*[1 << 24]Color)(unsafe.Pointer(ret))[0 : img.Width*img.Height] return (*[1 << 24]Color)(unsafe.Pointer(ret))[0 : img.Width*img.Height]
} }
// GetTextureData - Get pixel data from GPU texture and return an Image // LoadImageFromTexture - Get pixel data from GPU texture and return an Image
func GetTextureData(texture Texture2D) *Image { func LoadImageFromTexture(texture Texture2D) *Image {
ctexture := texture.cptr() ctexture := texture.cptr()
ret := C.GetTextureData(*ctexture) ret := C.LoadImageFromTexture(*ctexture)
v := newImageFromPointer(unsafe.Pointer(&ret)) v := newImageFromPointer(unsafe.Pointer(&ret))
return v return v
} }
@ -543,19 +543,6 @@ func GenImageWhiteNoise(width, height int, factor float32) *Image {
return v return v
} }
// GenImagePerlinNoise - Generate image: perlin noise
func GenImagePerlinNoise(width, height, offsetX, offsetY int, scale float32) *Image {
cwidth := (C.int)(width)
cheight := (C.int)(height)
coffsetX := (C.int)(offsetX)
coffsetY := (C.int)(offsetY)
cscale := (C.float)(scale)
ret := C.GenImagePerlinNoise(cwidth, cheight, coffsetX, coffsetY, cscale)
v := newImageFromPointer(unsafe.Pointer(&ret))
return v
}
// GenImageCellular - Generate image: cellular algorithm. Bigger tileSize means bigger cells // GenImageCellular - Generate image: cellular algorithm. Bigger tileSize means bigger cells
func GenImageCellular(width, height, tileSize int) *Image { func GenImageCellular(width, height, tileSize int) *Image {
cwidth := (C.int)(width) cwidth := (C.int)(width)