[Bf-blender-cvs] [93e82c7] wiggly-widgets: Some tweaks to new low-level widget utility API

Julian Eisel noreply at git.blender.org
Tue Feb 23 21:41:24 CET 2016


Commit: 93e82c7967c1f436aa06e25464e163bdac1f0397
Author: Julian Eisel
Date:   Tue Feb 23 21:39:14 2016 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB93e82c7967c1f436aa06e25464e163bdac1f0397

Some tweaks to new low-level widget utility API

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

M	source/blender/windowmanager/widgets/intern/widget_library/arrow_widget.c
M	source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h
M	source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c

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

diff --git a/source/blender/windowmanager/widgets/intern/widget_library/arrow_widget.c b/source/blender/windowmanager/widgets/intern/widget_library/arrow_widget.c
index 7d57cbd..b3750f0 100644
--- a/source/blender/windowmanager/widgets/intern/widget_library/arrow_widget.c
+++ b/source/blender/windowmanager/widgets/intern/widget_library/arrow_widget.c
@@ -271,7 +271,6 @@ static void widget_arrow_draw(const bContext *UNUSED(C), wmWidget *widget)
 static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *widget, const int flag)
 {
 	ArrowWidget *arrow = (ArrowWidget *)widget;
-	WidgetCommonData *wdata = &arrow->data;
 	WidgetInteraction *inter = widget->interaction_data;
 	ARegion *ar = CTX_wm_region(C);
 	RegionView3D *rv3d = ar->regiondata;
@@ -355,6 +354,7 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
 	}
 
 
+	WidgetCommonData *data = &arrow->data;
 	const float ofs_new = facdir * len_v3(offset);
 	const int slot = ARROW_SLOT_OFFSET_WORLD_SPACE;
 
@@ -363,22 +363,16 @@ static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget *wid
 		const bool constrained = arrow->style & WIDGET_ARROW_STYLE_CONSTRAINED;
 		const bool inverted = arrow->style & WIDGET_ARROW_STYLE_INVERTED;
 		const bool use_precision = flag & WM_WIDGET_TWEAK_PRECISE;
-		float value = widget_value_from_offset_float(wdata, inter, ofs_new, constrained, inverted, use_precision);
+		float value = widget_value_from_offset(data, inter, ofs_new, constrained, inverted, use_precision);
 
-		widget_property_set_float(C, widget, slot, value);
+		widget_property_value_set(C, widget, slot, value);
 		/* get clamped value */
-		value = widget_property_get_float(widget, slot);
+		value = widget_property_value_get(widget, slot);
 
-		if (constrained) {
-			wdata->offset = widget_offset_from_value_constrained_float(
-			                    wdata->range_fac, wdata->min, wdata->range,
-			                    value, inverted);
-		}
-		else
-			wdata->offset = value;
+		data->offset = widget_offset_from_value(data, value, constrained, inverted);
 	}
 	else {
-		wdata->offset = ofs_new;
+		data->offset = ofs_new;
 	}
 
 	/* tag the region for redraw */
