mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-13 08:28:51 +01:00
add SoundPatch
This commit is contained in:
parent
325d57ac23
commit
30149a8f24
@ -262,7 +262,7 @@ func (self *InfoPage) GenList() {
|
|||||||
li.SetSmallText(v["value"])
|
li.SetSmallText(v["value"])
|
||||||
|
|
||||||
self.MyList = append(self.MyList,li)
|
self.MyList = append(self.MyList,li)
|
||||||
|
i+=1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -196,7 +196,7 @@ func (self *SoundSlider) StepBack() {
|
|||||||
|
|
||||||
func (self *SoundSlider) Draw() {
|
func (self *SoundSlider) Draw() {
|
||||||
self.BGpng.NewCoord(self.Width/2,self.Height/2)
|
self.BGpng.NewCoord(self.Width/2,self.Height/2)
|
||||||
fmt.Printf("%x\n",self.BGpng.Parent)
|
//fmt.Printf("%x\n",self.BGpng.Parent)
|
||||||
self.BGpng.Draw()
|
self.BGpng.Draw()
|
||||||
|
|
||||||
self.Scale.NewCoord(self.Width/2,self.Height/2)
|
self.Scale.NewCoord(self.Width/2,self.Height/2)
|
||||||
|
|||||||
39
main.go
39
main.go
@ -36,6 +36,8 @@ var (
|
|||||||
|
|
||||||
everytime_keydown = gotime.Now()
|
everytime_keydown = gotime.Now()
|
||||||
|
|
||||||
|
sound_patch *UI.SoundPatch
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// flash the Led1 on the GS back
|
// flash the Led1 on the GS back
|
||||||
@ -276,7 +278,11 @@ func run() int {
|
|||||||
ReunionPagesIcons(main_screen)
|
ReunionPagesIcons(main_screen)
|
||||||
|
|
||||||
main_screen.FartherPages()
|
main_screen.FartherPages()
|
||||||
|
|
||||||
|
sound_patch = UI.NewSoundPatch()
|
||||||
|
sound_patch.Parent = main_screen
|
||||||
|
sound_patch.Init()
|
||||||
|
|
||||||
main_screen.Draw()
|
main_screen.Draw()
|
||||||
main_screen.SwapAndShow()
|
main_screen.SwapAndShow()
|
||||||
|
|
||||||
@ -389,15 +395,36 @@ func run() int {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ev.Data["Key"] == "Q" {
|
if ev.Data["Key"] == "Q" {
|
||||||
main_screen.OnExitCb()
|
main_screen.OnExitCb()
|
||||||
return 0
|
return 0
|
||||||
}else if ev.Data["Key"] == "P" {
|
|
||||||
event.Post(UI.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simplify the stuff
|
|
||||||
|
|
||||||
}else {
|
|
||||||
main_screen.KeyDown(ev)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ev.Data["Key"] == "Keypad +" {
|
||||||
|
if main_screen.CurPage().GetName() != "Sound volume" {
|
||||||
|
main_screen.Draw()
|
||||||
|
sound_patch.VolumeUp()
|
||||||
|
sound_patch.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev.Data["Key"] == "Keypad -" {
|
||||||
|
if main_screen.CurPage().GetName() != "Sound volume" {
|
||||||
|
main_screen.Draw()
|
||||||
|
sound_patch.VolumeDown()
|
||||||
|
sound_patch.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
main_screen.KeyDown(ev)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
76
sysgo/UI/above_all_patch.go
Normal file
76
sysgo/UI/above_all_patch.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import(
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/draw"
|
||||||
|
"github.com/cuu/gogame/rect"
|
||||||
|
"github.com/cuu/gogame/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AboveAllPatch struct {
|
||||||
|
|
||||||
|
Widget
|
||||||
|
|
||||||
|
Text string
|
||||||
|
|
||||||
|
FontObj *ttf.Font
|
||||||
|
|
||||||
|
Color *color.Color
|
||||||
|
ValColor *color.Color
|
||||||
|
|
||||||
|
CanvasHWND *sdl.Surface
|
||||||
|
|
||||||
|
Icons map[string]IconItemInterface
|
||||||
|
|
||||||
|
Value int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAboveAllPatch() *AboveAllPatch {
|
||||||
|
|
||||||
|
p := &AboveAllPatch{}
|
||||||
|
p.PosX = Width /2
|
||||||
|
p.PosY = Height /2
|
||||||
|
p.Width = 50
|
||||||
|
p.Height = 120
|
||||||
|
|
||||||
|
p.FontObj = Fonts["veramono20"]
|
||||||
|
p.Color = MySkinManager.GiveColor("Text")
|
||||||
|
p.ValColor = MySkinManager.GiveColor("URL")
|
||||||
|
|
||||||
|
p.Icons = make( map[string]IconItemInterface )
|
||||||
|
|
||||||
|
p.Value = 0
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *AboveAllPatch) SetCanvasHWND( _canvashwnd *sdl.Surface) {
|
||||||
|
|
||||||
|
self.CanvasHWND = _canvashwnd
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *AboveAllPatch) Draw() {
|
||||||
|
start_rect := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||||
|
draw.AARoundRect(self.CanvasHWND,start_rect,self.Color,3,0,self.Color)
|
||||||
|
|
||||||
|
if self.Value > 10 {
|
||||||
|
vol_height := int(float64(self.Height) * (float64(self.Value)/100.0))
|
||||||
|
dheight := self.Height - vol_height
|
||||||
|
|
||||||
|
vol_rect := rect.Rect(self.PosX - self.Width/2,self.PosY - self.Height/2+dheight,self.Width,vol_height)
|
||||||
|
|
||||||
|
draw.AARoundRect(self.CanvasHWND,&vol_rect,self.ValColor,3,0,self.ValColor)
|
||||||
|
|
||||||
|
}else {
|
||||||
|
vol_height := 10
|
||||||
|
dheight := self.Height - vol_height
|
||||||
|
vol_rect := rect.Rect(self.PosX - self.Width/2,self.PosY - self.Height/2+dheight,self.Width,vol_height)
|
||||||
|
|
||||||
|
draw.AARoundRect(self.CanvasHWND,&vol_rect,self.ValColor,3,0,self.ValColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +25,26 @@ import (
|
|||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
//eg: MainScreen
|
||||||
|
type ScreenInterface interface {
|
||||||
|
AppendPage( pg PageInterface )
|
||||||
|
ClearCanvas()
|
||||||
|
CurPage() PageInterface
|
||||||
|
Draw()
|
||||||
|
ExtraName(name string) string
|
||||||
|
FartherPages()
|
||||||
|
Init()
|
||||||
|
IsEmulatorPackage(dirname string ) bool
|
||||||
|
IsExecPackage(dirname string ) bool
|
||||||
|
IsPluginPackage(dirname string ) bool
|
||||||
|
KeyDown(ev *event.Event)
|
||||||
|
OnExitCb()
|
||||||
|
PushCurPage()
|
||||||
|
PushPage( pg PageInterface)
|
||||||
|
RunEXE( cmdpath string)
|
||||||
|
SetCurPage( pg PageInterface)
|
||||||
|
SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
type PluginConfig struct {
|
type PluginConfig struct {
|
||||||
NAME string `json:"NAME"` // plugin name,default could be the same as Plugin Folder's name
|
NAME string `json:"NAME"` // plugin name,default could be the same as Plugin Folder's name
|
||||||
@ -359,7 +379,7 @@ func (self *MainScreen) KeyDown(ev *event.Event) {
|
|||||||
if ev.Data["Key"] == "Space" {
|
if ev.Data["Key"] == "Space" {
|
||||||
self.Draw()
|
self.Draw()
|
||||||
self.SwapAndShow()
|
self.SwapAndShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.CurrentPage.KeyDown(ev)
|
self.CurrentPage.KeyDown(ev)
|
||||||
}
|
}
|
||||||
|
|||||||
124
sysgo/UI/sound_patch.go
Normal file
124
sysgo/UI/sound_patch.go
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/itchyny/volume-go"
|
||||||
|
"github.com/cuu/gogame/draw"
|
||||||
|
"github.com/cuu/gogame/rect"
|
||||||
|
//"github.com/cuu/gogame/color"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
type SoundPatch struct {
|
||||||
|
AboveAllPatch
|
||||||
|
|
||||||
|
snd_segs [][2]int
|
||||||
|
Needle int
|
||||||
|
Parent *MainScreen
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSoundPatch() *SoundPatch {
|
||||||
|
p := &SoundPatch{}
|
||||||
|
p.PosX = Width /2
|
||||||
|
p.PosY = Height /2
|
||||||
|
p.Width = 50
|
||||||
|
p.Height = 120
|
||||||
|
|
||||||
|
p.FontObj = Fonts["veramono20"]
|
||||||
|
p.Color = MySkinManager.GiveColor("Text")
|
||||||
|
p.ValColor = MySkinManager.GiveColor("URL")
|
||||||
|
|
||||||
|
p.Icons = make( map[string]IconItemInterface )
|
||||||
|
|
||||||
|
p.Value = 0
|
||||||
|
|
||||||
|
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 *SoundPatch) Init() {
|
||||||
|
self.SetCanvasHWND(self.Parent.CanvasHWND)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPatch) VolumeUp() int {
|
||||||
|
|
||||||
|
vol, err := volume.GetVolume()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("SoundPatch VolumeUp get volume failed: %+v", err)
|
||||||
|
vol = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for i,v := range self.snd_segs {
|
||||||
|
if vol >= v[0] && vol <= v[1] {
|
||||||
|
self.Needle = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Needle += 1
|
||||||
|
|
||||||
|
if self.Needle > len(self.snd_segs) -1 {
|
||||||
|
self.Needle = len(self.snd_segs) -1
|
||||||
|
}
|
||||||
|
|
||||||
|
val := self.snd_segs[self.Needle][0] + (self.snd_segs[self.Needle][1] - self.snd_segs[self.Needle][0])/2
|
||||||
|
|
||||||
|
volume.SetVolume(val)
|
||||||
|
|
||||||
|
self.Value = self.snd_segs[self.Needle][1]
|
||||||
|
|
||||||
|
self.Parent.TitleBar.SetSoundVolume(val)
|
||||||
|
|
||||||
|
return self.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPatch) VolumeDown() int {
|
||||||
|
vol, err := volume.GetVolume()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("SoundPatch VolumeDown get volume failed: %+v\n", err)
|
||||||
|
vol = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for i,v := range self.snd_segs {
|
||||||
|
if vol >= v[0] && vol <= v[1] {
|
||||||
|
self.Needle = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Needle -= 1
|
||||||
|
|
||||||
|
if self.Needle < 0 {
|
||||||
|
self.Needle = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
val := self.snd_segs[self.Needle][0]
|
||||||
|
|
||||||
|
if val < 0 {
|
||||||
|
val = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
volume.SetVolume(val)
|
||||||
|
|
||||||
|
self.Value = val
|
||||||
|
|
||||||
|
self.Parent.TitleBar.SetSoundVolume(val)
|
||||||
|
|
||||||
|
return self.Value
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SoundPatch) Draw() {
|
||||||
|
|
||||||
|
for i:=0;i< (self.Needle+1);i++ {
|
||||||
|
vol_rect := rect.Rect(80+i*20, self.Height/2+20,10, 40)
|
||||||
|
draw.AARoundRect(self.CanvasHWND,&vol_rect,MySkinManager.GiveColor("Front"),3,0,MySkinManager.GiveColor("Front"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ func (self *TitleBar) SyncSoundVolume() {
|
|||||||
|
|
||||||
vol, err := volume.GetVolume()
|
vol, err := volume.GetVolume()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("TitleBar SyncSoundVolume get volume failed: %+v", err)
|
log.Printf("TitleBar SyncSoundVolume get volume failed: %+v\n", err)
|
||||||
vol = 0
|
vol = 0
|
||||||
}
|
}
|
||||||
fmt.Printf("TitleBar SyncSoundVolume current volume: %d\n", vol)
|
fmt.Printf("TitleBar SyncSoundVolume current volume: %d\n", vol)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user