updated to raylib
This commit is contained in:
parent
f82fa6ef37
commit
84fe6fe9eb
18 changed files with 1065 additions and 1130 deletions
118
ui.go
Normal file
118
ui.go
Normal file
|
@ -0,0 +1,118 @@
|
|||
package main
|
||||
|
||||
import rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
type ColorOption struct {
|
||||
Name string
|
||||
Color rl.Color
|
||||
}
|
||||
|
||||
type ThemeOption struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type LayoutOption struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func drawRoundedRect(r rl.Rectangle, roundness float32, col rl.Color) {
|
||||
segments := int32(8)
|
||||
rl.DrawRectangleRounded(r, roundness, segments, col)
|
||||
}
|
||||
|
||||
func drawRoundedRectButton(r rl.Rectangle, text string, alpha float32, hovered bool) {
|
||||
r.X += 0.5
|
||||
r.Y += 0.5
|
||||
r.Width -= 1.0
|
||||
r.Height -= 1.0
|
||||
|
||||
col := applyAlpha(rl.White, 0.1)
|
||||
if hovered {
|
||||
col = applyAlpha(rl.White, 0.3)
|
||||
}
|
||||
lineCol := applyAlpha(rl.White, 1.0)
|
||||
textCol := applyAlpha(rl.RayWhite, alpha)
|
||||
|
||||
roundness := float32(0.3)
|
||||
rl.DrawRectangleRounded(r, roundness, 8, col)
|
||||
rl.DrawRectangleRoundedLines(r, roundness, 8, lineCol)
|
||||
|
||||
txW := rl.MeasureText(text, 20)
|
||||
rl.DrawText(text, int32(r.X+(r.Width-float32(txW))/2),
|
||||
int32(r.Y+(r.Height-20)/2), 20, textCol)
|
||||
}
|
||||
|
||||
func drawRectButtonAlpha(r rl.Rectangle, text string, alpha float32) {
|
||||
hovered := overRect(rl.GetMousePosition(), r)
|
||||
drawRoundedRectButton(r, text, alpha, hovered)
|
||||
}
|
||||
|
||||
func drawButton(text string, x, y, w, h int32, mousePos rl.Vector2) {
|
||||
r := rl.Rectangle{X: float32(x), Y: float32(y), Width: float32(w), Height: float32(h)}
|
||||
hovered := overRect(mousePos, r)
|
||||
drawRoundedRectButton(r, text, 1.0, hovered)
|
||||
}
|
||||
|
||||
func drawColorCircleAlpha(x, y float32, col rl.Color, selected bool, alpha float32) {
|
||||
baseCol := applyAlpha(col, alpha)
|
||||
darkCol := applyAlpha(rl.Color{
|
||||
R: uint8(float32(col.R) * 0.8),
|
||||
G: uint8(float32(col.G) * 0.8),
|
||||
B: uint8(float32(col.B) * 0.8),
|
||||
A: col.A,
|
||||
}, alpha)
|
||||
rl.DrawCircleGradient(int32(x), int32(y), 8, baseCol, darkCol)
|
||||
if selected {
|
||||
rl.DrawCircleLines(int32(x), int32(y), 8, applyAlpha(rl.White, alpha))
|
||||
} else if overCircle(rl.GetMousePosition(), rl.Vector2{X: x, Y: y}, 8) {
|
||||
rl.DrawCircleLines(int32(x), int32(y), 8, applyAlpha(rl.Fade(rl.White, 0.5), alpha))
|
||||
}
|
||||
}
|
||||
|
||||
func drawThemeBoxAlpha(x, y float32, label string, selected bool, alpha float32) {
|
||||
rect := rl.Rectangle{X: x - 50, Y: y - 20, Width: 100, Height: 40}
|
||||
hovered := overRect(rl.GetMousePosition(), rect)
|
||||
|
||||
col := applyAlpha(rl.White, 0.1*alpha)
|
||||
if hovered {
|
||||
col = applyAlpha(rl.White, 0.3*alpha)
|
||||
}
|
||||
lineCol := applyAlpha(rl.White, alpha)
|
||||
textCol := applyAlpha(rl.RayWhite, alpha)
|
||||
|
||||
drawRoundedRect(rect, 0.3, col)
|
||||
rl.DrawRectangleRoundedLines(rect, 0.3, 8, lineCol)
|
||||
|
||||
txW := rl.MeasureText(label, 20)
|
||||
rl.DrawTextEx(rl.GetFontDefault(), label,
|
||||
rl.Vector2{X: float32(int32(x) - txW/2), Y: float32(int32(y) - 10)}, 20, 1, textCol)
|
||||
if selected {
|
||||
rl.DrawRectangleRoundedLines(rect, 0.3, 8, lineCol)
|
||||
}
|
||||
}
|
||||
|
||||
func drawLayoutOptionAlpha(x, y float32, label string, selected bool, alpha float32) {
|
||||
rect := rl.Rectangle{X: x - 60, Y: y - 20, Width: 120, Height: 40}
|
||||
hovered := overRect(rl.GetMousePosition(), rect)
|
||||
col := applyAlpha(rl.White, 0.1*alpha)
|
||||
if hovered {
|
||||
col = applyAlpha(rl.White, 0.3*alpha)
|
||||
}
|
||||
lineCol := applyAlpha(rl.White, alpha)
|
||||
textCol := applyAlpha(rl.RayWhite, alpha)
|
||||
|
||||
drawRoundedRect(rect, 0.3, col)
|
||||
rl.DrawRectangleRoundedLines(rect, 0.3, 8, lineCol)
|
||||
|
||||
txW := rl.MeasureText(label, 20)
|
||||
rl.DrawTextEx(rl.GetFontDefault(), label,
|
||||
rl.Vector2{X: float32(int32(x) - txW/2), Y: float32(int32(y) - 10)}, 20, 1, textCol)
|
||||
if selected {
|
||||
rl.DrawRectangleRoundedLines(rect, 0.3, 8, lineCol)
|
||||
}
|
||||
}
|
||||
|
||||
func applyAlpha(c rl.Color, alpha float32) rl.Color {
|
||||
c.A = uint8(float32(c.A) * alpha)
|
||||
return c
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue