package ui import ( "image" "image/color" "opslag.de/schobers/geom" "opslag.de/schobers/zntg" ) type Renderer interface { // Events PushEvents(t EventTarget, wait bool) bool Refresh() // Lifetime Destroy() error // Drawing Clear(c color.Color) CreateFontPath(path string, size int) (Font, error) CreateTexture(m ImageSource) (Texture, error) CreateTextureGo(m image.Image, source bool) (Texture, error) CreateTexturePath(path string, source bool) (Texture, error) CreateTextureTarget(w, h float32) (Texture, error) DefaultTarget() Texture DrawTexture(t Texture, p geom.RectangleF32) DrawTextureOptions(t Texture, p geom.RectangleF32, opts DrawOptions) DrawTexturePoint(t Texture, p geom.PointF32) DrawTexturePointOptions(t Texture, p geom.PointF32, opts DrawOptions) FillRectangle(r geom.RectangleF32, c color.Color) Line(p, q geom.PointF32, color color.Color, thickness float32) Rectangle(r geom.RectangleF32, c color.Color, thickness float32) RenderTo(Texture) RenderToDisplay() Resize(width, height int) SetIcon(source ImageSource) SetMouseCursor(c MouseCursor) Size() geom.Point Target() Texture Text(font Font, p geom.PointF32, color color.Color, text string) TextAlign(font Font, p geom.PointF32, color color.Color, text string, align HorizontalAlignment) TextTexture(font Font, color color.Color, text string) (Texture, error) // Resources Resources() Resources SetResourceProvider(resources Resources) } // TextTexture renders specified text to a new texture. func TextTexture(render Renderer, font Font, color color.Color, text string) (Texture, error) { target := render.Target() defer render.RenderTo(target) bounds := font.Measure(text) texture, err := render.CreateTextureTarget(bounds.Dx(), bounds.Dy()) if err != nil { return nil, err } render.RenderTo(texture) render.Clear(zntg.MustHexColor(`#00000000`)) render.Text(font, bounds.Min.Invert(), color, text) return texture, nil }