Alertbox added.
This commit is contained in:
49
elements/alert.go
Normal file
49
elements/alert.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"fluids/fonts"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
AlertWidth = 50
|
||||
AlertHeight = 150
|
||||
)
|
||||
|
||||
type Alert struct {
|
||||
Sprite *ebiten.Image
|
||||
text string
|
||||
textfacesource *text.GoTextFaceSource
|
||||
}
|
||||
|
||||
func NewAlert() *Alert {
|
||||
a := &Alert{
|
||||
Sprite: ebiten.NewImage(AlertWidth, AlertHeight),
|
||||
textfacesource: fonts.PixelFont,
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Alert) Draw() {
|
||||
a.Sprite.Clear()
|
||||
|
||||
fnt := &text.GoTextFace{
|
||||
Source: a.textfacesource,
|
||||
Size: 20,
|
||||
}
|
||||
|
||||
_, h := text.Measure(a.text, fnt, 0)
|
||||
top := &text.DrawOptions{}
|
||||
top.GeoM.Translate(0, h)
|
||||
text.Draw(a.Sprite, a.text, fnt, top)
|
||||
}
|
||||
|
||||
func (a *Alert) Update() {
|
||||
|
||||
}
|
||||
|
||||
func (a *Alert) SetText(t string) {
|
||||
a.text = t
|
||||
}
|
||||
Reference in New Issue
Block a user