[Bf-blender-cvs] [e0722a2c071] blender2.8: Draw Manager: use pose bone theme and constraint colors

Campbell Barton noreply at git.blender.org
Wed May 3 15:55:08 CEST 2017


Commit: e0722a2c071309aabaf0b14bf8c4c3b8508b5075
Author: Campbell Barton
Date:   Thu May 4 00:00:17 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBe0722a2c071309aabaf0b14bf8c4c3b8508b5075

Draw Manager: use pose bone theme and constraint colors

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

M	source/blender/draw/intern/draw_armature.c
M	source/blender/makesdna/DNA_action_types.h

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

diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c
index 9bc19443499..ec44de60645 100644
--- a/source/blender/draw/intern/draw_armature.c
+++ b/source/blender/draw/intern/draw_armature.c
@@ -211,6 +211,256 @@ static void UNUSED_FUNCTION(DRW_shgroup_bone_relationship_lines)(const float hea
 
 /* -------------------------------------------------------------------- */
 
+/** \name Drawing Theme Helpers
+ * \{ */
+
+/* global here is reset before drawing each bone */
+struct {
+	const ThemeWireColor *bcolor;
+} g_color;
+
+/* values of colCode for set_pchan_color */
+enum {
+	PCHAN_COLOR_NORMAL  = 0,        /* normal drawing */
+	PCHAN_COLOR_SOLID,              /* specific case where "solid" color is needed */
+	PCHAN_COLOR_CONSTS,             /* "constraint" colors (which may/may-not be suppressed) */
+
+	PCHAN_COLOR_SPHEREBONE_BASE,    /* for the 'stick' of sphere (envelope) bones */
+	PCHAN_COLOR_SPHEREBONE_END,     /* for the ends of sphere (envelope) bones */
+	PCHAN_COLOR_LINEBONE            /* for the middle of line-bones */
+};
+
+/* This function sets the color-set for coloring a certain bone */
+static void set_pchan_colorset(Object *ob, bPoseChannel *pchan)
+{
+	bPose *pose = (ob) ? ob->pose : NULL;
+	bArmature *arm = (ob) ? ob->data : NULL;
+	bActionGroup *grp = NULL;
+	short color_index = 0;
+
+	/* sanity check */
+	if (ELEM(NULL, ob, arm, pose, pchan)) {
+		g_color.bcolor = NULL;
+		return;
+	}
+
+	/* only try to set custom color if enabled for armature */
+	if (arm->flag & ARM_COL_CUSTOM) {
+		/* currently, a bone can only use a custom color set if it's group (if it has one),
+		 * has been set to use one
+		 */
+		if (pchan->agrp_index) {
+			grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+			if (grp)
+				color_index = grp->customCol;
+		}
+	}
+
+	/* bcolor is a pointer to the color set to use. If NULL, then the default
+	 * color set (based on the theme colors for 3d-view) is used.
+	 */
+	if (color_index > 0) {
+		bTheme *btheme = UI_GetTheme();
+		g_color.bcolor = &btheme->tarm[(color_index - 1)];
+	}
+	else if (color_index == -1) {
+		/* use the group's own custom color set (grp is always != NULL here) */
+		g_color.bcolor = &grp->cs;
+	}
+	else {
+		g_color.bcolor = NULL;
+	}
+}
+
+/* This function is for brightening/darkening a given color (like UI_GetThemeColorShade3ubv()) */
+static void cp_shade_color3ub(unsigned char cp[3], const int offset)
+{
+	int r, g, b;
+
+	r = offset + (int) cp[0];
+	CLAMP(r, 0, 255);
+	g = offset + (int) cp[1];
+	CLAMP(g, 0, 255);
+	b = offset + (int) cp[2];
+	CLAMP(b, 0, 255);
+
+	cp[0] = r;
+	cp[1] = g;
+	cp[2] = b;
+}
+
+/* This function sets the gl-color for coloring a certain bone (based on bcolor) */
+static bool set_pchan_color(short colCode, const int boneflag, const short constflag, float r_color[4])
+{
+	float *fcolor = r_color;
+	const ThemeWireColor *bcolor = g_color.bcolor;
+
+	switch (colCode) {
+		case PCHAN_COLOR_NORMAL:
+		{
+			if (bcolor) {
+				unsigned char cp[4] = {255};
+
+				if (boneflag & BONE_DRAW_ACTIVE) {
+					copy_v3_v3_char((char *)cp, bcolor->active);
+					if (!(boneflag & BONE_SELECTED)) {
+						cp_shade_color3ub(cp, -80);
+					}
+				}
+				else if (boneflag & BONE_SELECTED) {
+					copy_v3_v3_char((char *)cp, bcolor->select);
+				}
+				else {
+					/* a bit darker than solid */
+					copy_v3_v3_char((char *)cp, bcolor->solid);
+					cp_shade_color3ub(cp, -50);
+				}
+
+				rgb_uchar_to_float(fcolor, cp);
+			}
+			else {
+				if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
+					UI_GetThemeColor4fv(TH_BONE_POSE_ACTIVE, fcolor);
+				}
+				else if (boneflag & BONE_DRAW_ACTIVE) {
+					UI_GetThemeColorBlendShade4fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, fcolor);
+				}
+				else if (boneflag & BONE_SELECTED) {
+					UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+				}
+				else {
+					UI_GetThemeColor4fv(TH_WIRE, fcolor);
+				}
+			}
+
+			return true;
+		}
+		case PCHAN_COLOR_SOLID:
+		{
+			if (bcolor) {
+				rgb_uchar_to_float(fcolor, (unsigned char *)bcolor->solid);
+			}
+			else {
+				UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+			}
+
+			return true;
+		}
+		case PCHAN_COLOR_CONSTS:
+		{
+			if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
+				unsigned char cp[4];
+				if (constflag & PCHAN_HAS_TARGET) rgba_char_args_set((char *)cp, 255, 150, 0, 80);
+				else if (constflag & PCHAN_HAS_IK) rgba_char_args_set((char *)cp, 255, 255, 0, 80);
+				else if (constflag & PCHAN_HAS_SPLINEIK) rgba_char_args_set((char *)cp, 200, 255, 0, 80);
+				else if (constflag & PCHAN_HAS_CONST) rgba_char_args_set((char *)cp, 0, 255, 120, 80);
+
+				rgba_uchar_to_float(fcolor, cp);
+
+				return true;
+			}
+			return false;
+		}
+		case PCHAN_COLOR_SPHEREBONE_BASE:
+		{
+			if (bcolor) {
+				unsigned char cp[4] = {255};
+
+				if (boneflag & BONE_DRAW_ACTIVE) {
+					copy_v3_v3_char((char *)cp, bcolor->active);
+				}
+				else if (boneflag & BONE_SELECTED) {
+					copy_v3_v3_char((char *)cp, bcolor->select);
+				}
+				else {
+					copy_v3_v3_char((char *)cp, bcolor->solid);
+				}
+
+				rgb_uchar_to_float(fcolor, cp);
+			}
+			else {
+				if (boneflag & BONE_DRAW_ACTIVE) {
+					UI_GetThemeColorShade4fv(TH_BONE_POSE, 40, fcolor);
+				}
+				else if (boneflag & BONE_SELECTED) {
+					UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+				}
+				else {
+					UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+				}
+			}
+
+			return true;
+		}
+		case PCHAN_COLOR_SPHEREBONE_END:
+		{
+			if (bcolor) {
+				unsigned char cp[4] = {255};
+
+				if (boneflag & BONE_DRAW_ACTIVE) {
+					copy_v3_v3_char((char *)cp, bcolor->active);
+					cp_shade_color3ub(cp, 10);
+				}
+				else if (boneflag & BONE_SELECTED) {
+					copy_v3_v3_char((char *)cp, bcolor->select);
+					cp_shade_color3ub(cp, -30);
+				}
+				else {
+					copy_v3_v3_char((char *)cp, bcolor->solid);
+					cp_shade_color3ub(cp, -30);
+				}
+
+				rgb_uchar_to_float(fcolor, cp);
+			}
+			else {
+				if (boneflag & BONE_DRAW_ACTIVE) {
+					UI_GetThemeColorShade4fv(TH_BONE_POSE, 10, fcolor);
+				}
+				else if (boneflag & BONE_SELECTED) {
+					UI_GetThemeColorShade4fv(TH_BONE_POSE, -30, fcolor);
+				}
+				else {
+					UI_GetThemeColorShade4fv(TH_BONE_SOLID, -30, fcolor);
+				}
+			}
+			break;
+		}
+		case PCHAN_COLOR_LINEBONE:
+		{
+			/* inner part in background color or constraint */
+			if ((constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS))) {
+				unsigned char cp[4];
+				if (constflag & PCHAN_HAS_TARGET) rgba_char_args_set((char *)cp, 255, 150, 0, 255);
+				else if (constflag & PCHAN_HAS_IK) rgba_char_args_set((char *)cp, 255, 255, 0, 255);
+				else if (constflag & PCHAN_HAS_SPLINEIK) rgba_char_args_set((char *)cp, 200, 255, 0, 255);
+				else if (constflag & PCHAN_HAS_CONST) rgba_char_args_set((char *)cp, 0, 255, 120, 255);
+				else if (constflag) UI_GetThemeColor4ubv(TH_BONE_POSE, cp);  /* PCHAN_HAS_ACTION */
+
+				rgb_uchar_to_float(fcolor, cp);
+			}
+			else {
+				if (bcolor) {
+					const char *cp = bcolor->solid;
+					rgb_uchar_to_float(fcolor, (unsigned char *)cp);
+					fcolor[3] = 204.f / 255.f;
+				}
+				else {
+					UI_GetThemeColorShade4fv(TH_BACK, -30, fcolor);
+				}
+			}
+
+			return true;
+		}
+	}
+
+	return false;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
 /** \name Drawing Color Helpers
  * \{ */
 
