Added Resize & SetIcon to Renderer.
Refactored Size (on Renderer) to return geom.Point instead of geom.PointF32.
This commit is contained in:
parent
de87c5d3aa
commit
44220c8f9a
@ -180,7 +180,7 @@ func (r *Renderer) CreateFontPath(path string, size int) (ui.Font, error) {
|
|||||||
return &font{f}, nil
|
return &font{f}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Texture, error) {
|
func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (*texture, error) {
|
||||||
im, err := source.CreateImage()
|
im, err := source.CreateImage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -314,15 +314,23 @@ func (r *Renderer) RenderToDisplay() {
|
|||||||
r.disp.SetAsTarget()
|
r.disp.SetAsTarget()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) Resources() ui.Resources { return r.res }
|
func (r *Renderer) Resize(width, height int) {
|
||||||
|
r.disp.Resize(width, height)
|
||||||
func (r *Renderer) Size() geom.PointF32 {
|
|
||||||
return geom.PtF32(float32(r.disp.Width()), float32(r.disp.Height()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) SetIcon(texture ui.Texture) {
|
func (r *Renderer) Resources() ui.Resources { return r.res }
|
||||||
bmp := r.mustGetBitmap(texture)
|
|
||||||
r.disp.SetIcon(bmp)
|
func (r *Renderer) Size() geom.Point {
|
||||||
|
return geom.Pt(r.disp.Width(), r.disp.Height())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) SetIcon(source ui.ImageSource) {
|
||||||
|
texture, err := r.createTexture(source, false)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer texture.Destroy()
|
||||||
|
r.disp.SetIcon(texture.bmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) SetMouseCursor(c ui.MouseCursor) {
|
func (r *Renderer) SetMouseCursor(c ui.MouseCursor) {
|
||||||
|
@ -238,7 +238,7 @@ func (r *Renderer) CreateFontPath(path string, size int) (ui.Font, error) {
|
|||||||
return &Font{font}, nil
|
return &Font{font}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Texture, error) {
|
func (r *Renderer) createSurface(source ui.ImageSource) (*sdl.Surface, error) {
|
||||||
m, err := source.CreateImage()
|
m, err := source.CreateImage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -252,6 +252,14 @@ func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Tex
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return surface, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) createTexture(source ui.ImageSource, keepSource bool) (ui.Texture, error) {
|
||||||
|
surface, err := r.createSurface(source)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
defer surface.Free()
|
defer surface.Free()
|
||||||
texture, err := r.renderer.CreateTextureFromSurface(surface)
|
texture, err := r.renderer.CreateTextureFromSurface(surface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -391,6 +399,10 @@ func (r *Renderer) RenderToDisplay() {
|
|||||||
r.renderer.SetRenderTarget(nil)
|
r.renderer.SetRenderTarget(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) Resize(width, height int) {
|
||||||
|
r.window.SetSize(int32(width), int32(height))
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Renderer) SetDrawColor(c sdl.Color) {
|
func (r *Renderer) SetDrawColor(c sdl.Color) {
|
||||||
r.renderer.SetDrawColor(c.R, c.G, c.B, c.A)
|
r.renderer.SetDrawColor(c.R, c.G, c.B, c.A)
|
||||||
}
|
}
|
||||||
@ -399,14 +411,27 @@ func (r *Renderer) SetDrawColorGo(c color.Color) {
|
|||||||
r.SetDrawColor(ColorSDL(c))
|
r.SetDrawColor(ColorSDL(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Renderer) SetIcon(source ui.ImageSource) {
|
||||||
|
window := r.window
|
||||||
|
if window == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
surface, err := r.createSurface(source)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer surface.Free()
|
||||||
|
window.SetIcon(surface)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Renderer) SetMouseCursor(c ui.MouseCursor) { r.cursor = c }
|
func (r *Renderer) SetMouseCursor(c ui.MouseCursor) { r.cursor = c }
|
||||||
|
|
||||||
func (r *Renderer) Size() geom.PointF32 {
|
func (r *Renderer) Size() geom.Point {
|
||||||
w, h, err := r.renderer.GetOutputSize()
|
w, h, err := r.renderer.GetOutputSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return geom.PtF32(geom.NaN32(), geom.NaN32())
|
return geom.ZeroPt
|
||||||
}
|
}
|
||||||
return geom.PtF32(float32(w), float32(h))
|
return geom.Pt(int(w), int(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) SystemCursor(id sdl.SystemCursor) *sdl.Cursor {
|
func (r *Renderer) SystemCursor(id sdl.SystemCursor) *sdl.Cursor {
|
||||||
|
@ -32,8 +32,10 @@ type Renderer interface {
|
|||||||
Rectangle(r geom.RectangleF32, c color.Color, thickness float32)
|
Rectangle(r geom.RectangleF32, c color.Color, thickness float32)
|
||||||
RenderTo(Texture)
|
RenderTo(Texture)
|
||||||
RenderToDisplay()
|
RenderToDisplay()
|
||||||
|
Resize(width, height int)
|
||||||
|
SetIcon(source ImageSource)
|
||||||
SetMouseCursor(c MouseCursor)
|
SetMouseCursor(c MouseCursor)
|
||||||
Size() geom.PointF32
|
Size() geom.Point
|
||||||
Target() Texture
|
Target() Texture
|
||||||
Text(font Font, p geom.PointF32, color color.Color, text string)
|
Text(font Font, p geom.PointF32, color color.Color, text string)
|
||||||
TextAlign(font Font, p geom.PointF32, color color.Color, text string, align HorizontalAlignment)
|
TextAlign(font Font, p geom.PointF32, color color.Color, text string, align HorizontalAlignment)
|
||||||
|
2
ui/ui.go
2
ui/ui.go
@ -46,7 +46,7 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error {
|
|||||||
ctx.Renderer().Refresh()
|
ctx.Renderer().Refresh()
|
||||||
for !ctx.HasQuit() {
|
for !ctx.HasQuit() {
|
||||||
var size = r.Size()
|
var size = r.Size()
|
||||||
var bounds = geom.RectF32(0, 0, size.X, size.Y)
|
var bounds = geom.RectF32(0, 0, float32(size.X), float32(size.Y))
|
||||||
overlays.Arrange(ctx, bounds, geom.ZeroPtF32, nil)
|
overlays.Arrange(ctx, bounds, geom.ZeroPtF32, nil)
|
||||||
overlays.Render(ctx)
|
overlays.Render(ctx)
|
||||||
if ctx.HasQuit() {
|
if ctx.HasQuit() {
|
||||||
|
Loading…
Reference in New Issue
Block a user