diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_manipulators.c | 131 |
3 files changed, 126 insertions, 11 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 8bb3806a070..30cdafe9369 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -735,7 +735,8 @@ static void view3d_widgets(void) &(const struct wmManipulatorMapType_Params){SPACE_VIEW3D, RGN_TYPE_WINDOW}); WM_manipulatorgrouptype_append_and_link(mmap_type, TRANSFORM_WGT_manipulator); - WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp); + WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp_spot); + WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp_area); WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_force_field); WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_camera); } diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index c5dae4a46c9..f3bae2370b0 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -319,7 +319,8 @@ ARegion *view3d_has_tools_region(ScrArea *sa); extern const char *view3d_context_dir[]; /* doc access */ /* view3d_widgets.c */ -void VIEW3D_WGT_lamp (struct wmManipulatorGroupType *wgt); +void VIEW3D_WGT_lamp_spot (struct wmManipulatorGroupType *wgt); +void VIEW3D_WGT_lamp_area (struct wmManipulatorGroupType *wgt); void VIEW3D_WGT_camera (struct wmManipulatorGroupType *wgt); void VIEW3D_WGT_force_field (struct wmManipulatorGroupType *wgt); void VIEW3D_WGT_armature_facemaps(struct wmManipulatorGroupType *wgt); diff --git a/source/blender/editors/space_view3d/view3d_manipulators.c b/source/blender/editors/space_view3d/view3d_manipulators.c index 68d1fa8a51b..6cbdb7c691c 100644 --- a/source/blender/editors/space_view3d/view3d_manipulators.c +++ b/source/blender/editors/space_view3d/view3d_manipulators.c @@ -58,7 +58,9 @@ /** \name Lamp Manipulators * \{ */ -static bool WIDGETGROUP_lamp_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) +/* Spot Lamp */ + +static bool WIDGETGROUP_lamp_spot_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) { Object *ob = CTX_data_active_object(C); @@ -69,7 +71,7 @@ static bool WIDGETGROUP_lamp_poll(const bContext *C, wmManipulatorGroupType *UNU return false; } -static void WIDGETGROUP_lamp_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup) +static void WIDGETGROUP_lamp_spot_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup) { const float color[4] = {0.5f, 0.5f, 1.0f, 1.0f}; const float color_hi[4] = {0.8f, 0.8f, 0.45f, 1.0f}; @@ -86,7 +88,7 @@ static void WIDGETGROUP_lamp_setup(const bContext *UNUSED(C), wmManipulatorGroup WM_manipulator_set_color_highlight(wwrapper->manipulator, color_hi); } -static void WIDGETGROUP_lamp_refresh(const bContext *C, wmManipulatorGroup *mgroup) +static void WIDGETGROUP_lamp_spot_refresh(const bContext *C, wmManipulatorGroup *mgroup) { wmManipulatorWrapper *wwrapper = mgroup->customdata; Object *ob = CTX_data_active_object(C); @@ -105,18 +107,129 @@ static void WIDGETGROUP_lamp_refresh(const bContext *C, wmManipulatorGroup *mgro WM_manipulator_target_property_def_rna(wwrapper->manipulator, "offset", &lamp_ptr, propname, -1); } -void VIEW3D_WGT_lamp(wmManipulatorGroupType *wgt) +void VIEW3D_WGT_lamp_spot(wmManipulatorGroupType *wgt) +{ + wgt->name = "Spot Lamp Widgets"; + wgt->idname = "VIEW3D_WGT_lamp_spot"; + + wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT | + WM_MANIPULATORGROUPTYPE_3D | + WM_MANIPULATORGROUPTYPE_DEPTH_3D); + + wgt->poll = WIDGETGROUP_lamp_spot_poll; + wgt->setup = WIDGETGROUP_lamp_spot_setup; + wgt->refresh = WIDGETGROUP_lamp_spot_refresh; +} + +/* Area Lamp */ + +/* translate callbacks */ +static void manipulator_area_lamp_prop_size_get( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, + void *value_p) +{ + float *value = value_p; + BLI_assert(mpr_prop->type->array_length == 2); + UNUSED_VARS_NDEBUG(mpr_prop); + Lamp *la = mpr_prop->custom_func.user_data; + + value[0] = la->area_size; + value[1] = (la->area_shape == LA_AREA_RECT) ? la->area_sizey : la->area_size; +} + +static void manipulator_area_lamp_prop_size_set( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, + const void *value_p) +{ + const float *value = value_p; + + BLI_assert(mpr_prop->type->array_length == 2); + UNUSED_VARS_NDEBUG(mpr_prop); + Lamp *la = mpr_prop->custom_func.user_data; + if (la->area_shape == LA_AREA_RECT) { + la->area_size = value[0]; + la->area_sizey = value[1]; + } + else { + la->area_size = value[0]; + } +} + +static void manipulator_area_lamp_prop_size_range( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *UNUSED(mpr_prop), + void *value_p) +{ + float *value = value_p; + value[0] = 0.0f; + value[1] = FLT_MAX; +} + +static bool WIDGETGROUP_lamp_area_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) +{ + Object *ob = CTX_data_active_object(C); + + if (ob && ob->type == OB_LAMP) { + Lamp *la = ob->data; + return (la->type == LA_AREA); + } + return false; +} + +static void WIDGETGROUP_lamp_area_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup) +{ + const float color[4] = {1.0f, 1.0f, 0.5f, 1.0f}; + const float color_hi[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + + wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__); + wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL); + + RNA_enum_set(wwrapper->manipulator->ptr, "transform", + ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE); + + const float dims[4] = {1.0f, 1.0f}; + RNA_float_set_array(wwrapper->manipulator->ptr, "dimensions", dims); + + mgroup->customdata = wwrapper; + + WM_manipulator_set_color(wwrapper->manipulator, color); + WM_manipulator_set_color_highlight(wwrapper->manipulator, color_hi); +} + +static void WIDGETGROUP_lamp_area_refresh(const bContext *C, wmManipulatorGroup *mgroup) +{ + wmManipulatorWrapper *wwrapper = mgroup->customdata; + Object *ob = CTX_data_active_object(C); + Lamp *la = ob->data; + + copy_m4_m4(wwrapper->manipulator->matrix_basis, ob->obmat); + + RNA_enum_set(wwrapper->manipulator->ptr, "transform", + ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE | + ((la->area_shape == LA_AREA_SQUARE) ? ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE_UNIFORM : 0)); + + /* need to set property here for undo. TODO would prefer to do this in _init */ + WM_manipulator_target_property_def_func( + wwrapper->manipulator, "scale", + &(const struct wmManipulatorPropertyFnParams) { + .value_get_fn = manipulator_area_lamp_prop_size_get, + .value_set_fn = manipulator_area_lamp_prop_size_set, + .range_get_fn = manipulator_area_lamp_prop_size_range, + .user_data = la, + }); +} + +void VIEW3D_WGT_lamp_area(wmManipulatorGroupType *wgt) { - wgt->name = "Lamp Widgets"; - wgt->idname = "VIEW3D_WGT_lamp"; + wgt->name = "Area Lamp Widgets"; + wgt->idname = "VIEW3D_WGT_lamp_area"; wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT | WM_MANIPULATORGROUPTYPE_3D | WM_MANIPULATORGROUPTYPE_DEPTH_3D); - wgt->poll = WIDGETGROUP_lamp_poll; - wgt->setup = WIDGETGROUP_lamp_setup; - wgt->refresh = WIDGETGROUP_lamp_refresh; + wgt->poll = WIDGETGROUP_lamp_area_poll; + wgt->setup = WIDGETGROUP_lamp_area_setup; + wgt->refresh = WIDGETGROUP_lamp_area_refresh; } /** \} */ |