Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-11-25 00:49:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-11-25 02:40:52 +0400
commit4a6802b00b38ca03f6f8d75e5b2a786b4a3c1a16 (patch)
tree04578b08c3b29a1c6535278a8f57003152ca0b87 /source/blender/editors/transform/transform_orientations.c
parentcbb5a12eb71e28aeeba594d480e46f179bb955cf (diff)
Transform: internal changes for orientations calculations.
- use (const char *) for the 'name' - use bool where possible. - remove unused return value for initTransInfo
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r--source/blender/editors/transform/transform_orientations.c85
1 files changed, 41 insertions, 44 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index cd6a2e6712e..9a50c0c73da 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -78,15 +78,7 @@ void BIF_clearTransformOrientation(bContext *C)
static TransformOrientation *findOrientationName(ListBase *lb, const char *name)
{
- TransformOrientation *ts = NULL;
-
- for (ts = lb->first; ts; ts = ts->next) {
- if (strncmp(ts->name, name, sizeof(ts->name) - 1) == 0) {
- return ts;
- }
- }
-
- return NULL;
+ return BLI_findstring(lb, name, offsetof(TransformOrientation, name));
}
static bool uniqueOrientationNameCheck(void *arg, const char *name)
@@ -100,7 +92,8 @@ static void uniqueOrientationName(ListBase *lb, char *name)
sizeof(((TransformOrientation *)NULL)->name));
}
-static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
+static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports),
+ const char *name, const bool overwrite)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float mat[3][3];
@@ -111,21 +104,22 @@ static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(rep
copy_m3_m4(mat, rv3d->viewinv);
normalize_m3(mat);
- if (!name[0]) {
+ if (name[0] == 0) {
View3D *v3d = CTX_wm_view3d(C);
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
/* If an object is used as camera, then this space is the same as object space! */
- BLI_strncpy(name, v3d->camera->id.name + 2, MAX_NAME);
+ name = v3d->camera->id.name + 2;
}
else {
- strcpy(name, "Custom View");
+ name = "Custom View";
}
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
+static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports),
+ const char *name, const bool overwrite)
{
Base *base = CTX_data_active_base(C);
Object *ob;
@@ -141,13 +135,14 @@ static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(r
/* use object name if no name is given */
if (name[0] == 0) {
- BLI_strncpy(name, ob->id.name + 2, MAX_ID_NAME - 2);
+ name = ob->id.name + 2;
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -160,13 +155,14 @@ static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Bone");
+ name = "Bone";
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -179,14 +175,15 @@ static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
}
if (name[0] == 0) {
- strcpy(name, "Curve");
+ name = "Curve";
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -202,7 +199,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Vertex");
+ name = "Vertex";
}
break;
case ORIENTATION_EDGE:
@@ -212,7 +209,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Edge");
+ name = "Edge";
}
break;
case ORIENTATION_FACE:
@@ -222,7 +219,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Face");
+ name = "Face";
}
break;
default:
@@ -288,8 +285,9 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa
return true;
}
-/* name must be a MAX_NAME length string! */
-void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use_view, int use, int overwrite)
+void BIF_createTransformOrientation(bContext *C, ReportList *reports,
+ const char *name, const bool use_view,
+ const bool activate, const bool overwrite)
{
TransformOrientation *ts = NULL;
@@ -315,21 +313,25 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name
}
}
- if (use && ts != NULL) {
+ if (activate && ts != NULL) {
BIF_selectTransformOrientation(C, ts);
}
}
-TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
+TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
+ const char *name, const bool overwrite)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = NULL;
+ char name_unique[sizeof(ts->name)];
if (overwrite) {
ts = findOrientationName(transform_spaces, name);
}
else {
- uniqueOrientationName(transform_spaces, name);
+ BLI_strncpy(name_unique, name, sizeof(name_unique));
+ uniqueOrientationName(transform_spaces, name_unique);
+ name = name_unique;
}
/* if not, create a new one */
@@ -422,17 +424,10 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation)
int BIF_countTransformOrientation(const bContext *C)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- TransformOrientation *ts;
- int count = 0;
-
- for (ts = transform_spaces->first; ts; ts = ts->next) {
- count++;
- }
-
- return count;
+ return BLI_countlist(transform_spaces);
}
-void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX_NAME])
+void applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name)
{
TransformOrientation *ts;
View3D *v3d = CTX_wm_view3d(C);
@@ -443,8 +438,8 @@ void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX
for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
if (selected_index == i) {
- if (name) {
- BLI_strncpy(name, ts->name, MAX_NAME);
+ if (r_name) {
+ BLI_strncpy(r_name, ts->name, MAX_NAME);
}
copy_m3_m3(mat, ts->mat);
@@ -454,10 +449,10 @@ void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX
}
}
-static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
+static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
{
Bone *bone;
- int do_next;
+ bool do_next;
int total = 0;
for (bone = lb->first; bone; bone = bone->next) {
@@ -468,7 +463,9 @@ static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
if (bone->flag & BONE_SELECTED) {
bone->flag |= BONE_TRANSFORM;
total++;
- do_next = FALSE; // no transform on children if one parent bone is selected
+
+ /* no transform on children if one parent bone is selected */
+ do_next = false;
}
}
}
@@ -537,7 +534,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
}
}
-int getTransformOrientation(const bContext *C, float normal[3], float plane[3], int activeOnly)
+int getTransformOrientation(const bContext *C, float normal[3], float plane[3], const bool activeOnly)
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
@@ -864,7 +861,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
else {
int totsel;
- totsel = count_bone_select(arm, &arm->bonebase, 1);
+ totsel = count_bone_select(arm, &arm->bonebase, true);
if (totsel) {
/* use channels to get stats */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {