[Bf-blender-cvs] [49f394946ee] greasepencil-object: Various fixes to get GP Palettes UI working
Joshua Leung
noreply at git.blender.org
Wed Oct 4 14:17:14 CEST 2017
Commit: 49f394946ee2290c228ba5b8234280a2637abde5
Author: Joshua Leung
Date: Wed Oct 4 13:56:49 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB49f394946ee2290c228ba5b8234280a2637abde5
Various fixes to get GP Palettes UI working
* Switched the UI to using the "active_gpencil_palette" (and palette color) context
vars (in favor of the "active_palette"/color) ones for retrieving the active
palette. For some unknown reason, context.active_object returns null when
trying to use it in the Properties Editor when drawing UI layouts, but it works
perfectly fine when operators calling operator.poll() or running operators.
* Sanitise many of the hacks added to the Palette operators to make them usable
for Grease Pencil-linked palettes (e.g. remove special hacky args)
* Add RNA support for getting the active GP palette slot
===================================================================
M release/scripts/startup/bl_ui/properties_material_gpencil.py
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/paint.c
M source/blender/editors/screen/screen_context.c
M source/blender/editors/sculpt_paint/paint_ops.c
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 6c0e541c79a..5d6856a9fa1 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -97,10 +97,10 @@ class MATERIAL_PT_gpencil_palette_colors(Panel):
layout = self.layout
gpd = context.gpencil_data
- slot = gpd.palette_slots[gpd.active_palette_index] # XXX
-
- #palette = context.active_palette
- palette = slot.palette if slot else None
+ slot = gpd.active_palette_slot
+ #palette = slot.palette
+ palette = context.active_gpencil_palette
+ #assert(slot.palette == palette)
row = layout.row()
row.template_ID(slot, "palette", new="palette.new_gpencil")
@@ -118,7 +118,7 @@ class MATERIAL_PT_gpencil_palette_colors(Panel):
col = row.column()
sub = col.column(align=True)
- sub.operator("palette.color_add", icon='ZOOMIN', text="").grease_pencil = True
+ sub.operator("palette.color_add", icon='ZOOMIN', text="")
sub.operator("palette.color_delete", icon='ZOOMOUT', text="")
palcol = context.active_palettecolor
@@ -147,12 +147,12 @@ class MATERIAL_PT_gpencil_palette_strokecolor(Panel):
@classmethod
def poll(cls, context):
- return context.object and context.object.type == 'GPENCIL' and context.active_palettecolor
+ return context.object and context.object.type == 'GPENCIL' and context.active_gpencil_palettecolor
@staticmethod
def draw(self, context):
layout = self.layout
- palette = context.active_palette
+ palette = context.active_gpencil_palette
pcolor = palette.colors.active
split = layout.split(percentage=1.0)
@@ -193,12 +193,12 @@ class MATERIAL_PT_gpencil_palette_fillcolor(Panel):
@classmethod
def poll(cls, context):
- return context.object and context.object.type == 'GPENCIL' and context.active_palettecolor
+ return context.object and context.object.type == 'GPENCIL' and context.active_gpencil_palettecolor
@staticmethod
def draw(self, context):
layout = self.layout
- palette = context.active_palette
+ palette = context.active_gpencil_palette
pcolor = palette.colors.active
# color settings
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index f87f35a8c27..0a903256720 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1885,6 +1885,7 @@ void BKE_gpencil_palettecolor_delete_allstrokes(bContext *C, PaletteColor *palco
Main *bmain = CTX_data_main(C);
+ /* TODO: Optimise this by only checking GP datablocks that reference the palette this comes from */
for (gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 582f912a93c..c280a71ab3d 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -371,6 +371,9 @@ Palette *BKE_palette_get_active_from_context(const bContext *C)
Object *ob = CTX_data_active_object(C);
Palette *palette = NULL;
+ /* XXX: Object detection fails in some contexts
+ * (e.g. Properties Editor when drawing UI)
+ */
if ((ob) && (ob->type == OB_GPENCIL)) {
bGPdata *gpd = CTX_data_gpencil_data(C);
bGPDpaletteref *palslot = BKE_gpencil_paletteslot_get_active(gpd);
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index 04c3c90181f..ae2879d90bc 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -480,17 +480,23 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
}
}
else if (CTX_data_equals(member, "active_gpencil_palette")) {
- Palette *palette = BKE_palette_get_active_from_context(C);
-
- if (palette) {
+ /* XXX: see comment for gpencil_data case... */
+ bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
+ bGPDpaletteref *palslot = BKE_gpencil_paletteslot_get_active(gpd);
+
+ if (palslot && palslot->palette) {
+ Palette *palette = palslot->palette;
CTX_data_pointer_set(result, &palette->id, &RNA_Palette, palette);
return 1;
}
}
else if (CTX_data_equals(member, "active_gpencil_palettecolor")) {
- Palette *palette = BKE_palette_get_active_from_context(C);
-
- if (palette) {
+ /* XXX: see comment for gpencil_data case... */
+ bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact);
+ bGPDpaletteref *palslot = BKE_gpencil_paletteslot_get_active(gpd);
+
+ if (palslot && palslot->palette) {
+ Palette *palette = palslot->palette;
PaletteColor *palcolor = BKE_palette_color_get_active(palette);
if (palcolor) {
CTX_data_pointer_set(result, &palette->id, &RNA_PaletteColor, palcolor);
@@ -499,7 +505,6 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
}
}
else if (CTX_data_equals(member, "active_gpencil_brush")) {
- /* XXX: see comment for gpencil_data case... */
bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings);
if (brush) {
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 1ebf499669a..e41e77f0639 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -214,12 +214,8 @@ static void PALETTE_OT_new(wmOperatorType *ot)
static int palette_poll(bContext *C)
{
- Paint *paint = BKE_paint_get_active_from_context(C);
-
- if (paint && paint->palette != NULL)
- return true;
-
- return false;
+ Palette *palette = BKE_palette_get_active_from_context(C);
+ return (palette != NULL);
}
static int palette_new_gpencil_exec(bContext *C, wmOperator *UNUSED(op))
@@ -316,18 +312,22 @@ static void PALETTE_OT_lock_layer(wmOperatorType *ot)
static int palette_color_add_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
+ Palette *palette = BKE_palette_get_active_from_context(C);
Paint *paint = BKE_paint_get_active_from_context(C);
- Brush *brush = paint->brush;
- PaintMode mode = BKE_paintmode_get_active_from_context(C);
- Palette *palette = paint->palette;
PaletteColor *color;
- const bool grease_pencil = RNA_boolean_get(op->ptr, "grease_pencil");
-
+ /* Add a new color and make it active */
color = BKE_palette_color_add(palette);
palette->active_color = BLI_listbase_count(&palette->colors) - 1;
- if (!grease_pencil) {
+ /* For Grease Pencil, the active palette won't be the one the current
+ * Paint context stores (as it comes from the active Palette Slot on the
+ * current GP Object instead)
+ */
+ if (palette != paint->palette) {
+ PaintMode mode = BKE_paintmode_get_active_from_context(C);
+ Brush *brush = paint->brush;
+
if (ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex)) {
copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
color->value = 0.0;
@@ -337,9 +337,6 @@ static int palette_color_add_exec(bContext *C, wmOperator *op)
color->value = brush->weight;
}
}
-
- /* disable option to avoid errors */
- RNA_boolean_set(op->ptr, "grease_pencil", false);
return OPERATOR_FINISHED;
}
@@ -354,24 +351,23 @@ static void PALETTE_OT_color_add(wmOperatorType *ot)
/* api callbacks */
ot->exec = palette_color_add_exec;
ot->poll = palette_poll;
+
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* grease pencil */
- RNA_def_boolean(ot->srna, "grease_pencil", false, "Grease Pencil", "The color is for grease pencil mode");
}
static int palette_color_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
Paint *paint = BKE_paint_get_active_from_context(C);
- Palette *palette = paint->palette;
+ Palette *palette = BKE_palette_get_active_from_context(C);
PaletteColor *color = BLI_findlink(&palette->colors, palette->active_color);
if (color) {
- /* delete the gp strokes */
+ /* delete any gp strokes using this color */
BKE_gpencil_palettecolor_delete_allstrokes(C, color);
-
+
+ /* delete the active color */
BKE_palette_color_remove(palette, color);
}
@@ -396,6 +392,7 @@ static void PALETTE_OT_color_delete(wmOperatorType *ot)
}
/* ********************** Isolate palette color **************************** */
+
static int palettecolor_isolate_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
@@ -474,6 +471,7 @@ static void PALETTE_OT_palettecolor_isolate(wmOperatorType *ot)
}
/* *********************** Hide Palette colors ******************************** */
+
static int palettecolor_hide_exec(bContext *C, wmOperator *op)
{
Palette *palette = BKE_palette_get_active_from_context(C);
@@ -525,6 +523,7 @@ static void PALETTE_OT_palettecolor_hide(wmOperatorType *ot)
}
/* ********************** Show All Colors ***************************** */
+
static int palettecolor_reveal_exec(bContext *C, wmOperator *UNUSED(op))
{
Palette *palette = BKE_palette_get_active_from_context(C);
@@ -561,6 +560,7 @@ static void PALETTE_OT_palettecolor_reveal(wmOperatorType *ot)
}
/* ***************** Lock/Unlock All Palette colors ************************ */
+
static int palettecolor_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
{
Palette *palette = BKE_palette_get_active_from_context(C);
@@ -597,6 +597,7 @@ static void PALETTE_OT_palettecolor_lock_all(wmOperatorType *ot)
}
/* -------------------------- */
+
static int palettecolor_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
{
Palette *palette = BKE_palette_get_active_from_context(C);
@@ -633,6 +634,7 @@ static void PALETTE_OT_palettecolor_unlock_all(wmOperatorType *ot)
}
/* ******************* Move Color Up/Down ************************** */
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list