From 5450f40b3cf26e792668a0c556d012a41af855f8 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 22 Dec 2019 14:11:01 -0800 Subject: [PATCH] render: Refactor Events System to Make Module Standalone * Refactor the events used in lib/render/sdl to be more general-purpose to make librender a stand-alone library separate from Doodle. --- main_window.go | 2 +- supervisor.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main_window.go b/main_window.go index b62450f..5cf5487 100644 --- a/main_window.go +++ b/main_window.go @@ -100,7 +100,7 @@ func (mw *MainWindow) Loop() error { return fmt.Errorf("event poll error: %s", err) } - if ev.Resized.Now { + if ev.WindowResized { w, h := mw.engine.WindowSize() if w != mw.w || h != mw.h { mw.w = w diff --git a/supervisor.go b/supervisor.go index ac78a51..b5fda2f 100644 --- a/supervisor.go +++ b/supervisor.go @@ -4,8 +4,8 @@ import ( "errors" "sync" - "git.kirsle.net/apps/doodle/lib/events" "git.kirsle.net/apps/doodle/lib/render" + "git.kirsle.net/apps/doodle/lib/render/event" ) // Event is a named event that the supervisor will send. @@ -79,11 +79,11 @@ var ( // // Useful errors returned by this may be: // - ErrStopPropagation -func (s *Supervisor) Loop(ev *events.State) error { +func (s *Supervisor) Loop(ev *event.State) error { var ( XY = render.Point{ - X: ev.CursorX.Now, - Y: ev.CursorY.Now, + X: int32(ev.CursorX), + Y: int32(ev.CursorY), } ) @@ -93,7 +93,7 @@ func (s *Supervisor) Loop(ev *events.State) error { // If we are dragging something around, do not trigger any mouse events // to other widgets but DO notify any widget we dropped on top of! if s.dd.IsDragging() { - if !ev.Button1.Now && !ev.Button2.Now { + if !ev.Button1 && !ev.Button3 { // The mouse has been released. TODO: make mouse button important? for _, child := range hovering { child.widget.Event(Drop, XY) @@ -121,7 +121,7 @@ func (s *Supervisor) Loop(ev *events.State) error { } _, isClicked := s.clicked[id] - if ev.Button1.Now { + if ev.Button1 { if !isClicked { w.Event(MouseDown, XY) s.clicked[id] = nil