remove device list
audio toggle is still not rendering
This commit is contained in:
+45
-117
@@ -8,23 +8,22 @@ import (
|
|||||||
"rhemawavetech.com/rhemawave/internal/colors"
|
"rhemawavetech.com/rhemawave/internal/colors"
|
||||||
"rhemawavetech.com/rhemawave/internal/db"
|
"rhemawavetech.com/rhemawave/internal/db"
|
||||||
"rhemawavetech.com/rhemawave/internal/fontManager"
|
"rhemawavetech.com/rhemawave/internal/fontManager"
|
||||||
"rhemawavetech.com/rhemawave/internal/mixer"
|
"rhemawavetech.com/rhemawave/internal/logger"
|
||||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AudioDevices struct {
|
type AudioDevices struct {
|
||||||
Base
|
Base
|
||||||
font *fontManager.FontEntry
|
font *fontManager.FontEntry
|
||||||
textShader *shaderManager.Shader
|
textShader *shaderManager.Shader
|
||||||
solidShader *shaderManager.Shader
|
solidShader *shaderManager.Shader
|
||||||
title StringItem
|
title StringItem
|
||||||
prompt StringItem
|
prompt StringItem
|
||||||
devices []StringItem
|
AudioStatusToggle StringItem
|
||||||
highlightIndex int
|
highlightIndex int
|
||||||
selectedIndex int
|
selectedIndex int
|
||||||
verticalMargin int32
|
verticalMargin int32
|
||||||
CfgPtr *db.AppConfig
|
CfgPtr *db.AppConfig
|
||||||
// DbPtr *gorm.DB
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AudioDevices) Init(ctx *PageCtx) error {
|
func (p *AudioDevices) Init(ctx *PageCtx) error {
|
||||||
@@ -76,32 +75,6 @@ func (p *AudioDevices) Init(ctx *PageCtx) error {
|
|||||||
}
|
}
|
||||||
p.prompt.Scale(itemScale)
|
p.prompt.Scale(itemScale)
|
||||||
|
|
||||||
// Get list of audio output devices
|
|
||||||
devices := mixer.ListDevices()
|
|
||||||
if len(devices) == 0 {
|
|
||||||
// Create a default entry so the page doesn't break
|
|
||||||
devices = []string{"System Default"}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get currently selected device from database
|
|
||||||
currentDevice := p.Context.CfgPtr.SelectedAudioDevice
|
|
||||||
|
|
||||||
// Create UI items for each device
|
|
||||||
for i, name := range devices { // Iterate over the devices
|
|
||||||
item, err := NewStringItem(name, p.font, colors.White) // Create a new string string texture
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create device item name: %w", err)
|
|
||||||
}
|
|
||||||
item.Scale(itemScale) // Scale the new string item
|
|
||||||
p.devices = append(p.devices, item) // Add the new scaled string item to the list of items
|
|
||||||
|
|
||||||
// Mark currently selected device
|
|
||||||
if name == currentDevice {
|
|
||||||
p.selectedIndex = i
|
|
||||||
p.highlightIndex = i // Start with cursor on current device
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
on := p.Context.CfgPtr.AudioEnabled
|
on := p.Context.CfgPtr.AudioEnabled
|
||||||
|
|
||||||
audioStatus := "Turn Audio On"
|
audioStatus := "Turn Audio On"
|
||||||
@@ -117,12 +90,26 @@ func (p *AudioDevices) Init(ctx *PageCtx) error {
|
|||||||
// Scale the new option
|
// Scale the new option
|
||||||
audioStatusStringItem.Scale(itemScale)
|
audioStatusStringItem.Scale(itemScale)
|
||||||
|
|
||||||
p.devices = append(p.devices, audioStatusStringItem)
|
|
||||||
|
|
||||||
p.layout()
|
p.layout()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *AudioDevices) CreateAudioStatusItem() error {
|
||||||
|
on := p.Context.CfgPtr.AudioEnabled
|
||||||
|
statusString := "Turn Audio Off" // The audio is ON
|
||||||
|
color := colors.Green
|
||||||
|
if !on {
|
||||||
|
statusString = "Turn Audio on"
|
||||||
|
color = colors.Red
|
||||||
|
}
|
||||||
|
audioStatusStringItem, err := NewStringItem(statusString, p.font, color)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create '%s' string item: %v", statusString, err)
|
||||||
|
}
|
||||||
|
p.AudioStatusToggle = audioStatusStringItem
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *AudioDevices) layout() {
|
func (p *AudioDevices) layout() {
|
||||||
// Position title at bottom
|
// Position title at bottom
|
||||||
p.title.X = p.ScreenCenterX - p.title.W/2
|
p.title.X = p.ScreenCenterX - p.title.W/2
|
||||||
@@ -131,16 +118,6 @@ func (p *AudioDevices) layout() {
|
|||||||
// Position prompt above title
|
// Position prompt above title
|
||||||
p.prompt.X = p.ScreenCenterX - p.prompt.W/2
|
p.prompt.X = p.ScreenCenterX - p.prompt.W/2
|
||||||
p.prompt.Y = p.title.Y - p.verticalMargin*2 - p.prompt.H
|
p.prompt.Y = p.title.Y - p.verticalMargin*2 - p.prompt.H
|
||||||
|
|
||||||
// Position device items stacked upward from prompt
|
|
||||||
for i := range p.devices {
|
|
||||||
p.devices[i].X = p.ScreenCenterX - p.devices[i].W/2
|
|
||||||
if i == 0 {
|
|
||||||
p.devices[i].Y = p.prompt.Y - p.verticalMargin*2 - p.devices[i].H
|
|
||||||
} else {
|
|
||||||
p.devices[i].Y = p.devices[i-1].Y - p.devices[i].H - 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
||||||
@@ -150,45 +127,16 @@ func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch e.Keysym.Sym {
|
switch e.Keysym.Sym {
|
||||||
case sdl.K_UP:
|
|
||||||
if p.highlightIndex > 0 {
|
|
||||||
p.highlightIndex--
|
|
||||||
}
|
|
||||||
|
|
||||||
case sdl.K_DOWN:
|
|
||||||
if p.highlightIndex < len(p.devices)-1 {
|
|
||||||
p.highlightIndex++
|
|
||||||
}
|
|
||||||
|
|
||||||
case sdl.K_RETURN:
|
case sdl.K_RETURN:
|
||||||
selection := p.devices[p.highlightIndex].content
|
// Toggle AudioEnabled
|
||||||
|
p.Context.CfgPtr.AudioEnabled = !p.Context.CfgPtr.AudioEnabled
|
||||||
// Handle audio disable
|
// Save the config to the database
|
||||||
if selection == "Turn Audio Off" || selection == "Turn Audio On" {
|
|
||||||
newStatus := !p.Context.CfgPtr.AudioEnabled
|
|
||||||
updatedConfig := p.Context.CfgPtr
|
|
||||||
updatedConfig.AudioEnabled = newStatus
|
|
||||||
p.Context.DbPtr.Save(&updatedConfig)
|
|
||||||
p.Context.RefreshConfig()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map "System Default" to empty string for SDL
|
|
||||||
deviceName := selection
|
|
||||||
if selection == "System Default" {
|
|
||||||
deviceName = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate by attempting the switch
|
|
||||||
if err := mixer.SwitchDevice(deviceName); err != nil {
|
|
||||||
return fmt.Errorf("failed to switch to device %q: %w", selection, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save settings
|
|
||||||
p.Context.CfgPtr.SelectedAudioDevice = deviceName
|
|
||||||
p.Context.CfgPtr.AudioEnabled = true
|
|
||||||
p.Context.DbPtr.Save(p.Context.CfgPtr)
|
p.Context.DbPtr.Save(p.Context.CfgPtr)
|
||||||
|
// Refresh the config throughout the application
|
||||||
p.Context.RefreshConfig()
|
p.Context.RefreshConfig()
|
||||||
|
// Update AudioEnabled UI element
|
||||||
|
|
||||||
case sdl.K_BACKSPACE:
|
case sdl.K_BACKSPACE:
|
||||||
p.Context.NavigateTo(SETTINGS)
|
p.Context.NavigateTo(SETTINGS)
|
||||||
}
|
}
|
||||||
@@ -198,43 +146,23 @@ func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
|||||||
|
|
||||||
func (p *AudioDevices) Render() error {
|
func (p *AudioDevices) Render() error {
|
||||||
// Always render title and prompt
|
// Always render title and prompt
|
||||||
p.RenderTexture(p.textShader, p.title.ID, p.title.Position(), p.title.RawDimensions(), p.title.Color)
|
if err := p.RenderTexture(p.textShader, p.title.ID, p.title.Position(), p.title.RawDimensions(), p.title.Color); err != nil {
|
||||||
p.RenderTexture(p.textShader, p.prompt.ID, p.prompt.Position(), p.prompt.RawDimensions(), p.prompt.Color)
|
logger.Error("unable to render title texture: %v", err)
|
||||||
|
return fmt.Errorf("unable to render title texture: %w", err)
|
||||||
// Render highlight box behind highlighted item
|
}
|
||||||
//p.RenderSolidColorQuad(
|
if err := p.RenderTexture(p.textShader, p.prompt.ID, p.prompt.Position(), p.prompt.RawDimensions(), p.prompt.Color); err != nil {
|
||||||
// p.solidShader,
|
logger.Error("unable to render prompt texture: %v", err)
|
||||||
// p.devices[p.highlightIndex].Position(),
|
return fmt.Errorf("unable to render prompt texture: %w", err)
|
||||||
// p.devices[p.highlightIndex].RawDimensions(),
|
}
|
||||||
// colors.White,
|
if err := p.RenderTexture(p.textShader, p.AudioStatusToggle.ID, p.AudioStatusToggle.Position(), p.AudioStatusToggle.RawDimensions(), p.AudioStatusToggle.Color); err != nil {
|
||||||
//)
|
logger.Error("unable to render audioStatusToggle texture: %v", err)
|
||||||
|
return fmt.Errorf("unable to render audioStatusToggle texture: %w", err)
|
||||||
// Render device items with appropriate colors
|
}
|
||||||
//for i, item := range p.devices {
|
|
||||||
// if i == p.highlightIndex && i == p.selectedIndex {
|
|
||||||
// // Currently highlighted AND selected device - dark green
|
|
||||||
// item.Color = colors.DarkGreen
|
|
||||||
// } else if i == p.highlightIndex {
|
|
||||||
// // Just highlighted - black (shows on white background)
|
|
||||||
// item.Color = colors.Black
|
|
||||||
// } else if i == p.selectedIndex {
|
|
||||||
// // Just selected - green
|
|
||||||
// item.Color = colors.Green
|
|
||||||
// } else {
|
|
||||||
// // Normal item - white
|
|
||||||
// item.Color = colors.White
|
|
||||||
// }
|
|
||||||
// p.RenderTexture(p.textShader, item.ID, item.Position(), item.RawDimensions(), item.Color)
|
|
||||||
//}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AudioDevices) Destroy() error {
|
func (p *AudioDevices) Destroy() error {
|
||||||
gl.DeleteTextures(1, &p.title.ID)
|
gl.DeleteTextures(1, &p.title.ID)
|
||||||
gl.DeleteTextures(1, &p.prompt.ID)
|
gl.DeleteTextures(1, &p.prompt.ID)
|
||||||
for _, item := range p.devices {
|
|
||||||
gl.DeleteTextures(1, &item.ID)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user