76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.sr.ht/~tslocum/cview"
|
|
"github.com/faiface/beep/speaker"
|
|
"github.com/gdamore/tcell"
|
|
)
|
|
|
|
func handleMouse(event *cview.EventMouse) *cview.EventMouse {
|
|
if event.Action()&cview.MouseDown != 0 && event.Buttons()&tcell.Button1 != 0 {
|
|
mouseX, mouseY := event.Position()
|
|
if mouseY > 0 && mouseY < mainBufHeight+1 {
|
|
// TODO Delay playing while cursor is moved
|
|
if mouseY-1 < len(mainBufferFiles)+1 {
|
|
mainBufferCursor = mainBufferOrigin + (mouseY - 1)
|
|
go selectTrack()
|
|
}
|
|
return nil
|
|
} else if mouseY == screenHeight-1 {
|
|
if mouseX >= seekStart && mouseX <= seekEnd {
|
|
if strings.ToLower(path.Ext(playingFileName)) == ".flac" {
|
|
statusText = "Seeking FLAC files is unsupported"
|
|
go func() {
|
|
time.Sleep(5 * time.Second)
|
|
statusText = ""
|
|
app.QueueUpdateDraw(updateMain)
|
|
}()
|
|
app.QueueUpdateDraw(updateMain)
|
|
|
|
return nil
|
|
}
|
|
|
|
speaker.Lock()
|
|
seekTo := int(float64(playingStreamer.Len()) * (float64(mouseX-seekStart) / float64(seekEnd-seekStart)))
|
|
_ = playingStreamer.Seek(seekTo) // Ignore seek errors
|
|
speaker.Unlock()
|
|
app.QueueUpdateDraw(updateStatus)
|
|
return nil
|
|
} else if mouseX >= volumeStart && mouseX <= volumeEnd+1 {
|
|
if mouseX > volumeEnd {
|
|
mouseX = volumeEnd
|
|
}
|
|
|
|
if mouseX-volumeStart <= 3 {
|
|
speaker.Lock()
|
|
volume.Silent = !volume.Silent
|
|
speaker.Unlock()
|
|
app.QueueUpdateDraw(updateStatus)
|
|
} else {
|
|
speaker.Lock()
|
|
setVolume := -7.5 + float64(7.5)*(float64(mouseX-volumeStart-3)/float64(volumeEnd-volumeStart-3))
|
|
if setVolume < -7.0 {
|
|
setVolume = -7.0
|
|
}
|
|
|
|
volume.Volume = roundUnit(setVolume, 0.5)
|
|
if volume.Volume > 0 {
|
|
volume.Volume = 0
|
|
}
|
|
|
|
volume.Silent = setVolume <= -7.5
|
|
|
|
speaker.Unlock()
|
|
app.QueueUpdateDraw(updateStatus)
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return event
|
|
}
|