Merge upstream - fixed conflicts

This commit is contained in:
Zyko 2024-04-10 19:15:34 +02:00
commit c73221ac16
12 changed files with 90 additions and 29 deletions

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8
github.com/ebitengine/hideconsole v1.0.0 github.com/ebitengine/hideconsole v1.0.0
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 github.com/ebitengine/oto/v3 v3.3.0-alpha.1
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 github.com/ebitengine/purego v0.8.0-alpha.1
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 github.com/hajimehoshi/bitmapfont/v3 v3.0.0
github.com/hajimehoshi/go-mp3 v0.3.4 github.com/hajimehoshi/go-mp3 v0.3.4

4
go.sum
View File

@ -4,8 +4,8 @@ github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A= github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk= github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg= github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 h1:8mFaXjlt/DLC5MlrnsR71EpK196kVYvPTC2soh06rGU= github.com/ebitengine/purego v0.8.0-alpha.1 h1:52AgJTNaQRi7YtOtdJl4hkxNWhAGMxuDuDjOVIp5Ojk=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM= github.com/ebitengine/purego v0.8.0-alpha.1/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=

View File

@ -538,7 +538,7 @@ func (w *Window) SetOpacity(opacity float32) {
C.glfwSetWindowOpacity(w.data, C.float(opacity)) C.glfwSetWindowOpacity(w.data, C.float(opacity))
} }
// RequestWindowAttention funciton requests user attention to the specified // RequestAttention function requests user attention to the specified
// window. On platforms where this is not supported, attention is requested to // window. On platforms where this is not supported, attention is requested to
// the application as a whole. // the application as a whole.
// //

View File

@ -162,9 +162,9 @@ func (c *context) setViewport(width, height int, screen bool) {
func (c *context) newScreenFramebuffer(width, height int) *framebuffer { func (c *context) newScreenFramebuffer(width, height int) *framebuffer {
return &framebuffer{ return &framebuffer{
native: c.screenFramebuffer, native: c.screenFramebuffer,
width: width, viewportWidth: width,
height: height, viewportHeight: height,
} }
} }
@ -334,9 +334,9 @@ func (c *context) newFramebuffer(texture textureNative, width, height int) (*fra
return nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error") return nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
} }
return &framebuffer{ return &framebuffer{
native: framebufferNative(f), native: framebufferNative(f),
width: width, viewportWidth: width,
height: height, viewportHeight: height,
}, nil }, nil
} }

View File

@ -273,7 +273,7 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
g.context.bindFramebuffer(framebufferNative(f)) g.context.bindFramebuffer(framebufferNative(f))
} }
w, h := dsts[0].framebufferSize() w, h := dsts[0].framebuffer.viewportWidth, dsts[0].framebuffer.viewportHeight
g.context.setViewport(w, h, dsts[0].screen) g.context.setViewport(w, h, dsts[0].screen)
g.context.blend(blend) g.context.blend(blend)

View File

@ -37,9 +37,9 @@ type Image struct {
// framebuffer is a wrapper of OpenGL's framebuffer. // framebuffer is a wrapper of OpenGL's framebuffer.
type framebuffer struct { type framebuffer struct {
native framebufferNative native framebufferNative
width int viewportWidth int
height int viewportHeight int
} }
func (i *Image) ID() graphicsdriver.ImageID { func (i *Image) ID() graphicsdriver.ImageID {
@ -72,7 +72,7 @@ func (i *Image) ReadPixels(args []graphicsdriver.PixelsArgs) error {
return nil return nil
} }
func (i *Image) framebufferSize() (int, int) { func (i *Image) viewportSize() (int, int) {
if i.screen { if i.screen {
// The (default) framebuffer size can't be converted to a power of 2. // The (default) framebuffer size can't be converted to a power of 2.
// On browsers, i.width and i.height are used as viewport size and // On browsers, i.width and i.height are used as viewport size and
@ -87,11 +87,12 @@ func (i *Image) ensureFramebuffer() error {
return nil return nil
} }
w, h := i.framebufferSize() w, h := i.viewportSize()
if i.screen { if i.screen {
i.framebuffer = i.graphics.context.newScreenFramebuffer(w, h) i.framebuffer = i.graphics.context.newScreenFramebuffer(w, h)
return nil return nil
} }
f, err := i.graphics.context.newFramebuffer(i.texture, w, h) f, err := i.graphics.context.newFramebuffer(i.texture, w, h)
if err != nil { if err != nil {
return err return err
@ -109,7 +110,7 @@ func (i *Image) ensureStencilBuffer(f framebufferNative) error {
return err return err
}*/ }*/
r, err := i.graphics.context.newRenderbuffer(i.framebufferSize()) r, err := i.graphics.context.newRenderbuffer(i.viewportSize())
if err != nil { if err != nil {
return err return err
} }

View File

@ -1027,7 +1027,7 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
return err return err
} }
// Window is shown after the first buffer swap. // Window is shown after the first buffer swap (#2725).
if err := glfw.WindowHint(glfw.Visible, glfw.False); err != nil { if err := glfw.WindowHint(glfw.Visible, glfw.False); err != nil {
return err return err
} }
@ -1294,6 +1294,40 @@ func (u *UserInterface) update() (float64, float64, error) {
if err = u.window.Focus(); err != nil { if err = u.window.Focus(); err != nil {
return return
} }
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
return
}
// On Linux or UNIX, there is a problematic desktop environment like i3wm
// where an invisible window size cannot be initialized correctly (#2951).
// Call SetSize explicitly after the window becomes visible.
fullscreen, e := u.isFullscreen()
if e != nil {
err = e
return
}
if fullscreen {
return
}
m, e := u.currentMonitor()
if e != nil {
err = e
return
}
s := m.DeviceScaleFactor()
newW := int(dipToGLFWPixel(float64(u.origWindowWidthInDIP), s))
newH := int(dipToGLFWPixel(float64(u.origWindowHeightInDIP), s))
// Even though a framebuffer callback is not called, waitForFramebufferSizeCallback returns by timeout,
// so it is safe to use this.
if err = u.waitForFramebufferSizeCallback(u.window, func() error {
return u.window.SetSize(newW, newH)
}); err != nil {
return
}
}) })
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err

