mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
text: Remove 'lineHeight' argument
This commit is contained in:
parent
e0d0f477dc
commit
20a43a88e8
@ -22,6 +22,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
@ -150,9 +151,11 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
|
||||
const x = 20
|
||||
text.Draw(screen, mplusNormalFont, msg, x, 40, 30, color.White)
|
||||
text.Draw(screen, mplusNormalFont, sampleText, x, 80, 30, color.White)
|
||||
text.Draw(screen, mplusBigFont, string(kanjiText), x, 160, 54, codeToColor(kanjiText[0]))
|
||||
text.Draw(screen, mplusNormalFont, msg, x, 40, color.White)
|
||||
text.Draw(screen, mplusNormalFont, sampleText, x, 80, color.White)
|
||||
for i, line := range strings.Split(string(kanjiText), "\n") {
|
||||
text.Draw(screen, mplusBigFont, line, x, 160+54*i, codeToColor(kanjiText[0]))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
13
text/text.go
13
text/text.go
@ -256,35 +256,24 @@ var textM sync.Mutex
|
||||
//
|
||||
// face is the font for text rendering.
|
||||
// (x, y) represents a 'dot' position. Be careful that this doesn't represent left-upper corner position.
|
||||
// lineHeight is the Y offset for line spacing.
|
||||
// clr is the color for text rendering.
|
||||
//
|
||||
// Glyphs used for rendering are cached in least-recently-used way.
|
||||
// It is OK to call this function with a same text and a same face at every frame.
|
||||
//
|
||||
// This function is concurrent-safe.
|
||||
func Draw(dst *ebiten.Image, face font.Face, text string, x, y int, lineHeight int, clr color.Color) {
|
||||
func Draw(dst *ebiten.Image, face font.Face, text string, x, y int, clr color.Color) {
|
||||
textM.Lock()
|
||||
|
||||
n := now()
|
||||
fx := fixed.I(x)
|
||||
ofx := fx
|
||||
prevC := rune(-1)
|
||||
|
||||
runes := []rune(text)
|
||||
for _, c := range runes {
|
||||
// TODO: What if c is '\r'?
|
||||
if c == '\n' {
|
||||
fx = ofx
|
||||
y += lineHeight
|
||||
prevC = rune(-1)
|
||||
continue
|
||||
}
|
||||
|
||||
if prevC >= 0 {
|
||||
fx += face.Kern(prevC, c)
|
||||
}
|
||||
|
||||
if g := getGlyphFromCache(face, c, n); g != nil {
|
||||
if !g.empty() {
|
||||
g.draw(dst, fx.Ceil(), y, clr)
|
||||
|
Loading…
Reference in New Issue
Block a user