@@ -417,7 +411,7 @@ static int widget_arrow_invoke(bContext *UNUSED(C), const wmEvent *event, wmWidg
 static void widget_arrow_bind_to_prop(wmWidget *widget, const int slot)
 {
 	ArrowWidget *arrow = (ArrowWidget *)widget;
-	widget_bind_to_prop_float(
+	widget_property_bind(
 	            widget, &arrow->data, slot,
 	            arrow->style & WIDGET_ARROW_STYLE_CONSTRAINED,
 	            arrow->style & WIDGET_ARROW_STYLE_INVERTED);
@@ -428,7 +422,7 @@ static void widget_arrow_exit(bContext *C, wmWidget *widget, const bool cancel)
 	if (!cancel)
 		return;
 
-	widget_reset_float(C, widget, (WidgetInteraction *)widget->interaction_data, ARROW_SLOT_OFFSET_WORLD_SPACE);
+	widget_property_value_reset(C, widget, (WidgetInteraction *)widget->interaction_data, ARROW_SLOT_OFFSET_WORLD_SPACE);
 }
 
 
diff --git a/source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h b/source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h
index b18d7d4..3a3d9ff 100644
--- a/source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h
+++ b/source/blender/windowmanager/widgets/intern/widget_library/widget_library_intern.h
@@ -66,24 +66,20 @@ enum {
 };
 
 
-float widget_offset_from_value_constrained_float(
-        const float range_fac, const float min, const float range, const float value,
-        const bool inverted);
-float widget_value_from_offset_constrained_float(
-        const float range_fac, const float min, const float range, const float value,
-        const bool inverted);
-float widget_value_from_offset_float(
+float widget_offset_from_value(
+        WidgetCommonData *data, const float value,
+        const bool constrained, const bool inverted);
+float widget_value_from_offset(
         WidgetCommonData *data, WidgetInteraction *inter, const float offset,
         const bool constrained, const bool inverted, const bool use_precision);
 
-void widget_bind_to_prop_float(
+void widget_property_bind(
         wmWidget *widget, WidgetCommonData *data, const int slot,
         const bool constrained, const bool inverted);
 
-void  widget_property_set_float(bContext *C, const wmWidget *widget, const int slot, const float value);
-float widget_property_get_float(const wmWidget *widget, const int slot);
-
-void widget_reset_float(bContext *C, const wmWidget *widget, WidgetInteraction *inter, const int slot);
+void  widget_property_value_set(bContext *C, const wmWidget *widget, const int slot, const float value);
+float widget_property_value_get(const wmWidget *widget, const int slot);
+void  widget_property_value_reset(bContext *C, const wmWidget *widget, WidgetInteraction *inter, const int slot);
 
 #endif  /* __WIDGET_LIBRARY_INTERN_H__ */
 
diff --git a/source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c b/source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c
index 7341915..19ddfc5 100644
--- a/source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c
+++ b/source/blender/windowmanager/widgets/intern/widget_library/widget_library_utils.c
@@ -45,21 +45,29 @@
 #define WIDGET_PRECISION_FAC 0.05f
 
 
-float widget_offset_from_value_constrained_float(
+BLI_INLINE float widget_offset_from_value_constr(
         const float range_fac, const float min, const float range, const float value,
         const bool inverted)
 {
 	return inverted ? (range_fac * (min + range - value) / range) : (range_fac * (value / range));
 }
 
-float widget_value_from_offset_constrained_float(
+BLI_INLINE float widget_value_from_offset_constr(
         const float range_fac, const float min, const float range, const float value,
         const bool inverted)
 {
 	return inverted ? (min + range - (value * range / range_fac)) : (value * range / range_fac);
 }
 
-float widget_value_from_offset_float(
+float widget_offset_from_value(WidgetCommonData *data, const float value, const bool constrained, const bool inverted)
+{
+	if (constrained)
+		return widget_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted);
+
+	return value;
+}
+
+float widget_value_from_offset(
         WidgetCommonData *data, WidgetInteraction *inter, const float offset,
         const bool constrained, const bool inverted, const bool use_precision)
 {
@@ -75,8 +83,10 @@ float widget_value_from_offset_float(
 	float value;
 
 	if (constrained) {
-		value = widget_value_from_offset_constrained_float(data->range_fac, data->min, data->range,
-		                                                   ofs_new, inverted);
+		value = widget_value_from_offset_constr(data->range_fac, data->min, data->range, ofs_new, inverted);
+	}
+	else {
+		value = ofs_new;
 	}
 
 	/* clamp to custom range */
@@ -87,7 +97,7 @@ float widget_value_from_offset_float(
 	return value;
 }
 
-void widget_bind_to_prop_float(
+void widget_property_bind(
         wmWidget *widget, WidgetCommonData *data, const int slot,
         const bool constrained, const bool inverted)
 {
@@ -98,7 +108,7 @@ void widget_bind_to_prop_float(
 
 	PointerRNA ptr = widget->ptr[slot];
 	PropertyRNA *prop = widget->props[slot];
-	float value = RNA_property_float_get(&ptr, prop);
+	float value = widget_property_value_get(widget, slot);
 
 	if (constrained) {
 		if ((data->flag & WIDGET_CUSTOM_RANGE_SET) == 0) {
@@ -108,15 +118,14 @@ void widget_bind_to_prop_float(
 			data->range = max - min;
 			data->min = min;
 		}
-		data->offset = widget_offset_from_value_constrained_float(data->range_fac, data->min, data->range,
-		                                                          value, inverted);
+		data->offset = widget_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted);
 	}
 	else {
 		data->offset = value;
 	}
 }
 
-void widget_property_set_float(bContext *C, const wmWidget *widget, const int slot, const float value)
+void widget_property_value_set(bContext *C, const wmWidget *widget, const int slot, const float value)
 {
 	PointerRNA ptr = widget->ptr[slot];
 	PropertyRNA *prop = widget->props[slot];
@@ -126,12 +135,13 @@ void widget_property_set_float(bContext *C, const wmWidget *widget, const int sl
 	RNA_property_update(C, &ptr, prop);
 }
 
-float widget_property_get_float(const wmWidget *widget, const int slot)
+float widget_property_value_get(const wmWidget *widget, const int slot)
 {
+	BLI_assert(RNA_property_type(widget->props[slot]) == PROP_FLOAT);
 	return RNA_property_float_get(&widget->ptr[slot], widget->props[slot]);
 }
 
-void widget_reset_float(bContext *C, const wmWidget *widget, WidgetInteraction *inter, const int slot)
+void widget_property_value_reset(bContext *C, const wmWidget *widget, WidgetInteraction *inter, const int slot)
 {
-	widget_property_set_float(C, widget, slot, inter->init_value);
+	widget_property_value_set(C, widget, slot, inter->init_value);
 }




More information about the Bf-blender-cvs mailing list