Optimization and ready jump to godot

This commit is contained in:
2024-07-19 10:55:05 +08:00
parent 3fd38c73b6
commit b67353c1ae
6 changed files with 36 additions and 25 deletions

View File

@@ -2,7 +2,6 @@ package ui
import (
"git.solsynth.dev/highland/codingland/pkg/internal/land"
"git.solsynth.dev/highland/codingland/pkg/internal/land/renderer"
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/ttf"
"log"
@@ -20,6 +19,10 @@ type ButtonWidget struct {
}
func (p *ButtonWidget) Draw(pen *sdl.Renderer) {
if !p.BaseWidget.IsVisible {
return
}
var borderColor, bgColor sdl.Color
if p.isClicking {
borderColor = sdl.Color{R: 200, G: 0, B: 0, A: 255}
@@ -35,18 +38,19 @@ func (p *ButtonWidget) Draw(pen *sdl.Renderer) {
var borderWidth int32 = 2
pen.SetDrawColor(borderColor.R, borderColor.G, borderColor.B, borderColor.A)
renderer.FillRoundedRect(pen, &sdl.Rect{
pen.FillRect(&sdl.Rect{
X: int32(p.Position.X),
Y: int32(p.Position.Y),
W: int32(p.Size.X),
H: int32(p.Size.Y),
}, borderColor, 16)
renderer.FillRoundedRect(pen, &sdl.Rect{
})
pen.SetDrawColor(bgColor.R, bgColor.G, bgColor.B, bgColor.A)
pen.FillRect(&sdl.Rect{
X: int32(p.Position.X) + borderWidth/2,
Y: int32(p.Position.Y) + borderWidth/2,
W: int32(p.Size.X) - borderWidth,
H: int32(p.Size.Y) - borderWidth,
}, bgColor, 16)
})
surface, err := p.Font.RenderUTF8Blended(p.Label, sdl.Color{R: 255, G: 255, B: 255, A: 255})
if err != nil {