2019-06-23 23:15:09 +00:00
|
|
|
package uix
|
|
|
|
|
2019-06-28 05:54:46 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
|
|
|
)
|
2019-06-23 23:15:09 +00:00
|
|
|
|
|
|
|
// LinkStart initializes the Link tool.
|
|
|
|
func (w *Canvas) LinkStart() {
|
|
|
|
w.Tool = LinkTool
|
|
|
|
w.linkFirst = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkAdd adds an actor to be linked in the Link tool.
|
|
|
|
func (w *Canvas) LinkAdd(a *Actor) error {
|
|
|
|
if w.linkFirst == nil {
|
|
|
|
// First click, hold onto this actor.
|
|
|
|
w.linkFirst = a
|
2019-06-28 05:54:46 +00:00
|
|
|
shmem.Flash("Doodad '%s' selected, click the next Doodad to link it to",
|
|
|
|
a.Doodad.Title,
|
|
|
|
)
|
2019-06-23 23:15:09 +00:00
|
|
|
} else {
|
|
|
|
// Second click, call the OnLinkActors handler with the two actors.
|
|
|
|
if w.OnLinkActors != nil {
|
2019-06-28 05:54:46 +00:00
|
|
|
w.OnLinkActors(w.linkFirst, a)
|
2019-06-23 23:15:09 +00:00
|
|
|
} else {
|
|
|
|
return errors.New("Canvas.LinkAdd: no OnLinkActors handler is ready")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the link state.
|
|
|
|
w.linkFirst = nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|