multi_icon_item.go 1.3 KB

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