98 lines
3.2 KiB
Go
98 lines
3.2 KiB
Go
package system
|
|
|
|
import "image"
|
|
import "git.tebibyte.media/tomo/tomo/input"
|
|
|
|
// HandleFocusChange sets whether or not the window containing this Hierarchy
|
|
// has input focus.
|
|
func (this *Hierarchy) HandleFocusChange (focused bool) {
|
|
if this.windowFocused == focused { return }
|
|
this.windowFocused = focused
|
|
}
|
|
|
|
// HandleModifiers sets the modifier keys that are currently being pressed.
|
|
func (this *Hierarchy) HandleModifiers (modifiers input.Modifiers) {
|
|
if this.modifiers == modifiers { return }
|
|
this.modifiers = modifiers
|
|
}
|
|
|
|
// HandleKeyDown sends a key down event to the currently focused Box. If the
|
|
// event which triggers this comes with modifier key information,
|
|
// HandleModifiers must be called *before* HandleKeyDown.
|
|
func (this *Hierarchy) HandleKeyDown (key input.Key, numberPad bool) {
|
|
if key == input.KeyTab && this.modifiers.Alt {
|
|
if this.modifiers.Shift {
|
|
this.focusPrevious()
|
|
} else {
|
|
this.focusNext()
|
|
}
|
|
} else if target := this.keyboardTarget(); target != nil {
|
|
target.handleKeyDown(key, numberPad)
|
|
}
|
|
}
|
|
|
|
// HandleKeyUp sends a key up event to the currently focused Box. If the event
|
|
// which triggers this comes with modifier key information, HandleModifiers must
|
|
// be called *before* HandleKeyUp.
|
|
func (this *Hierarchy) HandleKeyUp (key input.Key, numberPad bool) {
|
|
if target := this.keyboardTarget(); target != nil {
|
|
target.handleKeyUp(key, numberPad)
|
|
}
|
|
}
|
|
|
|
// HandleMouseDown sends a mouse down event to the Box positioned underneath the
|
|
// mouse cursor and marks it as being "dragged" by that mouse button. If the
|
|
// event which triggers this comes with mouse position information,
|
|
// HandleMouseMove must be called *before* HandleMouseDown.
|
|
func (this *Hierarchy) HandleMouseDown (button input.Button) {
|
|
underneath := this.boxUnder(this.mousePosition, eventCategoryMouse)
|
|
this.drags[button] = underneath
|
|
if underneath != nil {
|
|
underneath.handleMouseDown(button)
|
|
}
|
|
}
|
|
|
|
// HandleMouseUp sends a mouse up event to the Box currently being "dragged" by
|
|
// the specified mouse button, and marks it as being "not dragged" by that mouse
|
|
// button. If the event which triggers this comes with mouse position
|
|
// information, HandleMouseMove must be caleld *before* HandleMouseUp
|
|
func (this *Hierarchy) HandleMouseUp (button input.Button) {
|
|
dragging := this.drags[button]
|
|
this.drags[button] = nil
|
|
if dragging != nil {
|
|
dragging.handleMouseUp(button)
|
|
}
|
|
}
|
|
|
|
// HandleMouseMove sends a mouse move event to any Boxes currently being
|
|
// "dragged" by a mouse button. If none are, it sends the event to the Box which
|
|
// is underneath the mouse pointer.
|
|
func (this *Hierarchy) HandleMouseMove (position image.Point) {
|
|
if this.mousePosition == position { return }
|
|
this.mousePosition = position
|
|
|
|
handled := false
|
|
for _, child := range this.drags {
|
|
if child == nil { continue }
|
|
child.handleMouseMove()
|
|
handled = true
|
|
}
|
|
|
|
underneath := this.boxUnder(position, eventCategoryMouse)
|
|
if underneath != nil {
|
|
this.hover(underneath)
|
|
if !handled {
|
|
underneath.handleMouseMove()
|
|
}
|
|
}
|
|
}
|
|
|
|
// HandleScroll sends a scroll event to the Box currently underneath the mouse
|
|
// cursor.
|
|
func (this *Hierarchy) HandleScroll (x, y float64) {
|
|
underneath := this.boxUnder(this.mousePosition, eventCategoryScroll)
|
|
if underneath != nil {
|
|
underneath.handleScroll(x, y)
|
|
}
|
|
}
|