mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
text: Refactoring: create glyph object in appendGlyph
This commit is contained in:
parent
28934c4fd2
commit
94c4a76dcf
20
text/text.go
20
text/text.go
@ -153,7 +153,11 @@ func (a *atlas) maxGlyphNum() int {
|
||||
return xnum * ynum
|
||||
}
|
||||
|
||||
func (a *atlas) append(g *glyph) {
|
||||
func (a *atlas) appendGlyph(face font.Face, rune rune, now int64) *glyph {
|
||||
g := &glyph{
|
||||
char: char{face, rune},
|
||||
atime: now,
|
||||
}
|
||||
if len(a.charToGlyph) == a.maxGlyphNum() {
|
||||
var oldest *glyph
|
||||
t := int64(math.MaxInt64)
|
||||
@ -175,6 +179,7 @@ func (a *atlas) append(g *glyph) {
|
||||
}
|
||||
a.charToGlyph[g.char] = g
|
||||
a.draw(g)
|
||||
return g
|
||||
}
|
||||
|
||||
func (a *atlas) draw(glyph *glyph) {
|
||||
@ -213,12 +218,8 @@ func getGlyphFromCache(face font.Face, r rune, now int64) *glyph {
|
||||
}
|
||||
}
|
||||
|
||||
g := &glyph{
|
||||
char: ch,
|
||||
atime: now,
|
||||
}
|
||||
if ch.empty() {
|
||||
return g
|
||||
return nil
|
||||
}
|
||||
|
||||
if !ok {
|
||||
@ -236,14 +237,13 @@ func getGlyphFromCache(face font.Face, r rune, now int64) *glyph {
|
||||
i, _ := ebiten.NewImage(size, size, ebiten.FilterNearest)
|
||||
a = &atlas{
|
||||
image: i,
|
||||
glyphSize: g.char.atlasGroup(),
|
||||
glyphSize: ch.atlasGroup(),
|
||||
charToGlyph: map[char]*glyph{},
|
||||
}
|
||||
atlases[g.char.atlasGroup()] = a
|
||||
atlases[ch.atlasGroup()] = a
|
||||
}
|
||||
|
||||
a.append(g)
|
||||
return g
|
||||
return a.appendGlyph(ch.face, ch.rune, now)
|
||||
}
|
||||
|
||||
var textM sync.Mutex
|
||||
|
Loading…
Reference in New Issue
Block a user