@@ -298,15 +548,17 @@ static const float *get_bone_solid_color(const EditBone *eBone, const bPoseChann
 	return g_theme.bone_solid_color;
 }
 
-static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm)
+static const float *get_bone_wire_color(
+        const EditBone *eBone, const bPoseChannel *pchan,
+        const bArmature *arm,
+        const int boneflag, const short constflag)
 {
 	if (g_theme.const_color)
 		return g_theme.const_color;
 
 	if (eBone) {
-		bool is_active = (arm->act_edbone == eBone);
-		if (eBone->flag & BONE_SELECTED) {
-			if (is_active) {
+		if (boneflag & BONE_SELECTED) {
+			if (boneflag & BONE_DRAW_ACTIVE) {
 				return g_theme.edge_select_color;
 			}
 			else {
@@ -314,7 +566,7 @@ static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChanne
 			}
 		}
 		else {
-			if (is_active) {
+			if (boneflag & BONE_DRAW_ACTIVE) {
 				return g_theme.bone_active_unselect_color;
 			}
 			else {
@@ -323,8 +575,13 @@ static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChanne
 		}
 	}
 	else if (arm->flag & ARM_POSEMODE) {
-		bool is_active = (arm->act_bone == pchan->bone);
-		if (pchan->bone->flag & BONE_SELECTED) {
+		set_pchan_color(PCHAN_COLOR_NORMAL, boneflag, constflag, (float *)pchan->disp_color);
+		((float *)pchan->disp_color)[3] = 1.0;
+		return pchan->disp_color;
+
+
+#if 0
+		if (boneflag & BONE_SELECTED) {
 			if (is_active) {
 				return g_theme.bone_pose_active_color;
 			}
@@ -340,6 +597,7 @@ static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChanne
 				return g_theme.wire_color;
 			}
 		}
+#endif
 	}
 
 	return g_theme.vertex_color;
@@ -563,6 +821,7 @@ static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
 
 static void draw_points(
         const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
+        const int boneflag, const short constflag,
         const int select_id)
 {
 	const float *col_solid_root = g_theme.bone_solid_color;
@@ -587,7 +846,7 @@ static void draw_points(
 	}
 	else if (arm->flag & ARM_POSEMODE) {
 		col_solid_root = col_solid_tail = get_bone_solid_color(eBone, pchan, arm);
-		col_wire_root = col_wire_tail = get_bone_wire_color(eBone, pchan, arm);
+		col_wire_root = col_wire_tail = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
 	}
 
 	/*	Draw root point if we are not connected and parent are not hidden */
@@ -633,10 +892,11 @@ static void draw_points(
 
 static void draw_bone_custom_shape(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+        const int boneflag, const short constflag,
         const int select_id)
 {
 	const float *col_solid = get_bone_solid_color(e

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list