Layer Group design - drawpile/Drawpile GitHub Wiki

Ideas for layer group support to be implemented in version 2.2.

Current layer stack structure:

Layer Stack

  • Layer 1
  • Layer 2
  • Layer 3
  • ...

Layers can also have sublayers. These are used internally for indirect painting as well as previews for tools like Line, Rectangle, Ellipse and Bezier Curve.

New layer stack structure:

Layer Stack

  • Layer group (root)
    • Raster Layer
    • Layer group
      • ...
    • Fill Layer
    • ...

There is always a root group in the layer stack, although this is only an internal implementation detail.

Layer classes:

  • Layer - an abstract base class for everything that can be added to a layer group
  • RasterLayer - a normal layer
  • LayerGroup - a group of layers. Has no pixel data of its own.
  • FillLayer - a special layer filled with solid color
  • more special types?

Common layer properties:

  • width and height
  • id
  • title
  • opacity
  • hidden bit
  • censored bit
  • fixed bit
  • blending mode

Common layer methods (abstract virtual):

  • toImage(): convert layer content to a QImage
  • colorAt(x,y, dia): sample color at the given point
  • resize(top, right, bottom, left): resize this layer
  • flattenTile(quint32 *data, int x, int y): composite a tile from this layer onto the given tile

Raster layer properties and methods:

  • Everything there is now

Layer group properties and methods:

  • isolation mode = isolated | pass-through
  • addLayer(layer)
  • removeLayer(id)
  • reorganizeLayers(newOrder)

Fill layer properties and methods:

  • color

Layer commands

Layer creation

Currently, there is only one layer creation command. New commands are needed for creating each of the new layer type.

Layer deletion

Deletion should work the same as before.

TODO should deleting a group delete its sublayers as well?

Layer attributes and retitling

These should work the same as before

Layer ordering

Currently, all newly created layers are added to the top of the stack or above a targeted layer. The LayerOrder command is used to set the order of the layer stack. Every layer must appear exactly once in the LayerOrder command. The ordering is sanitized by removing all non-existent (and duplicate) layers and adding all missing layers to the end in their current relative order.

The order is simply a list of layer IDs: [0x0101, 0x0102, ....]

Reordering grouped layers

TODO