untitled_icon.go 1.4 KB

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