[Bf-blender-cvs] [23aa0fdc362] greasepencil-object: Cleanup: De-duplicate dynamic enum function used for setting GP brush icons

Joshua Leung noreply at git.blender.org
Fri Feb 2 07:43:40 CET 2018


Commit: 23aa0fdc3621a2ee486320ae86ba11979c5fb258
Author: Joshua Leung
Date:   Fri Feb 2 19:43:27 2018 +1300
Branches: greasepencil-object
https://developer.blender.org/rB23aa0fdc3621a2ee486320ae86ba11979c5fb258

Cleanup: De-duplicate dynamic enum function used for setting GP brush icons

It turned out that there were slight differences between these two
versions (namely, where they searched for the list of active brushes),
but it's not too much of a stretch to use the same code for this with
a few minor tweaks, as per this commit.

===================================================================

M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 0c4ba1fb499..501e40f79c5 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1554,7 +1554,7 @@ void GPENCIL_OT_brush_change(wmOperatorType *ot)
 
 	/* gp brush to use (dynamic enum) */
 	ot->prop = RNA_def_enum(ot->srna, "brush", DummyRNA_DEFAULT_items, 0, "Grease Pencil Brush", "");
-	RNA_def_enum_funcs(ot->prop, ED_gpencil_brushes_enum_itemf);
+	RNA_def_enum_funcs(ot->prop, rna_GPencilBrush_enum_itemf);
 }
 
 /* ******************* Move Brush Up/Down ************************** */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index ad88006a602..ca8bae77e65 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -316,11 +316,6 @@ const struct EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(
         struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop,
         bool *r_free);
 
-/* Enums of GP Brushes */
-const EnumPropertyItem *ED_gpencil_brushes_enum_itemf(
-        bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
-        bool *r_free);
-
 /* ***************************************************** */
 /* Operator Defines */
 
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 58585a96fa2..7a1ed085046 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -360,72 +360,6 @@ const EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(
 	return item;
 }
 
-/* Dynamic Enums of GP Brushes */
-// XXX: Duplicates rna_GPencilBrush_enum_itemf()
-const EnumPropertyItem *ED_gpencil_brushes_enum_itemf(
-        bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
-        bool *r_free)
-{
-	ToolSettings *ts = CTX_data_tool_settings(C);
-	bGPDbrush *brush;
-	EnumPropertyItem *item = NULL, item_tmp = { 0 };
-	int totitem = 0;
-	int i = 0;
-
-	if (ELEM(NULL, C, ts)) {
-		return DummyRNA_DEFAULT_items;
-	}
-
-	/* Existing brushes */
-	for (brush = ts->gp_brushes.first; brush; brush = brush->next, i++) {
-		item_tmp.identifier = brush->info;
-		item_tmp.name = brush->info;
-		item_tmp.value = i;
-
-		if (brush->flag & GP_BRUSH_ACTIVE)
-			if (brush->flag & GP_BRUSH_FILL_ONLY) {
-				item_tmp.icon = ICON_GPBRUSH_FILL;
-			}
-			else {
-				item_tmp.icon = ED_gpencil_get_brush_icon(brush->icon);
-			}
-		else
-			item_tmp.icon = ICON_NONE;
-
-		RNA_enum_item_add(&item, &totitem, &item_tmp);
-	}
-
-	RNA_enum_item_end(&item, &totitem);
-	*r_free = true;
-
-	return item;
-}
-
-/* helper to get brush icon */
-int ED_gpencil_get_brush_icon(int type)
-{
-	switch (type) {
-		case GPBRUSH_CUSTOM:
-			return ICON_GPBRUSH_CUSTOM;
-		case GPBRUSH_PENCIL:
-			return ICON_GPBRUSH_PENCIL;
-		case GPBRUSH_PEN:
-			return ICON_GPBRUSH_PEN;
-		case GPBRUSH_INK:
-			return ICON_GPBRUSH_INK;
-		case GPBRUSH_INKNOISE:
-			return ICON_GPBRUSH_INKNOISE;
-		case GPBRUSH_BLOCK:
-			return ICON_GPBRUSH_BLOCK;
-		case GPBRUSH_MARKER:
-			return ICON_GPBRUSH_MARKER;
-		case GPBRUSH_FILL:
-			return ICON_GPBRUSH_FILL;
-		default:
-			return ICON_GPBRUSH_CUSTOM;
-	}
-}
-
 
 /* ******************************************************** */
 /* Brush Tool Core */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 9c6cf8e1cf9..a3fb091f16f 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -149,6 +149,9 @@ void ED_gpencil_draw_view3d_object(struct wmWindowManager *wm,
                                    bool only3d);
 void ED_gpencil_draw_ex(struct RegionView3D *rv3d, struct Scene *scene, struct bGPdata *gpd, int winx, int winy,
                         const int cfra, const char spacetype);
