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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-09-16 08:19:22 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-09-16 08:19:22 +0400
commit36c273b1f7c65a759f77c8ed42b65b878dbb09da (patch)
tree8b75b606f4745c980c21790ff641b38fdb87d9ae /source
parentd6baea457e51c1443d68eb4ca5393e7de9981c02 (diff)
- bone roll now in degrees not radians.
- rna buttons with units set now use the units base value for snapping. - bone head/tail radius could be set negative. matt: removed a check in ui_is_but_unit() which made angle buttons return false, what was this for?
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_unit.h4
-rw-r--r--source/blender/blenkernel/intern/unit.c16
-rw-r--r--source/blender/editors/interface/interface.c6
-rw-r--r--source/blender/editors/interface/interface_handlers.c62
-rw-r--r--source/blender/makesrna/intern/rna_armature.c10
-rw-r--r--source/blender/makesrna/intern/rna_object.c3
6 files changed, 74 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h
index 65bdea8095a..7461d43e721 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -45,6 +45,9 @@ double bUnit_ClosestScalar(double value, int system, int type);
/* base scale for these units */
double bUnit_BaseScalar(int system, int type);
+/* return true is the unit system exists */
+int bUnit_IsValid(int system, int type);
+
/* loop over scales, coudl add names later */
//double bUnit_Iter(void **unit, char **name, int system, int type);
@@ -63,6 +66,7 @@ double bUnit_GetScaler(void *usys_pt, int index);
#define B_UNIT_TIME 6
#define B_UNIT_VELOCITY 7
#define B_UNIT_ACCELERATION 8
+#define B_UNIT_MAXDEF 9
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 963cfdbea1b..36a4cfea7a0 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include "BKE_unit.h"
+
#ifdef WIN32
#define _USE_MATH_DEFINES
#endif
@@ -31,6 +33,7 @@
#include "BLI_winstuff.h"
+
#define TEMP_STR_SIZE 256
#define SEP_CHR '#'
@@ -127,7 +130,8 @@ static struct bUnitDef buNaturalRotDef[] = {
};
static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, sizeof(buNaturalRotDef)/sizeof(bUnitDef)};
-#define UNIT_SYSTEM_MAX 3
+#define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / 8) / sizeof(void *)) - 1)
+
static struct bUnitCollection *bUnitSystems[][8] = {
{0,0,0,0,0,&buNaturalRotCollection,&buNaturalTimeCollecton,0},
{0,&buMetricLenCollecton, 0,0,0, &buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* metric */
@@ -135,6 +139,8 @@ static struct bUnitCollection *bUnitSystems[][8] = {
{0,0,0,0,0,0,0,0}
};
+
+
/* internal, has some option not exposed */
static bUnitCollection *unit_get_system(int system, int type)
{
@@ -459,7 +465,7 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre
bUnitCollection *usys_iter;
int system_iter;
- for(system_iter= 0; system_iter<UNIT_SYSTEM_MAX; system_iter++) {
+ for(system_iter= 0; system_iter<UNIT_SYSTEM_TOT; system_iter++) {
if (system_iter != system) {
usys_iter= unit_get_system(system_iter, type);
if (usys_iter) {
@@ -610,6 +616,12 @@ double bUnit_BaseScalar(int system, int type)
}
/* external access */
+int bUnit_IsValid(int system, int type)
+{
+ return !(type < 0 || type >= B_UNIT_MAXDEF || system < 0 || system > UNIT_SYSTEM_TOT);
+}
+
+
void bUnit_GetSystem(void **usys_pt, int *len, int system, int type)
{
bUnitCollection *usys = unit_get_system(system, type);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 59e0af634b8..f6ba948db7d 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1234,11 +1234,13 @@ int ui_is_but_unit(uiBut *but)
if(but->rnaprop==NULL)
return 0;
-
+
unit_type = RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop));
-
+
+#if 0 // removed so angle buttons get correct snapping
if (scene->unit.flag & USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
return 0;
+#endif
/* for now disable time unit conversion */
if (unit_type == PROP_UNIT_TIME)
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index b4ac56a6f0f..fea152bb4a7 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -44,6 +44,7 @@
#include "BKE_idprop.h"
#include "BKE_report.h"
#include "BKE_texture.h"
+#include "BKE_unit.h"
#include "ED_screen.h"
#include "ED_util.h"
@@ -2195,26 +2196,47 @@ static int ui_do_but_EXIT(bContext *C, uiBut *but, uiHandleButtonData *data, wmE
}
/* var names match ui_numedit_but_NUM */
-static float ui_numedit_apply_snapf(float tempf, float softmin, float softmax, float softrange, int snap)
+static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, float softmax, float softrange, int snap)
{
- if(tempf==softmin || tempf==softmax)
- return tempf;
+ if(tempf==softmin || tempf==softmax || snap==0) {
+ /* pass */
+ }
+ else {
+ float fac= 1.0f;
+
+ if(ui_is_but_unit(but)) {
+ Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+ int unit_type = RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
+
+ if(bUnit_IsValid(scene->unit.system, unit_type)) {
+ fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type);
+ if(ELEM3(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) {
+ fac /= scene->unit.scale_length;
+ }
+ }
+ }
- switch(snap) {
- case 0:
- break;
- case 1:
- if(tempf==softmin || tempf==softmax) { }
- else if(softrange < 2.10) tempf= 0.1*floor(10*tempf);
- else if(softrange < 21.0) tempf= floor(tempf);
- else tempf= 10.0*floor(tempf/10.0);
- break;
- case 2:
- if(tempf==softmin || tempf==softmax) { }
- else if(softrange < 2.10) tempf= 0.01*floor(100.0*tempf);
- else if(softrange < 21.0) tempf= 0.1*floor(10.0*tempf);
- else tempf= floor(tempf);
- break;
+ if(fac != 1.0f) {
+ /* snap in unit-space */
+ tempf /= fac;
+ softmin /= fac;
+ softmax /= fac;
+ softrange /= fac;
+ }
+
+ if(snap==1) {
+ if(softrange < 2.10) tempf= 0.1*floor(10*tempf);
+ else if(softrange < 21.0) tempf= floor(tempf);
+ else tempf= 10.0*floor(tempf/10.0);
+ }
+ else if(snap==2) {
+ if(softrange < 2.10) tempf= 0.01*floor(100.0*tempf);
+ else if(softrange < 21.0) tempf= 0.1*floor(10.0*tempf);
+ else tempf= floor(tempf);
+ }
+
+ if(fac != 1.0f)
+ tempf *= fac;
}
return tempf;
@@ -2267,7 +2289,7 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i
if(ui_is_but_float(but)) {
fac *= 0.01*but->a1;
tempf = data->startvalue + ((mx - data->dragstartx) * fac);
- tempf= ui_numedit_apply_snapf(tempf, softmin, softmax, softrange, snap);
+ tempf= ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap);
#if 1 /* fake moving the click start, nicer for dragging back after passing the limit */
if(tempf < softmin) {
@@ -2360,7 +2382,7 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i
}
else {
temp= 0;
- tempf= ui_numedit_apply_snapf(tempf, softmin, softmax, softrange, snap);
+ tempf= ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap);
CLAMP(tempf, softmin, softmax);
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 0a79a4ff538..8d0f7d5fae0 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -23,6 +23,7 @@
*/
#include <stdlib.h>
+#include <math.h>
#include "RNA_define.h"
@@ -468,16 +469,18 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
RNA_def_property_ui_text(prop, "Envelope Deform Weight", "Bone deformation weight (for Envelope deform only)");
RNA_def_property_update(prop, 0, "rna_Armature_update_data");
- prop= RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_UNSIGNED);
if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
RNA_def_property_float_sdna(prop, NULL, "rad_head");
//RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
+ RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
RNA_def_property_ui_text(prop, "Envelope Head Radius", "Radius of head of bone (for Envelope deform only)");
- prop= RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_UNSIGNED);
if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
RNA_def_property_float_sdna(prop, NULL, "rad_tail");
//RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
+ RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
RNA_def_property_ui_text(prop, "Envelope Tail Radius", "Radius of tail of bone (for Envelope deform only)");
/* b-bones deform settings */
@@ -601,8 +604,9 @@ static void rna_def_edit_bone(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Parent", "Parent edit bone (in same Armature)");
RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
- prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_ANGLE);
RNA_def_property_float_sdna(prop, NULL, "roll");
+ RNA_def_property_ui_range(prop, -M_PI * 2, M_PI * 2, 0.1, 2);
RNA_def_property_ui_text(prop, "Roll", "Bone rotation around head-tail axis");
RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 3777005aaad..d354e152fce 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1748,6 +1748,7 @@ static void rna_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_float_sdna(prop, NULL, "loc");
RNA_def_property_editable_array_func(prop, "rna_Object_location_editable");
+ RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
RNA_def_property_ui_text(prop, "Location", "Location of the object");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
@@ -1785,6 +1786,7 @@ static void rna_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "size");
RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
+ RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
RNA_def_property_float_array_default(prop, default_scale);
RNA_def_property_ui_text(prop, "Scale", "Scaling of the object");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
@@ -1792,6 +1794,7 @@ static void rna_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL);
+ RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
RNA_def_property_ui_text(prop, "Dimensions", "Absolute bounding box dimensions of the object");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");