scroller.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package UI
  2. import (
  3. "fmt"
  4. "github.com/veandco/go-sdl2/sdl"
  5. // "github.com/veandco/go-sdl2/ttf"
  6. // "github.com/cuu/gogame/surface"
  7. // "github.com/cuu/gogame/rect"
  8. "github.com/cuu/gogame/color"
  9. // "github.com/cuu/gogame/font"
  10. "github.com/cuu/gogame/draw"
  11. )
  12. type ListScroller struct{
  13. Widget
  14. MinHeight int
  15. Parent PageInterface
  16. Color *color.Color
  17. StartX int
  18. StartY int
  19. EndX int
  20. EndY int
  21. Value int
  22. CanvasHWND *sdl.Surface
  23. }
  24. func NewListScroller() *ListScroller {
  25. l := &ListScroller{}
  26. l.Width = 7
  27. l.Color = &color.Color{131,199,219,255} // SkinManager().GiveColor('Front')
  28. return l
  29. }
  30. func (self *ListScroller) Init() {
  31. //just set the CanvasHWND
  32. cav_ := self.Parent.GetCanvasHWND()
  33. self.SetCanvasHWND(cav_)
  34. }
  35. func (self *ListScroller) SetCanvasHWND( canvas *sdl.Surface) {
  36. self.CanvasHWND = canvas
  37. }
  38. func (self *ListScroller) AnimateDraw(x2,y2 int) {
  39. }
  40. func (self *ListScroller) UpdateSize(bigheight, dirtyheight int) {
  41. _,h_ := self.Parent.Size()
  42. bodyheight := float64(h_)/float64(bigheight)
  43. if bodyheight > 1.0 {
  44. bodyheight = 1.0
  45. }
  46. margin := 4
  47. self.Height = int( bodyheight * float64(h_) - float64(margin) )
  48. if self.Height < self.MinHeight {
  49. self.Height = self.MinHeight
  50. }
  51. self.StartX = self.Width/2
  52. self.StartY = margin/2 + self.Height/2
  53. self.EndX = self.Width/2
  54. self.EndY = h_ - margin/2 - self.Height/2
  55. process := float64(dirtyheight) / float64(bigheight)
  56. value := process * float64(self.EndY - self.StartY)
  57. self.Value = int(value)
  58. }
  59. func (self *ListScroller) Draw() {
  60. w_,h_ := self.Parent.Size()
  61. start_rect := draw.MidRect(self.PosX+self.StartX,self.StartY+self.Value,self.Width,self.Height,w_,h_)
  62. if self.Width < 1 {
  63. fmt.Println("ListScroller width error")
  64. }else {
  65. draw.AARoundRect(self.CanvasHWND,start_rect,self.Color,3,0,self.Color)
  66. }
  67. }