Exemplo n.º 1
0
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
                                  const size_t tool_offset, const int ob_mode,
                                  const char *tool_name, int create_missing,
                                  int toggle)
{
	struct Brush *brush, *brush_orig = paint_brush(paint);

	if (toggle)
		brush = brush_tool_toggle(bmain, brush_orig, tool, tool_offset, ob_mode);
	else
		brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);

	if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
		brush = BKE_brush_add(tool_name);
		brush_tool_set(brush, tool_offset, tool);
		brush->ob_mode = ob_mode;
		brush->toggle_brush = brush_orig;
	}

	if (brush) {
		paint_brush_set(paint, brush);
		WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
Exemplo n.º 2
0
void make_local_brush(Brush *brush)
{

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	Main *bmain= G.main;
	Scene *scene;
	int is_local= FALSE, is_lib= FALSE;

	if(brush->id.lib==NULL) return;

	if(brush->clone.image) {
		/* special case: ima always local immediately. Clone image should only
		   have one user anyway. */
		id_clear_lib_data(bmain, &brush->clone.image->id);
		extern_local_brush(brush);
	}

	for(scene= bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene=scene->id.next) {
		if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
			if(scene->id.lib) is_lib= TRUE;
			else is_local= TRUE;
		}
	}

	if(is_local && is_lib == FALSE) {
		id_clear_lib_data(bmain, &brush->id);
		extern_local_brush(brush);

		/* enable fake user by default */
		if (!(brush->id.flag & LIB_FAKEUSER)) {
			brush->id.flag |= LIB_FAKEUSER;
			brush->id.us++;
		}
	}
	else if(is_local && is_lib) {
		Brush *brush_new= copy_brush(brush);
		brush_new->id.us= 1; /* only keep fake user */
		brush_new->id.flag |= LIB_FAKEUSER;

		/* Remap paths of new ID using old library as base. */
		BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
		
		for(scene= bmain->scene.first; scene; scene=scene->id.next) {
			if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
				if(scene->id.lib==NULL) {
					paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
				}
			}
		}
	}
}
Exemplo n.º 3
0
void make_local_brush(Brush *brush)
{

	/* - only lib users: do nothing
	 * - only local users: set flag
	 * - mixed: make copy
	 */

	Main *bmain= G.main;
	Scene *scene;
	int local= 0, lib= 0;

	if(brush->id.lib==NULL) return;

	if(brush->clone.image) {
		/* special case: ima always local immediately */
		brush->clone.image->id.lib= NULL;
		brush->clone.image->id.flag= LIB_LOCAL;
		new_id(&bmain->brush, (ID *)brush->clone.image, NULL);
		extern_local_brush(brush);
	}

	for(scene= bmain->scene.first; scene && ELEM(0, lib, local); scene=scene->id.next) {
		if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
			if(scene->id.lib) lib= 1;
			else local= 1;
		}
	}

	if(local && lib==0) {
		brush->id.lib= NULL;
		brush->id.flag= LIB_LOCAL;
		new_id(&bmain->brush, (ID *)brush, NULL);
		extern_local_brush(brush);

		/* enable fake user by default */
		if (!(brush->id.flag & LIB_FAKEUSER)) {
			brush->id.flag |= LIB_FAKEUSER;
			brush->id.us++;
		}
	}
	else if(local && lib) {
		Brush *brushn= copy_brush(brush);
		brushn->id.us= 1; /* only keep fake user */
		brushn->id.flag |= LIB_FAKEUSER;
		
		for(scene= bmain->scene.first; scene; scene=scene->id.next) {
			if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
				if(scene->id.lib==NULL) {
					paint_brush_set(&scene->toolsettings->imapaint.paint, brushn);
				}
			}
		}
	}
}
Exemplo n.º 4
0
void BKE_paint_init(Paint *p, const char col[3])
{
	Brush *brush;

	/* If there's no brush, create one */
	brush = paint_brush(p);
	if (brush == NULL)
		brush = BKE_brush_add("Brush");
	paint_brush_set(p, brush);

	memcpy(p->paint_cursor_col, col, 3);
	p->paint_cursor_col[3] = 128;

	p->flags |= PAINT_SHOW_BRUSH;
}
Exemplo n.º 5
0
/* Brush operators */
static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
{
	/*int type = RNA_enum_get(op->ptr, "type");*/
	Paint *paint = paint_get_active_from_context(C);
	struct Brush *br = paint_brush(paint);

	if (br)
		br = BKE_brush_copy(br);
	else
		br = BKE_brush_add("Brush");

	paint_brush_set(paint, br);

	return OPERATOR_FINISHED;
}
Exemplo n.º 6
0
/* Brush operators */
static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
{
	/*int type = RNA_enum_get(op->ptr, "type");*/
	Paint *paint = paint_get_active(CTX_data_scene(C));
	struct Brush *br = paint_brush(paint);

	if (br)
		br = copy_brush(br);
	else
		br = add_brush("Brush");

	paint_brush_set(paint_get_active(CTX_data_scene(C)), br);

	return OPERATOR_FINISHED;
}
Exemplo n.º 7
0
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
{
	struct Brush *brush, *brush_orig= paint_brush(paint);

	brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);

	if(brush) {
		paint_brush_set(paint, brush);
		WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}