Commit: c3bfe6d786601fc3e6b1b567b309e72827cb2eb5
Author: Julian Eisel
Date:   Tue Sep 8 01:25:00 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBc3bfe6d786601fc3e6b1b567b309e72827cb2eb5

Allow custom arrow range per widget

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

M       source/blender/editors/object/object_lamp.c
M       source/blender/editors/space_view3d/space_view3d.c
M       source/blender/windowmanager/WM_api.h
M       source/blender/windowmanager/intern/wm_generic_widgets.c

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

diff --git a/source/blender/editors/object/object_lamp.c 
b/source/blender/editors/object/object_lamp.c
index 92276269..2dd97c1 100644
--- a/source/blender/editors/object/object_lamp.c
+++ b/source/blender/editors/object/object_lamp.c
@@ -231,6 +231,7 @@ void WIDGETGROUP_lamp_create(const struct bContext *C, 
struct wmWidgetGroup *wgr
        
        RNA_pointer_create(&la->id, &RNA_Lamp, la, &ptr);
        WM_widget_set_origin(widget, ob->obmat[3]);
+       WIDGET_arrow_set_range_fac(widget, 4.0f);
        WM_widget_property(widget, ARROW_SLOT_OFFSET_WORLD_SPACE, &ptr, 
propname);
        negate_v3_v3(dir, ob->obmat[2]);
        WIDGET_arrow_set_direction(widget, dir);
diff --git a/source/blender/editors/space_view3d/space_view3d.c 
b/source/blender/editors/space_view3d/space_view3d.c
index 2da168e..5c91d08 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -791,6 +791,7 @@ static void WIDGETGROUP_forcefield_create(const struct 
bContext *C, struct wmWid
                RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &ptr);
                WIDGET_arrow_set_direction(widget, ob->obmat[2]);
                WIDGET_arrow_set_ui_range(widget, -200.0f, 200.0f);
+               WIDGET_arrow_set_range_fac(widget, 6.0f);
                WM_widget_set_colors(widget, col, col_hi);
                WM_widget_set_origin(widget, ob->obmat[3]);
                WM_widget_set_offset(widget, ofs);
diff --git a/source/blender/windowmanager/WM_api.h 
b/source/blender/windowmanager/WM_api.h
index 7448d0d..cafc9ec 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -580,6 +580,7 @@ void WIDGET_arrow_set_direction(struct wmWidget *widget, 
const float direction[3
 void WIDGET_arrow_set_up_vector(struct wmWidget *widget, const float 
direction[3]);
 void WIDGET_arrow_set_line_vec(struct wmWidget *widget, const float (*vec)[3], 
const int tot_points);
 void WIDGET_arrow_set_ui_range(struct wmWidget *widget, const float min, const 
float max);
+void WIDGET_arrow_set_range_fac(struct wmWidget *widget, const float 
range_fac);
 
 struct wmWidget *WIDGET_dial_new(struct wmWidgetGroup *wgroup, const char 
*name, const int style);
 void WIDGET_dial_set_direction(struct wmWidget *widget, const float 
direction[3]);
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c 
b/source/blender/windowmanager/intern/wm_generic_widgets.c
index c57ef0f..16021ef 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -166,8 +166,11 @@ typedef struct ArrowWidget {
        int flag;
        float direction[3];
        float up[3];
+
        float (*line)[3];    /* custom coords for arrow line drawing */
        int tot_line_points; /* amount of points for arrow line drawing */
+
+       float range_fac;      /* factor for arrow min/max distance */
        float offset;
        /* property range and minimum for constrained arrows */
        float range, min;
@@ -360,8 +363,6 @@ static void widget_arrow_draw(const bContext *UNUSED(C), 
wmWidget *widget)
        arrow_draw_intern((ArrowWidget *)widget, false, (widget->flag & 
WM_WIDGET_HIGHLIGHT) != 0);
 }
 
-#define ARROW_RANGE 6.0f
-
 static int widget_arrow_handler(bContext *C, const wmEvent *event, wmWidget 
*widget)
 {
        ArrowWidget *arrow = (ArrowWidget *)widget;
@@ -457,9 +458,9 @@ static int widget_arrow_handler(bContext *C, const wmEvent 
*event, wmWidget *wid
                value = data->orig_offset + facdir * len_v3(offset);
                if (arrow->style & WIDGET_ARROW_STYLE_CONSTRAINED) {
                        if (arrow->style & WIDGET_ARROW_STYLE_INVERTED)
-                               value = max - (value * arrow->range / 
ARROW_RANGE);
+                               value = max - (value * arrow->range / 
arrow->range_fac);
                        else
-                               value = arrow->min + (value * arrow->range / 
ARROW_RANGE);
+                               value = arrow->min + (value * arrow->range / 
arrow->range_fac);
                }
 
                /* clamp to custom range */
@@ -475,9 +476,9 @@ static int widget_arrow_handler(bContext *C, const wmEvent 
*event, wmWidget *wid
                /* accounts for clamping properly */
                if (arrow->style & WIDGET_ARROW_STYLE_CONSTRAINED) {
                        if (arrow->style & WIDGET_ARROW_STYLE_INVERTED)
-                               arrow->offset = ARROW_RANGE * (max - value) / 
arrow->range;
+                               arrow->offset = arrow->range_fac * (max - 
value) / arrow->range;
                        else
-                               arrow->offset = ARROW_RANGE * ((value - 
arrow->min) / arrow->range);
+                               arrow->offset = arrow->range_fac * ((value - 
arrow->min) / arrow->range);
                }
                else
                        arrow->offset = value;
@@ -540,10 +541,10 @@ static void widget_arrow_bind_to_prop(wmWidget *widget, 
const int UNUSED(slot))
                        }
 
                        if (arrow->style & WIDGET_ARROW_STYLE_INVERTED) {
-                               arrow->offset = ARROW_RANGE * (max - 
float_prop) / arrow->range;
+                               arrow->offset = arrow->range_fac * (max - 
float_prop) / arrow->range;
                        }
                        else {
-                               arrow->offset = ARROW_RANGE * ((float_prop - 
arrow->min) / arrow->range);
+                               arrow->offset = arrow->range_fac * ((float_prop 
- arrow->min) / arrow->range);
                        }
                }
                else {
@@ -612,6 +613,7 @@ wmWidget *WIDGET_arrow_new(wmWidgetGroup *wgroup, const 
char *name, const int st
        arrow->widget.flag |= WM_WIDGET_SCALE_3D;
 
        arrow->style = real_style;
+       arrow->range_fac = 1.0f;
 
        /* defaults */
        copy_v3_v3(arrow->direction, dir_default);
@@ -679,6 +681,18 @@ void WIDGET_arrow_set_ui_range(wmWidget *widget, const 
float min, const float ma
        arrow->flag |= ARROW_CUSTOM_RANGE_SET;
 }
 
+/**
+ * Define a custom factor for arrow min/max distance
+ *
+ * \note Needs to be called before WM_widget_property!
+ */
+void WIDGET_arrow_set_range_fac(wmWidget *widget, const float range_fac)
+{
+       ArrowWidget *arrow = (ArrowWidget *)widget;
+
+       arrow->range_fac = range_fac;
+}
+
 
 /********* Dial widget ************/

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to