Mouse input works
This commit is contained in:
parent
f3d0bad959
commit
3a879d9a5f
@ -97,3 +97,8 @@ func (application *Application) Resized () (resized bool) {
|
||||
resized = application.backend.Resized()
|
||||
return
|
||||
}
|
||||
|
||||
func (application *Application) MousePosition () (x, y int) {
|
||||
x, y = application.backend.MousePosition()
|
||||
return
|
||||
}
|
||||
|
21
backend.go
21
backend.go
@ -4,16 +4,17 @@ import "time"
|
||||
import "errors"
|
||||
|
||||
type Backend interface {
|
||||
Run (callback func (application *Application)) ()
|
||||
Await (timeout time.Duration) (keepRunning bool)
|
||||
Poll () (keepRunning bool)
|
||||
SetTitle (title string)
|
||||
JustPressed (button Button) (pressed bool)
|
||||
JustReleased (button Button) (released bool)
|
||||
Pressed (button Button) (pressed bool)
|
||||
Repeated (button Button) (repeated bool)
|
||||
Typed () (text string)
|
||||
Resized () (resized bool)
|
||||
Run (callback func (application *Application)) ()
|
||||
Await (timeout time.Duration) (keepRunning bool)
|
||||
Poll () (keepRunning bool)
|
||||
SetTitle (title string)
|
||||
JustPressed (button Button) (pressed bool)
|
||||
JustReleased (button Button) (released bool)
|
||||
Pressed (button Button) (pressed bool)
|
||||
Repeated (button Button) (repeated bool)
|
||||
Typed () (text string)
|
||||
Resized () (resized bool)
|
||||
MousePosition () (x, y int)
|
||||
}
|
||||
|
||||
type BackendFactory func (application *Application) (backend Backend, err error)
|
||||
|
@ -126,6 +126,19 @@ func (backend *Backend) Resized () (resized bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) MousePosition () (x, y int) {
|
||||
vector := backend.window.MousePosition()
|
||||
x = int (
|
||||
(vector.X - float64(backend.metrics.paddingX)) /
|
||||
float64(backend.metrics.cellWidth))
|
||||
y = int (
|
||||
(backend.windowBounds.Y -
|
||||
vector.Y -
|
||||
float64(backend.metrics.paddingY)) /
|
||||
float64(backend.metrics.cellHeight))
|
||||
return
|
||||
}
|
||||
|
||||
func (backend *Backend) draw () {
|
||||
// didDrawing := false
|
||||
width, height := backend.application.Size()
|
||||
|
@ -65,6 +65,7 @@ func (buffer *Buffer) Size () (width, height int) {
|
||||
}
|
||||
|
||||
func (buffer *Buffer) SetSize (width, height int) {
|
||||
if width < 0 || height < 0 { return }
|
||||
buffer.width = width
|
||||
buffer.height = height
|
||||
buffer.content = make([]Cell, width * height)
|
||||
@ -115,6 +116,7 @@ type DamageBuffer struct {
|
||||
}
|
||||
|
||||
func (buffer *DamageBuffer) SetSize (width, height int) {
|
||||
if width < 0 || height < 0 { return }
|
||||
buffer.Buffer.SetSize(width, height)
|
||||
buffer.clean = make([]bool, width * height)
|
||||
}
|
||||
|
@ -47,6 +47,12 @@ func run (application *stone.Application) {
|
||||
application.Dot.X = 0
|
||||
application.Dot.Y = 2
|
||||
fmt.Fprintln(application, textBuffer)
|
||||
|
||||
}
|
||||
|
||||
if application.Pressed(stone.MouseButtonLeft) {
|
||||
x, y := application.MousePosition()
|
||||
application.SetRune(x, y, '#')
|
||||
}
|
||||
|
||||
if !application.Await(frameDelay) { break }
|
||||
|
Loading…
Reference in New Issue
Block a user