mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
sound and brightenss
This commit is contained in:
parent
b7ad646046
commit
e45800dfe2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
test
|
test
|
||||||
main
|
main
|
||||||
|
*.so
|
||||||
|
|||||||
Binary file not shown.
252
Menu/GameShell/10_Settings/Brightness/brightness_page.go
Normal file
252
Menu/GameShell/10_Settings/Brightness/brightness_page.go
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
"github.com/cuu/gogame/event"
|
||||||
|
"github.com/cuu/LauncherGo/sysgo"
|
||||||
|
"github.com/cuu/LauncherGo/sysgo/UI"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OnChangeCB_T func(int)
|
||||||
|
|
||||||
|
type SliderIcon struct {
|
||||||
|
UI.IconItem
|
||||||
|
Parent *BSlider
|
||||||
|
|
||||||
|
}
|
||||||
|
func NewSliderIcon() *SliderIcon {
|
||||||
|
p := &UI.SliderIcon{}
|
||||||
|
p.MyType = ICON_TYPES["EXE"]
|
||||||
|
p.Align = ALIGN["VCenter"]
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type SliderMultiIcon struct {
|
||||||
|
UI.MultiIconItem
|
||||||
|
Parent *SoundSlider
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSliderMultiIcon() *SliderMultiIcon {
|
||||||
|
p := &SliderMultiIcon{}
|
||||||
|
p.MyType = ICON_TYPES["EXE"]
|
||||||
|
p.Align = ALIGN["VCenter"]
|
||||||
|
|
||||||
|
p.IconIndex = 0
|
||||||
|
p.IconWidth = 18
|
||||||
|
p.IconHeight = 18
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type BSlider struct {
|
||||||
|
UI.Slider
|
||||||
|
|
||||||
|
BGpng *SliderIcon
|
||||||
|
BGwidth int
|
||||||
|
BGheight int
|
||||||
|
NeedleSurf
|
||||||
|
Scale *SliderMultiIcon
|
||||||
|
Parent *BrightnessPage
|
||||||
|
|
||||||
|
OnChangeCB OnChangeCB_T
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBSlider() *BSlider {
|
||||||
|
p := &SoundSlider{}
|
||||||
|
p.Range = [2]int{0,255}
|
||||||
|
p.Value = 0
|
||||||
|
|
||||||
|
p.BGwidth = 179
|
||||||
|
p.BGheight = 153
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BSlider) Init() {
|
||||||
|
|
||||||
|
self.Width = self.Parent.Width
|
||||||
|
self.Height = self.Parent.Height
|
||||||
|
|
||||||
|
self.BGpng = NewSliderIcon()
|
||||||
|
self.BGpng.ImgSurf = UI.MyIconPool.GetImgSurf("vol")
|
||||||
|
self.BGpng.MyType = UI.ICON_TYPES["STAT"]
|
||||||
|
self.BGpng.Parent = self
|
||||||
|
self.BGpng.Adjust(0,0,self.BGwidth,self.BGheight,0)
|
||||||
|
|
||||||
|
self.Scale = NewSliderMultiIcon()
|
||||||
|
self.Scale.MyType = UI.ICON_TYPES["STAT"]
|
||||||
|
self.Scale.Parent = self
|
||||||
|
self.Scale.ImgSurf = UI.MyIconPool.GetImgSurf("scale")
|
||||||
|
self.Scale.IconWidth = 82
|
||||||
|
self.Scale.IconHeight = 63
|
||||||
|
self.Scale.Adjust(0,0,82,63,0)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BSlider) SetValue( brt int) {
|
||||||
|
self.Value = brt
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BSlider) Further() {
|
||||||
|
self.Value += 1
|
||||||
|
|
||||||
|
if self.Value > 9 {
|
||||||
|
self.Value = 9
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.OnChangeCB != nil {
|
||||||
|
self.OnChangeCB(self.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BSlider) StepBack() {
|
||||||
|
self.Value -= 1
|
||||||
|
|
||||||
|
if self.Value < 0 {
|
||||||
|
self.Value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.OnChangeCB != nil {
|
||||||
|
self.OnChangeCB(self.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BSlider) Draw() {
|
||||||
|
self.BGpng.NewCoord(self.Width/2,self.Height/2+11)
|
||||||
|
self.BGpng.Draw()
|
||||||
|
|
||||||
|
self.Scale.NewCoord(self.Width/2,self.Height/2)
|
||||||
|
|
||||||
|
icon_idx := self.Value-1
|
||||||
|
if icon_idx <0 {
|
||||||
|
icon_idx = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Scale.IconIndex = icon_idx
|
||||||
|
self.Scale.Draw()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrightnessPage struct {
|
||||||
|
UI.Page
|
||||||
|
MySlider *BSlider
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBrightnessPage() *BrightnessPage {
|
||||||
|
p:= &BrightnessPage{}
|
||||||
|
|
||||||
|
p.PageIconMargin = 20
|
||||||
|
p.SelectedIconTopOffset = 20
|
||||||
|
p.EasingDur = 10
|
||||||
|
p.Align = UI.ALIGN["SLeft"]
|
||||||
|
|
||||||
|
p.FootMsg = [5]string{"Nav","","","Back","Enter"}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) Init() {
|
||||||
|
self.CanvasHWND = self.Screen.CanvasHWND
|
||||||
|
self.Width = self.Screen.Width
|
||||||
|
self.Height = self.Screen.Height
|
||||||
|
|
||||||
|
self.MySlider = NewBSlider()
|
||||||
|
|
||||||
|
self.MySlider.Parent = self
|
||||||
|
|
||||||
|
self.MySlider.SetCanvasHWND(self.CanvasHWND)
|
||||||
|
self.MySlider.OnChangeCB = self.WhenSliderDrag
|
||||||
|
|
||||||
|
self.MySlider.Init()
|
||||||
|
|
||||||
|
brt := self.ReadBackLight()
|
||||||
|
|
||||||
|
self.MySlider.SetValue(brt)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) ReadBackLight() int {
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) == false {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
lines,err := UI.ReadLines(sysgo.BackLight)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for _,v := range lines {
|
||||||
|
n,e := strconv.Atoi(v)
|
||||||
|
if e == nil {
|
||||||
|
return n
|
||||||
|
}else {
|
||||||
|
fmt.Println(e)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) OnLoadCb() {
|
||||||
|
brt := self.ReadBackLight()
|
||||||
|
|
||||||
|
self.MySlider.SetValue(brt)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) SetBackLight( newbrt int){
|
||||||
|
|
||||||
|
newbrt_str := fmt.Sprintf("%d",newbrt)
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) {
|
||||||
|
err:= ioutil.WriteFile(sysgo.BackLight,[]byte(newbrt_str),0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
fmt.Println(sysgo.BackLight, " file not existed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) WhenSliderDrag( val int) {
|
||||||
|
self.SetBackLight(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) KeyDown(ev *event.Event) {
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
|
||||||
|
self.ReturnToUpLevelPage()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["Right"] {
|
||||||
|
self.MySlider.Further()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["Left"] {
|
||||||
|
self.MySlider.StepBack()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPage) Draw() {
|
||||||
|
|
||||||
|
self.ClearCanvas()
|
||||||
|
self.MySlider.Draw()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
39
Menu/GameShell/10_Settings/Brightness/plugin_init.go
Normal file
39
Menu/GameShell/10_Settings/Brightness/plugin_init.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sysgo.BackLight
|
||||||
|
*/
|
||||||
|
import (
|
||||||
|
/*
|
||||||
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
|
"github.com/cuu/gogame/event"
|
||||||
|
"github.com/cuu/gogame/rect"
|
||||||
|
"github.com/cuu/gogame/color"
|
||||||
|
*/
|
||||||
|
"github.com/cuu/LauncherGo/sysgo/UI"
|
||||||
|
//"github.com/cuu/LauncherGo/sysgo/DBUS"
|
||||||
|
)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
type BrightnessPlugin struct {
|
||||||
|
UI.Plugin
|
||||||
|
BrightnessPage *BrightnessPage
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *BrightnessPlugin) Init( main_screen *UI.MainScreen ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *BrightnessPlugin) Run( main_screen *UI.MainScreen ) {
|
||||||
|
if main_screen != nil {
|
||||||
|
main_screen.PushCurPage()
|
||||||
|
main_screen.SetCurPage(self.BrightnessPage)
|
||||||
|
main_screen.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var APIOBJ BrightnessPlugin
|
||||||
@ -92,8 +92,9 @@ func (self *SettingsPage) Init() {
|
|||||||
|
|
||||||
|
|
||||||
alist := [][]string{ // "so file", "folder name", "label text"
|
alist := [][]string{ // "so file", "folder name", "label text"
|
||||||
{"about.so","About","About"},
|
|
||||||
{"wifi.so","Wifi","Wi-Fi"},
|
{"wifi.so","Wifi","Wi-Fi"},
|
||||||
|
{"about.so","About","About"},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
40
Menu/GameShell/10_Settings/Sound/plugin_init.go
Normal file
40
Menu/GameShell/10_Settings/Sound/plugin_init.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
* need amixer
|
||||||
|
* `sudo apt-get install alsa-utils`
|
||||||
|
*/
|
||||||
|
import (
|
||||||
|
/*
|
||||||
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
|
"github.com/cuu/gogame/event"
|
||||||
|
"github.com/cuu/gogame/rect"
|
||||||
|
"github.com/cuu/gogame/color"
|
||||||
|
*/
|
||||||
|
"github.com/cuu/LauncherGo/sysgo/UI"
|
||||||
|
//"github.com/cuu/LauncherGo/sysgo/DBUS"
|
||||||
|
)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
type SoundPlugin struct {
|
||||||
|
UI.Plugin
|
||||||
|
SoundPage *SoundPage
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *SoundPlugin) Init( main_screen *UI.MainScreen ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPlugin) Run( main_screen *UI.MainScreen ) {
|
||||||
|
if main_screen != nil {
|
||||||
|
main_screen.PushCurPage()
|
||||||
|
main_screen.SetCurPage(self.SoundPage)
|
||||||
|
main_screen.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var APIOBJ SoundPlugin
|
||||||
230
Menu/GameShell/10_Settings/Sound/sound_page.go
Normal file
230
Menu/GameShell/10_Settings/Sound/sound_page.go
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
"github.com/cuu/gogame/event"
|
||||||
|
"github.com/cuu/LauncherGo/sysgo/UI"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OnChangeCB_T func(int)
|
||||||
|
|
||||||
|
type SliderIcon struct {
|
||||||
|
UI.IconItem
|
||||||
|
Parent *SoundSlider
|
||||||
|
|
||||||
|
}
|
||||||
|
func NewSliderIcon() *SliderIcon {
|
||||||
|
p := &SliderIcon{}
|
||||||
|
p.MyType = ICON_TYPES["EXE"]
|
||||||
|
p.Align = ALIGN["VCenter"]
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type SliderMultiIcon struct {
|
||||||
|
UI.MultiIconItem
|
||||||
|
Parent *SoundSlider
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSliderMultiIcon() *SliderMultiIcon {
|
||||||
|
p := &SliderMultiIcon{}
|
||||||
|
p.MyType = ICON_TYPES["EXE"]
|
||||||
|
p.Align = ALIGN["VCenter"]
|
||||||
|
|
||||||
|
p.IconIndex = 0
|
||||||
|
p.IconWidth = 18
|
||||||
|
p.IconHeight = 18
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
type SoundSlider struct {
|
||||||
|
UI.Slider
|
||||||
|
|
||||||
|
BGpng *SliderIcon
|
||||||
|
BGwidth int
|
||||||
|
BGheight int
|
||||||
|
NeedleSurf
|
||||||
|
Scale *SliderMultiIcon
|
||||||
|
Parent *SoundPage
|
||||||
|
|
||||||
|
OnChangeCB OnChangeCB_T
|
||||||
|
|
||||||
|
snd_segs [][2]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSoundSlider() *SoundSlider {
|
||||||
|
p := &SoundSlider{}
|
||||||
|
p.Range = [2]int{0,255}
|
||||||
|
p.Value = 0
|
||||||
|
|
||||||
|
p.BGwidth = 192
|
||||||
|
p.BGheight = 173
|
||||||
|
|
||||||
|
p.snd_segs = [][2]int{ [2]int{0,20},[2]int{21,40},[2]int{41,50},
|
||||||
|
[2]int{51,60},[2]int{61,70},[2]int{71,85},
|
||||||
|
[2]int{86,90},[2]int{91,95},[2]int{96,100}}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) GetCanvasHWND() *sdl.Surface {
|
||||||
|
return self.CanvasHWND
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) Init() {
|
||||||
|
self.Width = self.Parent.Width
|
||||||
|
self.Height = self.Parent.Height
|
||||||
|
|
||||||
|
self.BGpng = NewSliderIcon()
|
||||||
|
self.BGpng.ImgSurf = UI.MyIconPool.GetImgSurf("vol")
|
||||||
|
self.BGpng.MyType = UI.ICON_TYPES["STAT"]
|
||||||
|
self.BGpng.Parent = self
|
||||||
|
self.BGpng.Adjust(0,0,self.BGwidth,self.BGheight,0)
|
||||||
|
|
||||||
|
self.Scale = NewSliderMultiIcon()
|
||||||
|
self.Scale.MyType = UI.ICON_TYPES["STAT"]
|
||||||
|
self.Scale.Parent = self
|
||||||
|
self.Scale.ImgSurf = UI.MyIconPool.GetImgSurf("scale")
|
||||||
|
self.Scale.IconWidth = 82
|
||||||
|
self.Scale.IconHeight = 63
|
||||||
|
self.Scale.Adjust(0,0,82,63,0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) SetValue(vol int) { // pct 0 - 100
|
||||||
|
for i,v := range self.snd_segs {
|
||||||
|
if vol >= v[0] && vol <= v[1] {
|
||||||
|
self.Value = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) Further() {
|
||||||
|
self.Value += 1
|
||||||
|
|
||||||
|
if self.Value >= len(self.snd_segs) -1 {
|
||||||
|
self.Value = len(self.snd_segs) -1
|
||||||
|
}
|
||||||
|
|
||||||
|
vol := self.snd_segs[self.Value][0] + (self.snd_segs[self.Value][1]-self.snd_segs[self.Value][0])/2
|
||||||
|
|
||||||
|
if self.OnChangeCB != nil {
|
||||||
|
self.OnChangeCB(vol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) StepBack() {
|
||||||
|
self.Value -= 1
|
||||||
|
|
||||||
|
if self.Value < 0 {
|
||||||
|
self.Value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
vol := self.snd_segs[self.Value][0]
|
||||||
|
|
||||||
|
if self.OnChangeCB != nil {
|
||||||
|
self.OnChangeCB(vol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundSlider) Draw() {
|
||||||
|
self.BGpng.NewCoord(self.Width/2,self.Height/2)
|
||||||
|
self.BGpng.Draw()
|
||||||
|
|
||||||
|
self.Scale.NewCoord(self.Width/2,self.Height/2)
|
||||||
|
|
||||||
|
self.Scale.IconIndex = self.Value
|
||||||
|
|
||||||
|
self.Scale.Draw()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type SoundPage struct {
|
||||||
|
UI.Page
|
||||||
|
|
||||||
|
MySlider *SoundSlider
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSoundPage() *SoundPage {
|
||||||
|
p := &SoundPage{}
|
||||||
|
|
||||||
|
p.PageIconMargin = 20
|
||||||
|
p.SelectedIconTopOffset = 20
|
||||||
|
p.EasingDur = 10
|
||||||
|
p.Align = UI.ALIGN["SLeft"]
|
||||||
|
|
||||||
|
p.FootMsg = [5]string{"Nav","","","Back","Enter"}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPage) Init() {
|
||||||
|
self.CanvasHWND = self.Screen.CanvasHWND
|
||||||
|
self.Width = self.Screen.Width
|
||||||
|
self.Height = self.Screen.Height
|
||||||
|
|
||||||
|
self.MySlider = NewSoundSlider()
|
||||||
|
|
||||||
|
self.MySlider.Parent = self
|
||||||
|
self.MySlider.SetCanvasHWND(self.CanvasHWND)
|
||||||
|
|
||||||
|
self.MySlider.OnChangeCB = self.WhenSliderDrag
|
||||||
|
|
||||||
|
self.MySlider.Init()
|
||||||
|
|
||||||
|
v,err := GetVolume()
|
||||||
|
if err == nil {
|
||||||
|
self.MySlider.SetValue(v)
|
||||||
|
}else {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPage) OnLoadCb() {
|
||||||
|
v,err := GetVolume()
|
||||||
|
if err == nil {
|
||||||
|
self.MySlider.SetValue(v)
|
||||||
|
}else {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPage) WhenSliderDrag(val int) { //value 0 - 100
|
||||||
|
if value <0 || value > 100 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
SetVolume(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPage) KeyDown(ev *event.Event) {
|
||||||
|
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
|
||||||
|
self.ReturnToUpLevelPage()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["Right"] {
|
||||||
|
self.MySlider.Further()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Data["Key"] == UI.CurKeys["Left"] {
|
||||||
|
self.MySlider.StepBack()
|
||||||
|
self.Screen.Draw()
|
||||||
|
self.Screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *SoundPage) Draw() {
|
||||||
|
self.ClearCanvas()
|
||||||
|
self.MySlider.Draw()
|
||||||
|
}
|
||||||
|
|
||||||
105
Menu/GameShell/10_Settings/Sound/volume_linux.go
Normal file
105
Menu/GameShell/10_Settings/Sound/volume_linux.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
// +build !windows,!darwin
|
||||||
|
/*
|
||||||
|
* Copied from https://github.com/itchyny/volume-go, MIT License
|
||||||
|
*/
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var useAmixer bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if _, err := exec.LookPath("pactl"); err != nil {
|
||||||
|
useAmixer = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdEnv() []string {
|
||||||
|
return []string{"LANG=C", "LC_ALL=C"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVolumeCmd() []string {
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "get", "Master"}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "list", "sinks"}
|
||||||
|
}
|
||||||
|
|
||||||
|
var volumePattern = regexp.MustCompile(`\d+%`)
|
||||||
|
|
||||||
|
func parseVolume(out string) (int, error) {
|
||||||
|
lines := strings.Split(out, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
s := strings.TrimLeft(line, " \t")
|
||||||
|
if useAmixer && strings.Contains(s, "Playback") && strings.Contains(s, "%") ||
|
||||||
|
!useAmixer && strings.HasPrefix(s, "Volume:") {
|
||||||
|
volumeStr := volumePattern.FindString(s)
|
||||||
|
return strconv.Atoi(volumeStr[:len(volumeStr)-1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("no volume found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setVolumeCmd(volume int) []string {
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "set", "Master", strconv.Itoa(volume) + "%"}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "set-sink-volume", "0", strconv.Itoa(volume) + "%"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func increaseVolumeCmd(diff int) []string {
|
||||||
|
var sign string
|
||||||
|
if diff >= 0 {
|
||||||
|
sign = "+"
|
||||||
|
} else if useAmixer {
|
||||||
|
diff = -diff
|
||||||
|
sign = "-"
|
||||||
|
}
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "set", "Master", strconv.Itoa(diff) + "%" + sign}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "--", "set-sink-volume", "0", sign + strconv.Itoa(diff) + "%"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMutedCmd() []string {
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "get", "Master"}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "list", "sinks"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMuted(out string) (bool, error) {
|
||||||
|
lines := strings.Split(out, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
s := strings.TrimLeft(line, " \t")
|
||||||
|
if useAmixer && strings.Contains(s, "Playback") && strings.Contains(s, "%") ||
|
||||||
|
!useAmixer && strings.HasPrefix(s, "Mute: ") {
|
||||||
|
if strings.Contains(s, "[off]") || strings.Contains(s, "yes") {
|
||||||
|
return true, nil
|
||||||
|
} else if strings.Contains(s, "[on]") || strings.Contains(s, "no") {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, errors.New("no muted information found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func muteCmd() []string {
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "-D", "pulse", "set", "Master", "mute"}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "set-sink-mute", "0", "1"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmuteCmd() []string {
|
||||||
|
if useAmixer {
|
||||||
|
return []string{"amixer", "-D", "pulse", "set", "Master", "unmute"}
|
||||||
|
}
|
||||||
|
return []string{"pactl", "set-sink-mute", "0", "0"}
|
||||||
|
}
|
||||||
68
Menu/GameShell/10_Settings/Sound/volume_unix.go
Normal file
68
Menu/GameShell/10_Settings/Sound/volume_unix.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// +build !windows
|
||||||
|
/*
|
||||||
|
* Copied from https://github.com/itchyny/volume-go, MIT License
|
||||||
|
*/
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func execCmd(cmdArgs []string) ([]byte, error) {
|
||||||
|
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
|
||||||
|
cmd.Env = append(os.Environ(), cmdEnv()...)
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(cmdArgs, " "), err)
|
||||||
|
}
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVolume returns the current volume (0 to 100).
|
||||||
|
func GetVolume() (int, error) {
|
||||||
|
out, err := execCmd(getVolumeCmd())
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return parseVolume(string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetVolume sets the sound volume to the specified value.
|
||||||
|
func SetVolume(volume int) error {
|
||||||
|
if volume < 0 || 100 < volume {
|
||||||
|
return errors.New("out of valid volume range")
|
||||||
|
}
|
||||||
|
_, err := execCmd(setVolumeCmd(volume))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IncreaseVolume increases (or decreases) the audio volume by the specified value.
|
||||||
|
func IncreaseVolume(diff int) error {
|
||||||
|
_, err := execCmd(increaseVolumeCmd(diff))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMuted returns the current muted status.
|
||||||
|
func GetMuted() (bool, error) {
|
||||||
|
out, err := execCmd(getMutedCmd())
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return parseMuted(string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mute mutes the audio.
|
||||||
|
func Mute() error {
|
||||||
|
_, err := execCmd(muteCmd())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmute unmutes the audio.
|
||||||
|
func Unmute() error {
|
||||||
|
_, err := execCmd(unmuteCmd())
|
||||||
|
return err
|
||||||
|
}
|
||||||
@ -42,6 +42,11 @@ func (self *WifiPlugin) Init( main_screen *UI.MainScreen ) {
|
|||||||
self.ScanPage.Wireless.EnableSignal("SendStartScanSignal")
|
self.ScanPage.Wireless.EnableSignal("SendStartScanSignal")
|
||||||
self.ScanPage.Wireless.EnableSignal("SendEndScanSignal")
|
self.ScanPage.Wireless.EnableSignal("SendEndScanSignal")
|
||||||
|
|
||||||
|
self.ScanPage.Daemon.SigFuncs["StatusChanged"] = self.ScanPage.DbusDaemonStatusChangedSig
|
||||||
|
self.ScanPage.Daemon.SigFuncs["ConnectResultSent"] = self.ScanPage.DbusConnectResultsSent
|
||||||
|
|
||||||
|
self.ScanPage.Wireless.SigFuncs["SendStartScanSignal"] = self.ScanPage.WifiDbusScanStarted
|
||||||
|
self.ScanPage.Wireless.SigFuncs["SendEndScanSignal"] = self.ScanPage.WifiDbusScanFinishedSig
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -543,7 +543,7 @@ func (self *WifiList) DbusDaemonStatusChangedSig(body []interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var info_str []string
|
var info_str []string
|
||||||
for i,v := range info {
|
for _,v := range info {
|
||||||
info_str = append(info_str, v.String())
|
info_str = append(info_str, v.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +565,7 @@ func (self *WifiList) DbusConnectResultsSent(body []interface{}) {
|
|||||||
fmt.Println(ret_val)
|
fmt.Println(ret_val)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Connecting = flase
|
self.Connecting = false
|
||||||
self.BlockingUI = false
|
self.BlockingUI = false
|
||||||
if self.BlockCb != nil {
|
if self.BlockCb != nil {
|
||||||
self.BlockCb()
|
self.BlockCb()
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ package DBUS
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
//"strconv"
|
//"strconv"
|
||||||
"github.com/godbus/dbus"
|
"github.com/godbus/dbus"
|
||||||
)
|
)
|
||||||
|
|||||||
74
sysgo/UI/slider.go
Normal file
74
sysgo/UI/slider.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
//"fmt"
|
||||||
|
//"math"
|
||||||
|
//"sync"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
|
||||||
|
//"github.com/cuu/gogame/surface"
|
||||||
|
//"github.com/cuu/gogame/draw"
|
||||||
|
//"github.com/cuu/gogame/rect"
|
||||||
|
//"github.com/cuu/gogame/font"
|
||||||
|
"github.com/cuu/gogame/event"
|
||||||
|
|
||||||
|
//"github.com/cuu/gogame/transform"
|
||||||
|
//"github.com/cuu/LauncherGo/sysgo/easings"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
type SliderInterface interface {
|
||||||
|
WidgetInterface
|
||||||
|
|
||||||
|
Init()
|
||||||
|
SetValue()
|
||||||
|
SetRange(m1,m2 int)
|
||||||
|
SetCanvasHWND( canvas *sdl.Surface)
|
||||||
|
KeyDown(ev *event.Event)
|
||||||
|
Draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
type Slider struct {
|
||||||
|
Widget
|
||||||
|
|
||||||
|
Value int
|
||||||
|
|
||||||
|
CanvasHWND *sdl.Surface
|
||||||
|
|
||||||
|
Range [2]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSlider() *Slider {
|
||||||
|
p := &Slider{}
|
||||||
|
p.Range = [2]int{0,255}
|
||||||
|
p.Value = 0
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) Init() {
|
||||||
|
self.Value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) SetValue(v int) {
|
||||||
|
self.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) SetRange(m1 ,m2 int) {
|
||||||
|
if m1 >= m2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.Range[0] = m1
|
||||||
|
self.Range[1] = m2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) SetCanvasHWND( canvas *sdl.Surface) {
|
||||||
|
self.CanvasHWND = canvas
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) KeyDown(ev *event.Event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Slider) Draw() {
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user