mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
e7fa9d50de
commit
147175d400
@ -48,7 +48,7 @@ func drawTextWithShadow(rt *ebiten.Image, str string, x, y, scale int, clr color
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(float64(x)+1, float64(y)+1)
|
||||
op.ColorScale.ScaleWithColor(shadowColor)
|
||||
op.LineHeight = arcadeFontBaseSize * float64(scale)
|
||||
op.LineSpacingInPixels = arcadeFontBaseSize * float64(scale)
|
||||
op.PrimaryAlign = primaryAlign
|
||||
op.SecondaryAlign = secondaryAlign
|
||||
text.Draw(rt, str, &text.GoTextFace{
|
||||
|
@ -277,7 +277,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(screenWidth/2, 3*titleFontSize)
|
||||
op.ColorScale.ScaleWithColor(color.White)
|
||||
op.LineHeight = titleFontSize
|
||||
op.LineSpacingInPixels = titleFontSize
|
||||
op.PrimaryAlign = text.AlignCenter
|
||||
text.Draw(screen, titleTexts, &text.GoTextFace{
|
||||
Source: arcadeFaceSource,
|
||||
@ -287,7 +287,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
op = &text.DrawOptions{}
|
||||
op.GeoM.Translate(screenWidth/2, 3*titleFontSize)
|
||||
op.ColorScale.ScaleWithColor(color.White)
|
||||
op.LineHeight = fontSize
|
||||
op.LineSpacingInPixels = fontSize
|
||||
op.PrimaryAlign = text.AlignCenter
|
||||
text.Draw(screen, texts, &text.GoTextFace{
|
||||
Source: arcadeFaceSource,
|
||||
@ -300,7 +300,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(screenWidth/2, screenHeight-smallFontSize/2)
|
||||
op.ColorScale.ScaleWithColor(color.White)
|
||||
op.LineHeight = smallFontSize
|
||||
op.LineSpacingInPixels = smallFontSize
|
||||
op.PrimaryAlign = text.AlignCenter
|
||||
op.SecondaryAlign = text.AlignEnd
|
||||
text.Draw(screen, msg, &text.GoTextFace{
|
||||
@ -312,7 +312,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
op = &text.DrawOptions{}
|
||||
op.GeoM.Translate(screenWidth, 0)
|
||||
op.ColorScale.ScaleWithColor(color.White)
|
||||
op.LineHeight = fontSize
|
||||
op.LineSpacingInPixels = fontSize
|
||||
op.PrimaryAlign = text.AlignEnd
|
||||
text.Draw(screen, fmt.Sprintf("%04d", g.score()), &text.GoTextFace{
|
||||
Source: arcadeFaceSource,
|
||||
|
@ -93,7 +93,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
|
||||
// Use bitmapfont.Face instead of ebitenutil.DebugPrint, since some key names might not be printed with DebugPrint.
|
||||
textOp := &text.DrawOptions{}
|
||||
textOp.LineHeight = fontFace.Metrics().Height
|
||||
textOp.LineSpacingInPixels = fontFace.Metrics().Height
|
||||
text.Draw(screen, strings.Join(keyStrs, ", ")+"\n"+strings.Join(keyNames, ", "), fontFace, textOp)
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (g *Game) Update() error {
|
||||
// Initialize the glyphs for special (colorful) rendering.
|
||||
if len(g.glyphs) == 0 {
|
||||
op := &text.LayoutOptions{}
|
||||
op.LineHeight = mplusNormalFace.Metrics().Height
|
||||
op.LineSpacingInPixels = mplusNormalFace.Metrics().Height
|
||||
g.glyphs = text.AppendGlyphs(g.glyphs, sampleText, mplusNormalFace, op)
|
||||
}
|
||||
return nil
|
||||
@ -83,7 +83,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(x, y)
|
||||
op.LineHeight = mplusNormalFace.Metrics().Height
|
||||
op.LineSpacingInPixels = mplusNormalFace.Metrics().Height
|
||||
text.Draw(screen, sampleText, mplusNormalFace, op)
|
||||
}
|
||||
{
|
||||
@ -92,7 +92,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(x, y)
|
||||
op.LineHeight = mplusBigFace.Metrics().Height
|
||||
op.LineSpacingInPixels = mplusBigFace.Metrics().Height
|
||||
text.Draw(screen, sampleText, mplusBigFace, op)
|
||||
}
|
||||
{
|
||||
@ -101,19 +101,19 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
op.GeoM.Rotate(math.Pi / 4)
|
||||
op.GeoM.Translate(x, y)
|
||||
op.Filter = ebiten.FilterLinear
|
||||
op.LineHeight = mplusNormalFace.Metrics().Height
|
||||
op.LineSpacingInPixels = mplusNormalFace.Metrics().Height
|
||||
text.Draw(screen, sampleText, mplusNormalFace, op)
|
||||
}
|
||||
{
|
||||
const x, y = 160, 220
|
||||
const lineHeight = 80
|
||||
w, h := text.Measure(sampleText, mplusBigFace, lineHeight)
|
||||
const lineSpacingInPixels = 80
|
||||
w, h := text.Measure(sampleText, mplusBigFace, lineSpacingInPixels)
|
||||
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
|
||||
op := &text.DrawOptions{}
|
||||
// Add the width as the text rendering region's upper-right position comes to (0, 0)
|
||||
// when the horizontal alignment is right. The alignment is specified later (PrimaryAlign).
|
||||
op.GeoM.Translate(x+w, y)
|
||||
op.LineHeight = lineHeight
|
||||
op.LineSpacingInPixels = lineSpacingInPixels
|
||||
// The primary alignment for the left-to-right direction is a horizontal alignment, and the end means the right.
|
||||
op.PrimaryAlign = text.AlignEnd
|
||||
text.Draw(screen, sampleText, mplusBigFace, op)
|
||||
|
@ -126,7 +126,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(screenWidth-20, 210)
|
||||
op.LineHeight = 48
|
||||
op.LineSpacingInPixels = 48
|
||||
text.Draw(screen, japaneseText, &text.GoTextFace{
|
||||
Source: japaneseFaceSource,
|
||||
Direction: text.DirectionTopToBottomAndRightToLeft,
|
||||
|
@ -91,7 +91,7 @@ func (t *TextField) textIndexByCursorPosition(x, y int) (int, bool) {
|
||||
y = 0
|
||||
}
|
||||
|
||||
lineHeight := int(fontFace.Metrics().Height)
|
||||
lineSpacingInPixels := int(fontFace.Metrics().Height)
|
||||
var nlCount int
|
||||
var lineStart int
|
||||
var prevAdvance float64
|
||||
@ -113,7 +113,7 @@ func (t *TextField) textIndexByCursorPosition(x, y int) (int, bool) {
|
||||
} else {
|
||||
x1 = int(currentAdvance)
|
||||
}
|
||||
if x0 <= x && x < x1 && nlCount*lineHeight <= y && y < (nlCount+1)*lineHeight {
|
||||
if x0 <= x && x < x1 && nlCount*lineSpacingInPixels <= y && y < (nlCount+1)*lineSpacingInPixels {
|
||||
return i, true
|
||||
}
|
||||
prevAdvance = currentAdvance
|
||||
@ -288,7 +288,7 @@ func (t *TextField) Draw(screen *ebiten.Image) {
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(float64(tx), float64(ty))
|
||||
op.ColorScale.ScaleWithColor(color.Black)
|
||||
op.LineHeight = fontFace.Metrics().Height
|
||||
op.LineSpacingInPixels = fontFace.Metrics().Height
|
||||
text.Draw(screen, shownText, fontFace, op)
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
uiFontSize = 12
|
||||
lineHeight = 16
|
||||
uiFontSize = 12
|
||||
lineSpacingInPixels = 16
|
||||
)
|
||||
|
||||
var (
|
||||
@ -180,7 +180,7 @@ func (b *Button) Draw(dst *ebiten.Image) {
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(float64(b.Rect.Min.X+b.Rect.Max.X)/2, float64(b.Rect.Min.Y+b.Rect.Max.Y)/2)
|
||||
op.ColorScale.ScaleWithColor(color.Black)
|
||||
op.LineHeight = lineHeight
|
||||
op.LineSpacingInPixels = lineSpacingInPixels
|
||||
op.PrimaryAlign = text.AlignCenter
|
||||
op.SecondaryAlign = text.AlignCenter
|
||||
text.Draw(dst, b.Text, &text.GoTextFace{
|
||||
@ -319,7 +319,7 @@ func (t *TextBox) Update() {
|
||||
}
|
||||
|
||||
func (t *TextBox) contentSize() (int, int) {
|
||||
h := len(strings.Split(t.Text, "\n"))*lineHeight + textBoxPaddingTop
|
||||
h := len(strings.Split(t.Text, "\n"))*lineSpacingInPixels + textBoxPaddingTop
|
||||
return t.Rect.Dx(), h
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
|
||||
textOp.GeoM.Translate(x, y)
|
||||
textOp.GeoM.Translate(float64(t.Rect.Min.X), float64(t.Rect.Min.Y))
|
||||
textOp.ColorScale.ScaleWithColor(color.Black)
|
||||
textOp.LineHeight = lineHeight
|
||||
textOp.LineSpacingInPixels = lineSpacingInPixels
|
||||
text.Draw(dst.SubImage(t.Rect).(*ebiten.Image), t.Text, &text.GoTextFace{
|
||||
Source: uiFaceSource,
|
||||
Size: uiFontSize,
|
||||
@ -409,7 +409,7 @@ func (c *CheckBox) Draw(dst *ebiten.Image) {
|
||||
op := &text.DrawOptions{}
|
||||
op.GeoM.Translate(float64(x), float64(y))
|
||||
op.ColorScale.ScaleWithColor(color.Black)
|
||||
op.LineHeight = lineHeight
|
||||
op.LineSpacingInPixels = lineSpacingInPixels
|
||||
op.PrimaryAlign = text.AlignStart
|
||||
op.SecondaryAlign = text.AlignCenter
|
||||
text.Draw(dst, c.Text, &text.GoTextFace{
|
||||
|
@ -45,8 +45,8 @@ type DrawOptions struct {
|
||||
// PrimaryAlign and SecondaryAlign determine where to put the text in the given region at Draw.
|
||||
// Draw might render the text outside of the specified image bounds, so you might have to specify GeoM to make the text visible.
|
||||
type LayoutOptions struct {
|
||||
// LineHeight is a line height in pixels.
|
||||
LineHeight float64
|
||||
// LineSpacingInPixels is a distance between two adjacent lines's baselines.
|
||||
LineSpacingInPixels float64
|
||||
|
||||
// PrimaryAlign is an alignment of the primary direction, in which a text in one line is rendered.
|
||||
// The primary direction is the horizontal direction for a horizontal-direction face,
|
||||
@ -162,9 +162,9 @@ func appendGlyphs(glyphs []Glyph, text string, face Face, x, y float64, options
|
||||
var boundaryWidth, boundaryHeight float64
|
||||
if d.isHorizontal() {
|
||||
boundaryWidth = longestAdvance
|
||||
boundaryHeight = float64(lineCount-1)*options.LineHeight + m.HAscent + m.HDescent
|
||||
boundaryHeight = float64(lineCount-1)*options.LineSpacingInPixels + m.HAscent + m.HDescent
|
||||
} else {
|
||||
boundaryWidth = float64(lineCount-1)*options.LineHeight + m.VAscent + m.VDescent
|
||||
boundaryWidth = float64(lineCount-1)*options.LineSpacingInPixels + m.VAscent + m.VDescent
|
||||
boundaryHeight = longestAdvance
|
||||
}
|
||||
|
||||
@ -244,13 +244,13 @@ func appendGlyphs(glyphs []Glyph, text string, face Face, x, y float64, options
|
||||
// Advance the origin position in the secondary direction.
|
||||
switch face.direction() {
|
||||
case DirectionLeftToRight:
|
||||
originY += options.LineHeight
|
||||
originY += options.LineSpacingInPixels
|
||||
case DirectionRightToLeft:
|
||||
originY += options.LineHeight
|
||||
originY += options.LineSpacingInPixels
|
||||
case DirectionTopToBottomAndLeftToRight:
|
||||
originX += options.LineHeight
|
||||
originX += options.LineSpacingInPixels
|
||||
case DirectionTopToBottomAndRightToLeft:
|
||||
originX -= options.LineHeight
|
||||
originX -= options.LineSpacingInPixels
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ func (d Direction) isHorizontal() bool {
|
||||
// With a vertical direction face, the width and the height are calculated in an opposite manner.
|
||||
//
|
||||
// Measure is concurrent-safe.
|
||||
func Measure(text string, face Face, lineHeight float64) (width, height float64) {
|
||||
func Measure(text string, face Face, lineSpacingInPixels float64) (width, height float64) {
|
||||
if text == "" {
|
||||
return 0, 0
|
||||
}
|
||||
@ -218,10 +218,10 @@ func Measure(text string, face Face, lineHeight float64) (width, height float64)
|
||||
m := face.Metrics()
|
||||
|
||||
if face.direction().isHorizontal() {
|
||||
secondary := float64(lineCount-1)*lineHeight + m.HAscent + m.HDescent
|
||||
secondary := float64(lineCount-1)*lineSpacingInPixels + m.HAscent + m.HDescent
|
||||
return primary, secondary
|
||||
}
|
||||
secondary := float64(lineCount-1)*lineHeight + m.VAscent + m.VDescent
|
||||
secondary := float64(lineCount-1)*lineSpacingInPixels + m.VAscent + m.VDescent
|
||||
return secondary, primary
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user