diff --git a/Menu/GameShell/10_Settings/PowerOptions/power_options_page.go b/Menu/GameShell/10_Settings/PowerOptions/power_options_page.go index 7df7e36..b461297 100644 --- a/Menu/GameShell/10_Settings/PowerOptions/power_options_page.go +++ b/Menu/GameShell/10_Settings/PowerOptions/power_options_page.go @@ -262,7 +262,7 @@ func (self *InfoPage) GenList() { li.SetSmallText(v["value"]) self.MyList = append(self.MyList,li) - + i+=1 } } diff --git a/Menu/GameShell/10_Settings/Sound/sound_page.go b/Menu/GameShell/10_Settings/Sound/sound_page.go index 1360256..bb6dc56 100644 --- a/Menu/GameShell/10_Settings/Sound/sound_page.go +++ b/Menu/GameShell/10_Settings/Sound/sound_page.go @@ -196,7 +196,7 @@ func (self *SoundSlider) StepBack() { func (self *SoundSlider) Draw() { 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.Scale.NewCoord(self.Width/2,self.Height/2) diff --git a/main.go b/main.go index c8a80df..2d0ce46 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ var ( everytime_keydown = gotime.Now() + sound_patch *UI.SoundPatch + ) // flash the Led1 on the GS back @@ -276,7 +278,11 @@ func run() int { ReunionPagesIcons(main_screen) main_screen.FartherPages() - + + sound_patch = UI.NewSoundPatch() + sound_patch.Parent = main_screen + sound_patch.Init() + main_screen.Draw() main_screen.SwapAndShow() @@ -389,15 +395,36 @@ func run() int { continue } + if ev.Data["Key"] == "Q" { main_screen.OnExitCb() 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) + } } diff --git a/sysgo/UI/above_all_patch.go b/sysgo/UI/above_all_patch.go new file mode 100644 index 0000000..e19f58b --- /dev/null +++ b/sysgo/UI/above_all_patch.go @@ -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) + } +} + + diff --git a/sysgo/UI/main_screen.go b/sysgo/UI/main_screen.go index b232560..960625b 100644 --- a/sysgo/UI/main_screen.go +++ b/sysgo/UI/main_screen.go @@ -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 { 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" { self.Draw() self.SwapAndShow() - } + } self.CurrentPage.KeyDown(ev) } diff --git a/sysgo/UI/sound_patch.go b/sysgo/UI/sound_patch.go new file mode 100644 index 0000000..e0a8508 --- /dev/null +++ b/sysgo/UI/sound_patch.go @@ -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")) + } +} + diff --git a/sysgo/UI/title_bar.go b/sysgo/UI/title_bar.go index fbc6270..db41fe4 100644 --- a/sysgo/UI/title_bar.go +++ b/sysgo/UI/title_bar.go @@ -198,7 +198,7 @@ func (self *TitleBar) SyncSoundVolume() { vol, err := volume.GetVolume() if err != nil { - log.Fatalf("TitleBar SyncSoundVolume get volume failed: %+v", err) + log.Printf("TitleBar SyncSoundVolume get volume failed: %+v\n", err) vol = 0 } fmt.Printf("TitleBar SyncSoundVolume current volume: %d\n", vol)