From f56c5dd389df2cf0bd0ca111ae44bf58ece8a5e2 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 1 May 2022 12:05:17 +0000 Subject: [PATCH] Added support for getting & setting location of Renderer. --- allg5ui/renderer.go | 9 +++++++++ sdlui/renderer.go | 9 +++++++++ ui/renderer.go | 2 ++ 3 files changed, 20 insertions(+) diff --git a/allg5ui/renderer.go b/allg5ui/renderer.go index 5a31023..e57f974 100644 --- a/allg5ui/renderer.go +++ b/allg5ui/renderer.go @@ -287,6 +287,15 @@ func (r *Renderer) Line(p, q geom.PointF32, color color.Color, thickness float32 allg5.DrawLine(p.X, p.Y, q.X, q.Y, newColor(color), thickness) } +func (r *Renderer) Location() geom.Point { + x, y := r.disp.Position() + return geom.Pt(x, y) +} + +func (r *Renderer) Move(to geom.Point) { + r.disp.SetPosition(to.X, to.Y) +} + func (r *Renderer) mustGetBitmap(t ui.Texture) *allg5.Bitmap { texture, ok := t.(*texture) if !ok { diff --git a/sdlui/renderer.go b/sdlui/renderer.go index ce72923..89008b1 100644 --- a/sdlui/renderer.go +++ b/sdlui/renderer.go @@ -374,6 +374,15 @@ func (r *Renderer) Line(p, q geom.PointF32, color color.Color, thickness float32 r.renderer.DrawLineF(p.X, p.Y, q.X, q.Y) } +func (r *Renderer) Location() geom.Point { + x, y := r.window.GetPosition() + return geom.Pt(int(x), int(y)) +} + +func (r *Renderer) Move(to geom.Point) { + r.window.SetPosition(int32(to.X), int32(to.Y)) +} + func (r *Renderer) Rectangle(rect geom.RectangleF32, c color.Color, thickness float32) { r.SetDrawColorGo(c) if rect.Dx() == 0 { // SDL doesn't draw a 1 px wide line when Dx() == 0 && thickness == 1 diff --git a/ui/renderer.go b/ui/renderer.go index fb69f67..32c2aa2 100644 --- a/ui/renderer.go +++ b/ui/renderer.go @@ -31,6 +31,8 @@ type Renderer interface { 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) + Location() geom.Point + Move(geom.Point) Rectangle(r geom.RectangleF32, c color.Color, thickness float32) RenderTo(Texture) RenderToDisplay()