above_all_patch.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package UI
  2. import (
  3. "github.com/veandco/go-sdl2/sdl"
  4. "github.com/veandco/go-sdl2/ttf"
  5. "github.com/cuu/gogame/color"
  6. "github.com/cuu/gogame/draw"
  7. "github.com/cuu/gogame/rect"
  8. )
  9. type AboveAllPatch struct {
  10. Widget
  11. Text string
  12. FontObj *ttf.Font
  13. Color *color.Color
  14. ValColor *color.Color
  15. CanvasHWND *sdl.Surface
  16. Icons map[string]IconItemInterface
  17. Value int
  18. }
  19. func NewAboveAllPatch() *AboveAllPatch {
  20. p := &AboveAllPatch{}
  21. p.PosX = Width / 2
  22. p.PosY = Height / 2
  23. p.Width = 50
  24. p.Height = 120
  25. p.FontObj = Fonts["veramono20"]
  26. p.Color = MySkinManager.GiveColor("Text")
  27. p.ValColor = MySkinManager.GiveColor("URL")
  28. p.Icons = make(map[string]IconItemInterface)
  29. p.Value = 0
  30. return p
  31. }
  32. func (self *AboveAllPatch) SetCanvasHWND(_canvashwnd *sdl.Surface) {
  33. self.CanvasHWND = _canvashwnd
  34. }
  35. func (self *AboveAllPatch) Draw() {
  36. start_rect := draw.MidRect(self.PosX, self.PosY, self.Width, self.Height, Width, Height)
  37. draw.AARoundRect(self.CanvasHWND, start_rect, self.Color, 3, 0, self.Color)
  38. if self.Value > 10 {
  39. vol_height := int(float64(self.Height) * (float64(self.Value) / 100.0))
  40. dheight := self.Height - vol_height
  41. vol_rect := rect.Rect(self.PosX-self.Width/2, self.PosY-self.Height/2+dheight, self.Width, vol_height)
  42. draw.AARoundRect(self.CanvasHWND, &vol_rect, self.ValColor, 3, 0, self.ValColor)
  43. } else {
  44. vol_height := 10
  45. dheight := self.Height - vol_height
  46. vol_rect := rect.Rect(self.PosX-self.Width/2, self.PosY-self.Height/2+dheight, self.Width, vol_height)
  47. draw.AARoundRect(self.CanvasHWND, &vol_rect, self.ValColor, 3, 0, self.ValColor)
  48. }
  49. }