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).