net_item.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package Bluetooth
  2. import (
  3. //"fmt"
  4. //bleapi "github.com/muka/go-bluetooth/api"
  5. //"github.com/muka/go-bluetooth/bluez/profile"
  6. "github.com/muka/go-bluetooth/bluez/profile/device"
  7. "github.com/veandco/go-sdl2/ttf"
  8. "github.com/veandco/go-sdl2/sdl"
  9. "github.com/cuu/gogame/rect"
  10. "github.com/cuu/gogame/surface"
  11. "github.com/cuu/gogame/color"
  12. "github.com/cuu/gogame/draw"
  13. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  14. )
  15. var NetItemDefaultHeight = 30
  16. type NetItemMultiIcon struct {
  17. UI.MultiIconItem
  18. CanvasHWND *sdl.Surface // self._Parent._CanvasHWND
  19. Parent UI.WidgetInterface //
  20. }
  21. func NewNetItemMultiIcon() *NetItemMultiIcon{
  22. p := &NetItemMultiIcon{}
  23. p.IconIndex = 0
  24. p.IconWidth = 18
  25. p.IconHeight = 18
  26. p.Width = 18
  27. p.Height = 18
  28. return p
  29. }
  30. func (self *NetItemMultiIcon) Draw() {
  31. _,h_ := self.Parent.Size()
  32. dest_rect := rect.Rect(self.PosX,self.PosY+(h_-self.Height)/2, self.Width,self.Height)
  33. area_rect := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
  34. surface.Blit(self.CanvasHWND,self.ImgSurf,&dest_rect,&area_rect)
  35. }
  36. type NetItemIcon struct {
  37. UI.IconItem
  38. CanvasHWND *sdl.Surface
  39. Parent UI.WidgetInterface
  40. }
  41. func NewNetItemIcon() *NetItemIcon {
  42. p := &NetItemIcon{}
  43. p.Width = 18
  44. p.Height = 18
  45. return p
  46. }
  47. func (self *NetItemIcon) Draw() {
  48. _,h_ := self.Parent.Size()
  49. dest_rect := rect.Rect(self.PosX,self.PosY+(h_-self.Height)/2,self.Width,self.Height)
  50. surface.Blit(self.CanvasHWND,self.ImgSurf,&dest_rect,nil)
  51. }
  52. type NetItem struct {
  53. UI.Widget
  54. Channel string //'10'
  55. Stren string //19%
  56. Icons map[string]UI.IconItemInterface
  57. Labels map[string]UI.LabelInterface
  58. IsActive bool
  59. FontObj *ttf.Font
  60. RSSI int // 0
  61. MacAddr string //
  62. Parent *BluetoothPage
  63. Path string ///org/bluez/hci0/dev_34_88_5D_97_FF_26
  64. Props *device.Device1Properties
  65. Device *device.Device1
  66. }
  67. func NewNetItem() *NetItem {
  68. p:= &NetItem{}
  69. p.Height = NetItemDefaultHeight
  70. p.Labels = make(map[string]UI.LabelInterface)
  71. p.Icons = make( map[string]UI.IconItemInterface)
  72. return p
  73. }
  74. func (self *NetItem) SetActive(act bool) {
  75. self.IsActive = act
  76. }
  77. func (self *NetItem) Init( _label string) {
  78. self.MacAddr = self.Props.Address
  79. self.SetActive(self.Props.Connected)
  80. name_label := UI.NewLabel()
  81. name_label.PosX = 12
  82. name_label.CanvasHWND = self.Parent.CanvasHWND
  83. mac_addr := self.MacAddr
  84. if len(self.Props.Name) > 3 {
  85. mac_addr = self.Props.Name
  86. }
  87. self.RSSI = int(self.Props.RSSI)
  88. name_label.Init(mac_addr,self.FontObj,nil)
  89. self.Labels["mac_addr"] = name_label
  90. done_icon := NewNetItemIcon()
  91. done_icon.ImgSurf = UI.MyIconPool.GetImgSurf("done")
  92. done_icon.CanvasHWND = self.Parent.GetCanvasHWND()
  93. done_icon.Parent = self
  94. self.Icons["done"] = done_icon
  95. }
  96. func (self *NetItem) Connect() {
  97. if self.Device != nil {
  98. self.Device.Connect()
  99. }
  100. }
  101. func (self *NetItem) GetLinkObj() UI.PluginInterface {
  102. return nil
  103. }
  104. func (self *NetItem) Draw() {
  105. for k,v := range self.Labels {
  106. x,_ := v.Coord()
  107. _,h := v.Size()
  108. self.Labels[k].NewCoord(x, self.PosY+(self.Height - h)/2)
  109. self.Labels[k].Draw()
  110. }
  111. if self.IsActive {
  112. self.Icons["done"].NewCoord(UI.Width-22, self.PosY)
  113. self.Icons["done"].Draw()
  114. }
  115. draw.Line(self.Parent.CanvasHWND,&color.Color{169,169,169,255},
  116. self.PosX,self.PosY+self.Height-1,
  117. self.PosX+self.Width,self.PosY+self.Height-1,
  118. 1)
  119. }