[Bf-blender-cvs] [cb82eda] wiggly-widgets: Cleanup: Mixed code and declarations are allowed now \o/
Julian Eisel
noreply at git.blender.org
Tue Nov 24 16:27:59 CET 2015
Commit: cb82eda2eee33d1a1a6a60acb95753fdb90b3122
Author: Julian Eisel
Date: Tue Nov 24 16:06:40 2015 +0100
Branches: wiggly-widgets
https://developer.blender.org/rBcb82eda2eee33d1a1a6a60acb95753fdb90b3122
Cleanup: Mixed code and declarations are allowed now \o/
(And other cleanup)
===================================================================
M source/blender/editors/space_view3d/view3d_widgets.c
M source/blender/windowmanager/intern/wm_generic_widgets.c
M source/blender/windowmanager/intern/wm_widgets.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_widgets.c b/source/blender/editors/space_view3d/view3d_widgets.c
index d14cdef..c63d1a7 100644
--- a/source/blender/editors/space_view3d/view3d_widgets.c
+++ b/source/blender/editors/space_view3d/view3d_widgets.c
@@ -88,31 +88,21 @@ void WIDGETGROUP_camera_create(const bContext *C, wmWidgetGroup *wgroup)
/* focal length
* - logic/calculations are similar to BKE_camera_view_frame_ex, better keep in sync */
if (focallen_widget) {
- const Scene *scene = CTX_data_scene(C);
const bool is_ortho = (ca->type == CAM_ORTHO);
- const float scale_fac = ca->drawsize;
- const float half_sensor = 0.5f * ((ca->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? ca->sensor_y : ca->sensor_x);
- const float scale[3] = {1.0f / len_v3(ob->obmat[0]), 1.0f / len_v3(ob->obmat[1]), 1.0f / len_v3(ob->obmat[2])};
- const float drawsize = is_ortho ? (0.5f * ca->ortho_scale) :
- (scale_fac / ((scale[0] + scale[1] + scale[2]) / 3.0f));
- const float aspx = (float)scene->r.xsch * scene->r.xasp;
- const float aspy = (float)scene->r.ysch * scene->r.yasp;
- const int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, aspx, aspy);
const char *propname = is_ortho ? "ortho_scale" : "lens";
- const bool fit_hor = (sensor_fit == CAMERA_SENSOR_FIT_HOR);
-
- const float color[4] = {1.0f, 1.0, 0.27f, 0.5f};
- const float color_hi[4] = {1.0f, 1.0, 0.27f, 1.0f};
- PropertyRNA *prop;
float offset[3], asp[2];
float min, max, range;
- float step, precision; /* dummys, unused */
+ float step, precision;
/* get aspect */
- asp[0] = fit_hor ? 1.0 : aspx / aspy;
- asp[1] = fit_hor ? aspy / aspx : 1.0f;
+ const Scene *scene = CTX_data_scene(C);
+ const float aspx = (float)scene->r.xsch * scene->r.xasp;
+ const float aspy = (float)scene->r.ysch * scene->r.yasp;
+ const int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, aspx, aspy);
+ asp[0] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? 1.0 : aspx / aspy;
+ asp[1] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? aspy / aspx : 1.0f;
/* account for lens shifting */
offset[0] = ((ob->size[0] > 0.0f) ? -2.0f : 2.0f) * ca->shiftx;
@@ -120,13 +110,21 @@ void WIDGETGROUP_camera_create(const bContext *C, wmWidgetGroup *wgroup)
offset[2] = 0.0f;
/* get property range */
- prop = RNA_struct_find_property(&cameraptr, propname);
+ PropertyRNA *prop = RNA_struct_find_property(&cameraptr, propname);
RNA_property_float_ui_range(&cameraptr, prop, &min, &max, &step, &precision);
range = max - min;
/* *** actual widget stuff *** */
+ const float scale[3] = {1.0f / len_v3(ob->obmat[0]), 1.0f / len_v3(ob->obmat[1]), 1.0f / len_v3(ob->obmat[2])};
+ const float scale_fac = ca->drawsize;
+ const float drawsize = is_ortho ? (0.5f * ca->ortho_scale) :
+ (scale_fac / ((scale[0] + scale[1] + scale[2]) / 3.0f));
+ const float half_sensor = 0.5f * ((ca->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? ca->sensor_y : ca->sensor_x);
+ const float color[4] = {1.0f, 1.0, 0.27f, 0.5f};
+ const float color_hi[4] = {1.0f, 1.0, 0.27f, 1.0f};
+
widget = WIDGET_arrow_new(wgroup, propname, (WIDGET_ARROW_STYLE_CONE | WIDGET_ARROW_STYLE_CONSTRAINED));
WIDGET_arrow_set_range_fac(widget, is_ortho ? (scale_fac * range) : (drawsize * range / half_sensor));
@@ -147,7 +145,7 @@ int WIDGETGROUP_forcefield_poll(const bContext *C, wmWidgetGroupType *UNUSED(wgr
{
Object *ob = CTX_data_active_object(C);
- return ob && ob->pd && ob->pd->forcefield;
+ return (ob && ob->pd && ob->pd->forcefield);
}
void WIDGETGROUP_forcefield_create(const bContext *C, wmWidgetGroup *wgroup)
@@ -230,8 +228,7 @@ int WIDGETGROUP_armature_facemaps_poll(const bContext *C, wmWidgetGroupType *UNU
#ifdef USE_FACEMAP_FROM_BONE
if (ob && BKE_object_pose_context_check(ob)) {
- bPoseChannel *pchan;
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
if (pchan->fmap_object && pchan->fmap) {
return true;
}
@@ -263,11 +260,10 @@ int WIDGETGROUP_armature_facemaps_poll(const bContext *C, wmWidgetGroupType *UNU
static void WIDGET_armature_facemaps_select(bContext *C, wmWidget *widget, const int action)
{
Object *ob = CTX_data_active_object(C);
- bPoseChannel *pchan;
switch (action) {
case SEL_SELECT:
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
if (pchan->fmap == WIDGET_facemap_get_fmap(widget)) {
/* deselect all first */
ED_pose_de_selectall(ob, SEL_DESELECT, false);
@@ -284,10 +280,6 @@ void WIDGETGROUP_armature_facemaps_create(const bContext *C, wmWidgetGroup *wgro
{
Object *ob = CTX_data_active_object(C);
bArmature *arm = (bArmature *)ob->data;
- wmWidget *widget;
- PointerRNA famapptr;
- PropertyRNA *prop;
-
#ifdef USE_FACEMAP_FROM_BONE
bPoseChannel *pchan;
@@ -297,7 +289,6 @@ void WIDGETGROUP_armature_facemaps_create(const bContext *C, wmWidgetGroup *wgro
ThemeWireColor *bcol = ED_pchan_get_colorset(arm, ob->pose, pchan);
Object *fmap_ob = pchan->fmap_object;
bFaceMap *fmap = pchan->fmap;
- PointerRNA *opptr;
float col[4] = {0.8f, 0.8f, 0.45f, 0.2f};
float col_hi[4] = {0.8f, 0.8f, 0.45f, 0.4f};
@@ -307,17 +298,14 @@ void WIDGETGROUP_armature_facemaps_create(const bContext *C, wmWidgetGroup *wgro
rgb_uchar_to_float(col_hi, (unsigned char *)bcol->active);
}
- widget = WIDGET_facemap_new(wgroup, fmap->name, 0, fmap_ob, BLI_findindex(&fmap_ob->fmaps, fmap));
+ wmWidget *widget = WIDGET_facemap_new(wgroup, fmap->name, 0, fmap_ob, BLI_findindex(&fmap_ob->fmaps, fmap));
- RNA_pointer_create(&fmap_ob->id, &RNA_FaceMap, fmap, &famapptr);
WM_widget_set_operator(widget, "TRANSFORM_OT_translate");
WM_widget_set_colors(widget, col, col_hi);
WM_widget_set_flag(widget, WM_WIDGET_DRAW_HOVER, true);
WM_widget_set_func_select(widget, WIDGET_armature_facemaps_select);
- opptr = WM_widget_set_operator(widget, "TRANSFORM_OT_translate");
- if ((prop = RNA_struct_find_property(opptr, "release_confirm"))) {
- RNA_property_boolean_set(opptr, prop, true);
- }
+ PointerRNA *opptr = WM_widget_set_operator(widget, "TRANSFORM_OT_translate");
+ RNA_boolean_set(opptr, "release_confirm", true);
}
}
#else
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index e0874d7..4fcff75 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -388,7 +388,6 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
float offset[4];
float m_diff[2];
float dir_2d[2], dir2d_final[2];
- float fac, zfac;
float facdir = 1.0f;
bool use_vertical = false;
@@ -407,8 +406,6 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
}
normalize_v3(viewvec);
- zfac = ED_view3d_calc_zfac(rv3d, orig_origin, NULL);
-
/* first determine if view vector is really close to the direction. If it is, we use
* vertical movement to determine offset, just like transform system does */
if (RAD2DEG(acos(dot_v3v3(viewvec, arrow->direction))) > 5.0f) {
@@ -436,6 +433,7 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
/* project the displacement on the screen space arrow direction */
project_v2_v2v2(dir2d_final, m_diff, dir_2d);
+ float zfac = ED_view3d_calc_zfac(rv3d, orig_origin, NULL);
ED_view3d_win_to_delta(ar, dir2d_final, offset, zfac);
add_v3_v3v3(orig_origin, offset, data->orig_origin);
@@ -450,6 +448,7 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
normalize_v3(viewvec);
if (!use_vertical) {
+ int fac;
/* now find a plane parallel to the view vector so we can intersect with the arrow direction */
cross_v3_v3v3(tangent, viewvec, offset);
cross_v3_v3v3(plane, tangent, viewvec);
@@ -464,8 +463,6 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
/* set the property for the operator and call its modal function */
if (widget->props[ARROW_SLOT_OFFSET_WORLD_SPACE]) {
- PointerRNA ptr = widget->ptr[ARROW_SLOT_OFFSET_WORLD_SPACE];
- PropertyRNA *prop = widget->props[ARROW_SLOT_OFFSET_WORLD_SPACE];
float max = arrow->min + arrow->range;
float value;
@@ -486,6 +483,9 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
CLAMP(value, arrow->min, max);
}
+ PointerRNA ptr = widget->ptr[ARROW_SLOT_OFFSET_WORLD_SPACE];
+ PropertyRNA *prop = widget->props[ARROW_SLOT_OFFSET_WORLD_SPACE];
+
RNA_property_float_set(&ptr, prop, value);
RNA_property_update(C, &ptr, prop);
/* get clamped value */
@@ -518,7 +518,7 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
static int widget_arrow_invoke(bContext *UNUSED(C), const wmEvent *event, wmWidget *widget)
{
- ArrowWidget *arrow = (ArrowWidget *) widget;
+ ArrowWidget *arrow = (ArrowWidget *)widget;
ArrowInteraction *data = MEM_callocN(sizeof(ArrowInteraction), "arrow_interaction");
PointerRNA ptr = widget->ptr[ARROW_SLOT_OFFSET_WORLD_SPACE];
PropertyRNA *prop = widget->props[ARROW_SLOT_OFFSET_WORLD_SPACE];
@@ -551,12 +551,13 @@ static void widget_arrow_bind_to_prop(wmWidget *widget, const int UNUSED(slot))
float float_prop = RNA_property_float_get(&ptr, prop);
if (arrow->style & WIDGET_ARROW_STYLE_CONSTRAINED) {
- float min, max, step, precision;
+ float min, max;
if (arrow->flag & ARROW_CUSTOM_RANGE_SET) {
max = arrow->min + arrow->range;
}
else {
+ float step, precision;
RNA_property_float_ui_range(&ptr, prop, &min, &max, &step, &precision);
arrow->range = max - min;
arrow->min = min;
@@ -599,8 +600,6 @@ static void widget_arrow_cancel(bContext *C, wmWidget *widget)
wmWidget *WIDGET_arrow_new(wmWidgetGroup *wgroup, const char *name, const int style)
{
- ArrowWidget *arrow = MEM_callocN(sizeof(ArrowWidge
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list