+
+/* Modal Operator Geometry Preview */
+// XXX: Are these called from the draw engine at all? Can we hide these?
 void ED_gp_draw_interpolation(const struct bContext *C, struct tGPDinterpolate *tgpi, const int type);
 void ED_gp_draw_primitives(const struct bContext *C, struct tGPDprimitive *tgpi, const int type);
 void ED_gp_draw_fill(struct tGPDdraw *tgpw);
@@ -216,7 +219,4 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
 /* join objects */
 int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
 
-/* helper to get brush icon */
-int ED_gpencil_get_brush_icon(int type);
-
 #endif /*  __ED_GPENCIL_H__ */
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 9c0b269da85..41a1da977bf 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -229,10 +229,13 @@ const EnumPropertyItem *rna_node_socket_type_itemf(
 struct bContext;
 struct PointerRNA;
 struct PropertyRNA;
+
 const EnumPropertyItem *rna_TransformOrientation_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
 const EnumPropertyItem *rna_Sensor_type_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
 const EnumPropertyItem *rna_Actuator_type_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
 
+const EnumPropertyItem *rna_GPencilBrush_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
+
 /* Generic functions, return an enum from library data, index is the position
  * in the linked list can add more for different types as needed */
 const EnumPropertyItem *RNA_action_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 61d3fa64fb6..6d65de64618 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -632,18 +632,57 @@ static void rna_GPencilBrush_name_set(PointerRNA *ptr, const char *value)
 	BLI_uniquename(&ts->gp_brushes, brush, DATA_("GP_Brush"), '.', offsetof(bGPDbrush, info), sizeof(brush->info));
 }
 
+/* GPencilBrush icon */
+static int gpencil_get_brush_icon(int type)
+{
+	switch (type) {
+		case GPBRUSH_CUSTOM:
+			return ICON_GPBRUSH_CUSTOM;
+		case GPBRUSH_PENCIL:
+			return ICON_GPBRUSH_PENCIL;
+		case GPBRUSH_PEN:
+			return ICON_GPBRUSH_PEN;
+		case GPBRUSH_INK:
+			return ICON_GPBRUSH_INK;
+		case GPBRUSH_INKNOISE:
+			return ICON_GPBRUSH_INKNOISE;
+		case GPBRUSH_BLOCK:
+			return ICON_GPBRUSH_BLOCK;
+		case GPBRUSH_MARKER:
+			return ICON_GPBRUSH_MARKER;
+		case GPBRUSH_FILL:
+			return ICON_GPBRUSH_FILL;
+		default:
+			return ICON_GPBRUSH_CUSTOM;
+	}
+}
+
 /* Dynamic Enums of GP Brushes */
-static const EnumPropertyItem *rna_GPencilBrush_enum_itemf(
-        bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop),
-	bool *r_free)
+ const EnumPropertyItem *rna_GPencilBrush_enum_itemf(
+        bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop),
+        bool *r_free)
 {
-	ToolSettings *ts = ((Scene *)ptr->id.data)->toolsettings;
+	ToolSettings *ts = NULL;
 	bGPDbrush *brush;
-	EnumPropertyItem *item = NULL, item_tmp = { 0 };
+	EnumPropertyItem item_tmp = {0};
+	EnumPropertyItem *item = NULL;
 	int totitem = 0;
 	int i = 0;
-
-	if (ELEM(NULL, ts)) {
+	
+	/* Try to get toolsettings pointer */
+	if (ptr->id.data != NULL) {
+		Scene *scene = ptr->id.data;
+		
+		if (GS(scene->id.name) == ID_SCE) {
+			ts = scene->toolsettings;
+		}
+	}
+	else if (C != NULL) {
+		ts = CTX_data_tool_settings(C);
+	}
+	
+	/* Fallback - For generating Py/RNA docs */
+	if (ts == NULL) {
 		return rna_enum_gpencil_drawing_brushes_items;
 	}
 
@@ -656,7 +695,7 @@ static const EnumPropertyItem *rna_GPencilBrush_enum_itemf(
 			item_tmp.icon = ICON_GPBRUSH_FILL;
 		}
 		else {
-			item_tmp.icon = ED_gpencil_get_brush_icon(brush->icon);
+			item_tmp.icon = gpencil_get_brush_icon(brush->icon);
 		}
 
 		RNA_enum_item_add(&item, &totitem, &item_tmp);



More information about the Bf-blender-cvs mailing list