atomize-element-interface #2
|
@ -26,13 +26,8 @@ func NewMouse () (element *Mouse) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Mouse) Handle (event tomo.Event) {
|
func (element *Mouse) Resize (width, height int) {
|
||||||
switch event.(type) {
|
element.core.AllocateCanvas(width, height)
|
||||||
case tomo.EventResize:
|
|
||||||
resizeEvent := event.(tomo.EventResize)
|
|
||||||
element.core.AllocateCanvas (
|
|
||||||
resizeEvent.Width,
|
|
||||||
resizeEvent.Height)
|
|
||||||
artist.FillRectangle (
|
artist.FillRectangle (
|
||||||
element.core,
|
element.core,
|
||||||
theme.AccentPattern(),
|
theme.AccentPattern(),
|
||||||
|
@ -44,40 +39,34 @@ func (element *Mouse) Handle (event tomo.Event) {
|
||||||
artist.Line (
|
artist.Line (
|
||||||
element.core, artist.NewUniform(color.White), 3,
|
element.core, artist.NewUniform(color.White), 3,
|
||||||
image.Pt(1, 1),
|
image.Pt(1, 1),
|
||||||
image.Pt(resizeEvent.Width - 2, resizeEvent.Height - 2))
|
image.Pt(width - 2, height - 2))
|
||||||
artist.Line (
|
artist.Line (
|
||||||
element.core, artist.NewUniform(color.White), 1,
|
element.core, artist.NewUniform(color.White), 1,
|
||||||
image.Pt(1, resizeEvent.Height - 2),
|
image.Pt(1, height - 2),
|
||||||
image.Pt(resizeEvent.Width - 2, 1))
|
image.Pt(width - 2, 1))
|
||||||
|
}
|
||||||
|
|
||||||
case tomo.EventMouseDown:
|
func (element *Mouse) HandleMouseDown (x, y int, button tomo.Button) {
|
||||||
element.drawing = true
|
element.drawing = true
|
||||||
mouseDownEvent := event.(tomo.EventMouseDown)
|
element.lastMousePos = image.Pt(x, y)
|
||||||
element.lastMousePos = image.Pt (
|
}
|
||||||
mouseDownEvent.X,
|
|
||||||
mouseDownEvent.Y)
|
|
||||||
|
|
||||||
case tomo.EventMouseUp:
|
func (element *Mouse) HandleMouseUp (x, y int, button tomo.Button) {
|
||||||
element.drawing = false
|
element.drawing = false
|
||||||
mouseUpEvent := event.(tomo.EventMouseUp)
|
mousePos := image.Pt(x, y)
|
||||||
mousePos := image.Pt (
|
|
||||||
mouseUpEvent.X,
|
|
||||||
mouseUpEvent.Y)
|
|
||||||
element.core.PushRegion (artist.Line (
|
element.core.PushRegion (artist.Line (
|
||||||
element.core, element.color, 1,
|
element.core, element.color, 1,
|
||||||
element.lastMousePos, mousePos))
|
element.lastMousePos, mousePos))
|
||||||
element.lastMousePos = mousePos
|
element.lastMousePos = mousePos
|
||||||
|
}
|
||||||
|
|
||||||
case tomo.EventMouseMove:
|
func (element *Mouse) HandleMouseMove (x, y int) {
|
||||||
if !element.drawing { return }
|
if !element.drawing { return }
|
||||||
mouseMoveEvent := event.(tomo.EventMouseMove)
|
mousePos := image.Pt(x, y)
|
||||||
mousePos := image.Pt (
|
|
||||||
mouseMoveEvent.X,
|
|
||||||
mouseMoveEvent.Y)
|
|
||||||
element.core.PushRegion (artist.Line (
|
element.core.PushRegion (artist.Line (
|
||||||
element.core, element.color, 1,
|
element.core, element.color, 1,
|
||||||
element.lastMousePos, mousePos))
|
element.lastMousePos, mousePos))
|
||||||
element.lastMousePos = mousePos
|
element.lastMousePos = mousePos
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
func (element *Mouse) HandleScroll (x, y int, deltaX, deltaY float64) { }
|
||||||
|
|
Reference in New Issue
Block a user