Line/Square Tool, Undo Feature, and Linked Doodad Lines #11

Closed
opened 2019-07-01 22:32:53 +00:00 by kirsle · 0 comments
Owner

This describes an idea how to support a Line and Rectangle drawing tool, the Undo feature, and ability to draw "imaginary" connecting lines to visualize linked Doodads.

// Stroke represents one atomic drawing element. It is used as a
// "staging" object when actively dragging a new shape onto a level,
// a "unit of work" for the Undo/Redo feature, and a holder for
// arbitrary temporary lines such as to visualize Doodad links,
// collision hitbox debug lines, etc.
type Stroke struct {
    Shape int  // Freehand, Line, Square
    Color render.Color

    // Lines and Squares have only two important points
    Point1 render.Point  // start point
    Point2 render.Point  // stop/current point

    // Freehand lines record all of their points
    Points []render.Point
}

Freehand Tool

  • On mouse down, create a new Stroke and begin logging every pixel intended for change as the user drags the mouse around.
  • On release, commit the Stroke's points to the drawing all at once.

Line and Square Tool

  • On mouse down, create a new Stroke and record the first point clicked as Point1.
  • On drag, update Point2 to the current point under the cursor.
  • On release, commit the shape to the level drawing.

Undo/Redo Feature

  • Store an array of Strokes into a History buffer and have a HistoryIndex pointing to the current/most recent stroke.
  • On Undo, roll the HistoryIndex back and undo the strokes that came after, etc.
  • When the Doodad Tool or Link Tool is active, loop through all the actors to find their links.
  • For every given pair of actors A and B, create a Stroke object that draws a Line between the center of actor A and the center of actor B.
This describes an idea how to support a Line and Rectangle drawing tool, the Undo feature, and ability to draw "imaginary" connecting lines to visualize linked Doodads. ```go // Stroke represents one atomic drawing element. It is used as a // "staging" object when actively dragging a new shape onto a level, // a "unit of work" for the Undo/Redo feature, and a holder for // arbitrary temporary lines such as to visualize Doodad links, // collision hitbox debug lines, etc. type Stroke struct { Shape int // Freehand, Line, Square Color render.Color // Lines and Squares have only two important points Point1 render.Point // start point Point2 render.Point // stop/current point // Freehand lines record all of their points Points []render.Point } ``` ## Freehand Tool * On mouse down, create a new Stroke and begin logging every pixel intended for change as the user drags the mouse around. * On release, commit the Stroke's points to the drawing all at once. ## Line and Square Tool * On mouse down, create a new Stroke and record the first point clicked as Point1. * On drag, update Point2 to the current point under the cursor. * On release, commit the shape to the level drawing. ## Undo/Redo Feature * Store an array of Strokes into a History buffer and have a HistoryIndex pointing to the current/most recent stroke. * On Undo, roll the HistoryIndex back and undo the strokes that came after, etc. ## Doodad Link Lines * When the Doodad Tool or Link Tool is active, loop through all the actors to find their links. * For every given pair of actors A and B, create a Stroke object that draws a Line between the center of actor A and the center of actor B.
kirsle added this to the First Beta Release MVP milestone 2019-07-05 23:29:42 +00:00
Sign in to join this conversation.
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: SketchyMaze/doodle#11
No description provided.