Checkpoint
This commit is contained in:
160 files changed
+76293
-387
No files matched your search
+147
@@ -0,0 +1,147 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"time"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/BeatGlow/beatglow/ui/widget"
|
||||
"github.com/BeatGlow/display"
|
||||
"github.com/BeatGlow/display/draw"
|
||||
|
||||
_ "embed" // Embed binary files
|
||||
)
|
||||
|
||||
var (
|
||||
logoBG = color.RGBA{R: 0x11, G: 0xff, B: 0xe3, A: 0xff}
|
||||
logoFG = color.RGBA{R: 0x8a, G: 0x00, B: 0xc4, A: 0xff}
|
||||
)
|
||||
|
||||
// Boot renders the boot splash.
|
||||
func Boot(dst display.Display) error {
|
||||
logrus.WithField("display", dst).Info("Welcome to BeatGlow!")
|
||||
|
||||
var (
|
||||
styles = StylesFor(dst.ColorModel())
|
||||
bounds = dst.Bounds()
|
||||
width = bounds.Dx()
|
||||
height = bounds.Dy()
|
||||
canvas = image.NewRGBA(bounds)
|
||||
)
|
||||
logrus.Infof("styles: %#+v", styles)
|
||||
|
||||
draw.Draw(canvas, bounds, styles.Boot.Background, image.Point{}, draw.Src)
|
||||
if err := dst.Refresh(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fontSize := 24.0
|
||||
switch {
|
||||
case height >= 64:
|
||||
fontSize = 36.0
|
||||
case height >= 128:
|
||||
fontSize = 48.0
|
||||
}
|
||||
|
||||
font := styles.Boot.Font.WithPointSize(fontSize)
|
||||
logoTextWidth, logoTextHeight := font.MeasureText("beatglow")
|
||||
logoText := widget.NewText(image.Point{}, font, image.NewUniform(styles.Boot.Foreground), "beatglow")
|
||||
logoText.Position = bounds.Size()
|
||||
logoText.Position.X /= 2
|
||||
logoText.Position.Y /= 2
|
||||
logoText.Position.X -= logoTextWidth / 2
|
||||
logoText.Position.Y -= logoTextHeight / 2
|
||||
logoText.Render(dst)
|
||||
|
||||
border := bounds
|
||||
border.Max.X--
|
||||
border.Max.Y--
|
||||
draw.Rectangle(dst, border, color.White)
|
||||
|
||||
if err := dst.Refresh(); err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
|
||||
var (
|
||||
logoTextStep image.Point
|
||||
logoTextStop image.Point
|
||||
logoLoveMaxX uint
|
||||
logoLoveMaxY uint
|
||||
logoLovePosition image.Point
|
||||
logoLoveCenterX bool
|
||||
logoLoveCenterY bool
|
||||
)
|
||||
switch {
|
||||
case width == 256 && height == 64:
|
||||
// Side by side
|
||||
logoTextStep = image.Pt(-1, 0)
|
||||
logoTextStop = image.Pt(2, logoText.Position.Y)
|
||||
logoLoveMaxX = uint(width) / 2
|
||||
logoLoveMaxY = uint(height)
|
||||
logoLovePosition = image.Pt((width/4)*3, height/2) // center right
|
||||
logoLoveCenterX = true
|
||||
default:
|
||||
// Scroll up
|
||||
logoTextStep = image.Pt(0, -1)
|
||||
logoTextStop = image.Pt(logoText.Position.X, 0)
|
||||
logoLoveMaxX = uint(width)
|
||||
logoLoveMaxY = uint(height / 2)
|
||||
logoLovePosition = image.Pt(width/2, (height/4)*3) // bottom
|
||||
logoLoveCenterY = true
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(10 * time.Millisecond)
|
||||
for ; !logoText.Position.Eq(logoTextStop); logoText.Position = logoText.Position.Add(logoTextStep) {
|
||||
draw.Draw(canvas, bounds, styles.Boot.Background, image.Point{}, draw.Src) // clear canvas
|
||||
logoText.Render(canvas) // render logo
|
||||
draw.Draw(dst, bounds, canvas, image.Point{}, draw.Src) // canvas to display
|
||||
dst.Refresh() // display refresh
|
||||
<-ticker.C
|
||||
}
|
||||
ticker.Stop()
|
||||
|
||||
logrus.Info("BeatGlow 💖 Volumio")
|
||||
logoLove := resize.Thumbnail(logoLoveMaxX, logoLoveMaxY, logoVolumio, resize.Lanczos3)
|
||||
|
||||
//draw.Draw(canvas, bounds, image.NewUniform(color.Black), image.Point{}, draw.Src)
|
||||
if logoLoveCenterX {
|
||||
logoLovePosition.X -= logoLove.Bounds().Dx() / 2
|
||||
}
|
||||
if logoLoveCenterY {
|
||||
logoLovePosition.Y -= logoLove.Bounds().Dy() / 2
|
||||
}
|
||||
draw.Draw(canvas, bounds.Add(logoLovePosition), logoLove, image.Point{}, draw.Src)
|
||||
draw.Draw(dst, bounds, canvas, image.Point{}, draw.Src)
|
||||
|
||||
if err := dst.Refresh(); err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mustDecodePNG(b []byte) image.Image {
|
||||
i, err := png.Decode(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var (
|
||||
logoVolumio = mustDecodePNG(logoVolumioPNG)
|
||||
logoMoode = mustDecodePNG(logoMoodePNG)
|
||||
)
|
||||
|
||||
//go:embed asset/logo-volumio.png
|
||||
var logoVolumioPNG []byte
|
||||
|
||||
//go:embed asset/logo-moode.png
|
||||
var logoMoodePNG []byte
|
||||
Reference in new issue
Block a user