untitled_icon.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package UI
  2. import (
  3. "strings"
  4. "github.com/veandco/go-sdl2/sdl"
  5. "github.com/veandco/go-sdl2/ttf"
  6. "github.com/cuu/gogame/color"
  7. "github.com/cuu/gogame/draw"
  8. "github.com/cuu/gogame/font"
  9. "github.com/cuu/gogame/image"
  10. "github.com/cuu/gogame/surface"
  11. )
  12. type UntitledIcon struct {
  13. Widget
  14. Words []string
  15. FontObj *ttf.Font
  16. BG *sdl.Surface
  17. Color *color.Color
  18. BlankPng string
  19. Text *sdl.Surface
  20. }
  21. func NewUntitledIcon() *UntitledIcon {
  22. u := &UntitledIcon{}
  23. u.Width = 80
  24. u.Height = 80
  25. u.Words = []string{"G", "s"}
  26. u.FontObj = Fonts["varela40"]
  27. u.Color = &color.Color{83, 83, 83, 255}
  28. u.BlankPng = SkinMap("sysgo/gameshell/blank.png")
  29. return u
  30. }
  31. func (self *UntitledIcon) Init() {
  32. self.BG = image.Load(self.BlankPng)
  33. }
  34. func (self *UntitledIcon) SetWords(TwoWords ...string) {
  35. if len(TwoWords) == 1 {
  36. self.Words[0] = strings.ToUpper(TwoWords[0])
  37. }
  38. if len(TwoWords) == 2 {
  39. self.Words[0] = strings.ToUpper(TwoWords[0])
  40. self.Words[1] = strings.ToLower(TwoWords[1])
  41. self.Text = font.Render(self.FontObj, strings.Join(self.Words, ""), true, self.Color, nil)
  42. }
  43. }
  44. func (self *UntitledIcon) Draw() {
  45. if self.BG != nil {
  46. w_ := self.Text.W
  47. h_ := self.Text.H
  48. surface.Blit(self.BG, self.Text, draw.MidRect(self.Width/2, self.Height/2, int(w_), int(h_), self.Width, self.Height), nil)
  49. }
  50. }
  51. func (self *UntitledIcon) Surface() *sdl.Surface {
  52. self.Draw()
  53. return self.BG
  54. }