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.

This commit is contained in:
Pietro Gagliardi 2014-08-09 10:33:38 -04:00
parent b4a97e871a
commit 6c1bf7aabd
6 changed files with 12 additions and 31 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()