mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
1 Commits
d091bf72d8
...
804f024424
Author | SHA1 | Date | |
---|---|---|---|
|
804f024424 |
@ -21,9 +21,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||||
)
|
)
|
||||||
@ -60,8 +58,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
glyphs []text.Glyph
|
counter int
|
||||||
showOrigins bool
|
kanjiText []rune
|
||||||
|
kanjiTextColor color.RGBA
|
||||||
|
glyphs []text.Glyph
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
@ -71,15 +71,10 @@ func (g *Game) Update() error {
|
|||||||
op.LineSpacing = mplusNormalFace.Size * 1.5
|
op.LineSpacing = mplusNormalFace.Size * 1.5
|
||||||
g.glyphs = text.AppendGlyphs(g.glyphs, sampleText, mplusNormalFace, op)
|
g.glyphs = text.AppendGlyphs(g.glyphs, sampleText, mplusNormalFace, op)
|
||||||
}
|
}
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyO) {
|
|
||||||
g.showOrigins = !g.showOrigins
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
ebitenutil.DebugPrint(screen, "Press O to show/hide origins")
|
|
||||||
|
|
||||||
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -152,12 +147,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op.ColorScale.Scale(r, g, b, 1)
|
op.ColorScale.Scale(r, g, b, 1)
|
||||||
screen.DrawImage(gl.Image, op)
|
screen.DrawImage(gl.Image, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
for _, gl := range g.glyphs {
|
|
||||||
vector.DrawFilledCircle(screen, x+float32(gl.OriginX), y+float32(gl.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ import (
|
|||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||||
)
|
)
|
||||||
@ -111,19 +109,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
showOrigins bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyO) {
|
|
||||||
g.showOrigins = !g.showOrigins
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
ebitenutil.DebugPrint(screen, "Press O to show/hide origins")
|
|
||||||
|
|
||||||
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -141,13 +133,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op := &text.DrawOptions{}
|
op := &text.DrawOptions{}
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
text.Draw(screen, arabicText, f, op)
|
text.Draw(screen, arabicText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
for _, g := range text.AppendGlyphs(nil, arabicText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const hindiText = "चूंकि मानव परिवार के सभी सदस्यों के जन्मजात गौरव और समान"
|
const hindiText = "चूंकि मानव परिवार के सभी सदस्यों के जन्मजात गौरव और समान"
|
||||||
@ -162,13 +147,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op := &text.DrawOptions{}
|
op := &text.DrawOptions{}
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
text.Draw(screen, hindiText, f, op)
|
text.Draw(screen, hindiText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
for _, g := range text.AppendGlyphs(nil, hindiText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const myanmarText = "လူခပ်သိမ်း၏ မျိုးရိုးဂုဏ်သိက္ခာနှင့်တကွ"
|
const myanmarText = "လူခပ်သိမ်း၏ မျိုးရိုးဂုဏ်သိက္ခာနှင့်တကွ"
|
||||||
@ -183,13 +161,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op := &text.DrawOptions{}
|
op := &text.DrawOptions{}
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
text.Draw(screen, myanmarText, f, op)
|
text.Draw(screen, myanmarText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
for _, g := range text.AppendGlyphs(nil, myanmarText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const thaiText = "โดยที่การยอมรับนับถือเกียรติศักดิ์ประจำตัว"
|
const thaiText = "โดยที่การยอมรับนับถือเกียรติศักดิ์ประจำตัว"
|
||||||
@ -204,13 +175,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op := &text.DrawOptions{}
|
op := &text.DrawOptions{}
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
text.Draw(screen, thaiText, f, op)
|
text.Draw(screen, thaiText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
for _, g := range text.AppendGlyphs(nil, thaiText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const mongolianText = "ᠬᠦᠮᠦᠨ ᠪᠦᠷ ᠲᠥᠷᠥᠵᠦ ᠮᠡᠨᠳᠡᠯᠡᠬᠦ\nᠡᠷᠬᠡ ᠴᠢᠯᠥᠭᠡ ᠲᠡᠢ᠂ ᠠᠳᠠᠯᠢᠬᠠᠨ"
|
const mongolianText = "ᠬᠦᠮᠦᠨ ᠪᠦᠷ ᠲᠥᠷᠥᠵᠦ ᠮᠡᠨᠳᠡᠯᠡᠬᠦ\nᠡᠷᠬᠡ ᠴᠢᠯᠥᠭᠡ ᠲᠡᠢ᠂ ᠠᠳᠠᠯᠢᠬᠠᠨ"
|
||||||
@ -230,14 +194,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
op.LineSpacing = lineSpacing
|
op.LineSpacing = lineSpacing
|
||||||
text.Draw(screen, mongolianText, f, op)
|
text.Draw(screen, mongolianText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
op.LineSpacing = lineSpacing
|
|
||||||
for _, g := range text.AppendGlyphs(nil, mongolianText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const japaneseText = "あのイーハトーヴォの\nすきとおった風、\n夏でも底に冷たさを\nもつ青いそら…\nあHello World.あ"
|
const japaneseText = "あのイーハトーヴォの\nすきとおった風、\n夏でも底に冷たさを\nもつ青いそら…\nあHello World.あ"
|
||||||
@ -256,14 +212,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
op.LineSpacing = lineSpacing
|
op.LineSpacing = lineSpacing
|
||||||
text.Draw(screen, japaneseText, f, op)
|
text.Draw(screen, japaneseText, f, op)
|
||||||
|
|
||||||
if g.showOrigins {
|
|
||||||
op := &text.LayoutOptions{}
|
|
||||||
op.LineSpacing = lineSpacing
|
|
||||||
for _, g := range text.AppendGlyphs(nil, japaneseText, f, op) {
|
|
||||||
vector.DrawFilledCircle(screen, float32(x)+float32(g.OriginX), float32(y)+float32(g.OriginY), 2, color.RGBA{0xff, 0, 0, 0xff}, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,11 +304,10 @@ func (g *GoTextFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffse
|
|||||||
}
|
}
|
||||||
_, gs := g.Source.shape(line, g)
|
_, gs := g.Source.shape(line, g)
|
||||||
for _, glyph := range gs {
|
for _, glyph := range gs {
|
||||||
o := origin.Add(fixed.Point26_6{
|
img, imgX, imgY := g.glyphImage(glyph, origin.Add(fixed.Point26_6{
|
||||||
X: glyph.shapingGlyph.XOffset,
|
X: glyph.shapingGlyph.XOffset,
|
||||||
Y: -glyph.shapingGlyph.YOffset,
|
Y: -glyph.shapingGlyph.YOffset,
|
||||||
})
|
}))
|
||||||
img, imgX, imgY := g.glyphImage(glyph, o)
|
|
||||||
// Append a glyph even if img is nil.
|
// Append a glyph even if img is nil.
|
||||||
// This is necessary to return index information for control characters.
|
// This is necessary to return index information for control characters.
|
||||||
var ebitenImage *ebiten.Image
|
var ebitenImage *ebiten.Image
|
||||||
@ -323,8 +322,6 @@ func (g *GoTextFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffse
|
|||||||
Image: ebitenImage,
|
Image: ebitenImage,
|
||||||
X: float64(imgX),
|
X: float64(imgX),
|
||||||
Y: float64(imgY),
|
Y: float64(imgY),
|
||||||
OriginX: fixed26_6ToFloat64(o.X),
|
|
||||||
OriginY: fixed26_6ToFloat64(o.Y),
|
|
||||||
})
|
})
|
||||||
origin = origin.Add(fixed.Point26_6{
|
origin = origin.Add(fixed.Point26_6{
|
||||||
X: glyph.shapingGlyph.XAdvance,
|
X: glyph.shapingGlyph.XAdvance,
|
||||||
|
@ -124,8 +124,6 @@ func (s *GoXFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffset i
|
|||||||
Image: img.Image(),
|
Image: img.Image(),
|
||||||
X: float64(imgX),
|
X: float64(imgX),
|
||||||
Y: float64(imgY),
|
Y: float64(imgY),
|
||||||
OriginX: fixed26_6ToFloat64(origin.X),
|
|
||||||
OriginY: fixed26_6ToFloat64(origin.Y),
|
|
||||||
})
|
})
|
||||||
origin.X += a
|
origin.X += a
|
||||||
prevR = r
|
prevR = r
|
||||||
|
@ -146,12 +146,6 @@ type Glyph struct {
|
|||||||
// The position is determined in a sequence of characters given at AppendGlyphs.
|
// The position is determined in a sequence of characters given at AppendGlyphs.
|
||||||
// The position's origin is the first character's origin position.
|
// The position's origin is the first character's origin position.
|
||||||
Y float64
|
Y float64
|
||||||
|
|
||||||
// OriginX is the X position of the origin of this glyph.
|
|
||||||
OriginX float64
|
|
||||||
|
|
||||||
// OriginY is the Y position of the origin of this glyph.
|
|
||||||
OriginY float64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance returns the advanced distance from the origin position when rendering the given text with the given face.
|
// Advance returns the advanced distance from the origin position when rendering the given text with the given face.
|
||||||
|
Loading…
Reference in New Issue
Block a user