x-backend #2

Merged
sashakoshka merged 34 commits from x-backend into main 2022-11-14 21:40:25 -07:00
2 changed files with 28 additions and 3 deletions
Showing only changes of commit 636e5ce7e7 - Show all commits

View File

@ -161,6 +161,21 @@ func (backend *Backend) handleButtonRelease (
backend.channel <- stone.EventRelease(buttonEvent.Detail)
}
func (backend *Backend) handleMotionNotify (
connection *xgbutil.XUtil,
event xevent.MotionNotifyEvent,
) {
motionEvent := *event.MotionNotifyEvent
x, y := backend.cellAt (image.Point {
X: int(motionEvent.EventX),
Y: int(motionEvent.EventY),
})
backend.channel <- stone.EventMouseMove {
X: x,
Y: y,
}
}
func (backend *Backend) compressConfigureNotify (
firstEvent xproto.ConfigureNotifyEvent,
) (
@ -292,6 +307,12 @@ func (backend *Backend) drawRune (x, y int, character rune) {
draw.Over)
}
func (backend *Backend) cellAt (onScreen image.Point) (x, y int) {
x = (onScreen.X - backend.metrics.paddingX) / backend.metrics.cellWidth
y = (onScreen.Y - backend.metrics.paddingY) / backend.metrics.cellHeight
return
}
func (backend *Backend) cellSubImage (x, y int) (cell *xgraphics.Image) {
cell = backend.canvas.SubImage(backend.boundsOfCell(x, y)).(*xgraphics.Image)
return
@ -375,7 +396,7 @@ func factory (application *stone.Application) (output stone.Backend, err error)
// keyboard buttons (uncompressed)
err = backend.window.Listen (
xproto.EventMaskStructureNotify,
// xproto.EventMaskPointerMotion,
xproto.EventMaskPointerMotion,
// xproto.EventMaskKeyPress,
// xproto.EventMaskKeyRelease,
xproto.EventMaskButtonPress,
@ -400,6 +421,8 @@ func factory (application *stone.Application) (output stone.Backend, err error)
Connect(backend.connection, backend.window.Id)
xevent.ButtonReleaseFun(backend.handleButtonRelease).
Connect(backend.connection, backend.window.Id)
xevent.MotionNotifyFun(backend.handleMotionNotify).
Connect(backend.connection, backend.window.Id)
output = backend
return

View File

@ -55,8 +55,10 @@ func main () {
case stone.EventMouseMove:
event := event.(stone.EventMouseMove)
application.SetRune(event.X, event.Y, '#')
application.Draw()
if mousePressed {
application.SetRune(event.X, event.Y, '#')
application.Draw()
}
case stone.EventResize:
application.Draw()