mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
counter screen and interval checking in main.go
This commit is contained in:
parent
d596d71cbb
commit
47ff78e11d
@ -263,7 +263,9 @@ func (self *SoundPage) WhenSliderDrag(val int) { //value 0 - 100
|
|||||||
if val <0 || val > 100 {
|
if val <0 || val > 100 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.Screen.TitleBar.SetSoundVolume(val)
|
||||||
|
|
||||||
SetVolume(val)
|
SetVolume(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
194
main.go
194
main.go
@ -4,7 +4,7 @@ import (
|
|||||||
|
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
gotime "time"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
|
||||||
"github.com/cuu/gogame/display"
|
"github.com/cuu/gogame/display"
|
||||||
@ -13,9 +13,187 @@ import (
|
|||||||
"github.com/cuu/gogame/font"
|
"github.com/cuu/gogame/font"
|
||||||
"github.com/cuu/gogame/time"
|
"github.com/cuu/gogame/time"
|
||||||
|
|
||||||
|
"github.com/cuu/LauncherGoDev/sysgo"
|
||||||
|
|
||||||
"github.com/cuu/LauncherGoDev/sysgo/UI"
|
"github.com/cuu/LauncherGoDev/sysgo/UI"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flash_led1_counter = 0
|
||||||
|
last_brt = 0
|
||||||
|
passout_time_stage = 0
|
||||||
|
led1_proc_file = "/proc/driver/led1"
|
||||||
|
|
||||||
|
everytime_keydown = gotime.Now()
|
||||||
|
|
||||||
|
)
|
||||||
|
// flash the Led1 on the GS back
|
||||||
|
func FlashLed1(main_screen *UI.MainScreen) {
|
||||||
|
|
||||||
|
for {
|
||||||
|
if UI.FileExists(led1_proc_file) {
|
||||||
|
if main_screen.Closed == false {
|
||||||
|
if flash_led1_counter > 0 {
|
||||||
|
d := []byte(fmt.Sprintf("%d",0))
|
||||||
|
err := ioutil.WriteFile(led1_proc_file, d, 0644) // turn off led1
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
flash_led1_counter = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
flash_led1_counter +=1
|
||||||
|
if flash_led1_counter == 3 {
|
||||||
|
d := []byte(fmt.Sprintf("%d",1))
|
||||||
|
err := ioutil.WriteFile(led1_proc_file, d, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flash_led1_counter == 5 {
|
||||||
|
d := []byte(fmt.Sprintf("%d",0))
|
||||||
|
err := ioutil.WriteFile(led1_proc_file, d, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flash_led1_counter == 11 {
|
||||||
|
flash_led1_counter = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gotime.Sleep(200 * gotime.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//happens everytime when KeyDown occurs
|
||||||
|
func RestoreLastBackLightBrightness(main_screen *UI.MainScreen) bool {
|
||||||
|
|
||||||
|
passout_time_stage = 0
|
||||||
|
main_screen.TitleBar.InLowBackLight = -1
|
||||||
|
main_screen.Closed = false
|
||||||
|
|
||||||
|
if last_brt == -1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) {
|
||||||
|
lines,err := UI.ReadLines(sysgo.BackLight)
|
||||||
|
if err == nil {
|
||||||
|
brt,err2 := strconv.Atoi(strings.Trim(lines[0],"\r\n "))
|
||||||
|
if err2 == nil {
|
||||||
|
if brt < last_brt {
|
||||||
|
d := []byte(fmt.Sprintf("%d",last_brt))
|
||||||
|
ioutil.WriteFile(sysgo.BackLight,d,0644)
|
||||||
|
last_brt = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if UI.FileExists(led1_proc_file) {
|
||||||
|
d := []byte(fmt.Sprintf("%d",0))
|
||||||
|
err := ioutil.WriteFile(led1_proc_file, d, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Stop CounterScreen here
|
||||||
|
|
||||||
|
if main_screen.CounterScreen.Counting == true {
|
||||||
|
main_screen.CounterScreen.StopCounter()
|
||||||
|
main_screen.Draw()
|
||||||
|
main_screen.SwapAndShow()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//power stuff dealer
|
||||||
|
func InspectionTeam(main_screen *UI.MainScreen) {
|
||||||
|
|
||||||
|
for {
|
||||||
|
cur_time := gotime.Now()
|
||||||
|
elapsed := cur_time.Sub(everytime_keydown)
|
||||||
|
|
||||||
|
time1 := sysgo.PowerLevels[sysgo.CurPowerLevel].Dim
|
||||||
|
time2 := sysgo.PowerLevels[sysgo.CurPowerLevel].Close
|
||||||
|
time3 := sysgo.PowerLevels[sysgo.CurPowerLevel].PowerOff
|
||||||
|
|
||||||
|
if elapsed > gotime.Duration(time1) *gotime.Millisecond && passout_time_stage == 0 {
|
||||||
|
fmt.Println("timeout, dim screen ",elapsed)
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) {
|
||||||
|
lines,err := UI.ReadLines(sysgo.BackLight)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
brt,err2 := strconv.Atoi(strings.Trim(lines[0],"\r\n "))
|
||||||
|
if err2 == nil {
|
||||||
|
if brt > 0 {
|
||||||
|
if last_brt < 0 {
|
||||||
|
last_brt = brt
|
||||||
|
}
|
||||||
|
d := []byte(fmt.Sprintf("%d",1))
|
||||||
|
ioutil.WriteFile(sysgo.BackLight,d,0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main_screen.TitleBar.InLowBackLight = 0
|
||||||
|
if time2 != 0 {
|
||||||
|
passout_time_stage = 1 // next
|
||||||
|
}
|
||||||
|
everytime_keydown = cur_time
|
||||||
|
}else if elapsed > gotime.Duration(time2) *gotime.Millisecond && passout_time_stage == 1 {
|
||||||
|
fmt.Println("timeout, close screen ", elapsed)
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) {
|
||||||
|
d := []byte(fmt.Sprintf("%d",0))
|
||||||
|
ioutil.WriteFile(sysgo.BackLight,d,0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_screen.TitleBar.InLowBackLight = 0
|
||||||
|
main_screen.Closed = true
|
||||||
|
if time3 != 0 {
|
||||||
|
passout_time_stage = 2 // next
|
||||||
|
}
|
||||||
|
|
||||||
|
everytime_keydown = cur_time
|
||||||
|
}else if elapsed > gotime.Duration(time3) * gotime.Millisecond && passout_time_stage == 2{
|
||||||
|
|
||||||
|
fmt.Println("Power Off counting down")
|
||||||
|
|
||||||
|
main_screen.CounterScreen.Draw()
|
||||||
|
main_screen.CounterScreen.SwapAndShow()
|
||||||
|
main_screen.CounterScreen.StartCounter()
|
||||||
|
|
||||||
|
if UI.FileExists(sysgo.BackLight) {
|
||||||
|
d := []byte(fmt.Sprintf("%d",last_brt))
|
||||||
|
ioutil.WriteFile(sysgo.BackLight,d,0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_screen.TitleBar.InLowBackLight = 0
|
||||||
|
|
||||||
|
passout_time_stage = 4
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gotime.Sleep(UI.DT * gotime.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func run() int {
|
func run() int {
|
||||||
display.Init()
|
display.Init()
|
||||||
@ -46,10 +224,13 @@ func run() int {
|
|||||||
|
|
||||||
UI.SwapAndShow()
|
UI.SwapAndShow()
|
||||||
|
|
||||||
fmt.Println(main_screen)
|
//fmt.Println(main_screen)
|
||||||
|
|
||||||
event.AddCustomEvent(UI.RUNEVT)
|
event.AddCustomEvent(UI.RUNEVT)
|
||||||
|
|
||||||
|
go FlashLed1(main_screen)
|
||||||
|
go InspectionTeam(main_screen)
|
||||||
|
|
||||||
running := true
|
running := true
|
||||||
for running {
|
for running {
|
||||||
ev := event.Wait()
|
ev := event.Wait()
|
||||||
@ -62,11 +243,14 @@ func run() int {
|
|||||||
fmt.Println("UserEvent: ",ev.Data["Msg"])
|
fmt.Println("UserEvent: ",ev.Data["Msg"])
|
||||||
}
|
}
|
||||||
if ev.Type == event.KEYDOWN {
|
if ev.Type == event.KEYDOWN {
|
||||||
|
everytime_keydown = gotime.Now()
|
||||||
|
if RestoreLastBackLightBrightness(main_screen) == false {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
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"] == "D" {
|
|
||||||
time.Delay(1000)
|
|
||||||
}else if ev.Data["Key"] == "P" {
|
}else if ev.Data["Key"] == "P" {
|
||||||
event.Post(UI.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simplify the stuff
|
event.Post(UI.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simplify the stuff
|
||||||
|
|
||||||
|
|||||||
159
sysgo/UI/counter_screen.go
Normal file
159
sysgo/UI/counter_screen.go
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
gotime "time"
|
||||||
|
|
||||||
|
)
|
||||||
|
type CounterScreen struct {
|
||||||
|
FullScreen
|
||||||
|
|
||||||
|
|
||||||
|
CounterFont *ttf.Font
|
||||||
|
TextFont1 *ttf.Font
|
||||||
|
TextFont2 *ttf.Font
|
||||||
|
|
||||||
|
TopLabel LabelInterface
|
||||||
|
BottomLabel LabelInterface
|
||||||
|
NumberLabel LabelInterface
|
||||||
|
BGColor *color.Color
|
||||||
|
FGColor *color.Color
|
||||||
|
|
||||||
|
Counting bool
|
||||||
|
|
||||||
|
Number int // 10
|
||||||
|
|
||||||
|
inter_counter int //
|
||||||
|
|
||||||
|
TheTicker *gotime.Ticker
|
||||||
|
TickerStoped chan bool
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCounterScreen() *CounterScreen {
|
||||||
|
p := &CounterScreen{}
|
||||||
|
p.Number = 10
|
||||||
|
p.CounterFont = Fonts["varela120"]
|
||||||
|
p.TextFont1 = Fonts["varela15"]
|
||||||
|
p.TextFont2 = Fonts["varela12"]
|
||||||
|
|
||||||
|
p.BGColor = &color.Color{0,0,0,255}
|
||||||
|
p.FGColor = &color.Color{255,255,255,255}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *CounterScreen ) Interval() {
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-self.TheTicker.C:
|
||||||
|
self.inter_counter += 1
|
||||||
|
|
||||||
|
if self.Number == 0 {
|
||||||
|
self.Counting = false
|
||||||
|
self.TheTicker.Stop()
|
||||||
|
fmt.Println("do the real shutdown")
|
||||||
|
|
||||||
|
if sysgo.CurKeySet != "PC" {
|
||||||
|
cmdpath := "feh --bg-center sysgo/gameshell/wallpaper/seeyou.png;"
|
||||||
|
cmdpath = cmdpath + "sleep 3;"
|
||||||
|
cmdpath = cmdpath + "sudo halt -p"
|
||||||
|
event.Post(RUNEVT,cmdpath)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.inter_counter >= 2 {
|
||||||
|
self.Number -= 1
|
||||||
|
if self.Number < 0 {
|
||||||
|
self.Number = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("sub Number ", self.Number)
|
||||||
|
self.inter_counter = 0
|
||||||
|
|
||||||
|
self.Draw()
|
||||||
|
self.SwapAndShow()
|
||||||
|
|
||||||
|
}
|
||||||
|
case <- self.TickerStoped:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *CounterScreen) StartCounter() {
|
||||||
|
if self.Counting == true {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Number = 10
|
||||||
|
self.inter_counter = 0
|
||||||
|
|
||||||
|
self.Counting = true
|
||||||
|
|
||||||
|
self.TheTicker.Start()
|
||||||
|
|
||||||
|
go self.Interval()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *CounterScreen) StopCounter() {
|
||||||
|
if self.Counting == false {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Counting = false
|
||||||
|
self.Number = 0
|
||||||
|
self.inter_counter = 0
|
||||||
|
|
||||||
|
self.TheTicker.Stop()
|
||||||
|
self.TickerStoped <- true
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *CounterScreen) Init() {
|
||||||
|
|
||||||
|
self.CanvasHWND = surface.Surface(self.Width,self.Height)
|
||||||
|
|
||||||
|
self.TopLabel = NewLabel()
|
||||||
|
self.TopLabel.SetCanvasHWND( self.CanvasHWND)
|
||||||
|
self.TopLabel.Init("System shutdown in", self.TextFont1,self.FGColor)
|
||||||
|
|
||||||
|
self.BottomLabel = NewLabel()
|
||||||
|
self.BottomLabel.SetCanvasHWND(self.CanvasHWND)
|
||||||
|
self.BottomLabel.Init("Press any key to stop countdown",self.TextFont2,self.FGColor)
|
||||||
|
|
||||||
|
|
||||||
|
self.NumberLabel = NewLabel()
|
||||||
|
self.NumberLabel.SetCanvasHWND(self.CanvasHWND)
|
||||||
|
number_str := fmt.Sprintf("%d",self.Number)
|
||||||
|
self.NumberLabel.Init(number_str,self.CounterFont,self.FGColor)
|
||||||
|
|
||||||
|
self.TheTicker = gotime.NewTicker(500 * gotime.Millisecond)
|
||||||
|
self.TickerStoped = make(chan bool,1)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *CounterScreen) Draw() {
|
||||||
|
surface.Fill(self.CanvasHWND, self.FGColor)
|
||||||
|
|
||||||
|
self.TopLabel.NewCoord(Width/2,15)
|
||||||
|
self.TopLabel.DrawCenter(false)
|
||||||
|
|
||||||
|
self.BottomLabel.NewCoord(Width/2, Height-15)
|
||||||
|
self.BottomLabel.DrawCenter(false)
|
||||||
|
|
||||||
|
self.NumberLabel.NewCoord(Width/2,Height/2)
|
||||||
|
number_str := fmt.Sprintf("%d",self.Number)
|
||||||
|
self.NumberLabel.SetText(number_str)
|
||||||
|
self.NumberLabel.DrawCenter(false)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -76,11 +76,7 @@ func (self *FootBarIconItem) Draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FootBar struct {
|
type FootBar struct {
|
||||||
|
Widget
|
||||||
PosX int
|
|
||||||
PosY int
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
BarHeight int
|
BarHeight int
|
||||||
BorderWidth int
|
BorderWidth int
|
||||||
CanvasHWND *sdl.Surface
|
CanvasHWND *sdl.Surface
|
||||||
|
|||||||
35
sysgo/UI/fullscreen.go
Normal file
35
sysgo/UI/fullscreen.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package UI
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"github.com/cuu/gogame/surface"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
type FullScreen struct {
|
||||||
|
Widget
|
||||||
|
CanvasHWND *sdl.Surface
|
||||||
|
HWND *sdl.Surface
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFullScreen() *FullScreen {
|
||||||
|
p := &FullScreen{}
|
||||||
|
|
||||||
|
return p
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *FullScreen) SwapAndShow() {
|
||||||
|
if self.HWND !=nil {
|
||||||
|
rect_ := rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
|
||||||
|
surface.Blit(self.HWND,self.CanvasHWND,&rect_,nil)
|
||||||
|
SwapAndShow()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *FullScreen) Draw() {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ type LabelInterface interface {
|
|||||||
GetText() string
|
GetText() string
|
||||||
SetText(text string)
|
SetText(text string)
|
||||||
Draw()
|
Draw()
|
||||||
|
DrawCenter(bold bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Label struct {
|
type Label struct {
|
||||||
@ -87,6 +88,15 @@ func (self *Label) SetText(text string) {
|
|||||||
self.Width,self.Height = font.Size(self.FontObj, self.Text)
|
self.Width,self.Height = font.Size(self.FontObj, self.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Label) DrawCenter(bold bool) { // default bold is false
|
||||||
|
font.SetBold(self.FontObj,bold)
|
||||||
|
my_text := font.Render(self.FontObj,self.Text, true, self.Color, nil)
|
||||||
|
|
||||||
|
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||||
|
|
||||||
|
surface.Blit(self.CanvasHWND,my_text,rect_,nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Label) Draw() {
|
func (self *Label) Draw() {
|
||||||
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
||||||
|
|
||||||
|
|||||||
@ -141,13 +141,11 @@ func (self *MessageBox) Draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MainScreen struct {
|
type MainScreen struct {
|
||||||
|
Widget
|
||||||
Pages []PageInterface
|
Pages []PageInterface
|
||||||
PageMax int
|
PageMax int
|
||||||
PageIndex int
|
PageIndex int
|
||||||
PosX int
|
|
||||||
PosY int
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
MyPageStack *PageStack
|
MyPageStack *PageStack
|
||||||
CurrentPage PageInterface
|
CurrentPage PageInterface
|
||||||
CanvasHWND *sdl.Surface
|
CanvasHWND *sdl.Surface
|
||||||
@ -159,6 +157,8 @@ type MainScreen struct {
|
|||||||
IconFont *ttf.Font
|
IconFont *ttf.Font
|
||||||
SkinManager *SkinManager
|
SkinManager *SkinManager
|
||||||
DBusManager *DBUS.DBus
|
DBusManager *DBUS.DBus
|
||||||
|
CounterScreen *CounterScreen
|
||||||
|
Closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -186,6 +186,12 @@ func (self *MainScreen) Init() {
|
|||||||
self.SkinManager.Init()
|
self.SkinManager.Init()
|
||||||
|
|
||||||
self.DBusManager = DBUS.DBusHandler
|
self.DBusManager = DBUS.DBusHandler
|
||||||
|
|
||||||
|
self.CounterScreen = NewCounterScreen()
|
||||||
|
self.CounterScreen.HWND = self.HWND
|
||||||
|
self.CounterScreen.Init()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
|
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
|
||||||
|
|||||||
@ -66,6 +66,10 @@ func (self *MultiLabel) SetText(text string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *MultiLabel) DrawCenter(bold bool) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (self *MultiLabel) Draw() {
|
func (self *MultiLabel) Draw() {
|
||||||
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
||||||
self.blit_text(self.CanvasHWND, self.Text,self.PosX,self.PosY,self.FontObj)
|
self.blit_text(self.CanvasHWND, self.Text,self.PosX,self.PosY,self.FontObj)
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"bufio"
|
"bufio"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
gotime "time"
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
"github.com/veandco/go-sdl2/ttf"
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
@ -88,11 +88,7 @@ func (self *TitleBarIconItem) Draw() {
|
|||||||
|
|
||||||
|
|
||||||
type TitleBar struct {
|
type TitleBar struct {
|
||||||
|
Widget
|
||||||
PosX int
|
|
||||||
PosY int
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
BarHeight int
|
BarHeight int
|
||||||
LOffset int
|
LOffset int
|
||||||
ROffset int
|
ROffset int
|
||||||
@ -103,12 +99,16 @@ type TitleBar struct {
|
|||||||
CanvasHWND *sdl.Surface
|
CanvasHWND *sdl.Surface
|
||||||
HWND *sdl.Surface
|
HWND *sdl.Surface
|
||||||
Title string
|
Title string
|
||||||
|
|
||||||
InLowBackLight int
|
InLowBackLight int
|
||||||
|
InAirPlaneMode bool
|
||||||
|
|
||||||
SkinManager *SkinManager //set by MainScreen
|
SkinManager *SkinManager //set by MainScreen
|
||||||
DBusManager DBUS.DBusInterface
|
DBusManager DBUS.DBusInterface
|
||||||
|
|
||||||
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
||||||
|
|
||||||
|
|
||||||
TitleFont *ttf.Font
|
TitleFont *ttf.Font
|
||||||
TimeFont *ttf.Font
|
TimeFont *ttf.Font
|
||||||
}
|
}
|
||||||
@ -141,11 +141,33 @@ func NewTitleBar() *TitleBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TitleBar) RoundRobinCheck() {
|
func (t *TitleBar) RoundRobinCheck() {
|
||||||
|
for {
|
||||||
|
|
||||||
|
if self.InLowBackLight < 0 {
|
||||||
|
self.CheckBatteryStat()
|
||||||
|
///self.CheckBluetooth()
|
||||||
|
self.UpdateWifiStrength()
|
||||||
|
|
||||||
|
}else if self.InLowBackLight >= 0 {
|
||||||
|
self.InLowBackLight +=1
|
||||||
|
|
||||||
|
if self.InLowBackLight > 10 {
|
||||||
|
self.CheckBatteryStat()
|
||||||
|
|
||||||
|
self.UpdateWifiStrength()
|
||||||
|
|
||||||
|
self.InLowBackLight = 0 // reset
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gotime.Sleep(3000 * gotime.Millisecond)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TitleBar) UpdateWifiStrength() {
|
func (t *TitleBar) UpdateWifiStrength() {
|
||||||
|
self.Draw(self.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TitleBar) GetWifiStrength(stren int) int {
|
func (t *TitleBar) GetWifiStrength(stren int) int {
|
||||||
@ -170,10 +192,10 @@ func (self *TitleBar) SyncSoundVolume() {
|
|||||||
|
|
||||||
vol, err := volume.GetVolume()
|
vol, err := volume.GetVolume()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("get volume failed: %+v", err)
|
log.Fatalf("TitleBar SyncSoundVolume get volume failed: %+v", err)
|
||||||
vol = 0
|
vol = 0
|
||||||
}
|
}
|
||||||
fmt.Printf("current volume: %d\n", vol)
|
fmt.Printf("TitleBar SyncSoundVolume current volume: %d\n", vol)
|
||||||
|
|
||||||
snd_segs := [][]int{ []int{0,10}, []int{10,30}, []int{30,70},[]int{70,100} }
|
snd_segs := [][]int{ []int{0,10}, []int{10,30}, []int{30,70},[]int{70,100} }
|
||||||
ge := 0
|
ge := 0
|
||||||
@ -190,8 +212,22 @@ func (self *TitleBar) SyncSoundVolume() {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for outside widget to update sound icon
|
||||||
func (t *TitleBar) SetSoundVolume(vol int) {
|
func (t *TitleBar) SetSoundVolume(vol int) {
|
||||||
//pass
|
|
||||||
|
snd_segs := [][]int{ []int{0,10}, []int{10,30}, []int{30,70},[]int{70,100} }
|
||||||
|
ge := 0
|
||||||
|
|
||||||
|
for i,v := range snd_segs {
|
||||||
|
if vol >= v[0] && vol <= v[1] {
|
||||||
|
ge = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Icons["soundvolume"].SetIconIndex(ge)
|
||||||
|
self.Icons["sound"] = self.Icons["soundvolume"]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *TitleBar) CheckBatteryStat() {
|
func (self *TitleBar) CheckBatteryStat() {
|
||||||
@ -322,7 +358,22 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
|
|||||||
if self.DBusManager.IsWifiConnectedNow() {
|
if self.DBusManager.IsWifiConnectedNow() {
|
||||||
print("wifi is connected")
|
print("wifi is connected")
|
||||||
print( self.DBusManager.WifiStrength())
|
print( self.DBusManager.WifiStrength())
|
||||||
}
|
}else {
|
||||||
|
|
||||||
|
cmd := "sudo rfkill list | grep yes | cut -d \" \" -f3" //make sure sudo rfkill needs no password
|
||||||
|
out, err := exec.Command("bash", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to execute command: %s\n", cmd)
|
||||||
|
}else {
|
||||||
|
outs := strings.Split(string(out),"\n")
|
||||||
|
if len(outs) > 0 && outs[0] == "yes" {
|
||||||
|
self.InAirPlaneMode = true
|
||||||
|
}else{
|
||||||
|
self.InAirPlaneMode = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *TitleBar) ClearCanvas() {
|
func (self *TitleBar) ClearCanvas() {
|
||||||
@ -343,7 +394,7 @@ func (self *TitleBar) Draw(title string) {
|
|||||||
self.ClearCanvas()
|
self.ClearCanvas()
|
||||||
self.Title = title
|
self.Title = title
|
||||||
|
|
||||||
cur_time := jodaTime.Format("HH:mm", time.Now())
|
cur_time := jodaTime.Format("HH:mm", gotime.Now())
|
||||||
|
|
||||||
time_text_w, time_text_h := font.Size(self.TimeFont, cur_time)
|
time_text_w, time_text_h := font.Size(self.TimeFont, cur_time)
|
||||||
title_text_w, title_text_h := font.Size(self.TitleFont, self.Title)
|
title_text_w, title_text_h := font.Size(self.TitleFont, self.Title)
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
package sysgo
|
package sysgo
|
||||||
|
|
||||||
|
type PowerLevel struct {
|
||||||
|
Dim int
|
||||||
|
Close int
|
||||||
|
PowerOff int
|
||||||
|
}
|
||||||
|
|
||||||
|
var PowerLevels map[string]*PowerLevel
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CurKeySet = "GameShell" // PC or GameShell
|
CurKeySet = "GameShell" // PC or GameShell
|
||||||
DontLeave = false
|
DontLeave = false
|
||||||
@ -9,8 +17,24 @@ var (
|
|||||||
|
|
||||||
UPDATE_URL="https://raw.githubusercontent.com/cuu/CPI/master/launchergo_ver.json"
|
UPDATE_URL="https://raw.githubusercontent.com/cuu/CPI/master/launchergo_ver.json"
|
||||||
|
|
||||||
VERSION="stable 1.22"
|
VERSION="0.22"
|
||||||
|
|
||||||
SKIN="default"
|
SKIN="default"
|
||||||
|
|
||||||
|
//load from dot files
|
||||||
|
CurPowerLevel= "performance"
|
||||||
|
Lang = "English"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if PowerLevels == nil {
|
||||||
|
PowerLevels = make(map[string]*PowerLevel)
|
||||||
|
PowerLevels["supersaving"] = &PowerLevel{10, 30, 120}
|
||||||
|
PowerLevels["powersaving"] = &PowerLevel{40, 120, 300}
|
||||||
|
PowerLevels["server"] = &PowerLevel{40, 120, 0 }
|
||||||
|
PowerLevels["performance"] = &PowerLevel{40, 0, 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
sysgo/gameshell/wallpaper/gameover.png
Normal file
BIN
sysgo/gameshell/wallpaper/gameover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
sysgo/gameshell/wallpaper/loading.png
Normal file
BIN
sysgo/gameshell/wallpaper/loading.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
sysgo/gameshell/wallpaper/seeyou.png
Normal file
BIN
sysgo/gameshell/wallpaper/seeyou.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
sysgo/gameshell/wallpaper/updating.png
Normal file
BIN
sysgo/gameshell/wallpaper/updating.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Loading…
x
Reference in New Issue
Block a user