2019-03-05 20:52:18 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
"opslag.de/schobers/geom"
|
2020-05-22 15:42:02 +00:00
|
|
|
"opslag.de/schobers/zntg"
|
2019-03-05 20:52:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Renderer interface {
|
|
|
|
// Events
|
2020-05-17 19:02:07 +00:00
|
|
|
PushEvents(t EventTarget, wait bool) bool
|
2019-03-06 17:18:35 +00:00
|
|
|
Refresh()
|
2019-03-05 20:52:18 +00:00
|
|
|
|
|
|
|
// Lifetime
|
|
|
|
Destroy() error
|
|
|
|
|
|
|
|
// Drawing
|
|
|
|
Clear(c color.Color)
|
2020-05-15 13:42:24 +00:00
|
|
|
CreateFontPath(path string, size int) (Font, error)
|
2020-05-15 07:20:44 +00:00
|
|
|
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
|
2020-05-17 09:12:45 +00:00
|
|
|
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)
|
2019-03-05 20:52:18 +00:00
|
|
|
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)
|
2019-03-05 20:52:18 +00:00
|
|
|
Rectangle(r geom.RectangleF32, c color.Color, thickness float32)
|
2020-05-12 21:03:43 +00:00
|
|
|
RenderTo(Texture)
|
2019-03-05 20:52:18 +00:00
|
|
|
RenderToDisplay()
|
2020-12-12 13:40:50 +00:00
|
|
|
Resize(width, height int)
|
|
|
|
SetIcon(source ImageSource)
|
2019-03-11 16:30:41 +00:00
|
|
|
SetMouseCursor(c MouseCursor)
|
2020-12-12 13:40:50 +00:00
|
|
|
Size() geom.Point
|
2020-05-12 21:03:43 +00:00
|
|
|
Target() Texture
|
2020-05-15 13:42:24 +00:00
|
|
|
Text(font Font, p geom.PointF32, color color.Color, text string)
|
|
|
|
TextAlign(font Font, p geom.PointF32, color color.Color, text string, align HorizontalAlignment)
|
2020-05-22 15:42:02 +00:00
|
|
|
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
|
2020-07-07 16:19:34 +00:00
|
|
|
SetResourceProvider(resources Resources)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
2020-05-22 15:42:02 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|