View File

@ -36,6 +36,10 @@ var _ Face = (*GoTextFace)(nil)
// GoTextFace is a Face implementation for go-text's font.Face (github.com/go-text/typesetting). // GoTextFace is a Face implementation for go-text's font.Face (github.com/go-text/typesetting).
// With a GoTextFace, shaping.HarfBuzzShaper is always used as a shaper internally. // With a GoTextFace, shaping.HarfBuzzShaper is always used as a shaper internally.
// GoTextFace includes the source and various options. // GoTextFace includes the source and various options.
//
// Unlike GoXFace, one GoTextFace instance doesn't have its own glyph image cache.
// Instead, a GoTextFaceSource has a glyph image cache.
// You can casually create multiple GoTextFace instances from the same GoTextFaceSource.
type GoTextFace struct { type GoTextFace struct {
// Source is the font face source. // Source is the font face source.
Source *GoTextFaceSource Source *GoTextFaceSource
@ -164,7 +168,7 @@ func (t Tag) String() string {
return string([]byte{byte(t >> 24), byte(t >> 16), byte(t >> 8), byte(t)}) return string([]byte{byte(t >> 24), byte(t >> 16), byte(t >> 8), byte(t)})
} }
// PraseTag converts a string to Tag. // ParseTag converts a string to Tag.
func ParseTag(str string) (Tag, error) { func ParseTag(str string) (Tag, error) {
if len(str) != 4 { if len(str) != 4 {
return 0, fmt.Errorf("text: a string's length must be 4 but was %d at ParseTag", len(str)) return 0, fmt.Errorf("text: a string's length must be 4 but was %d at ParseTag", len(str))
@ -172,7 +176,7 @@ func ParseTag(str string) (Tag, error) {
return Tag((uint32(str[0]) << 24) | (uint32(str[1]) << 16) | (uint32(str[2]) << 8) | uint32(str[3])), nil return Tag((uint32(str[0]) << 24) | (uint32(str[1]) << 16) | (uint32(str[2]) << 8) | uint32(str[3])), nil
} }
// MustPraseTag converts a string to Tag. // MustParseTag converts a string to Tag.
// If parsing fails, MustParseTag panics. // If parsing fails, MustParseTag panics.
func MustParseTag(str string) Tag { func MustParseTag(str string) Tag {
t, err := ParseTag(str) t, err := ParseTag(str)

View File

@ -37,6 +37,9 @@ type goXFaceGlyphImageCacheKey struct {
// GoXFace is a Face implementation for a semi-standard font.Face (golang.org/x/image/font). // GoXFace is a Face implementation for a semi-standard font.Face (golang.org/x/image/font).
// GoXFace is useful to transit from existing codebase with text v1, or to use some bitmap fonts defined as font.Face. // GoXFace is useful to transit from existing codebase with text v1, or to use some bitmap fonts defined as font.Face.
// GoXFace must not be copied by value. // GoXFace must not be copied by value.
//
// Unlike GoFontFace, one GoXFace instance has its own glyph image cache.
// You should reuse the same GoXFace instance as much as possible.
type GoXFace struct { type GoXFace struct {
f *faceWithCache f *faceWithCache

View File

@ -101,20 +101,24 @@ type LayoutOptions struct {
// If the vertical alignment is center, the rendering region's middle Y comes to the origin. // If the vertical alignment is center, the rendering region's middle Y comes to the origin.
// If the vertical alignment is bottom, the rendering region's bottom Y comes to the origin. // If the vertical alignment is bottom, the rendering region's bottom Y comes to the origin.
func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) { func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) {
if options == nil { var layoutOp LayoutOptions
options = &DrawOptions{} var drawOp ebiten.DrawImageOptions
if options != nil {
layoutOp = options.LayoutOptions
drawOp = options.DrawImageOptions
} }
geoM := options.GeoM geoM := drawOp.GeoM
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
for _, g := range AppendGlyphs(nil, text, face, &layoutOp) {
if g.Image == nil { if g.Image == nil {
continue continue
} }
op := &options.DrawImageOptions drawOp.GeoM.Reset()
op.GeoM.Reset() drawOp.GeoM.Translate(g.X, g.Y)
op.GeoM.Translate(g.X, g.Y) drawOp.GeoM.Concat(geoM)
op.GeoM.Concat(geoM) dst.DrawImage(g.Image, &drawOp)
dst.DrawImage(g.Image, op)
} }
} }

View File

@ -356,3 +356,18 @@ func TestConvertToFloat(t *testing.T) {
} }
} }
} }
// Issue #2954
func TestDrawOptionsNotModified(t *testing.T) {
img := ebiten.NewImage(30, 30)
op := &text.DrawOptions{}
text.Draw(img, "Hello", text.NewGoXFace(bitmapfont.Face), op)
if got, want := op.GeoM, (ebiten.GeoM{}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
if got, want := op.ColorScale, (ebiten.ColorScale{}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}