From 7f2e155eddb475b95e3cb567d3958786951355c7 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 17 May 2020 21:02:38 +0200 Subject: [PATCH] Renderers now respect Location of NewRendererOptions. --- allg5ui/renderer.go | 2 ++ allg5ui/rendererfactory.go | 3 +++ sdlui/rendererfactory.go | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/allg5ui/renderer.go b/allg5ui/renderer.go index 311048b..d4c2fea 100644 --- a/allg5ui/renderer.go +++ b/allg5ui/renderer.go @@ -308,6 +308,8 @@ func (r *Renderer) SetMouseCursor(c ui.MouseCursor) { r.cursor = c } +func (r *Renderer) SetPosition(p geom.PointF32) { r.disp.SetPosition(int(p.X), int(p.Y)) } + func (r *Renderer) SetResourceProvider(factory func() ui.Resources) { if r.res != nil { r.res.Destroy() diff --git a/allg5ui/rendererfactory.go b/allg5ui/rendererfactory.go index 6d24112..148924a 100644 --- a/allg5ui/rendererfactory.go +++ b/allg5ui/rendererfactory.go @@ -20,5 +20,8 @@ func (f rendererFactory) New(title string, width, height int, opts ui.NewRendere return nil, err } renderer.SetWindowTitle(title) + if opts.Location != nil { + renderer.SetPosition(*opts.Location) + } return renderer, nil } diff --git a/sdlui/rendererfactory.go b/sdlui/rendererfactory.go index 2a43028..7ee84fd 100644 --- a/sdlui/rendererfactory.go +++ b/sdlui/rendererfactory.go @@ -12,8 +12,13 @@ func init() { type rendererFactory struct{} func (f rendererFactory) New(title string, width, height int, opts ui.NewRendererOptions) (ui.Renderer, error) { + location := sdl.Point{X: sdl.WINDOWPOS_UNDEFINED, Y: sdl.WINDOWPOS_UNDEFINED} + if opts.Location != nil { + location.X = int32(opts.Location.X) + location.Y = int32(opts.Location.Y) + } return NewRenderer(title, int32(width), int32(height), NewRendererOptions{ - Location: sdl.Point{X: sdl.WINDOWPOS_UNDEFINED, Y: sdl.WINDOWPOS_UNDEFINED}, + Location: location, Resizable: opts.Resizable, VSync: opts.VSync, })