gpu_driver_page.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package Lima
  2. import (
  3. //"fmt"
  4. //"io/ioutil"
  5. //"path/filepath"
  6. "strings"
  7. "runtime"
  8. "github.com/veandco/go-sdl2/ttf"
  9. "github.com/mitchellh/go-homedir"
  10. "github.com/cuu/gogame/draw"
  11. "github.com/cuu/gogame/rect"
  12. "github.com/cuu/gogame/surface"
  13. "github.com/cuu/gogame/color"
  14. "github.com/cuu/gogame/event"
  15. "github.com/cuu/gogame/time"
  16. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  17. )
  18. type ListPageSelector struct {
  19. UI.InfoPageSelector
  20. }
  21. func NewListPageSelector() *ListPageSelector {
  22. p := &ListPageSelector{}
  23. p.Width = UI.Width
  24. p.BackgroundColor = &color.Color{131,199,219,255} //SkinManager().GiveColor('Front')
  25. return p
  26. }
  27. func (self *ListPageSelector) Draw() {
  28. idx := self.Parent.GetPsIndex()
  29. mylist := self.Parent.GetMyList()
  30. if idx < len(mylist) {
  31. x,y := mylist[idx].Coord()
  32. _,h := mylist[idx].Size()
  33. self.PosX = x+2
  34. self.PosY = y+1
  35. self.Height = h-3
  36. canvas_ := self.Parent.GetCanvasHWND()
  37. rect_ := rect.Rect(self.PosX,self.PosY,self.Width-4, self.Height)
  38. draw.AARoundRect(canvas_,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
  39. }
  40. }
  41. type PageListItem struct {
  42. UI.InfoPageListItem
  43. Active bool
  44. Value string
  45. }
  46. func NewPageListItem() *PageListItem {
  47. p := &PageListItem{}
  48. p.Height = UI.DefaultInfoPageListItemHeight
  49. p.ReadOnly = false
  50. p.Labels = make(map[string]UI.LabelInterface)
  51. p.Icons = make( map[string]UI.IconItemInterface)
  52. p.Fonts = make(map[string]*ttf.Font)
  53. return p
  54. }
  55. func (self *PageListItem) Draw() {
  56. x,_ := self.Labels["Text"].Coord()
  57. w,h := self.Labels["Text"].Size()
  58. self.Labels["Text"].NewCoord( x, self.PosY + (self.Height - h)/2 )
  59. if self.Active == true {
  60. self.Parent.(*GPUDriverPage).Icons["done"].NewCoord(self.Parent.(*GPUDriverPage).Width-30,self.PosY+5)
  61. self.Parent.(*GPUDriverPage).Icons["done"].Draw()
  62. }
  63. self.Labels["Text"].SetBold(self.Active)
  64. self.Labels["Text"].Draw()
  65. if _, ok := self.Labels["Small"]; ok {
  66. x,_ = self.Labels["Small"].Coord()
  67. w,h = self.Labels["Small"].Size()
  68. self.Labels["Small"].NewCoord( self.Width - w - 10 , self.PosY + (self.Height - h)/2 )
  69. self.Labels["Small"].Draw()
  70. }
  71. canvas_ := self.Parent.GetCanvasHWND()
  72. draw.Line(canvas_, &color.Color{169,169,169,255},
  73. self.PosX, self.PosY+self.Height -1,
  74. self.PosX + self.Width, self.PosY+self.Height -1 ,1)
  75. }
  76. type GPUDriverPage struct {
  77. UI.Page
  78. ListFont *ttf.Font
  79. BGwidth int
  80. BGheight int
  81. DrawOnce bool
  82. Scroller *UI.ListScroller
  83. Icons map[string]UI.IconItemInterface
  84. }
  85. func NewGPUDriverPage() *GPUDriverPage {
  86. p := &GPUDriverPage{}
  87. p.ListFont = UI.Fonts["notosanscjk12"]
  88. p.FootMsg = [5]string{"Nav","","","Back","Select"}
  89. p.BGwidth = UI.Width
  90. p.BGheight = UI.Height - 24 - 20
  91. p.Icons = make(map[string]UI.IconItemInterface)
  92. return p
  93. }
  94. func (self *GPUDriverPage) GenList() {
  95. self.MyList = nil
  96. start_x := 0
  97. start_y := 0
  98. last_height := 0
  99. var drivers = [][2]string{[2]string{"fbturbo","FBTURBO driver (Software Rendering)"},
  100. [2]string{"modesetting","LIMA driver (Experimental Hardware Rendering)"}}
  101. for _,u := range drivers {
  102. li := NewPageListItem()
  103. li.Parent = self
  104. li.PosX = start_x
  105. li.PosY = start_y + last_height
  106. li.Width = UI.Width
  107. li.Fonts["normal"] = self.ListFont
  108. li.Active = false
  109. li.Value = u[0]
  110. li.Init(u[1])
  111. last_height += li.Height
  112. self.MyList = append(self.MyList,li)
  113. }
  114. }
  115. func (self *GPUDriverPage) Init() {
  116. if self.Screen != nil {
  117. if self.Screen.CanvasHWND != nil && self.CanvasHWND == nil {
  118. self.HWND = self.Screen.CanvasHWND
  119. self.CanvasHWND = surface.Surface( self.Screen.Width,self.Screen.Height )
  120. }
  121. }
  122. self.PosX = self.Index*self.Screen.Width
  123. self.Width = self.Screen.Width
  124. self.Height = self.Screen.Height
  125. done := UI.NewIconItem()
  126. done.ImgSurf = UI.MyIconPool.GetImgSurf("done")
  127. done.MyType = UI.ICON_TYPES["STAT"]
  128. done.Parent = self
  129. self.Icons["done"] = done
  130. ps := NewListPageSelector()
  131. ps.Parent = self
  132. self.Ps = ps
  133. self.PsIndex = 0
  134. self.GenList()
  135. self.Scroller = UI.NewListScroller()
  136. self.Scroller.Parent = self
  137. self.Scroller.PosX = self.Width - 10
  138. self.Scroller.PosY = 2
  139. self.Scroller.Init()
  140. self.Scroller.SetCanvasHWND(self.HWND)
  141. }
  142. func (self *GPUDriverPage) Click() {
  143. if len(self.MyList) == 0 {
  144. return
  145. }
  146. if self.PsIndex >= len(self.MyList) {
  147. self.PsIndex = len(self.MyList) -1
  148. }
  149. cur_li := self.MyList[self.PsIndex].(*PageListItem)
  150. if cur_li.Active == true {
  151. return
  152. }
  153. if strings.Contains(runtime.GOARCH,"arm") == true {
  154. for i,_ := range self.MyList {
  155. self.MyList[i].(*PageListItem).Active = false
  156. }
  157. cur_li.Active = true
  158. self.Screen.MsgBox.SetText("Applying")
  159. self.Screen.MsgBox.Draw()
  160. self.Screen.SwapAndShow()
  161. if strings.Contains(cur_li.Value,"modesetting") {
  162. lockfile,_ := homedir.Expand("~/.lima")
  163. UI.System("touch "+lockfile)
  164. UI.ArmSystem("sudo mv /usr/lib/xorg/modules/drivers/modesetting_drv.so.lima /usr/lib/xorg/modules/drivers/modesetting_drv.so")
  165. UI.ArmSystem("sudo sed -i '/^#.*lima/s/^#//' /etc/ld.so.conf.d/00-arm-linux-gnueabihf.conf")
  166. UI.ArmSystem("sudo ldconfig")
  167. }else {
  168. lockfile,_ := homedir.Expand("~/.lima")
  169. UI.System("rm "+lockfile)
  170. UI.ArmSystem("sudo mv /usr/lib/xorg/modules/drivers/modesetting_drv.so /usr/lib/xorg/modules/drivers/modesetting_drv.so.lima")
  171. UI.ArmSystem("sudo sed -i 's/^[^#]*lima/#&/' /etc/ld.so.conf.d/00-arm-linux-gnueabihf.conf")
  172. UI.ArmSystem("sudo ldconfig")
  173. }
  174. time.BlockDelay(1000)
  175. UI.System("sudo reboot")
  176. }else {
  177. self.Screen.MsgBox.SetText("Do it in GameShell")
  178. self.Screen.MsgBox.Draw()
  179. self.Screen.SwapAndShow()
  180. }
  181. }
  182. func (self *GPUDriverPage) OnLoadCb() {
  183. self.PosY = 0
  184. self.DrawOnce = false
  185. thedrv := ""
  186. if strings.Contains(runtime.GOARCH,"arm") == true {
  187. lockfile,_ := homedir.Expand("~/.lima")
  188. if UI.FileExists(lockfile) {
  189. thedrv = "modesetting"
  190. }else {
  191. thedrv = "fbturbo"
  192. }
  193. }
  194. if thedrv == "" {
  195. thedrv = "fbturbo"
  196. }
  197. for i, v := range self.MyList {
  198. if strings.Contains( v.(*PageListItem).Value, thedrv) {
  199. self.MyList[i].(*PageListItem).Active = true
  200. break
  201. }
  202. }
  203. }
  204. func (self *GPUDriverPage) KeyDown(ev *event.Event ) {
  205. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  206. self.ReturnToUpLevelPage()
  207. self.Screen.Draw()
  208. self.Screen.SwapAndShow()
  209. }
  210. if ev.Data["Key"] == UI.CurKeys["B"] {
  211. self.Click()
  212. }
  213. if ev.Data["Key"] == UI.CurKeys["Up"] {
  214. self.ScrollUp()
  215. self.Screen.Draw()
  216. self.Screen.SwapAndShow()
  217. }
  218. if ev.Data["Key"] == UI.CurKeys["Down"] {
  219. self.ScrollDown()
  220. self.Screen.Draw()
  221. self.Screen.SwapAndShow()
  222. }
  223. }
  224. func (self *GPUDriverPage) Draw() {
  225. self.ClearCanvas()
  226. if len(self.MyList) == 0 {
  227. return
  228. }
  229. if len(self.MyList) * UI.DefaultInfoPageListItemHeight > self.Height {
  230. self.Ps.(*ListPageSelector).Width = self.Width - 11
  231. self.Ps.Draw()
  232. for _,v := range self.MyList {
  233. if v.(*PageListItem).PosY > self.Height + self.Height/2 {
  234. break
  235. }
  236. if v.(*PageListItem).PosY < 0 {
  237. continue
  238. }
  239. v.Draw()
  240. }
  241. self.Scroller.UpdateSize( len(self.MyList)*UI.DefaultInfoPageListItemHeight,
  242. self.PsIndex*UI.DefaultInfoPageListItemHeight)
  243. self.Scroller.Draw()
  244. }else {
  245. self.Ps.(*ListPageSelector).Width = self.Width
  246. self.Ps.Draw()
  247. for _,v := range self.MyList {
  248. if v.(*PageListItem).PosY > self.Height + self.Height/2 {
  249. break
  250. }
  251. if v.(*PageListItem).PosY < 0 {
  252. continue
  253. }
  254. v.Draw()
  255. }
  256. }
  257. if self.HWND != nil {
  258. surface.Fill(self.HWND, UI.MySkinManager.GiveColor("White"))
  259. rect_ := rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
  260. surface.Blit(self.HWND,self.CanvasHWND,&rect_,nil)
  261. }
  262. }