aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-10-07 21:35:16 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-10-08 10:48:55 +0200
commit0bc5bd306f274aa60b075fd8e0167e1ee4f28845 (patch)
tree9ebe8abd51efb2653212ddab91179bb51614b064
parentd4a314f5e2e0e11a1bb30728b47d70ea56a75771 (diff)
downloadmuhqs-game-0bc5bd306f274aa60b075fd8e0167e1ee4f28845.tar.gz
muhqs-game-0bc5bd306f274aa60b075fd8e0167e1ee4f28845.zip
switch to new vector API for drawing paths
-rw-r--r--go/ui/button.go4
-rw-r--r--go/ui/mapView.go37
-rw-r--r--go/ui/spinner.go24
3 files changed, 8 insertions, 57 deletions
diff --git a/go/ui/button.go b/go/ui/button.go
index 5bda91aa..42cbe304 100644
--- a/go/ui/button.go
+++ b/go/ui/button.go
@@ -63,7 +63,7 @@ func (b *SimpleButton) drawLabel(img *ebiten.Image) {
func (b *SimpleButton) renderRect() *ebiten.Image {
img := ebiten.NewImage(b.Width, b.Height)
- vector.DrawFilledRect(img, float32(0), float32(0), float32(b.Width), float32(b.Height), b.Bg, false)
+ vector.FillRect(img, float32(0), float32(0), float32(b.Width), float32(b.Height), b.Bg, false)
b.drawLabel(img)
return img
}
@@ -71,7 +71,7 @@ func (b *SimpleButton) renderRect() *ebiten.Image {
func (b *SimpleButton) renderCircle() *ebiten.Image {
img := ebiten.NewImage(b.Width, b.Height)
- vector.DrawFilledCircle(img, float32(b.Width)/2, float32(b.Height)/2, float32(b.Width/2), b.Bg, false)
+ vector.FillCircle(img, float32(b.Width)/2, float32(b.Height)/2, float32(b.Width/2), b.Bg, false)
b.drawLabel(img)
return img
}
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 169aaaf3..051c216f 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -2,7 +2,6 @@ package ui
import (
"fmt"
- "image"
"image/color"
"math"
"unicode"
@@ -14,20 +13,6 @@ import (
"muhq.space/muhqs-game/go/log"
)
-var (
- // No idea why image.DrawTrianglesOptions needs this it is copied from
- // the ebiten vector example.
- whiteImage = ebiten.NewImage(3, 3)
-
- // whiteSubImage is an internal sub image of whiteImage.
- // Use whiteSubImage at DrawTriangles instead of whiteImage in order to avoid bleeding edges.
- whiteSubImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
-)
-
-func init() {
- whiteImage.Fill(color.White)
-}
-
const (
PERMANENT_WIDTH int = 40
PERMANENT_HEIGHT int = 40
@@ -353,25 +338,9 @@ func drawPileHint(screen *ebiten.Image) {
path.LineTo(PILE_HINT_STARTX+PILE_HINT_LENGTH, y)
path.Close()
}
-
- var vs []ebiten.Vertex
- var is []uint16
- {
- op := &vector.StrokeOptions{Width: PILE_HINT_WIDTH}
- vs, is = path.AppendVerticesAndIndicesForStroke(nil, nil, op)
- }
-
- for i := range vs {
- vs[i].SrcX = 1
- vs[i].SrcY = 1
- vs[i].ColorR = 0
- vs[i].ColorG = 0
- vs[i].ColorB = 0
- vs[i].ColorA = 1
- }
-
- op := &ebiten.DrawTrianglesOptions{AntiAlias: true}
- screen.DrawTriangles(vs, is, whiteSubImage, op)
+ strokeOp := &vector.StrokeOptions{Width: PILE_HINT_WIDTH}
+ drawOp := &vector.DrawPathOptions{AntiAlias: true}
+ vector.StrokePath(screen, &path, strokeOp, drawOp)
}
func (vw *MapView) Draw(screen *ebiten.Image) {
diff --git a/go/ui/spinner.go b/go/ui/spinner.go
index 083ec292..e00fcc02 100644
--- a/go/ui/spinner.go
+++ b/go/ui/spinner.go
@@ -52,26 +52,8 @@ func (s *Spinner) render() *ebiten.Image {
strokeOp := &vector.StrokeOptions{}
strokeOp.Width = float32(SPINNER_DEFAULT_STROKE)
- vertices := []ebiten.Vertex{}
- indices := []uint16{}
- vertices, indices = path.AppendVerticesAndIndicesForStroke(vertices, indices, strokeOp)
-
- {
- r, g, b, a := s.fg.RGBA()
- for i := range vertices {
- vertices[i].SrcX = 1
- vertices[i].SrcY = 1
- vertices[i].ColorR = float32(r)
- vertices[i].ColorG = float32(g)
- vertices[i].ColorB = float32(b)
- vertices[i].ColorA = float32(a)
- }
- }
-
- op := &ebiten.DrawTrianglesOptions{}
- op.AntiAlias = true
- op.FillRule = ebiten.FillRuleNonZero
- op.ColorScaleMode = ebiten.ColorScaleModePremultipliedAlpha
- img.DrawTriangles(vertices, indices, whiteSubImage, op)
+ drawOp := &vector.DrawPathOptions{}
+ drawOp.AntiAlias = true
+ vector.StrokePath(img, &path, strokeOp, drawOp)
return img
}