Page MenuHome

Grease Pencil: save brush assigned by tool
Closed, ResolvedPublicBUG

Description

Note: original text by @Antonio Vazquez (antoniov)

Current Status

The current logic is using a general place to save the brush by “mode” (weight paint, texture paint, gpencil sculpt, etc). This information is currently saved in ToolSettings struct:

typedef struct ToolSettings {
    VPaint *vpaint;        /* vertex paint */
    VPaint *wpaint;        /* weight paint */
    Sculpt *sculpt;
    UvSculpt *uvsculpt;    /* uv smooth */
    GpPaint *gp_paint;
            ..
            ..

For each mode, we have a struct with the Paint data, for example:

typedef struct GpPaint {
    Paint paint;
} GpPaint;

And Paint struct contains the active brush.

/* Paint Tool Base */
typedef struct Paint {
    struct Brush *brush;
    struct Palette *palette;
            ..
            ..

When we need use a brush (in any mode), we usually have functions like this that uses ToolSettings as the source to find the corresponding paint.

Brush *BKE_brush_getactive_gpencil(ToolSettings *ts)
{
    /* error checking */
    if (ELEM(NULL, ts, ts->gp_paint)) {
        return NULL;
    }
    Paint *paint = &ts->gp_paint->paint;

    return paint->brush;
}

After looking at code, it’s clear that we cannot save what brush is active for each tool, so we need a place to save this.

I’m not sure what is the best place to do that, maybe add a Paint struct for each tool? add a bmain hash with tool->brush?

We also need a way on Python to get the active brush by tool to display its properties. Not sure, but we will need something like this, but by active tool (“active_tool_brush”??):

// Context function
if (CTX_data_equals(member, "active_gpencil_brush")) {
  Brush *brush = BKE_brush_getactive_gpencil(scene->toolsettings);
  if (brush) {
     CTX_data_pointer_set(result, &scene->id, &RNA_Brush, brush);
     return 1;
  }
}

Summary of what we need

  • A way to save the brush of each tool.
  • Functions to get the active brush for the current active tool.
  • Python context functions to get the brush.
  • Preview system for brushes (phase II).

Event Timeline

Campbell Barton (campbellbarton) lowered the priority of this task from 90 to High.Oct 31 2018, 12:09 AM
Campbell Barton (campbellbarton) updated the task description. (Show Details)

This could be solved by grouping brushes by a custom category,
see: T57528

Where each category would have an active brush (we have this already for sculpt, it's just not written into DNA).

Proposal:

  • Implement brush categories T57528 (where in this case a category is a 'tool' from the user perspective since each category gets it's own button in the toolbar).
  • Add support for saving/loading the current brush for a category to the blend file (nice to support even ignoring paint systems).

This way from the perspective of grease pencil's C code, there is only ever a single active brush. The tool system is responsible keeping a category -> brush map.

Note that a down-side here is the map would likely use tool names (which are currently brush names). So renaming a brush would loose its reference if it was set to active.
Since renaming brushes isn't as common as object/bone names, I think this isn't such a problem (in fact this happens for the current active tool which is stored by name).

Campbell Barton (campbellbarton) changed the task status from Unknown Status to Resolved.Nov 4 2018, 1:02 AM

Update, based on a meeting we agreed to go with an active brush per internal tool implementation, see: rBac8d7873278c47e8e282b7f83888108e2720a451

Closing, brush preview system isn't done but not the main purpose of this task.