confirm_page.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package UI
  2. import (
  3. "github.com/veandco/go-sdl2/ttf"
  4. // "github.com/cuu/gogame/surface"
  5. "github.com/cuu/gogame/event"
  6. "github.com/cuu/gogame/rect"
  7. "github.com/cuu/gogame/color"
  8. // "github.com/cuu/gogame/font"
  9. "github.com/cuu/gogame/draw"
  10. )
  11. type ListPageSelector struct {
  12. PageSelector
  13. BackgroundColor *color.Color
  14. Parent *ConfirmPage
  15. }
  16. func NewListPageSelector() *ListPageSelector {
  17. p := &ListPageSelector{}
  18. p.Width = Width
  19. p.BackgroundColor = &color.Color{131,199,219,255}
  20. return p
  21. }
  22. func (self *ListPageSelector) Draw() {
  23. idx := self.Parent.GetPsIndex()
  24. mylist := self.Parent.MyList
  25. if idx > (len(mylist) -1) {
  26. idx = len(mylist)
  27. if idx > 0 {
  28. idx -= 1
  29. }else if idx == 0 {
  30. return
  31. }
  32. }
  33. x,y := mylist[idx].Coord()
  34. _,h := mylist[idx].Size()
  35. self.PosX = x
  36. self.PosY = y
  37. self.Height = h -3
  38. canvas_ := self.Parent.GetCanvasHWND()
  39. rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
  40. draw.AARoundRect(canvas_,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
  41. }
  42. type ConfirmPage struct {
  43. Page
  44. ListFont *ttf.Font
  45. FileName string
  46. TrashDir string
  47. ConfirmText string
  48. BGPosX int
  49. BGPosY int
  50. BGWidth int
  51. BGHeight int
  52. Icons map[string]IconItemInterface
  53. MyList []LabelInterface
  54. }
  55. func NewConfirmPage() *ConfirmPage {
  56. p := &ConfirmPage{}
  57. p.ListFont = Fonts["veramono20"]
  58. p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
  59. p.ConfirmText ="Confirm?"
  60. return p
  61. }
  62. func (self *ConfirmPage) Reset() {
  63. self.MyList[0].SetText(self.ConfirmText)
  64. x,y := self.MyList[0].Coord()
  65. w,h := self.MyList[0].Size()
  66. self.MyList[0].NewCoord( (self.Width - w)/2, (self.Height - h)/2)
  67. x,y = self.MyList[0].Coord()
  68. self.BGPosX = x - 10
  69. self.BGPosY = y - 10
  70. self.BGWidth = w + 20
  71. self.BGHeight = h + 20
  72. }
  73. func (self *ConfirmPage) SnapMsg(msg string) {
  74. self.MyList[0].SetText(msg)
  75. x,y := self.MyList[0].Coord()
  76. w,h := self.MyList[0].Size()
  77. self.MyList[0].NewCoord( (self.Width - w )/2, (self.Height - h)/2 )
  78. x, y = self.MyList[0].Coord()
  79. self.BGPosX = x - 10
  80. self.BGPosY = y - 10
  81. self.BGWidth = w + 20
  82. self.BGHeight = h +20
  83. }
  84. func (self *ConfirmPage) Init() {
  85. if self.Screen != nil {
  86. self.PosX = self.Index * self.Screen.Width
  87. self.Width = self.Screen.Width
  88. self.Height = self.Screen.Height
  89. self.CanvasHWND = self.Screen.CanvasHWND
  90. ps := NewListPageSelector()
  91. ps.Parent = self
  92. self.Ps = ps
  93. self.PsIndex = 0
  94. li := NewLabel()
  95. li.SetCanvasHWND(self.CanvasHWND)
  96. li.Init(self.ConfirmText,self.ListFont,nil)
  97. li.PosX = (self.Width - li.Width)/2
  98. li.PosY = (self.Height - li.Height)/2
  99. self.BGPosX = li.PosX - 10
  100. self.BGPosY = li.PosY - 10
  101. self.BGWidth = li.Width + 20
  102. self.BGHeight = li.Height + 20
  103. self.MyList = append(self.MyList,li)
  104. }
  105. }
  106. func (self *ConfirmPage) KeyDown( ev *event.Event ) {
  107. if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
  108. self.ReturnToUpLevelPage()
  109. self.Screen.Draw()
  110. self.Screen.SwapAndShow()
  111. }
  112. }
  113. func (self *ConfirmPage) DrawBG() {
  114. rect_ := rect.Rect(self.BGPosX,self.BGPosY,self.BGWidth,self.BGHeight)
  115. draw.Rect(self.CanvasHWND,&color.Color{255,255,255,255}, &rect_, 0) // SkinManager().GiveColor('White')
  116. draw.Rect(self.CanvasHWND,&color.Color{83,83,83,255}, &rect_, 1)//SkinManager().GiveColor('Text')
  117. }
  118. func (self *ConfirmPage) Draw() {
  119. self.DrawBG()
  120. for _,v := range self.MyList{
  121. v.Draw()
  122. }
  123. self.Reset()
  124. }