Skip to content

enable panning around the canvas #5

Description

@DivineDominion

I think this is rather simple.

  • Holding the spacebar changes the tool from drawing to panning until you release the key.
  • Decouple CanvasView coordinate system from a Canvas coordinate system:
    • When you pan, you add the drag/mouse-move vector (Δx, Δy) to a scrollOffset. Maybe part of the CanvasView itself, because it's a presentation detail.
    • A Canvas representation then takes care of holding on to Strokes and fetching them for a given NSRect partition of itself.

That's similar to drawing and scrolling tile maps in 2D games. Canvasis the map, CanvasView is the viewport or camera that moves around and asks the map for everything that's inside its boundary.

  • Similarly, new strokes have to be translated from the CanvasView coordinates to the Canvas coordinate system.

Essentially, you just add the scrollOffset: (Δx, Δy) to the view coordinates and that should do the trick.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions