list_item.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package Emulator
  2. import (
  3. "fmt"
  4. "github.com/veandco/go-sdl2/ttf"
  5. "io/ioutil"
  6. "path/filepath"
  7. "strings"
  8. //"github.com/veandco/go-sdl2/sdl"
  9. //"github.com/cuu/gogame/surface"
  10. //"github.com/cuu/gogame/rect"
  11. "github.com/cuu/gogame/color"
  12. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  13. "github.com/cuu/gogame/draw"
  14. )
  15. type EmulatorPageInterface interface {
  16. UI.PageInterface
  17. GetMapIcons() map[string]UI.IconItemInterface
  18. GetEmulatorConfig() *ActionConfig
  19. }
  20. type EmulatorListItem struct {
  21. UI.HierListItem
  22. Parent EmulatorPageInterface
  23. }
  24. func NewEmulatorListItem() *EmulatorListItem {
  25. p := &EmulatorListItem{}
  26. p.Labels = make(map[string]UI.LabelInterface)
  27. p.Icons = make(map[string]UI.IconItemInterface)
  28. p.Fonts = make(map[string]*ttf.Font)
  29. p.MyType = UI.ICON_TYPES["EXE"]
  30. p.Height = 32
  31. p.Width = 0
  32. return p
  33. }
  34. func (self *EmulatorListItem) Init(text string) {
  35. l := UI.NewLabel()
  36. l.PosX = 20
  37. l.SetCanvasHWND(self.Parent.GetCanvasHWND())
  38. if self.IsDir() == true || self.IsFile() == true {
  39. self.Path = text
  40. }
  41. label_text := filepath.Base(text)
  42. ext := filepath.Ext(text)
  43. if ext != "" {
  44. alias_file := strings.Replace(text, ext, "", -1) + ".alias"
  45. if UI.FileExists(alias_file) == true {
  46. b, err := ioutil.ReadFile(alias_file)
  47. if err != nil {
  48. fmt.Print(err)
  49. } else {
  50. label_text = string(b)
  51. }
  52. }
  53. }
  54. if self.IsDir() == true {
  55. l.Init(label_text, self.Fonts["normal"], nil)
  56. } else {
  57. l.Init(label_text, self.Fonts["normal"], nil)
  58. }
  59. self.Labels["Text"] = l
  60. }
  61. func (self *EmulatorListItem) Draw() {
  62. x, y := self.Labels["Text"].Coord()
  63. _, h := self.Labels["Text"].Size()
  64. if self.Path != "[..]" {
  65. self.Labels["Text"].NewCoord(23, y)
  66. } else {
  67. self.Labels["Text"].NewCoord(3, y)
  68. }
  69. x, y = self.Labels["Text"].Coord()
  70. self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
  71. self.Labels["Text"].Draw()
  72. parent_icons := self.Parent.GetMapIcons()
  73. _, h = parent_icons["sys"].Size()
  74. if self.IsDir() == true && self.Path != "[..]" {
  75. parent_icons["sys"].SetIconIndex(0)
  76. parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
  77. parent_icons["sys"].Draw()
  78. }
  79. if self.IsFile() == true {
  80. parent_icons["sys"].SetIconIndex(1)
  81. parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
  82. parent_icons["sys"].Draw()
  83. }
  84. draw.Line(self.Parent.GetCanvasHWND(), &color.Color{169, 169, 169, 255},
  85. self.PosX, self.PosY+self.Height-1, self.PosX+self.Width, self.PosY+self.Height-1, 1)
  86. }