mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
bluetooth alpha
This commit is contained in:
parent
78522c4b46
commit
f4e4ff3921
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
"strings"
|
||||
"github.com/fatih/structs"
|
||||
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
@ -87,18 +88,22 @@ func (self *BleForgetConfirmPage) Draw() {
|
||||
|
||||
type BleInfoPageSelector struct {
|
||||
UI.InfoPageSelector
|
||||
|
||||
}
|
||||
|
||||
func NewBleInfoPageSelector() *BleInfoPageSelector{
|
||||
p := &BleInfoPageSelector{}
|
||||
|
||||
p.Width = UI.Width
|
||||
p.BackgroundColor = &color.Color{131,199,219,255} //SkinManager().GiveColor('Front')
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (self *BleInfoPageSelector) Draw() {
|
||||
|
||||
idx := self.Parent.GetPsIndex()
|
||||
mylist := self.Parent.GetMyList()
|
||||
|
||||
|
||||
if idx < len(mylist) {
|
||||
_,y := mylist[idx].Coord()
|
||||
_,h := mylist[idx].Size()
|
||||
@ -109,7 +114,7 @@ func (self *BleInfoPageSelector) Draw() {
|
||||
|
||||
canvas_ := self.Parent.GetCanvasHWND()
|
||||
rect_ := rect.Rect(x,self.PosY,self.Width-4, self.Height)
|
||||
|
||||
|
||||
draw.AARoundRect(canvas_,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||
}
|
||||
}
|
||||
@ -121,9 +126,7 @@ type BleInfoPage struct {
|
||||
ListFontObj *ttf.Font
|
||||
ListSmFontObj *ttf.Font
|
||||
ListSm2FontObj *ttf.Font
|
||||
|
||||
MyList []UI.ListItemInterface
|
||||
|
||||
|
||||
AList map[string]interface{}
|
||||
|
||||
Scroller *UI.ListScroller
|
||||
@ -146,7 +149,6 @@ func NewBleInfoPage() *BleInfoPage {
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
func (self *BleInfoPage) Init() {
|
||||
|
||||
if self.Screen != nil {
|
||||
@ -191,7 +193,23 @@ func (self *BleInfoPage) GenList() {
|
||||
start_y := 0
|
||||
|
||||
i := 0
|
||||
skip_arrays := []string{"ManufacturerData","AdvertisingFlags","ServiceData"}
|
||||
|
||||
for k,v := range self.AList {
|
||||
|
||||
skip2 := false
|
||||
for _,u := range skip_arrays {
|
||||
if strings.HasPrefix(k,u) {
|
||||
skip2 = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if skip2 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
|
||||
li := UI.NewInfoPageListItem()
|
||||
li.Parent = self
|
||||
li.PosX = start_x
|
||||
@ -219,15 +237,12 @@ func (self *BleInfoPage) GenList() {
|
||||
sm_text = fmt.Sprintf("%v",v)
|
||||
}
|
||||
|
||||
if sm_text == "0" {
|
||||
sm_text = "No"
|
||||
}else if sm_text == "1" {
|
||||
sm_text = "Yes"
|
||||
}
|
||||
|
||||
li.SetSmallText(sm_text)
|
||||
li.PosX = 2
|
||||
self.MyList = append(self.MyList,li)
|
||||
|
||||
self.MyList = append(self.MyList,li)
|
||||
i+=1
|
||||
}
|
||||
|
||||
}
|
||||
@ -261,21 +276,22 @@ func (self *BleInfoPage) ScrollDown() {
|
||||
if len(self.MyList) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
self.PsIndex += 1
|
||||
|
||||
self.PsIndex -= 1
|
||||
|
||||
if self.PsIndex < 0 {
|
||||
self.PsIndex = 0
|
||||
if self.PsIndex >= len(self.MyList) {
|
||||
self.PsIndex = len(self.MyList)-1
|
||||
}
|
||||
|
||||
cur_li := self.MyList[self.PsIndex]
|
||||
|
||||
x,y := cur_li.Coord()
|
||||
_,h := cur_li.Size()
|
||||
|
||||
if y < 0 {
|
||||
if y + h > self.Height {
|
||||
for i,v := range self.MyList {
|
||||
x,y = v.Coord()
|
||||
_,h := v.Size()
|
||||
_,h = v.Size()
|
||||
self.MyList[i].NewCoord(x,y-h)
|
||||
}
|
||||
}
|
||||
@ -347,7 +363,12 @@ func (self *BleInfoPage) Click() {
|
||||
}
|
||||
|
||||
func (self *BleInfoPage) OnLoadCb() {
|
||||
|
||||
if self.Props.Connected == true {
|
||||
self.FootMsg[1] = "Disconnect"
|
||||
}else {
|
||||
self.FootMsg[1] = ""
|
||||
}
|
||||
|
||||
self.GenList()
|
||||
}
|
||||
|
||||
@ -414,8 +435,6 @@ func (self *BleInfoPage) Draw() {
|
||||
}
|
||||
}
|
||||
|
||||
type BleListSelector BleInfoPageSelector
|
||||
|
||||
type BleListMessageBox struct {
|
||||
UI.Label
|
||||
Parent UI.PageInterface
|
||||
@ -476,9 +495,7 @@ type BluetoothPage struct{
|
||||
|
||||
LastStatusMsg string
|
||||
ADAPTER_DEV string // == adapterID
|
||||
|
||||
|
||||
MyList []*NetItem
|
||||
|
||||
}
|
||||
|
||||
func NewBluetoothPage() *BluetoothPage {
|
||||
@ -519,7 +536,7 @@ func (self *BluetoothPage) Init() {
|
||||
|
||||
self.CanvasHWND = self.Screen.CanvasHWND
|
||||
|
||||
ps := &BleListSelector{}
|
||||
ps := NewBleInfoPageSelector()
|
||||
ps.Parent = self
|
||||
ps.Width = UI.Width - 12
|
||||
|
||||
@ -653,15 +670,17 @@ func (self *BluetoothPage) ScrollUp() {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Scroll Up")
|
||||
|
||||
self.PsIndex -= 1
|
||||
if self.PsIndex < 0 {
|
||||
self.PsIndex=0
|
||||
}
|
||||
|
||||
cur_ni := self.MyList[self.PsIndex]//*NetItem
|
||||
if cur_ni.PosY < 0 {
|
||||
if cur_ni.(*NetItem).PosY < 0 {
|
||||
for i:=0;i<len(self.MyList);i++ {
|
||||
self.MyList[i].PosY += self.MyList[i].Height
|
||||
self.MyList[i].(*NetItem).PosY += self.MyList[i].(*NetItem).Height
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -677,9 +696,9 @@ func (self *BluetoothPage) ScrollDown() {
|
||||
}
|
||||
|
||||
cur_ni := self.MyList[self.PsIndex]
|
||||
if cur_ni.PosY + cur_ni.Height > self.Height {
|
||||
if cur_ni.(*NetItem).PosY + cur_ni.(*NetItem).Height > self.Height {
|
||||
for i:=0;i<len(self.MyList);i++ {
|
||||
self.MyList[i].PosY -= self.MyList[i].Height
|
||||
self.MyList[i].(*NetItem).PosY -= self.MyList[i].(*NetItem).Height
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -723,9 +742,9 @@ func (self *BluetoothPage) KeyDown(ev *event.Event) {
|
||||
return
|
||||
}
|
||||
|
||||
self.InfoPage.Props = self.MyList[self.PsIndex].Props
|
||||
self.InfoPage.Path = self.MyList[self.PsIndex].Path
|
||||
self.InfoPage.MyDevice = self.MyList[self.PsIndex].Device
|
||||
self.InfoPage.Props = self.MyList[self.PsIndex].(*NetItem).Props
|
||||
self.InfoPage.Path = self.MyList[self.PsIndex].(*NetItem).Path
|
||||
self.InfoPage.MyDevice = self.MyList[self.PsIndex].(*NetItem).Device
|
||||
|
||||
self.Screen.PushPage(self.InfoPage)
|
||||
self.Screen.Draw()
|
||||
@ -748,7 +767,7 @@ func (self *BluetoothPage) Draw() {
|
||||
|
||||
|
||||
if len(self.MyList) * NetItemDefaultHeight > self.Height {
|
||||
self.Ps.(*BleListSelector).Width = self.Width - 11
|
||||
self.Ps.(*BleInfoPageSelector).Width = self.Width - 11
|
||||
self.Ps.Draw()
|
||||
|
||||
for _,v := range self.MyList {
|
||||
@ -759,8 +778,9 @@ func (self *BluetoothPage) Draw() {
|
||||
self.Scroller.Draw()
|
||||
|
||||
}else {
|
||||
self.Ps.(*BleListSelector).Width = self.Width
|
||||
self.Ps.(*BleInfoPageSelector).Width = self.Width
|
||||
self.Ps.Draw()
|
||||
|
||||
for _,v := range self.MyList {
|
||||
v.Draw()
|
||||
}
|
||||
|
||||
@ -145,6 +145,9 @@ func (self *NetItem) Connect() {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *NetItem) GetLinkObj() UI.PluginInterface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *NetItem) Draw() {
|
||||
for k,v := range self.Labels {
|
||||
|
||||
@ -250,6 +250,8 @@ func (self *FavListPage) ScrollUp() {
|
||||
|
||||
if y < 0 {
|
||||
for i,_ := range self.MyList{
|
||||
x,y = self.MyList[i].Coord()
|
||||
_, h = self.MyList[i].Size()
|
||||
self.MyList[i].NewCoord(x, y + h)
|
||||
}
|
||||
|
||||
@ -273,6 +275,8 @@ func (self *FavListPage) ScrollDown(){
|
||||
_,h := cur_li.Size()
|
||||
if y + h > self.Height {
|
||||
for i,_ := range self.MyList{
|
||||
x,y = self.MyList[i].Coord()
|
||||
_, h = self.MyList[i].Size()
|
||||
self.MyList[i].NewCoord(x,y-h)
|
||||
}
|
||||
self.Scrolled -=1
|
||||
|
||||
@ -227,6 +227,7 @@ func (self *EmulatorListItem) Draw() {
|
||||
x,y := self.Labels["Text"].Coord()
|
||||
_,h := self.Labels["Text"].Size()
|
||||
|
||||
|
||||
if self.Path != "[..]" {
|
||||
self.Labels["Text"].NewCoord(23,y)
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
|
||||
if UI.IsDirectory(path) == false {
|
||||
return nil,errors.New("Path is not a folder")
|
||||
}
|
||||
dirmap := make(map[string]string)
|
||||
|
||||
var ret []map[string]string
|
||||
|
||||
file_paths,err := filepath.Glob(path+"/*")//sorted
|
||||
@ -82,8 +82,9 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
|
||||
fmt.Println(err)
|
||||
return ret,err
|
||||
}
|
||||
|
||||
|
||||
for _,v := range file_paths {
|
||||
dirmap := make(map[string]string)
|
||||
if UI.IsDirectory(v) && self.EmulatorConfig.FILETYPE == "dir" { // like DOSBOX
|
||||
gameshell_bat := self.EmulatorConfig.EXT[0]
|
||||
if UI.GetGid(v) == FavGID { // skip fav roms
|
||||
@ -139,7 +140,7 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
|
||||
func (self *RomListPage) SyncList( path string ) {
|
||||
|
||||
alist,err := self.GeneratePathList(path)
|
||||
//fmt.Println(alist)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@ -191,7 +192,6 @@ func (self *RomListPage) SyncList( path string ) {
|
||||
}
|
||||
|
||||
li.Init(init_val)
|
||||
|
||||
self.MyList = append(self.MyList,li)
|
||||
}
|
||||
}
|
||||
@ -276,6 +276,8 @@ func (self *RomListPage) ScrollUp() {
|
||||
_,h := cur_li.Size()
|
||||
if y < 0 {
|
||||
for i,_ := range self.MyList{
|
||||
x,y = self.MyList[i].Coord()
|
||||
_, h = self.MyList[i].Size()
|
||||
self.MyList[i].NewCoord(x,y + h)
|
||||
}
|
||||
|
||||
@ -300,6 +302,8 @@ func (self *RomListPage) ScrollDown(){
|
||||
|
||||
if y+ h > self.Height {
|
||||
for i,_ := range self.MyList{
|
||||
x,y = self.MyList[i].Coord()
|
||||
_, h = self.MyList[i].Size()
|
||||
self.MyList[i].NewCoord(x,y - h)
|
||||
}
|
||||
self.Scrolled -=1
|
||||
@ -538,28 +542,20 @@ func (self *RomListPage) Draw() {
|
||||
}else{
|
||||
_,h := self.Ps.Size()
|
||||
if len(self.MyList) * HierListItemDefaultHeight > self.Height {
|
||||
|
||||
self.Ps.NewSize(self.Width - 10,h)
|
||||
self.Ps.Draw()
|
||||
|
||||
|
||||
for _,v := range self.MyList {
|
||||
_,y := v.Coord()
|
||||
if y > self.Height + self.Height/2 {
|
||||
if y > (self.Height + self.Height/2) {
|
||||
break
|
||||
}
|
||||
|
||||
if y < 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
v.Draw()
|
||||
}
|
||||
|
||||
self.Scroller.UpdateSize( len(self.MyList)*HierListItemDefaultHeight, self.PsIndex*HierListItemDefaultHeight)
|
||||
self.Scroller.Draw()
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
self.Ps.NewSize(self.Width,h)
|
||||
self.Ps.Draw()
|
||||
|
||||
@ -291,6 +291,25 @@ 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)
|
||||
|
||||
}
|
||||
|
||||
func (self *TitleBar) Init(main_screen *MainScreen) {
|
||||
|
||||
start_x := 0
|
||||
@ -346,6 +365,16 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
|
||||
|
||||
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()
|
||||
|
||||
|
||||
round_corners := NewTitleBarIconItem()
|
||||
round_corners.IconWidth = 10
|
||||
round_corners.IconHeight = 10
|
||||
@ -410,6 +439,8 @@ func (self *TitleBar) Draw(title string) {
|
||||
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)
|
||||
|
||||
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["battery"].NewCoord(start_x+self.IconWidth+self.IconWidth+8, self.IconHeight/2+(self.BarHeight-self.IconHeight)/2)
|
||||
|
||||
@ -435,7 +466,8 @@ func (self *TitleBar) Draw(title string) {
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user