Changed the API for scrolling

This commit is contained in:
Sasha Koshka 2022-11-17 19:11:49 -05:00
parent 43696543d8
commit c57c8acba7
4 changed files with 27 additions and 5 deletions

View File

@ -63,6 +63,12 @@ func (application *Application) OnMouseMove (
application.callbackManager.onMouseMove = onMouseMove
}
func (application *Application) OnScroll (
onScroll func (x, y int),
) {
application.callbackManager.onScroll = onScroll
}
func (application *Application) OnStart (
onStart func (),
) {

View File

@ -68,7 +68,20 @@ func (backend *Backend) handleButtonPress (
event xevent.ButtonPressEvent,
) {
buttonEvent := *event.ButtonPressEvent
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
switch buttonEvent.Detail {
case 4:
backend.callbackManager.RunScroll(0, -1)
case 5:
backend.callbackManager.RunScroll(0, 1)
case 6:
backend.callbackManager.RunScroll(-1, 0)
case 7:
backend.callbackManager.RunScroll(1, 0)
}
} else {
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
}
}
func (backend *Backend) handleButtonRelease (
@ -76,6 +89,7 @@ func (backend *Backend) handleButtonRelease (
event xevent.ButtonReleaseEvent,
) {
buttonEvent := *event.ButtonReleaseEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
backend.callbackManager.RunRelease(stone.Button(buttonEvent.Detail + 127))
}

View File

@ -6,6 +6,7 @@ type CallbackManager struct {
onRelease func (button Button)
onResize func ()
onMouseMove func (x, y int)
onScroll func (x, y int)
onStart func ()
}
@ -34,6 +35,11 @@ func (manager *CallbackManager) RunMouseMove (x, y int) {
manager.onMouseMove(x, y)
}
func (manager *CallbackManager) RunScroll (x, y int) {
if manager.onScroll == nil { return }
manager.onScroll(x, y)
}
func (manager *CallbackManager) RunStart () {
if manager.onStart == nil { return }
manager.onStart()

View File

@ -52,10 +52,6 @@ const (
MouseButtonLeft Button = MouseButton1
MouseButtonMiddle Button = MouseButton2
MouseButtonRight Button = MouseButton3
MouseButtonScrollUp Button = MouseButton4
MouseButtonScrollDown Button = MouseButton5
MouseButtonScrollLeft Button = MouseButton6
MouseButtonScrollRight Button = MouseButton7
MouseButtonBack Button = MouseButton8
MouseButtonForward Button = MouseButton9