From 6c1bf7aabd859c27f26898ead8572dd00f419d57 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 9 Aug 2014 10:33:38 -0400 Subject: [PATCH] Big change: with the current event model, it's safe to call Area.RepaintAll() (and the future Area.Repaint()) from within AreaHandler.Key() and AreaHandler.Mouse(); get rid of the bool returns from each. The future Area.Repaint() is important; the bool returns repainted the whole Area, which may not be optimal. --- redo/area.go | 6 ++---- redo/area_darwin.go | 10 ++-------- redo/area_unix.go | 10 ++-------- redo/area_windows.go | 11 ++--------- redo/future | 2 ++ redo/zz_test.go | 4 ++-- 6 files changed, 12 insertions(+), 31 deletions(-) diff --git a/redo/area.go b/redo/area.go index 01b7208..2ce7d5c 100644 --- a/redo/area.go +++ b/redo/area.go @@ -68,16 +68,14 @@ type AreaHandler interface { // Mouse is called when the Area receives a mouse event. // You are allowed to do nothing in this handler (to ignore mouse events). // See MouseEvent for details. - // If repaint is true, the Area is marked as needing to be redrawn. // After handling the mouse event, package ui will decide whether to perform platform-dependent event chain continuation based on that platform's designated action (so it is not possible to override global mouse events this way). - Mouse(e MouseEvent) (repaint bool) + Mouse(e MouseEvent) // Key is called when the Area receives a keyboard event. // You are allowed to do nothing in this handler (to ignore keyboard events). // See KeyEvent for details. - // If repaint is true, the Area is marked as needing to be redrawn. // After handling the key event, package ui will decide whether to perform platform-dependent event chain continuation based on that platform's designated action (so it is not possible to override global key events, such as Alt-Tab, this way). - Key(e KeyEvent) (repaint bool) + Key(e KeyEvent) } // MouseEvent contains all the information for a mous event sent by Area.Mouse. diff --git a/redo/area_darwin.go b/redo/area_darwin.go index 471ad58..1d715ac 100644 --- a/redo/area_darwin.go +++ b/redo/area_darwin.go @@ -126,10 +126,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool, data unsafe.Pointer) } held >>= 1 } - repaint := a.handler.Mouse(me) - if repaint { - C.display(self) - } + a.handler.Mouse(me) } //export areaView_mouseMoved_mouseDragged @@ -152,10 +149,7 @@ func areaView_mouseUp(self C.id, e C.id, data unsafe.Pointer) { func sendKeyEvent(self C.id, ke KeyEvent, data unsafe.Pointer) { a := (*area)(data) - repaint := a.handler.Key(ke) - if repaint { - C.display(self) - } + a.handler.Key(ke) } func areaKeyEvent(self C.id, e C.id, up bool, data unsafe.Pointer) { diff --git a/redo/area_unix.go b/redo/area_unix.go index 8b96ff0..3a6ce68 100644 --- a/redo/area_unix.go +++ b/redo/area_unix.go @@ -190,10 +190,7 @@ func finishMouseEvent(widget *C.GtkWidget, data C.gpointer, me MouseEvent, mb ui if me.Up >= 8 { me.Up -= 4 } - repaint := a.handler.Mouse(me) - if repaint { - C.gtk_widget_queue_draw(widget) - } + a.handler.Mouse(me) } // convenience name to make our intent clear @@ -298,10 +295,7 @@ func doKeyEvent(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer, up bool return } ke.Up = up - repaint := a.handler.Key(ke) - if repaint { - C.gtk_widget_queue_draw(widget) - } + a.handler.Key(ke) } //export our_area_key_press_event_callback diff --git a/redo/area_windows.go b/redo/area_windows.go index d96a21c..0137a3f 100644 --- a/redo/area_windows.go +++ b/redo/area_windows.go @@ -150,10 +150,7 @@ func finishAreaMouseEvent(data unsafe.Pointer, cbutton C.DWORD, up C.BOOL, wPara if button != 5 && (wParam & C.MK_XBUTTON2) != 0 { me.Held = append(me.Held, 5) } - repaint := a.handler.Mouse(me) - if repaint { - a.RepaintAll() - } + a.handler.Mouse(me) } //export areaKeyEvent @@ -188,11 +185,7 @@ func areaKeyEvent(data unsafe.Pointer, up C.BOOL, wParam C.WPARAM, lParam C.LPAR return } ke.Up = up != C.FALSE - // TODO repaint may no longer be needed - repaint := a.handler.Key(ke) - if repaint { - a.RepaintAll() - } + a.handler.Key(ke) } // all mappings come from GLFW - https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152 diff --git a/redo/future b/redo/future index 3eb26d0..a6e63f1 100644 --- a/redo/future +++ b/redo/future @@ -17,6 +17,8 @@ Tab // It panics if index is out of range. // After Delete(), the effect of accessing the Control of the deleted tab or any of its children is undefned. [TODO reword?] investigate close buttons (especially for LikeTab) +Area + Repaint(rect image.Rectangle) so I don't forget, some TODOs: windows diff --git a/redo/zz_test.go b/redo/zz_test.go index 59f577b..0dc1421 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -50,8 +50,8 @@ func (a *areaHandler) Paint(r image.Rectangle) *image.RGBA { draw.Draw(i, r, &image.Uniform{color.RGBA{128,0,128,255}}, image.ZP, draw.Src) return i } -func (a *areaHandler) Mouse(me MouseEvent) bool { fmt.Printf("%#v\n", me); return false } -func (a *areaHandler) Key(ke KeyEvent) bool { fmt.Printf("%#v\n", ke); return false } +func (a *areaHandler) Mouse(me MouseEvent) { fmt.Printf("%#v\n", me) } +func (a *areaHandler) Key(ke KeyEvent) { fmt.Printf("%#v\n", ke) } func (tw *testwin) make(done chan struct{}) { tw.t = NewTab()