mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
examples/audio: Use DrawRect
This commit is contained in:
parent
27365161f0
commit
4a13267590
@ -43,18 +43,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
playerBarImage *ebiten.Image
|
playerBarColor = color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||||
playerCurrentImage *ebiten.Image
|
playerCurrentColor = color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
playerBarImage, _ = ebiten.NewImage(300, 4, ebiten.FilterNearest)
|
|
||||||
playerBarImage.Fill(&color.RGBA{0x80, 0x80, 0x80, 0xff})
|
|
||||||
|
|
||||||
playerCurrentImage, _ = ebiten.NewImage(4, 10, ebiten.FilterNearest)
|
|
||||||
playerCurrentImage.Fill(&color.RGBA{0xff, 0xff, 0xff, 0xff})
|
|
||||||
}
|
|
||||||
|
|
||||||
type Input struct {
|
type Input struct {
|
||||||
mouseButtonStates map[ebiten.MouseButton]int
|
mouseButtonStates map[ebiten.MouseButton]int
|
||||||
keyStates map[ebiten.Key]int
|
keyStates map[ebiten.Key]int
|
||||||
@ -103,7 +95,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func playerBarRect() (x, y, w, h int) {
|
func playerBarRect() (x, y, w, h int) {
|
||||||
w, h = playerBarImage.Size()
|
w, h = 300, 4
|
||||||
x = (screenWidth - w) / 2
|
x = (screenWidth - w) / 2
|
||||||
y = screenHeight - h - 16
|
y = screenHeight - h - 16
|
||||||
return
|
return
|
||||||
@ -245,10 +237,10 @@ func (p *Player) close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) draw(screen *ebiten.Image) {
|
func (p *Player) draw(screen *ebiten.Image) {
|
||||||
op := &ebiten.DrawImageOptions{}
|
// Bar
|
||||||
x, y, w, h := playerBarRect()
|
x, y, w, h := playerBarRect()
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
ebitenutil.DrawRect(screen, float64(x), float64(y), float64(w), float64(h), playerBarColor)
|
||||||
screen.DrawImage(playerBarImage, op)
|
|
||||||
currentTimeStr := "00:00"
|
currentTimeStr := "00:00"
|
||||||
|
|
||||||
// Current Time
|
// Current Time
|
||||||
@ -257,13 +249,11 @@ func (p *Player) draw(screen *ebiten.Image) {
|
|||||||
s := (c / time.Second) % 60
|
s := (c / time.Second) % 60
|
||||||
currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)
|
currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)
|
||||||
|
|
||||||
// Bar
|
// Cursor
|
||||||
cw, ch := playerCurrentImage.Size()
|
cw, ch := 4, 10
|
||||||
cx := int(time.Duration(w)*c/p.total) + x - cw/2
|
cx := int(time.Duration(w)*c/p.total) + x - cw/2
|
||||||
cy := y - (ch-h)/2
|
cy := y - (ch-h)/2
|
||||||
op = &ebiten.DrawImageOptions{}
|
ebitenutil.DrawRect(screen, float64(cx), float64(cy), float64(cw), float64(ch), playerCurrentColor)
|
||||||
op.GeoM.Translate(float64(cx), float64(cy))
|
|
||||||
screen.DrawImage(playerCurrentImage, op)
|
|
||||||
|
|
||||||
msg := fmt.Sprintf(`FPS: %0.2f
|
msg := fmt.Sprintf(`FPS: %0.2f
|
||||||
Press S to toggle Play/Pause
|
Press S to toggle Play/Pause
|
||||||
|
Loading…
Reference in New Issue
Block a user