zntg/ui/renderer.go

65 lines
1.9 KiB
Go
Raw Normal View History

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)
2020-05-12 21:03:43 +00:00
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)
2021-03-23 11:31:31 +00:00
Line(p, q geom.PointF32, color color.Color, thickness float32)
Rectangle(r geom.RectangleF32, c color.Color, thickness float32)
2020-05-12 21:03:43 +00:00
RenderTo(Texture)
RenderToDisplay()
Resize(width, height int)
SetIcon(source ImageSource)
2019-03-11 16:30:41 +00:00
SetMouseCursor(c MouseCursor)
Size() geom.Point
2020-05-12 21:03:43 +00:00
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)
2021-06-01 19:14:51 +00:00
WindowHandle() uintptr
2020-05-15 12:20:07 +00:00
// 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
}