undefined
Posted On Nov 2, 2021
The idea is, each drawable shape (line, rectangle, arrow,…) will have
its own Tool object, and there is a ToolManager to manage them all, pass
the current mouse input from the grid into the active tool.
The list of the available tools should be fixed and pre-allocated at
compile time. But it can be dynamic too, just not something to worry about
at this moment.
Each tool will implement the ToolControl
trait, which defined the three
stages of each drawing behavior:
- start(): called when the user started drawing
- draw(): called when the user is drawing with their mouse down
- end(): called when the user finished drawing, with their mouse up
Each stage could modify the data buffer directly.
┌──────────────┐
MouseDown────▶│ ├─────▶start()
MouseMove────▶│ ToolManager ├─────▶draw()
MouseUp────▶│┌────────────┐├─────▶end()
└┤Active Tool ├┘
└────────────┘
The first tool in this commit is LineTool
, to draw a straight line between
the start and current mouse position.