mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-03-19 02:12:46 +01:00
counter screen and interval checking in main.go
This commit is contained in:
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 {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Widget
|
||||
BarHeight int
|
||||
BorderWidth int
|
||||
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
|
||||
SetText(text string)
|
||||
Draw()
|
||||
DrawCenter(bold bool)
|
||||
}
|
||||
|
||||
type Label struct {
|
||||
@@ -87,6 +88,15 @@ func (self *Label) SetText(text string) {
|
||||
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() {
|
||||
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
||||
|
||||
|
||||
@@ -141,13 +141,11 @@ func (self *MessageBox) Draw() {
|
||||
}
|
||||
|
||||
type MainScreen struct {
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
PageMax int
|
||||
PageIndex int
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
|
||||
MyPageStack *PageStack
|
||||
CurrentPage PageInterface
|
||||
CanvasHWND *sdl.Surface
|
||||
@@ -159,6 +157,8 @@ type MainScreen struct {
|
||||
IconFont *ttf.Font
|
||||
SkinManager *SkinManager
|
||||
DBusManager *DBUS.DBus
|
||||
CounterScreen *CounterScreen
|
||||
Closed bool
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +186,12 @@ func (self *MainScreen) Init() {
|
||||
self.SkinManager.Init()
|
||||
|
||||
self.DBusManager = DBUS.DBusHandler
|
||||
|
||||
self.CounterScreen = NewCounterScreen()
|
||||
self.CounterScreen.HWND = self.HWND
|
||||
self.CounterScreen.Init()
|
||||
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
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)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
"bufio"
|
||||
"strings"
|
||||
"time"
|
||||
gotime "time"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
@@ -88,11 +88,7 @@ func (self *TitleBarIconItem) Draw() {
|
||||
|
||||
|
||||
type TitleBar struct {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Widget
|
||||
BarHeight int
|
||||
LOffset int
|
||||
ROffset int
|
||||
@@ -103,12 +99,16 @@ type TitleBar struct {
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
Title string
|
||||
|
||||
InLowBackLight int
|
||||
InAirPlaneMode bool
|
||||
|
||||
SkinManager *SkinManager //set by MainScreen
|
||||
DBusManager DBUS.DBusInterface
|
||||
|
||||
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
||||
|
||||
|
||||
|
||||
TitleFont *ttf.Font
|
||||
TimeFont *ttf.Font
|
||||
}
|
||||
@@ -141,11 +141,33 @@ func NewTitleBar() *TitleBar {
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
self.Draw(self.Title)
|
||||
}
|
||||
|
||||
func (t *TitleBar) GetWifiStrength(stren int) int {
|
||||
@@ -170,10 +192,10 @@ func (self *TitleBar) SyncSoundVolume() {
|
||||
|
||||
vol, err := volume.GetVolume()
|
||||
if err != nil {
|
||||
log.Fatalf("get volume failed: %+v", err)
|
||||
log.Fatalf("TitleBar SyncSoundVolume get volume failed: %+v", err)
|
||||
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} }
|
||||
ge := 0
|
||||
@@ -190,8 +212,22 @@ func (self *TitleBar) SyncSoundVolume() {
|
||||
//
|
||||
}
|
||||
|
||||
// for outside widget to update sound icon
|
||||
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() {
|
||||
@@ -322,7 +358,22 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
|
||||
if self.DBusManager.IsWifiConnectedNow() {
|
||||
print("wifi is connected")
|
||||
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() {
|
||||
@@ -343,7 +394,7 @@ func (self *TitleBar) Draw(title string) {
|
||||
self.ClearCanvas()
|
||||
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)
|
||||
title_text_w, title_text_h := font.Size(self.TitleFont, self.Title)
|
||||
|
||||
Reference in New Issue
Block a user