-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.go
36 lines (30 loc) · 789 Bytes
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/sdl_ttf"
)
// text type
type Text struct {
texture *sdl.Texture
str string
font *ttf.Font
color sdl.Color
}
func NewText( font *ttf.Font, str string ) *Text {
ntxt := &Text{
nil, "", font, sdl.Color{255,255,255,255},
}
ntxt.SetString( str )
return ntxt
}
func (self *Text) SetString( str string ) {
self.str = str
self.texture.Destroy()
txsfc, _ := self.font.RenderUTF8_Blended( self.str, self.color )
self.texture, _ = Rnd.CreateTextureFromSurface( txsfc )
txsfc.Free()
}
func (self *Text) Draw( rnd *sdl.Renderer, x, y int32 ) {
_, _, tw, th, _ := self.texture.Query()
rnd.Copy( self.texture, nil, &sdl.Rect{ x, y, tw, th } )
}