multi_icon_item.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package UI
  2. import (
  3. "fmt"
  4. "github.com/cuu/gogame/surface"
  5. "github.com/cuu/gogame/image"
  6. "github.com/cuu/gogame/draw"
  7. "github.com/cuu/gogame/rect"
  8. )
  9. type MultiIconItem struct {
  10. IconItem
  11. IconWidth int
  12. IconHeight int
  13. }
  14. func NewMultiIconItem() *MultiIconItem {
  15. m := &MultiIconItem{}
  16. m.IconIndex = 0
  17. m.IconWidth = 18
  18. m.IconHeight = 18
  19. return m
  20. }
  21. func (self * MultiIconItem) CreateImgSurf() {
  22. if self.ImgSurf == nil && self.ImageName != "" {
  23. self.ImgSurf = image.Load(self.ImageName)
  24. }
  25. }
  26. func (self *MultiIconItem) Draw() {
  27. if self.Parent == nil {
  28. fmt.Println("Error: MultiIconItem Draw Parent nil")
  29. return
  30. }
  31. parent_x,parent_y := self.Parent.Coord()
  32. if self.Label != nil {
  33. // lab_x,lab_y := self.Label.Coord()
  34. lab_w,lab_h:= self.Label.Size()
  35. if self.Align == ALIGN["VCenter"] {
  36. self.Label.NewCoord( self.PosX - lab_w/2 + parent_x, self.PosY + self.Height/2+6 + parent_y)
  37. }else if self.Align == ALIGN["HLeft"] {
  38. self.Label.NewCoord( self.PosX + self.Width/2+3 + parent_x, self.PosY - lab_h/2 + parent_y )
  39. }
  40. self.Label.Draw()
  41. }
  42. if self.ImgSurf != nil {
  43. portion := rect.Rect(0,self.IconIndex*self.IconHeight,self.IconWidth,self.IconHeight)
  44. surface.Blit(self.Parent.GetCanvasHWND(),
  45. self.ImgSurf,draw.MidRect(self.PosX + parent_x, self.PosY + parent_y,
  46. self.Width,self.Height, Width, Height),&portion)
  47. }
  48. }