mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-03-19 10:22:41 +01:00
go fmt ./...
This commit is contained in:
@@ -1,87 +1,77 @@
|
||||
package Emulator
|
||||
|
||||
import (
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
)
|
||||
|
||||
type ActionConfig struct {
|
||||
ROM string `ini:"ROM"`
|
||||
ROM_SO string `ini:"ROM_SO"`
|
||||
EXT []string `ini:"EXT,omitempty"`
|
||||
EXCLUDE []string `ini:"EXCLUDE,omitempty"`
|
||||
FILETYPE string `ini:"FILETYPE"` // defalut is file
|
||||
LAUNCHER string `ini:"LAUNCHER"`
|
||||
TITLE string `ini:"TITLE"` // defaut is Game
|
||||
SO_URL string `ini:"SO_URL"`
|
||||
RETRO_CONFIG string `ini:"RETRO_CONFIG"`
|
||||
ROM string `ini:"ROM"`
|
||||
ROM_SO string `ini:"ROM_SO"`
|
||||
EXT []string `ini:"EXT,omitempty"`
|
||||
EXCLUDE []string `ini:"EXCLUDE,omitempty"`
|
||||
FILETYPE string `ini:"FILETYPE"` // defalut is file
|
||||
LAUNCHER string `ini:"LAUNCHER"`
|
||||
TITLE string `ini:"TITLE"` // defaut is Game
|
||||
SO_URL string `ini:"SO_URL"`
|
||||
RETRO_CONFIG string `ini:"RETRO_CONFIG"`
|
||||
}
|
||||
|
||||
|
||||
var (
|
||||
FavGID = 31415
|
||||
FavGname = "cpifav"
|
||||
|
||||
FavGID = 31415
|
||||
FavGname = "cpifav"
|
||||
)
|
||||
|
||||
|
||||
type MyEmulator struct { // as leader of RomListPage and FavListPage, it's a PluginInterface
|
||||
Name string
|
||||
RomPage *RomListPage
|
||||
FavPage *FavListPage
|
||||
DeleteConfirmPage *UI.DeleteConfirmPage
|
||||
EmulatorConfig *ActionConfig
|
||||
|
||||
SpeedMax int
|
||||
SpeedTimeInter int
|
||||
|
||||
Name string
|
||||
RomPage *RomListPage
|
||||
FavPage *FavListPage
|
||||
DeleteConfirmPage *UI.DeleteConfirmPage
|
||||
EmulatorConfig *ActionConfig
|
||||
|
||||
SpeedMax int
|
||||
SpeedTimeInter int
|
||||
}
|
||||
|
||||
func NewMyEmulator() *MyEmulator{
|
||||
p := &MyEmulator{}
|
||||
|
||||
p.SpeedMax = 5
|
||||
p.SpeedTimeInter = 300
|
||||
|
||||
return p
|
||||
func NewMyEmulator() *MyEmulator {
|
||||
p := &MyEmulator{}
|
||||
|
||||
p.SpeedMax = 5
|
||||
p.SpeedTimeInter = 300
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *MyEmulator) GetName() string {
|
||||
return "MyEmulator"
|
||||
return "MyEmulator"
|
||||
}
|
||||
|
||||
func (self *MyEmulator) Init(main_screen *UI.MainScreen) {
|
||||
self.DeleteConfirmPage = UI.NewDeleteConfirmPage()
|
||||
self.DeleteConfirmPage.Screen = main_screen
|
||||
self.DeleteConfirmPage.Name = "Delete Confirm"
|
||||
self.DeleteConfirmPage.Init()
|
||||
func (self *MyEmulator) Init(main_screen *UI.MainScreen) {
|
||||
self.DeleteConfirmPage = UI.NewDeleteConfirmPage()
|
||||
self.DeleteConfirmPage.Screen = main_screen
|
||||
self.DeleteConfirmPage.Name = "Delete Confirm"
|
||||
self.DeleteConfirmPage.Init()
|
||||
|
||||
self.RomPage = NewRomListPage()
|
||||
self.RomPage.Screen = main_screen
|
||||
self.RomPage.Name = self.EmulatorConfig.TITLE
|
||||
self.RomPage.EmulatorConfig = self.EmulatorConfig
|
||||
self.RomPage.Leader = self
|
||||
self.RomPage.Init()
|
||||
|
||||
self.FavPage = NewFavListPage()
|
||||
self.FavPage.Screen = main_screen
|
||||
self.FavPage.Name = "FavouriteGames"
|
||||
self.FavPage.EmulatorConfig = self.EmulatorConfig
|
||||
self.FavPage.Leader = self
|
||||
self.FavPage.Init()
|
||||
|
||||
self.RomPage = NewRomListPage()
|
||||
self.RomPage.Screen = main_screen
|
||||
self.RomPage.Name = self.EmulatorConfig.TITLE
|
||||
self.RomPage.EmulatorConfig = self.EmulatorConfig
|
||||
self.RomPage.Leader = self
|
||||
self.RomPage.Init()
|
||||
|
||||
self.FavPage = NewFavListPage()
|
||||
self.FavPage.Screen = main_screen
|
||||
self.FavPage.Name = "FavouriteGames"
|
||||
self.FavPage.EmulatorConfig = self.EmulatorConfig
|
||||
self.FavPage.Leader = self
|
||||
self.FavPage.Init()
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *MyEmulator) Run(main_screen *UI.MainScreen) {
|
||||
if main_screen != nil {
|
||||
main_screen.PushCurPage()
|
||||
main_screen.SetCurPage(self.RomPage)
|
||||
main_screen.PushCurPage()
|
||||
main_screen.SetCurPage(self.RomPage)
|
||||
main_screen.Draw()
|
||||
main_screen.SwapAndShow()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,118 +1,112 @@
|
||||
package Emulator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
//"github.com/veandco/go-sdl2/sdl"
|
||||
"fmt"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
//"github.com/veandco/go-sdl2/sdl"
|
||||
//"github.com/cuu/gogame/surface"
|
||||
//"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/color"
|
||||
//"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
|
||||
)
|
||||
|
||||
type EmulatorPageInterface interface {
|
||||
UI.PageInterface
|
||||
GetMapIcons() map[string]UI.IconItemInterface
|
||||
GetEmulatorConfig() *ActionConfig
|
||||
type EmulatorPageInterface interface {
|
||||
UI.PageInterface
|
||||
GetMapIcons() map[string]UI.IconItemInterface
|
||||
GetEmulatorConfig() *ActionConfig
|
||||
}
|
||||
|
||||
|
||||
type EmulatorListItem struct {
|
||||
UI.HierListItem
|
||||
Parent EmulatorPageInterface
|
||||
UI.HierListItem
|
||||
Parent EmulatorPageInterface
|
||||
}
|
||||
|
||||
func NewEmulatorListItem() *EmulatorListItem {
|
||||
p := &EmulatorListItem{}
|
||||
p.Labels = make(map[string]UI.LabelInterface)
|
||||
p.Icons = make( map[string]UI.IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
p.MyType = UI.ICON_TYPES["EXE"]
|
||||
p := &EmulatorListItem{}
|
||||
p.Labels = make(map[string]UI.LabelInterface)
|
||||
p.Icons = make(map[string]UI.IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
p.MyType = UI.ICON_TYPES["EXE"]
|
||||
p.Height = 32
|
||||
p.Width = 0
|
||||
|
||||
|
||||
return p
|
||||
p.Width = 0
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *EmulatorListItem) Init(text string) {
|
||||
l := UI.NewLabel()
|
||||
l.PosX = 20
|
||||
l := UI.NewLabel()
|
||||
l.PosX = 20
|
||||
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
|
||||
if self.IsDir() == true || self.IsFile() == true {
|
||||
self.Path = text
|
||||
}
|
||||
|
||||
label_text := filepath.Base(text)
|
||||
ext:= filepath.Ext(text)
|
||||
if ext != "" {
|
||||
alias_file := strings.Replace(text,ext,"",-1) + ".alias"
|
||||
|
||||
if UI.FileExists(alias_file) == true {
|
||||
b, err := ioutil.ReadFile(alias_file)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}else {
|
||||
label_text = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if self.IsDir() == true {
|
||||
l.Init(label_text, self.Fonts["normal"],nil)
|
||||
}else {
|
||||
l.Init(label_text,self.Fonts["normal"],nil)
|
||||
}
|
||||
|
||||
self.Labels["Text"] = l
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
|
||||
if self.IsDir() == true || self.IsFile() == true {
|
||||
self.Path = text
|
||||
}
|
||||
|
||||
label_text := filepath.Base(text)
|
||||
ext := filepath.Ext(text)
|
||||
if ext != "" {
|
||||
alias_file := strings.Replace(text, ext, "", -1) + ".alias"
|
||||
|
||||
if UI.FileExists(alias_file) == true {
|
||||
b, err := ioutil.ReadFile(alias_file)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
} else {
|
||||
label_text = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if self.IsDir() == true {
|
||||
l.Init(label_text, self.Fonts["normal"], nil)
|
||||
} else {
|
||||
l.Init(label_text, self.Fonts["normal"], nil)
|
||||
}
|
||||
|
||||
self.Labels["Text"] = l
|
||||
}
|
||||
|
||||
func (self *EmulatorListItem) Draw() {
|
||||
x,y := self.Labels["Text"].Coord()
|
||||
_,h := self.Labels["Text"].Size()
|
||||
|
||||
|
||||
if self.Path != "[..]" {
|
||||
self.Labels["Text"].NewCoord(23,y)
|
||||
|
||||
}else {
|
||||
self.Labels["Text"].NewCoord(3,y)
|
||||
}
|
||||
|
||||
x,y = self.Labels["Text"].Coord()
|
||||
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height-h)/2)
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
parent_icons := self.Parent.GetMapIcons()
|
||||
_,h = parent_icons["sys"].Size()
|
||||
|
||||
if self.IsDir() == true && self.Path != "[..]" {
|
||||
parent_icons["sys"].SetIconIndex (0)
|
||||
parent_icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
parent_icons["sys"].Draw()
|
||||
}
|
||||
|
||||
if self.IsFile() == true {
|
||||
parent_icons["sys"].SetIconIndex(1)
|
||||
parent_icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
parent_icons["sys"].Draw()
|
||||
}
|
||||
|
||||
draw.Line(self.Parent.GetCanvasHWND(),&color.Color{169,169,169,255},
|
||||
self.PosX,self.PosY+self.Height-1,self.PosX+self.Width,self.PosY+self.Height-1,1)
|
||||
x, y := self.Labels["Text"].Coord()
|
||||
_, h := self.Labels["Text"].Size()
|
||||
|
||||
if self.Path != "[..]" {
|
||||
self.Labels["Text"].NewCoord(23, y)
|
||||
|
||||
} else {
|
||||
self.Labels["Text"].NewCoord(3, y)
|
||||
}
|
||||
|
||||
x, y = self.Labels["Text"].Coord()
|
||||
self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
parent_icons := self.Parent.GetMapIcons()
|
||||
_, h = parent_icons["sys"].Size()
|
||||
|
||||
if self.IsDir() == true && self.Path != "[..]" {
|
||||
parent_icons["sys"].SetIconIndex(0)
|
||||
parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
|
||||
parent_icons["sys"].Draw()
|
||||
}
|
||||
|
||||
if self.IsFile() == true {
|
||||
parent_icons["sys"].SetIconIndex(1)
|
||||
parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
|
||||
parent_icons["sys"].Draw()
|
||||
}
|
||||
|
||||
draw.Line(self.Parent.GetCanvasHWND(), &color.Color{169, 169, 169, 255},
|
||||
self.PosX, self.PosY+self.Height-1, self.PosX+self.Width, self.PosY+self.Height-1, 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,122 +1,119 @@
|
||||
package Emulator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//"strconv"
|
||||
"strings"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
"fmt"
|
||||
//"strconv"
|
||||
"strings"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||
"github.com/cuu/gogame/event"
|
||||
)
|
||||
|
||||
type RomSoConfirmPage struct {
|
||||
UI.ConfirmPage
|
||||
Parent EmulatorPageInterface
|
||||
DownloadPage *UI.DownloadProcessPage
|
||||
|
||||
UI.ConfirmPage
|
||||
Parent EmulatorPageInterface
|
||||
DownloadPage *UI.DownloadProcessPage
|
||||
}
|
||||
|
||||
func NewRomSoConfirmPage() *RomSoConfirmPage {
|
||||
p := &RomSoConfirmPage{}
|
||||
p.PageIconMargin = 20
|
||||
p := &RomSoConfirmPage{}
|
||||
p.PageIconMargin = 20
|
||||
p.SelectedIconTopOffset = 20
|
||||
p.EasingDur = 10
|
||||
p.Align = UI.ALIGN["SLeft"]
|
||||
|
||||
p.ListFont = UI.Fonts["veramono18"]
|
||||
p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
|
||||
p.ConfirmText ="Do you want to setup this game engine automatically?"
|
||||
|
||||
return p
|
||||
|
||||
|
||||
p.ListFont = UI.Fonts["veramono18"]
|
||||
p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
|
||||
p.ConfirmText = "Do you want to setup this game engine automatically?"
|
||||
|
||||
return p
|
||||
|
||||
}
|
||||
|
||||
func (self *RomSoConfirmPage) Init() {
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
self.Width = self.Screen.Width
|
||||
self.Height = self.Screen.Height
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
self.Width = self.Screen.Width
|
||||
self.Height = self.Screen.Height
|
||||
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
|
||||
li := UI.NewMultiLabel()
|
||||
li.SetCanvasHWND(self.CanvasHWND)
|
||||
li.Width = 160
|
||||
li.Init(self.ConfirmText,self.ListFont,nil)
|
||||
|
||||
li.PosX = (self.Width - li.Width)/2
|
||||
li.PosY = (self.Height - li.Height)/2
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
|
||||
li := UI.NewMultiLabel()
|
||||
li.SetCanvasHWND(self.CanvasHWND)
|
||||
li.Width = 160
|
||||
li.Init(self.ConfirmText, self.ListFont, nil)
|
||||
|
||||
li.PosX = (self.Width - li.Width) / 2
|
||||
li.PosY = (self.Height - li.Height) / 2
|
||||
|
||||
self.BGPosX = li.PosX - 20
|
||||
self.BGPosY = li.PosY - 20
|
||||
self.BGWidth = li.Width + 40
|
||||
self.BGHeight = li.Height + 40
|
||||
|
||||
self.MyList = append(self.MyList, li)
|
||||
|
||||
self.BGPosX = li.PosX-20
|
||||
self.BGPosY = li.PosY-20
|
||||
self.BGWidth = li.Width+40
|
||||
self.BGHeight = li.Height+40
|
||||
|
||||
self.MyList = append(self.MyList ,li )
|
||||
|
||||
}
|
||||
|
||||
func (self *RomSoConfirmPage) SnapMsg(msg string) {
|
||||
self.MyList[0].SetText(msg)
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.MyList[0].SetText(self.ConfirmText)
|
||||
self.MyList[0].SetText(msg)
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.MyList[0].SetText(self.ConfirmText)
|
||||
}
|
||||
|
||||
func (self *RomSoConfirmPage) OnReturnBackCb() {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
func (self *RomSoConfirmPage) KeyDown(ev *event.Event) {
|
||||
|
||||
if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["A"] {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == UI.CurKeys["B"] {
|
||||
bat := UI.CheckBattery()
|
||||
if bat < 5 && bat >= 0 {
|
||||
self.SnapMsg("Battery must over 5%")
|
||||
}else { // -1 or something else,
|
||||
if self.DownloadPage == nil {
|
||||
self.DownloadPage = UI.NewDownloadProcessPage()
|
||||
self.DownloadPage.Screen = self.Screen
|
||||
self.DownloadPage.Name = "Downloading"
|
||||
self.DownloadPage.Init()
|
||||
}
|
||||
|
||||
self.Screen.PushPage(self.DownloadPage)
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
ec := self.Parent.GetEmulatorConfig()
|
||||
if sysgo.CurKeySet == "PC" {
|
||||
|
||||
so_url := ec.SO_URL
|
||||
so_url = strings.Replace(so_url,"armhf","x86_64",-1)
|
||||
fmt.Println(so_url)
|
||||
self.DownloadPage.StartDownload(so_url,filepath.Dir(ec.ROM_SO))
|
||||
|
||||
}else{
|
||||
so_url := ec.SO_URL
|
||||
go self.DownloadPage.StartDownload(so_url,filepath.Dir(ec.ROM_SO))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["A"] {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == UI.CurKeys["B"] {
|
||||
bat := UI.CheckBattery()
|
||||
if bat < 5 && bat >= 0 {
|
||||
self.SnapMsg("Battery must over 5%")
|
||||
} else { // -1 or something else,
|
||||
if self.DownloadPage == nil {
|
||||
self.DownloadPage = UI.NewDownloadProcessPage()
|
||||
self.DownloadPage.Screen = self.Screen
|
||||
self.DownloadPage.Name = "Downloading"
|
||||
self.DownloadPage.Init()
|
||||
}
|
||||
|
||||
self.Screen.PushPage(self.DownloadPage)
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
ec := self.Parent.GetEmulatorConfig()
|
||||
if sysgo.CurKeySet == "PC" {
|
||||
|
||||
so_url := ec.SO_URL
|
||||
so_url = strings.Replace(so_url, "armhf", "x86_64", -1)
|
||||
fmt.Println(so_url)
|
||||
self.DownloadPage.StartDownload(so_url, filepath.Dir(ec.ROM_SO))
|
||||
|
||||
} else {
|
||||
so_url := ec.SO_URL
|
||||
go self.DownloadPage.StartDownload(so_url, filepath.Dir(ec.ROM_SO))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *RomSoConfirmPage) Draw() {
|
||||
self.ClearCanvas()
|
||||
self.DrawBG()
|
||||
for _,v := range self.MyList{
|
||||
v.Draw()
|
||||
}
|
||||
|
||||
self.ClearCanvas()
|
||||
self.DrawBG()
|
||||
for _, v := range self.MyList {
|
||||
v.Draw()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
117
sysgo/UI/UI.go
117
sysgo/UI/UI.go
@@ -1,54 +1,52 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
|
||||
"fmt"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/font"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
"github.com/cuu/gogame/font"
|
||||
)
|
||||
|
||||
type WidgetInterface interface {
|
||||
Size() (int,int)
|
||||
NewSize(w,h int)
|
||||
Coord()(int,int)
|
||||
NewCoord(x,y int)
|
||||
Size() (int, int)
|
||||
NewSize(w, h int)
|
||||
Coord() (int, int)
|
||||
NewCoord(x, y int)
|
||||
}
|
||||
|
||||
type Coord struct {
|
||||
X int
|
||||
Y int
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Plane struct {
|
||||
W int
|
||||
H int
|
||||
|
||||
W int
|
||||
H int
|
||||
}
|
||||
|
||||
type Widget struct {
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
func (self *Widget) Size() (int,int) {
|
||||
return self.Width,self.Height
|
||||
func (self *Widget) Size() (int, int) {
|
||||
return self.Width, self.Height
|
||||
}
|
||||
|
||||
func (self *Widget) NewSize(w,h int) {
|
||||
func (self *Widget) NewSize(w, h int) {
|
||||
self.Width = w
|
||||
self.Height = h
|
||||
}
|
||||
|
||||
func (self *Widget) Coord() (int,int) {
|
||||
return self.PosX,self.PosY
|
||||
func (self *Widget) Coord() (int, int) {
|
||||
return self.PosX, self.PosY
|
||||
}
|
||||
|
||||
func (self *Widget) NewCoord(x,y int) {
|
||||
func (self *Widget) NewCoord(x, y int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
}
|
||||
@@ -57,58 +55,55 @@ func (self *Widget) NewCoord(x,y int) {
|
||||
func Init() {
|
||||
font.Init()
|
||||
|
||||
skinpath := sysgo.SKIN+"/truetype"
|
||||
skinpath := sysgo.SKIN + "/truetype"
|
||||
|
||||
Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
fonts_path := make(map[string]string)
|
||||
|
||||
fonts_path["varela"] = fmt.Sprintf("%s/VarelaRound-Regular.ttf", skinpath)
|
||||
fonts_path["veramono"] = fmt.Sprintf("%s/VeraMono.ttf", skinpath)
|
||||
fonts_path["noto"] = fmt.Sprintf("%s/NotoSansMono-Regular.ttf", skinpath)
|
||||
fonts_path["notocjk"] = fmt.Sprintf("%s/NotoSansCJK-Regular.ttf", skinpath)
|
||||
|
||||
fonts_path["varela"] = fmt.Sprintf("%s/VarelaRound-Regular.ttf",skinpath)
|
||||
fonts_path["veramono"] = fmt.Sprintf("%s/VeraMono.ttf",skinpath)
|
||||
fonts_path["noto"] = fmt.Sprintf("%s/NotoSansMono-Regular.ttf", skinpath)
|
||||
fonts_path["notocjk"] = fmt.Sprintf("%s/NotoSansCJK-Regular.ttf" ,skinpath)
|
||||
|
||||
for i:=10;i<41;i++ {
|
||||
keyname := fmt.Sprintf("varela%d",i)
|
||||
Fonts[ keyname ] = font.Font(fonts_path["varela"],i)
|
||||
for i := 10; i < 41; i++ {
|
||||
keyname := fmt.Sprintf("varela%d", i)
|
||||
Fonts[keyname] = font.Font(fonts_path["varela"], i)
|
||||
}
|
||||
|
||||
Fonts["varela120"] = font.Font(fonts_path["varela"],120)
|
||||
|
||||
for i:=10;i<26;i++ {
|
||||
|
||||
Fonts["varela120"] = font.Font(fonts_path["varela"], 120)
|
||||
|
||||
for i := 10; i < 26; i++ {
|
||||
keyname := fmt.Sprintf("veramono%d", i)
|
||||
Fonts[keyname] = font.Font(fonts_path["veramono"],i)
|
||||
Fonts[keyname] = font.Font(fonts_path["veramono"], i)
|
||||
}
|
||||
|
||||
for i:= 10;i<28;i++ {
|
||||
for i := 10; i < 28; i++ {
|
||||
keyname := fmt.Sprintf("notosansmono%d", i)
|
||||
Fonts[keyname] = font.Font(fonts_path["noto"], i)
|
||||
}
|
||||
|
||||
for i:=10;i<28;i++ {
|
||||
keyname := fmt.Sprintf("notosanscjk%d",i)
|
||||
Fonts[keyname] = font.Font(fonts_path["notocjk"],i)
|
||||
for i := 10; i < 28; i++ {
|
||||
keyname := fmt.Sprintf("notosanscjk%d", i)
|
||||
Fonts[keyname] = font.Font(fonts_path["notocjk"], i)
|
||||
}
|
||||
|
||||
//
|
||||
keys_def_init()
|
||||
|
||||
//// global variables Init
|
||||
if MyIconPool == nil {
|
||||
MyIconPool = NewIconPool()
|
||||
MyIconPool.Init()
|
||||
}
|
||||
if MyLangManager == nil {
|
||||
|
||||
MyLangManager = NewLangManager()
|
||||
MyLangManager.Init()
|
||||
|
||||
}
|
||||
if MySkinManager == nil {
|
||||
MySkinManager = NewSkinManager()
|
||||
MySkinManager.Init()
|
||||
}
|
||||
|
||||
//
|
||||
keys_def_init()
|
||||
|
||||
//// global variables Init
|
||||
if MyIconPool == nil {
|
||||
MyIconPool = NewIconPool()
|
||||
MyIconPool.Init()
|
||||
}
|
||||
if MyLangManager == nil {
|
||||
|
||||
MyLangManager = NewLangManager()
|
||||
MyLangManager.Init()
|
||||
|
||||
}
|
||||
if MySkinManager == nil {
|
||||
MySkinManager = NewSkinManager()
|
||||
MySkinManager.Init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +1,73 @@
|
||||
package UI
|
||||
|
||||
import(
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/rect"
|
||||
)
|
||||
|
||||
type AboveAllPatch struct {
|
||||
Widget
|
||||
|
||||
Widget
|
||||
|
||||
Text string
|
||||
|
||||
FontObj *ttf.Font
|
||||
|
||||
Color *color.Color
|
||||
ValColor *color.Color
|
||||
|
||||
CanvasHWND *sdl.Surface
|
||||
|
||||
Icons map[string]IconItemInterface
|
||||
|
||||
Value int
|
||||
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
|
||||
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) 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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,167 +3,160 @@ package UI
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
// "github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
// "github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/color"
|
||||
// "github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/rect"
|
||||
// "github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
)
|
||||
|
||||
type ListPageSelector struct {
|
||||
PageSelector
|
||||
BackgroundColor *color.Color
|
||||
Parent *ConfirmPage
|
||||
PageSelector
|
||||
BackgroundColor *color.Color
|
||||
Parent *ConfirmPage
|
||||
}
|
||||
|
||||
func NewListPageSelector() *ListPageSelector {
|
||||
p := &ListPageSelector{}
|
||||
p.Width = Width
|
||||
p.BackgroundColor = &color.Color{131,199,219,255}
|
||||
return p
|
||||
p := &ListPageSelector{}
|
||||
p.Width = Width
|
||||
p.BackgroundColor = &color.Color{131, 199, 219, 255}
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *ListPageSelector) Draw() {
|
||||
idx := self.Parent.GetPsIndex()
|
||||
mylist := self.Parent.MyList
|
||||
if idx > (len(mylist) -1) {
|
||||
idx = len(mylist)
|
||||
if idx > 0 {
|
||||
idx -= 1
|
||||
}else if idx == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
x,y := mylist[idx].Coord()
|
||||
_,h := mylist[idx].Size()
|
||||
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Height = h -3
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
|
||||
draw.AARoundRect(canvas_,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||
|
||||
|
||||
idx := self.Parent.GetPsIndex()
|
||||
mylist := self.Parent.MyList
|
||||
if idx > (len(mylist) - 1) {
|
||||
idx = len(mylist)
|
||||
if idx > 0 {
|
||||
idx -= 1
|
||||
} else if idx == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
x, y := mylist[idx].Coord()
|
||||
_, h := mylist[idx].Size()
|
||||
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Height = h - 3
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
|
||||
draw.AARoundRect(canvas_, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
|
||||
|
||||
}
|
||||
|
||||
type ConfirmPage struct {
|
||||
Page
|
||||
ListFont *ttf.Font
|
||||
FileName string
|
||||
TrashDir string
|
||||
ConfirmText string
|
||||
BGPosX int
|
||||
BGPosY int
|
||||
BGWidth int
|
||||
BGHeight int
|
||||
Icons map[string]IconItemInterface
|
||||
|
||||
MyList []LabelInterface
|
||||
|
||||
Page
|
||||
ListFont *ttf.Font
|
||||
FileName string
|
||||
TrashDir string
|
||||
ConfirmText string
|
||||
BGPosX int
|
||||
BGPosY int
|
||||
BGWidth int
|
||||
BGHeight int
|
||||
Icons map[string]IconItemInterface
|
||||
|
||||
MyList []LabelInterface
|
||||
}
|
||||
|
||||
func NewConfirmPage() *ConfirmPage {
|
||||
p := &ConfirmPage{}
|
||||
p.ListFont = Fonts["veramono20"]
|
||||
p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
|
||||
p.ConfirmText = "Confirm?"
|
||||
|
||||
func NewConfirmPage() *ConfirmPage {
|
||||
p := &ConfirmPage{}
|
||||
p.ListFont = Fonts["veramono20"]
|
||||
p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
|
||||
p.ConfirmText ="Confirm?"
|
||||
|
||||
return p
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
func (self *ConfirmPage) Reset() {
|
||||
self.MyList[0].SetText(self.ConfirmText)
|
||||
x,y := self.MyList[0].Coord()
|
||||
w,h := self.MyList[0].Size()
|
||||
|
||||
self.MyList[0].NewCoord( (self.Width - w)/2, (self.Height - h)/2)
|
||||
|
||||
x,y = self.MyList[0].Coord()
|
||||
|
||||
self.BGPosX = x - 10
|
||||
self.BGPosY = y - 10
|
||||
|
||||
self.BGWidth = w + 20
|
||||
self.BGHeight = h + 20
|
||||
self.MyList[0].SetText(self.ConfirmText)
|
||||
x, y := self.MyList[0].Coord()
|
||||
w, h := self.MyList[0].Size()
|
||||
|
||||
self.MyList[0].NewCoord((self.Width-w)/2, (self.Height-h)/2)
|
||||
|
||||
x, y = self.MyList[0].Coord()
|
||||
|
||||
self.BGPosX = x - 10
|
||||
self.BGPosY = y - 10
|
||||
|
||||
self.BGWidth = w + 20
|
||||
self.BGHeight = h + 20
|
||||
}
|
||||
|
||||
func (self *ConfirmPage) SnapMsg(msg string) {
|
||||
self.MyList[0].SetText(msg)
|
||||
x,y := self.MyList[0].Coord()
|
||||
w,h := self.MyList[0].Size()
|
||||
|
||||
self.MyList[0].NewCoord( (self.Width - w )/2, (self.Height - h)/2 )
|
||||
|
||||
x, y = self.MyList[0].Coord()
|
||||
|
||||
self.BGPosX = x - 10
|
||||
self.BGPosY = y - 10
|
||||
|
||||
self.BGWidth = w + 20
|
||||
self.BGHeight = h +20
|
||||
|
||||
self.MyList[0].SetText(msg)
|
||||
x, y := self.MyList[0].Coord()
|
||||
w, h := self.MyList[0].Size()
|
||||
|
||||
self.MyList[0].NewCoord((self.Width-w)/2, (self.Height-h)/2)
|
||||
|
||||
x, y = self.MyList[0].Coord()
|
||||
|
||||
self.BGPosX = x - 10
|
||||
self.BGPosY = y - 10
|
||||
|
||||
self.BGWidth = w + 20
|
||||
self.BGHeight = h + 20
|
||||
|
||||
}
|
||||
|
||||
func (self *ConfirmPage) Init() {
|
||||
if self.Screen != nil {
|
||||
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
if self.Screen != nil {
|
||||
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
self.Width = self.Screen.Width
|
||||
self.Height = self.Screen.Height
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
|
||||
ps := NewListPageSelector()
|
||||
ps.Parent = self
|
||||
self.Ps = ps
|
||||
self.PsIndex = 0
|
||||
|
||||
li := NewLabel()
|
||||
li.SetCanvasHWND(self.CanvasHWND)
|
||||
li.Init(self.ConfirmText,self.ListFont,nil)
|
||||
|
||||
li.PosX = (self.Width - li.Width)/2
|
||||
li.PosY = (self.Height - li.Height)/2
|
||||
|
||||
self.BGPosX = li.PosX - 10
|
||||
self.BGPosY = li.PosY - 10
|
||||
self.BGWidth = li.Width + 20
|
||||
self.BGHeight = li.Height + 20
|
||||
|
||||
self.MyList = append(self.MyList,li)
|
||||
|
||||
}
|
||||
|
||||
ps := NewListPageSelector()
|
||||
ps.Parent = self
|
||||
self.Ps = ps
|
||||
self.PsIndex = 0
|
||||
|
||||
li := NewLabel()
|
||||
li.SetCanvasHWND(self.CanvasHWND)
|
||||
li.Init(self.ConfirmText, self.ListFont, nil)
|
||||
|
||||
li.PosX = (self.Width - li.Width) / 2
|
||||
li.PosY = (self.Height - li.Height) / 2
|
||||
|
||||
self.BGPosX = li.PosX - 10
|
||||
self.BGPosY = li.PosY - 10
|
||||
self.BGWidth = li.Width + 20
|
||||
self.BGHeight = li.Height + 20
|
||||
|
||||
self.MyList = append(self.MyList, li)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ConfirmPage) KeyDown(ev *event.Event) {
|
||||
|
||||
func (self *ConfirmPage) KeyDown( ev *event.Event ) {
|
||||
|
||||
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ConfirmPage) DrawBG() {
|
||||
rect_ := rect.Rect(self.BGPosX,self.BGPosY,self.BGWidth,self.BGHeight)
|
||||
|
||||
draw.Rect(self.CanvasHWND,&color.Color{255,255,255,255}, &rect_, 0) // SkinManager().GiveColor('White')
|
||||
draw.Rect(self.CanvasHWND,&color.Color{83,83,83,255}, &rect_, 1)//SkinManager().GiveColor('Text')
|
||||
}
|
||||
rect_ := rect.Rect(self.BGPosX, self.BGPosY, self.BGWidth, self.BGHeight)
|
||||
|
||||
draw.Rect(self.CanvasHWND, &color.Color{255, 255, 255, 255}, &rect_, 0) // SkinManager().GiveColor('White')
|
||||
draw.Rect(self.CanvasHWND, &color.Color{83, 83, 83, 255}, &rect_, 1) //SkinManager().GiveColor('Text')
|
||||
}
|
||||
|
||||
func (self *ConfirmPage) Draw() {
|
||||
self.DrawBG()
|
||||
for _,v := range self.MyList{
|
||||
v.Draw()
|
||||
}
|
||||
self.Reset()
|
||||
self.DrawBG()
|
||||
for _, v := range self.MyList {
|
||||
v.Draw()
|
||||
}
|
||||
self.Reset()
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
|
||||
package UI
|
||||
|
||||
var (
|
||||
Width = 320
|
||||
Height = 240
|
||||
IconWidth = 80
|
||||
Width = 320
|
||||
Height = 240
|
||||
IconWidth = 80
|
||||
IconHeight = 80
|
||||
IconExt = ".sh"
|
||||
IconExt = ".sh"
|
||||
|
||||
ICON_TYPES = map[string]int{"Emulator":7,"FILE":6,"STAT":5,"NAV":4,"LETTER":3,"FUNC":2,"DIR":1,"EXE":0,"None":-1 }
|
||||
ALIGN = map[string]int{ "HLeft":0,"HCenter":1,"HRight":2,"VMiddle":3,"SLeft":4,"VCenter":5,"SCenter":6}
|
||||
ICON_TYPES = map[string]int{"Emulator": 7, "FILE": 6, "STAT": 5, "NAV": 4, "LETTER": 3, "FUNC": 2, "DIR": 1, "EXE": 0, "None": -1}
|
||||
ALIGN = map[string]int{"HLeft": 0, "HCenter": 1, "HRight": 2, "VMiddle": 3, "SLeft": 4, "VCenter": 5, "SCenter": 6}
|
||||
|
||||
DT = 50
|
||||
|
||||
DT = 50
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,168 +1,162 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
gotime "time"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"fmt"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
gotime "time"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
)
|
||||
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
|
||||
|
||||
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.Width = Width
|
||||
p.Height = Height
|
||||
|
||||
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
|
||||
p := &CounterScreen{}
|
||||
p.Width = Width
|
||||
p.Height = Height
|
||||
|
||||
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() {
|
||||
func (self *CounterScreen) Interval() {
|
||||
|
||||
for {
|
||||
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
|
||||
}
|
||||
}
|
||||
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 = gotime.NewTicker(500 * gotime.Millisecond)
|
||||
|
||||
go self.Interval()
|
||||
if self.Counting == true {
|
||||
return
|
||||
}
|
||||
|
||||
self.Number = 10
|
||||
self.inter_counter = 0
|
||||
|
||||
self.Counting = true
|
||||
|
||||
self.TheTicker = gotime.NewTicker(500 * gotime.Millisecond)
|
||||
|
||||
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
|
||||
|
||||
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.TickerStoped = make(chan bool,1)
|
||||
|
||||
|
||||
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.TickerStoped = make(chan bool, 1)
|
||||
|
||||
}
|
||||
|
||||
func (self *CounterScreen) Draw() {
|
||||
surface.Fill(self.CanvasHWND, self.BGColor)
|
||||
|
||||
self.TopLabel.NewCoord(Width/2,15)
|
||||
self.TopLabel.DrawCenter(false)
|
||||
|
||||
self.BottomLabel.NewCoord(Width/2, Height-15)
|
||||
self.BottomLabel.DrawCenter(false)
|
||||
surface.Fill(self.CanvasHWND, self.BGColor)
|
||||
|
||||
self.NumberLabel.NewCoord(Width/2,Height/2)
|
||||
number_str := fmt.Sprintf("%d",self.Number)
|
||||
self.NumberLabel.SetText(number_str)
|
||||
self.NumberLabel.DrawCenter(false)
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,77 +1,73 @@
|
||||
package UI
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/time"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/time"
|
||||
)
|
||||
|
||||
type DeleteConfirmPage struct {
|
||||
ConfirmPage
|
||||
|
||||
ConfirmPage
|
||||
}
|
||||
|
||||
|
||||
func NewDeleteConfirmPage() *DeleteConfirmPage {
|
||||
p := &DeleteConfirmPage{}
|
||||
p.ListFont = Fonts["veramono20"]
|
||||
p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
|
||||
p.ConfirmText ="Confirm Delete ?"
|
||||
|
||||
|
||||
return p
|
||||
p := &DeleteConfirmPage{}
|
||||
p.ListFont = Fonts["veramono20"]
|
||||
p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
|
||||
p.ConfirmText = "Confirm Delete ?"
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
func (self *DeleteConfirmPage) SetTrashDir(d string) {
|
||||
self.TrashDir = d
|
||||
if IsDirectory(self.TrashDir)== false {
|
||||
panic("DeleteConfirmPage SetTrashDir errors")
|
||||
}
|
||||
self.TrashDir = d
|
||||
if IsDirectory(self.TrashDir) == false {
|
||||
panic("DeleteConfirmPage SetTrashDir errors")
|
||||
}
|
||||
}
|
||||
|
||||
func (self *DeleteConfirmPage) SetFileName(fn string) {
|
||||
self.FileName = fn
|
||||
self.FileName = fn
|
||||
}
|
||||
|
||||
func (self *DeleteConfirmPage) KeyDown(ev *event.Event) {
|
||||
|
||||
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
|
||||
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["B"] {
|
||||
err := os.Remove(filepath.Join(self.TrashDir, filepath.Base(self.FileName)))
|
||||
if err != nil {
|
||||
fmt.Println("DeleteConfirmPage os.Remove errors :",err)
|
||||
}
|
||||
|
||||
err = os.Rename(filepath.Base(self.FileName), filepath.Join(self.TrashDir, filepath.Base(self.FileName)))
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(),"exists" ) {
|
||||
self.Screen.MsgBox.SetText("Already Existed")
|
||||
} else {
|
||||
self.Screen.MsgBox.SetText("Error")
|
||||
}
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
} else {
|
||||
self.SnapMsg("Deleting")
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.Reset()
|
||||
time.BlockDelay(300)
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
fmt.Println(self.FileName)
|
||||
}
|
||||
if ev.Data["Key"] == CurKeys["B"] {
|
||||
err := os.Remove(filepath.Join(self.TrashDir, filepath.Base(self.FileName)))
|
||||
if err != nil {
|
||||
fmt.Println("DeleteConfirmPage os.Remove errors :", err)
|
||||
}
|
||||
|
||||
err = os.Rename(filepath.Base(self.FileName), filepath.Join(self.TrashDir, filepath.Base(self.FileName)))
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "exists") {
|
||||
self.Screen.MsgBox.SetText("Already Existed")
|
||||
} else {
|
||||
self.Screen.MsgBox.SetText("Error")
|
||||
}
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
} else {
|
||||
self.SnapMsg("Deleting")
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.Reset()
|
||||
time.BlockDelay(300)
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
fmt.Println(self.FileName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,291 +1,284 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
"os/exec"
|
||||
|
||||
gotime "time"
|
||||
"net/url"
|
||||
|
||||
"github.com/cuu/grab"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"net/url"
|
||||
gotime "time"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/grab"
|
||||
)
|
||||
|
||||
type DownloadProcessPage struct {
|
||||
Page
|
||||
|
||||
URL string
|
||||
DST_DIR string
|
||||
Value int
|
||||
PngSize map[string][2]int
|
||||
Doing bool
|
||||
|
||||
FileNameLabel LabelInterface
|
||||
SizeLabel LabelInterface
|
||||
|
||||
Icons map[string]IconItemInterface
|
||||
Page
|
||||
|
||||
URLColor *color.Color
|
||||
TextColor *color.Color
|
||||
TheTicker *gotime.Ticker
|
||||
|
||||
Downloader *grab.Client
|
||||
resp *grab.Response
|
||||
req *grab.Request
|
||||
|
||||
URL string
|
||||
DST_DIR string
|
||||
Value int
|
||||
PngSize map[string][2]int
|
||||
Doing bool
|
||||
|
||||
FileNameLabel LabelInterface
|
||||
SizeLabel LabelInterface
|
||||
|
||||
Icons map[string]IconItemInterface
|
||||
|
||||
URLColor *color.Color
|
||||
TextColor *color.Color
|
||||
TheTicker *gotime.Ticker
|
||||
|
||||
Downloader *grab.Client
|
||||
resp *grab.Response
|
||||
req *grab.Request
|
||||
}
|
||||
|
||||
|
||||
func NewDownloadProcessPage() *DownloadProcessPage {
|
||||
|
||||
p := &DownloadProcessPage{}
|
||||
|
||||
p.FootMsg = [5]string{"Nav","","","Back",""}
|
||||
|
||||
p.URLColor = &color.Color{51, 166, 255,255 } // URL
|
||||
p.TextColor = &color.Color{83,83,83,255 } // Text
|
||||
|
||||
p.PngSize = make(map[string][2]int,0)
|
||||
|
||||
p.Icons=make(map[string]IconItemInterface)
|
||||
|
||||
return p
|
||||
|
||||
p := &DownloadProcessPage{}
|
||||
|
||||
p.FootMsg = [5]string{"Nav", "", "", "Back", ""}
|
||||
|
||||
p.URLColor = &color.Color{51, 166, 255, 255} // URL
|
||||
p.TextColor = &color.Color{83, 83, 83, 255} // Text
|
||||
|
||||
p.PngSize = make(map[string][2]int, 0)
|
||||
|
||||
p.Icons = make(map[string]IconItemInterface)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) Init() {
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
self.Width = self.Screen.Width
|
||||
self.Height = self.Screen.Height
|
||||
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
self.PngSize["bg"] = [2]int{48,79}
|
||||
self.PngSize["needwifi_bg"] = [2]int{253,132}
|
||||
|
||||
bgpng := NewIconItem()
|
||||
bgpng.ImgSurf = MyIconPool.GetImgSurf("rom_download")
|
||||
bgpng.MyType = ICON_TYPES["STAT"]
|
||||
bgpng.Parent = self
|
||||
bgpng.Adjust(0,0,self.PngSize["bg"][0],self.PngSize["bg"][1],0)
|
||||
self.Icons["bg"] = bgpng
|
||||
|
||||
needwifi_bg := NewIconItem()
|
||||
needwifi_bg.ImgSurf = MyIconPool.GetImgSurf("needwifi_bg")
|
||||
needwifi_bg.MyType = ICON_TYPES["STAT"]
|
||||
needwifi_bg.Parent = self
|
||||
needwifi_bg.Adjust(0,0,self.PngSize["needwifi_bg"][0],self.PngSize["needwifi_bg"][1],0)
|
||||
|
||||
self.Icons["needwifi_bg"] = needwifi_bg
|
||||
self.PosX = self.Index * self.Screen.Width
|
||||
self.Width = self.Screen.Width
|
||||
self.Height = self.Screen.Height
|
||||
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
self.PngSize["bg"] = [2]int{48, 79}
|
||||
self.PngSize["needwifi_bg"] = [2]int{253, 132}
|
||||
|
||||
bgpng := NewIconItem()
|
||||
bgpng.ImgSurf = MyIconPool.GetImgSurf("rom_download")
|
||||
bgpng.MyType = ICON_TYPES["STAT"]
|
||||
bgpng.Parent = self
|
||||
bgpng.Adjust(0, 0, self.PngSize["bg"][0], self.PngSize["bg"][1], 0)
|
||||
self.Icons["bg"] = bgpng
|
||||
|
||||
needwifi_bg := NewIconItem()
|
||||
needwifi_bg.ImgSurf = MyIconPool.GetImgSurf("needwifi_bg")
|
||||
needwifi_bg.MyType = ICON_TYPES["STAT"]
|
||||
needwifi_bg.Parent = self
|
||||
needwifi_bg.Adjust(0, 0, self.PngSize["needwifi_bg"][0], self.PngSize["needwifi_bg"][1], 0)
|
||||
|
||||
self.Icons["needwifi_bg"] = needwifi_bg
|
||||
|
||||
self.FileNameLabel = NewLabel()
|
||||
self.FileNameLabel.SetCanvasHWND(self.CanvasHWND)
|
||||
self.FileNameLabel.Init("", Fonts["varela12"], nil)
|
||||
|
||||
self.SizeLabel = NewLabel()
|
||||
self.SizeLabel.SetCanvasHWND(self.CanvasHWND)
|
||||
self.SizeLabel.Init("0/0Kb", Fonts["varela12"], nil)
|
||||
self.SizeLabel.SetColor(self.URLColor)
|
||||
|
||||
self.Downloader = grab.NewClient()
|
||||
|
||||
self.FileNameLabel = NewLabel()
|
||||
self.FileNameLabel.SetCanvasHWND(self.CanvasHWND)
|
||||
self.FileNameLabel.Init("", Fonts["varela12"],nil)
|
||||
|
||||
self.SizeLabel = NewLabel()
|
||||
self.SizeLabel.SetCanvasHWND(self.CanvasHWND)
|
||||
self.SizeLabel.Init("0/0Kb",Fonts["varela12"],nil)
|
||||
self.SizeLabel.SetColor( self.URLColor )
|
||||
|
||||
self.Downloader = grab.NewClient()
|
||||
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) OnExitCb() {
|
||||
|
||||
//Stop Ticker and the Grab
|
||||
if self.TheTicker != nil {
|
||||
self.TheTicker.Stop()
|
||||
}
|
||||
|
||||
|
||||
//Stop Ticker and the Grab
|
||||
if self.TheTicker != nil {
|
||||
self.TheTicker.Stop()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// should be in a gorotine
|
||||
func (self *DownloadProcessPage) UpdateProcessInterval() {
|
||||
|
||||
if self.Doing == true {
|
||||
return
|
||||
}
|
||||
self.Doing = true
|
||||
for {
|
||||
|
||||
gotime.Sleep(150 * gotime.Millisecond)
|
||||
|
||||
fmt.Printf(" transferred %v / %v bytes (%.2f%%)\n",
|
||||
func (self *DownloadProcessPage) UpdateProcessInterval() {
|
||||
|
||||
if self.Doing == true {
|
||||
return
|
||||
}
|
||||
self.Doing = true
|
||||
for {
|
||||
|
||||
gotime.Sleep(150 * gotime.Millisecond)
|
||||
|
||||
fmt.Printf(" transferred %v / %v bytes (%.2f%%)\n",
|
||||
self.resp.BytesComplete(),
|
||||
self.resp.Size,
|
||||
100*self.resp.Progress())
|
||||
|
||||
self.Value = int(100.0*self.resp.Progress())
|
||||
total := float64(self.resp.Size)/1000.0/1000.0
|
||||
downloaded := float64(self.resp.BytesComplete())/1000.0/1000.0
|
||||
|
||||
lb_str := fmt.Sprintf("%.2f/%.2fMb",downloaded,total)
|
||||
self.SizeLabel.SetText(lb_str)
|
||||
|
||||
self.FileNameLabel.SetText(filepath.Base(self.resp.Filename))
|
||||
|
||||
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
|
||||
if self.resp.Progress() >= 1.0 {
|
||||
// download is complete
|
||||
fmt.Println("download is complete ",self.Value)
|
||||
self.Value = 0
|
||||
self.Doing=false
|
||||
break
|
||||
}
|
||||
|
||||
if self.Doing == false {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
self.Doing=false
|
||||
|
||||
if err := self.resp.Err(); err != nil {
|
||||
self.DownloadErr()
|
||||
fmt.Fprintf(os.Stderr, "Download failed: %v\n", err)
|
||||
|
||||
cmd := exec.Command("rm","-rf",self.resp.Filename)
|
||||
cmd.Dir= self.DST_DIR
|
||||
cmd.Run()
|
||||
|
||||
self.Value = int(100.0 * self.resp.Progress())
|
||||
total := float64(self.resp.Size) / 1000.0 / 1000.0
|
||||
downloaded := float64(self.resp.BytesComplete()) / 1000.0 / 1000.0
|
||||
|
||||
lb_str := fmt.Sprintf("%.2f/%.2fMb", downloaded, total)
|
||||
self.SizeLabel.SetText(lb_str)
|
||||
|
||||
self.FileNameLabel.SetText(filepath.Base(self.resp.Filename))
|
||||
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
|
||||
if self.resp.Progress() >= 1.0 {
|
||||
// download is complete
|
||||
fmt.Println("download is complete ", self.Value)
|
||||
self.Value = 0
|
||||
self.Doing = false
|
||||
break
|
||||
}
|
||||
|
||||
if self.Doing == false {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Download saved to %s/%v \n",self.DST_DIR, self.resp.Filename)
|
||||
|
||||
filename := filepath.Base(self.resp.Filename)
|
||||
|
||||
if strings.HasSuffix(filename,".zip") {
|
||||
cmd := exec.Command("unzip",filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
}else if strings.HasSuffix(filename,".zsync") {
|
||||
cmd := exec.Command("rm","-rf",filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
}else if strings.HasSuffix(filename,".tar.gz") {
|
||||
cmd := exec.Command("tar", "xf", filename)
|
||||
cmd.Dir= self.DST_DIR
|
||||
cmd.Run()
|
||||
}
|
||||
|
||||
cmd := exec.Command("rm","-rf",filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
|
||||
self.DoneAndReturnUpLevel()
|
||||
|
||||
self.Doing = false
|
||||
|
||||
if err := self.resp.Err(); err != nil {
|
||||
self.DownloadErr()
|
||||
fmt.Fprintf(os.Stderr, "Download failed: %v\n", err)
|
||||
|
||||
cmd := exec.Command("rm", "-rf", self.resp.Filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
}
|
||||
|
||||
fmt.Printf("Download saved to %s/%v \n", self.DST_DIR, self.resp.Filename)
|
||||
|
||||
filename := filepath.Base(self.resp.Filename)
|
||||
|
||||
if strings.HasSuffix(filename, ".zip") {
|
||||
cmd := exec.Command("unzip", filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
} else if strings.HasSuffix(filename, ".zsync") {
|
||||
cmd := exec.Command("rm", "-rf", filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
} else if strings.HasSuffix(filename, ".tar.gz") {
|
||||
cmd := exec.Command("tar", "xf", filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
}
|
||||
|
||||
cmd := exec.Command("rm", "-rf", filename)
|
||||
cmd.Dir = self.DST_DIR
|
||||
cmd.Run()
|
||||
|
||||
self.DoneAndReturnUpLevel()
|
||||
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) DownloadErr() {
|
||||
self.Screen.MsgBox.SetText("Download Failed")
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
func (self *DownloadProcessPage) DownloadErr() {
|
||||
self.Screen.MsgBox.SetText("Download Failed")
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) DoneAndReturnUpLevel() {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) StartDownload(_url, dst_dir string) {
|
||||
|
||||
if self.Screen.IsWifiConnectedNow() == false {
|
||||
return
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) StartDownload(_url,dst_dir string) {
|
||||
|
||||
if self.Screen.IsWifiConnectedNow() == false {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := url.ParseRequestURI(_url)
|
||||
if err == nil && IsDirectory(dst_dir) {
|
||||
self.URL = _url
|
||||
self.DST_DIR = dst_dir
|
||||
}else{
|
||||
|
||||
self.Screen.MsgBox.SetText("Invaid")
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
fmt.Println("DownloadProcessPage StartDownload Invalid ",err)
|
||||
return
|
||||
}
|
||||
|
||||
if self.Doing == false {
|
||||
self.req, _ = grab.NewRequest(self.DST_DIR, _url)
|
||||
fmt.Printf("Downloading %v...\n", self.req.URL())
|
||||
self.resp = self.Downloader.Do(self.req)
|
||||
fmt.Printf(" %v\n", self.resp.HTTPResponse.Status)
|
||||
self.UpdateProcessInterval()
|
||||
}
|
||||
_, err := url.ParseRequestURI(_url)
|
||||
if err == nil && IsDirectory(dst_dir) {
|
||||
self.URL = _url
|
||||
self.DST_DIR = dst_dir
|
||||
} else {
|
||||
|
||||
self.Screen.MsgBox.SetText("Invaid")
|
||||
self.Screen.MsgBox.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
fmt.Println("DownloadProcessPage StartDownload Invalid ", err)
|
||||
return
|
||||
}
|
||||
|
||||
if self.Doing == false {
|
||||
self.req, _ = grab.NewRequest(self.DST_DIR, _url)
|
||||
fmt.Printf("Downloading %v...\n", self.req.URL())
|
||||
self.resp = self.Downloader.Do(self.req)
|
||||
fmt.Printf(" %v\n", self.resp.HTTPResponse.Status)
|
||||
self.UpdateProcessInterval()
|
||||
}
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) StopDownload() {
|
||||
|
||||
self.Doing=false
|
||||
self.Doing = false
|
||||
}
|
||||
func (self *DownloadProcessPage) KeyDown( ev *event.Event) {
|
||||
func (self *DownloadProcessPage) KeyDown(ev *event.Event) {
|
||||
|
||||
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
|
||||
self.StopDownload()
|
||||
|
||||
if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
|
||||
self.StopDownload()
|
||||
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *DownloadProcessPage) Draw() {
|
||||
|
||||
self.ClearCanvas()
|
||||
|
||||
if self.Screen.IsWifiConnectedNow() == false {
|
||||
self.Icons["needwifi_bg"].NewCoord(self.Width/2,self.Height/2)
|
||||
self.Icons["needwifi_bg"].Draw()
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
self.Icons["bg"].NewCoord(self.Width/2,self.Height/2-20)
|
||||
self.Icons["bg"].Draw()
|
||||
|
||||
percent := self.Value
|
||||
if percent < 10 {
|
||||
percent = 10
|
||||
}
|
||||
|
||||
rect_ := draw.MidRect(self.Width/2,self.Height/2+33,170,17, Width,Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND,rect_,
|
||||
&color.Color{228,228,228,255},5,0,&color.Color{228,228,228,255})
|
||||
|
||||
|
||||
rect2_ := draw.MidRect( self.Width/2,self.Height/2+33,int(170.0*(float64(percent)/100.0)),17, Width,Height )
|
||||
|
||||
rect2_.X = rect_.X
|
||||
rect2_.Y = rect_.Y
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND,rect2_,
|
||||
&color.Color{131, 199, 219,255},5,0,&color.Color{131, 199, 219,255})
|
||||
|
||||
w,h := self.FileNameLabel.Size()
|
||||
|
||||
rect3_ := draw.MidRect(self.Width/2,self.Height/2+53,w, h,Width,Height)
|
||||
self.ClearCanvas()
|
||||
|
||||
if self.Screen.IsWifiConnectedNow() == false {
|
||||
self.Icons["needwifi_bg"].NewCoord(self.Width/2, self.Height/2)
|
||||
self.Icons["needwifi_bg"].Draw()
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
self.Icons["bg"].NewCoord(self.Width/2, self.Height/2-20)
|
||||
self.Icons["bg"].Draw()
|
||||
|
||||
percent := self.Value
|
||||
if percent < 10 {
|
||||
percent = 10
|
||||
}
|
||||
|
||||
rect_ := draw.MidRect(self.Width/2, self.Height/2+33, 170, 17, Width, Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND, rect_,
|
||||
&color.Color{228, 228, 228, 255}, 5, 0, &color.Color{228, 228, 228, 255})
|
||||
|
||||
rect2_ := draw.MidRect(self.Width/2, self.Height/2+33, int(170.0*(float64(percent)/100.0)), 17, Width, Height)
|
||||
|
||||
rect2_.X = rect_.X
|
||||
rect2_.Y = rect_.Y
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND, rect2_,
|
||||
&color.Color{131, 199, 219, 255}, 5, 0, &color.Color{131, 199, 219, 255})
|
||||
|
||||
w, h := self.FileNameLabel.Size()
|
||||
|
||||
rect3_ := draw.MidRect(self.Width/2, self.Height/2+53, w, h, Width, Height)
|
||||
|
||||
w, h = self.SizeLabel.Size()
|
||||
|
||||
rect4_ := draw.MidRect(self.Width/2, self.Height/2+70, w, h, Width, Height)
|
||||
|
||||
self.FileNameLabel.NewCoord(int(rect3_.X), int(rect3_.Y))
|
||||
self.FileNameLabel.Draw()
|
||||
|
||||
self.SizeLabel.NewCoord(int(rect4_.X), int(rect4_.Y))
|
||||
self.SizeLabel.Draw()
|
||||
|
||||
w, h = self.SizeLabel.Size()
|
||||
|
||||
rect4_ := draw.MidRect(self.Width/2,self.Height/2+70,w, h,Width,Height)
|
||||
|
||||
self.FileNameLabel.NewCoord(int(rect3_.X),int(rect3_.Y))
|
||||
self.FileNameLabel.Draw()
|
||||
|
||||
self.SizeLabel.NewCoord(int(rect4_.X),int(rect4_.Y))
|
||||
self.SizeLabel.Draw()
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package UI
|
||||
|
||||
|
||||
const (
|
||||
RUNEVT=1
|
||||
RESTARTUI=2
|
||||
RUNSH=3
|
||||
RUNSYS=4
|
||||
POWEROPT=5
|
||||
RUNEVT = 1
|
||||
RESTARTUI = 2
|
||||
RUNSH = 3
|
||||
RUNSYS = 4
|
||||
POWEROPT = 5
|
||||
)
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"sync"
|
||||
)
|
||||
|
||||
type FolderStack struct {
|
||||
lock *sync.Mutex
|
||||
head *element
|
||||
Size int
|
||||
RootPath string
|
||||
lock *sync.Mutex
|
||||
head *element
|
||||
Size int
|
||||
RootPath string
|
||||
}
|
||||
|
||||
func (stk *FolderStack) Push(data interface{}) {
|
||||
stk.lock.Lock()
|
||||
stk.lock.Lock()
|
||||
|
||||
element := new(element)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
element := new(element)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
|
||||
stk.lock.Unlock()
|
||||
stk.lock.Unlock()
|
||||
}
|
||||
|
||||
func (stk *FolderStack) Pop() interface{} {
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
|
||||
stk.lock.Unlock()
|
||||
stk.lock.Unlock()
|
||||
|
||||
return r
|
||||
return r
|
||||
}
|
||||
|
||||
func (stk *FolderStack) SetRootPath(path string) {
|
||||
stk.RootPath = path
|
||||
stk.RootPath = path
|
||||
}
|
||||
|
||||
func (stk *FolderStack) Length() int {
|
||||
@@ -48,16 +47,16 @@ func (stk *FolderStack) Length() int {
|
||||
}
|
||||
|
||||
func (stk *FolderStack) Last() string {
|
||||
idx := stk.Length() -1
|
||||
if idx < 0 {
|
||||
return stk.RootPath
|
||||
}else {
|
||||
return stk.head.data.(string)
|
||||
}
|
||||
idx := stk.Length() - 1
|
||||
if idx < 0 {
|
||||
return stk.RootPath
|
||||
} else {
|
||||
return stk.head.data.(string)
|
||||
}
|
||||
}
|
||||
|
||||
func NewFolderStack() *FolderStack {
|
||||
stk := new(FolderStack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
stk := new(FolderStack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package UI
|
||||
import(
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
)
|
||||
|
||||
var Fonts map[string]*ttf.Font
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,24 +2,23 @@ package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// "io/ioutil"
|
||||
// "io/ioutil"
|
||||
"log"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/font"
|
||||
|
||||
)
|
||||
|
||||
var FootBar_BarHeight = 20
|
||||
|
||||
type FootBarIconItem struct {
|
||||
MultiIconItem
|
||||
MultiIconItem
|
||||
Parent *FootBar
|
||||
}
|
||||
|
||||
@@ -29,11 +28,11 @@ func NewFootBarIconItem() *FootBarIconItem {
|
||||
m.IconWidth = 18
|
||||
m.IconHeight = 18
|
||||
m.Align = ALIGN["VCenter"]
|
||||
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (self *FootBarIconItem) Adjust(x,y,w,h,at int) {
|
||||
func (self *FootBarIconItem) Adjust(x, y, w, h, at int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Width = w
|
||||
@@ -45,53 +44,51 @@ func (self *FootBarIconItem) Adjust(x,y,w,h,at int) {
|
||||
}
|
||||
|
||||
self.CreateImgSurf()
|
||||
// self.AdjustLinkPage()
|
||||
|
||||
// self.AdjustLinkPage()
|
||||
|
||||
}
|
||||
|
||||
func (self *FootBarIconItem) TotalWidth() int {
|
||||
lab_w,_ := self.Label.Size()
|
||||
lab_w, _ := self.Label.Size()
|
||||
return self.Width + lab_w
|
||||
}
|
||||
|
||||
func (self *FootBarIconItem) Draw() {
|
||||
|
||||
|
||||
if self.Label != nil {
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
self.Label.NewCoord( self.PosX - lab_w/2, self.PosY+ self.Height/2+12)
|
||||
self.Label.NewCoord(self.PosX-lab_w/2, self.PosY+self.Height/2+12)
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3, self.PosY - lab_h/2)
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3, self.PosY-lab_h/2)
|
||||
}
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
portion := rect.Rect(0, self.IconIndex*self.IconHeight, self.IconWidth, self.IconHeight)
|
||||
surface.Blit(self.Parent.CanvasHWND, self.ImgSurf, draw.MidRect(self.PosX,self.PosY, self.Width,self.Height, Width,Height),&portion)
|
||||
}else {
|
||||
surface.Blit(self.Parent.CanvasHWND, self.ImgSurf, draw.MidRect(self.PosX, self.PosY, self.Width, self.Height, Width, Height), &portion)
|
||||
} else {
|
||||
fmt.Println("self.ImgSurf is nil ")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
type FootBar struct {
|
||||
Widget
|
||||
BarHeight int
|
||||
Widget
|
||||
BarHeight int
|
||||
BorderWidth int
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
Icons map[string]IconItemInterface
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
LabelFont *ttf.Font
|
||||
State string
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
Icons map[string]IconItemInterface
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
LabelFont *ttf.Font
|
||||
State string
|
||||
SkinManager *SkinManager
|
||||
|
||||
icon_base_path string
|
||||
|
||||
}
|
||||
|
||||
icon_base_path string
|
||||
}
|
||||
|
||||
func NewFootBar() *FootBar {
|
||||
f := &FootBar{}
|
||||
@@ -103,63 +100,62 @@ func NewFootBar() *FootBar {
|
||||
|
||||
f.IconWidth = 18
|
||||
f.IconHeight = 18
|
||||
|
||||
|
||||
f.LabelFont = Fonts["veramono10"]
|
||||
f.State = "normal"
|
||||
f.icon_base_path = SkinMap("sysgo/gameshell/footbar_icons/")
|
||||
|
||||
f.Icons = make(map[string]IconItemInterface)
|
||||
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func (self *FootBar) ReadFootBarIcons( icondir string) {
|
||||
func (self *FootBar) ReadFootBarIcons(icondir string) {
|
||||
if FileExists(icondir) == false && IsDirectory(icondir) == false {
|
||||
return
|
||||
}
|
||||
keynames := [5]string{"nav","x","y","a","b"}
|
||||
keynames := [5]string{"nav", "x", "y", "a", "b"}
|
||||
|
||||
share_surf := image.Load(self.icon_base_path+"footbar.png")
|
||||
share_surf := image.Load(self.icon_base_path + "footbar.png")
|
||||
|
||||
for i,v := range keynames { // share_surf contains same number of image pieces of keynames
|
||||
for i, v := range keynames { // share_surf contains same number of image pieces of keynames
|
||||
it := NewFootBarIconItem()
|
||||
it.MyType = ICON_TYPES["NAV"]
|
||||
it.Parent = self
|
||||
it.ImgSurf = share_surf
|
||||
it.Align = ALIGN["HLeft"] // (X)Text
|
||||
it.IconWidth = self.IconWidth
|
||||
it.IconHeight =self.IconHeight
|
||||
it.IconHeight = self.IconHeight
|
||||
it.AddLabel("game", self.LabelFont)
|
||||
it.Adjust( self.IconWidth/2+i*self.IconWidth, self.IconHeight/2+2, self.IconWidth,self.IconHeight,0)
|
||||
it.Adjust(self.IconWidth/2+i*self.IconWidth, self.IconHeight/2+2, self.IconWidth, self.IconHeight, 0)
|
||||
it.IconIndex = i
|
||||
if val, ok := self.Icons[v]; ok {
|
||||
if val.(*FootBarIconItem).ImgSurf != nil {
|
||||
val.(*FootBarIconItem).ImgSurf.Free()
|
||||
}
|
||||
}
|
||||
if val, ok := self.Icons[v]; ok {
|
||||
if val.(*FootBarIconItem).ImgSurf != nil {
|
||||
val.(*FootBarIconItem).ImgSurf.Free()
|
||||
}
|
||||
}
|
||||
self.Icons[v] = it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (self *FootBar) Init(main_screen *MainScreen) {
|
||||
self.CanvasHWND = surface.Surface(self.Width,self.Height)
|
||||
self.CanvasHWND = surface.Surface(self.Width, self.Height)
|
||||
self.HWND = main_screen.HWND
|
||||
self.SkinManager = main_screen.SkinManager
|
||||
|
||||
self.ReadFootBarIcons(self.icon_base_path)
|
||||
|
||||
|
||||
round_corners := NewFootBarIconItem()
|
||||
round_corners.IconWidth = 10
|
||||
round_corners.IconHeight = 10
|
||||
|
||||
|
||||
round_corners.MyType = ICON_TYPES["STAT"]
|
||||
round_corners.Parent = self
|
||||
round_corners.ImgSurf = MyIconPool.GetImgSurf("roundcorners")
|
||||
round_corners.Adjust(0,0,10,10,0)
|
||||
|
||||
round_corners.Adjust(0, 0, 10, 10, 0)
|
||||
|
||||
self.Icons["round_corners"] = round_corners
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *FootBar) ResetNavText() {
|
||||
@@ -170,88 +166,87 @@ func (self *FootBar) ResetNavText() {
|
||||
|
||||
func (self *FootBar) UpdateNavText(texts string) {
|
||||
self.State = "tips"
|
||||
|
||||
// my_text := font.Render(self.LabelFont, texts, true,self.SkinManager.GiveColor("Text"),nil)
|
||||
|
||||
// my_text := font.Render(self.LabelFont, texts, true,self.SkinManager.GiveColor("Text"),nil)
|
||||
|
||||
left_width := self.Width - 18
|
||||
|
||||
final_piece := ""
|
||||
|
||||
for i,_ := range texts {
|
||||
for i, _ := range texts {
|
||||
text_ := texts[:i+1]
|
||||
my_text := font.Render(self.LabelFont, text_, true, self.SkinManager.GiveColor("Text"),nil)
|
||||
final_piece = text_
|
||||
my_text := font.Render(self.LabelFont, text_, true, self.SkinManager.GiveColor("Text"), nil)
|
||||
final_piece = text_
|
||||
if int(my_text.W) >= left_width {
|
||||
my_text.Free()
|
||||
my_text.Free()
|
||||
break
|
||||
}
|
||||
my_text.Free()
|
||||
my_text.Free()
|
||||
}
|
||||
|
||||
|
||||
fmt.Printf("finalpiece %s\n", final_piece)
|
||||
|
||||
self.Icons["nav"].SetLabelText(final_piece)
|
||||
self.Draw()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *FootBar) SetLabelTexts( texts [5]string) {
|
||||
keynames := [5]string{"nav","x","y","a","b"}
|
||||
func (self *FootBar) SetLabelTexts(texts [5]string) {
|
||||
keynames := [5]string{"nav", "x", "y", "a", "b"}
|
||||
if len(texts) < 5 {
|
||||
log.Fatal("SetLabelTexts texts length error")
|
||||
return
|
||||
}
|
||||
|
||||
for idx,x := range keynames {
|
||||
for idx, x := range keynames {
|
||||
self.Icons[x].SetLabelText(texts[idx])
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *FootBar) ClearCanvas() {
|
||||
surface.Fill( self.CanvasHWND, self.SkinManager.GiveColor("White"))
|
||||
surface.Fill(self.CanvasHWND, self.SkinManager.GiveColor("White"))
|
||||
|
||||
self.Icons["round_corners"].NewCoord(5,self.Height-5)
|
||||
self.Icons["round_corners"].NewCoord(5, self.Height-5)
|
||||
self.Icons["round_corners"].SetIconIndex(2)
|
||||
self.Icons["round_corners"].Draw()
|
||||
|
||||
|
||||
self.Icons["round_corners"].NewCoord(self.Width - 5,self.Height - 5)
|
||||
self.Icons["round_corners"].NewCoord(self.Width-5, self.Height-5)
|
||||
self.Icons["round_corners"].SetIconIndex(3)
|
||||
|
||||
self.Icons["round_corners"].Draw()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *FootBar) Draw() {
|
||||
self.ClearCanvas()
|
||||
|
||||
|
||||
self.Icons["nav"].NewCoord(self.IconWidth/2+3, self.IconHeight/2+2)
|
||||
self.Icons["nav"].Draw()
|
||||
|
||||
if self.State == "normal" {
|
||||
_w := 0
|
||||
|
||||
for i,x := range []string{"b","a","y","x"} {
|
||||
for i, x := range []string{"b", "a", "y", "x"} {
|
||||
if self.Icons[x].GetLabelText() != "" {
|
||||
if i== 0 {
|
||||
if i == 0 {
|
||||
_w += self.Icons[x].TotalWidth()
|
||||
}else {
|
||||
_w += self.Icons[x].TotalWidth()+5
|
||||
} else {
|
||||
_w += self.Icons[x].TotalWidth() + 5
|
||||
}
|
||||
|
||||
start_x := self.Width - _w
|
||||
start_y := self.IconHeight/2+2
|
||||
start_y := self.IconHeight/2 + 2
|
||||
self.Icons[x].NewCoord(start_x, start_y)
|
||||
self.Icons[x].Draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw.Line(self.CanvasHWND, self.SkinManager.GiveColor("Line"),0,0,Width,0,self.BorderWidth)
|
||||
|
||||
|
||||
draw.Line(self.CanvasHWND, self.SkinManager.GiveColor("Line"), 0, 0, Width, 0, self.BorderWidth)
|
||||
|
||||
if self.HWND != nil {
|
||||
rect_ := rect.Rect(self.PosX, Height - self.Height, Width, self.BarHeight)
|
||||
surface.Blit(self.HWND,self.CanvasHWND, &rect_,nil)
|
||||
rect_ := rect.Rect(self.PosX, Height-self.Height, Width, self.BarHeight)
|
||||
surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,36 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
)
|
||||
|
||||
type FullScreen struct {
|
||||
Widget
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
|
||||
Widget
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
}
|
||||
|
||||
func NewFullScreen() *FullScreen {
|
||||
p := &FullScreen{}
|
||||
p.Width = Width
|
||||
p.Height = Height
|
||||
|
||||
return p
|
||||
p := &FullScreen{}
|
||||
p.Width = Width
|
||||
p.Height = Height
|
||||
|
||||
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()
|
||||
}
|
||||
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() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,161 +1,156 @@
|
||||
package UI
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
type ListItemIcon struct {
|
||||
IconItem
|
||||
|
||||
IconItem
|
||||
}
|
||||
|
||||
func NewListItemIcon() *ListItemIcon {
|
||||
p := &ListItemIcon{}
|
||||
p.MyType = ICON_TYPES["EXE"]
|
||||
p := &ListItemIcon{}
|
||||
p.MyType = ICON_TYPES["EXE"]
|
||||
|
||||
p.Align = ALIGN["VCenter"]
|
||||
|
||||
p.Width = 18
|
||||
p.Height = 18
|
||||
|
||||
return p
|
||||
|
||||
p.Width = 18
|
||||
p.Height = 18
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *ListItemIcon) Draw() {
|
||||
_,h := self.Parent.Size()
|
||||
|
||||
rect_ := rect.Rect(self.PosX,self.PosY+(h-self.Height)/2,self.Width,self.Height)
|
||||
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf,&rect_,nil)
|
||||
_, h := self.Parent.Size()
|
||||
|
||||
rect_ := rect.Rect(self.PosX, self.PosY+(h-self.Height)/2, self.Width, self.Height)
|
||||
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf, &rect_, nil)
|
||||
}
|
||||
|
||||
/// [..] [.]
|
||||
/// [..] [.]
|
||||
type HierListItem struct {
|
||||
ListItem
|
||||
MyType int
|
||||
Path string
|
||||
Active bool
|
||||
Playing bool
|
||||
ListItem
|
||||
MyType int
|
||||
Path string
|
||||
Active bool
|
||||
Playing bool
|
||||
}
|
||||
|
||||
var HierListItemDefaultHeight = 32
|
||||
|
||||
func NewHierListItem() *HierListItem {
|
||||
p := &HierListItem{}
|
||||
p.Labels = make(map[string]LabelInterface)
|
||||
p.Icons = make( map[string]IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
p.MyType = ICON_TYPES["EXE"]
|
||||
p := &HierListItem{}
|
||||
p.Labels = make(map[string]LabelInterface)
|
||||
p.Icons = make(map[string]IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
p.MyType = ICON_TYPES["EXE"]
|
||||
p.Height = HierListItemDefaultHeight
|
||||
p.Width = 0
|
||||
|
||||
return p
|
||||
p.Width = 0
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *HierListItem) IsFile() bool {
|
||||
if self.MyType == ICON_TYPES["FILE"] {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
if self.MyType == ICON_TYPES["FILE"] {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *HierListItem) IsDir() bool {
|
||||
if self.MyType == ICON_TYPES["DIR"] {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
if self.MyType == ICON_TYPES["DIR"] {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func (self *HierListItem) Init(text string) {
|
||||
l := NewLabel()
|
||||
l.PosX = 20
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Parent nil")
|
||||
return
|
||||
}
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
|
||||
if self.IsDir() == true || self.IsFile() == true {
|
||||
self.Path = text
|
||||
}
|
||||
|
||||
label_text := filepath.Base(text)
|
||||
ext:= filepath.Ext(text)
|
||||
if ext != "" {
|
||||
alias_file := strings.Replace(text,ext,"",-1) + ".alias"
|
||||
|
||||
if FileExists(alias_file) == true {
|
||||
b, err := ioutil.ReadFile(alias_file)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}else {
|
||||
label_text = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if self.IsDir() == true {
|
||||
l.Init(label_text, self.Fonts["normal"],nil)
|
||||
}else {
|
||||
l.Init(label_text,self.Fonts["normal"],nil)
|
||||
}
|
||||
|
||||
self.Labels["Text"] = l
|
||||
l := NewLabel()
|
||||
l.PosX = 20
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Parent nil")
|
||||
return
|
||||
}
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
|
||||
if self.IsDir() == true || self.IsFile() == true {
|
||||
self.Path = text
|
||||
}
|
||||
|
||||
label_text := filepath.Base(text)
|
||||
ext := filepath.Ext(text)
|
||||
if ext != "" {
|
||||
alias_file := strings.Replace(text, ext, "", -1) + ".alias"
|
||||
|
||||
if FileExists(alias_file) == true {
|
||||
b, err := ioutil.ReadFile(alias_file)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
} else {
|
||||
label_text = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if self.IsDir() == true {
|
||||
l.Init(label_text, self.Fonts["normal"], nil)
|
||||
} else {
|
||||
l.Init(label_text, self.Fonts["normal"], nil)
|
||||
}
|
||||
|
||||
self.Labels["Text"] = l
|
||||
}
|
||||
|
||||
func (self *HierListItem) Draw() {
|
||||
|
||||
x,y := self.Labels["Text"].Coord()
|
||||
_,h := self.Labels["Text"].Size()
|
||||
|
||||
if self.Path != "[..]" {
|
||||
self.Labels["Text"].NewCoord(23,y)
|
||||
|
||||
}else {
|
||||
self.Labels["Text"].NewCoord(3,y)
|
||||
}
|
||||
|
||||
x,y = self.Labels["Text"].Coord()
|
||||
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height-h)/2)
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
|
||||
/*
|
||||
w,h := self.Parent.Icons["sys"].Size()
|
||||
|
||||
if self.IsDir() == true && self.Path != "[..]" {
|
||||
self.Parent.Icons["sys"].IconIndex = 0
|
||||
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
self.Parent.Icons["sys"].Draw()
|
||||
}
|
||||
|
||||
if self.IsFile() == true {
|
||||
self.Parent.Icons["sys"].IconIndex = 1
|
||||
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
self.Parent.Icons["sys"].Draw()
|
||||
}
|
||||
*/
|
||||
|
||||
draw.Line(self.Parent.GetCanvasHWND(),&color.Color{169,169,169,255},
|
||||
self.PosX,self.PosY+self.Height-1,self.PosX+self.Width,self.PosY+self.Height-1,1)
|
||||
|
||||
|
||||
x, y := self.Labels["Text"].Coord()
|
||||
_, h := self.Labels["Text"].Size()
|
||||
|
||||
if self.Path != "[..]" {
|
||||
self.Labels["Text"].NewCoord(23, y)
|
||||
|
||||
} else {
|
||||
self.Labels["Text"].NewCoord(3, y)
|
||||
}
|
||||
|
||||
x, y = self.Labels["Text"].Coord()
|
||||
self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
/*
|
||||
w,h := self.Parent.Icons["sys"].Size()
|
||||
|
||||
if self.IsDir() == true && self.Path != "[..]" {
|
||||
self.Parent.Icons["sys"].IconIndex = 0
|
||||
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
self.Parent.Icons["sys"].Draw()
|
||||
}
|
||||
|
||||
if self.IsFile() == true {
|
||||
self.Parent.Icons["sys"].IconIndex = 1
|
||||
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
|
||||
self.Parent.Icons["sys"].Draw()
|
||||
}
|
||||
*/
|
||||
|
||||
draw.Line(self.Parent.GetCanvasHWND(), &color.Color{169, 169, 169, 255},
|
||||
self.PosX, self.PosY+self.Height-1, self.PosX+self.Width, self.PosY+self.Height-1, 1)
|
||||
|
||||
}
|
||||
|
||||
@@ -2,48 +2,47 @@ package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/transform"
|
||||
"github.com/cuu/gogame/utils"
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
)
|
||||
|
||||
type IconItemInterface interface {
|
||||
Init(x,y,w,h,at int)
|
||||
Adjust(x,y,w,h,at int)
|
||||
Init(x, y, w, h, at int)
|
||||
Adjust(x, y, w, h, at int)
|
||||
GetCmdPath() string
|
||||
SetCmdPath( path string)
|
||||
|
||||
SetMyType( thetype int )
|
||||
SetCmdPath(path string)
|
||||
|
||||
SetMyType(thetype int)
|
||||
GetMyType() int
|
||||
|
||||
GetIconIndex() int
|
||||
SetIconIndex(idx int)
|
||||
|
||||
|
||||
GetIndex() int
|
||||
SetIndex(i int)
|
||||
|
||||
SetParent( p interface{} )
|
||||
|
||||
|
||||
SetParent(p interface{})
|
||||
|
||||
SetLabelColor(col *color.Color)
|
||||
SetLabelText(text string)
|
||||
GetLabelText() string
|
||||
|
||||
Coord() (int,int)
|
||||
NewCoord(x,y int)
|
||||
Size() (int,int)
|
||||
NewSize(w,h int)
|
||||
|
||||
Coord() (int, int)
|
||||
NewCoord(x, y int)
|
||||
Size() (int, int)
|
||||
NewSize(w, h int)
|
||||
|
||||
TotalWidth() int
|
||||
|
||||
|
||||
AddLabel(text string, fontobj *ttf.Font)
|
||||
GetLinkPage() PageInterface
|
||||
AdjustLinkPage()
|
||||
@@ -51,46 +50,43 @@ type IconItemInterface interface {
|
||||
SetImgSurf(newsurf *sdl.Surface)
|
||||
CreateImgSurf()
|
||||
ChangeImgSurfColor(col *color.Color)
|
||||
|
||||
|
||||
Clear()
|
||||
|
||||
GetCmdInvoke() PluginInterface
|
||||
|
||||
GetFileName() string
|
||||
Draw()
|
||||
DrawTopLeft()
|
||||
|
||||
DrawTopLeft()
|
||||
}
|
||||
|
||||
type IconItem struct {
|
||||
Widget
|
||||
ImageName string
|
||||
ImgSurf *sdl.Surface
|
||||
Parent PageInterface
|
||||
Index int
|
||||
IconIndex int
|
||||
MyType int
|
||||
CmdPath string
|
||||
CmdInvoke PluginInterface
|
||||
LinkPage PageInterface
|
||||
Label LabelInterface
|
||||
Align int
|
||||
ImageName string
|
||||
ImgSurf *sdl.Surface
|
||||
Parent PageInterface
|
||||
Index int
|
||||
IconIndex int
|
||||
MyType int
|
||||
CmdPath string
|
||||
CmdInvoke PluginInterface
|
||||
LinkPage PageInterface
|
||||
Label LabelInterface
|
||||
Align int
|
||||
AnimationTime int
|
||||
FileName string
|
||||
FileName string
|
||||
}
|
||||
|
||||
|
||||
func NewIconItem() *IconItem {
|
||||
i := &IconItem{}
|
||||
i.MyType = ICON_TYPES["EXE"]
|
||||
|
||||
i.Align = ALIGN["VCenter"]
|
||||
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
|
||||
func (self *IconItem) Init(x,y,w,h,at int) {
|
||||
func (self *IconItem) Init(x, y, w, h, at int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Width = w
|
||||
@@ -98,7 +94,7 @@ func (self *IconItem) Init(x,y,w,h,at int) {
|
||||
self.AnimationTime = at
|
||||
}
|
||||
|
||||
func (self *IconItem) Adjust(x,y,w,h,at int) {
|
||||
func (self *IconItem) Adjust(x, y, w, h, at int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Width = w
|
||||
@@ -111,19 +107,18 @@ func (self *IconItem) Adjust(x,y,w,h,at int) {
|
||||
|
||||
self.CreateImgSurf()
|
||||
self.AdjustLinkPage()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *IconItem) GetCmdPath() string {
|
||||
return self.CmdPath
|
||||
}
|
||||
|
||||
func (self *IconItem) SetCmdPath( path string) {
|
||||
func (self *IconItem) SetCmdPath(path string) {
|
||||
self.CmdPath = path
|
||||
}
|
||||
|
||||
func (self *IconItem) SetMyType( thetype int ) {
|
||||
func (self *IconItem) SetMyType(thetype int) {
|
||||
self.MyType = thetype
|
||||
}
|
||||
|
||||
@@ -135,7 +130,7 @@ func (self *IconItem) GetIconIndex() int {
|
||||
return self.IconIndex
|
||||
}
|
||||
|
||||
func (self *IconItem) SetIconIndex( idx int) {
|
||||
func (self *IconItem) SetIconIndex(idx int) {
|
||||
self.IconIndex = idx
|
||||
}
|
||||
|
||||
@@ -147,7 +142,7 @@ func (self *IconItem) SetIndex(i int) {
|
||||
self.Index = i
|
||||
}
|
||||
|
||||
func (self *IconItem) SetParent(p interface{} ) {
|
||||
func (self *IconItem) SetParent(p interface{}) {
|
||||
self.Parent = p.(PageInterface)
|
||||
}
|
||||
|
||||
@@ -163,11 +158,11 @@ func (self *IconItem) SetLabelText(text string) {
|
||||
self.Label.SetText(text)
|
||||
}
|
||||
|
||||
func (self *IconItem) Coord() (int,int) {
|
||||
return self.PosX,self.PosY
|
||||
func (self *IconItem) Coord() (int, int) {
|
||||
return self.PosX, self.PosY
|
||||
}
|
||||
|
||||
func (self *IconItem) NewCoord(x,y int) {
|
||||
func (self *IconItem) NewCoord(x, y int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
}
|
||||
@@ -176,18 +171,18 @@ func (self *IconItem) TotalWidth() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *IconItem) Size() (int,int) {
|
||||
return self.Width,self.Height
|
||||
func (self *IconItem) Size() (int, int) {
|
||||
return self.Width, self.Height
|
||||
}
|
||||
|
||||
func (self *IconItem) AddLabel(text string, fontobj *ttf.Font) {
|
||||
if self.Label == nil {
|
||||
l:= NewLabel()
|
||||
l := NewLabel()
|
||||
self.Label = l
|
||||
}
|
||||
|
||||
self.Label.Init(text,fontobj,nil)
|
||||
|
||||
|
||||
self.Label.Init(text, fontobj, nil)
|
||||
|
||||
}
|
||||
|
||||
func (self *IconItem) GetLinkPage() PageInterface {
|
||||
@@ -200,21 +195,20 @@ func (self *IconItem) AdjustLinkPage() {
|
||||
self.LinkPage.SetAlign(ALIGN["SLeft"])
|
||||
self.LinkPage.UpdateIconNumbers()
|
||||
self.LinkPage.SetScreen(self.Parent.GetScreen())
|
||||
self.LinkPage.SetCanvasHWND( (self.Parent.GetScreen()).CanvasHWND )
|
||||
self.LinkPage.SetFootMsg([5]string{ "Nav.","","","Back","Enter" } )
|
||||
self.LinkPage.SetCanvasHWND((self.Parent.GetScreen()).CanvasHWND)
|
||||
self.LinkPage.SetFootMsg([5]string{"Nav.", "", "", "Back", "Enter"})
|
||||
if self.LinkPage.GetAlign() == ALIGN["HLeft"] {
|
||||
self.LinkPage.AdjustHLeftAlign()
|
||||
}else if self.LinkPage.GetAlign() == ALIGN["SLeft"] {
|
||||
} else if self.LinkPage.GetAlign() == ALIGN["SLeft"] {
|
||||
self.LinkPage.AdjustSAutoLeftAlign()
|
||||
if self.LinkPage.GetIconNumbers() > 1 {
|
||||
self.LinkPage.SetPsIndex(1)
|
||||
self.LinkPage.SetIconIndex ( 1 )
|
||||
self.LinkPage.SetIconIndex(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (self *IconItem) GetImgSurf() *sdl.Surface {
|
||||
return self.ImgSurf
|
||||
}
|
||||
@@ -223,22 +217,21 @@ func (self *IconItem) SetImgSurf(newsurf *sdl.Surface) {
|
||||
self.ImgSurf = newsurf
|
||||
}
|
||||
|
||||
|
||||
func (self *IconItem) CreateImgSurf() {
|
||||
if self.ImgSurf == nil && self.ImageName != "" {
|
||||
self.ImgSurf = image.Load(self.ImageName)
|
||||
if int(self.ImgSurf.W) > IconWidth || int(self.ImgSurf.H) > IconHeight {
|
||||
self.ImgSurf = transform.Scale(self.ImgSurf,IconWidth,IconHeight)
|
||||
if int(self.ImgSurf.W) > IconWidth || int(self.ImgSurf.H) > IconHeight {
|
||||
self.ImgSurf = transform.Scale(self.ImgSurf, IconWidth, IconHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *IconItem) ChangeImgSurfColor(col *color.Color) {
|
||||
utils.ColorSurface(self.ImgSurf,col)
|
||||
utils.ColorSurface(self.ImgSurf, col)
|
||||
}
|
||||
|
||||
func (self *IconItem) Clear() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *IconItem) GetCmdInvoke() PluginInterface {
|
||||
@@ -246,65 +239,64 @@ func (self *IconItem) GetCmdInvoke() PluginInterface {
|
||||
}
|
||||
|
||||
func (self *IconItem) GetFileName() string {
|
||||
return self.FileName
|
||||
return self.FileName
|
||||
}
|
||||
|
||||
func (self *IconItem) DrawTopLeft() {
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: IconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x,parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: IconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x, parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Label != nil {
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
// fmt.Println("IconItem Draw VCenter:",lab_w,lab_h,self.Label.GetText())
|
||||
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6+parent_y)
|
||||
|
||||
}else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3+parent_x, self.PosY - lab_h/2 + parent_y)
|
||||
// fmt.Println("IconItem Draw VCenter:",lab_w,lab_h,self.Label.GetText())
|
||||
|
||||
self.Label.NewCoord(self.PosX-lab_w/2+parent_x, self.PosY+self.Height/2+6+parent_y)
|
||||
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3+parent_x, self.PosY-lab_h/2+parent_y)
|
||||
}
|
||||
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
rect_ := rect.Rect( self.PosX+parent_x,self.PosY+parent_y, self.Width,self.Height ) // DIFF
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf,&rect_,nil)
|
||||
rect_ := rect.Rect(self.PosX+parent_x, self.PosY+parent_y, self.Width, self.Height) // DIFF
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf, &rect_, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *IconItem) Draw() {
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: IconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x,parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: IconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x, parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Label != nil {
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
// fmt.Println("IconItem Draw VCenter:",lab_w,lab_h,self.Label.GetText())
|
||||
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6+parent_y)
|
||||
|
||||
}else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3+parent_x, self.PosY - lab_h/2 + parent_y)
|
||||
// fmt.Println("IconItem Draw VCenter:",lab_w,lab_h,self.Label.GetText())
|
||||
|
||||
self.Label.NewCoord(self.PosX-lab_w/2+parent_x, self.PosY+self.Height/2+6+parent_y)
|
||||
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3+parent_x, self.PosY-lab_h/2+parent_y)
|
||||
}
|
||||
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf,draw.MidRect(self.PosX + parent_x, self.PosY + parent_y,
|
||||
self.Width,self.Height, Width, Height),nil)
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf, draw.MidRect(self.PosX+parent_x, self.PosY+parent_y,
|
||||
self.Width, self.Height, Width, Height), nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,41 +5,39 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/image"
|
||||
|
||||
)
|
||||
|
||||
type IconPool struct {
|
||||
GameShellIconPath string
|
||||
Icons map[string]*sdl.Surface
|
||||
GameShellIconPath string
|
||||
Icons map[string]*sdl.Surface
|
||||
}
|
||||
|
||||
func NewIconPool() *IconPool {
|
||||
i := &IconPool{}
|
||||
i.GameShellIconPath = SkinMap("sysgo/gameshell/icons/")
|
||||
i.Icons = make( map[string]*sdl.Surface )
|
||||
i.Icons = make(map[string]*sdl.Surface)
|
||||
return i
|
||||
}
|
||||
|
||||
|
||||
func (self *IconPool) Init() {
|
||||
files,err := ioutil.ReadDir(self.GameShellIconPath)
|
||||
files, err := ioutil.ReadDir(self.GameShellIconPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _,f := range files {
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
//pass
|
||||
}else {
|
||||
if strings.HasSuffix(f.Name(),".png") == true {
|
||||
keyname := strings.Split(f.Name(),".")
|
||||
} else {
|
||||
if strings.HasSuffix(f.Name(), ".png") == true {
|
||||
keyname := strings.Split(f.Name(), ".")
|
||||
if len(keyname) > 1 {
|
||||
self.Icons[ keyname[0] ] = image.Load( self.GameShellIconPath+ "/"+f.Name() )
|
||||
self.Icons[keyname[0]] = image.Load(self.GameShellIconPath + "/" + f.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +45,7 @@ func (self *IconPool) Init() {
|
||||
}
|
||||
|
||||
func (self *IconPool) GetImgSurf(keyname string) *sdl.Surface {
|
||||
if _,ok := self.Icons[keyname]; ok {
|
||||
if _, ok := self.Icons[keyname]; ok {
|
||||
return self.Icons[keyname]
|
||||
} else {
|
||||
fmt.Println("IconPool GetImgSurf ", keyname, " failed")
|
||||
@@ -56,5 +54,5 @@ func (self *IconPool) GetImgSurf(keyname string) *sdl.Surface {
|
||||
}
|
||||
|
||||
var MyIconPool *IconPool
|
||||
// = NewIconPool()
|
||||
|
||||
// = NewIconPool()
|
||||
|
||||
@@ -2,73 +2,72 @@ package UI
|
||||
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
)
|
||||
|
||||
var DefaultInfoPageListItemHeight = 30
|
||||
|
||||
type InfoPageListItem struct {
|
||||
ListItem
|
||||
Flag string
|
||||
ReadOnly bool
|
||||
ListItem
|
||||
Flag string
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
func NewInfoPageListItem() *InfoPageListItem {
|
||||
p := &InfoPageListItem{}
|
||||
p.Height = DefaultInfoPageListItemHeight
|
||||
p.ReadOnly = false
|
||||
p := &InfoPageListItem{}
|
||||
p.Height = DefaultInfoPageListItemHeight
|
||||
p.ReadOnly = false
|
||||
p.Labels = make(map[string]LabelInterface)
|
||||
p.Icons = make( map[string]IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
return p
|
||||
p.Icons = make(map[string]IconItemInterface)
|
||||
p.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *InfoPageListItem) SetSmallText(text string) {
|
||||
l := NewLabel()
|
||||
l.PosX = 40
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
l.Init(text,self.Fonts["small"],nil)
|
||||
l.Init(text, self.Fonts["small"], nil)
|
||||
self.Labels["Small"] = l
|
||||
}
|
||||
|
||||
func (self *InfoPageListItem) Init(text string ) {
|
||||
func (self *InfoPageListItem) Init(text string) {
|
||||
l := NewLabel()
|
||||
l.PosX = 10
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
l.Init(text,self.Fonts["normal"],nil)
|
||||
l.Init(text, self.Fonts["normal"], nil)
|
||||
self.Labels["Text"] = l
|
||||
}
|
||||
|
||||
func (self *InfoPageListItem) Draw() {
|
||||
if self.ReadOnly == true {
|
||||
self.Labels["Text"].SetColor(&color.Color{130,130,130,255} ) //SkinManager().GiveColor("ReadOnlyText")
|
||||
}else {
|
||||
self.Labels["Text"].SetColor(&color.Color{83,83,83,255} ) // SkinManager().GiveColor("Text")
|
||||
}
|
||||
|
||||
x,_ := self.Labels["Text"].Coord()
|
||||
w,h := self.Labels["Text"].Size()
|
||||
|
||||
self.Labels["Text"].NewCoord( x + self.PosX, self.PosY + (self.Height - h)/2 )
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height - h)/2 )
|
||||
|
||||
if _, ok := self.Labels["Small"]; ok {
|
||||
x,_ = self.Labels["Small"].Coord()
|
||||
w,h = self.Labels["Small"].Size()
|
||||
|
||||
self.Labels["Small"].NewCoord( self.Width - w - 5 , self.PosY + (self.Height - h)/2 )
|
||||
self.Labels["Small"].Draw()
|
||||
|
||||
}
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
draw.Line(canvas_, &color.Color{169,169,169,255}, self.PosX, self.PosY+self.Height -1,self.PosX + self.Width, self.PosY+self.Height -1 ,1)
|
||||
if self.ReadOnly == true {
|
||||
self.Labels["Text"].SetColor(&color.Color{130, 130, 130, 255}) //SkinManager().GiveColor("ReadOnlyText")
|
||||
} else {
|
||||
self.Labels["Text"].SetColor(&color.Color{83, 83, 83, 255}) // SkinManager().GiveColor("Text")
|
||||
}
|
||||
|
||||
x, _ := self.Labels["Text"].Coord()
|
||||
w, h := self.Labels["Text"].Size()
|
||||
|
||||
self.Labels["Text"].NewCoord(x+self.PosX, self.PosY+(self.Height-h)/2)
|
||||
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
|
||||
|
||||
if _, ok := self.Labels["Small"]; ok {
|
||||
x, _ = self.Labels["Small"].Coord()
|
||||
w, h = self.Labels["Small"].Size()
|
||||
|
||||
self.Labels["Small"].NewCoord(self.Width-w-5, self.PosY+(self.Height-h)/2)
|
||||
self.Labels["Small"].Draw()
|
||||
|
||||
}
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
draw.Line(canvas_, &color.Color{169, 169, 169, 255}, self.PosX, self.PosY+self.Height-1, self.PosX+self.Width, self.PosY+self.Height-1, 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +1,49 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
// "github.com/veandco/go-sdl2/ttf"
|
||||
//"fmt"
|
||||
// "github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
// "github.com/cuu/gogame/surface"
|
||||
// "github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/rect"
|
||||
// "github.com/cuu/gogame/surface"
|
||||
// "github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
)
|
||||
|
||||
type InfoPageSelector struct {
|
||||
PageSelector
|
||||
BackgroundColor *color.Color
|
||||
PageSelector
|
||||
BackgroundColor *color.Color
|
||||
}
|
||||
|
||||
func NewInfoPageSelector() *InfoPageSelector {
|
||||
p := &InfoPageSelector{}
|
||||
|
||||
p.Width = Width
|
||||
p.BackgroundColor = &color.Color{131,199,219,255} //SkinManager().GiveColor('Front')
|
||||
|
||||
return p
|
||||
|
||||
p := &InfoPageSelector{}
|
||||
|
||||
p.Width = Width
|
||||
p.BackgroundColor = &color.Color{131, 199, 219, 255} //SkinManager().GiveColor('Front')
|
||||
|
||||
return p
|
||||
|
||||
}
|
||||
|
||||
func (self *InfoPageSelector) AnimateDraw(x2, y2 int) {
|
||||
//pass
|
||||
//pass
|
||||
}
|
||||
|
||||
func (self *InfoPageSelector) Draw() {
|
||||
idx := self.Parent.GetPsIndex()
|
||||
mylist := self.Parent.GetMyList()
|
||||
|
||||
if idx < len(mylist) {
|
||||
_,y := mylist[idx].Coord()
|
||||
_,h := mylist[idx].Size()
|
||||
|
||||
|
||||
self.PosY = y+1
|
||||
self.Height = h-3
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
rect_ := rect.Rect(self.PosX,self.PosY,self.Width-4, self.Height)
|
||||
|
||||
draw.AARoundRect(canvas_,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||
}
|
||||
}
|
||||
idx := self.Parent.GetPsIndex()
|
||||
mylist := self.Parent.GetMyList()
|
||||
|
||||
|
||||
if idx < len(mylist) {
|
||||
_, y := mylist[idx].Coord()
|
||||
_, h := mylist[idx].Size()
|
||||
|
||||
self.PosY = y + 1
|
||||
self.Height = h - 3
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
|
||||
|
||||
draw.AARoundRect(canvas_, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/event"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/event"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo/easings"
|
||||
|
||||
)
|
||||
|
||||
//sysgo/UI/keyboard_keys.layout
|
||||
type KeyboardIcon struct {
|
||||
TextItem // IconItem->TextItem->KeyboardIcon
|
||||
@@ -22,8 +21,8 @@ type KeyboardIcon struct {
|
||||
func NewKeyboardIcon() *KeyboardIcon {
|
||||
p := &KeyboardIcon{}
|
||||
|
||||
p.Color = &color.Color{83,83,83,255}//SkinManager().GiveColor('Text')
|
||||
|
||||
p.Color = &color.Color{83, 83, 83, 255} //SkinManager().GiveColor('Text')
|
||||
|
||||
p.MyType = ICON_TYPES["NAV"]
|
||||
|
||||
return p
|
||||
@@ -31,20 +30,18 @@ func NewKeyboardIcon() *KeyboardIcon {
|
||||
|
||||
func (self *KeyboardIcon) Draw() {
|
||||
|
||||
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||
|
||||
surface.Blit(self.Parent.GetCanvasHWND(),self.ImgSurf,rect_,nil)
|
||||
|
||||
}
|
||||
rect_ := draw.MidRect(self.PosX, self.PosY, self.Width, self.Height, Width, Height)
|
||||
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf, rect_, nil)
|
||||
|
||||
}
|
||||
|
||||
type KeyboardSelector struct {
|
||||
PageSelector
|
||||
Parent *Keyboard
|
||||
}
|
||||
|
||||
|
||||
func NewKeyboardSelector() * KeyboardSelector {
|
||||
func NewKeyboardSelector() *KeyboardSelector {
|
||||
p := &KeyboardSelector{}
|
||||
|
||||
return p
|
||||
@@ -53,19 +50,19 @@ func NewKeyboardSelector() * KeyboardSelector {
|
||||
func (self *KeyboardSelector) Draw() {
|
||||
sec_idx := self.Parent.SectionIndex
|
||||
row_idx := self.Parent.RowIndex
|
||||
idx := self.Parent.PsIndex
|
||||
idx := self.Parent.PsIndex
|
||||
|
||||
x, y := self.Parent.SecsKeys[sec_idx][row_idx][idx].Coord()
|
||||
w, h := self.Parent.SecsKeys[sec_idx][row_idx][idx].Size()
|
||||
x, y := self.Parent.SecsKeys[sec_idx][row_idx][idx].Coord()
|
||||
w, h := self.Parent.SecsKeys[sec_idx][row_idx][idx].Size()
|
||||
|
||||
rect_ := draw.MidRect(x,y,w+6,h+1,self.Parent.Width,self.Parent.Height)
|
||||
rect_ := draw.MidRect(x, y, w+6, h+1, self.Parent.Width, self.Parent.Height)
|
||||
|
||||
if rect_.W <= 0 || rect_.H <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
color_ := &color.Color{126,206,244,255}
|
||||
draw.AARoundRect(self.Parent.CanvasHWND,rect_,color_,3,0,color_)
|
||||
|
||||
color_ := &color.Color{126, 206, 244, 255}
|
||||
draw.AARoundRect(self.Parent.CanvasHWND, rect_, color_, 3, 0, color_)
|
||||
|
||||
}
|
||||
|
||||
@@ -73,12 +70,12 @@ type Keyboard struct {
|
||||
Page
|
||||
|
||||
Secs map[int][][]string
|
||||
|
||||
|
||||
SecsKeys map[int][][]TextItemInterface
|
||||
|
||||
|
||||
SectionNumbers int
|
||||
SectionIndex int
|
||||
Icons map[string]IconItemInterface
|
||||
SectionIndex int
|
||||
Icons map[string]IconItemInterface
|
||||
|
||||
KeyboardLayoutFile string ///sysgo/UI/keyboard_keys.layout
|
||||
|
||||
@@ -99,36 +96,34 @@ func NewKeyboard() *Keyboard {
|
||||
p.SelectedIconTopOffset = 20
|
||||
|
||||
p.Align = ALIGN["SLeft"]
|
||||
|
||||
|
||||
p.EasingDur = 10
|
||||
|
||||
|
||||
p.SectionNumbers = 3
|
||||
p.SectionIndex = 1
|
||||
|
||||
p.Icons = make( map[string]IconItemInterface )
|
||||
p.Icons = make(map[string]IconItemInterface)
|
||||
|
||||
p.LeftOrRight = 1
|
||||
|
||||
p.RowIndex = 0
|
||||
|
||||
p.FootMsg = [5]string{"Nav.","ABC","Done","Backspace","Enter"}
|
||||
|
||||
p.FootMsg = [5]string{"Nav.", "ABC", "Done", "Backspace", "Enter"}
|
||||
|
||||
p.Secs = make(map[int][][]string)
|
||||
p.SecsKeys = make(map[int][][]TextItemInterface)
|
||||
|
||||
|
||||
p.KeyboardLayoutFile = "sysgo/UI/keyboard_keys.layout"
|
||||
|
||||
|
||||
return p
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Keyboard) ReadLayoutFile( fname string) {
|
||||
func (self *Keyboard) ReadLayoutFile(fname string) {
|
||||
|
||||
|
||||
LayoutIndex := 0
|
||||
|
||||
content ,err := ReadLines(fname)
|
||||
content, err := ReadLines(fname)
|
||||
|
||||
Assert(err)
|
||||
|
||||
@@ -159,19 +154,17 @@ func (self *Keyboard) ReadLayoutFile( fname string) {
|
||||
} else { //empty []
|
||||
LayoutIndex += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (self *Keyboard) SetPassword(pwd string) {
|
||||
pwd_seq_list := strings.SplitAfter(pwd,"")
|
||||
|
||||
self.Textarea.ResetMyWords()
|
||||
for _,v := range pwd_seq_list {
|
||||
self.Textarea.AppendText(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Keyboard) SetPassword(pwd string) {
|
||||
pwd_seq_list := strings.SplitAfter(pwd, "")
|
||||
|
||||
self.Textarea.ResetMyWords()
|
||||
for _, v := range pwd_seq_list {
|
||||
self.Textarea.AppendText(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Keyboard) Init() {
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
@@ -187,26 +180,26 @@ func (self *Keyboard) Init() {
|
||||
|
||||
word_margin := 15
|
||||
|
||||
secs_zero := strings.Join(self.Secs[0][0],"")
|
||||
fw,_:= font.Size(fontobj,secs_zero)
|
||||
secs_zero := strings.Join(self.Secs[0][0], "")
|
||||
fw, _ := font.Size(fontobj, secs_zero)
|
||||
|
||||
start_x := (self.Width - fw - len(self.Secs[0][0])*word_margin)/2+word_margin/2
|
||||
start_x := (self.Width-fw-len(self.Secs[0][0])*word_margin)/2 + word_margin/2
|
||||
start_y := 0
|
||||
|
||||
// cnt := 0
|
||||
// cnt := 0
|
||||
|
||||
for i:=0; i < self.SectionNumbers; i++ {
|
||||
for i := 0; i < self.SectionNumbers; i++ {
|
||||
self.SecsKeys[i] = [][]TextItemInterface{}
|
||||
for j:=0; j < len(self.Secs[i]); j++ {
|
||||
self.SecsKeys[i] = append(self.SecsKeys[i],[]TextItemInterface{})
|
||||
secs_ij := strings.Join(self.Secs[i][j],"")
|
||||
fw,_ := font.Size(fontobj,secs_ij)
|
||||
start_x = (self.Width-fw- len(self.Secs[i][j])*word_margin)/2+word_margin/2
|
||||
for j := 0; j < len(self.Secs[i]); j++ {
|
||||
self.SecsKeys[i] = append(self.SecsKeys[i], []TextItemInterface{})
|
||||
secs_ij := strings.Join(self.Secs[i][j], "")
|
||||
fw, _ := font.Size(fontobj, secs_ij)
|
||||
start_x = (self.Width-fw-len(self.Secs[i][j])*word_margin)/2 + word_margin/2
|
||||
start_x = start_x + i*self.Width
|
||||
|
||||
start_y = 84 + j * (word_margin+14)
|
||||
start_y = 84 + j*(word_margin+14)
|
||||
|
||||
for _,val := range self.Secs[i][j] {
|
||||
for _, val := range self.Secs[i][j] {
|
||||
ti := NewTextItem()
|
||||
ti.FontObj = fontobj
|
||||
ti.Parent = self
|
||||
@@ -216,23 +209,23 @@ func (self *Keyboard) Init() {
|
||||
it.ImgSurf = MyIconPool.GetImgSurf(val)
|
||||
it.Parent = self
|
||||
it.Str = val
|
||||
it.Init(start_x+surface.GetWidth(it.ImgSurf)/2,start_y,surface.GetWidth(it.ImgSurf),surface.GetHeight(it.ImgSurf),0)
|
||||
self.SecsKeys[i][j] = append(self.SecsKeys[i][j],it)
|
||||
it.Init(start_x+surface.GetWidth(it.ImgSurf)/2, start_y, surface.GetWidth(it.ImgSurf), surface.GetHeight(it.ImgSurf), 0)
|
||||
self.SecsKeys[i][j] = append(self.SecsKeys[i][j], it)
|
||||
self.IconNumbers += 1
|
||||
start_x = start_x + surface.GetWidth(it.ImgSurf)+word_margin
|
||||
}else {
|
||||
start_x = start_x + surface.GetWidth(it.ImgSurf) + word_margin
|
||||
} else {
|
||||
|
||||
if val == "_S" {
|
||||
if val == "_S" {
|
||||
val = "Space"
|
||||
ti.FontObj = Fonts["veramono15"]
|
||||
ti.Bold = true
|
||||
}
|
||||
|
||||
cur_alpha_w,cur_alpha_h := font.Size(ti.FontObj,val)
|
||||
ti.Init(start_x + cur_alpha_w/2,start_y,cur_alpha_w,cur_alpha_h,0)
|
||||
cur_alpha_w, cur_alpha_h := font.Size(ti.FontObj, val)
|
||||
ti.Init(start_x+cur_alpha_w/2, start_y, cur_alpha_w, cur_alpha_h, 0)
|
||||
ti.Str = val
|
||||
start_x = start_x + cur_alpha_w+word_margin // prepare for next alphabet
|
||||
self.SecsKeys[i][j] = append(self.SecsKeys[i][j],ti)
|
||||
start_x = start_x + cur_alpha_w + word_margin // prepare for next alphabet
|
||||
self.SecsKeys[i][j] = append(self.SecsKeys[i][j], ti)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,9 +246,9 @@ func (self *Keyboard) Init() {
|
||||
ps := NewKeyboardSelector()
|
||||
|
||||
ps.Parent = self
|
||||
ps.Init(start_x,start_y,25,25,128)
|
||||
ps.OnShow = true
|
||||
|
||||
ps.Init(start_x, start_y, 25, 25, 128)
|
||||
ps.OnShow = true
|
||||
|
||||
self.Ps = ps
|
||||
self.PsIndex = 0
|
||||
|
||||
@@ -264,13 +257,13 @@ func (self *Keyboard) Init() {
|
||||
func (self *Keyboard) SelectUpChar() {
|
||||
sec_idx := self.SectionIndex
|
||||
|
||||
self.RowIndex -=1
|
||||
self.RowIndex -= 1
|
||||
if self.RowIndex < 0 {
|
||||
self.RowIndex = len(self.SecsKeys[sec_idx])-1
|
||||
self.RowIndex = len(self.SecsKeys[sec_idx]) - 1
|
||||
}
|
||||
|
||||
if self.PsIndex >= len(self.SecsKeys[sec_idx][self.RowIndex]) {
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex])-1
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex]) - 1
|
||||
}
|
||||
|
||||
self.ClearCanvas()
|
||||
@@ -287,8 +280,8 @@ func (self *Keyboard) SelectDownChar() {
|
||||
self.RowIndex = 0
|
||||
}
|
||||
|
||||
if self.PsIndex >=len(self.SecsKeys[sec_idx][self.RowIndex]) {
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex])-1
|
||||
if self.PsIndex >= len(self.SecsKeys[sec_idx][self.RowIndex]) {
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex]) - 1
|
||||
}
|
||||
|
||||
self.ClearCanvas()
|
||||
@@ -300,34 +293,34 @@ func (self *Keyboard) SelectNextChar() {
|
||||
|
||||
sec_idx := self.SectionIndex
|
||||
row_idx := self.RowIndex
|
||||
self.PsIndex+=1
|
||||
|
||||
self.PsIndex += 1
|
||||
|
||||
if self.PsIndex >= len(self.SecsKeys[sec_idx][row_idx]) {
|
||||
self.PsIndex = 0
|
||||
self.RowIndex+=1
|
||||
|
||||
self.RowIndex += 1
|
||||
|
||||
if self.RowIndex >= len(self.SecsKeys[sec_idx]) {
|
||||
self.RowIndex = 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.ClearCanvas()
|
||||
self.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Keyboard) SelectPrevChar() {
|
||||
|
||||
sec_idx := self.SectionIndex
|
||||
self.PsIndex-=1
|
||||
sec_idx := self.SectionIndex
|
||||
self.PsIndex -= 1
|
||||
if self.PsIndex < 0 {
|
||||
self.RowIndex-=1
|
||||
if self.RowIndex <=0 {
|
||||
self.RowIndex = len(self.SecsKeys[sec_idx])-1
|
||||
self.RowIndex -= 1
|
||||
if self.RowIndex <= 0 {
|
||||
self.RowIndex = len(self.SecsKeys[sec_idx]) - 1
|
||||
}
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex]) -1
|
||||
self.PsIndex = len(self.SecsKeys[sec_idx][self.RowIndex]) - 1
|
||||
}
|
||||
|
||||
self.ClearCanvas()
|
||||
@@ -336,20 +329,20 @@ func (self *Keyboard) SelectPrevChar() {
|
||||
}
|
||||
|
||||
func (self *Keyboard) ClickOnChar() {
|
||||
sec_idx := self.SectionIndex
|
||||
sec_idx := self.SectionIndex
|
||||
alphabet := self.SecsKeys[sec_idx][self.RowIndex][self.PsIndex].GetStr()
|
||||
|
||||
if alphabet == "Space"{
|
||||
|
||||
if alphabet == "Space" {
|
||||
alphabet = " "
|
||||
}
|
||||
|
||||
if alphabet == "_L" || alphabet == "_R" {
|
||||
if alphabet == "_L" {
|
||||
self.Textarea.SubTextIndex()
|
||||
}else if alphabet == "_R"{
|
||||
} else if alphabet == "_R" {
|
||||
self.Textarea.AddTextIndex()
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
self.Textarea.AppendText(alphabet)
|
||||
}
|
||||
|
||||
@@ -360,23 +353,23 @@ func (self *Keyboard) ClickOnChar() {
|
||||
func (self *Keyboard) KeyboardShift() {
|
||||
distance := self.Width //320
|
||||
current_time := float32(0.0)
|
||||
start_posx := float32(0.0)
|
||||
start_posx := float32(0.0)
|
||||
current_posx := start_posx
|
||||
final_posx := float32(distance)
|
||||
// posx_init := start
|
||||
dur := self.EasingDur
|
||||
last_posx := float32(0.0)
|
||||
final_posx := float32(distance)
|
||||
// posx_init := start
|
||||
dur := self.EasingDur
|
||||
last_posx := float32(0.0)
|
||||
|
||||
var all_last_posx []int
|
||||
|
||||
for i:=0;i<distance*dur;i++ {
|
||||
current_posx = float32(easings.SineIn(float32(current_time), float32(start_posx), float32(final_posx-start_posx),float32(dur)))
|
||||
for i := 0; i < distance*dur; i++ {
|
||||
current_posx = float32(easings.SineIn(float32(current_time), float32(start_posx), float32(final_posx-start_posx), float32(dur)))
|
||||
if current_posx >= final_posx {
|
||||
current_posx = final_posx
|
||||
}
|
||||
dx := current_posx - last_posx
|
||||
all_last_posx = append(all_last_posx,int(dx))
|
||||
current_time+=1.0
|
||||
all_last_posx = append(all_last_posx, int(dx))
|
||||
current_time += 1.0
|
||||
last_posx = current_posx
|
||||
if current_posx >= final_posx {
|
||||
break
|
||||
@@ -384,19 +377,19 @@ func (self *Keyboard) KeyboardShift() {
|
||||
}
|
||||
|
||||
c := 0
|
||||
for _,v := range all_last_posx {
|
||||
c+=v
|
||||
for _, v := range all_last_posx {
|
||||
c += v
|
||||
}
|
||||
if c < int(final_posx - start_posx) {
|
||||
all_last_posx = append(all_last_posx, int( int(final_posx) - c ))
|
||||
if c < int(final_posx-start_posx) {
|
||||
all_last_posx = append(all_last_posx, int(int(final_posx)-c))
|
||||
}
|
||||
|
||||
for _,v := range all_last_posx {
|
||||
for j:=0;j<self.SectionNumbers;j++ {
|
||||
for _,u := range self.SecsKeys[j] {
|
||||
for _,x := range u {
|
||||
x_,y_ := x.Coord()
|
||||
x.NewCoord(x_+self.LeftOrRight*v,y_)
|
||||
for _, v := range all_last_posx {
|
||||
for j := 0; j < self.SectionNumbers; j++ {
|
||||
for _, u := range self.SecsKeys[j] {
|
||||
for _, x := range u {
|
||||
x_, y_ := x.Coord()
|
||||
x.NewCoord(x_+self.LeftOrRight*v, y_)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,8 +408,7 @@ func (self *Keyboard) ShiftKeyboardPage() {
|
||||
self.Screen.SwapAndShow()
|
||||
}
|
||||
|
||||
|
||||
func (self *Keyboard) KeyDown( ev *event.Event) {
|
||||
func (self *Keyboard) KeyDown(ev *event.Event) {
|
||||
if ev.Data["Key"] == CurKeys["Up"] {
|
||||
self.SelectUpChar()
|
||||
return
|
||||
@@ -441,36 +433,36 @@ func (self *Keyboard) KeyDown( ev *event.Event) {
|
||||
self.ClickOnChar()
|
||||
return
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["X"] {
|
||||
if self.SectionIndex <= 0 {
|
||||
self.LeftOrRight = -1
|
||||
}
|
||||
|
||||
if self.SectionIndex >= (self.SectionNumbers - 1) {
|
||||
self.LeftOrRight = 1
|
||||
}
|
||||
|
||||
self.ShiftKeyboardPage()
|
||||
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["X"] {
|
||||
if self.SectionIndex <= 0 {
|
||||
self.LeftOrRight = -1
|
||||
}
|
||||
|
||||
if self.SectionIndex >= (self.SectionNumbers - 1) {
|
||||
self.LeftOrRight = 1
|
||||
}
|
||||
|
||||
self.ShiftKeyboardPage()
|
||||
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["Menu"] {
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.Draw()
|
||||
self.Screen.SwapAndShow()
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["Y"] { // done
|
||||
fmt.Println(strings.Join(self.Textarea.MyWords,""))
|
||||
fmt.Println(strings.Join(self.Textarea.MyWords, ""))
|
||||
self.ReturnToUpLevelPage()
|
||||
self.Screen.SwapAndShow()
|
||||
if self.Caller != nil {
|
||||
self.Caller.OnKbdReturnBackCb()
|
||||
}
|
||||
if self.Caller != nil {
|
||||
self.Caller.OnKbdReturnBackCb()
|
||||
}
|
||||
//Uplevel/Parent page invoke OnReturnBackCb,eg: ConfigWireless
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["A"] {
|
||||
@@ -480,7 +472,7 @@ func (self *Keyboard) KeyDown( ev *event.Event) {
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == CurKeys["LK1"] {
|
||||
if self.SectionIndex < self.SectionNumbers -1 {
|
||||
if self.SectionIndex < self.SectionNumbers-1 {
|
||||
self.LeftOrRight = -1
|
||||
self.ShiftKeyboardPage()
|
||||
}
|
||||
@@ -499,9 +491,9 @@ func (self *Keyboard) Draw() {
|
||||
self.ClearCanvas()
|
||||
self.Ps.Draw()
|
||||
|
||||
for i:=0; i < self.SectionNumbers; i++ {
|
||||
for _,j := range self.SecsKeys[i] {
|
||||
for _,u := range j {
|
||||
for i := 0; i < self.SectionNumbers; i++ {
|
||||
for _, j := range self.SecsKeys[i] {
|
||||
for _, u := range j {
|
||||
u.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,10 @@ import (
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
)
|
||||
|
||||
|
||||
var CurKeys map[string]string
|
||||
|
||||
var GameShell map[string]string
|
||||
var PC map[string]string
|
||||
|
||||
var PC map[string]string
|
||||
|
||||
func DefinePC() {
|
||||
PC["Up"] = "Up"
|
||||
@@ -17,19 +15,19 @@ func DefinePC() {
|
||||
PC["Left"] = "Left"
|
||||
PC["Right"] = "Right"
|
||||
PC["Menu"] = "Escape"
|
||||
PC["X"] = "X"
|
||||
PC["Y"] = "Y"
|
||||
PC["A"] = "A"
|
||||
PC["B"] = "B"
|
||||
PC["X"] = "X"
|
||||
PC["Y"] = "Y"
|
||||
PC["A"] = "A"
|
||||
PC["B"] = "B"
|
||||
|
||||
PC["Vol-"] = "Space"
|
||||
PC["Vol+"] = "Return"
|
||||
PC["Vol-"] = "Space"
|
||||
PC["Vol+"] = "Return"
|
||||
PC["Space"] = "Space"
|
||||
PC["Enter"] = "Return"
|
||||
PC["Start"] = "S"
|
||||
|
||||
PC["LK1"] = "H"
|
||||
PC["LK5"] = "L"
|
||||
PC["LK1"] = "H"
|
||||
PC["LK5"] = "L"
|
||||
}
|
||||
|
||||
func DefineGameShell() {
|
||||
@@ -38,33 +36,32 @@ func DefineGameShell() {
|
||||
GameShell["Left"] = "Left"
|
||||
GameShell["Right"] = "Right"
|
||||
GameShell["Menu"] = "Escape"
|
||||
GameShell["X"] = "U"
|
||||
GameShell["Y"] = "I"
|
||||
GameShell["A"] = "J"
|
||||
GameShell["B"] = "K"
|
||||
GameShell["X"] = "U"
|
||||
GameShell["Y"] = "I"
|
||||
GameShell["A"] = "J"
|
||||
GameShell["B"] = "K"
|
||||
|
||||
GameShell["Vol-"] = "Space"
|
||||
GameShell["Vol+"] = "Return"
|
||||
GameShell["Vol-"] = "Space"
|
||||
GameShell["Vol+"] = "Return"
|
||||
GameShell["Space"] = "Space"
|
||||
GameShell["Enter"] = "K"
|
||||
GameShell["Start"] = "Return"
|
||||
|
||||
GameShell["LK1"] = "H"
|
||||
GameShell["LK5"] = "L"
|
||||
|
||||
GameShell["LK1"] = "H"
|
||||
GameShell["LK5"] = "L"
|
||||
|
||||
}
|
||||
|
||||
|
||||
func keys_def_init(){
|
||||
func keys_def_init() {
|
||||
GameShell = make(map[string]string)
|
||||
PC = make(map[string]string)
|
||||
PC = make(map[string]string)
|
||||
|
||||
DefineGameShell()
|
||||
DefinePC()
|
||||
|
||||
|
||||
if sysgo.CurKeySet == "GameShell" {
|
||||
CurKeys = GameShell
|
||||
}else {
|
||||
} else {
|
||||
CurKeys = PC
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,81 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
//"fmt"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
type LabelInterface interface {
|
||||
Init( text string, font_obj *ttf.Font,col *color.Color )
|
||||
SetCanvasHWND( canvas *sdl.Surface)
|
||||
Coord() (int,int)
|
||||
Size() (int,int)
|
||||
NewCoord(x,y int)
|
||||
NewSize(w,h int)
|
||||
SetColor(col *color.Color )
|
||||
Init(text string, font_obj *ttf.Font, col *color.Color)
|
||||
SetCanvasHWND(canvas *sdl.Surface)
|
||||
Coord() (int, int)
|
||||
Size() (int, int)
|
||||
NewCoord(x, y int)
|
||||
NewSize(w, h int)
|
||||
SetColor(col *color.Color)
|
||||
GetText() string
|
||||
SetText(text string)
|
||||
Draw()
|
||||
DrawCenter(bold bool)
|
||||
SetBold(b bool)
|
||||
DrawCenter(bold bool)
|
||||
SetBold(b bool)
|
||||
}
|
||||
|
||||
type Label struct {
|
||||
Widget
|
||||
Text string
|
||||
FontObj *ttf.Font
|
||||
Color *color.Color
|
||||
Text string
|
||||
FontObj *ttf.Font
|
||||
Color *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
Bold bool
|
||||
// TextSurf *sdl.Surface
|
||||
Bold bool
|
||||
// TextSurf *sdl.Surface
|
||||
}
|
||||
|
||||
func NewLabel() *Label {
|
||||
l := &Label{}
|
||||
l.Color = &color.Color{83,83,83,255}
|
||||
l.Bold = false
|
||||
l.Color = &color.Color{83, 83, 83, 255}
|
||||
l.Bold = false
|
||||
return l
|
||||
}
|
||||
|
||||
func (self *Label) Init(text string, font_obj *ttf.Font,col *color.Color ) {
|
||||
func (self *Label) Init(text string, font_obj *ttf.Font, col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
|
||||
|
||||
self.Text = text
|
||||
|
||||
self.FontObj = font_obj
|
||||
|
||||
self.Width,self.Height = font.Size(self.FontObj, self.Text)
|
||||
|
||||
self.Width, self.Height = font.Size(self.FontObj, self.Text)
|
||||
|
||||
}
|
||||
|
||||
func (self *Label) SetCanvasHWND( canvas *sdl.Surface) {
|
||||
func (self *Label) SetCanvasHWND(canvas *sdl.Surface) {
|
||||
self.CanvasHWND = canvas
|
||||
}
|
||||
|
||||
func (self *Label) Coord() (int,int) {
|
||||
return self.PosX,self.PosY
|
||||
func (self *Label) Coord() (int, int) {
|
||||
return self.PosX, self.PosY
|
||||
}
|
||||
|
||||
func (self *Label) Size() (int,int) {
|
||||
return self.Width,self.Height
|
||||
func (self *Label) Size() (int, int) {
|
||||
return self.Width, self.Height
|
||||
}
|
||||
|
||||
func (self *Label) NewCoord(x,y int) {
|
||||
func (self *Label) NewCoord(x, y int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Label) SetColor(col *color.Color){
|
||||
func (self *Label) SetColor(col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
@@ -87,35 +85,34 @@ func (self *Label) GetText() string {
|
||||
return self.Text
|
||||
}
|
||||
|
||||
|
||||
func (self *Label) SetText(text string) {
|
||||
self.Text = text
|
||||
self.Width,self.Height = font.Size(self.FontObj, self.Text)
|
||||
self.Width, self.Height = font.Size(self.FontObj, self.Text)
|
||||
}
|
||||
|
||||
func (self *Label) SetBold(b bool) {
|
||||
self.Bold = b
|
||||
self.Bold = b
|
||||
}
|
||||
|
||||
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)
|
||||
my_text.Free()
|
||||
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)
|
||||
my_text.Free()
|
||||
}
|
||||
|
||||
func (self *Label) Draw() {
|
||||
font.SetBold(self.FontObj,self.Bold) // avoing same font tangling set_bold to others
|
||||
if len(self.Text) == 0 {
|
||||
font.SetBold(self.FontObj, self.Bold) // avoing same font tangling set_bold to others
|
||||
if len(self.Text) == 0 {
|
||||
return
|
||||
}
|
||||
my_text := font.Render(self.FontObj,self.Text, true, self.Color, nil)
|
||||
my_text := font.Render(self.FontObj, self.Text, true, self.Color, nil)
|
||||
|
||||
rect_ := rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
|
||||
|
||||
surface.Blit(self.CanvasHWND,my_text,&rect_,nil)
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
|
||||
surface.Blit(self.CanvasHWND, my_text, &rect_, nil)
|
||||
my_text.Free()
|
||||
}
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"fmt"
|
||||
"github.com/go-ini/ini"
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
func sliceToInt(s []int) int {
|
||||
res := 0
|
||||
op := 1
|
||||
for i := len(s) - 1; i >= 0; i-- {
|
||||
res += s[i] * op
|
||||
op *= 10
|
||||
}
|
||||
return res
|
||||
res := 0
|
||||
op := 1
|
||||
for i := len(s) - 1; i >= 0; i-- {
|
||||
res += s[i] * op
|
||||
op *= 10
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
func ParseNum(s string) []int {
|
||||
nLen := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
@@ -39,134 +36,133 @@ func ParseNum(s string) []int {
|
||||
}
|
||||
|
||||
func GetNumberFromString(s string) int {
|
||||
is := ParseNum(s)
|
||||
|
||||
return sliceToInt(is)
|
||||
is := ParseNum(s)
|
||||
|
||||
return sliceToInt(is)
|
||||
|
||||
}
|
||||
|
||||
type LangManager struct {
|
||||
|
||||
Langs map[string]string
|
||||
ConfigFilename string
|
||||
|
||||
CJKMode bool
|
||||
Langs map[string]string
|
||||
ConfigFilename string
|
||||
|
||||
CJKMode bool
|
||||
}
|
||||
|
||||
func NewLangManager() *LangManager {
|
||||
p := &LangManager{}
|
||||
|
||||
p.ConfigFilename = "00_English.ini"
|
||||
p.CJKMode = false
|
||||
|
||||
return p
|
||||
p := &LangManager{}
|
||||
|
||||
p.ConfigFilename = "00_English.ini"
|
||||
p.CJKMode = false
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *LangManager) Init() {
|
||||
if self.Langs == nil {
|
||||
self.SetLangs()
|
||||
}
|
||||
if self.Langs == nil {
|
||||
self.SetLangs()
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LangManager) UpdateLang() {
|
||||
|
||||
self.Langs = nil
|
||||
self.SetLangs()
|
||||
|
||||
self.Langs = nil
|
||||
self.SetLangs()
|
||||
|
||||
}
|
||||
|
||||
func (self *LangManager) IsCJKMode() bool {
|
||||
var latins = [1]string{"English"}
|
||||
|
||||
self.CJKMode= false
|
||||
|
||||
for _,v := range latins {
|
||||
if strings.HasPrefix(self.ConfigFilename,v) {
|
||||
self.CJKMode = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return self.CJKMode
|
||||
var latins = [1]string{"English"}
|
||||
|
||||
self.CJKMode = false
|
||||
|
||||
for _, v := range latins {
|
||||
if strings.HasPrefix(self.ConfigFilename, v) {
|
||||
self.CJKMode = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return self.CJKMode
|
||||
}
|
||||
|
||||
func (self *LangManager) SetLangs() {
|
||||
|
||||
self.Langs = make(map[string]string)
|
||||
fname := "sysgo/.lang"
|
||||
|
||||
load_opts := ini.LoadOptions{
|
||||
IgnoreInlineComment:true,
|
||||
|
||||
self.Langs = make(map[string]string)
|
||||
fname := "sysgo/.lang"
|
||||
|
||||
load_opts := ini.LoadOptions{
|
||||
IgnoreInlineComment: true,
|
||||
}
|
||||
|
||||
if FileExists(fname) {
|
||||
config_bytes,err := ioutil.ReadFile(fname)
|
||||
if err == nil {
|
||||
self.ConfigFilename = strings.Trim(string(config_bytes),"\r\n ")
|
||||
if len(self.ConfigFilename) < 3 {
|
||||
self.ConfigFilename = "00_English.ini"
|
||||
}
|
||||
}
|
||||
}else {
|
||||
System("touch " + fname)
|
||||
}
|
||||
|
||||
config_file_relative_path := filepath.Join("sysgo","langs",self.ConfigFilename)
|
||||
|
||||
if FileExists(config_file_relative_path) == false {
|
||||
return
|
||||
}
|
||||
|
||||
//no matter what ,we must have 00_English.ini
|
||||
|
||||
if FileExists(fname) {
|
||||
config_bytes, err := ioutil.ReadFile(fname)
|
||||
if err == nil {
|
||||
self.ConfigFilename = strings.Trim(string(config_bytes), "\r\n ")
|
||||
if len(self.ConfigFilename) < 3 {
|
||||
self.ConfigFilename = "00_English.ini"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System("touch " + fname)
|
||||
}
|
||||
|
||||
config_file_relative_path := filepath.Join("sysgo", "langs", self.ConfigFilename)
|
||||
|
||||
if FileExists(config_file_relative_path) == false {
|
||||
return
|
||||
}
|
||||
|
||||
//no matter what ,we must have 00_English.ini
|
||||
cfg, err := ini.LoadSources(load_opts, config_file_relative_path)
|
||||
if err != nil {
|
||||
fmt.Printf("Fail to read file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
section := cfg.Section("Langs")
|
||||
if section != nil {
|
||||
opts := section.KeyStrings()
|
||||
for _,v := range opts {
|
||||
self.Langs[v] = section.Key(v).String()
|
||||
for _, v := range opts {
|
||||
self.Langs[v] = section.Key(v).String()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *LangManager) Tr(english_key_str string) string {
|
||||
|
||||
if self.Langs == nil {
|
||||
return english_key_str
|
||||
}
|
||||
|
||||
if len(self.Langs) == 0 {
|
||||
return english_key_str
|
||||
}
|
||||
|
||||
if v,ok := self.Langs[english_key_str]; ok {
|
||||
|
||||
return v
|
||||
}
|
||||
return english_key_str
|
||||
if self.Langs == nil {
|
||||
return english_key_str
|
||||
}
|
||||
|
||||
if len(self.Langs) == 0 {
|
||||
return english_key_str
|
||||
}
|
||||
|
||||
if v, ok := self.Langs[english_key_str]; ok {
|
||||
|
||||
return v
|
||||
}
|
||||
return english_key_str
|
||||
}
|
||||
|
||||
func (self *LangManager) TrFont(orig_font_str string) *ttf.Font {
|
||||
|
||||
font_size_number := GetNumberFromString(orig_font_str)
|
||||
if font_size_number > 120 {
|
||||
panic("font string format error")
|
||||
}
|
||||
|
||||
if strings.Contains(self.ConfigFilename,"English.ini") {
|
||||
return Fonts[orig_font_str]
|
||||
}else {
|
||||
if font_size_number > 28 {
|
||||
panic("cjk font size over 28")
|
||||
}
|
||||
}
|
||||
|
||||
return Fonts[ fmt.Sprintf("notosanscjk%d",font_size_number) ]
|
||||
font_size_number := GetNumberFromString(orig_font_str)
|
||||
if font_size_number > 120 {
|
||||
panic("font string format error")
|
||||
}
|
||||
|
||||
if strings.Contains(self.ConfigFilename, "English.ini") {
|
||||
return Fonts[orig_font_str]
|
||||
} else {
|
||||
if font_size_number > 28 {
|
||||
panic("cjk font size over 28")
|
||||
}
|
||||
}
|
||||
|
||||
return Fonts[fmt.Sprintf("notosanscjk%d", font_size_number)]
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,21 @@ package UI
|
||||
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
)
|
||||
|
||||
type ListItemInterface interface {
|
||||
|
||||
Init(text string)
|
||||
|
||||
Size() (int,int)
|
||||
NewSize(w,h int)
|
||||
Coord() (int,int)
|
||||
NewCoord(x,y int)
|
||||
|
||||
Size() (int, int)
|
||||
NewSize(w, h int)
|
||||
Coord() (int, int)
|
||||
NewCoord(x, y int)
|
||||
|
||||
GetLinkObj() PluginInterface
|
||||
Draw()
|
||||
|
||||
}
|
||||
|
||||
type ListItem struct {
|
||||
@@ -29,57 +26,52 @@ type ListItem struct {
|
||||
Fonts map[string]*ttf.Font
|
||||
|
||||
LinkObj PluginInterface
|
||||
|
||||
|
||||
Parent PageInterface
|
||||
}
|
||||
|
||||
func NewListItem() *ListItem {
|
||||
i := &ListItem{}
|
||||
i.Labels = make(map[string]LabelInterface)
|
||||
i.Icons = make( map[string]IconItemInterface)
|
||||
i.Fonts = make(map[string]*ttf.Font)
|
||||
i.Icons = make(map[string]IconItemInterface)
|
||||
i.Fonts = make(map[string]*ttf.Font)
|
||||
|
||||
i.Height = 30
|
||||
i.Width = 0
|
||||
|
||||
i.Width = 0
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
|
||||
func (self *ListItem) Init(text string) {
|
||||
l := NewLabel()
|
||||
l.PosX = 16
|
||||
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
|
||||
l.Init(text,self.Fonts["normal"],nil)
|
||||
l.Init(text, self.Fonts["normal"], nil)
|
||||
self.Labels["Text"] = l
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (self *ListItem) Coord() (int,int) {
|
||||
return self.PosX,self.PosY
|
||||
func (self *ListItem) Coord() (int, int) {
|
||||
return self.PosX, self.PosY
|
||||
}
|
||||
|
||||
func (self *ListItem) Size() (int,int) {
|
||||
return self.Width,self.Height
|
||||
func (self *ListItem) Size() (int, int) {
|
||||
return self.Width, self.Height
|
||||
}
|
||||
|
||||
|
||||
func (self *ListItem) GetLinkObj() PluginInterface {
|
||||
return self.LinkObj
|
||||
}
|
||||
|
||||
func (self *ListItem) Draw() {
|
||||
x_,_ := self.Labels["Text"].Coord()
|
||||
_,h_ := self.Labels["Text"].Size()
|
||||
|
||||
self.Labels["Text"].NewCoord(x_, self.PosY+(self.Height - h_)/2)
|
||||
x_, _ := self.Labels["Text"].Coord()
|
||||
_, h_ := self.Labels["Text"].Size()
|
||||
|
||||
self.Labels["Text"].NewCoord(x_, self.PosY+(self.Height-h_)/2)
|
||||
self.Labels["Text"].Draw()
|
||||
|
||||
|
||||
draw.Line(self.Parent.GetCanvasHWND(),&color.Color{169,169,169,255},
|
||||
self.PosX, (self.PosY+self.Height-1),
|
||||
(self.PosX+self.Width),(self.PosY+self.Height-1),1)
|
||||
draw.Line(self.Parent.GetCanvasHWND(), &color.Color{169, 169, 169, 255},
|
||||
self.PosX, (self.PosY + self.Height - 1),
|
||||
(self.PosX + self.Width), (self.PosY + self.Height - 1), 1)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,68 +3,68 @@ package UI
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"log"
|
||||
"strings"
|
||||
//"encoding/json"
|
||||
"path/filepath"
|
||||
gotime "time"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"path/filepath"
|
||||
gotime "time"
|
||||
|
||||
"github.com/cuu/gogame/display"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/display"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/time"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/event"
|
||||
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
)
|
||||
|
||||
//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()
|
||||
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()
|
||||
IsWifiConnectedNow()
|
||||
}
|
||||
|
||||
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
|
||||
SO_FILE string `json:"SO_FILE"`
|
||||
|
||||
}
|
||||
|
||||
type MessageBox struct {
|
||||
Label
|
||||
Parent *MainScreen
|
||||
HWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
}
|
||||
|
||||
func NewMessageBox() *MessageBox {
|
||||
m := &MessageBox{}
|
||||
m.Color = &color.Color{83,83,83,255}
|
||||
|
||||
m.Color = &color.Color{83, 83, 83, 255}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (self *MessageBox) Init( text string, font_obj *ttf.Font, col *color.Color) {
|
||||
func (self *MessageBox) Init(text string, font_obj *ttf.Font, col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
@@ -76,21 +76,21 @@ func (self *MessageBox) Init( text string, font_obj *ttf.Font, col *color.Color)
|
||||
self.Height = 0
|
||||
|
||||
self.CanvasHWND = surface.Surface(self.Parent.Width, self.Parent.Height)
|
||||
self.HWND = self.Parent.CanvasHWND
|
||||
|
||||
self.HWND = self.Parent.CanvasHWND
|
||||
|
||||
}
|
||||
|
||||
func (self *MessageBox) SetText( text string) {
|
||||
func (self *MessageBox) SetText(text string) {
|
||||
self.Text = text
|
||||
}
|
||||
|
||||
func (self *MessageBox) Draw() {
|
||||
self.Width = 0
|
||||
self.Height = 0
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255,255,255,255} )
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255, 255, 255, 255})
|
||||
|
||||
words := strings.Split(self.Text," ")
|
||||
space,_ := font.Size(self.FontObj," ")
|
||||
words := strings.Split(self.Text, " ")
|
||||
space, _ := font.Size(self.FontObj, " ")
|
||||
|
||||
max_width := self.Parent.Width - 40
|
||||
x := 0
|
||||
@@ -99,8 +99,8 @@ func (self *MessageBox) Draw() {
|
||||
row_total_width := 0
|
||||
lines := 0
|
||||
|
||||
for _,word := range words {
|
||||
word_surface := font.Render( self.FontObj, word, true, self.Color,nil)
|
||||
for _, word := range words {
|
||||
word_surface := font.Render(self.FontObj, word, true, self.Color, nil)
|
||||
word_width := int(word_surface.W)
|
||||
word_height := int(word_surface.H)
|
||||
row_total_width += word_width
|
||||
@@ -108,27 +108,27 @@ func (self *MessageBox) Draw() {
|
||||
lines += word_height
|
||||
}
|
||||
|
||||
if (row_total_width + space ) >= max_width {
|
||||
if (row_total_width + space) >= max_width {
|
||||
x = 0
|
||||
y += word_height
|
||||
row_total_width = word_width
|
||||
lines+=word_height
|
||||
lines += word_height
|
||||
}
|
||||
|
||||
dest_rect := rect.Rect(x,y, word_width,word_height)
|
||||
surface.Blit(self.CanvasHWND, word_surface, &dest_rect,nil)
|
||||
word_surface.Free()
|
||||
dest_rect := rect.Rect(x, y, word_width, word_height)
|
||||
surface.Blit(self.CanvasHWND, word_surface, &dest_rect, nil)
|
||||
word_surface.Free()
|
||||
if len(words) == 1 {
|
||||
x+=word_width
|
||||
x += word_width
|
||||
} else {
|
||||
x += word_width+space
|
||||
x += word_width + space
|
||||
}
|
||||
|
||||
|
||||
if x > self.Width {
|
||||
self.Width = x
|
||||
}
|
||||
|
||||
if lines >= self.Parent.Height - 40 {
|
||||
if lines >= self.Parent.Height-40 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -137,31 +137,30 @@ func (self *MessageBox) Draw() {
|
||||
|
||||
padding := 5
|
||||
x = (self.Parent.Width - self.Width) / 2
|
||||
y = (self.Parent.Height - self.Height) /2
|
||||
y = (self.Parent.Height - self.Height) / 2
|
||||
|
||||
rect_ := rect.Rect(x-padding, y-padding, self.Width+padding*2, self.Height+padding*2)
|
||||
|
||||
rect_ := rect.Rect(x-padding,y-padding, self.Width+padding*2, self.Height+padding*2)
|
||||
|
||||
if self.HWND != nil {
|
||||
|
||||
draw.Rect(self.HWND , &color.Color{255,255,255,255},&rect_,0)
|
||||
|
||||
rect__ := draw.MidRect(self.Parent.Width/2, self.Parent.Height/2,self.Width,self.Height,Width,Height)
|
||||
|
||||
dest_rect := rect.Rect(0,0,self.Width,self.Height)
|
||||
|
||||
|
||||
draw.Rect(self.HWND, &color.Color{255, 255, 255, 255}, &rect_, 0)
|
||||
|
||||
rect__ := draw.MidRect(self.Parent.Width/2, self.Parent.Height/2, self.Width, self.Height, Width, Height)
|
||||
|
||||
dest_rect := rect.Rect(0, 0, self.Width, self.Height)
|
||||
|
||||
surface.Blit(self.HWND, self.CanvasHWND, rect__, &dest_rect)
|
||||
|
||||
draw.Rect(self.HWND , &color.Color{0,0,0,255},&rect_,1)
|
||||
|
||||
|
||||
draw.Rect(self.HWND, &color.Color{0, 0, 0, 255}, &rect_, 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
type MainScreen struct {
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
PageMax int
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
PageMax int
|
||||
PageIndex int
|
||||
|
||||
MyPageStack *PageStack
|
||||
@@ -174,71 +173,68 @@ type MainScreen struct {
|
||||
MsgBoxFont *ttf.Font
|
||||
IconFont *ttf.Font
|
||||
SkinManager *SkinManager
|
||||
|
||||
CounterScreen *CounterScreen
|
||||
Closed bool
|
||||
|
||||
UIPluginList []*UIPlugin
|
||||
|
||||
LastKey string
|
||||
LastKeyDown gotime.Time
|
||||
}
|
||||
|
||||
CounterScreen *CounterScreen
|
||||
Closed bool
|
||||
|
||||
UIPluginList []*UIPlugin
|
||||
|
||||
LastKey string
|
||||
LastKeyDown gotime.Time
|
||||
}
|
||||
|
||||
func NewMainScreen() *MainScreen {
|
||||
m := &MainScreen{}
|
||||
|
||||
m.PosY = TitleBar_BarHeight+1
|
||||
|
||||
m.PosY = TitleBar_BarHeight + 1
|
||||
m.Width = Width
|
||||
m.Height = Height - FootBar_BarHeight - TitleBar_BarHeight - 1
|
||||
m.MyPageStack = NewPageStack()
|
||||
|
||||
|
||||
m.MsgBoxFont = Fonts["veramono20"]
|
||||
m.IconFont = Fonts["varela15"]
|
||||
m.Closed = false
|
||||
m.IconFont = Fonts["varela15"]
|
||||
m.Closed = false
|
||||
return m
|
||||
}
|
||||
|
||||
func (self *MainScreen) Init() {
|
||||
self.CanvasHWND = surface.Surface(self.Width,self.Height)
|
||||
|
||||
self.MsgBox = NewMessageBox()
|
||||
self.CanvasHWND = surface.Surface(self.Width, self.Height)
|
||||
|
||||
self.MsgBox = NewMessageBox()
|
||||
self.MsgBox.Parent = self
|
||||
self.MsgBox.Init(" ", self.MsgBoxFont, &color.Color{83,83,83,255})
|
||||
self.MsgBox.Init(" ", self.MsgBoxFont, &color.Color{83, 83, 83, 255})
|
||||
|
||||
self.SkinManager = NewSkinManager()
|
||||
self.SkinManager.Init()
|
||||
|
||||
self.CounterScreen = NewCounterScreen()
|
||||
self.CounterScreen.HWND = self.HWND
|
||||
self.CounterScreen.Init()
|
||||
|
||||
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
|
||||
|
||||
self.CounterScreen = NewCounterScreen()
|
||||
self.CounterScreen.HWND = self.HWND
|
||||
self.CounterScreen.Init()
|
||||
|
||||
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
|
||||
self.PageMax = len(self.Pages)
|
||||
|
||||
for i:=0;i< self.PageMax; i++ {
|
||||
for i := 0; i < self.PageMax; i++ {
|
||||
self.Pages[i].SetIndex(i)
|
||||
self.Pages[i].SetCanvasHWND(self.CanvasHWND)
|
||||
self.Pages[i].UpdateIconNumbers() // IconNumbers always == len(Pages[i].Icons)
|
||||
self.Pages[i].SetScreen(self)
|
||||
self.Pages[i].Adjust()
|
||||
|
||||
|
||||
if self.Pages[i].GetIconNumbers() > 1 {
|
||||
self.Pages[i].SetPsIndex(1)
|
||||
self.Pages[i].SetIconIndex( 1 )
|
||||
self.Pages[i].SetIconIndex(1)
|
||||
}
|
||||
}
|
||||
|
||||
self.CurrentPage = self.Pages[ self.PageIndex ]
|
||||
self.CurrentPage = self.Pages[self.PageIndex]
|
||||
self.CurrentPage.SetOnShow(true)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (self *MainScreen) CurPage() PageInterface {
|
||||
return self.CurrentPage
|
||||
}
|
||||
@@ -247,28 +243,28 @@ func (self *MainScreen) PushCurPage() {
|
||||
self.MyPageStack.Push(self.CurrentPage)
|
||||
}
|
||||
|
||||
func (self *MainScreen) SetCurPage( pg PageInterface) {
|
||||
func (self *MainScreen) SetCurPage(pg PageInterface) {
|
||||
self.CurrentPage = pg
|
||||
pg.OnLoadCb()
|
||||
}
|
||||
|
||||
func (self *MainScreen) PushPage( pg PageInterface) {
|
||||
func (self *MainScreen) PushPage(pg PageInterface) {
|
||||
self.PushCurPage()
|
||||
self.SetCurPage(pg)
|
||||
}
|
||||
|
||||
func (self *MainScreen) AppendPage( pg PageInterface ) {
|
||||
self.Pages = append(self.Pages,pg)
|
||||
func (self *MainScreen) AppendPage(pg PageInterface) {
|
||||
self.Pages = append(self.Pages, pg)
|
||||
}
|
||||
|
||||
func (self *MainScreen) ClearCanvas() {
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255,255,255,255} )
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255, 255, 255, 255})
|
||||
}
|
||||
|
||||
func (self *MainScreen) SwapAndShow() {
|
||||
if self.HWND != nil {
|
||||
rect_ := rect.Rect( self.PosX,self.PosY,self.Width,self.Height)
|
||||
surface.Blit(self.HWND,self.CanvasHWND,&rect_, nil)
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
|
||||
}
|
||||
|
||||
display.Flip()
|
||||
@@ -276,50 +272,49 @@ func (self *MainScreen) SwapAndShow() {
|
||||
|
||||
func (self *MainScreen) ExtraName(name string) string {
|
||||
|
||||
parts := strings.Split(name,"_")
|
||||
if len(parts) > 1 {
|
||||
parts := strings.Split(name, "_")
|
||||
if len(parts) > 1 {
|
||||
return parts[1]
|
||||
}else if len(parts) == 1 {
|
||||
} else if len(parts) == 1 {
|
||||
return parts[0]
|
||||
}else {
|
||||
} else {
|
||||
return name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ExecPackage is all-in-one folder ,Name.sh,Name.png,etc
|
||||
func (self *MainScreen) IsExecPackage(dirname string ) bool {
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
func (self *MainScreen) IsExecPackage(dirname string) bool {
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
bname := filepath.Base(dirname)
|
||||
bname = self.ExtraName(bname)
|
||||
|
||||
for _,v := range files {
|
||||
if v.Name() == bname+".sh" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
bname := filepath.Base(dirname)
|
||||
bname = self.ExtraName(bname)
|
||||
|
||||
for _, v := range files {
|
||||
if v.Name() == bname+".sh" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsPluginPackage(dirname string ) bool {
|
||||
func (self *MainScreen) IsPluginPackage(dirname string) bool {
|
||||
ret := false
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _,f := range files {
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
//pass
|
||||
}else {
|
||||
if strings.HasSuffix(f.Name(),Plugin_flag) == true {
|
||||
} else {
|
||||
if strings.HasSuffix(f.Name(), Plugin_flag) == true {
|
||||
ret = true
|
||||
break
|
||||
}
|
||||
@@ -329,33 +324,33 @@ func (self *MainScreen) IsPluginPackage(dirname string ) bool {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsEmulatorPackage(dirname string ) bool {
|
||||
func (self *MainScreen) IsEmulatorPackage(dirname string) bool {
|
||||
ret := false
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _,f := range files {
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
//pass
|
||||
}else {
|
||||
if strings.HasSuffix(f.Name(),Emulator_flag) == true {
|
||||
} else {
|
||||
if strings.HasSuffix(f.Name(), Emulator_flag) == true {
|
||||
ret = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsWifiConnectedNow() bool {
|
||||
|
||||
cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out)<6 {
|
||||
|
||||
cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out) < 6 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -363,25 +358,23 @@ func (self *MainScreen) IsWifiConnectedNow() bool {
|
||||
|
||||
func (self *MainScreen) GetWirelessIP() string {
|
||||
|
||||
cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
|
||||
out := SystemTrim(cli)
|
||||
cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
|
||||
out := SystemTrim(cli)
|
||||
|
||||
|
||||
return out
|
||||
return out
|
||||
}
|
||||
|
||||
func (self *MainScreen) RunEXE( cmdpath string) {
|
||||
func (self *MainScreen) RunEXE(cmdpath string) {
|
||||
self.DrawRun()
|
||||
self.SwapAndShow()
|
||||
|
||||
|
||||
time.BlockDelay(1000)
|
||||
|
||||
cmdpath = strings.Trim(cmdpath," ")
|
||||
cmdpath = strings.Trim(cmdpath, " ")
|
||||
cmdpath = CmdClean(cmdpath)
|
||||
|
||||
event.Post(RUNEVT,cmdpath)
|
||||
|
||||
|
||||
event.Post(RUNEVT, cmdpath)
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) OnExitCb() {
|
||||
@@ -399,13 +392,12 @@ func (self *MainScreen) KeyDown(ev *event.Event) {
|
||||
if ev.Data["Key"] == "Space" {
|
||||
self.Draw()
|
||||
self.SwapAndShow()
|
||||
}
|
||||
}
|
||||
|
||||
self.CurrentPage.KeyDown(ev)
|
||||
self.LastKey = ev.Data["Key"]
|
||||
|
||||
}
|
||||
self.LastKey = ev.Data["Key"]
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) DrawRun() {
|
||||
self.MsgBox.SetText("Launching....")
|
||||
@@ -416,14 +408,14 @@ func (self *MainScreen) Draw() {
|
||||
if self.CurrentPage != nil {
|
||||
self.CurrentPage.Draw()
|
||||
}
|
||||
|
||||
|
||||
if self.TitleBar != nil {
|
||||
//every plugin_init should not do any Draw actions since CurrentPage might be nil at that time
|
||||
self.TitleBar.Draw( self.CurrentPage.GetName())
|
||||
//every plugin_init should not do any Draw actions since CurrentPage might be nil at that time
|
||||
self.TitleBar.Draw(self.CurrentPage.GetName())
|
||||
}
|
||||
|
||||
if self.FootBar != nil {
|
||||
self.FootBar.SetLabelTexts( self.CurrentPage.GetFootMsg())
|
||||
self.FootBar.SetLabelTexts(self.CurrentPage.GetFootMsg())
|
||||
self.FootBar.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/image"
|
||||
"fmt"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
|
||||
type MultiIconItem struct {
|
||||
IconItem
|
||||
|
||||
IconWidth int
|
||||
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
|
||||
}
|
||||
|
||||
func NewMultiIconItem() *MultiIconItem {
|
||||
@@ -22,67 +20,67 @@ func NewMultiIconItem() *MultiIconItem {
|
||||
m.IconIndex = 0
|
||||
m.IconWidth = 18
|
||||
m.IconHeight = 18
|
||||
return m
|
||||
return m
|
||||
}
|
||||
|
||||
func (self * MultiIconItem) CreateImgSurf() {
|
||||
func (self *MultiIconItem) CreateImgSurf() {
|
||||
if self.ImgSurf == nil && self.ImageName != "" {
|
||||
self.ImgSurf = image.Load(self.ImageName)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MultiIconItem) DrawTopLeft() {
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: MultiIconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
|
||||
parent_x,parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Label != nil {
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6 + parent_y)
|
||||
}else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3 + parent_x, self.PosY - lab_h/2 + parent_y )
|
||||
}
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
portion := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
|
||||
rect_ := rect.Rect( self.PosX+parent_x,self.PosY+parent_y, self.Width,self.Height ) // DIFF
|
||||
surface.Blit(self.Parent.GetCanvasHWND(),self.ImgSurf,&rect_,&portion)
|
||||
}
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: MultiIconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
|
||||
parent_x, parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Label != nil {
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
|
||||
self.Label.NewCoord(self.PosX-lab_w/2+parent_x, self.PosY+self.Height/2+6+parent_y)
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3+parent_x, self.PosY-lab_h/2+parent_y)
|
||||
}
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
portion := rect.Rect(0, self.IconIndex*self.IconHeight, self.IconWidth, self.IconHeight)
|
||||
rect_ := rect.Rect(self.PosX+parent_x, self.PosY+parent_y, self.Width, self.Height) // DIFF
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf, &rect_, &portion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *MultiIconItem) Draw() {
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: MultiIconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x,parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Parent == nil {
|
||||
fmt.Println("Error: MultiIconItem Draw Parent nil")
|
||||
return
|
||||
}
|
||||
parent_x, parent_y := self.Parent.Coord()
|
||||
|
||||
if self.Label != nil {
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6 + parent_y)
|
||||
}else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3 + parent_x, self.PosY - lab_h/2 + parent_y )
|
||||
self.Label.NewCoord(self.PosX-lab_w/2+parent_x, self.PosY+self.Height/2+6+parent_y)
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3+parent_x, self.PosY-lab_h/2+parent_y)
|
||||
}
|
||||
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
|
||||
portion := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
|
||||
|
||||
|
||||
portion := rect.Rect(0, self.IconIndex*self.IconHeight, self.IconWidth, self.IconHeight)
|
||||
|
||||
surface.Blit(self.Parent.GetCanvasHWND(),
|
||||
self.ImgSurf,draw.MidRect(self.PosX + parent_x, self.PosY + parent_y,
|
||||
self.Width,self.Height, Width, Height),&portion)
|
||||
self.ImgSurf, draw.MidRect(self.PosX+parent_x, self.PosY+parent_y,
|
||||
self.Width, self.Height, Width, Height), &portion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package UI
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
//MultiLabel is also a LabelInterface
|
||||
@@ -20,24 +20,24 @@ type MultiLabel struct {
|
||||
Color *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
//TextSurf *sdl.Surface
|
||||
MaxWidth int
|
||||
Bold bool
|
||||
MaxWidth int
|
||||
Bold bool
|
||||
}
|
||||
|
||||
func NewMultiLabel() *MultiLabel{
|
||||
func NewMultiLabel() *MultiLabel {
|
||||
l := &MultiLabel{}
|
||||
l.Color = &color.Color{83,83,83,255}
|
||||
l.Color = &color.Color{83, 83, 83, 255}
|
||||
l.Width = 135
|
||||
l.Height = 100
|
||||
l.Bold = false
|
||||
l.Bold = false
|
||||
return l
|
||||
}
|
||||
|
||||
func (self *MultiLabel) Init(text string, font_obj *ttf.Font,col *color.Color) {
|
||||
func (self *MultiLabel) Init(text string, font_obj *ttf.Font, col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
|
||||
|
||||
self.Text = text
|
||||
self.FontObj = font_obj
|
||||
|
||||
@@ -46,12 +46,11 @@ func (self *MultiLabel) Init(text string, font_obj *ttf.Font,col *color.Color) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MultiLabel) SetCanvasHWND( canvas *sdl.Surface) {
|
||||
func (self *MultiLabel) SetCanvasHWND(canvas *sdl.Surface) {
|
||||
self.CanvasHWND = canvas
|
||||
}
|
||||
|
||||
|
||||
func (self *MultiLabel) SetColor(col *color.Color){
|
||||
func (self *MultiLabel) SetColor(col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
@@ -61,14 +60,13 @@ func (self *MultiLabel) GetText() string {
|
||||
return self.Text
|
||||
}
|
||||
|
||||
|
||||
func (self *MultiLabel) SetText(text string) {
|
||||
self.Text = text
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *MultiLabel) SetBold(b bool) {
|
||||
self.Bold = b
|
||||
self.Bold = b
|
||||
|
||||
}
|
||||
|
||||
@@ -77,22 +75,22 @@ func (self *MultiLabel) DrawCenter(bold bool) {
|
||||
}
|
||||
|
||||
func (self *MultiLabel) Draw() {
|
||||
font.SetBold(self.FontObj,self.Bold) // avoing same font tangling set_bold to others
|
||||
self.blit_text(self.CanvasHWND, self.Text,self.PosX,self.PosY,self.FontObj)
|
||||
font.SetBold(self.FontObj, self.Bold) // avoing same font tangling set_bold to others
|
||||
self.blit_text(self.CanvasHWND, self.Text, self.PosX, self.PosY, self.FontObj)
|
||||
}
|
||||
|
||||
// difference to Label
|
||||
func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int, fnt *ttf.Font) {
|
||||
func (self *MultiLabel) blit_text(surf *sdl.Surface, text string, pos_x, pos_y int, fnt *ttf.Font) {
|
||||
words := make([][]string, 0)
|
||||
temp := strings.Split(text,"\n")
|
||||
for _,v := range temp {
|
||||
t := strings.Split(v," ")
|
||||
words = append(words,t)
|
||||
temp := strings.Split(text, "\n")
|
||||
for _, v := range temp {
|
||||
t := strings.Split(v, " ")
|
||||
words = append(words, t)
|
||||
}
|
||||
|
||||
space,_ := font.Size(fnt," ")
|
||||
space, _ := font.Size(fnt, " ")
|
||||
max_width := self.Width
|
||||
x,y := pos_x,pos_y
|
||||
x, y := pos_x, pos_y
|
||||
|
||||
row_total_width := 0
|
||||
lines := 0
|
||||
@@ -101,33 +99,33 @@ func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int
|
||||
if len(words) > 4 {
|
||||
tmp = words[:4]
|
||||
}
|
||||
|
||||
for _,line := range tmp {
|
||||
|
||||
for _, line := range tmp {
|
||||
word_height := 0
|
||||
tmp2 := line
|
||||
if len(line) > 12 {
|
||||
tmp2 = line[:12]
|
||||
}
|
||||
|
||||
for _,word := range tmp2 {
|
||||
word_surface := font.Render(fnt,word,true,self.Color,nil)
|
||||
word_width := surface.GetWidth(word_surface)
|
||||
word_height = surface.GetHeight(word_surface)
|
||||
|
||||
for _, word := range tmp2 {
|
||||
word_surface := font.Render(fnt, word, true, self.Color, nil)
|
||||
word_width := surface.GetWidth(word_surface)
|
||||
word_height = surface.GetHeight(word_surface)
|
||||
row_total_width += word_width
|
||||
if row_total_width+space >= max_width {
|
||||
x = pos_x
|
||||
y = y+word_height
|
||||
y = y + word_height
|
||||
row_total_width = word_width
|
||||
if lines == 0 {
|
||||
lines = lines + word_height
|
||||
}else {
|
||||
} else {
|
||||
lines = lines + word_height
|
||||
}
|
||||
}
|
||||
}
|
||||
rect_ := rect.Rect(x,y,self.Width,self.Height)
|
||||
surface.Blit(surf,word_surface,&rect_,nil)
|
||||
word_surface.Free()
|
||||
x += (word_width+space)
|
||||
rect_ := rect.Rect(x, y, self.Width, self.Height)
|
||||
surface.Blit(surf, word_surface, &rect_, nil)
|
||||
word_surface.Free()
|
||||
x += (word_width + space)
|
||||
}
|
||||
x = pos_x
|
||||
y += word_height
|
||||
@@ -135,6 +133,5 @@ func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int
|
||||
}
|
||||
|
||||
self.Height = lines
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
760
sysgo/UI/page.go
760
sysgo/UI/page.go
File diff suppressed because it is too large
Load Diff
@@ -21,69 +21,67 @@ func (self *Plugin) GetName() string {
|
||||
return self.Name
|
||||
}
|
||||
|
||||
func (self *Plugin) Init( screen *MainScreen) {
|
||||
|
||||
func (self *Plugin) Init(screen *MainScreen) {
|
||||
|
||||
}
|
||||
|
||||
func (self *Plugin) Run(screen *MainScreen) {
|
||||
|
||||
func (self *Plugin) Run( screen *MainScreen) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func NewPluginPool() map[string]PluginInterface {
|
||||
pp :=make( map[string]PluginInterface )
|
||||
pp := make(map[string]PluginInterface)
|
||||
return pp
|
||||
}
|
||||
|
||||
func PluginPoolRegister( pi PluginInterface ) bool {
|
||||
func PluginPoolRegister(pi PluginInterface) bool {
|
||||
name := pi.GetName()
|
||||
|
||||
if _,ok := PluginPool[name]; ok {
|
||||
|
||||
if _, ok := PluginPool[name]; ok {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
PluginPool[name] = pi
|
||||
return true
|
||||
|
||||
|
||||
}
|
||||
|
||||
func LoadPlugin( pname string) (*goplugin.Plugin,error) {
|
||||
func LoadPlugin(pname string) (*goplugin.Plugin, error) {
|
||||
return goplugin.Open(pname)
|
||||
}
|
||||
|
||||
func InitPlugin(p *goplugin.Plugin, main_screen *MainScreen) PluginInterface {
|
||||
symAPI,err := p.Lookup("APIOBJ")
|
||||
symAPI, err := p.Lookup("APIOBJ")
|
||||
|
||||
if err!= nil {
|
||||
log.Fatal( "init plugin failed")
|
||||
if err != nil {
|
||||
log.Fatal("init plugin failed")
|
||||
return nil
|
||||
}
|
||||
|
||||
var pi PluginInterface
|
||||
pi,ok := symAPI.(PluginInterface)
|
||||
pi, ok := symAPI.(PluginInterface)
|
||||
if !ok {
|
||||
log.Fatal("unexpected type from module symbol")
|
||||
return nil
|
||||
}
|
||||
|
||||
//PluginPoolRegister(pi)
|
||||
|
||||
|
||||
pi.Init(main_screen)
|
||||
|
||||
return pi
|
||||
}
|
||||
|
||||
func RunPlugin(p *goplugin.Plugin, main_screen *MainScreen) {
|
||||
symAPI,err := p.Lookup("APIOBJ")
|
||||
symAPI, err := p.Lookup("APIOBJ")
|
||||
|
||||
if err!= nil {
|
||||
log.Fatal( "init plugin failed")
|
||||
if err != nil {
|
||||
log.Fatal("init plugin failed")
|
||||
return
|
||||
}
|
||||
|
||||
var pi PluginInterface
|
||||
pi,ok := symAPI.(PluginInterface)
|
||||
pi, ok := symAPI.(PluginInterface)
|
||||
if !ok {
|
||||
log.Fatal("unexpected type from module symbol")
|
||||
return
|
||||
@@ -92,14 +90,14 @@ func RunPlugin(p *goplugin.Plugin, main_screen *MainScreen) {
|
||||
}
|
||||
|
||||
const (
|
||||
PluginPackage = iota
|
||||
PluginSo
|
||||
PluginPackage = iota
|
||||
PluginSo
|
||||
)
|
||||
|
||||
type UIPlugin struct{ //Loadable and injectable
|
||||
Type int // 0 == loadable package, 1 == .so
|
||||
SoFile string
|
||||
FolderName string
|
||||
LabelText string
|
||||
EmbInterface PluginInterface
|
||||
type UIPlugin struct { //Loadable and injectable
|
||||
Type int // 0 == loadable package, 1 == .so
|
||||
SoFile string
|
||||
FolderName string
|
||||
LabelText string
|
||||
EmbInterface PluginInterface
|
||||
}
|
||||
|
||||
@@ -2,36 +2,35 @@ package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
// "github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
// "github.com/cuu/gogame/surface"
|
||||
// "github.com/cuu/gogame/rect"
|
||||
// "github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
// "github.com/cuu/gogame/surface"
|
||||
// "github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/color"
|
||||
// "github.com/cuu/gogame/font"
|
||||
// "github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/draw"
|
||||
)
|
||||
|
||||
type ListScroller struct{
|
||||
type ListScroller struct {
|
||||
Widget
|
||||
MinHeight int
|
||||
Parent PageInterface
|
||||
Color *color.Color
|
||||
|
||||
StartX int
|
||||
StartY int
|
||||
EndX int
|
||||
EndY int
|
||||
Value int
|
||||
Parent PageInterface
|
||||
Color *color.Color
|
||||
|
||||
StartX int
|
||||
StartY int
|
||||
EndX int
|
||||
EndY int
|
||||
Value int
|
||||
CanvasHWND *sdl.Surface
|
||||
}
|
||||
|
||||
|
||||
func NewListScroller() *ListScroller {
|
||||
l := &ListScroller{}
|
||||
l.Width = 7
|
||||
l.Color = &color.Color{131,199,219,255} // SkinManager().GiveColor('Front')
|
||||
l.Color = &color.Color{131, 199, 219, 255} // SkinManager().GiveColor('Front')
|
||||
return l
|
||||
}
|
||||
|
||||
@@ -41,52 +40,52 @@ func (self *ListScroller) Init() {
|
||||
self.SetCanvasHWND(cav_)
|
||||
}
|
||||
|
||||
func (self *ListScroller) SetCanvasHWND( canvas *sdl.Surface) {
|
||||
func (self *ListScroller) SetCanvasHWND(canvas *sdl.Surface) {
|
||||
self.CanvasHWND = canvas
|
||||
}
|
||||
|
||||
func (self *ListScroller) AnimateDraw(x2,y2 int) {
|
||||
|
||||
func (self *ListScroller) AnimateDraw(x2, y2 int) {
|
||||
|
||||
}
|
||||
|
||||
func (self *ListScroller) UpdateSize(bigheight, dirtyheight int) {
|
||||
_,h_ := self.Parent.Size()
|
||||
|
||||
bodyheight := float64(h_)/float64(bigheight)
|
||||
_, h_ := self.Parent.Size()
|
||||
|
||||
bodyheight := float64(h_) / float64(bigheight)
|
||||
if bodyheight > 1.0 {
|
||||
bodyheight = 1.0
|
||||
}
|
||||
|
||||
margin := 4
|
||||
|
||||
self.Height = int( bodyheight * float64(h_) - float64(margin) )
|
||||
self.Height = int(bodyheight*float64(h_) - float64(margin))
|
||||
|
||||
if self.Height < self.MinHeight {
|
||||
self.Height = self.MinHeight
|
||||
}
|
||||
|
||||
self.StartX = self.Width/2
|
||||
self.StartX = self.Width / 2
|
||||
self.StartY = margin/2 + self.Height/2
|
||||
|
||||
self.EndX = self.Width/2
|
||||
self.EndX = self.Width / 2
|
||||
self.EndY = h_ - margin/2 - self.Height/2
|
||||
|
||||
process := float64(dirtyheight) / float64(bigheight)
|
||||
process := float64(dirtyheight) / float64(bigheight)
|
||||
|
||||
value := process * float64(self.EndY - self.StartY)
|
||||
value := process * float64(self.EndY-self.StartY)
|
||||
|
||||
self.Value = int(value)
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *ListScroller) Draw() {
|
||||
w_,h_ := self.Parent.Size()
|
||||
w_, h_ := self.Parent.Size()
|
||||
|
||||
start_rect := draw.MidRect(self.PosX+self.StartX,self.StartY+self.Value,self.Width,self.Height,w_,h_)
|
||||
start_rect := draw.MidRect(self.PosX+self.StartX, self.StartY+self.Value, self.Width, self.Height, w_, h_)
|
||||
|
||||
if self.Width < 1 {
|
||||
fmt.Println("ListScroller width error")
|
||||
}else {
|
||||
draw.AARoundRect(self.CanvasHWND,start_rect,self.Color,3,0,self.Color)
|
||||
} else {
|
||||
draw.AARoundRect(self.CanvasHWND, start_rect, self.Color, 3, 0, self.Color)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package UI
|
||||
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
|
||||
"log"
|
||||
"strings"
|
||||
"strconv"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
)
|
||||
|
||||
type SkinManager struct {
|
||||
Colors map[string]*color.Color
|
||||
|
||||
}
|
||||
|
||||
func NewSkinManager() *SkinManager {
|
||||
@@ -26,61 +24,60 @@ func NewSkinManager() *SkinManager {
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
func (self *SkinManager) ConvertToRGB(hexstr string) *color.Color {
|
||||
if len(hexstr) < 7 || string(hexstr[0]) != "#" { // # 00 00 00
|
||||
log.Fatalf("ConvertToRGB hex string format error %s", hexstr)
|
||||
//fmt.Printf("ConvertToRGB hex string format error %s", hexstr)
|
||||
return nil
|
||||
}
|
||||
|
||||
h := strings.TrimLeft(hexstr,"#")
|
||||
|
||||
r,_ := strconv.ParseInt(h[0:2], 16,0)
|
||||
g,_ := strconv.ParseInt(h[2:4], 16,0)
|
||||
b,_ := strconv.ParseInt(h[4:6], 16,0)
|
||||
|
||||
col := &color.Color{ uint32(r),uint32(g),uint32(b),255 }
|
||||
h := strings.TrimLeft(hexstr, "#")
|
||||
|
||||
r, _ := strconv.ParseInt(h[0:2], 16, 0)
|
||||
g, _ := strconv.ParseInt(h[2:4], 16, 0)
|
||||
b, _ := strconv.ParseInt(h[4:6], 16, 0)
|
||||
|
||||
col := &color.Color{uint32(r), uint32(g), uint32(b), 255}
|
||||
return col
|
||||
}
|
||||
|
||||
func (self *SkinManager) ChangeSkin( skin_name string ) {
|
||||
|
||||
func (self *SkinManager) ChangeSkin(skin_name string) {
|
||||
|
||||
}
|
||||
|
||||
func (self *SkinManager) Init() {
|
||||
self.Colors = make(map[string]*color.Color)
|
||||
|
||||
self.Colors["High"] = &color.Color{51,166,255,255}
|
||||
self.Colors["Text"] = &color.Color{83,83,83,255}
|
||||
self.Colors["ReadOnlyText"] = &color.Color{130,130,130,255}
|
||||
self.Colors["Front"] = &color.Color{131,199,219,255}
|
||||
self.Colors["URL"] = &color.Color{51,166,255,255}
|
||||
self.Colors["Line"] = &color.Color{169,169,169,255}
|
||||
self.Colors["TitleBg"] = &color.Color{228,228,228,255}
|
||||
self.Colors["Active"] = &color.Color{175,90,0,255}
|
||||
self.Colors["Disabled"] = &color.Color{204,204,204,255}
|
||||
self.Colors["High"] = &color.Color{51, 166, 255, 255}
|
||||
self.Colors["Text"] = &color.Color{83, 83, 83, 255}
|
||||
self.Colors["ReadOnlyText"] = &color.Color{130, 130, 130, 255}
|
||||
self.Colors["Front"] = &color.Color{131, 199, 219, 255}
|
||||
self.Colors["URL"] = &color.Color{51, 166, 255, 255}
|
||||
self.Colors["Line"] = &color.Color{169, 169, 169, 255}
|
||||
self.Colors["TitleBg"] = &color.Color{228, 228, 228, 255}
|
||||
self.Colors["Active"] = &color.Color{175, 90, 0, 255}
|
||||
self.Colors["Disabled"] = &color.Color{204, 204, 204, 255}
|
||||
|
||||
self.Colors["White"] = &color.Color{255,255,255,255}
|
||||
self.Colors["Black"] = &color.Color{0,0,0,255}
|
||||
self.Colors["White"] = &color.Color{255, 255, 255, 255}
|
||||
self.Colors["Black"] = &color.Color{0, 0, 0, 255}
|
||||
|
||||
fname := sysgo.SKIN+"/config.ini"
|
||||
fname := sysgo.SKIN + "/config.ini"
|
||||
|
||||
load_opts := ini.LoadOptions{
|
||||
IgnoreInlineComment:true,
|
||||
IgnoreInlineComment: true,
|
||||
}
|
||||
cfg, err := ini.LoadSources(load_opts, fname )
|
||||
cfg, err := ini.LoadSources(load_opts, fname)
|
||||
if err != nil {
|
||||
fmt.Printf("Fail to read file: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
section := cfg.Section("Colors")
|
||||
if section != nil {
|
||||
colour_opts := section.KeyStrings()
|
||||
for _,v := range colour_opts {
|
||||
for _, v := range colour_opts {
|
||||
if _, ok := self.Colors[v]; ok { // has this Color key
|
||||
parsed_color := self.ConvertToRGB( section.Key(v).String() )
|
||||
parsed_color := self.ConvertToRGB(section.Key(v).String())
|
||||
if parsed_color != nil {
|
||||
self.Colors[v] = parsed_color
|
||||
}
|
||||
@@ -89,13 +86,12 @@ func (self *SkinManager) Init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (self *SkinManager) GiveColor(name string) *color.Color {
|
||||
|
||||
if val,ok := self.Colors[name]; ok {
|
||||
if val, ok := self.Colors[name]; ok {
|
||||
return val
|
||||
}else {
|
||||
return &color.Color{255,0,0,255}
|
||||
} else {
|
||||
return &color.Color{255, 0, 0, 255}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,67 +2,65 @@ package UI
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
//"math"
|
||||
//"math"
|
||||
//"sync"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
//"github.com/cuu/gogame/surface"
|
||||
//"github.com/cuu/gogame/draw"
|
||||
//"github.com/cuu/gogame/rect"
|
||||
//"github.com/cuu/gogame/font"
|
||||
//"github.com/cuu/gogame/rect"
|
||||
//"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/event"
|
||||
|
||||
//"github.com/cuu/gogame/transform"
|
||||
//"github.com/clockworkpi/LauncherGoDev/sysgo/easings"
|
||||
|
||||
)
|
||||
|
||||
type SliderInterface interface {
|
||||
WidgetInterface
|
||||
|
||||
Init()
|
||||
SetValue()
|
||||
SetRange(m1,m2 int)
|
||||
SetCanvasHWND( canvas *sdl.Surface)
|
||||
KeyDown(ev *event.Event)
|
||||
Draw()
|
||||
WidgetInterface
|
||||
|
||||
Init()
|
||||
SetValue()
|
||||
SetRange(m1, m2 int)
|
||||
SetCanvasHWND(canvas *sdl.Surface)
|
||||
KeyDown(ev *event.Event)
|
||||
Draw()
|
||||
}
|
||||
|
||||
type Slider struct {
|
||||
Widget
|
||||
|
||||
Value int
|
||||
|
||||
CanvasHWND *sdl.Surface
|
||||
|
||||
Range [2]int
|
||||
Widget
|
||||
|
||||
Value int
|
||||
|
||||
CanvasHWND *sdl.Surface
|
||||
|
||||
Range [2]int
|
||||
}
|
||||
|
||||
func NewSlider() *Slider {
|
||||
p := &Slider{}
|
||||
p.Range = [2]int{0,255}
|
||||
p.Value = 0
|
||||
return p
|
||||
p := &Slider{}
|
||||
p.Range = [2]int{0, 255}
|
||||
p.Value = 0
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *Slider) Init() {
|
||||
self.Value = 0
|
||||
self.Value = 0
|
||||
}
|
||||
|
||||
func (self *Slider) SetValue(v int) {
|
||||
self.Value = v
|
||||
self.Value = v
|
||||
}
|
||||
|
||||
func (self *Slider) SetRange(m1 ,m2 int) {
|
||||
if m1 >= m2 {
|
||||
return
|
||||
}
|
||||
self.Range[0] = m1
|
||||
self.Range[1] = m2
|
||||
func (self *Slider) SetRange(m1, m2 int) {
|
||||
if m1 >= m2 {
|
||||
return
|
||||
}
|
||||
self.Range[0] = m1
|
||||
self.Range[1] = m2
|
||||
}
|
||||
|
||||
func (self *Slider) SetCanvasHWND( canvas *sdl.Surface) {
|
||||
func (self *Slider) SetCanvasHWND(canvas *sdl.Surface) {
|
||||
self.CanvasHWND = canvas
|
||||
}
|
||||
|
||||
@@ -70,5 +68,5 @@ func (self *Slider) KeyDown(ev *event.Event) {
|
||||
}
|
||||
|
||||
func (self *Slider) Draw() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,124 +1,120 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/itchyny/volume-go"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/rect"
|
||||
//"github.com/cuu/gogame/color"
|
||||
"log"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/itchyny/volume-go"
|
||||
//"github.com/cuu/gogame/color"
|
||||
)
|
||||
|
||||
type SoundPatch struct {
|
||||
AboveAllPatch
|
||||
|
||||
snd_segs [][2]int
|
||||
Needle int
|
||||
Parent *MainScreen
|
||||
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
|
||||
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)
|
||||
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, err := volume.GetVolume()
|
||||
if err != nil {
|
||||
log.Printf("SoundPatch VolumeUp get volume failed: %+v", err)
|
||||
vol = 0
|
||||
}
|
||||
|
||||
for i,v := range self.snd_segs {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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, 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 {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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"))
|
||||
}
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +1,39 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/draw"
|
||||
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
type TextItemInterface interface{
|
||||
|
||||
IconItemInterface
|
||||
|
||||
type TextItemInterface interface {
|
||||
IconItemInterface
|
||||
|
||||
GetBold() bool
|
||||
SetBold(bold bool)
|
||||
GetStr() string
|
||||
|
||||
}
|
||||
|
||||
|
||||
type TextItem struct {
|
||||
IconItem
|
||||
Str string
|
||||
Color *color.Color
|
||||
Str string
|
||||
Color *color.Color
|
||||
FontObj *ttf.Font
|
||||
Bold bool
|
||||
Bold bool
|
||||
}
|
||||
|
||||
func NewTextItem() *TextItem {
|
||||
p := &TextItem{}
|
||||
|
||||
|
||||
p.Align = ALIGN["VCenter"]
|
||||
|
||||
p.Color = &color.Color{83,83,83,255}
|
||||
|
||||
p.Color = &color.Color{83, 83, 83, 255}
|
||||
p.MyType = ICON_TYPES["LETTER"]
|
||||
p.Bold = false
|
||||
|
||||
p.Bold = false
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -55,20 +50,19 @@ func (self *TextItem) GetStr() string {
|
||||
}
|
||||
|
||||
func (self *TextItem) Draw() {
|
||||
font.SetBold(self.FontObj,self.Bold)
|
||||
font.SetBold(self.FontObj, self.Bold)
|
||||
|
||||
my_text := font.Render(self.FontObj,self.Str,true,self.Color,nil)
|
||||
my_text := font.Render(self.FontObj, self.Str, true, self.Color, nil)
|
||||
|
||||
if surface.GetWidth(my_text) != self.Width {
|
||||
self.Width = surface.GetWidth(my_text)
|
||||
}
|
||||
|
||||
|
||||
if surface.GetHeight(my_text) != self.Height {
|
||||
self.Height = surface.GetHeight(my_text)
|
||||
}
|
||||
|
||||
|
||||
rect_ := draw.MidRect(self.PosX,self.PosY,self.Width,self.Height,Width,Height)
|
||||
surface.Blit(self.Parent.GetCanvasHWND(),my_text,rect_,nil)
|
||||
rect_ := draw.MidRect(self.PosX, self.PosY, self.Width, self.Height, Width, Height)
|
||||
surface.Blit(self.Parent.GetCanvasHWND(), my_text, rect_, nil)
|
||||
my_text.Free()
|
||||
}
|
||||
|
||||
@@ -3,29 +3,29 @@ package UI
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
type Textarea struct {
|
||||
Widget
|
||||
BackgroundColor *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
MyWords []string
|
||||
BlitWords []string
|
||||
FontObj *ttf.Font
|
||||
LineNumber int
|
||||
TextLimit int
|
||||
TextFull bool
|
||||
TextIndex int
|
||||
BlitIndex int
|
||||
CanvasHWND *sdl.Surface
|
||||
MyWords []string
|
||||
BlitWords []string
|
||||
FontObj *ttf.Font
|
||||
LineNumber int
|
||||
TextLimit int
|
||||
TextFull bool
|
||||
TextIndex int
|
||||
BlitIndex int
|
||||
}
|
||||
|
||||
func NewTextarea() *Textarea {
|
||||
@@ -34,11 +34,11 @@ func NewTextarea() *Textarea {
|
||||
p.TextLimit = 63
|
||||
p.TextFull = false
|
||||
|
||||
p.MyWords = make([]string,0)
|
||||
p.BlitWords = make([]string,0)
|
||||
p.MyWords = make([]string, 0)
|
||||
p.BlitWords = make([]string, 0)
|
||||
|
||||
p.BackgroundColor = &color.Color{228, 228, 228, 255}
|
||||
|
||||
p.BackgroundColor = &color.Color{228,228,228,255}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (self *Textarea) AddTextIndex() {
|
||||
self.TextIndex += 1
|
||||
if self.TextIndex > len(self.MyWords) {
|
||||
self.TextIndex = len(self.MyWords)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Textarea) ResetMyWords() {
|
||||
@@ -70,84 +70,82 @@ func (self *Textarea) RemoveFromLastText() []string {
|
||||
if len(self.MyWords) > 0 {
|
||||
self.SubTextIndex()
|
||||
if self.TextIndex < len(self.MyWords) {
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex],self.MyWords[(self.TextIndex+1):]...)
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex], self.MyWords[(self.TextIndex+1):]...)
|
||||
}
|
||||
}
|
||||
|
||||
return self.MyWords
|
||||
}
|
||||
|
||||
|
||||
func (self *Textarea) AppendText( alphabet string) {
|
||||
func (self *Textarea) AppendText(alphabet string) {
|
||||
self.AppendAndBlitText(alphabet)
|
||||
}
|
||||
|
||||
func (self *Textarea) AppendAndBlitText(alphabet string) {
|
||||
if self.TextFull == false {
|
||||
|
||||
|
||||
if self.TextIndex <= len(self.MyWords) {
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex],
|
||||
append([]string{alphabet},self.MyWords[self.TextIndex:]...)...)
|
||||
|
||||
append([]string{alphabet}, self.MyWords[self.TextIndex:]...)...)
|
||||
|
||||
self.BlitText()
|
||||
self.AddTextIndex()
|
||||
}
|
||||
|
||||
}else {
|
||||
fmt.Printf("is Full %s\n",strings.Join(self.MyWords,""))
|
||||
|
||||
} else {
|
||||
fmt.Printf("is Full %s\n", strings.Join(self.MyWords, ""))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Textarea) BuildBlitText() {
|
||||
blit_rows := make([][]string,0)
|
||||
blit_rows = append(blit_rows,[]string{})
|
||||
|
||||
w := 0
|
||||
// xmargin := 5
|
||||
endmargin :=15
|
||||
blit_rows := make([][]string, 0)
|
||||
blit_rows = append(blit_rows, []string{})
|
||||
|
||||
w := 0
|
||||
// xmargin := 5
|
||||
endmargin := 15
|
||||
linenumber := 0
|
||||
cursor_row := 0
|
||||
|
||||
|
||||
for i,v := range self.MyWords {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for i, v := range self.MyWords {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
t_width := surface.GetWidth(t)
|
||||
w+=t_width
|
||||
w += t_width
|
||||
|
||||
blit_rows[linenumber] = append(blit_rows[linenumber],v)
|
||||
blit_rows[linenumber] = append(blit_rows[linenumber], v)
|
||||
|
||||
if i == self.TextIndex - 1 {
|
||||
if i == self.TextIndex-1 {
|
||||
cursor_row = linenumber
|
||||
}
|
||||
|
||||
if w + t_width >= self.Width - endmargin {
|
||||
if w+t_width >= self.Width-endmargin {
|
||||
w = 0
|
||||
linenumber += 1
|
||||
blit_rows = append(blit_rows,[]string{})
|
||||
blit_rows = append(blit_rows, []string{})
|
||||
}
|
||||
t.Free()
|
||||
t.Free()
|
||||
}
|
||||
|
||||
if len(blit_rows) == 1 {
|
||||
self.BlitWords = blit_rows[0]
|
||||
self.BlitIndex = self.TextIndex
|
||||
}else if len(blit_rows) == 2 || cursor_row < 2 {
|
||||
} else if len(blit_rows) == 2 || cursor_row < 2 {
|
||||
self.BlitWords = append(blit_rows[0], blit_rows[1]...)
|
||||
self.BlitIndex = self.TextIndex
|
||||
|
||||
}else {
|
||||
|
||||
} else {
|
||||
self.BlitWords = append(blit_rows[cursor_row-1], blit_rows[cursor_row]...)
|
||||
self.BlitIndex = self.TextIndex
|
||||
|
||||
for i,v := range blit_rows {
|
||||
if i == cursor_row - 1 {
|
||||
for i, v := range blit_rows {
|
||||
if i == cursor_row-1 {
|
||||
break
|
||||
}
|
||||
self.BlitIndex -= len(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Textarea) BlitText() {
|
||||
@@ -165,23 +163,23 @@ func (self *Textarea) BlitText() {
|
||||
|
||||
if len(self.MyWords) > self.TextLimit {
|
||||
self.TextFull = true
|
||||
}else {
|
||||
} else {
|
||||
self.TextFull = false
|
||||
}
|
||||
|
||||
for _,v := range self.BlitWords {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for _, v := range self.BlitWords {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
w += surface.GetWidth(t)
|
||||
|
||||
if w >= self.Width - endmargin && linenumber == 0 {
|
||||
if w >= self.Width-endmargin && linenumber == 0 {
|
||||
linenumber += 1
|
||||
x = self.PosX + xmargin
|
||||
y = self.PosY + surface.GetHeight(t) * linenumber
|
||||
y = self.PosY + surface.GetHeight(t)*linenumber
|
||||
w = 0
|
||||
}
|
||||
|
||||
rect_ := rect.Rect(x,y,0,0)
|
||||
surface.Blit(self.CanvasHWND,t,&rect_,nil)
|
||||
rect_ := rect.Rect(x, y, 0, 0)
|
||||
surface.Blit(self.CanvasHWND, t, &rect_, nil)
|
||||
x += surface.GetWidth(t)
|
||||
t.Free()
|
||||
}
|
||||
@@ -191,42 +189,42 @@ func (self *Textarea) Cursor() {
|
||||
w := 0
|
||||
xmargin := 5
|
||||
endmargin := 15
|
||||
x := self.PosX+xmargin
|
||||
x := self.PosX + xmargin
|
||||
y := self.PosY
|
||||
linenumber := 0
|
||||
|
||||
for _,v := range self.BlitWords[:self.BlitIndex] {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for _, v := range self.BlitWords[:self.BlitIndex] {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
w += surface.GetWidth(t)
|
||||
|
||||
if w >= self.Width - endmargin && linenumber == 0 {
|
||||
if w >= self.Width-endmargin && linenumber == 0 {
|
||||
x = self.PosX + xmargin
|
||||
y = self.PosY + surface.GetHeight(t)
|
||||
w = 0
|
||||
linenumber +=1
|
||||
linenumber += 1
|
||||
}
|
||||
|
||||
if w >= self.Width - endmargin*3 && linenumber > 0 {
|
||||
if w >= self.Width-endmargin*3 && linenumber > 0 {
|
||||
x += surface.GetWidth(t)
|
||||
break
|
||||
}
|
||||
x += surface.GetWidth(t)
|
||||
t.Free()
|
||||
t.Free()
|
||||
}
|
||||
|
||||
c_t := font.Render(self.FontObj,"_",true,&color.Color{0,0,0,255},nil)
|
||||
rect_ := rect.Rect(x+1,y-2,0,0)
|
||||
surface.Blit(self.CanvasHWND,c_t,&rect_,nil)
|
||||
c_t.Free()
|
||||
c_t := font.Render(self.FontObj, "_", true, &color.Color{0, 0, 0, 255}, nil)
|
||||
rect_ := rect.Rect(x+1, y-2, 0, 0)
|
||||
surface.Blit(self.CanvasHWND, c_t, &rect_, nil)
|
||||
c_t.Free()
|
||||
}
|
||||
|
||||
func (self *Textarea) Draw() {
|
||||
|
||||
rect_:= rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||
|
||||
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
|
||||
|
||||
self.BlitText()
|
||||
self.Cursor()
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
"strconv"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"os/exec"
|
||||
"io/ioutil"
|
||||
gotime "time"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/font"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/itchyny/volume-go"
|
||||
|
||||
|
||||
"github.com/vjeantet/jodaTime"
|
||||
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
var TitleBar_BarHeight = 24
|
||||
|
||||
type TitleBarIconItem struct {
|
||||
@@ -45,7 +42,7 @@ func NewTitleBarIconItem() *TitleBarIconItem {
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBarIconItem) Adjust(x,y,w,h,at int) {
|
||||
func (self *TitleBarIconItem) Adjust(x, y, w, h, at int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Width = w
|
||||
@@ -57,62 +54,60 @@ func (self *TitleBarIconItem) Adjust(x,y,w,h,at int) {
|
||||
}
|
||||
|
||||
self.CreateImgSurf()
|
||||
// self.AdjustLinkPage()
|
||||
|
||||
// self.AdjustLinkPage()
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBarIconItem) Draw() {
|
||||
parent_x,parent_y := self.Parent.PosX,self.Parent.PosY
|
||||
|
||||
parent_x, parent_y := self.Parent.PosX, self.Parent.PosY
|
||||
|
||||
if self.Label != nil {
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w,lab_h:= self.Label.Size()
|
||||
// lab_x,lab_y := self.Label.Coord()
|
||||
lab_w, lab_h := self.Label.Size()
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6 + parent_y)
|
||||
}else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord( self.PosX + self.Width/2+3 + parent_x, self.PosY - lab_h/2 + parent_y )
|
||||
self.Label.NewCoord(self.PosX-lab_w/2+parent_x, self.PosY+self.Height/2+6+parent_y)
|
||||
} else if self.Align == ALIGN["HLeft"] {
|
||||
self.Label.NewCoord(self.PosX+self.Width/2+3+parent_x, self.PosY-lab_h/2+parent_y)
|
||||
}
|
||||
|
||||
self.Label.Draw()
|
||||
}
|
||||
|
||||
if self.ImgSurf != nil {
|
||||
|
||||
portion := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
|
||||
|
||||
|
||||
portion := rect.Rect(0, self.IconIndex*self.IconHeight, self.IconWidth, self.IconHeight)
|
||||
|
||||
surface.Blit(self.Parent.CanvasHWND,
|
||||
self.ImgSurf,draw.MidRect(self.PosX + parent_x, self.PosY + parent_y,
|
||||
self.Width,self.Height, Width, Height),&portion)
|
||||
self.ImgSurf, draw.MidRect(self.PosX+parent_x, self.PosY+parent_y,
|
||||
self.Width, self.Height, Width, Height), &portion)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type TitleBar struct {
|
||||
Widget
|
||||
BarHeight int
|
||||
LOffset int
|
||||
ROffset int
|
||||
Icons map[string]IconItemInterface
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
BorderWidth int
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
Title string
|
||||
|
||||
InLowBackLight int
|
||||
InAirPlaneMode bool
|
||||
|
||||
SkinManager *SkinManager //set by MainScreen
|
||||
|
||||
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
||||
|
||||
MyTimeLocation *gotime.Location
|
||||
|
||||
TitleFont *ttf.Font
|
||||
TimeFont *ttf.Font
|
||||
}
|
||||
Widget
|
||||
BarHeight int
|
||||
LOffset int
|
||||
ROffset int
|
||||
Icons map[string]IconItemInterface
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
BorderWidth int
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
Title string
|
||||
|
||||
InLowBackLight int
|
||||
InAirPlaneMode bool
|
||||
|
||||
SkinManager *SkinManager //set by MainScreen
|
||||
|
||||
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
||||
|
||||
MyTimeLocation *gotime.Location
|
||||
|
||||
TitleFont *ttf.Font
|
||||
TimeFont *ttf.Font
|
||||
}
|
||||
|
||||
func NewTitleBar() *TitleBar {
|
||||
t := &TitleBar{}
|
||||
@@ -129,58 +124,58 @@ func NewTitleBar() *TitleBar {
|
||||
|
||||
t.LOffset = 3
|
||||
t.ROffset = 3
|
||||
|
||||
|
||||
t.Icons = make(map[string]IconItemInterface)
|
||||
|
||||
t.icon_base_path = SkinMap("sysgo/gameshell/titlebar_icons/")
|
||||
|
||||
t.icon_base_path = SkinMap("sysgo/gameshell/titlebar_icons/")
|
||||
|
||||
t.TitleFont = Fonts["varela16"]
|
||||
t.TimeFont = Fonts["varela12"]
|
||||
|
||||
t.InLowBackLight = -1
|
||||
t.TimeFont = Fonts["varela12"]
|
||||
|
||||
t.InLowBackLight = -1
|
||||
return t
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) RoundRobinCheck() {
|
||||
for {
|
||||
|
||||
if self.InLowBackLight < 0 {
|
||||
self.CheckBatteryStat()
|
||||
self.CheckBluetooth()
|
||||
self.UpdateWifiStrength()
|
||||
SwapAndShow()
|
||||
|
||||
}else if self.InLowBackLight >= 0 {
|
||||
self.InLowBackLight +=1
|
||||
|
||||
if self.InLowBackLight > 10 {
|
||||
self.CheckBatteryStat()
|
||||
self.CheckBluetooth()
|
||||
self.UpdateWifiStrength()
|
||||
|
||||
self.InLowBackLight = 0 // reset
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
gotime.Sleep(3000 * gotime.Millisecond)
|
||||
|
||||
}
|
||||
if self.InLowBackLight < 0 {
|
||||
self.CheckBatteryStat()
|
||||
self.CheckBluetooth()
|
||||
self.UpdateWifiStrength()
|
||||
SwapAndShow()
|
||||
|
||||
} else if self.InLowBackLight >= 0 {
|
||||
self.InLowBackLight += 1
|
||||
|
||||
if self.InLowBackLight > 10 {
|
||||
self.CheckBatteryStat()
|
||||
self.CheckBluetooth()
|
||||
self.UpdateWifiStrength()
|
||||
|
||||
self.InLowBackLight = 0 // reset
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
gotime.Sleep(3000 * gotime.Millisecond)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (self *TitleBar) IsWifiConnectedNow() bool {
|
||||
cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if(len(out) > 7) {
|
||||
if strings.Contains(out,"not") {
|
||||
return false
|
||||
}else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out) > 7 {
|
||||
if strings.Contains(out, "not") {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
@@ -189,51 +184,51 @@ func (self *TitleBar) UpdateWifiStrength() {
|
||||
}
|
||||
|
||||
func (t *TitleBar) GetWifiStrength() int {
|
||||
qua := 0
|
||||
cli := fmt.Sprintf("iwconfig %s | grep Signal | /usr/bin/awk '{print $4}' | /usr/bin/cut -d'=' -f2",sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if(len(out) > 2) {
|
||||
if strings.Contains(out,"No") == false {
|
||||
out = strings.TrimSuffix(out, "\n")
|
||||
stren,err := strconv.ParseInt(out, 10, 0)
|
||||
if err == nil {
|
||||
qua = 2 * (int(stren) + 100)
|
||||
}else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
qua := 0
|
||||
cli := fmt.Sprintf("iwconfig %s | grep Signal | /usr/bin/awk '{print $4}' | /usr/bin/cut -d'=' -f2", sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out) > 2 {
|
||||
if strings.Contains(out, "No") == false {
|
||||
out = strings.TrimSuffix(out, "\n")
|
||||
stren, err := strconv.ParseInt(out, 10, 0)
|
||||
if err == nil {
|
||||
qua = 2 * (int(stren) + 100)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
segs := [][]int{ []int{-2,-1}, []int{0,25}, []int{25,50}, []int{50,75},[]int{75,100}}
|
||||
stren_number := qua
|
||||
segs := [][]int{[]int{-2, -1}, []int{0, 25}, []int{25, 50}, []int{50, 75}, []int{75, 100}}
|
||||
stren_number := qua
|
||||
ge := 0
|
||||
if stren_number == 0 {
|
||||
return ge
|
||||
}
|
||||
|
||||
for i,v := range segs {
|
||||
|
||||
for i, v := range segs {
|
||||
if stren_number >= v[0] && stren_number <= v[1] {
|
||||
ge = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ge
|
||||
return ge
|
||||
}
|
||||
|
||||
func (self *TitleBar) SyncSoundVolume() {
|
||||
|
||||
vol, err := volume.GetVolume()
|
||||
if err != nil {
|
||||
log.Printf("TitleBar SyncSoundVolume get volume failed: %+v\n", err)
|
||||
vol = 0
|
||||
}
|
||||
fmt.Printf("TitleBar SyncSoundVolume current volume: %d\n", vol)
|
||||
|
||||
snd_segs := [][]int{ []int{0,10}, []int{10,30}, []int{30,70},[]int{70,100} }
|
||||
vol, err := volume.GetVolume()
|
||||
if err != nil {
|
||||
log.Printf("TitleBar SyncSoundVolume get volume failed: %+v\n", err)
|
||||
vol = 0
|
||||
}
|
||||
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
|
||||
|
||||
for i,v := range snd_segs {
|
||||
for i, v := range snd_segs {
|
||||
if vol >= v[0] && vol <= v[1] {
|
||||
ge = i
|
||||
break
|
||||
@@ -242,16 +237,16 @@ func (self *TitleBar) SyncSoundVolume() {
|
||||
|
||||
self.Icons["soundvolume"].SetIconIndex(ge)
|
||||
self.Icons["sound"] = self.Icons["soundvolume"]
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
// for outside widget to update sound icon
|
||||
func (self *TitleBar) SetSoundVolume(vol int) {
|
||||
|
||||
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
|
||||
|
||||
for i,v := range snd_segs {
|
||||
for i, v := range snd_segs {
|
||||
if vol >= v[0] && vol <= v[1] {
|
||||
ge = i
|
||||
break
|
||||
@@ -259,19 +254,19 @@ func (self *TitleBar) SetSoundVolume(vol int) {
|
||||
}
|
||||
|
||||
self.Icons["soundvolume"].SetIconIndex(ge)
|
||||
self.Icons["sound"] = self.Icons["soundvolume"]
|
||||
self.Icons["sound"] = self.Icons["soundvolume"]
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) CheckBatteryStat() {
|
||||
bat_segs:= [][]int{[]int{0,6},[]int{7,15},[]int{16,20},[]int{21,30},[]int{31,50},[]int{51,60},[]int{61,80},[]int{81,90},[]int{91,100}}
|
||||
|
||||
if FileExists(sysgo.Battery) == false {
|
||||
self.Icons["battery"] = self.Icons["battery_unknown"]
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Open( sysgo.Battery )
|
||||
bat_segs := [][]int{[]int{0, 6}, []int{7, 15}, []int{16, 20}, []int{21, 30}, []int{31, 50}, []int{51, 60}, []int{61, 80}, []int{81, 90}, []int{91, 100}}
|
||||
|
||||
if FileExists(sysgo.Battery) == false {
|
||||
self.Icons["battery"] = self.Icons["battery_unknown"]
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Open(sysgo.Battery)
|
||||
if err != nil {
|
||||
fmt.Println("Could not open file ", sysgo.Battery)
|
||||
self.Icons["battery"] = self.Icons["battery_unknown"]
|
||||
@@ -281,30 +276,30 @@ func (self *TitleBar) CheckBatteryStat() {
|
||||
defer file.Close()
|
||||
|
||||
bat_uevent := make(map[string]string)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line = strings.Trim(line," ")
|
||||
pis := strings.Split(line,"=")
|
||||
line = strings.Trim(line, " ")
|
||||
pis := strings.Split(line, "=")
|
||||
if len(pis) > 1 {
|
||||
bat_uevent[ pis[0] ] = pis[1]
|
||||
bat_uevent[pis[0]] = pis[1]
|
||||
}
|
||||
}
|
||||
|
||||
cur_cap := 0
|
||||
|
||||
|
||||
if val, ok := bat_uevent["POWER_SUPPLY_CAPACITY"]; ok {
|
||||
cur_cap,_ = strconv.Atoi(val)
|
||||
}else {
|
||||
cur_cap, _ = strconv.Atoi(val)
|
||||
} else {
|
||||
cur_cap = 0
|
||||
}
|
||||
|
||||
cap_ge := 0
|
||||
|
||||
for i,v := range bat_segs {
|
||||
for i, v := range bat_segs {
|
||||
if cur_cap >= v[0] && cur_cap <= v[1] {
|
||||
cap_ge = i
|
||||
break
|
||||
@@ -315,78 +310,78 @@ func (self *TitleBar) CheckBatteryStat() {
|
||||
if val == "Charging" {
|
||||
self.Icons["battery_charging"].SetIconIndex(cap_ge)
|
||||
self.Icons["battery"] = self.Icons["battery_charging"]
|
||||
}else {
|
||||
} else {
|
||||
self.Icons["battery_discharging"].SetIconIndex(cap_ge)
|
||||
self.Icons["battery"] = self.Icons["battery_discharging"]
|
||||
self.Icons["battery"] = self.Icons["battery_discharging"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) SetBatteryStat( bat int) {
|
||||
|
||||
func (self *TitleBar) SetBatteryStat(bat int) {
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) CheckBluetooth() {
|
||||
|
||||
out := System("hcitool dev | grep hci0 |cut -f3")
|
||||
|
||||
if len(out) < 17 {
|
||||
fmt.Println("Titlebar CheckBluetooth: no bluetooth",out)
|
||||
self.Icons["bluetooth"].SetIconIndex(2)
|
||||
return
|
||||
}else {
|
||||
out = System("sudo rfkill list | grep hci0 -A 2 | grep yes")
|
||||
if len(out) > 10 {
|
||||
self.Icons["bluetooth"].SetIconIndex(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
self.Icons["bluetooth"].SetIconIndex(0)
|
||||
|
||||
out := System("hcitool dev | grep hci0 |cut -f3")
|
||||
|
||||
if len(out) < 17 {
|
||||
fmt.Println("Titlebar CheckBluetooth: no bluetooth", out)
|
||||
self.Icons["bluetooth"].SetIconIndex(2)
|
||||
return
|
||||
} else {
|
||||
out = System("sudo rfkill list | grep hci0 -A 2 | grep yes")
|
||||
if len(out) > 10 {
|
||||
self.Icons["bluetooth"].SetIconIndex(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
self.Icons["bluetooth"].SetIconIndex(0)
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) Init(main_screen *MainScreen) {
|
||||
|
||||
start_x := 0
|
||||
|
||||
self.CanvasHWND = surface.Surface(self.Width,self.Height)
|
||||
self.CanvasHWND = surface.Surface(self.Width, self.Height)
|
||||
self.HWND = main_screen.HWND
|
||||
self.SkinManager = main_screen.SkinManager
|
||||
|
||||
|
||||
icon_wifi_status := NewTitleBarIconItem()
|
||||
|
||||
icon_wifi_status.MyType = ICON_TYPES["STAT"]
|
||||
icon_wifi_status.ImageName = self.icon_base_path+"wifi.png"
|
||||
icon_wifi_status.ImageName = self.icon_base_path + "wifi.png"
|
||||
icon_wifi_status.Parent = self
|
||||
|
||||
icon_wifi_status.Adjust(start_x+self.IconWidth+5,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
icon_wifi_status.Adjust(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["wifistatus"] = icon_wifi_status
|
||||
|
||||
battery_charging := NewTitleBarIconItem()
|
||||
battery_charging.MyType = ICON_TYPES["STAT"]
|
||||
battery_charging.Parent = self
|
||||
battery_charging.ImageName = self.icon_base_path+"withcharging.png"
|
||||
battery_charging.Adjust(start_x+self.IconWidth+self.IconWidth+8,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
battery_charging.ImageName = self.icon_base_path + "withcharging.png"
|
||||
battery_charging.Adjust(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["battery_charging"] = battery_charging
|
||||
|
||||
battery_discharging := NewTitleBarIconItem()
|
||||
battery_discharging.MyType = ICON_TYPES["STAT"]
|
||||
battery_discharging.Parent = self
|
||||
battery_discharging.ImageName = self.icon_base_path+"without_charging.png"
|
||||
battery_discharging.Adjust(start_x+self.IconWidth+self.IconWidth+8,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
battery_discharging.ImageName = self.icon_base_path + "without_charging.png"
|
||||
battery_discharging.Adjust(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["battery_discharging"] = battery_discharging
|
||||
|
||||
battery_unknown := NewTitleBarIconItem()
|
||||
battery_unknown := NewTitleBarIconItem()
|
||||
battery_unknown.MyType = ICON_TYPES["STAT"]
|
||||
battery_unknown.Parent = self
|
||||
battery_unknown.ImageName = self.icon_base_path+"battery_unknown.png"
|
||||
battery_unknown.Adjust(start_x+self.IconWidth+self.IconWidth+8,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
|
||||
battery_unknown.ImageName = self.icon_base_path + "battery_unknown.png"
|
||||
battery_unknown.Adjust(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["battery_unknown"] = battery_unknown
|
||||
|
||||
self.CheckBatteryStat()
|
||||
@@ -394,117 +389,114 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
|
||||
sound_volume := NewTitleBarIconItem()
|
||||
sound_volume.MyType = ICON_TYPES["STAT"]
|
||||
sound_volume.Parent = self
|
||||
sound_volume.ImageName = self.icon_base_path+"soundvolume.png"
|
||||
sound_volume.Adjust(start_x+self.IconWidth+self.IconWidth+8,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
sound_volume.ImageName = self.icon_base_path + "soundvolume.png"
|
||||
sound_volume.Adjust(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["soundvolume"] = sound_volume
|
||||
|
||||
self.SyncSoundVolume()
|
||||
|
||||
bluetooth := NewTitleBarIconItem()
|
||||
bluetooth.MyType = ICON_TYPES["STAT"]
|
||||
bluetooth.Parent = self
|
||||
bluetooth.ImageName = self.icon_base_path+"bluetooth.png"
|
||||
bluetooth.Adjust(start_x+self.IconWidth+self.IconWidth+8,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2,self.IconWidth,self.IconHeight,0)
|
||||
|
||||
self.Icons["bluetooth"] = bluetooth
|
||||
self.CheckBluetooth()
|
||||
bluetooth := NewTitleBarIconItem()
|
||||
bluetooth.MyType = ICON_TYPES["STAT"]
|
||||
bluetooth.Parent = self
|
||||
bluetooth.ImageName = self.icon_base_path + "bluetooth.png"
|
||||
bluetooth.Adjust(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2, self.IconWidth, self.IconHeight, 0)
|
||||
|
||||
self.Icons["bluetooth"] = bluetooth
|
||||
self.CheckBluetooth()
|
||||
|
||||
round_corners := NewTitleBarIconItem()
|
||||
round_corners.IconWidth = 10
|
||||
round_corners.IconHeight = 10
|
||||
|
||||
|
||||
round_corners.MyType = ICON_TYPES["STAT"]
|
||||
round_corners.Parent = self
|
||||
round_corners.ImgSurf = MyIconPool.GetImgSurf("roundcorners")
|
||||
round_corners.Adjust(0,0,10,10,0)
|
||||
|
||||
round_corners.Adjust(0, 0, 10, 10, 0)
|
||||
|
||||
self.Icons["round_corners"] = round_corners
|
||||
|
||||
if self.IsWifiConnectedNow() {
|
||||
print("wifi is connected")
|
||||
}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
|
||||
}
|
||||
}
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.UpdateTimeLocation()
|
||||
|
||||
}
|
||||
|
||||
self.UpdateTimeLocation()
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) ClearCanvas() {
|
||||
surface.Fill(self.CanvasHWND, self.SkinManager.GiveColor("TitleBg"))
|
||||
|
||||
self.Icons["round_corners"].NewCoord(5,5)
|
||||
self.Icons["round_corners"].NewCoord(5, 5)
|
||||
self.Icons["round_corners"].SetIconIndex(0)
|
||||
self.Icons["round_corners"].Draw()
|
||||
|
||||
self.Icons["round_corners"].NewCoord(self.Width-5, 5)
|
||||
self.Icons["round_corners"].SetIconIndex(1)
|
||||
self.Icons["round_corners"].Draw()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) UpdateTimeLocation() {
|
||||
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
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
|
||||
|
||||
cur_time := jodaTime.Format("HH:mm", self.GetLocalTime())
|
||||
|
||||
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_surf := font.Render(self.TitleFont, self.Title, true, self.SkinManager.GiveColor("Text"),nil)
|
||||
|
||||
surface.Blit(self.CanvasHWND,title_text_surf, draw.MidRect(title_text_w/2+self.LOffset,title_text_h/2+(self.BarHeight-title_text_h)/2,title_text_w,title_text_h,Width,Height),nil)
|
||||
title_text_surf.Free()
|
||||
title_text_surf := font.Render(self.TitleFont, self.Title, true, self.SkinManager.GiveColor("Text"), nil)
|
||||
|
||||
surface.Blit(self.CanvasHWND, title_text_surf, draw.MidRect(title_text_w/2+self.LOffset, title_text_h/2+(self.BarHeight-title_text_h)/2, title_text_w, title_text_h, Width, Height), nil)
|
||||
title_text_surf.Free()
|
||||
|
||||
time_text_surf := font.Render(self.TimeFont, cur_time, true, self.SkinManager.GiveColor("Text"), nil)
|
||||
surface.Blit(self.CanvasHWND, time_text_surf, draw.MidRect(Width-time_text_w/2-self.ROffset, time_text_h/2+(self.BarHeight-time_text_h)/2, time_text_w, time_text_h, Width, Height), nil)
|
||||
|
||||
time_text_surf.Free()
|
||||
|
||||
time_text_surf := font.Render(self.TimeFont, cur_time,true,self.SkinManager.GiveColor("Text"),nil)
|
||||
surface.Blit(self.CanvasHWND, time_text_surf, draw.MidRect(Width-time_text_w/2-self.ROffset, time_text_h/2+(self.BarHeight-time_text_h)/2, time_text_w,time_text_h,Width,Height),nil)
|
||||
|
||||
time_text_surf.Free()
|
||||
|
||||
start_x := Width - time_text_w - self.ROffset - self.IconWidth*3 // close to the time_text
|
||||
|
||||
self.Icons["bluetooth"].NewCoord(start_x - self.IconWidth,self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
self.Icons["sound"].NewCoord( start_x, self.IconHeight/2+ (self.BarHeight-self.IconHeight)/2)
|
||||
|
||||
self.Icons["bluetooth"].NewCoord(start_x-self.IconWidth, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
self.Icons["sound"].NewCoord(start_x, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
self.Icons["battery"].NewCoord(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
|
||||
if self.IsWifiConnectedNow() == true {
|
||||
@@ -512,34 +504,31 @@ func (self *TitleBar) Draw(title string) {
|
||||
//fmt.Println("wifi ge: ",ge)
|
||||
if ge > 0 {
|
||||
self.Icons["wifistatus"].SetIconIndex(ge)
|
||||
self.Icons["wifistatus"].NewCoord(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2 )
|
||||
self.Icons["wifistatus"].NewCoord(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
self.Icons["wifistatus"].Draw()
|
||||
}else {
|
||||
} else {
|
||||
self.Icons["wifistatus"].SetIconIndex(0)
|
||||
self.Icons["wifistatus"].NewCoord(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2 )
|
||||
self.Icons["wifistatus"].NewCoord(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
self.Icons["wifistatus"].Draw()
|
||||
}
|
||||
}else {
|
||||
|
||||
} else {
|
||||
|
||||
self.Icons["wifistatus"].SetIconIndex(0)
|
||||
|
||||
|
||||
self.Icons["wifistatus"].NewCoord(start_x+self.IconWidth+5, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
|
||||
|
||||
self.Icons["wifistatus"].Draw()
|
||||
}
|
||||
|
||||
self.Icons["sound"].Draw()
|
||||
self.Icons["battery"].Draw()
|
||||
|
||||
self.Icons["bluetooth"].Draw()
|
||||
|
||||
draw.Line(self.CanvasHWND,self.SkinManager.GiveColor("Line"), 0,self.BarHeight,self.Width,self.BarHeight, self.BorderWidth)
|
||||
|
||||
self.Icons["bluetooth"].Draw()
|
||||
|
||||
draw.Line(self.CanvasHWND, self.SkinManager.GiveColor("Line"), 0, self.BarHeight, self.Width, self.BarHeight, self.BorderWidth)
|
||||
|
||||
if self.HWND != nil {
|
||||
rect_ := rect.Rect(self.PosX,self.PosY, self.Width,self.Height)
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,37 +2,36 @@ package UI
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
|
||||
type UntitledIcon struct {
|
||||
Widget
|
||||
Words []string
|
||||
FontObj *ttf.Font
|
||||
BG *sdl.Surface
|
||||
Color *color.Color
|
||||
Words []string
|
||||
FontObj *ttf.Font
|
||||
BG *sdl.Surface
|
||||
Color *color.Color
|
||||
BlankPng string
|
||||
Text *sdl.Surface
|
||||
Text *sdl.Surface
|
||||
}
|
||||
|
||||
func NewUntitledIcon() *UntitledIcon {
|
||||
u := &UntitledIcon{}
|
||||
u.Width = 80
|
||||
u.Height = 80
|
||||
u.Words = []string{"G","s"}
|
||||
u.Words = []string{"G", "s"}
|
||||
|
||||
u.FontObj = Fonts["varela40"]
|
||||
|
||||
u.Color = &color.Color{83,83,83,255}
|
||||
u.Color = &color.Color{83, 83, 83, 255}
|
||||
|
||||
u.BlankPng = SkinMap("sysgo/gameshell/blank.png")
|
||||
return u
|
||||
@@ -42,15 +41,15 @@ func (self *UntitledIcon) Init() {
|
||||
self.BG = image.Load(self.BlankPng)
|
||||
}
|
||||
|
||||
func (self *UntitledIcon) SetWords( TwoWords ...string) {
|
||||
func (self *UntitledIcon) SetWords(TwoWords ...string) {
|
||||
if len(TwoWords) == 1 {
|
||||
self.Words[0] = strings.ToUpper(TwoWords[0])
|
||||
}
|
||||
if len(TwoWords) == 2 {
|
||||
self.Words[0] = strings.ToUpper( TwoWords[0])
|
||||
self.Words[1] = strings.ToLower( TwoWords[1] )
|
||||
self.Words[0] = strings.ToUpper(TwoWords[0])
|
||||
self.Words[1] = strings.ToLower(TwoWords[1])
|
||||
|
||||
self.Text = font.Render(self.FontObj, strings.Join(self.Words,""),true,self.Color, nil)
|
||||
self.Text = font.Render(self.FontObj, strings.Join(self.Words, ""), true, self.Color, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +57,8 @@ func (self *UntitledIcon) Draw() {
|
||||
if self.BG != nil {
|
||||
w_ := self.Text.W
|
||||
h_ := self.Text.H
|
||||
|
||||
surface.Blit(self.BG,self.Text,draw.MidRect(self.Width/2, self.Height/2, int(w_),int(h_), self.Width, self.Height),nil)
|
||||
|
||||
surface.Blit(self.BG, self.Text, draw.MidRect(self.Width/2, self.Height/2, int(w_), int(h_), self.Width, self.Height), nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +66,3 @@ func (self *UntitledIcon) Surface() *sdl.Surface {
|
||||
self.Draw()
|
||||
return self.BG
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/cuu/gogame/display"
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
@@ -27,14 +27,14 @@ func ShowErr(e error) {
|
||||
|
||||
func Assert(e error) {
|
||||
if e != nil {
|
||||
log.Fatal("Assert: " , e)
|
||||
log.Fatal("Assert: ", e)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckAndPanic(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func Abs(n int) int {
|
||||
@@ -42,42 +42,41 @@ func Abs(n int) int {
|
||||
return (n ^ y) - y
|
||||
}
|
||||
|
||||
|
||||
func SkinMap(orig_file_or_dir string) string {
|
||||
DefaultSkin := "skin/default/"
|
||||
ret := ""
|
||||
|
||||
|
||||
if strings.HasPrefix(orig_file_or_dir, "/home/cpi/apps/Menu") {
|
||||
ret = strings.Replace(orig_file_or_dir,"/home/cpi/apps/Menu/", sysgo.SKIN+"/Menu/GameShell/",-1)
|
||||
if FileExists(ret) == false {
|
||||
ret = DefaultSkin+orig_file_or_dir
|
||||
}
|
||||
}else { // there is no need to add insert "sysgo" in the middle
|
||||
ret = sysgo.SKIN+orig_file_or_dir
|
||||
ret = strings.Replace(orig_file_or_dir, "/home/cpi/apps/Menu/", sysgo.SKIN+"/Menu/GameShell/", -1)
|
||||
if FileExists(ret) == false {
|
||||
ret = DefaultSkin+orig_file_or_dir
|
||||
ret = DefaultSkin + orig_file_or_dir
|
||||
}
|
||||
} else { // there is no need to add insert "sysgo" in the middle
|
||||
ret = sysgo.SKIN + orig_file_or_dir
|
||||
if FileExists(ret) == false {
|
||||
ret = DefaultSkin + orig_file_or_dir
|
||||
}
|
||||
}
|
||||
|
||||
if FileExists(ret) {
|
||||
return ret
|
||||
}else { // if not existed both in default or custom skin ,return where it is
|
||||
} else { // if not existed both in default or custom skin ,return where it is
|
||||
return orig_file_or_dir
|
||||
}
|
||||
}
|
||||
|
||||
func CmdClean(cmdpath string) string {
|
||||
spchars := "\\`$();|{}&'\"*?<>[]!^~-#\n\r "
|
||||
for _,v:= range spchars {
|
||||
cmdpath = strings.Replace(cmdpath,string(v),"\\"+string(v),-1)
|
||||
for _, v := range spchars {
|
||||
cmdpath = strings.Replace(cmdpath, string(v), "\\"+string(v), -1)
|
||||
}
|
||||
return cmdpath
|
||||
}
|
||||
|
||||
func FileExists(name string) bool {
|
||||
if _, err := os.Stat(name ); err == nil {
|
||||
if _, err := os.Stat(name); err == nil {
|
||||
return true
|
||||
}else {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -86,22 +85,20 @@ func IsDirectory(path string) bool {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}else {
|
||||
return fileInfo.IsDir()
|
||||
} else {
|
||||
return fileInfo.IsDir()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func IsAFile(path string) bool {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}else {
|
||||
return fileInfo.Mode().IsRegular()
|
||||
} else {
|
||||
return fileInfo.Mode().IsRegular()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func MakeExecutable(path string) {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@@ -109,8 +106,8 @@ func MakeExecutable(path string) {
|
||||
return
|
||||
}
|
||||
mode := fileInfo.Mode()
|
||||
mode |= (mode & 0444) >> 2
|
||||
os.Chmod(path,mode)
|
||||
mode |= (mode & 0444) >> 2
|
||||
os.Chmod(path, mode)
|
||||
}
|
||||
|
||||
func GetExePath() string {
|
||||
@@ -118,73 +115,72 @@ func GetExePath() string {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return dir
|
||||
|
||||
return dir
|
||||
|
||||
}
|
||||
|
||||
func ReplaceSuffix(orig_file_str string, new_ext string) string {
|
||||
orig_ext := filepath.Ext(orig_file_str)
|
||||
if orig_ext!= "" {
|
||||
las_pos := strings.LastIndex(orig_file_str,".")
|
||||
return orig_file_str[0:las_pos]+"."+new_ext
|
||||
if orig_ext != "" {
|
||||
las_pos := strings.LastIndex(orig_file_str, ".")
|
||||
return orig_file_str[0:las_pos] + "." + new_ext
|
||||
}
|
||||
return orig_file_str // failed just return back where it came
|
||||
return orig_file_str // failed just return back where it came
|
||||
}
|
||||
|
||||
func SwapAndShow() {
|
||||
display.Flip()
|
||||
}
|
||||
|
||||
func ReadLines(path string)(lines [] string,err error){
|
||||
func ReadLines(path string) (lines []string, err error) {
|
||||
var (
|
||||
file *os.File
|
||||
part [] byte
|
||||
file *os.File
|
||||
part []byte
|
||||
prefix bool
|
||||
)
|
||||
|
||||
|
||||
if file, err = os.Open(path); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
reader := bufio.NewReader(file)
|
||||
buffer := bytes.NewBuffer(make([]byte,0))
|
||||
|
||||
buffer := bytes.NewBuffer(make([]byte, 0))
|
||||
|
||||
for {
|
||||
if part, prefix, err = reader.ReadLine();err != nil {
|
||||
if part, prefix, err = reader.ReadLine(); err != nil {
|
||||
break
|
||||
}
|
||||
buffer.Write(part)
|
||||
if !prefix {
|
||||
lines = append(lines,buffer.String())
|
||||
lines = append(lines, buffer.String())
|
||||
buffer.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WriteLines(lines [] string,path string)(err error){
|
||||
var file *os.File
|
||||
|
||||
if file,err = os.Create(path); err != nil{
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
for _,elem := range lines {
|
||||
_,err := file.WriteString(strings.TrimSpace(elem)+"\n")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func WriteLines(lines []string, path string) (err error) {
|
||||
var file *os.File
|
||||
|
||||
if file, err = os.Create(path); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
for _, elem := range lines {
|
||||
_, err := file.WriteString(strings.TrimSpace(elem) + "\n")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetGid(path string) int {
|
||||
s, err := os.Stat(path)
|
||||
@@ -200,7 +196,6 @@ func GetGid(path string) int {
|
||||
return int(sys_interface.(*syscall.Stat_t).Gid)
|
||||
}
|
||||
|
||||
|
||||
func GetUid(path string) int {
|
||||
s, err := os.Stat(path)
|
||||
if err != nil {
|
||||
@@ -215,76 +210,73 @@ func GetUid(path string) int {
|
||||
return int(sys_interface.(*syscall.Stat_t).Uid)
|
||||
}
|
||||
|
||||
func CheckBattery() int {
|
||||
if FileExists(sysgo.Battery) == false {
|
||||
return -1
|
||||
}
|
||||
|
||||
batinfos,err := ReadLines(sysgo.Battery)
|
||||
if err == nil {
|
||||
for _,v := range batinfos {
|
||||
if strings.HasPrefix(v,"POWER_SUPPLY_CAPACITY") {
|
||||
parts := strings.Split(v,"=")
|
||||
if len(parts) > 1 {
|
||||
cur_cap,err := strconv.Atoi(parts[1])
|
||||
if err == nil {
|
||||
return cur_cap
|
||||
}else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
return 0
|
||||
func CheckBattery() int {
|
||||
if FileExists(sysgo.Battery) == false {
|
||||
return -1
|
||||
}
|
||||
|
||||
batinfos, err := ReadLines(sysgo.Battery)
|
||||
if err == nil {
|
||||
for _, v := range batinfos {
|
||||
if strings.HasPrefix(v, "POWER_SUPPLY_CAPACITY") {
|
||||
parts := strings.Split(v, "=")
|
||||
if len(parts) > 1 {
|
||||
cur_cap, err := strconv.Atoi(parts[1])
|
||||
if err == nil {
|
||||
return cur_cap
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func System(cmd string) string {
|
||||
ret := ""
|
||||
out,err := exec.Command("bash","-c",cmd).Output()
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
//exit code !=0 ,but it can be ignored
|
||||
}else{
|
||||
fmt.Println(err)
|
||||
}
|
||||
}else {
|
||||
ret = string(out)
|
||||
}
|
||||
ret := ""
|
||||
out, err := exec.Command("bash", "-c", cmd).Output()
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
//exit code !=0 ,but it can be ignored
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else {
|
||||
ret = string(out)
|
||||
}
|
||||
|
||||
return ret
|
||||
return ret
|
||||
}
|
||||
|
||||
func ArmSystem(cmd string) string {
|
||||
|
||||
if strings.Contains(runtime.GOARCH,"arm") == true {
|
||||
return System(cmd)
|
||||
}else {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.Contains(runtime.GOARCH, "arm") == true {
|
||||
return System(cmd)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func SystemTrim(cmd string) string {
|
||||
ret := ""
|
||||
out,err := exec.Command("bash","-c",cmd).Output()
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
//exit code !=0 ,but it can be ignored
|
||||
}else{
|
||||
fmt.Println(err)
|
||||
}
|
||||
}else {
|
||||
ret = string(out)
|
||||
}
|
||||
ret := ""
|
||||
out, err := exec.Command("bash", "-c", cmd).Output()
|
||||
if err != nil {
|
||||
if _, ok := err.(*exec.ExitError); ok {
|
||||
//exit code !=0 ,but it can be ignored
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else {
|
||||
ret = string(out)
|
||||
}
|
||||
|
||||
return strings.Trim(ret,"\r\n")
|
||||
return strings.Trim(ret, "\r\n")
|
||||
}
|
||||
|
||||
func cmdEnv() []string {
|
||||
|
||||
Reference in New Issue
Block a user