add TitleBar UpdateTimeLocation

This commit is contained in:
cuu
2018-12-24 07:00:27 +00:00
parent fe210d5561
commit 6f4bbe62dd
2 changed files with 32 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"bufio"
"strings"
"os/exec"
"io/ioutil"
gotime "time"
"github.com/veandco/go-sdl2/sdl"
@@ -109,6 +110,7 @@ type TitleBar struct {
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
MyTimeLocation *gotime.Location
TitleFont *ttf.Font
TimeFont *ttf.Font
@@ -405,6 +407,9 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
}
}
self.UpdateTimeLocation()
}
func (self *TitleBar) ClearCanvas() {
@@ -421,6 +426,29 @@ func (self *TitleBar) ClearCanvas() {
}
func (self *TitleBar) UpdateTimeLocation() {
d,err := ioutil.ReadFile("/etc/localtime")
if err != nil {
return
}
self.MyTimeLocation,err = gotime.LoadLocationFromTZData("local", d)
if err != nil {
fmt.Println(err)
self.MyTimeLocation = nil
}
}
func (self *TitleBar) GetLocalTime() gotime.Time {
if self.MyTimeLocation == nil {
return gotime.Now()
}else {
return gotime.Now().In(self.MyTimeLocation)
}
}
func (self *TitleBar) Draw(title string) {
self.ClearCanvas()
self.Title = title