mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
try to copy whole design from python gameshell launcher
This commit is contained in:
parent
7b0b08324c
commit
cd4c65ec8a
1
sysgo/UI/.#main_screen.go
Symbolic link
1
sysgo/UI/.#main_screen.go
Symbolic link
@ -0,0 +1 @@
|
||||
guu@guu-desktop.31499:1528607783
|
||||
0
sysgo/UI/confirm_page.go
Normal file
0
sysgo/UI/confirm_page.go
Normal file
16
sysgo/UI/constants.go
Normal file
16
sysgo/UI/constants.go
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
package UI
|
||||
|
||||
var (
|
||||
Width = 320
|
||||
Height = 240
|
||||
IconWidth = 80
|
||||
IconHeight = 80
|
||||
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}
|
||||
|
||||
DT = 50
|
||||
|
||||
)
|
||||
0
sysgo/UI/foot_bar.go
Normal file
0
sysgo/UI/foot_bar.go
Normal file
125
sysgo/UI/icon_item.go
Normal file
125
sysgo/UI/icon_item.go
Normal file
@ -0,0 +1,125 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/transform"
|
||||
"github.com/cuu/gogame/utils"
|
||||
)
|
||||
|
||||
type IconItem struct {
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
ImageName string
|
||||
ImgSurf *sdl.Surface
|
||||
Parent PageInterface
|
||||
Index int
|
||||
MyType int
|
||||
CmdPath interface{}
|
||||
LinkPage PageInterface
|
||||
Label LabelInterface
|
||||
Align int
|
||||
AnimationTime int
|
||||
}
|
||||
|
||||
|
||||
func NewIconItem() *IconItem {
|
||||
i := &IconItem{}
|
||||
i.MyType = ICON_TYPES["EXE"]
|
||||
|
||||
i.Align = ALIGN["VCenter"]
|
||||
|
||||
l := NewLabel()
|
||||
|
||||
i.Label = l
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
|
||||
func (self *IconItem) Init(x,y,w,h,at) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
self.Width = w
|
||||
self.Height = h
|
||||
self.AnimationTime = at
|
||||
}
|
||||
|
||||
func (self *IconItem) SetLabelColor(col *color.Color) {
|
||||
self.Label.SetColor(col)
|
||||
}
|
||||
|
||||
func (self *IconItem) NewCoord(x,y int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
}
|
||||
|
||||
func (self *IconItem) AddLabel(text string, fontobj *ttf.Font) {
|
||||
if self.Label == nil {
|
||||
l:= NewLabel()
|
||||
self.Label = l
|
||||
}else {
|
||||
self.Label.Init(text,fontobj)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *IconItem) AdjustLinkPage() {
|
||||
if self.MyType == ICON_TYPES["DIR"] && self.LinkPage != nil {
|
||||
self.LinkPage.SetIndex(0)
|
||||
self.LinkPage.SetAlign(ALIGN["SLeft"])
|
||||
self.LinkPage.SetIconNumbers( len(self.LinkPage.GetIcons()) )
|
||||
self.LinkPage.SetScreen(self.Parent.GetScreen())
|
||||
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"] {
|
||||
self.LinkPage.AdjustSAutoLeftAlign()
|
||||
if self.LinkPage.GetIconNumbers() > 1 {
|
||||
self.LinkPage.SetPsIndex(1)
|
||||
self.LinkPage.SetIconIndex ( 1 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *IconItem) CreateImageSurf() {
|
||||
if self.ImgSurf == nil && self.ImageName != "" {
|
||||
self.ImgSurf = image.Load(self.ImageName)
|
||||
if self.ImgSurf.W > IconWidth || self.ImgSurf.H > IconHeight {
|
||||
self.ImgSurf = transform.Scale(self.ImgSurf,IconWidth,IconHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *IconItem) ChangeImgSurfColor(col *color.Color) {
|
||||
utils.ColorSurface(self.ImgSurf,col)
|
||||
}
|
||||
|
||||
func (self *IconItem) Draw() {
|
||||
|
||||
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()
|
||||
|
||||
if self.Align == ALIGN["VCenter"] {
|
||||
self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + lab_h/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)
|
||||
}
|
||||
}
|
||||
|
||||
0
sysgo/UI/icon_pool.go
Normal file
0
sysgo/UI/icon_pool.go
Normal file
91
sysgo/UI/label.go
Normal file
91
sysgo/UI/label.go
Normal file
@ -0,0 +1,91 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/font"
|
||||
)
|
||||
|
||||
type LabelInterface interface {
|
||||
Init( text string, font_obj *ttf.Font,col *color.Color )
|
||||
Coord() (int,int)
|
||||
Size() (int,int)
|
||||
NewCoord(x,y int)
|
||||
SetColor(col *color.Color )
|
||||
GetText() string
|
||||
SetText(text string)
|
||||
Draw()
|
||||
}
|
||||
|
||||
type Label struct {
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Text string
|
||||
FontObj *ttf.Font
|
||||
Color *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
// TextSurf *sdl.Surface
|
||||
}
|
||||
|
||||
func NewLabel() *Label() {
|
||||
l := &Label{}
|
||||
l.Color = &color.Color{83,83,83,255}
|
||||
return l
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
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) NewCoord(x,y int) {
|
||||
self.PosX = x
|
||||
self.PosY = y
|
||||
|
||||
}
|
||||
|
||||
func (self *Label) SetColor(col *color.Color){
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (self *Label) Draw() {
|
||||
font.SetBold(self.FontObj,false) // avoing same font tangling set_bold to others
|
||||
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)
|
||||
|
||||
}
|
||||
20
sysgo/UI/main_screen.go
Normal file
20
sysgo/UI/main_screen.go
Normal file
@ -0,0 +1,20 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
|
||||
)
|
||||
|
||||
type MainScreen struct {
|
||||
Pages []interface{}
|
||||
PageMax int
|
||||
PageIndex int
|
||||
PosX int
|
||||
PosY int
|
||||
|
||||
}
|
||||
|
||||
|
||||
func NewMainScreen() *MainScreen {
|
||||
m := &MainScreen{}
|
||||
|
||||
}
|
||||
35
sysgo/UI/multi_icon_item.go
Normal file
35
sysgo/UI/multi_icon_item.go
Normal file
@ -0,0 +1,35 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"github.com/cuu/gogame/image"
|
||||
)
|
||||
|
||||
|
||||
type MultiIconItem struct {
|
||||
IconItem
|
||||
|
||||
IconWidth int
|
||||
IconHeight int
|
||||
IconIndex int
|
||||
}
|
||||
|
||||
func NewMultiIconItem() *MultiIconItem {
|
||||
m := &MultiIconItem{}
|
||||
m.IconIndex = 0
|
||||
m.IconWidth = 18
|
||||
m.IconHeight = 18
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (m * MultiIconItem) CreateImageSurf() {
|
||||
if m.ImgSurf == nil and m.ImageName != "" {
|
||||
m.ImgSurf = image.Load(m.ImageName)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MultiIconItem) Draw() {
|
||||
|
||||
}
|
||||
149
sysgo/UI/page.go
Normal file
149
sysgo/UI/page.go
Normal file
@ -0,0 +1,149 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
)
|
||||
|
||||
type element struct {
|
||||
data interface{}
|
||||
next *element
|
||||
}
|
||||
|
||||
type PageStack struct {
|
||||
lock *sync.Mutex
|
||||
head *element
|
||||
Size int
|
||||
}
|
||||
|
||||
func (stk *PageStack) Push(data interface{}) {
|
||||
stk.lock.Lock()
|
||||
|
||||
element := new(element)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
|
||||
stk.lock.Unlock()
|
||||
}
|
||||
|
||||
func (stk *PageStack) Pop() interface{} {
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
|
||||
stk.lock.Unlock()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func NewPageStack() *PageStack {
|
||||
stk := new(PageStack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
}
|
||||
|
||||
|
||||
type PageSelector struct {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Parent interface{} //
|
||||
Alpha int
|
||||
OnShow bool
|
||||
IconSurf *sdl.Surface
|
||||
|
||||
}
|
||||
|
||||
func (p *PageSelector) Adjust(x,y,w,h,alpha int) {
|
||||
p.PosX = x
|
||||
p.PosY = y
|
||||
p.Width = w
|
||||
p.Height = h
|
||||
p.Alpha = alpha
|
||||
}
|
||||
|
||||
func (p *PageSelector) Draw() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
type PageInterface interface {
|
||||
// shared functions
|
||||
// GetScreen
|
||||
// GetIcons
|
||||
// SetScreen
|
||||
// SetFootMsg
|
||||
// SetCanvasHWND
|
||||
// GetCanvasHWND
|
||||
// GetHWND
|
||||
// SetHWND
|
||||
// AdjustHLeftAlign
|
||||
// AdjustSAutoLeftAlign
|
||||
// SetPsIndex
|
||||
// SetIconIndex
|
||||
// GetPsIndex
|
||||
// GetIconIndex
|
||||
// Coord
|
||||
// Size
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Icons []interface{} // make first
|
||||
IconNumbers int
|
||||
IconIndex int
|
||||
PrevIconIndex int
|
||||
|
||||
Ps interface{}
|
||||
PsIndex int
|
||||
|
||||
Index int
|
||||
|
||||
Align string
|
||||
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
|
||||
OnShow bool
|
||||
|
||||
Name string
|
||||
Screen *MainScreen
|
||||
|
||||
PageIconMargin int // default 20
|
||||
FootMsg [5]string
|
||||
|
||||
SelectedIconTopOffset int
|
||||
EasingDur int
|
||||
}
|
||||
|
||||
func NewPage() *Page {
|
||||
p := &Page{}
|
||||
p.PageIconMargin = 20
|
||||
p.SelectedIconTopOffset = 20
|
||||
p.EasingDur = 30
|
||||
|
||||
p.FootMsg = [5]string{"Nav.","","","","Enter"}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
sysgo/UI/scroller.go
Normal file
0
sysgo/UI/scroller.go
Normal file
180
sysgo/UI/title_bar.go
Normal file
180
sysgo/UI/title_bar.go
Normal file
@ -0,0 +1,180 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"bufio"
|
||||
"strings"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
|
||||
"github.com/itchyny/volume-go"
|
||||
|
||||
"../sysgo"
|
||||
)
|
||||
|
||||
|
||||
var TitleBar_BarHeight = 24
|
||||
|
||||
type TitleBar struct {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
BarHeight int
|
||||
LOffset int
|
||||
ROffset int
|
||||
Icons map[string]interface{}
|
||||
IconWidth
|
||||
IconHeight
|
||||
BorderWidth
|
||||
CanvasHWND *sdl.Surface
|
||||
HWND interface{}
|
||||
Title string
|
||||
InLowBackLight int
|
||||
SkinManager interface{}
|
||||
|
||||
icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
|
||||
}
|
||||
|
||||
|
||||
func NewTitleBar() *TitleBar {
|
||||
t := &TitleBar{}
|
||||
|
||||
|
||||
t.BorderWidth = 1
|
||||
|
||||
t.BarHeight = TitleBar_BarHeight
|
||||
t.Height = t.BarHeight + t.BorderWidth
|
||||
|
||||
t.Width = Width
|
||||
|
||||
t.Icons = make(map[string]interface{})
|
||||
|
||||
//t.icon_base_path = SkinMap("gameshell/titlebar_icons/")
|
||||
}
|
||||
|
||||
func (t *TitleBar) RoundRobinCheck {
|
||||
|
||||
}
|
||||
|
||||
func (t *TitleBar) UpdateWifiStrength() {
|
||||
|
||||
}
|
||||
|
||||
func (t *TitleBar) GetWifiStrength(stren string) int {
|
||||
segs := [][]int{ []int{-2,-1}, []int{0,25}, []int{25,50}, []int{50,75},int{75,100}}
|
||||
stren_number,_ := strconv.Atoi( stren )
|
||||
ge := 0
|
||||
if stren_number == 0 {
|
||||
return ge
|
||||
}
|
||||
|
||||
for i,v in range segs {
|
||||
if stren_number >= v[0] && stren_number <= v[1] {
|
||||
ge = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ge
|
||||
}
|
||||
|
||||
func (t *TitleBar) SyncSoundVolume() {
|
||||
|
||||
vol, err := volume.GetVolume()
|
||||
if err != nil {
|
||||
log.Fatalf("get volume failed: %+v", err)
|
||||
vol = 0
|
||||
}
|
||||
fmt.Printf("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 in range snd_segs {
|
||||
if vol >= v[0] && vol <= v[1] {
|
||||
ge = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
func (t *TitleBar) SetSoundVolume(vol int) {
|
||||
//pass
|
||||
}
|
||||
|
||||
func (t *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}}
|
||||
|
||||
file, err := os.Open( sysgo.Battery )
|
||||
if err != nil {
|
||||
fmt.Println("Could not open file ", sysgo.Battery)
|
||||
t.Icons["battery"] = t.Icons["battery_unknown"]
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
bat_uevent := make([string]string)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line = strings.Trim(line," ")
|
||||
pis := strings.Split(line,"=")
|
||||
if len(pis) > 1 {
|
||||
bat_uevent[ pis[0] ] = pis[1]
|
||||
}
|
||||
}
|
||||
|
||||
cur_cap := 0
|
||||
|
||||
if val, ok := bat_uevent["POWER_SUPPLY_CAPACITY"]; ok {
|
||||
cur_cap = strings.Atoi(val)
|
||||
}else {
|
||||
cur_cap = 0
|
||||
}
|
||||
|
||||
cap_ge := 0
|
||||
|
||||
for i,v in range bat_segs {
|
||||
if cur_cap >= v[0] && cur_cap <= v[1] {
|
||||
cap_ge = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if val, ok := bat_uevent["POWER_SUPPLY_STATUS"]; ok {
|
||||
if val == "Charging" {
|
||||
t.Icons["battery_charging"].IconIndex = cap_ge
|
||||
t.Icons["battery"] = t.Icons["battery_charging"]
|
||||
}else {
|
||||
t.Icons["battery_charging"].IconIndex = cap_ge
|
||||
t.Icons["battery"] = t.Icons["battery_discharging"]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (t *TitleBar) SetBatteryStat( bat int) {
|
||||
|
||||
}
|
||||
|
||||
func (t *TitleBar) Init(screen *MainScreen) {
|
||||
|
||||
start_x := 0
|
||||
|
||||
t.CanvasHWND = surface.Surface(t.Width,t.Height)
|
||||
t.HWND = screen
|
||||
|
||||
icon_wifi_statu := NewMultiIconItem()
|
||||
|
||||
}
|
||||
10
sysgo/config.go
Normal file
10
sysgo/config.go
Normal file
@ -0,0 +1,10 @@
|
||||
package sysgo
|
||||
|
||||
var (
|
||||
CurKeySet = "GameShell"
|
||||
DontLeave = false
|
||||
BackLight = "/proc/driver/backlight"
|
||||
Battery = "/sys/class/power_supply/axp20x-battery/uevent"
|
||||
|
||||
SKIN="default"
|
||||
)
|
||||
0
sysgo/main.go
Normal file
0
sysgo/main.go
Normal file
Loading…
x
Reference in New Issue
Block a user