mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +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
|
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() {
|
if len(a.charToGlyph) == a.maxGlyphNum() {
|
||||||
var oldest *glyph
|
var oldest *glyph
|
||||||
t := int64(math.MaxInt64)
|
t := int64(math.MaxInt64)
|
||||||
@ -175,6 +179,7 @@ func (a *atlas) append(g *glyph) {
|
|||||||
}
|
}
|
||||||
a.charToGlyph[g.char] = g
|
a.charToGlyph[g.char] = g
|
||||||
a.draw(g)
|
a.draw(g)
|
||||||
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *atlas) draw(glyph *glyph) {
|
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() {
|
if ch.empty() {
|
||||||
return g
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -236,14 +237,13 @@ func getGlyphFromCache(face font.Face, r rune, now int64) *glyph {
|
|||||||
i, _ := ebiten.NewImage(size, size, ebiten.FilterNearest)
|
i, _ := ebiten.NewImage(size, size, ebiten.FilterNearest)
|
||||||
a = &atlas{
|
a = &atlas{
|
||||||
image: i,
|
image: i,
|
||||||
glyphSize: g.char.atlasGroup(),
|
glyphSize: ch.atlasGroup(),
|
||||||
charToGlyph: map[char]*glyph{},
|
charToGlyph: map[char]*glyph{},
|
||||||
}
|
}
|
||||||
atlases[g.char.atlasGroup()] = a
|
atlases[ch.atlasGroup()] = a
|
||||||
}
|
}
|
||||||
|
|
||||||
a.append(g)
|
return a.appendGlyph(ch.face, ch.rune, now)
|
||||||
return g
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var textM sync.Mutex
|
var textM sync.Mutex
|
||||||
|
Loading…
Reference in New Issue
Block a user