diff options
Diffstat (limited to 'source/blender/windowmanager/gizmo')
-rw-r--r-- | source/blender/windowmanager/gizmo/WM_gizmo_api.h | 354 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/WM_gizmo_types.h | 530 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo.c | 903 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c | 1320 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c | 156 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h | 116 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c | 1801 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c | 400 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_type.c | 162 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/wm_gizmo_fn.h | 95 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h | 31 |
11 files changed, 2898 insertions, 2970 deletions
diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_api.h b/source/blender/windowmanager/gizmo/WM_gizmo_api.h index b48f58cda7f..9a272b27f87 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_api.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_api.h @@ -26,7 +26,6 @@ * Only included in WM_api.h */ - #ifndef __WM_GIZMO_API_H__ #define __WM_GIZMO_API_H__ @@ -53,49 +52,49 @@ struct wmMsgSubscribeValue; /* -------------------------------------------------------------------- */ /* wmGizmo */ -struct wmGizmo *WM_gizmo_new_ptr( - const struct wmGizmoType *gzt, struct wmGizmoGroup *gzgroup, - struct PointerRNA *properties); -struct wmGizmo *WM_gizmo_new( - const char *idname, struct wmGizmoGroup *gzgroup, - struct PointerRNA *properties); +struct wmGizmo *WM_gizmo_new_ptr(const struct wmGizmoType *gzt, + struct wmGizmoGroup *gzgroup, + struct PointerRNA *properties); +struct wmGizmo *WM_gizmo_new(const char *idname, + struct wmGizmoGroup *gzgroup, + struct PointerRNA *properties); void WM_gizmo_free(struct wmGizmo *gz); -void WM_gizmo_unlink( - ListBase *gizmolist, struct wmGizmoMap *gzmap, struct wmGizmo *gz, - struct bContext *C); +void WM_gizmo_unlink(ListBase *gizmolist, + struct wmGizmoMap *gzmap, + struct wmGizmo *gz, + struct bContext *C); bool WM_gizmo_select_unlink(struct wmGizmoMap *gzmap, struct wmGizmo *gz); bool WM_gizmo_select_set(struct wmGizmoMap *gzmap, struct wmGizmo *gz, bool select); void WM_gizmo_highlight_set(struct wmGizmoMap *gzmap, struct wmGizmo *gz); -void WM_gizmo_modal_set_from_setup( - struct wmGizmoMap *gzmap, struct bContext *C, - struct wmGizmo *gz, int part_index, const struct wmEvent *event); +void WM_gizmo_modal_set_from_setup(struct wmGizmoMap *gzmap, + struct bContext *C, + struct wmGizmo *gz, + int part_index, + const struct wmEvent *event); -struct wmGizmoOpElem *WM_gizmo_operator_get( - struct wmGizmo *gz, int part_index); -struct PointerRNA *WM_gizmo_operator_set( - struct wmGizmo *gz, int part_index, - struct wmOperatorType *ot, struct IDProperty *properties); -int WM_gizmo_operator_invoke( - struct bContext *C, struct wmGizmo *gz, struct wmGizmoOpElem *gzop); +struct wmGizmoOpElem *WM_gizmo_operator_get(struct wmGizmo *gz, int part_index); +struct PointerRNA *WM_gizmo_operator_set(struct wmGizmo *gz, + int part_index, + struct wmOperatorType *ot, + struct IDProperty *properties); +int WM_gizmo_operator_invoke(struct bContext *C, struct wmGizmo *gz, struct wmGizmoOpElem *gzop); /* callbacks */ void WM_gizmo_set_fn_custom_modal(struct wmGizmo *gz, wmGizmoFnModal fn); -void WM_gizmo_set_matrix_location( - struct wmGizmo *gz, const float origin[3]); -void WM_gizmo_set_matrix_rotation_from_z_axis( - struct wmGizmo *gz, const float z_axis[3]); -void WM_gizmo_set_matrix_rotation_from_yz_axis( - struct wmGizmo *gz, const float y_axis[3], const float z_axis[3]); +void WM_gizmo_set_matrix_location(struct wmGizmo *gz, const float origin[3]); +void WM_gizmo_set_matrix_rotation_from_z_axis(struct wmGizmo *gz, const float z_axis[3]); +void WM_gizmo_set_matrix_rotation_from_yz_axis(struct wmGizmo *gz, + const float y_axis[3], + const float z_axis[3]); -void WM_gizmo_set_matrix_offset_location( - struct wmGizmo *gz, const float origin[3]); -void WM_gizmo_set_matrix_offset_rotation_from_z_axis( - struct wmGizmo *gz, const float z_axis[3]); -void WM_gizmo_set_matrix_offset_rotation_from_yz_axis( - struct wmGizmo *gz, const float y_axis[3], const float z_axis[3]); +void WM_gizmo_set_matrix_offset_location(struct wmGizmo *gz, const float origin[3]); +void WM_gizmo_set_matrix_offset_rotation_from_z_axis(struct wmGizmo *gz, const float z_axis[3]); +void WM_gizmo_set_matrix_offset_rotation_from_yz_axis(struct wmGizmo *gz, + const float y_axis[3], + const float z_axis[3]); void WM_gizmo_set_flag(struct wmGizmo *gz, const int flag, const bool enable); void WM_gizmo_set_scale(struct wmGizmo *gz, const float scale); @@ -110,32 +109,31 @@ void WM_gizmo_set_color_highlight(struct wmGizmo *gz, const float color[4]); * Leaving values NULL use values from #wmGizmo. */ struct WM_GizmoMatrixParams { - const float(*matrix_space)[4]; - const float(*matrix_basis)[4]; - const float(*matrix_offset)[4]; - const float *scale_final; + const float (*matrix_space)[4]; + const float (*matrix_basis)[4]; + const float (*matrix_offset)[4]; + const float *scale_final; }; -void WM_gizmo_calc_matrix_final_params( - const struct wmGizmo *gz, const struct WM_GizmoMatrixParams *params, - float r_mat[4][4]); -void WM_gizmo_calc_matrix_final_no_offset( - const struct wmGizmo *gz, float r_mat[4][4]); +void WM_gizmo_calc_matrix_final_params(const struct wmGizmo *gz, + const struct WM_GizmoMatrixParams *params, + float r_mat[4][4]); +void WM_gizmo_calc_matrix_final_no_offset(const struct wmGizmo *gz, float r_mat[4][4]); -void WM_gizmo_calc_matrix_final( - const struct wmGizmo *gz, float r_mat[4][4]); +void WM_gizmo_calc_matrix_final(const struct wmGizmo *gz, float r_mat[4][4]); /* properties */ void WM_gizmo_properties_create_ptr(struct PointerRNA *ptr, struct wmGizmoType *gzt); void WM_gizmo_properties_create(struct PointerRNA *ptr, const char *opstring); -void WM_gizmo_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *wtstring); +void WM_gizmo_properties_alloc(struct PointerRNA **ptr, + struct IDProperty **properties, + const char *wtstring); void WM_gizmo_properties_sanitize(struct PointerRNA *ptr, const bool no_context); bool WM_gizmo_properties_default(struct PointerRNA *ptr, const bool do_update); void WM_gizmo_properties_reset(struct wmGizmo *op); void WM_gizmo_properties_clear(struct PointerRNA *ptr); void WM_gizmo_properties_free(struct PointerRNA *ptr); - /* wm_gizmo_type.c */ const struct wmGizmoType *WM_gizmotype_find(const char *idname, bool quiet); void WM_gizmotype_append(void (*wtfunc)(struct wmGizmoType *)); @@ -147,95 +145,102 @@ void WM_gizmotype_iter(struct GHashIterator *ghi); /* wm_gizmo_group_type.c */ struct wmGizmoGroupType *WM_gizmogrouptype_find(const char *idname, bool quiet); struct wmGizmoGroupType *WM_gizmogrouptype_append(void (*wtfunc)(struct wmGizmoGroupType *)); -struct wmGizmoGroupType *WM_gizmogrouptype_append_ptr(void (*mnpfunc)(struct wmGizmoGroupType *, void *), void *userdata); +struct wmGizmoGroupType *WM_gizmogrouptype_append_ptr(void (*mnpfunc)(struct wmGizmoGroupType *, + void *), + void *userdata); bool WM_gizmogrouptype_free(const char *idname); void WM_gizmogrouptype_free_ptr(struct wmGizmoGroupType *wt); void WM_gizmogrouptype_iter(struct GHashIterator *ghi); struct wmGizmoGroupTypeRef *WM_gizmogrouptype_append_and_link( - struct wmGizmoMapType *gzmap_type, - void (*wtfunc)(struct wmGizmoGroupType *)); + struct wmGizmoMapType *gzmap_type, void (*wtfunc)(struct wmGizmoGroupType *)); /* wm_gizmo_map.c */ /* Dynamic Updates (for RNA runtime registration) */ -void WM_gizmoconfig_update_tag_init(struct wmGizmoMapType *gzmap_type, struct wmGizmoGroupType *gzgt); -void WM_gizmoconfig_update_tag_remove(struct wmGizmoMapType *gzmap_type, struct wmGizmoGroupType *gzgt); +void WM_gizmoconfig_update_tag_init(struct wmGizmoMapType *gzmap_type, + struct wmGizmoGroupType *gzgt); +void WM_gizmoconfig_update_tag_remove(struct wmGizmoMapType *gzmap_type, + struct wmGizmoGroupType *gzgt); void WM_gizmoconfig_update(struct Main *bmain); - /* wm_maniulator_target_props.c */ struct wmGizmoProperty *WM_gizmo_target_property_array(struct wmGizmo *gz); -struct wmGizmoProperty *WM_gizmo_target_property_at_index( - struct wmGizmo *gz, int index); -struct wmGizmoProperty *WM_gizmo_target_property_find( - struct wmGizmo *gz, const char *idname); - -void WM_gizmo_target_property_def_rna_ptr( - struct wmGizmo *gz, const struct wmGizmoPropertyType *gz_prop_type, - struct PointerRNA *ptr, struct PropertyRNA *prop, int index); -void WM_gizmo_target_property_def_rna( - struct wmGizmo *gz, const char *idname, - struct PointerRNA *ptr, const char *propname, int index); - -void WM_gizmo_target_property_def_func_ptr( - struct wmGizmo *gz, const struct wmGizmoPropertyType *gz_prop_type, - const struct wmGizmoPropertyFnParams *params); -void WM_gizmo_target_property_def_func( - struct wmGizmo *gz, const char *idname, - const struct wmGizmoPropertyFnParams *params); - -void WM_gizmo_target_property_clear_rna_ptr( - struct wmGizmo *gz, const struct wmGizmoPropertyType *gz_prop_type); -void WM_gizmo_target_property_clear_rna( - struct wmGizmo *gz, const char *idname); +struct wmGizmoProperty *WM_gizmo_target_property_at_index(struct wmGizmo *gz, int index); +struct wmGizmoProperty *WM_gizmo_target_property_find(struct wmGizmo *gz, const char *idname); + +void WM_gizmo_target_property_def_rna_ptr(struct wmGizmo *gz, + const struct wmGizmoPropertyType *gz_prop_type, + struct PointerRNA *ptr, + struct PropertyRNA *prop, + int index); +void WM_gizmo_target_property_def_rna(struct wmGizmo *gz, + const char *idname, + struct PointerRNA *ptr, + const char *propname, + int index); + +void WM_gizmo_target_property_def_func_ptr(struct wmGizmo *gz, + const struct wmGizmoPropertyType *gz_prop_type, + const struct wmGizmoPropertyFnParams *params); +void WM_gizmo_target_property_def_func(struct wmGizmo *gz, + const char *idname, + const struct wmGizmoPropertyFnParams *params); + +void WM_gizmo_target_property_clear_rna_ptr(struct wmGizmo *gz, + const struct wmGizmoPropertyType *gz_prop_type); +void WM_gizmo_target_property_clear_rna(struct wmGizmo *gz, const char *idname); bool WM_gizmo_target_property_is_valid_any(struct wmGizmo *gz); -bool WM_gizmo_target_property_is_valid( - const struct wmGizmoProperty *gz_prop); -float WM_gizmo_target_property_float_get( - const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop); -void WM_gizmo_target_property_float_set( - struct bContext *C, const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop, - const float value); - -void WM_gizmo_target_property_float_get_array( - const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop, - float *value); -void WM_gizmo_target_property_float_set_array( - struct bContext *C, const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop, - const float *value); - -bool WM_gizmo_target_property_float_range_get( - const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop, - float range[2]); - -int WM_gizmo_target_property_array_length( - const struct wmGizmo *gz, struct wmGizmoProperty *gz_prop); +bool WM_gizmo_target_property_is_valid(const struct wmGizmoProperty *gz_prop); +float WM_gizmo_target_property_float_get(const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop); +void WM_gizmo_target_property_float_set(struct bContext *C, + const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop, + const float value); + +void WM_gizmo_target_property_float_get_array(const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop, + float *value); +void WM_gizmo_target_property_float_set_array(struct bContext *C, + const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop, + const float *value); + +bool WM_gizmo_target_property_float_range_get(const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop, + float range[2]); + +int WM_gizmo_target_property_array_length(const struct wmGizmo *gz, + struct wmGizmoProperty *gz_prop); /* definitions */ -const struct wmGizmoPropertyType *WM_gizmotype_target_property_find( - const struct wmGizmoType *gzt, const char *idname); -void WM_gizmotype_target_property_def( - struct wmGizmoType *gzt, const char *idname, int data_type, int array_length); +const struct wmGizmoPropertyType *WM_gizmotype_target_property_find(const struct wmGizmoType *gzt, + const char *idname); +void WM_gizmotype_target_property_def(struct wmGizmoType *gzt, + const char *idname, + int data_type, + int array_length); /* utilities */ -void WM_gizmo_do_msg_notify_tag_refresh( - struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val); -void WM_gizmo_target_property_subscribe_all( - struct wmGizmo *gz, struct wmMsgBus *mbus, struct ARegion *ar); +void WM_gizmo_do_msg_notify_tag_refresh(struct bContext *C, + struct wmMsgSubscribeKey *msg_key, + struct wmMsgSubscribeValue *msg_val); +void WM_gizmo_target_property_subscribe_all(struct wmGizmo *gz, + struct wmMsgBus *mbus, + struct ARegion *ar); /* -------------------------------------------------------------------- */ /* wmGizmoGroup */ /* Callbacks for 'wmGizmoGroupType.setup_keymap' */ -struct wmKeyMap *WM_gizmogroup_keymap_common( - const struct wmGizmoGroupType *gzgt, struct wmKeyConfig *config); -struct wmKeyMap *WM_gizmogroup_keymap_common_select( - const struct wmGizmoGroupType *gzgt, struct wmKeyConfig *config); +struct wmKeyMap *WM_gizmogroup_keymap_common(const struct wmGizmoGroupType *gzgt, + struct wmKeyConfig *config); +struct wmKeyMap *WM_gizmogroup_keymap_common_select(const struct wmGizmoGroupType *gzgt, + struct wmKeyConfig *config); -void WM_gizmogroup_ensure_init( - const struct bContext *C, struct wmGizmoGroup *gzgroup); +void WM_gizmogroup_ensure_init(const struct bContext *C, struct wmGizmoGroup *gzgroup); /* Sort utilities for use with 'BLI_listbase_sort'. */ int WM_gizmo_cmp_temp_fl(const void *gz_a_ptr, const void *gz_b_ptr); @@ -244,65 +249,60 @@ int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr); /* -------------------------------------------------------------------- */ /* wmGizmoMap */ -struct wmGizmoMap *WM_gizmomap_new_from_type( - const struct wmGizmoMapType_Params *gzmap_params); +struct wmGizmoMap *WM_gizmomap_new_from_type(const struct wmGizmoMapType_Params *gzmap_params); void WM_gizmomap_reinit(struct wmGizmoMap *gzmap); const struct ListBase *WM_gizmomap_group_list(struct wmGizmoMap *gzmap); -struct wmGizmoGroup *WM_gizmomap_group_find( - struct wmGizmoMap *gzmap, - const char *idname); -struct wmGizmoGroup *WM_gizmomap_group_find_ptr( - struct wmGizmoMap *gzmap, - const struct wmGizmoGroupType *gzgt); +struct wmGizmoGroup *WM_gizmomap_group_find(struct wmGizmoMap *gzmap, const char *idname); +struct wmGizmoGroup *WM_gizmomap_group_find_ptr(struct wmGizmoMap *gzmap, + const struct wmGizmoGroupType *gzgt); void WM_gizmomap_tag_refresh(struct wmGizmoMap *gzmap); -void WM_gizmomap_draw( - struct wmGizmoMap *gzmap, const struct bContext *C, const eWM_GizmoFlagMapDrawStep drawstep); +void WM_gizmomap_draw(struct wmGizmoMap *gzmap, + const struct bContext *C, + const eWM_GizmoFlagMapDrawStep drawstep); void WM_gizmomap_add_handlers(struct ARegion *ar, struct wmGizmoMap *gzmap); bool WM_gizmomap_select_all(struct bContext *C, struct wmGizmoMap *gzmap, const int action); bool WM_gizmomap_cursor_set(const struct wmGizmoMap *gzmap, struct wmWindow *win); -void WM_gizmomap_message_subscribe( - struct bContext *C, struct wmGizmoMap *gzmap, struct ARegion *ar, struct wmMsgBus *mbus); +void WM_gizmomap_message_subscribe(struct bContext *C, + struct wmGizmoMap *gzmap, + struct ARegion *ar, + struct wmMsgBus *mbus); bool WM_gizmomap_is_any_selected(const struct wmGizmoMap *gzmap); -bool WM_gizmomap_minmax( - const struct wmGizmoMap *gzmap, bool use_hidden, bool use_select, - float r_min[3], float r_max[3]); +bool WM_gizmomap_minmax(const struct wmGizmoMap *gzmap, + bool use_hidden, + bool use_select, + float r_min[3], + float r_max[3]); struct ARegion *WM_gizmomap_tooltip_init( - struct bContext *C, struct ARegion *ar, int *pass, double *pass_delay, bool *r_exit_on_event); + struct bContext *C, struct ARegion *ar, int *pass, double *pass_delay, bool *r_exit_on_event); /* -------------------------------------------------------------------- */ /* wmGizmoMapType */ -struct wmGizmoMapType *WM_gizmomaptype_find( - const struct wmGizmoMapType_Params *gzmap_params); -struct wmGizmoMapType *WM_gizmomaptype_ensure( - const struct wmGizmoMapType_Params *gzmap_params); - -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find( - struct wmGizmoMapType *gzmap_type, - const char *idname); -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find_ptr( - struct wmGizmoMapType *gzmap_type, - const struct wmGizmoGroupType *gzgt); -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_link( - struct wmGizmoMapType *gzmap_type, - const char *idname); -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_link_ptr( - struct wmGizmoMapType *gzmap_type, - struct wmGizmoGroupType *gzgt); - -void WM_gizmomaptype_group_init_runtime_keymap( - const struct Main *bmain, - struct wmGizmoGroupType *gzgt); -void WM_gizmomaptype_group_init_runtime( - const struct Main *bmain, struct wmGizmoMapType *gzmap_type, - struct wmGizmoGroupType *gzgt); -wmGizmoGroup *WM_gizmomaptype_group_init_runtime_with_region( - struct wmGizmoMapType *gzmap_type, - struct wmGizmoGroupType *gzgt, struct ARegion *ar); -void WM_gizmomaptype_group_unlink( - struct bContext *C, struct Main *bmain, struct wmGizmoMapType *gzmap_type, - const struct wmGizmoGroupType *gzgt); +struct wmGizmoMapType *WM_gizmomaptype_find(const struct wmGizmoMapType_Params *gzmap_params); +struct wmGizmoMapType *WM_gizmomaptype_ensure(const struct wmGizmoMapType_Params *gzmap_params); + +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find(struct wmGizmoMapType *gzmap_type, + const char *idname); +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find_ptr(struct wmGizmoMapType *gzmap_type, + const struct wmGizmoGroupType *gzgt); +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_link(struct wmGizmoMapType *gzmap_type, + const char *idname); +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_link_ptr(struct wmGizmoMapType *gzmap_type, + struct wmGizmoGroupType *gzgt); + +void WM_gizmomaptype_group_init_runtime_keymap(const struct Main *bmain, + struct wmGizmoGroupType *gzgt); +void WM_gizmomaptype_group_init_runtime(const struct Main *bmain, + struct wmGizmoMapType *gzmap_type, + struct wmGizmoGroupType *gzgt); +wmGizmoGroup *WM_gizmomaptype_group_init_runtime_with_region(struct wmGizmoMapType *gzmap_type, + struct wmGizmoGroupType *gzgt, + struct ARegion *ar); +void WM_gizmomaptype_group_unlink(struct bContext *C, + struct Main *bmain, + struct wmGizmoMapType *gzmap_type, + const struct wmGizmoGroupType *gzgt); void WM_gizmomaptype_group_free(struct wmGizmoGroupTypeRef *gzgt); @@ -311,40 +311,32 @@ void WM_gizmomaptype_group_free(struct wmGizmoGroupTypeRef *gzgt); /* Add/Ensure/Remove (High level API) */ -void WM_gizmo_group_type_add_ptr_ex( - struct wmGizmoGroupType *gzgt, - struct wmGizmoMapType *gzmap_type); -void WM_gizmo_group_type_add_ptr( - struct wmGizmoGroupType *gzgt); +void WM_gizmo_group_type_add_ptr_ex(struct wmGizmoGroupType *gzgt, + struct wmGizmoMapType *gzmap_type); +void WM_gizmo_group_type_add_ptr(struct wmGizmoGroupType *gzgt); void WM_gizmo_group_type_add(const char *idname); -bool WM_gizmo_group_type_ensure_ptr_ex( - struct wmGizmoGroupType *gzgt, - struct wmGizmoMapType *gzmap_type); -bool WM_gizmo_group_type_ensure_ptr( - struct wmGizmoGroupType *gzgt); +bool WM_gizmo_group_type_ensure_ptr_ex(struct wmGizmoGroupType *gzgt, + struct wmGizmoMapType *gzmap_type); +bool WM_gizmo_group_type_ensure_ptr(struct wmGizmoGroupType *gzgt); bool WM_gizmo_group_type_ensure(const char *idname); -void WM_gizmo_group_type_remove_ptr_ex( - struct Main *bmain, struct wmGizmoGroupType *gzgt, - struct wmGizmoMapType *gzmap_type); -void WM_gizmo_group_type_remove_ptr( - struct Main *bmain, struct wmGizmoGroupType *gzgt); +void WM_gizmo_group_type_remove_ptr_ex(struct Main *bmain, + struct wmGizmoGroupType *gzgt, + struct wmGizmoMapType *gzmap_type); +void WM_gizmo_group_type_remove_ptr(struct Main *bmain, struct wmGizmoGroupType *gzgt); void WM_gizmo_group_type_remove(struct Main *bmain, const char *idname); -void WM_gizmo_group_type_unlink_delayed_ptr_ex( - struct wmGizmoGroupType *gzgt, - struct wmGizmoMapType *gzmap_type); -void WM_gizmo_group_type_unlink_delayed_ptr( - struct wmGizmoGroupType *gzgt); +void WM_gizmo_group_type_unlink_delayed_ptr_ex(struct wmGizmoGroupType *gzgt, + struct wmGizmoMapType *gzmap_type); +void WM_gizmo_group_type_unlink_delayed_ptr(struct wmGizmoGroupType *gzgt); void WM_gizmo_group_type_unlink_delayed(const char *idname); /* Has the result of unlinking and linking (re-initializes gizmo's). */ -void WM_gizmo_group_type_reinit_ptr_ex( - struct Main *bmain, struct wmGizmoGroupType *gzgt, - struct wmGizmoMapType *gzmap_type); -void WM_gizmo_group_type_reinit_ptr( - struct Main *bmain, struct wmGizmoGroupType *gzgt); +void WM_gizmo_group_type_reinit_ptr_ex(struct Main *bmain, + struct wmGizmoGroupType *gzgt, + struct wmGizmoMapType *gzmap_type); +void WM_gizmo_group_type_reinit_ptr(struct Main *bmain, struct wmGizmoGroupType *gzgt); void WM_gizmo_group_type_reinit(struct Main *bmain, const char *idname); /* Utilities */ @@ -352,4 +344,4 @@ bool WM_gizmo_context_check_drawstep(const struct bContext *C, eWM_GizmoFlagMapD bool WM_gizmo_group_type_poll(const struct bContext *C, const struct wmGizmoGroupType *gzgt); -#endif /* __WM_GIZMO_API_H__ */ +#endif /* __WM_GIZMO_API_H__ */ diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h index 2322d5fc448..1c298f378a4 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h @@ -26,7 +26,6 @@ * Only included in WM_types.h and lower level files. */ - #ifndef __WM_GIZMO_TYPES_H__ #define __WM_GIZMO_TYPES_H__ @@ -41,54 +40,51 @@ struct wmKeyConfig; #include "DNA_listBase.h" - /* -------------------------------------------------------------------- */ /* Enum Typedef's */ - /** * #wmGizmo.state */ typedef enum eWM_GizmoFlagState { - /** While hovered. */ - WM_GIZMO_STATE_HIGHLIGHT = (1 << 0), - /** While dragging. */ - WM_GIZMO_STATE_MODAL = (1 << 1), - WM_GIZMO_STATE_SELECT = (1 << 2), + /** While hovered. */ + WM_GIZMO_STATE_HIGHLIGHT = (1 << 0), + /** While dragging. */ + WM_GIZMO_STATE_MODAL = (1 << 1), + WM_GIZMO_STATE_SELECT = (1 << 2), } eWM_GizmoFlagState; - /** * #wmGizmo.flag * Flags for individual gizmos. */ typedef enum eWM_GizmoFlag { - /** Draw *only* while hovering. */ - WM_GIZMO_DRAW_HOVER = (1 << 0), - /** Draw while dragging. */ - WM_GIZMO_DRAW_MODAL = (1 << 1), - /** Draw an indicator for the current value while dragging. */ - WM_GIZMO_DRAW_VALUE = (1 << 2), - WM_GIZMO_HIDDEN = (1 << 3), - WM_GIZMO_HIDDEN_SELECT = (1 << 4), - /** - * When set 'scale_final' value also scales the offset. - * Use when offset is to avoid screen-space overlap instead of absolute positioning. */ - WM_GIZMO_DRAW_OFFSET_SCALE = (1 << 5), - /** - * User should still use 'scale_final' for any handles and UI elements. - * This simply skips scale when calculating the final matrix. - * Needed when the gizmo needs to align with the interface underneath it. */ - WM_GIZMO_DRAW_NO_SCALE = (1 << 6), - /** - * Hide the cursor and lock it's position while interacting with this gizmo. - */ - WM_GIZMO_MOVE_CURSOR = (1 << 7), - /** Don't write into the depth buffer when selecting. */ - WM_GIZMO_SELECT_BACKGROUND = (1 << 8), - - /** Use the active tools operator properties when running as an operator. */ - WM_GIZMO_OPERATOR_TOOL_INIT = (1 << 9), + /** Draw *only* while hovering. */ + WM_GIZMO_DRAW_HOVER = (1 << 0), + /** Draw while dragging. */ + WM_GIZMO_DRAW_MODAL = (1 << 1), + /** Draw an indicator for the current value while dragging. */ + WM_GIZMO_DRAW_VALUE = (1 << 2), + WM_GIZMO_HIDDEN = (1 << 3), + WM_GIZMO_HIDDEN_SELECT = (1 << 4), + /** + * When set 'scale_final' value also scales the offset. + * Use when offset is to avoid screen-space overlap instead of absolute positioning. */ + WM_GIZMO_DRAW_OFFSET_SCALE = (1 << 5), + /** + * User should still use 'scale_final' for any handles and UI elements. + * This simply skips scale when calculating the final matrix. + * Needed when the gizmo needs to align with the interface underneath it. */ + WM_GIZMO_DRAW_NO_SCALE = (1 << 6), + /** + * Hide the cursor and lock it's position while interacting with this gizmo. + */ + WM_GIZMO_MOVE_CURSOR = (1 << 7), + /** Don't write into the depth buffer when selecting. */ + WM_GIZMO_SELECT_BACKGROUND = (1 << 8), + + /** Use the active tools operator properties when running as an operator. */ + WM_GIZMO_OPERATOR_TOOL_INIT = (1 << 9), } eWM_GizmoFlag; /** @@ -96,40 +92,39 @@ typedef enum eWM_GizmoFlag { * Flags that influence the behavior of all gizmos in the group. */ typedef enum eWM_GizmoFlagGroupTypeFlag { - /** Mark gizmo-group as being 3D */ - WM_GIZMOGROUPTYPE_3D = (1 << 0), - /** Scale gizmos as 3D object that respects zoom (otherwise zoom independent draw size). - * note: currently only for 3D views, 2D support needs adding. */ - WM_GIZMOGROUPTYPE_SCALE = (1 << 1), - /** Gizmos can be depth culled with scene objects (covered by other geometry - TODO) */ - WM_GIZMOGROUPTYPE_DEPTH_3D = (1 << 2), - /** Gizmos can be selected. */ - WM_GIZMOGROUPTYPE_SELECT = (1 << 3), - /** The gizmo group is to be kept (not removed on loading a new file for eg). */ - WM_GIZMOGROUPTYPE_PERSISTENT = (1 << 4), - /** Show all other gizmos when interacting. */ - WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL = (1 << 5), - /** - * When used with tool, only run when activating the tool, - * instead of linking the gizmo while the tool is active. - * - * \warning this option has some limitations, we might even re-implement this differently. - * Currently it's quite minimal so we can see how it works out. - * The main issue is controlling how a gizmo is activated with a tool - * when a tool can activate multiple operators based on the key-map. - * We could even move the options into the key-map item. - * ~ campbell. */ - WM_GIZMOGROUPTYPE_TOOL_INIT = (1 << 6), + /** Mark gizmo-group as being 3D */ + WM_GIZMOGROUPTYPE_3D = (1 << 0), + /** Scale gizmos as 3D object that respects zoom (otherwise zoom independent draw size). + * note: currently only for 3D views, 2D support needs adding. */ + WM_GIZMOGROUPTYPE_SCALE = (1 << 1), + /** Gizmos can be depth culled with scene objects (covered by other geometry - TODO) */ + WM_GIZMOGROUPTYPE_DEPTH_3D = (1 << 2), + /** Gizmos can be selected. */ + WM_GIZMOGROUPTYPE_SELECT = (1 << 3), + /** The gizmo group is to be kept (not removed on loading a new file for eg). */ + WM_GIZMOGROUPTYPE_PERSISTENT = (1 << 4), + /** Show all other gizmos when interacting. */ + WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL = (1 << 5), + /** + * When used with tool, only run when activating the tool, + * instead of linking the gizmo while the tool is active. + * + * \warning this option has some limitations, we might even re-implement this differently. + * Currently it's quite minimal so we can see how it works out. + * The main issue is controlling how a gizmo is activated with a tool + * when a tool can activate multiple operators based on the key-map. + * We could even move the options into the key-map item. + * ~ campbell. */ + WM_GIZMOGROUPTYPE_TOOL_INIT = (1 << 6), } eWM_GizmoFlagGroupTypeFlag; - /** * #wmGizmoGroup.init_flag */ typedef enum eWM_GizmoFlagGroupInitFlag { - /** Gizmo-group has been initialized. */ - WM_GIZMOGROUP_INIT_SETUP = (1 << 0), - WM_GIZMOGROUP_INIT_REFRESH = (1 << 1), + /** Gizmo-group has been initialized. */ + WM_GIZMOGROUP_INIT_SETUP = (1 << 0), + WM_GIZMOGROUP_INIT_REFRESH = (1 << 1), } eWM_GizmoFlagGroupInitFlag; /** @@ -137,13 +132,13 @@ typedef enum eWM_GizmoFlagGroupInitFlag { * Gizmo-map type update flag */ typedef enum eWM_GizmoFlagMapTypeUpdateFlag { - /** A new type has been added, needs to be initialized for all views. */ - WM_GIZMOMAPTYPE_UPDATE_INIT = (1 << 0), - WM_GIZMOMAPTYPE_UPDATE_REMOVE = (1 << 1), + /** A new type has been added, needs to be initialized for all views. */ + WM_GIZMOMAPTYPE_UPDATE_INIT = (1 << 0), + WM_GIZMOMAPTYPE_UPDATE_REMOVE = (1 << 1), - /** Needed because keymap may be registered before and after window initialization. - * So we need to keep track of keymap initialization separately. */ - WM_GIZMOMAPTYPE_KEYMAP_INIT = (1 << 2), + /** Needed because keymap may be registered before and after window initialization. + * So we need to keep track of keymap initialization separately. */ + WM_GIZMOMAPTYPE_KEYMAP_INIT = (1 << 2), } eWM_GizmoFlagMapTypeUpdateFlag; /* -------------------------------------------------------------------- */ @@ -156,279 +151,276 @@ typedef enum eWM_GizmoFlagMapTypeUpdateFlag { * \note Gizmos are responsible for handling this #wmGizmo.modal callback!. */ typedef enum { - /* Drag with extra precision (Shift). */ - WM_GIZMO_TWEAK_PRECISE = (1 << 0), - /* Drag with snap enabled (Ctrl). */ - WM_GIZMO_TWEAK_SNAP = (1 << 1), + /* Drag with extra precision (Shift). */ + WM_GIZMO_TWEAK_PRECISE = (1 << 0), + /* Drag with snap enabled (Ctrl). */ + WM_GIZMO_TWEAK_SNAP = (1 << 1), } eWM_GizmoFlagTweak; #include "wm_gizmo_fn.h" typedef struct wmGizmoOpElem { - struct wmOperatorType *type; - /** Operator properties if gizmo spawns and controls an operator, - * or owner pointer if gizmo spawns and controls a property. */ - PointerRNA ptr; + struct wmOperatorType *type; + /** Operator properties if gizmo spawns and controls an operator, + * or owner pointer if gizmo spawns and controls a property. */ + PointerRNA ptr; - bool is_redo; + bool is_redo; } wmGizmoOpElem; /* gizmos are set per region by registering them on gizmo-maps */ struct wmGizmo { - struct wmGizmo *next, *prev; - - /** While we don't have a real type, use this to put type-like vars. */ - const struct wmGizmoType *type; - - /** Overrides 'type->modal' when set. - * Note that this is a workaround, remove if we can. */ - wmGizmoFnModal custom_modal; - - /** Pointer back to group this gizmo is in (just for quick access). */ - struct wmGizmoGroup *parent_gzgroup; - - void *py_instance; - - /** Rna pointer to access properties. */ - struct PointerRNA *ptr; - - /** Flags that influence the behavior or how the gizmos are drawn. */ - eWM_GizmoFlag flag; - /** State flags (active, highlighted, selected) */ - eWM_GizmoFlagState state; - - /** Optional ID for highlighting different parts of this gizmo. - * -1 when unset, otherwise a valid index. (Used as index to 'op_data'). */ - int highlight_part; - /** For single click button gizmos, use a different part as a fallback, -1 when unused. */ - int drag_part; - - /** - * Transformation of the gizmo in 2d or 3d space. - * - Matrix axis are expected to be unit length (scale is applied after). - * - Behavior when axis aren't orthogonal depends on each gizmo. - * - Typically the +Z is the primary axis for gizmos to use. - * - 'matrix[3]' must be used for location, - * besides this it's up to the gizmos internal code how the - * rotation components are used for drawing and interaction. - */ - - /** The space this gizmo is being modified in. */ - float matrix_space[4][4]; - /** Transformation of this gizmo. */ - float matrix_basis[4][4]; - /** Custom offset from origin. */ - float matrix_offset[4][4]; - /** Runtime property, set the scale while drawing on the viewport. */ - float scale_final; - /** User defined scale, in addition to the original one. */ - float scale_basis; - /** User defined width for line drawing. */ - float line_width; - /** Gizmo colors (uses default fallbacks if not defined). */ - float color[4], color_hi[4]; - - /** Data used during interaction. */ - void *interaction_data; - - /** Operator to spawn when activating the gizmo (overrides property editing), - * an array of items (aligned with #wmGizmo.highlight_part). */ - wmGizmoOpElem *op_data; - int op_data_len; - - struct IDProperty *properties; - - /** Temporary data (assume dirty). */ - union { - float f; - } temp; - - /* over alloc target_properties after 'wmGizmoType.struct_size' */ + struct wmGizmo *next, *prev; + + /** While we don't have a real type, use this to put type-like vars. */ + const struct wmGizmoType *type; + + /** Overrides 'type->modal' when set. + * Note that this is a workaround, remove if we can. */ + wmGizmoFnModal custom_modal; + + /** Pointer back to group this gizmo is in (just for quick access). */ + struct wmGizmoGroup *parent_gzgroup; + + void *py_instance; + + /** Rna pointer to access properties. */ + struct PointerRNA *ptr; + + /** Flags that influence the behavior or how the gizmos are drawn. */ + eWM_GizmoFlag flag; + /** State flags (active, highlighted, selected) */ + eWM_GizmoFlagState state; + + /** Optional ID for highlighting different parts of this gizmo. + * -1 when unset, otherwise a valid index. (Used as index to 'op_data'). */ + int highlight_part; + /** For single click button gizmos, use a different part as a fallback, -1 when unused. */ + int drag_part; + + /** + * Transformation of the gizmo in 2d or 3d space. + * - Matrix axis are expected to be unit length (scale is applied after). + * - Behavior when axis aren't orthogonal depends on each gizmo. + * - Typically the +Z is the primary axis for gizmos to use. + * - 'matrix[3]' must be used for location, + * besides this it's up to the gizmos internal code how the + * rotation components are used for drawing and interaction. + */ + + /** The space this gizmo is being modified in. */ + float matrix_space[4][4]; + /** Transformation of this gizmo. */ + float matrix_basis[4][4]; + /** Custom offset from origin. */ + float matrix_offset[4][4]; + /** Runtime property, set the scale while drawing on the viewport. */ + float scale_final; + /** User defined scale, in addition to the original one. */ + float scale_basis; + /** User defined width for line drawing. */ + float line_width; + /** Gizmo colors (uses default fallbacks if not defined). */ + float color[4], color_hi[4]; + + /** Data used during interaction. */ + void *interaction_data; + + /** Operator to spawn when activating the gizmo (overrides property editing), + * an array of items (aligned with #wmGizmo.highlight_part). */ + wmGizmoOpElem *op_data; + int op_data_len; + + struct IDProperty *properties; + + /** Temporary data (assume dirty). */ + union { + float f; + } temp; + + /* over alloc target_properties after 'wmGizmoType.struct_size' */ }; /** Similar to #PropertyElemRNA, but has an identifier. */ typedef struct wmGizmoProperty { - const struct wmGizmoPropertyType *type; - - PointerRNA ptr; - PropertyRNA *prop; - int index; - - - /* Optional functions for converting to/from RNA */ - struct { - wmGizmoPropertyFnGet value_get_fn; - wmGizmoPropertyFnSet value_set_fn; - wmGizmoPropertyFnRangeGet range_get_fn; - wmGizmoPropertyFnFree free_fn; - void *user_data; - } custom_func; + const struct wmGizmoPropertyType *type; + + PointerRNA ptr; + PropertyRNA *prop; + int index; + + /* Optional functions for converting to/from RNA */ + struct { + wmGizmoPropertyFnGet value_get_fn; + wmGizmoPropertyFnSet value_set_fn; + wmGizmoPropertyFnRangeGet range_get_fn; + wmGizmoPropertyFnFree free_fn; + void *user_data; + } custom_func; } wmGizmoProperty; typedef struct wmGizmoPropertyType { - struct wmGizmoPropertyType *next, *prev; - /** #PropertyType, typically #PROP_FLOAT. */ - int data_type; - int array_length; + struct wmGizmoPropertyType *next, *prev; + /** #PropertyType, typically #PROP_FLOAT. */ + int data_type; + int array_length; - /* index within 'wmGizmoType' */ - int index_in_type; + /* index within 'wmGizmoType' */ + int index_in_type; - /** over alloc. */ - char idname[0]; + /** over alloc. */ + char idname[0]; } wmGizmoPropertyType; - /** * Simple utility wrapper for storing a single gizmo as wmGizmoGroup.customdata (which gets freed). */ typedef struct wmGizmoWrapper { - struct wmGizmo *gizmo; + struct wmGizmo *gizmo; } wmGizmoWrapper; struct wmGizmoMapType_Params { - short spaceid; - short regionid; + short spaceid; + short regionid; }; typedef struct wmGizmoType { - const char *idname; /* MAX_NAME */ + const char *idname; /* MAX_NAME */ - /** Set to 'sizeof(wmGizmo)' or larger for instances of this type, - * use so we can cant to other types without the hassle of a custom-data pointer. */ - uint struct_size; + /** Set to 'sizeof(wmGizmo)' or larger for instances of this type, + * use so we can cant to other types without the hassle of a custom-data pointer. */ + uint struct_size; - /** Initialize struct (calloc'd 'struct_size' region). */ - wmGizmoFnSetup setup; + /** Initialize struct (calloc'd 'struct_size' region). */ + wmGizmoFnSetup setup; - /** Draw gizmo. */ - wmGizmoFnDraw draw; + /** Draw gizmo. */ + wmGizmoFnDraw draw; - /** Determines 3d intersection by rendering the gizmo in a selection routine. */ - wmGizmoFnDrawSelect draw_select; + /** Determines 3d intersection by rendering the gizmo in a selection routine. */ + wmGizmoFnDrawSelect draw_select; - /** Determine if the mouse intersects with the gizmo. - * The calculation should be done in the callback itself, -1 for no seleciton. */ - wmGizmoFnTestSelect test_select; + /** Determine if the mouse intersects with the gizmo. + * The calculation should be done in the callback itself, -1 for no seleciton. */ + wmGizmoFnTestSelect test_select; - /** Handler used by the gizmo. Usually handles interaction tied to a gizmo type. */ - wmGizmoFnModal modal; + /** Handler used by the gizmo. Usually handles interaction tied to a gizmo type. */ + wmGizmoFnModal modal; - /** Gizmo-specific handler to update gizmo attributes based on the property value. */ - wmGizmoFnPropertyUpdate property_update; + /** Gizmo-specific handler to update gizmo attributes based on the property value. */ + wmGizmoFnPropertyUpdate property_update; - /** Returns the final transformation which may be different from the 'matrix', - * depending on the gizmo. - * Notes: - * - Scale isn't applied (wmGizmo.scale/user_scale). - * - Offset isn't applied (wmGizmo.matrix_offset). - */ - wmGizmoFnMatrixBasisGet matrix_basis_get; + /** Returns the final transformation which may be different from the 'matrix', + * depending on the gizmo. + * Notes: + * - Scale isn't applied (wmGizmo.scale/user_scale). + * - Offset isn't applied (wmGizmo.matrix_offset). + */ + wmGizmoFnMatrixBasisGet matrix_basis_get; - /** Activate a gizmo state when the user clicks on it. */ - wmGizmoFnInvoke invoke; + /** Activate a gizmo state when the user clicks on it. */ + wmGizmoFnInvoke invoke; - /** Called when gizmo tweaking is done - used to free data and reset property when cancelling. */ - wmGizmoFnExit exit; + /** Called when gizmo tweaking is done - used to free data and reset property when cancelling. */ + wmGizmoFnExit exit; - wmGizmoFnCursorGet cursor_get; + wmGizmoFnCursorGet cursor_get; - /** Called when gizmo selection state changes. */ - wmGizmoFnSelectRefresh select_refresh; + /** Called when gizmo selection state changes. */ + wmGizmoFnSelectRefresh select_refresh; - /** Free data (not the gizmo it's self), use when the gizmo allocates it's own members. */ - wmGizmoFnFree free; + /** Free data (not the gizmo it's self), use when the gizmo allocates it's own members. */ + wmGizmoFnFree free; - /** RNA for properties. */ - struct StructRNA *srna; + /** RNA for properties. */ + struct StructRNA *srna; - /** RNA integration. */ - ExtensionRNA ext; + /** RNA integration. */ + ExtensionRNA ext; - ListBase target_property_defs; - int target_property_defs_len; + ListBase target_property_defs; + int target_property_defs_len; } wmGizmoType; - /* -------------------------------------------------------------------- */ /* wmGizmoGroup */ /** Factory class for a gizmo-group type, gets called every time a new area is spawned. */ typedef struct wmGizmoGroupTypeRef { - struct wmGizmoGroupTypeRef *next, *prev; - struct wmGizmoGroupType *type; + struct wmGizmoGroupTypeRef *next, *prev; + struct wmGizmoGroupType *type; } wmGizmoGroupTypeRef; /* factory class for a gizmo-group type, gets called every time a new area is spawned */ typedef struct wmGizmoGroupType { - const char *idname; /* MAX_NAME */ - /** Gizmo-group name - displayed in UI (keymap editor). */ - const char *name; - char owner_id[64]; /* MAX_NAME */ + const char *idname; /* MAX_NAME */ + /** Gizmo-group name - displayed in UI (keymap editor). */ + const char *name; + char owner_id[64]; /* MAX_NAME */ - /** Poll if gizmo-map should be visible. */ - wmGizmoGroupFnPoll poll; - /** Initially create gizmos and set permanent data - stuff you only need to do once. */ - wmGizmoGroupFnInit setup; - /** Refresh data, only called if recreate flag is set (WM_gizmomap_tag_refresh). */ - wmGizmoGroupFnRefresh refresh; - /** Refresh data for drawing, called before each redraw. */ - wmGizmoGroupFnDrawPrepare draw_prepare; - /** Initialize data for before invoke. */ - wmGizmoGroupFnInvokePrepare invoke_prepare; + /** Poll if gizmo-map should be visible. */ + wmGizmoGroupFnPoll poll; + /** Initially create gizmos and set permanent data - stuff you only need to do once. */ + wmGizmoGroupFnInit setup; + /** Refresh data, only called if recreate flag is set (WM_gizmomap_tag_refresh). */ + wmGizmoGroupFnRefresh refresh; + /** Refresh data for drawing, called before each redraw. */ + wmGizmoGroupFnDrawPrepare draw_prepare; + /** Initialize data for before invoke. */ + wmGizmoGroupFnInvokePrepare invoke_prepare; - /** Keymap init callback for this gizmo-group (optional), - * will fall back to default tweak keymap when left NULL. */ - wmGizmoGroupFnSetupKeymap setup_keymap; + /** Keymap init callback for this gizmo-group (optional), + * will fall back to default tweak keymap when left NULL. */ + wmGizmoGroupFnSetupKeymap setup_keymap; - /** Optionally subscribe to wmMsgBus events, - * these are calculated automatically from RNA properties, - * only needed if gizmos depend indirectly on properties. */ - wmGizmoGroupFnMsgBusSubscribe message_subscribe; + /** Optionally subscribe to wmMsgBus events, + * these are calculated automatically from RNA properties, + * only needed if gizmos depend indirectly on properties. */ + wmGizmoGroupFnMsgBusSubscribe message_subscribe; - /** Keymap created with callback from above. */ - struct wmKeyMap *keymap; - /** Only for convenient removal. */ - struct wmKeyConfig *keyconf; + /** Keymap created with callback from above. */ + struct wmKeyMap *keymap; + /** Only for convenient removal. */ + struct wmKeyConfig *keyconf; - /* Note: currently gizmo-group instances don't store properties, - * they're kept in the tool properties. */ + /* Note: currently gizmo-group instances don't store properties, + * they're kept in the tool properties. */ - /** RNA for properties. */ - struct StructRNA *srna; + /** RNA for properties. */ + struct StructRNA *srna; - /** RNA integration. */ - ExtensionRNA ext; + /** RNA integration. */ + ExtensionRNA ext; - eWM_GizmoFlagGroupTypeFlag flag; + eWM_GizmoFlagGroupTypeFlag flag; - /** So we know which group type to update. */ - eWM_GizmoFlagMapTypeUpdateFlag type_update_flag; + /** So we know which group type to update. */ + eWM_GizmoFlagMapTypeUpdateFlag type_update_flag; - /** Same as gizmo-maps, so registering/unregistering goes to the correct region. */ - struct wmGizmoMapType_Params gzmap_params; + /** Same as gizmo-maps, so registering/unregistering goes to the correct region. */ + struct wmGizmoMapType_Params gzmap_params; } wmGizmoGroupType; typedef struct wmGizmoGroup { - struct wmGizmoGroup *next, *prev; + struct wmGizmoGroup *next, *prev; - struct wmGizmoGroupType *type; - ListBase gizmos; + struct wmGizmoGroupType *type; + ListBase gizmos; - struct wmGizmoMap *parent_gzmap; + struct wmGizmoMap *parent_gzmap; - /** Python stores the class instance here. */ - void *py_instance; - /** Errors and warnings storage. */ - struct ReportList *reports; + /** Python stores the class instance here. */ + void *py_instance; + /** Errors and warnings storage. */ + struct ReportList *reports; - void *customdata; - /** For freeing customdata from above. */ - void (*customdata_free)(void *); - eWM_GizmoFlagGroupInitFlag init_flag; + void *customdata; + /** For freeing customdata from above. */ + void (*customdata_free)(void *); + eWM_GizmoFlagGroupInitFlag init_flag; } wmGizmoGroup; /* -------------------------------------------------------------------- */ @@ -438,11 +430,11 @@ typedef struct wmGizmoGroup { * Pass a value of this enum to #WM_gizmomap_draw to tell it what to draw. */ typedef enum eWM_GizmoFlagMapDrawStep { - /** Draw 2D gizmo-groups (#WM_GIZMOGROUPTYPE_3D not set). */ - WM_GIZMOMAP_DRAWSTEP_2D = 0, - /** Draw 3D gizmo-groups (#WM_GIZMOGROUPTYPE_3D set). */ - WM_GIZMOMAP_DRAWSTEP_3D, + /** Draw 2D gizmo-groups (#WM_GIZMOGROUPTYPE_3D not set). */ + WM_GIZMOMAP_DRAWSTEP_2D = 0, + /** Draw 3D gizmo-groups (#WM_GIZMOGROUPTYPE_3D set). */ + WM_GIZMOMAP_DRAWSTEP_3D, } eWM_GizmoFlagMapDrawStep; #define WM_GIZMOMAP_DRAWSTEP_MAX 2 -#endif /* __WM_GIZMO_TYPES_H__ */ +#endif /* __WM_GIZMO_TYPES_H__ */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c index 1a4141c0178..997afb1dc6c 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c @@ -49,7 +49,7 @@ #include "UI_interface.h" #ifdef WITH_PYTHON -#include "BPY_extern.h" +# include "BPY_extern.h" #endif /* only for own init/exit calls (wm_gizmotype_init/wm_gizmotype_free) */ @@ -59,58 +59,53 @@ #include "wm_gizmo_wmapi.h" #include "wm_gizmo_intern.h" -static void wm_gizmo_register( - wmGizmoGroup *gzgroup, wmGizmo *gz); +static void wm_gizmo_register(wmGizmoGroup *gzgroup, wmGizmo *gz); /** * \note Follow #wm_operator_create convention. */ -static wmGizmo *wm_gizmo_create( - const wmGizmoType *gzt, - PointerRNA *properties) +static wmGizmo *wm_gizmo_create(const wmGizmoType *gzt, PointerRNA *properties) { - BLI_assert(gzt != NULL); - BLI_assert(gzt->struct_size >= sizeof(wmGizmo)); + BLI_assert(gzt != NULL); + BLI_assert(gzt->struct_size >= sizeof(wmGizmo)); - wmGizmo *gz = MEM_callocN( - gzt->struct_size + (sizeof(wmGizmoProperty) * gzt->target_property_defs_len), __func__); - gz->type = gzt; + wmGizmo *gz = MEM_callocN( + gzt->struct_size + (sizeof(wmGizmoProperty) * gzt->target_property_defs_len), __func__); + gz->type = gzt; - /* initialize properties, either copy or create */ - gz->ptr = MEM_callocN(sizeof(PointerRNA), "wmGizmoPtrRNA"); - if (properties && properties->data) { - gz->properties = IDP_CopyProperty(properties->data); - } - else { - IDPropertyTemplate val = {0}; - gz->properties = IDP_New(IDP_GROUP, &val, "wmGizmoProperties"); - } - RNA_pointer_create(G_MAIN->wm.first, gzt->srna, gz->properties, gz->ptr); + /* initialize properties, either copy or create */ + gz->ptr = MEM_callocN(sizeof(PointerRNA), "wmGizmoPtrRNA"); + if (properties && properties->data) { + gz->properties = IDP_CopyProperty(properties->data); + } + else { + IDPropertyTemplate val = {0}; + gz->properties = IDP_New(IDP_GROUP, &val, "wmGizmoProperties"); + } + RNA_pointer_create(G_MAIN->wm.first, gzt->srna, gz->properties, gz->ptr); - WM_gizmo_properties_sanitize(gz->ptr, 0); + WM_gizmo_properties_sanitize(gz->ptr, 0); - unit_m4(gz->matrix_space); - unit_m4(gz->matrix_basis); - unit_m4(gz->matrix_offset); + unit_m4(gz->matrix_space); + unit_m4(gz->matrix_basis); + unit_m4(gz->matrix_offset); - gz->drag_part = -1; + gz->drag_part = -1; - return gz; + return gz; } -wmGizmo *WM_gizmo_new_ptr( - const wmGizmoType *gzt, wmGizmoGroup *gzgroup, - PointerRNA *properties) +wmGizmo *WM_gizmo_new_ptr(const wmGizmoType *gzt, wmGizmoGroup *gzgroup, PointerRNA *properties) { - wmGizmo *gz = wm_gizmo_create(gzt, properties); + wmGizmo *gz = wm_gizmo_create(gzt, properties); - wm_gizmo_register(gzgroup, gz); + wm_gizmo_register(gzgroup, gz); - if (gz->type->setup != NULL) { - gz->type->setup(gz); - } + if (gz->type->setup != NULL) { + gz->type->setup(gz); + } - return gz; + return gz; } /** @@ -118,12 +113,10 @@ wmGizmo *WM_gizmo_new_ptr( * if you need to check it exists use #WM_gizmo_new_ptr * because callers of this function don't NULL check the return value. */ -wmGizmo *WM_gizmo_new( - const char *idname, wmGizmoGroup *gzgroup, - PointerRNA *properties) +wmGizmo *WM_gizmo_new(const char *idname, wmGizmoGroup *gzgroup, PointerRNA *properties) { - const wmGizmoType *gzt = WM_gizmotype_find(idname, false); - return WM_gizmo_new_ptr(gzt, gzgroup, properties); + const wmGizmoType *gzt = WM_gizmotype_find(idname, false); + return WM_gizmo_new_ptr(gzt, gzgroup, properties); } /** @@ -131,14 +124,14 @@ wmGizmo *WM_gizmo_new( */ static void gizmo_init(wmGizmo *gz) { - const float color_default[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + const float color_default[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - gz->scale_basis = 1.0f; - gz->line_width = 1.0f; + gz->scale_basis = 1.0f; + gz->line_width = 1.0f; - /* defaults */ - copy_v4_v4(gz->color, color_default); - copy_v4_v4(gz->color_hi, color_default); + /* defaults */ + copy_v4_v4(gz->color, color_default); + copy_v4_v4(gz->color_hi, color_default); } /** @@ -148,8 +141,8 @@ static void gizmo_init(wmGizmo *gz) */ static void wm_gizmo_register(wmGizmoGroup *gzgroup, wmGizmo *gz) { - gizmo_init(gz); - wm_gizmogroup_gizmo_register(gzgroup, gz); + gizmo_init(gz); + wm_gizmogroup_gizmo_register(gzgroup, gz); } /** @@ -159,41 +152,41 @@ static void wm_gizmo_register(wmGizmoGroup *gzgroup, wmGizmo *gz) */ void WM_gizmo_free(wmGizmo *gz) { - if (gz->type->free != NULL) { - gz->type->free(gz); - } + if (gz->type->free != NULL) { + gz->type->free(gz); + } #ifdef WITH_PYTHON - if (gz->py_instance) { - /* do this first in case there are any __del__ functions or - * similar that use properties */ - BPY_DECREF_RNA_INVALIDATE(gz->py_instance); - } + if (gz->py_instance) { + /* do this first in case there are any __del__ functions or + * similar that use properties */ + BPY_DECREF_RNA_INVALIDATE(gz->py_instance); + } #endif - if (gz->op_data) { - for (int i = 0; i < gz->op_data_len; i++) { - WM_operator_properties_free(&gz->op_data[i].ptr); - } - MEM_freeN(gz->op_data); - } + if (gz->op_data) { + for (int i = 0; i < gz->op_data_len; i++) { + WM_operator_properties_free(&gz->op_data[i].ptr); + } + MEM_freeN(gz->op_data); + } - if (gz->ptr != NULL) { - WM_gizmo_properties_free(gz->ptr); - MEM_freeN(gz->ptr); - } + if (gz->ptr != NULL) { + WM_gizmo_properties_free(gz->ptr); + MEM_freeN(gz->ptr); + } - if (gz->type->target_property_defs_len != 0) { - wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); - for (int i = 0; i < gz->type->target_property_defs_len; i++) { - wmGizmoProperty *gz_prop = &gz_prop_array[i]; - if (gz_prop->custom_func.free_fn) { - gz_prop->custom_func.free_fn(gz, gz_prop); - } - } - } + if (gz->type->target_property_defs_len != 0) { + wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); + for (int i = 0; i < gz->type->target_property_defs_len; i++) { + wmGizmoProperty *gz_prop = &gz_prop_array[i]; + if (gz_prop->custom_func.free_fn) { + gz_prop->custom_func.free_fn(gz, gz_prop); + } + } + } - MEM_freeN(gz); + MEM_freeN(gz); } /** @@ -202,25 +195,25 @@ void WM_gizmo_free(wmGizmo *gz) */ void WM_gizmo_unlink(ListBase *gizmolist, wmGizmoMap *gzmap, wmGizmo *gz, bContext *C) { - if (gz->state & WM_GIZMO_STATE_HIGHLIGHT) { - wm_gizmomap_highlight_set(gzmap, C, NULL, 0); - } - if (gz->state & WM_GIZMO_STATE_MODAL) { - wm_gizmomap_modal_set(gzmap, C, gz, NULL, false); - } - /* Unlink instead of setting so we don't run callbacks. */ - if (gz->state & WM_GIZMO_STATE_SELECT) { - WM_gizmo_select_unlink(gzmap, gz); - } + if (gz->state & WM_GIZMO_STATE_HIGHLIGHT) { + wm_gizmomap_highlight_set(gzmap, C, NULL, 0); + } + if (gz->state & WM_GIZMO_STATE_MODAL) { + wm_gizmomap_modal_set(gzmap, C, gz, NULL, false); + } + /* Unlink instead of setting so we don't run callbacks. */ + if (gz->state & WM_GIZMO_STATE_SELECT) { + WM_gizmo_select_unlink(gzmap, gz); + } - if (gizmolist) { - BLI_remlink(gizmolist, gz); - } + if (gizmolist) { + BLI_remlink(gizmolist, gz); + } - BLI_assert(gzmap->gzmap_context.highlight != gz); - BLI_assert(gzmap->gzmap_context.modal != gz); + BLI_assert(gzmap->gzmap_context.highlight != gz); + BLI_assert(gzmap->gzmap_context.modal != gz); - WM_gizmo_free(gz); + WM_gizmo_free(gz); } /* -------------------------------------------------------------------- */ @@ -230,162 +223,160 @@ void WM_gizmo_unlink(ListBase *gizmolist, wmGizmoMap *gzmap, wmGizmo *gz, bConte * * \{ */ -struct wmGizmoOpElem *WM_gizmo_operator_get( - wmGizmo *gz, int part_index) +struct wmGizmoOpElem *WM_gizmo_operator_get(wmGizmo *gz, int part_index) { - if (gz->op_data && ((part_index >= 0) && (part_index < gz->op_data_len))) { - return &gz->op_data[part_index]; - } - return NULL; + if (gz->op_data && ((part_index >= 0) && (part_index < gz->op_data_len))) { + return &gz->op_data[part_index]; + } + return NULL; } -PointerRNA *WM_gizmo_operator_set( - wmGizmo *gz, int part_index, - wmOperatorType *ot, IDProperty *properties) +PointerRNA *WM_gizmo_operator_set(wmGizmo *gz, + int part_index, + wmOperatorType *ot, + IDProperty *properties) { - BLI_assert(part_index < 255); - /* We could pre-allocate these but using multiple is such a rare thing. */ - if (part_index >= gz->op_data_len) { - gz->op_data_len = part_index + 1; - gz->op_data = MEM_recallocN(gz->op_data, sizeof(*gz->op_data) * gz->op_data_len); - } - wmGizmoOpElem *gzop = &gz->op_data[part_index]; - gzop->type = ot; + BLI_assert(part_index < 255); + /* We could pre-allocate these but using multiple is such a rare thing. */ + if (part_index >= gz->op_data_len) { + gz->op_data_len = part_index + 1; + gz->op_data = MEM_recallocN(gz->op_data, sizeof(*gz->op_data) * gz->op_data_len); + } + wmGizmoOpElem *gzop = &gz->op_data[part_index]; + gzop->type = ot; - if (gzop->ptr.data) { - WM_operator_properties_free(&gzop->ptr); - } - WM_operator_properties_create_ptr(&gzop->ptr, ot); + if (gzop->ptr.data) { + WM_operator_properties_free(&gzop->ptr); + } + WM_operator_properties_create_ptr(&gzop->ptr, ot); - if (properties) { - gzop->ptr.data = properties; - } + if (properties) { + gzop->ptr.data = properties; + } - return &gzop->ptr; + return &gzop->ptr; } int WM_gizmo_operator_invoke(bContext *C, wmGizmo *gz, wmGizmoOpElem *gzop) { - if (gz->flag & WM_GIZMO_OPERATOR_TOOL_INIT) { - /* Merge toolsettings into the gizmo properties. */ - PointerRNA tref_ptr; - bToolRef *tref = WM_toolsystem_ref_from_context(C); - if (tref && WM_toolsystem_ref_properties_get_from_operator(tref, gzop->type, &tref_ptr)) { - if (gzop->ptr.data == NULL) { - IDPropertyTemplate val = {0}; - gzop->ptr.data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); - } - IDP_MergeGroup(gzop->ptr.data, tref_ptr.data, false); - } - } - return WM_operator_name_call_ptr(C, gzop->type, WM_OP_INVOKE_DEFAULT, &gzop->ptr); -} - -static void wm_gizmo_set_matrix_rotation_from_z_axis__internal( - float matrix[4][4], const float z_axis[3]) -{ - /* old code, seems we can use simpler method */ + if (gz->flag & WM_GIZMO_OPERATOR_TOOL_INIT) { + /* Merge toolsettings into the gizmo properties. */ + PointerRNA tref_ptr; + bToolRef *tref = WM_toolsystem_ref_from_context(C); + if (tref && WM_toolsystem_ref_properties_get_from_operator(tref, gzop->type, &tref_ptr)) { + if (gzop->ptr.data == NULL) { + IDPropertyTemplate val = {0}; + gzop->ptr.data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + } + IDP_MergeGroup(gzop->ptr.data, tref_ptr.data, false); + } + } + return WM_operator_name_call_ptr(C, gzop->type, WM_OP_INVOKE_DEFAULT, &gzop->ptr); +} + +static void wm_gizmo_set_matrix_rotation_from_z_axis__internal(float matrix[4][4], + const float z_axis[3]) +{ + /* old code, seems we can use simpler method */ #if 0 - const float z_global[3] = {0.0f, 0.0f, 1.0f}; - float rot[3][3]; + const float z_global[3] = {0.0f, 0.0f, 1.0f}; + float rot[3][3]; - rotation_between_vecs_to_mat3(rot, z_global, z_axis); - copy_v3_v3(matrix[0], rot[0]); - copy_v3_v3(matrix[1], rot[1]); - copy_v3_v3(matrix[2], rot[2]); + rotation_between_vecs_to_mat3(rot, z_global, z_axis); + copy_v3_v3(matrix[0], rot[0]); + copy_v3_v3(matrix[1], rot[1]); + copy_v3_v3(matrix[2], rot[2]); #else - normalize_v3_v3(matrix[2], z_axis); - ortho_basis_v3v3_v3(matrix[0], matrix[1], matrix[2]); + normalize_v3_v3(matrix[2], z_axis); + ortho_basis_v3v3_v3(matrix[0], matrix[1], matrix[2]); #endif - } -static void wm_gizmo_set_matrix_rotation_from_yz_axis__internal( - float matrix[4][4], const float y_axis[3], const float z_axis[3]) +static void wm_gizmo_set_matrix_rotation_from_yz_axis__internal(float matrix[4][4], + const float y_axis[3], + const float z_axis[3]) { - normalize_v3_v3(matrix[1], y_axis); - normalize_v3_v3(matrix[2], z_axis); - cross_v3_v3v3(matrix[0], matrix[1], matrix[2]); - normalize_v3(matrix[0]); + normalize_v3_v3(matrix[1], y_axis); + normalize_v3_v3(matrix[2], z_axis); + cross_v3_v3v3(matrix[0], matrix[1], matrix[2]); + normalize_v3(matrix[0]); } /** * wmGizmo.matrix utils. */ -void WM_gizmo_set_matrix_rotation_from_z_axis( - wmGizmo *gz, const float z_axis[3]) +void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3]) { - wm_gizmo_set_matrix_rotation_from_z_axis__internal(gz->matrix_basis, z_axis); + wm_gizmo_set_matrix_rotation_from_z_axis__internal(gz->matrix_basis, z_axis); } -void WM_gizmo_set_matrix_rotation_from_yz_axis( - wmGizmo *gz, const float y_axis[3], const float z_axis[3]) +void WM_gizmo_set_matrix_rotation_from_yz_axis(wmGizmo *gz, + const float y_axis[3], + const float z_axis[3]) { - wm_gizmo_set_matrix_rotation_from_yz_axis__internal(gz->matrix_basis, y_axis, z_axis); + wm_gizmo_set_matrix_rotation_from_yz_axis__internal(gz->matrix_basis, y_axis, z_axis); } void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3]) { - copy_v3_v3(gz->matrix_basis[3], origin); + copy_v3_v3(gz->matrix_basis[3], origin); } /** * wmGizmo.matrix_offset utils. */ -void WM_gizmo_set_matrix_offset_rotation_from_z_axis( - wmGizmo *gz, const float z_axis[3]) +void WM_gizmo_set_matrix_offset_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3]) { - wm_gizmo_set_matrix_rotation_from_z_axis__internal(gz->matrix_offset, z_axis); + wm_gizmo_set_matrix_rotation_from_z_axis__internal(gz->matrix_offset, z_axis); } -void WM_gizmo_set_matrix_offset_rotation_from_yz_axis( - wmGizmo *gz, const float y_axis[3], const float z_axis[3]) +void WM_gizmo_set_matrix_offset_rotation_from_yz_axis(wmGizmo *gz, + const float y_axis[3], + const float z_axis[3]) { - wm_gizmo_set_matrix_rotation_from_yz_axis__internal(gz->matrix_offset, y_axis, z_axis); + wm_gizmo_set_matrix_rotation_from_yz_axis__internal(gz->matrix_offset, y_axis, z_axis); } void WM_gizmo_set_matrix_offset_location(wmGizmo *gz, const float offset[3]) { - copy_v3_v3(gz->matrix_offset[3], offset); + copy_v3_v3(gz->matrix_offset[3], offset); } void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable) { - if (enable) { - gz->flag |= flag; - } - else { - gz->flag &= ~flag; - } + if (enable) { + gz->flag |= flag; + } + else { + gz->flag &= ~flag; + } } void WM_gizmo_set_scale(wmGizmo *gz, const float scale) { - gz->scale_basis = scale; + gz->scale_basis = scale; } void WM_gizmo_set_line_width(wmGizmo *gz, const float line_width) { - gz->line_width = line_width; + gz->line_width = line_width; } void WM_gizmo_get_color(const wmGizmo *gz, float color[4]) { - copy_v4_v4(color, gz->color); + copy_v4_v4(color, gz->color); } void WM_gizmo_set_color(wmGizmo *gz, const float color[4]) { - copy_v4_v4(gz->color, color); + copy_v4_v4(gz->color, color); } void WM_gizmo_get_color_highlight(const wmGizmo *gz, float color_hi[4]) { - copy_v4_v4(color_hi, gz->color_hi); + copy_v4_v4(color_hi, gz->color_hi); } void WM_gizmo_set_color_highlight(wmGizmo *gz, const float color_hi[4]) { - copy_v4_v4(gz->color_hi, color_hi); + copy_v4_v4(gz->color_hi, color_hi); } - -/** \} */ // Gizmo Creation API - +/** \} */ // Gizmo Creation API /* -------------------------------------------------------------------- */ /** \name Gizmo Callback Assignment @@ -394,12 +385,11 @@ void WM_gizmo_set_color_highlight(wmGizmo *gz, const float color_hi[4]) void WM_gizmo_set_fn_custom_modal(struct wmGizmo *gz, wmGizmoFnModal fn) { - gz->custom_modal = fn; + gz->custom_modal = fn; } /** \} */ - /* -------------------------------------------------------------------- */ /** * Add/Remove \a gizmo to selection. @@ -408,66 +398,65 @@ void WM_gizmo_set_fn_custom_modal(struct wmGizmo *gz, wmGizmoFnModal fn) * \return if the selection has changed. */ bool wm_gizmo_select_set_ex( - wmGizmoMap *gzmap, wmGizmo *gz, bool select, - bool use_array, bool use_callback) -{ - bool changed = false; - - if (select) { - if ((gz->state & WM_GIZMO_STATE_SELECT) == 0) { - if (use_array) { - wm_gizmomap_select_array_push_back(gzmap, gz); - } - gz->state |= WM_GIZMO_STATE_SELECT; - changed = true; - } - } - else { - if (gz->state & WM_GIZMO_STATE_SELECT) { - if (use_array) { - wm_gizmomap_select_array_remove(gzmap, gz); - } - gz->state &= ~WM_GIZMO_STATE_SELECT; - changed = true; - } - } - - /* In the case of unlinking we only want to remove from the array - * and not write to the external state */ - if (use_callback && changed) { - if (gz->type->select_refresh) { - gz->type->select_refresh(gz); - } - } - - return changed; + wmGizmoMap *gzmap, wmGizmo *gz, bool select, bool use_array, bool use_callback) +{ + bool changed = false; + + if (select) { + if ((gz->state & WM_GIZMO_STATE_SELECT) == 0) { + if (use_array) { + wm_gizmomap_select_array_push_back(gzmap, gz); + } + gz->state |= WM_GIZMO_STATE_SELECT; + changed = true; + } + } + else { + if (gz->state & WM_GIZMO_STATE_SELECT) { + if (use_array) { + wm_gizmomap_select_array_remove(gzmap, gz); + } + gz->state &= ~WM_GIZMO_STATE_SELECT; + changed = true; + } + } + + /* In the case of unlinking we only want to remove from the array + * and not write to the external state */ + if (use_callback && changed) { + if (gz->type->select_refresh) { + gz->type->select_refresh(gz); + } + } + + return changed; } /* Remove from selection array without running callbacks. */ bool WM_gizmo_select_unlink(wmGizmoMap *gzmap, wmGizmo *gz) { - return wm_gizmo_select_set_ex(gzmap, gz, false, true, false); + return wm_gizmo_select_set_ex(gzmap, gz, false, true, false); } bool WM_gizmo_select_set(wmGizmoMap *gzmap, wmGizmo *gz, bool select) { - return wm_gizmo_select_set_ex(gzmap, gz, select, true, true); + return wm_gizmo_select_set_ex(gzmap, gz, select, true, true); } void WM_gizmo_highlight_set(wmGizmoMap *gzmap, wmGizmo *gz) { - wm_gizmomap_highlight_set(gzmap, NULL, gz, gz ? gz->highlight_part : 0); + wm_gizmomap_highlight_set(gzmap, NULL, gz, gz ? gz->highlight_part : 0); } bool wm_gizmo_select_and_highlight(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz) { - if (WM_gizmo_select_set(gzmap, gz, true)) { - wm_gizmomap_highlight_set(gzmap, C, gz, gz->highlight_part); - return true; - } - else { - return false; - } + if (WM_gizmo_select_set(gzmap, gz, true)) { + wm_gizmomap_highlight_set(gzmap, C, gz, gz->highlight_part); + return true; + } + else { + return false; + } } /** @@ -475,157 +464,157 @@ bool wm_gizmo_select_and_highlight(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz) * * We could do this when linking them, but this complicates things since the window update code needs to run first. */ -void WM_gizmo_modal_set_from_setup( - struct wmGizmoMap *gzmap, struct bContext *C, - struct wmGizmo *gz, int part_index, const wmEvent *event) -{ - gz->highlight_part = part_index; - WM_gizmo_highlight_set(gzmap, gz); - if (false) { - wm_gizmomap_modal_set(gzmap, C, gz, event, true); - } - else { - /* WEAK: but it works. */ - WM_operator_name_call(C, "GIZMOGROUP_OT_gizmo_tweak", WM_OP_INVOKE_DEFAULT, NULL); - } +void WM_gizmo_modal_set_from_setup(struct wmGizmoMap *gzmap, + struct bContext *C, + struct wmGizmo *gz, + int part_index, + const wmEvent *event) +{ + gz->highlight_part = part_index; + WM_gizmo_highlight_set(gzmap, gz); + if (false) { + wm_gizmomap_modal_set(gzmap, C, gz, event, true); + } + else { + /* WEAK: but it works. */ + WM_operator_name_call(C, "GIZMOGROUP_OT_gizmo_tweak", WM_OP_INVOKE_DEFAULT, NULL); + } } void wm_gizmo_calculate_scale(wmGizmo *gz, const bContext *C) { - const RegionView3D *rv3d = CTX_wm_region_view3d(C); - float scale = UI_DPI_FAC; - - if ((gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_SCALE) == 0) { - scale *= U.gizmo_size; - if (rv3d) { - /* 'ED_view3d_pixel_size' includes 'U.pixelsize', remove it. */ - float matrix_world[4][4]; - if (gz->type->matrix_basis_get) { - float matrix_basis[4][4]; - gz->type->matrix_basis_get(gz, matrix_basis); - mul_m4_m4m4(matrix_world, gz->matrix_space, matrix_basis); - } - else { - mul_m4_m4m4(matrix_world, gz->matrix_space, gz->matrix_basis); - } - - /* Exclude matrix_offset from scale. */ - scale *= ED_view3d_pixel_size_no_ui_scale(rv3d, matrix_world[3]); - } - else { - scale *= 0.02f; - } - } - - gz->scale_final = gz->scale_basis * scale; + const RegionView3D *rv3d = CTX_wm_region_view3d(C); + float scale = UI_DPI_FAC; + + if ((gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_SCALE) == 0) { + scale *= U.gizmo_size; + if (rv3d) { + /* 'ED_view3d_pixel_size' includes 'U.pixelsize', remove it. */ + float matrix_world[4][4]; + if (gz->type->matrix_basis_get) { + float matrix_basis[4][4]; + gz->type->matrix_basis_get(gz, matrix_basis); + mul_m4_m4m4(matrix_world, gz->matrix_space, matrix_basis); + } + else { + mul_m4_m4m4(matrix_world, gz->matrix_space, gz->matrix_basis); + } + + /* Exclude matrix_offset from scale. */ + scale *= ED_view3d_pixel_size_no_ui_scale(rv3d, matrix_world[3]); + } + else { + scale *= 0.02f; + } + } + + gz->scale_final = gz->scale_basis * scale; } static void gizmo_update_prop_data(wmGizmo *gz) { - /* gizmo property might have been changed, so update gizmo */ - if (gz->type->property_update) { - wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); - for (int i = 0; i < gz->type->target_property_defs_len; i++) { - wmGizmoProperty *gz_prop = &gz_prop_array[i]; - if (WM_gizmo_target_property_is_valid(gz_prop)) { - gz->type->property_update(gz, gz_prop); - } - } - } + /* gizmo property might have been changed, so update gizmo */ + if (gz->type->property_update) { + wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); + for (int i = 0; i < gz->type->target_property_defs_len; i++) { + wmGizmoProperty *gz_prop = &gz_prop_array[i]; + if (WM_gizmo_target_property_is_valid(gz_prop)) { + gz->type->property_update(gz, gz_prop); + } + } + } } void wm_gizmo_update(wmGizmo *gz, const bContext *C, const bool refresh_map) { - if (refresh_map) { - gizmo_update_prop_data(gz); - } - wm_gizmo_calculate_scale(gz, C); + if (refresh_map) { + gizmo_update_prop_data(gz); + } + wm_gizmo_calculate_scale(gz, C); } int wm_gizmo_is_visible(wmGizmo *gz) { - if (gz->flag & WM_GIZMO_HIDDEN) { - return 0; - } - if ((gz->state & WM_GIZMO_STATE_MODAL) && - !(gz->flag & (WM_GIZMO_DRAW_MODAL | WM_GIZMO_DRAW_VALUE))) - { - /* don't draw while modal (dragging) */ - return 0; - } - if ((gz->flag & WM_GIZMO_DRAW_HOVER) && - !(gz->state & WM_GIZMO_STATE_HIGHLIGHT) && - !(gz->state & WM_GIZMO_STATE_SELECT)) /* still draw selected gizmos */ - { - /* update but don't draw */ - return WM_GIZMO_IS_VISIBLE_UPDATE; - } - - return WM_GIZMO_IS_VISIBLE_UPDATE | WM_GIZMO_IS_VISIBLE_DRAW; -} - -void WM_gizmo_calc_matrix_final_params( - const wmGizmo *gz, - const struct WM_GizmoMatrixParams *params, - float r_mat[4][4]) -{ - const float (* const matrix_space)[4] = params->matrix_space ? params->matrix_space : gz->matrix_space; - const float (* const matrix_basis)[4] = params->matrix_basis ? params->matrix_basis : gz->matrix_basis; - const float (* const matrix_offset)[4] = params->matrix_offset ? params->matrix_offset : gz->matrix_offset; - const float *scale_final = params->scale_final ? params->scale_final : &gz->scale_final; - - float final_matrix[4][4]; - if (params->matrix_basis == NULL && gz->type->matrix_basis_get) { - gz->type->matrix_basis_get(gz, final_matrix); - } - else { - copy_m4_m4(final_matrix, matrix_basis); - } - - if (gz->flag & WM_GIZMO_DRAW_NO_SCALE) { - mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); - } - else { - if (gz->flag & WM_GIZMO_DRAW_OFFSET_SCALE) { - mul_mat3_m4_fl(final_matrix, *scale_final); - mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); - } - else { - mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); - mul_mat3_m4_fl(final_matrix, *scale_final); - } - } - - mul_m4_m4m4(r_mat, matrix_space, final_matrix); + if (gz->flag & WM_GIZMO_HIDDEN) { + return 0; + } + if ((gz->state & WM_GIZMO_STATE_MODAL) && + !(gz->flag & (WM_GIZMO_DRAW_MODAL | WM_GIZMO_DRAW_VALUE))) { + /* don't draw while modal (dragging) */ + return 0; + } + if ((gz->flag & WM_GIZMO_DRAW_HOVER) && !(gz->state & WM_GIZMO_STATE_HIGHLIGHT) && + !(gz->state & WM_GIZMO_STATE_SELECT)) /* still draw selected gizmos */ + { + /* update but don't draw */ + return WM_GIZMO_IS_VISIBLE_UPDATE; + } + + return WM_GIZMO_IS_VISIBLE_UPDATE | WM_GIZMO_IS_VISIBLE_DRAW; +} + +void WM_gizmo_calc_matrix_final_params(const wmGizmo *gz, + const struct WM_GizmoMatrixParams *params, + float r_mat[4][4]) +{ + const float(*const matrix_space)[4] = params->matrix_space ? params->matrix_space : + gz->matrix_space; + const float(*const matrix_basis)[4] = params->matrix_basis ? params->matrix_basis : + gz->matrix_basis; + const float(*const matrix_offset)[4] = params->matrix_offset ? params->matrix_offset : + gz->matrix_offset; + const float *scale_final = params->scale_final ? params->scale_final : &gz->scale_final; + + float final_matrix[4][4]; + if (params->matrix_basis == NULL && gz->type->matrix_basis_get) { + gz->type->matrix_basis_get(gz, final_matrix); + } + else { + copy_m4_m4(final_matrix, matrix_basis); + } + + if (gz->flag & WM_GIZMO_DRAW_NO_SCALE) { + mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); + } + else { + if (gz->flag & WM_GIZMO_DRAW_OFFSET_SCALE) { + mul_mat3_m4_fl(final_matrix, *scale_final); + mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); + } + else { + mul_m4_m4m4(final_matrix, final_matrix, matrix_offset); + mul_mat3_m4_fl(final_matrix, *scale_final); + } + } + + mul_m4_m4m4(r_mat, matrix_space, final_matrix); } void WM_gizmo_calc_matrix_final_no_offset(const wmGizmo *gz, float r_mat[4][4]) { - float mat_identity[4][4]; - unit_m4(mat_identity); + float mat_identity[4][4]; + unit_m4(mat_identity); - WM_gizmo_calc_matrix_final_params( - gz, - &((struct WM_GizmoMatrixParams) { - .matrix_space = NULL, - .matrix_basis = NULL, - .matrix_offset = mat_identity, - .scale_final = NULL, - }), r_mat - ); + WM_gizmo_calc_matrix_final_params(gz, + &((struct WM_GizmoMatrixParams){ + .matrix_space = NULL, + .matrix_basis = NULL, + .matrix_offset = mat_identity, + .scale_final = NULL, + }), + r_mat); } void WM_gizmo_calc_matrix_final(const wmGizmo *gz, float r_mat[4][4]) { - WM_gizmo_calc_matrix_final_params( - gz, - &((struct WM_GizmoMatrixParams) { - .matrix_space = NULL, - .matrix_basis = NULL, - .matrix_offset = NULL, - .scale_final = NULL, - }), r_mat - ); + WM_gizmo_calc_matrix_final_params(gz, + &((struct WM_GizmoMatrixParams){ + .matrix_space = NULL, + .matrix_basis = NULL, + .matrix_offset = NULL, + .scale_final = NULL, + }), + r_mat); } /** \name Gizmo Property Access @@ -634,74 +623,69 @@ void WM_gizmo_calc_matrix_final(const wmGizmo *gz, float r_mat[4][4]) * * \{ */ - void WM_gizmo_properties_create_ptr(PointerRNA *ptr, wmGizmoType *gzt) { - RNA_pointer_create(NULL, gzt->srna, NULL, ptr); + RNA_pointer_create(NULL, gzt->srna, NULL, ptr); } void WM_gizmo_properties_create(PointerRNA *ptr, const char *gtstring) { - const wmGizmoType *gzt = WM_gizmotype_find(gtstring, false); + const wmGizmoType *gzt = WM_gizmotype_find(gtstring, false); - if (gzt) { - WM_gizmo_properties_create_ptr(ptr, (wmGizmoType *)gzt); - } - else { - RNA_pointer_create(NULL, &RNA_GizmoProperties, NULL, ptr); - } + if (gzt) { + WM_gizmo_properties_create_ptr(ptr, (wmGizmoType *)gzt); + } + else { + RNA_pointer_create(NULL, &RNA_GizmoProperties, NULL, ptr); + } } /* similar to the function above except its uses ID properties * used for keymaps and macros */ void WM_gizmo_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *gtstring) { - if (*properties == NULL) { - IDPropertyTemplate val = {0}; - *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); - } + if (*properties == NULL) { + IDPropertyTemplate val = {0}; + *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); + } - if (*ptr == NULL) { - *ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr"); - WM_gizmo_properties_create(*ptr, gtstring); - } - - (*ptr)->data = *properties; + if (*ptr == NULL) { + *ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr"); + WM_gizmo_properties_create(*ptr, gtstring); + } + (*ptr)->data = *properties; } void WM_gizmo_properties_sanitize(PointerRNA *ptr, const bool no_context) { - RNA_STRUCT_BEGIN (ptr, prop) - { - switch (RNA_property_type(prop)) { - case PROP_ENUM: - if (no_context) { - RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT); - } - else { - RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT); - } - break; - case PROP_POINTER: - { - StructRNA *ptype = RNA_property_pointer_type(ptr, prop); - - /* recurse into gizmo properties */ - if (RNA_struct_is_a(ptype, &RNA_GizmoProperties)) { - PointerRNA opptr = RNA_property_pointer_get(ptr, prop); - WM_gizmo_properties_sanitize(&opptr, no_context); - } - break; - } - default: - break; - } - } - RNA_STRUCT_END; + RNA_STRUCT_BEGIN (ptr, prop) { + switch (RNA_property_type(prop)) { + case PROP_ENUM: + if (no_context) { + RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT); + } + else { + RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT); + } + break; + case PROP_POINTER: { + StructRNA *ptype = RNA_property_pointer_type(ptr, prop); + + /* recurse into gizmo properties */ + if (RNA_struct_is_a(ptype, &RNA_GizmoProperties)) { + PointerRNA opptr = RNA_property_pointer_get(ptr, prop); + WM_gizmo_properties_sanitize(&opptr, no_context); + } + break; + } + default: + break; + } + } + RNA_STRUCT_END; } - /** set all props to their default, * \param do_update: Only update un-initialized props. * @@ -710,71 +694,68 @@ void WM_gizmo_properties_sanitize(PointerRNA *ptr, const bool no_context) */ bool WM_gizmo_properties_default(PointerRNA *ptr, const bool do_update) { - bool changed = false; - RNA_STRUCT_BEGIN (ptr, prop) - { - switch (RNA_property_type(prop)) { - case PROP_POINTER: - { - StructRNA *ptype = RNA_property_pointer_type(ptr, prop); - if (ptype != &RNA_Struct) { - PointerRNA opptr = RNA_property_pointer_get(ptr, prop); - changed |= WM_gizmo_properties_default(&opptr, do_update); - } - break; - } - default: - if ((do_update == false) || (RNA_property_is_set(ptr, prop) == false)) { - if (RNA_property_reset(ptr, prop, -1)) { - changed = true; - } - } - break; - } - } - RNA_STRUCT_END; - - return changed; + bool changed = false; + RNA_STRUCT_BEGIN (ptr, prop) { + switch (RNA_property_type(prop)) { + case PROP_POINTER: { + StructRNA *ptype = RNA_property_pointer_type(ptr, prop); + if (ptype != &RNA_Struct) { + PointerRNA opptr = RNA_property_pointer_get(ptr, prop); + changed |= WM_gizmo_properties_default(&opptr, do_update); + } + break; + } + default: + if ((do_update == false) || (RNA_property_is_set(ptr, prop) == false)) { + if (RNA_property_reset(ptr, prop, -1)) { + changed = true; + } + } + break; + } + } + RNA_STRUCT_END; + + return changed; } /* remove all props without PROP_SKIP_SAVE */ void WM_gizmo_properties_reset(wmGizmo *gz) { - if (gz->ptr->data) { - PropertyRNA *iterprop; - iterprop = RNA_struct_iterator_property(gz->type->srna); + if (gz->ptr->data) { + PropertyRNA *iterprop; + iterprop = RNA_struct_iterator_property(gz->type->srna); - RNA_PROP_BEGIN (gz->ptr, itemptr, iterprop) - { - PropertyRNA *prop = itemptr.data; + RNA_PROP_BEGIN (gz->ptr, itemptr, iterprop) { + PropertyRNA *prop = itemptr.data; - if ((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) { - const char *identifier = RNA_property_identifier(prop); - RNA_struct_idprops_unset(gz->ptr, identifier); - } - } - RNA_PROP_END; - } + if ((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) { + const char *identifier = RNA_property_identifier(prop); + RNA_struct_idprops_unset(gz->ptr, identifier); + } + } + RNA_PROP_END; + } } void WM_gizmo_properties_clear(PointerRNA *ptr) { - IDProperty *properties = ptr->data; + IDProperty *properties = ptr->data; - if (properties) { - IDP_ClearProperty(properties); - } + if (properties) { + IDP_ClearProperty(properties); + } } void WM_gizmo_properties_free(PointerRNA *ptr) { - IDProperty *properties = ptr->data; + IDProperty *properties = ptr->data; - if (properties) { - IDP_FreeProperty(properties); - MEM_freeN(properties); - ptr->data = NULL; /* just in case */ - } + if (properties) { + IDP_FreeProperty(properties); + MEM_freeN(properties); + ptr->data = NULL; /* just in case */ + } } /** \} */ @@ -785,21 +766,19 @@ void WM_gizmo_properties_free(PointerRNA *ptr) bool WM_gizmo_context_check_drawstep(const struct bContext *C, eWM_GizmoFlagMapDrawStep step) { - switch (step) { - case WM_GIZMOMAP_DRAWSTEP_2D: - { - break; - } - case WM_GIZMOMAP_DRAWSTEP_3D: - { - wmWindowManager *wm = CTX_wm_manager(C); - if (ED_screen_animation_playing(wm)) { - return false; - } - break; - } - } - return true; + switch (step) { + case WM_GIZMOMAP_DRAWSTEP_2D: { + break; + } + case WM_GIZMOMAP_DRAWSTEP_3D: { + wmWindowManager *wm = CTX_wm_manager(C); + if (ED_screen_animation_playing(wm)) { + return false; + } + break; + } + } + return true; } /** \} */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index ae264480751..b37991ec8cd 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -70,65 +70,65 @@ /** * Create a new gizmo-group from \a gzgt. */ -wmGizmoGroup *wm_gizmogroup_new_from_type( - wmGizmoMap *gzmap, wmGizmoGroupType *gzgt) +wmGizmoGroup *wm_gizmogroup_new_from_type(wmGizmoMap *gzmap, wmGizmoGroupType *gzgt) { - wmGizmoGroup *gzgroup = MEM_callocN(sizeof(*gzgroup), "gizmo-group"); - gzgroup->type = gzgt; + wmGizmoGroup *gzgroup = MEM_callocN(sizeof(*gzgroup), "gizmo-group"); + gzgroup->type = gzgt; - /* keep back-link */ - gzgroup->parent_gzmap = gzmap; + /* keep back-link */ + gzgroup->parent_gzmap = gzmap; - BLI_addtail(&gzmap->groups, gzgroup); + BLI_addtail(&gzmap->groups, gzgroup); - return gzgroup; + return gzgroup; } void wm_gizmogroup_free(bContext *C, wmGizmoGroup *gzgroup) { - wmGizmoMap *gzmap = gzgroup->parent_gzmap; - - /* Similar to WM_gizmo_unlink, but only to keep gzmap state correct, - * we don't want to run callbacks. */ - if (gzmap->gzmap_context.highlight && gzmap->gzmap_context.highlight->parent_gzgroup == gzgroup) { - wm_gizmomap_highlight_set(gzmap, C, NULL, 0); - } - if (gzmap->gzmap_context.modal && gzmap->gzmap_context.modal->parent_gzgroup == gzgroup) { - wm_gizmomap_modal_set(gzmap, C, gzmap->gzmap_context.modal, NULL, false); - } - - for (wmGizmo *gz = gzgroup->gizmos.first, *gz_next; gz; gz = gz_next) { - gz_next = gz->next; - if (gzmap->gzmap_context.select.len) { - WM_gizmo_select_unlink(gzmap, gz); - } - WM_gizmo_free(gz); - } - BLI_listbase_clear(&gzgroup->gizmos); + wmGizmoMap *gzmap = gzgroup->parent_gzmap; + + /* Similar to WM_gizmo_unlink, but only to keep gzmap state correct, + * we don't want to run callbacks. */ + if (gzmap->gzmap_context.highlight && + gzmap->gzmap_context.highlight->parent_gzgroup == gzgroup) { + wm_gizmomap_highlight_set(gzmap, C, NULL, 0); + } + if (gzmap->gzmap_context.modal && gzmap->gzmap_context.modal->parent_gzgroup == gzgroup) { + wm_gizmomap_modal_set(gzmap, C, gzmap->gzmap_context.modal, NULL, false); + } + + for (wmGizmo *gz = gzgroup->gizmos.first, *gz_next; gz; gz = gz_next) { + gz_next = gz->next; + if (gzmap->gzmap_context.select.len) { + WM_gizmo_select_unlink(gzmap, gz); + } + WM_gizmo_free(gz); + } + BLI_listbase_clear(&gzgroup->gizmos); #ifdef WITH_PYTHON - if (gzgroup->py_instance) { - /* do this first in case there are any __del__ functions or - * similar that use properties */ - BPY_DECREF_RNA_INVALIDATE(gzgroup->py_instance); - } + if (gzgroup->py_instance) { + /* do this first in case there are any __del__ functions or + * similar that use properties */ + BPY_DECREF_RNA_INVALIDATE(gzgroup->py_instance); + } #endif - if (gzgroup->reports && (gzgroup->reports->flag & RPT_FREE)) { - BKE_reports_clear(gzgroup->reports); - MEM_freeN(gzgroup->reports); - } + if (gzgroup->reports && (gzgroup->reports->flag & RPT_FREE)) { + BKE_reports_clear(gzgroup->reports); + MEM_freeN(gzgroup->reports); + } - if (gzgroup->customdata_free) { - gzgroup->customdata_free(gzgroup->customdata); - } - else { - MEM_SAFE_FREE(gzgroup->customdata); - } + if (gzgroup->customdata_free) { + gzgroup->customdata_free(gzgroup->customdata); + } + else { + MEM_SAFE_FREE(gzgroup->customdata); + } - BLI_remlink(&gzmap->groups, gzgroup); + BLI_remlink(&gzmap->groups, gzgroup); - MEM_freeN(gzgroup); + MEM_freeN(gzgroup); } /** @@ -136,42 +136,55 @@ void wm_gizmogroup_free(bContext *C, wmGizmoGroup *gzgroup) */ void wm_gizmogroup_gizmo_register(wmGizmoGroup *gzgroup, wmGizmo *gz) { - BLI_assert(BLI_findindex(&gzgroup->gizmos, gz) == -1); - BLI_addtail(&gzgroup->gizmos, gz); - gz->parent_gzgroup = gzgroup; + BLI_assert(BLI_findindex(&gzgroup->gizmos, gz) == -1); + BLI_addtail(&gzgroup->gizmos, gz); + gz->parent_gzgroup = gzgroup; } int WM_gizmo_cmp_temp_fl(const void *gz_a_ptr, const void *gz_b_ptr) { - const wmGizmo *gz_a = gz_a_ptr; - const wmGizmo *gz_b = gz_b_ptr; - if (gz_a->temp.f < gz_b->temp.f) { return -1; } - else if (gz_a->temp.f > gz_b->temp.f) { return 1; } - else { return 0; } + const wmGizmo *gz_a = gz_a_ptr; + const wmGizmo *gz_b = gz_b_ptr; + if (gz_a->temp.f < gz_b->temp.f) { + return -1; + } + else if (gz_a->temp.f > gz_b->temp.f) { + return 1; + } + else { + return 0; + } } int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) { - const wmGizmo *gz_a = gz_a_ptr; - const wmGizmo *gz_b = gz_b_ptr; - if (gz_a->temp.f < gz_b->temp.f) { return 1; } - else if (gz_a->temp.f > gz_b->temp.f) { return -1; } - else { return 0; } + const wmGizmo *gz_a = gz_a_ptr; + const wmGizmo *gz_b = gz_b_ptr; + if (gz_a->temp.f < gz_b->temp.f) { + return 1; + } + else if (gz_a->temp.f > gz_b->temp.f) { + return -1; + } + else { + return 0; + } } -wmGizmo *wm_gizmogroup_find_intersected_gizmo( - const wmGizmoGroup *gzgroup, bContext *C, const wmEvent *event, - int *r_part) +wmGizmo *wm_gizmogroup_find_intersected_gizmo(const wmGizmoGroup *gzgroup, + bContext *C, + const wmEvent *event, + int *r_part) { - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - if (gz->type->test_select && (gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) { - if ((*r_part = gz->type->test_select(C, gz, event->mval)) != -1) { - return gz; - } - } - } + for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + if (gz->type->test_select && (gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) { + if ((*r_part = gz->type->test_select(C, gz, event->mval)) != -1) { + return gz; + } + } + } - return NULL; + return NULL; } /** @@ -179,79 +192,79 @@ wmGizmo *wm_gizmogroup_find_intersected_gizmo( */ void wm_gizmogroup_intersectable_gizmos_to_list(const wmGizmoGroup *gzgroup, ListBase *listbase) { - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - if ((gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) { - if (((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) && (gz->type->draw_select || gz->type->test_select)) || - ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0 && gz->type->test_select)) - { - BLI_addhead(listbase, BLI_genericNodeN(gz)); - } - } - } + for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + if ((gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) { + if (((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) && + (gz->type->draw_select || gz->type->test_select)) || + ((gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0 && gz->type->test_select)) { + BLI_addhead(listbase, BLI_genericNodeN(gz)); + } + } + } } void WM_gizmogroup_ensure_init(const bContext *C, wmGizmoGroup *gzgroup) { - /* prepare for first draw */ - if (UNLIKELY((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0)) { - gzgroup->type->setup(C, gzgroup); - - /* Not ideal, initialize keymap here, needed for RNA runtime generated gizmos. */ - wmGizmoGroupType *gzgt = gzgroup->type; - if (gzgt->keymap == NULL) { - wmWindowManager *wm = CTX_wm_manager(C); - wm_gizmogrouptype_setup_keymap(gzgt, wm->defaultconf); - BLI_assert(gzgt->keymap != NULL); - } - gzgroup->init_flag |= WM_GIZMOGROUP_INIT_SETUP; - } - - /* refresh may be called multiple times, this just ensures its called at least once before we draw. */ - if (UNLIKELY((gzgroup->init_flag & WM_GIZMOGROUP_INIT_REFRESH) == 0)) { - if (gzgroup->type->refresh) { - gzgroup->type->refresh(C, gzgroup); - } - gzgroup->init_flag |= WM_GIZMOGROUP_INIT_REFRESH; - } + /* prepare for first draw */ + if (UNLIKELY((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0)) { + gzgroup->type->setup(C, gzgroup); + + /* Not ideal, initialize keymap here, needed for RNA runtime generated gizmos. */ + wmGizmoGroupType *gzgt = gzgroup->type; + if (gzgt->keymap == NULL) { + wmWindowManager *wm = CTX_wm_manager(C); + wm_gizmogrouptype_setup_keymap(gzgt, wm->defaultconf); + BLI_assert(gzgt->keymap != NULL); + } + gzgroup->init_flag |= WM_GIZMOGROUP_INIT_SETUP; + } + + /* refresh may be called multiple times, this just ensures its called at least once before we draw. */ + if (UNLIKELY((gzgroup->init_flag & WM_GIZMOGROUP_INIT_REFRESH) == 0)) { + if (gzgroup->type->refresh) { + gzgroup->type->refresh(C, gzgroup); + } + gzgroup->init_flag |= WM_GIZMOGROUP_INIT_REFRESH; + } } bool WM_gizmo_group_type_poll(const bContext *C, const struct wmGizmoGroupType *gzgt) { - /* If we're tagged, only use compatible. */ - if (gzgt->owner_id[0] != '\0') { - const WorkSpace *workspace = CTX_wm_workspace(C); - if (BKE_workspace_owner_id_check(workspace, gzgt->owner_id) == false) { - return false; - } - } - /* Check for poll function, if gizmo-group belongs to an operator, also check if the operator is running. */ - return (!gzgt->poll || gzgt->poll(C, (wmGizmoGroupType *)gzgt)); + /* If we're tagged, only use compatible. */ + if (gzgt->owner_id[0] != '\0') { + const WorkSpace *workspace = CTX_wm_workspace(C); + if (BKE_workspace_owner_id_check(workspace, gzgt->owner_id) == false) { + return false; + } + } + /* Check for poll function, if gizmo-group belongs to an operator, also check if the operator is running. */ + return (!gzgt->poll || gzgt->poll(C, (wmGizmoGroupType *)gzgt)); } -bool wm_gizmogroup_is_visible_in_drawstep( - const wmGizmoGroup *gzgroup, const eWM_GizmoFlagMapDrawStep drawstep) +bool wm_gizmogroup_is_visible_in_drawstep(const wmGizmoGroup *gzgroup, + const eWM_GizmoFlagMapDrawStep drawstep) { - switch (drawstep) { - case WM_GIZMOMAP_DRAWSTEP_2D: - return (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0; - case WM_GIZMOMAP_DRAWSTEP_3D: - return (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D); - default: - BLI_assert(0); - return false; - } + switch (drawstep) { + case WM_GIZMOMAP_DRAWSTEP_2D: + return (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) == 0; + case WM_GIZMOMAP_DRAWSTEP_3D: + return (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D); + default: + BLI_assert(0); + return false; + } } bool wm_gizmogroup_is_any_selected(const wmGizmoGroup *gzgroup) { - if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_SELECT) { - for (const wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - if (gz->state & WM_GIZMO_STATE_SELECT) { - return true; - } - } - } - return false; + if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_SELECT) { + for (const wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + if (gz->state & WM_GIZMO_STATE_SELECT) { + return true; + } + } + } + return false; } /** \} */ @@ -264,455 +277,452 @@ bool wm_gizmogroup_is_any_selected(const wmGizmoGroup *gzgroup) static int gizmo_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - ARegion *ar = CTX_wm_region(C); - wmGizmoMap *gzmap = ar->gizmo_map; - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - wmGizmo *highlight = gzmap->gzmap_context.highlight; - - bool extend = RNA_boolean_get(op->ptr, "extend"); - bool deselect = RNA_boolean_get(op->ptr, "deselect"); - bool toggle = RNA_boolean_get(op->ptr, "toggle"); - - /* deselect all first */ - if (extend == false && deselect == false && toggle == false) { - wm_gizmomap_deselect_all(gzmap); - BLI_assert(msel->items == NULL && msel->len == 0); - UNUSED_VARS_NDEBUG(msel); - } - - if (highlight) { - const bool is_selected = (highlight->state & WM_GIZMO_STATE_SELECT); - bool redraw = false; - - if (toggle) { - /* toggle: deselect if already selected, else select */ - deselect = is_selected; - } - - if (deselect) { - if (is_selected && WM_gizmo_select_set(gzmap, highlight, false)) { - redraw = true; - } - } - else if (wm_gizmo_select_and_highlight(C, gzmap, highlight)) { - redraw = true; - } - - if (redraw) { - ED_region_tag_redraw(ar); - } - - return OPERATOR_FINISHED; - } - else { - BLI_assert(0); - return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); - } + ARegion *ar = CTX_wm_region(C); + wmGizmoMap *gzmap = ar->gizmo_map; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + wmGizmo *highlight = gzmap->gzmap_context.highlight; + + bool extend = RNA_boolean_get(op->ptr, "extend"); + bool deselect = RNA_boolean_get(op->ptr, "deselect"); + bool toggle = RNA_boolean_get(op->ptr, "toggle"); + + /* deselect all first */ + if (extend == false && deselect == false && toggle == false) { + wm_gizmomap_deselect_all(gzmap); + BLI_assert(msel->items == NULL && msel->len == 0); + UNUSED_VARS_NDEBUG(msel); + } + + if (highlight) { + const bool is_selected = (highlight->state & WM_GIZMO_STATE_SELECT); + bool redraw = false; + + if (toggle) { + /* toggle: deselect if already selected, else select */ + deselect = is_selected; + } + + if (deselect) { + if (is_selected && WM_gizmo_select_set(gzmap, highlight, false)) { + redraw = true; + } + } + else if (wm_gizmo_select_and_highlight(C, gzmap, highlight)) { + redraw = true; + } + + if (redraw) { + ED_region_tag_redraw(ar); + } + + return OPERATOR_FINISHED; + } + else { + BLI_assert(0); + return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); + } } void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Gizmo Select"; - ot->description = "Select the currently highlighted gizmo"; - ot->idname = "GIZMOGROUP_OT_gizmo_select"; + /* identifiers */ + ot->name = "Gizmo Select"; + ot->description = "Select the currently highlighted gizmo"; + ot->idname = "GIZMOGROUP_OT_gizmo_select"; - /* api callbacks */ - ot->invoke = gizmo_select_invoke; + /* api callbacks */ + ot->invoke = gizmo_select_invoke; - ot->flag = OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; - WM_operator_properties_mouse_select(ot); + WM_operator_properties_mouse_select(ot); } typedef struct GizmoTweakData { - wmGizmoMap *gzmap; - wmGizmoGroup *gzgroup; - wmGizmo *gz_modal; + wmGizmoMap *gzmap; + wmGizmoGroup *gzgroup; + wmGizmo *gz_modal; - int init_event; /* initial event type */ - int flag; /* tweak flags */ + int init_event; /* initial event type */ + int flag; /* tweak flags */ #ifdef USE_DRAG_DETECT - /* True until the mouse is moved (only use when the operator has no modal). - * this allows some gizmos to be click-only. */ - enum { - /* Don't detect dragging. */ - DRAG_NOP = 0, - /* Detect dragging (wait until a drag or click is detected). */ - DRAG_DETECT, - /* Drag has started, idle until there is no active modal operator. - * This is needed because finishing the modal operator also exits - * the modal gizmo state (un-grabbs the cursor). - * Ideally this workaround could be removed later. */ - DRAG_IDLE, - } drag_state; + /* True until the mouse is moved (only use when the operator has no modal). + * this allows some gizmos to be click-only. */ + enum { + /* Don't detect dragging. */ + DRAG_NOP = 0, + /* Detect dragging (wait until a drag or click is detected). */ + DRAG_DETECT, + /* Drag has started, idle until there is no active modal operator. + * This is needed because finishing the modal operator also exits + * the modal gizmo state (un-grabbs the cursor). + * Ideally this workaround could be removed later. */ + DRAG_IDLE, + } drag_state; #endif } GizmoTweakData; -static bool gizmo_tweak_start( - bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event) +static bool gizmo_tweak_start(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event) { - /* activate highlighted gizmo */ - wm_gizmomap_modal_set(gzmap, C, gz, event, true); + /* activate highlighted gizmo */ + wm_gizmomap_modal_set(gzmap, C, gz, event, true); - return (gz->state & WM_GIZMO_STATE_MODAL); + return (gz->state & WM_GIZMO_STATE_MODAL); } static bool gizmo_tweak_start_and_finish( - bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event, bool *r_is_modal) + bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event, bool *r_is_modal) { - wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); - if (r_is_modal) { - *r_is_modal = false; - } - if (gzop && gzop->type) { + wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); + if (r_is_modal) { + *r_is_modal = false; + } + if (gzop && gzop->type) { - /* Undo/Redo */ - if (gzop->is_redo) { - wmWindowManager *wm = CTX_wm_manager(C); - wmOperator *op = WM_operator_last_redo(C); + /* Undo/Redo */ + if (gzop->is_redo) { + wmWindowManager *wm = CTX_wm_manager(C); + wmOperator *op = WM_operator_last_redo(C); - /* We may want to enable this, for now the gizmo can manage it's own properties. */ + /* We may want to enable this, for now the gizmo can manage it's own properties. */ #if 0 - IDP_MergeGroup(gzop->ptr.data, op->properties, false); + IDP_MergeGroup(gzop->ptr.data, op->properties, false); #endif - WM_operator_free_all_after(wm, op); - ED_undo_pop_op(C, op); - } - - /* XXX temporary workaround for modal gizmo operator - * conflicting with modal operator attached to gizmo */ - if (gzop->type->modal) { - /* activate highlighted gizmo */ - wm_gizmomap_modal_set(gzmap, C, gz, event, true); - if (r_is_modal) { - *r_is_modal = true; - } - } - else { - if (gz->parent_gzgroup->type->invoke_prepare) { - gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); - } - /* Allow for 'button' gizmos, single click to run an action. */ - WM_gizmo_operator_invoke(C, gz, gzop); - } - return true; - } - else { - return false; - } + WM_operator_free_all_after(wm, op); + ED_undo_pop_op(C, op); + } + + /* XXX temporary workaround for modal gizmo operator + * conflicting with modal operator attached to gizmo */ + if (gzop->type->modal) { + /* activate highlighted gizmo */ + wm_gizmomap_modal_set(gzmap, C, gz, event, true); + if (r_is_modal) { + *r_is_modal = true; + } + } + else { + if (gz->parent_gzgroup->type->invoke_prepare) { + gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); + } + /* Allow for 'button' gizmos, single click to run an action. */ + WM_gizmo_operator_invoke(C, gz, gzop); + } + return true; + } + else { + return false; + } } static void gizmo_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal) { - GizmoTweakData *mtweak = op->customdata; - if (mtweak->gz_modal->type->exit) { - mtweak->gz_modal->type->exit(C, mtweak->gz_modal, cancel); - } - if (clear_modal) { - /* The gizmo may have been removed. */ - if ((BLI_findindex(&mtweak->gzmap->groups, mtweak->gzgroup) != -1) && - (BLI_findindex(&mtweak->gzgroup->gizmos, mtweak->gz_modal) != -1)) - { - wm_gizmomap_modal_set(mtweak->gzmap, C, mtweak->gz_modal, NULL, false); - } - } - MEM_freeN(mtweak); + GizmoTweakData *mtweak = op->customdata; + if (mtweak->gz_modal->type->exit) { + mtweak->gz_modal->type->exit(C, mtweak->gz_modal, cancel); + } + if (clear_modal) { + /* The gizmo may have been removed. */ + if ((BLI_findindex(&mtweak->gzmap->groups, mtweak->gzgroup) != -1) && + (BLI_findindex(&mtweak->gzgroup->gizmos, mtweak->gz_modal) != -1)) { + wm_gizmomap_modal_set(mtweak->gzmap, C, mtweak->gz_modal, NULL, false); + } + } + MEM_freeN(mtweak); } static int gizmo_tweak_modal(bContext *C, wmOperator *op, const wmEvent *event) { - GizmoTweakData *mtweak = op->customdata; - wmGizmo *gz = mtweak->gz_modal; - int retval = OPERATOR_PASS_THROUGH; - bool clear_modal = true; + GizmoTweakData *mtweak = op->customdata; + wmGizmo *gz = mtweak->gz_modal; + int retval = OPERATOR_PASS_THROUGH; + bool clear_modal = true; - if (gz == NULL) { - BLI_assert(0); - return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); - } + if (gz == NULL) { + BLI_assert(0); + return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); + } #ifdef USE_DRAG_DETECT - wmGizmoMap *gzmap = mtweak->gzmap; - if (mtweak->drag_state == DRAG_DETECT) { - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { - if (len_manhattan_v2v2_int(&event->x, gzmap->gzmap_context.event_xy) >= WM_EVENT_CURSOR_CLICK_DRAG_THRESHOLD) { - mtweak->drag_state = DRAG_IDLE; - gz->highlight_part = gz->drag_part; - } - } - else if (event->type == mtweak->init_event && event->val == KM_RELEASE) { - mtweak->drag_state = DRAG_NOP; - retval = OPERATOR_FINISHED; - } - - if (mtweak->drag_state != DRAG_DETECT) { - /* Follow logic in 'gizmo_tweak_invoke' */ - bool is_modal = false; - if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, &is_modal)) { - if (is_modal) { - clear_modal = false; - } - } - else { - if (!gizmo_tweak_start(C, gzmap, gz, event)) { - retval = OPERATOR_FINISHED; - } - } - } - } - if (mtweak->drag_state == DRAG_IDLE) { - if (gzmap->gzmap_context.modal != NULL) { - return OPERATOR_PASS_THROUGH; - } - else { - gizmo_tweak_finish(C, op, false, false); - return OPERATOR_FINISHED; - } - } -#endif /* USE_DRAG_DETECT */ - - if (retval == OPERATOR_FINISHED) { - /* pass */ - } - else if (event->type == mtweak->init_event && event->val == KM_RELEASE) { - retval = OPERATOR_FINISHED; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case TWEAK_MODAL_CANCEL: - retval = OPERATOR_CANCELLED; - break; - case TWEAK_MODAL_CONFIRM: - retval = OPERATOR_FINISHED; - break; - case TWEAK_MODAL_PRECISION_ON: - mtweak->flag |= WM_GIZMO_TWEAK_PRECISE; - break; - case TWEAK_MODAL_PRECISION_OFF: - mtweak->flag &= ~WM_GIZMO_TWEAK_PRECISE; - break; - - case TWEAK_MODAL_SNAP_ON: - mtweak->flag |= WM_GIZMO_TWEAK_SNAP; - break; - case TWEAK_MODAL_SNAP_OFF: - mtweak->flag &= ~WM_GIZMO_TWEAK_SNAP; - break; - } - } - - if (retval != OPERATOR_PASS_THROUGH) { - gizmo_tweak_finish(C, op, retval != OPERATOR_FINISHED, clear_modal); - return retval; - } - - /* handle gizmo */ - wmGizmoFnModal modal_fn = gz->custom_modal ? gz->custom_modal : gz->type->modal; - if (modal_fn) { - int modal_retval = modal_fn(C, gz, event, mtweak->flag); - - if ((modal_retval & OPERATOR_RUNNING_MODAL) == 0) { - gizmo_tweak_finish(C, op, (modal_retval & OPERATOR_CANCELLED) != 0, true); - return OPERATOR_FINISHED; - } - - /* Ugly hack to send gizmo events */ - ((wmEvent *)event)->type = EVT_GIZMO_UPDATE; - } - - /* always return PASS_THROUGH so modal handlers - * with gizmos attached can update */ - BLI_assert(retval == OPERATOR_PASS_THROUGH); - return OPERATOR_PASS_THROUGH; + wmGizmoMap *gzmap = mtweak->gzmap; + if (mtweak->drag_state == DRAG_DETECT) { + if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (len_manhattan_v2v2_int(&event->x, gzmap->gzmap_context.event_xy) >= + WM_EVENT_CURSOR_CLICK_DRAG_THRESHOLD) { + mtweak->drag_state = DRAG_IDLE; + gz->highlight_part = gz->drag_part; + } + } + else if (event->type == mtweak->init_event && event->val == KM_RELEASE) { + mtweak->drag_state = DRAG_NOP; + retval = OPERATOR_FINISHED; + } + + if (mtweak->drag_state != DRAG_DETECT) { + /* Follow logic in 'gizmo_tweak_invoke' */ + bool is_modal = false; + if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, &is_modal)) { + if (is_modal) { + clear_modal = false; + } + } + else { + if (!gizmo_tweak_start(C, gzmap, gz, event)) { + retval = OPERATOR_FINISHED; + } + } + } + } + if (mtweak->drag_state == DRAG_IDLE) { + if (gzmap->gzmap_context.modal != NULL) { + return OPERATOR_PASS_THROUGH; + } + else { + gizmo_tweak_finish(C, op, false, false); + return OPERATOR_FINISHED; + } + } +#endif /* USE_DRAG_DETECT */ + + if (retval == OPERATOR_FINISHED) { + /* pass */ + } + else if (event->type == mtweak->init_event && event->val == KM_RELEASE) { + retval = OPERATOR_FINISHED; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case TWEAK_MODAL_CANCEL: + retval = OPERATOR_CANCELLED; + break; + case TWEAK_MODAL_CONFIRM: + retval = OPERATOR_FINISHED; + break; + case TWEAK_MODAL_PRECISION_ON: + mtweak->flag |= WM_GIZMO_TWEAK_PRECISE; + break; + case TWEAK_MODAL_PRECISION_OFF: + mtweak->flag &= ~WM_GIZMO_TWEAK_PRECISE; + break; + + case TWEAK_MODAL_SNAP_ON: + mtweak->flag |= WM_GIZMO_TWEAK_SNAP; + break; + case TWEAK_MODAL_SNAP_OFF: + mtweak->flag &= ~WM_GIZMO_TWEAK_SNAP; + break; + } + } + + if (retval != OPERATOR_PASS_THROUGH) { + gizmo_tweak_finish(C, op, retval != OPERATOR_FINISHED, clear_modal); + return retval; + } + + /* handle gizmo */ + wmGizmoFnModal modal_fn = gz->custom_modal ? gz->custom_modal : gz->type->modal; + if (modal_fn) { + int modal_retval = modal_fn(C, gz, event, mtweak->flag); + + if ((modal_retval & OPERATOR_RUNNING_MODAL) == 0) { + gizmo_tweak_finish(C, op, (modal_retval & OPERATOR_CANCELLED) != 0, true); + return OPERATOR_FINISHED; + } + + /* Ugly hack to send gizmo events */ + ((wmEvent *)event)->type = EVT_GIZMO_UPDATE; + } + + /* always return PASS_THROUGH so modal handlers + * with gizmos attached can update */ + BLI_assert(retval == OPERATOR_PASS_THROUGH); + return OPERATOR_PASS_THROUGH; } static int gizmo_tweak_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - ARegion *ar = CTX_wm_region(C); - wmGizmoMap *gzmap = ar->gizmo_map; - wmGizmo *gz = gzmap->gzmap_context.highlight; + ARegion *ar = CTX_wm_region(C); + wmGizmoMap *gzmap = ar->gizmo_map; + wmGizmo *gz = gzmap->gzmap_context.highlight; - /* Needed for single click actions which don't enter modal state. */ - WM_tooltip_clear(C, CTX_wm_window(C)); + /* Needed for single click actions which don't enter modal state. */ + WM_tooltip_clear(C, CTX_wm_window(C)); - if (!gz) { - /* wm_handlers_do_intern shouldn't let this happen */ - BLI_assert(0); - return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); - } + if (!gz) { + /* wm_handlers_do_intern shouldn't let this happen */ + BLI_assert(0); + return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); + } - bool use_drag_fallback = false; + bool use_drag_fallback = false; #ifdef USE_DRAG_DETECT - use_drag_fallback = !ELEM(gz->drag_part, -1, gz->highlight_part); + use_drag_fallback = !ELEM(gz->drag_part, -1, gz->highlight_part); #endif - if (use_drag_fallback == false) { - if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, NULL)) { - return OPERATOR_FINISHED; - } - } + if (use_drag_fallback == false) { + if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, NULL)) { + return OPERATOR_FINISHED; + } + } - bool use_drag_detect = false; + bool use_drag_detect = false; #ifdef USE_DRAG_DETECT - if (use_drag_fallback) { - wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); - if (gzop && gzop->type) { - if (gzop->type->modal == NULL) { - use_drag_detect = true; - } - } - } + if (use_drag_fallback) { + wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); + if (gzop && gzop->type) { + if (gzop->type->modal == NULL) { + use_drag_detect = true; + } + } + } #endif - if (use_drag_detect == false) { - if (!gizmo_tweak_start(C, gzmap, gz, event)) { - /* failed to start */ - return OPERATOR_PASS_THROUGH; - } - } + if (use_drag_detect == false) { + if (!gizmo_tweak_start(C, gzmap, gz, event)) { + /* failed to start */ + return OPERATOR_PASS_THROUGH; + } + } - GizmoTweakData *mtweak = MEM_mallocN(sizeof(GizmoTweakData), __func__); + GizmoTweakData *mtweak = MEM_mallocN(sizeof(GizmoTweakData), __func__); - mtweak->init_event = WM_userdef_event_type_from_keymap_type(event->type); - mtweak->gz_modal = gzmap->gzmap_context.highlight; - mtweak->gzgroup = mtweak->gz_modal->parent_gzgroup; - mtweak->gzmap = gzmap; - mtweak->flag = 0; + mtweak->init_event = WM_userdef_event_type_from_keymap_type(event->type); + mtweak->gz_modal = gzmap->gzmap_context.highlight; + mtweak->gzgroup = mtweak->gz_modal->parent_gzgroup; + mtweak->gzmap = gzmap; + mtweak->flag = 0; #ifdef USE_DRAG_DETECT - mtweak->drag_state = use_drag_detect ? DRAG_DETECT : DRAG_NOP; + mtweak->drag_state = use_drag_detect ? DRAG_DETECT : DRAG_NOP; #endif - op->customdata = mtweak; + op->customdata = mtweak; - WM_event_add_modal_handler(C, op); + WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; } void GIZMOGROUP_OT_gizmo_tweak(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Gizmo Tweak"; - ot->description = "Tweak the active gizmo"; - ot->idname = "GIZMOGROUP_OT_gizmo_tweak"; + /* identifiers */ + ot->name = "Gizmo Tweak"; + ot->description = "Tweak the active gizmo"; + ot->idname = "GIZMOGROUP_OT_gizmo_tweak"; - /* api callbacks */ - ot->invoke = gizmo_tweak_invoke; - ot->modal = gizmo_tweak_modal; + /* api callbacks */ + ot->invoke = gizmo_tweak_invoke; + ot->modal = gizmo_tweak_modal; - /* TODO(campbell) This causes problems tweaking settings for operators, - * need to find a way to support this. */ + /* TODO(campbell) This causes problems tweaking settings for operators, + * need to find a way to support this. */ #if 0 - ot->flag = OPTYPE_UNDO; + ot->flag = OPTYPE_UNDO; #endif } /** \} */ - static wmKeyMap *gizmogroup_tweak_modal_keymap(wmKeyConfig *keyconf, const char *gzgroupname) { - wmKeyMap *keymap; - char name[KMAP_MAX_NAME]; - - static EnumPropertyItem modal_items[] = { - {TWEAK_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""}, - {TWEAK_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - {TWEAK_MODAL_PRECISION_ON, "PRECISION_ON", 0, "Enable Precision", ""}, - {TWEAK_MODAL_PRECISION_OFF, "PRECISION_OFF", 0, "Disable Precision", ""}, - {TWEAK_MODAL_SNAP_ON, "SNAP_ON", 0, "Enable Snap", ""}, - {TWEAK_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Disable Snap", ""}, - {0, NULL, 0, NULL, NULL}, - }; + wmKeyMap *keymap; + char name[KMAP_MAX_NAME]; + static EnumPropertyItem modal_items[] = { + {TWEAK_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""}, + {TWEAK_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + {TWEAK_MODAL_PRECISION_ON, "PRECISION_ON", 0, "Enable Precision", ""}, + {TWEAK_MODAL_PRECISION_OFF, "PRECISION_OFF", 0, "Disable Precision", ""}, + {TWEAK_MODAL_SNAP_ON, "SNAP_ON", 0, "Enable Snap", ""}, + {TWEAK_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Disable Snap", ""}, + {0, NULL, 0, NULL, NULL}, + }; - BLI_snprintf(name, sizeof(name), "%s Tweak Modal Map", gzgroupname); - keymap = WM_modalkeymap_get(keyconf, name); + BLI_snprintf(name, sizeof(name), "%s Tweak Modal Map", gzgroupname); + keymap = WM_modalkeymap_get(keyconf, name); - /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) { - return NULL; - } + /* this function is called for each spacetype, only needs to add map once */ + if (keymap && keymap->modal_items) { + return NULL; + } - keymap = WM_modalkeymap_add(keyconf, name, modal_items); + keymap = WM_modalkeymap_add(keyconf, name, modal_items); + /* items for modal map */ + WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); + WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); - /* items for modal map */ - WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); - WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL); + WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); + WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); - WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); - WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM); + WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); + WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); + WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); + WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); - WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); - WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF); + WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); + WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); - WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); - WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF); + WM_modalkeymap_assign(keymap, "GIZMOGROUP_OT_gizmo_tweak"); - WM_modalkeymap_assign(keymap, "GIZMOGROUP_OT_gizmo_tweak"); - - return keymap; + return keymap; } /** * Common default keymap for gizmo groups */ -wmKeyMap *WM_gizmogroup_keymap_common( - const wmGizmoGroupType *gzgt, wmKeyConfig *config) +wmKeyMap *WM_gizmogroup_keymap_common(const wmGizmoGroupType *gzgt, wmKeyConfig *config) { - /* Use area and region id since we might have multiple gizmos with the same name in different areas/regions */ - wmKeyMap *km = WM_keymap_ensure(config, gzgt->name, gzgt->gzmap_params.spaceid, gzgt->gzmap_params.regionid); + /* Use area and region id since we might have multiple gizmos with the same name in different areas/regions */ + wmKeyMap *km = WM_keymap_ensure( + config, gzgt->name, gzgt->gzmap_params.spaceid, gzgt->gzmap_params.regionid); - WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", LEFTMOUSE, KM_PRESS, KM_ANY, 0); - gizmogroup_tweak_modal_keymap(config, gzgt->name); + WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", LEFTMOUSE, KM_PRESS, KM_ANY, 0); + gizmogroup_tweak_modal_keymap(config, gzgt->name); - return km; + return km; } /** * Variation of #WM_gizmogroup_keymap_common but with keymap items for selection */ -wmKeyMap *WM_gizmogroup_keymap_common_select( - const wmGizmoGroupType *gzgt, wmKeyConfig *config) +wmKeyMap *WM_gizmogroup_keymap_common_select(const wmGizmoGroupType *gzgt, wmKeyConfig *config) { - /* Use area and region id since we might have multiple gizmos with the same name in different areas/regions */ - wmKeyMap *km = WM_keymap_ensure(config, gzgt->name, gzgt->gzmap_params.spaceid, gzgt->gzmap_params.regionid); - /* FIXME(campbell) */ + /* Use area and region id since we might have multiple gizmos with the same name in different areas/regions */ + wmKeyMap *km = WM_keymap_ensure( + config, gzgt->name, gzgt->gzmap_params.spaceid, gzgt->gzmap_params.regionid); + /* FIXME(campbell) */ #if 0 - const int select_mouse = (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE; - const int select_tweak = (U.flag & USER_LMOUSESELECT) ? EVT_TWEAK_L : EVT_TWEAK_R; - const int action_mouse = (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE; + const int select_mouse = (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE; + const int select_tweak = (U.flag & USER_LMOUSESELECT) ? EVT_TWEAK_L : EVT_TWEAK_R; + const int action_mouse = (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE; #else - const int select_mouse = RIGHTMOUSE; - const int select_tweak = EVT_TWEAK_R; - const int action_mouse = LEFTMOUSE; + const int select_mouse = RIGHTMOUSE; + const int select_tweak = EVT_TWEAK_R; + const int action_mouse = LEFTMOUSE; #endif - WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", action_mouse, KM_PRESS, KM_ANY, 0); - WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", select_tweak, KM_ANY, 0, 0); - gizmogroup_tweak_modal_keymap(config, gzgt->name); + WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", action_mouse, KM_PRESS, KM_ANY, 0); + WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_tweak", select_tweak, KM_ANY, 0, 0); + gizmogroup_tweak_modal_keymap(config, gzgt->name); - wmKeyMapItem *kmi = WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, 0, 0); - RNA_boolean_set(kmi->ptr, "extend", false); - RNA_boolean_set(kmi->ptr, "deselect", false); - RNA_boolean_set(kmi->ptr, "toggle", false); - kmi = WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, KM_SHIFT, 0); - RNA_boolean_set(kmi->ptr, "extend", false); - RNA_boolean_set(kmi->ptr, "deselect", false); - RNA_boolean_set(kmi->ptr, "toggle", true); + wmKeyMapItem *kmi = WM_keymap_add_item( + km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, 0, 0); + RNA_boolean_set(kmi->ptr, "extend", false); + RNA_boolean_set(kmi->ptr, "deselect", false); + RNA_boolean_set(kmi->ptr, "toggle", false); + kmi = WM_keymap_add_item(km, "GIZMOGROUP_OT_gizmo_select", select_mouse, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "extend", false); + RNA_boolean_set(kmi->ptr, "deselect", false); + RNA_boolean_set(kmi->ptr, "toggle", true); - return km; + return km; } /** \} */ /* wmGizmoGroup */ @@ -722,106 +732,97 @@ wmKeyMap *WM_gizmogroup_keymap_common_select( * * \{ */ -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find_ptr( - struct wmGizmoMapType *gzmap_type, - const wmGizmoGroupType *gzgt) -{ - /* could use hash lookups as operator types do, for now simple search. */ - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; - gzgt_ref; - gzgt_ref = gzgt_ref->next) - { - if (gzgt_ref->type == gzgt) { - return gzgt_ref; - } - } - return NULL; -} - -struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find( - struct wmGizmoMapType *gzmap_type, - const char *idname) -{ - /* could use hash lookups as operator types do, for now simple search. */ - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; - gzgt_ref; - gzgt_ref = gzgt_ref->next) - { - if (STREQ(idname, gzgt_ref->type->idname)) { - return gzgt_ref; - } - } - return NULL; +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find_ptr(struct wmGizmoMapType *gzmap_type, + const wmGizmoGroupType *gzgt) +{ + /* could use hash lookups as operator types do, for now simple search. */ + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; + gzgt_ref = gzgt_ref->next) { + if (gzgt_ref->type == gzgt) { + return gzgt_ref; + } + } + return NULL; +} + +struct wmGizmoGroupTypeRef *WM_gizmomaptype_group_find(struct wmGizmoMapType *gzmap_type, + const char *idname) +{ + /* could use hash lookups as operator types do, for now simple search. */ + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; + gzgt_ref = gzgt_ref->next) { + if (STREQ(idname, gzgt_ref->type->idname)) { + return gzgt_ref; + } + } + return NULL; } /** * Use this for registering gizmos on startup. For runtime, use #WM_gizmomaptype_group_link_runtime. */ -wmGizmoGroupTypeRef *WM_gizmomaptype_group_link( - wmGizmoMapType *gzmap_type, const char *idname) +wmGizmoGroupTypeRef *WM_gizmomaptype_group_link(wmGizmoMapType *gzmap_type, const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); } -wmGizmoGroupTypeRef *WM_gizmomaptype_group_link_ptr( - wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt) +wmGizmoGroupTypeRef *WM_gizmomaptype_group_link_ptr(wmGizmoMapType *gzmap_type, + wmGizmoGroupType *gzgt) { - wmGizmoGroupTypeRef *gzgt_ref = MEM_callocN(sizeof(wmGizmoGroupTypeRef), "gizmo-group-ref"); - gzgt_ref->type = gzgt; - BLI_addtail(&gzmap_type->grouptype_refs, gzgt_ref); - return gzgt_ref; + wmGizmoGroupTypeRef *gzgt_ref = MEM_callocN(sizeof(wmGizmoGroupTypeRef), "gizmo-group-ref"); + gzgt_ref->type = gzgt; + BLI_addtail(&gzmap_type->grouptype_refs, gzgt_ref); + return gzgt_ref; } -void WM_gizmomaptype_group_init_runtime_keymap( - const Main *bmain, - wmGizmoGroupType *gzgt) +void WM_gizmomaptype_group_init_runtime_keymap(const Main *bmain, wmGizmoGroupType *gzgt) { - /* init keymap - on startup there's an extra call to init keymaps for 'permanent' gizmo-groups */ - wm_gizmogrouptype_setup_keymap(gzgt, ((wmWindowManager *)bmain->wm.first)->defaultconf); + /* init keymap - on startup there's an extra call to init keymaps for 'permanent' gizmo-groups */ + wm_gizmogrouptype_setup_keymap(gzgt, ((wmWindowManager *)bmain->wm.first)->defaultconf); } -void WM_gizmomaptype_group_init_runtime( - const Main *bmain, wmGizmoMapType *gzmap_type, - wmGizmoGroupType *gzgt) +void WM_gizmomaptype_group_init_runtime(const Main *bmain, + wmGizmoMapType *gzmap_type, + wmGizmoGroupType *gzgt) { - /* Tools add themselves. */ - if (gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) { - return; - } + /* Tools add themselves. */ + if (gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) { + return; + } - /* now create a gizmo for all existing areas */ - for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { - ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; - for (ARegion *ar = lb->first; ar; ar = ar->next) { - wmGizmoMap *gzmap = ar->gizmo_map; - if (gzmap && gzmap->type == gzmap_type) { - WM_gizmomaptype_group_init_runtime_with_region(gzmap_type, gzgt, ar); - } - } - } - } - } + /* now create a gizmo for all existing areas */ + for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + for (ARegion *ar = lb->first; ar; ar = ar->next) { + wmGizmoMap *gzmap = ar->gizmo_map; + if (gzmap && gzmap->type == gzmap_type) { + WM_gizmomaptype_group_init_runtime_with_region(gzmap_type, gzgt, ar); + } + } + } + } + } } -wmGizmoGroup *WM_gizmomaptype_group_init_runtime_with_region( - wmGizmoMapType *gzmap_type, - wmGizmoGroupType *gzgt, ARegion *ar) +wmGizmoGroup *WM_gizmomaptype_group_init_runtime_with_region(wmGizmoMapType *gzmap_type, + wmGizmoGroupType *gzgt, + ARegion *ar) { - wmGizmoMap *gzmap = ar->gizmo_map; - BLI_assert(gzmap && gzmap->type == gzmap_type); - UNUSED_VARS_NDEBUG(gzmap_type); + wmGizmoMap *gzmap = ar->gizmo_map; + BLI_assert(gzmap && gzmap->type == gzmap_type); + UNUSED_VARS_NDEBUG(gzmap_type); - wmGizmoGroup *gzgroup = wm_gizmogroup_new_from_type(gzmap, gzgt); + wmGizmoGroup *gzgroup = wm_gizmogroup_new_from_type(gzmap, gzgt); - wm_gizmomap_highlight_set(gzmap, NULL, NULL, 0); + wm_gizmomap_highlight_set(gzmap, NULL, NULL, 0); - ED_region_tag_redraw(ar); + ED_region_tag_redraw(ar); - return gzgroup; + return gzgroup; } /** @@ -829,59 +830,59 @@ wmGizmoGroup *WM_gizmomaptype_group_init_runtime_with_region( */ void WM_gizmomaptype_group_free(wmGizmoGroupTypeRef *gzgt_ref) { - MEM_freeN(gzgt_ref); -} - -void WM_gizmomaptype_group_unlink( - bContext *C, Main *bmain, wmGizmoMapType *gzmap_type, - const wmGizmoGroupType *gzgt) -{ - /* Free instances. */ - for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { - ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; - for (ARegion *ar = lb->first; ar; ar = ar->next) { - wmGizmoMap *gzmap = ar->gizmo_map; - if (gzmap && gzmap->type == gzmap_type) { - wmGizmoGroup *gzgroup, *gzgroup_next; - for (gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup_next) { - gzgroup_next = gzgroup->next; - if (gzgroup->type == gzgt) { - BLI_assert(gzgroup->parent_gzmap == gzmap); - wm_gizmogroup_free(C, gzgroup); - ED_region_tag_redraw(ar); - } - } - } - } - } - } - } - - /* Free types. */ - wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); - if (gzgt_ref) { - BLI_remlink(&gzmap_type->grouptype_refs, gzgt_ref); - WM_gizmomaptype_group_free(gzgt_ref); - } - - /* Note, we may want to keep this keymap for editing */ - WM_keymap_remove(gzgt->keyconf, gzgt->keymap); - - BLI_assert(WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt) == NULL); -} - -void wm_gizmogrouptype_setup_keymap( - wmGizmoGroupType *gzgt, wmKeyConfig *keyconf) -{ - /* Use flag since setup_keymap may return NULL, - * in that case we better not keep calling it. */ - if (gzgt->type_update_flag & WM_GIZMOMAPTYPE_KEYMAP_INIT) { - gzgt->keymap = gzgt->setup_keymap(gzgt, keyconf); - gzgt->keyconf = keyconf; - gzgt->type_update_flag &= ~WM_GIZMOMAPTYPE_KEYMAP_INIT; - } + MEM_freeN(gzgt_ref); +} + +void WM_gizmomaptype_group_unlink(bContext *C, + Main *bmain, + wmGizmoMapType *gzmap_type, + const wmGizmoGroupType *gzgt) +{ + /* Free instances. */ + for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + for (ARegion *ar = lb->first; ar; ar = ar->next) { + wmGizmoMap *gzmap = ar->gizmo_map; + if (gzmap && gzmap->type == gzmap_type) { + wmGizmoGroup *gzgroup, *gzgroup_next; + for (gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup_next) { + gzgroup_next = gzgroup->next; + if (gzgroup->type == gzgt) { + BLI_assert(gzgroup->parent_gzmap == gzmap); + wm_gizmogroup_free(C, gzgroup); + ED_region_tag_redraw(ar); + } + } + } + } + } + } + } + + /* Free types. */ + wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); + if (gzgt_ref) { + BLI_remlink(&gzmap_type->grouptype_refs, gzgt_ref); + WM_gizmomaptype_group_free(gzgt_ref); + } + + /* Note, we may want to keep this keymap for editing */ + WM_keymap_remove(gzgt->keyconf, gzgt->keymap); + + BLI_assert(WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt) == NULL); +} + +void wm_gizmogrouptype_setup_keymap(wmGizmoGroupType *gzgt, wmKeyConfig *keyconf) +{ + /* Use flag since setup_keymap may return NULL, + * in that case we better not keep calling it. */ + if (gzgt->type_update_flag & WM_GIZMOMAPTYPE_KEYMAP_INIT) { + gzgt->keymap = gzgt->setup_keymap(gzgt, keyconf); + gzgt->keyconf = keyconf; + gzgt->type_update_flag &= ~WM_GIZMOMAPTYPE_KEYMAP_INIT; + } } /** \} */ /* wmGizmoGroupType */ @@ -901,115 +902,104 @@ void wm_gizmogrouptype_setup_keymap( * * \{ */ -void WM_gizmo_group_type_add_ptr_ex( - wmGizmoGroupType *gzgt, - wmGizmoMapType *gzmap_type) +void WM_gizmo_group_type_add_ptr_ex(wmGizmoGroupType *gzgt, wmGizmoMapType *gzmap_type) { - WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); + WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); - WM_gizmoconfig_update_tag_init(gzmap_type, gzgt); + WM_gizmoconfig_update_tag_init(gzmap_type, gzgt); } -void WM_gizmo_group_type_add_ptr( - wmGizmoGroupType *gzgt) +void WM_gizmo_group_type_add_ptr(wmGizmoGroupType *gzgt) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); - WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); + WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); } void WM_gizmo_group_type_add(const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - WM_gizmo_group_type_add_ptr(gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + WM_gizmo_group_type_add_ptr(gzgt); } -bool WM_gizmo_group_type_ensure_ptr_ex( - wmGizmoGroupType *gzgt, - wmGizmoMapType *gzmap_type) +bool WM_gizmo_group_type_ensure_ptr_ex(wmGizmoGroupType *gzgt, wmGizmoMapType *gzmap_type) { - wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); - if (gzgt_ref == NULL) { - WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); - return true; - } - return false; + wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); + if (gzgt_ref == NULL) { + WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); + return true; + } + return false; } -bool WM_gizmo_group_type_ensure_ptr( - wmGizmoGroupType *gzgt) +bool WM_gizmo_group_type_ensure_ptr(wmGizmoGroupType *gzgt) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); - return WM_gizmo_group_type_ensure_ptr_ex(gzgt, gzmap_type); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); + return WM_gizmo_group_type_ensure_ptr_ex(gzgt, gzmap_type); } bool WM_gizmo_group_type_ensure(const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - return WM_gizmo_group_type_ensure_ptr(gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + return WM_gizmo_group_type_ensure_ptr(gzgt); } -void WM_gizmo_group_type_remove_ptr_ex( - struct Main *bmain, wmGizmoGroupType *gzgt, - wmGizmoMapType *gzmap_type) +void WM_gizmo_group_type_remove_ptr_ex(struct Main *bmain, + wmGizmoGroupType *gzgt, + wmGizmoMapType *gzmap_type) { - WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt); - WM_gizmogrouptype_free_ptr(gzgt); + WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt); + WM_gizmogrouptype_free_ptr(gzgt); } -void WM_gizmo_group_type_remove_ptr( - struct Main *bmain, wmGizmoGroupType *gzgt) +void WM_gizmo_group_type_remove_ptr(struct Main *bmain, wmGizmoGroupType *gzgt) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); - WM_gizmo_group_type_remove_ptr_ex(bmain, gzgt, gzmap_type); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); + WM_gizmo_group_type_remove_ptr_ex(bmain, gzgt, gzmap_type); } void WM_gizmo_group_type_remove(struct Main *bmain, const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - WM_gizmo_group_type_remove_ptr(bmain, gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + WM_gizmo_group_type_remove_ptr(bmain, gzgt); } -void WM_gizmo_group_type_reinit_ptr_ex( - struct Main *bmain, wmGizmoGroupType *gzgt, - wmGizmoMapType *gzmap_type) +void WM_gizmo_group_type_reinit_ptr_ex(struct Main *bmain, + wmGizmoGroupType *gzgt, + wmGizmoMapType *gzmap_type) { - wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); - BLI_assert(gzgt_ref != NULL); - UNUSED_VARS_NDEBUG(gzgt_ref); - WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt); - WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); + wmGizmoGroupTypeRef *gzgt_ref = WM_gizmomaptype_group_find_ptr(gzmap_type, gzgt); + BLI_assert(gzgt_ref != NULL); + UNUSED_VARS_NDEBUG(gzgt_ref); + WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt); + WM_gizmo_group_type_add_ptr_ex(gzgt, gzmap_type); } -void WM_gizmo_group_type_reinit_ptr( - struct Main *bmain, wmGizmoGroupType *gzgt) +void WM_gizmo_group_type_reinit_ptr(struct Main *bmain, wmGizmoGroupType *gzgt) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); - WM_gizmo_group_type_reinit_ptr_ex(bmain, gzgt, gzmap_type); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); + WM_gizmo_group_type_reinit_ptr_ex(bmain, gzgt, gzmap_type); } void WM_gizmo_group_type_reinit(struct Main *bmain, const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - WM_gizmo_group_type_reinit_ptr(bmain, gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + WM_gizmo_group_type_reinit_ptr(bmain, gzgt); } /* delayed versions */ -void WM_gizmo_group_type_unlink_delayed_ptr_ex( - wmGizmoGroupType *gzgt, - wmGizmoMapType *gzmap_type) +void WM_gizmo_group_type_unlink_delayed_ptr_ex(wmGizmoGroupType *gzgt, wmGizmoMapType *gzmap_type) { - WM_gizmoconfig_update_tag_remove(gzmap_type, gzgt); + WM_gizmoconfig_update_tag_remove(gzmap_type, gzgt); } -void WM_gizmo_group_type_unlink_delayed_ptr( - wmGizmoGroupType *gzgt) +void WM_gizmo_group_type_unlink_delayed_ptr(wmGizmoGroupType *gzgt) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); - WM_gizmo_group_type_unlink_delayed_ptr_ex(gzgt, gzmap_type); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params); + WM_gizmo_group_type_unlink_delayed_ptr_ex(gzgt, gzmap_type); } void WM_gizmo_group_type_unlink_delayed(const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - BLI_assert(gzgt != NULL); - WM_gizmo_group_type_unlink_delayed_ptr(gzgt); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + BLI_assert(gzgt != NULL); + WM_gizmo_group_type_unlink_delayed_ptr(gzgt); } /** \} */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c index 60377353182..7c8db18c0ca 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c @@ -38,7 +38,6 @@ #include "wm_gizmo_wmapi.h" #include "wm_gizmo_intern.h" - /** \name GizmoGroup Type Append * * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends. @@ -48,98 +47,96 @@ static GHash *global_gizmogrouptype_hash = NULL; wmGizmoGroupType *WM_gizmogrouptype_find(const char *idname, bool quiet) { - if (idname[0]) { - wmGizmoGroupType *gzgt; - - gzgt = BLI_ghash_lookup(global_gizmogrouptype_hash, idname); - if (gzgt) { - return gzgt; - } - - if (!quiet) { - printf("search for unknown gizmo group '%s'\n", idname); - } - } - else { - if (!quiet) { - printf("search for empty gizmo group\n"); - } - } - - return NULL; + if (idname[0]) { + wmGizmoGroupType *gzgt; + + gzgt = BLI_ghash_lookup(global_gizmogrouptype_hash, idname); + if (gzgt) { + return gzgt; + } + + if (!quiet) { + printf("search for unknown gizmo group '%s'\n", idname); + } + } + else { + if (!quiet) { + printf("search for empty gizmo group\n"); + } + } + + return NULL; } /* caller must free */ void WM_gizmogrouptype_iter(GHashIterator *ghi) { - BLI_ghashIterator_init(ghi, global_gizmogrouptype_hash); + BLI_ghashIterator_init(ghi, global_gizmogrouptype_hash); } static wmGizmoGroupType *wm_gizmogrouptype_append__begin(void) { - wmGizmoGroupType *gzgt = MEM_callocN(sizeof(wmGizmoGroupType), "gizmogrouptype"); - gzgt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoGroupProperties); + wmGizmoGroupType *gzgt = MEM_callocN(sizeof(wmGizmoGroupType), "gizmogrouptype"); + gzgt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoGroupProperties); #if 0 - /* Set the default i18n context now, so that opfunc can redefine it if needed! */ - RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); - ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; + /* Set the default i18n context now, so that opfunc can redefine it if needed! */ + RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); + ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; #endif - return gzgt; + return gzgt; } static void wm_gizmogrouptype_append__end(wmGizmoGroupType *gzgt) { - BLI_assert(gzgt->name != NULL); - BLI_assert(gzgt->idname != NULL); + BLI_assert(gzgt->name != NULL); + BLI_assert(gzgt->idname != NULL); - RNA_def_struct_identifier(&BLENDER_RNA, gzgt->srna, gzgt->idname); + RNA_def_struct_identifier(&BLENDER_RNA, gzgt->srna, gzgt->idname); - gzgt->type_update_flag |= WM_GIZMOMAPTYPE_KEYMAP_INIT; + gzgt->type_update_flag |= WM_GIZMOMAPTYPE_KEYMAP_INIT; - /* if not set, use default */ - if (gzgt->setup_keymap == NULL) { - if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) { - gzgt->setup_keymap = WM_gizmogroup_keymap_common_select; - } - else { - gzgt->setup_keymap = WM_gizmogroup_keymap_common; - } - } + /* if not set, use default */ + if (gzgt->setup_keymap == NULL) { + if (gzgt->flag & WM_GIZMOGROUPTYPE_SELECT) { + gzgt->setup_keymap = WM_gizmogroup_keymap_common_select; + } + else { + gzgt->setup_keymap = WM_gizmogroup_keymap_common; + } + } - BLI_ghash_insert(global_gizmogrouptype_hash, (void *)gzgt->idname, gzgt); + BLI_ghash_insert(global_gizmogrouptype_hash, (void *)gzgt->idname, gzgt); } -wmGizmoGroupType *WM_gizmogrouptype_append( - void (*wtfunc)(struct wmGizmoGroupType *)) +wmGizmoGroupType *WM_gizmogrouptype_append(void (*wtfunc)(struct wmGizmoGroupType *)) { - wmGizmoGroupType *gzgt = wm_gizmogrouptype_append__begin(); - wtfunc(gzgt); - wm_gizmogrouptype_append__end(gzgt); - return gzgt; + wmGizmoGroupType *gzgt = wm_gizmogrouptype_append__begin(); + wtfunc(gzgt); + wm_gizmogrouptype_append__end(gzgt); + return gzgt; } -wmGizmoGroupType *WM_gizmogrouptype_append_ptr( - void (*wtfunc)(struct wmGizmoGroupType *, void *), void *userdata) +wmGizmoGroupType *WM_gizmogrouptype_append_ptr(void (*wtfunc)(struct wmGizmoGroupType *, void *), + void *userdata) { - wmGizmoGroupType *gzgt = wm_gizmogrouptype_append__begin(); - wtfunc(gzgt, userdata); - wm_gizmogrouptype_append__end(gzgt); - return gzgt; + wmGizmoGroupType *gzgt = wm_gizmogrouptype_append__begin(); + wtfunc(gzgt, userdata); + wm_gizmogrouptype_append__end(gzgt); + return gzgt; } /** * Append and insert into a gizmo typemap. * This is most common for C gizmos which are enabled by default. */ -wmGizmoGroupTypeRef *WM_gizmogrouptype_append_and_link( - wmGizmoMapType *gzmap_type, - void (*wtfunc)(struct wmGizmoGroupType *)) +wmGizmoGroupTypeRef *WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, + void (*wtfunc)(struct wmGizmoGroupType *)) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_append(wtfunc); + wmGizmoGroupType *gzgt = WM_gizmogrouptype_append(wtfunc); - gzgt->gzmap_params.spaceid = gzmap_type->spaceid; - gzgt->gzmap_params.regionid = gzmap_type->regionid; + gzgt->gzmap_params.spaceid = gzmap_type->spaceid; + gzgt->gzmap_params.regionid = gzmap_type->regionid; - return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); + return WM_gizmomaptype_group_link_ptr(gzmap_type, gzgt); } /** @@ -147,53 +144,54 @@ wmGizmoGroupTypeRef *WM_gizmogrouptype_append_and_link( */ static void gizmogrouptype_free(wmGizmoGroupType *gzgt) { - if (gzgt->ext.srna) { /* python gizmo group, allocs own string */ - MEM_freeN((void *)gzgt->idname); - } + if (gzgt->ext.srna) { /* python gizmo group, allocs own string */ + MEM_freeN((void *)gzgt->idname); + } - MEM_freeN(gzgt); + MEM_freeN(gzgt); } void WM_gizmogrouptype_free_ptr(wmGizmoGroupType *gzgt) { - BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false)); + BLI_assert(gzgt == WM_gizmogrouptype_find(gzgt->idname, false)); - BLI_ghash_remove(global_gizmogrouptype_hash, gzgt->idname, NULL, NULL); + BLI_ghash_remove(global_gizmogrouptype_hash, gzgt->idname, NULL, NULL); - gizmogrouptype_free(gzgt); + gizmogrouptype_free(gzgt); - /* XXX, TODO, update the world! */ + /* XXX, TODO, update the world! */ } bool WM_gizmogrouptype_free(const char *idname) { - wmGizmoGroupType *gzgt = BLI_ghash_lookup(global_gizmogrouptype_hash, idname); + wmGizmoGroupType *gzgt = BLI_ghash_lookup(global_gizmogrouptype_hash, idname); - if (gzgt == NULL) { - return false; - } + if (gzgt == NULL) { + return false; + } - WM_gizmogrouptype_free_ptr(gzgt); + WM_gizmogrouptype_free_ptr(gzgt); - return true; + return true; } static void wm_gizmogrouptype_ghash_free_cb(wmGizmoGroupType *gzgt) { - gizmogrouptype_free(gzgt); + gizmogrouptype_free(gzgt); } void wm_gizmogrouptype_free(void) { - BLI_ghash_free(global_gizmogrouptype_hash, NULL, (GHashValFreeFP)wm_gizmogrouptype_ghash_free_cb); - global_gizmogrouptype_hash = NULL; + BLI_ghash_free( + global_gizmogrouptype_hash, NULL, (GHashValFreeFP)wm_gizmogrouptype_ghash_free_cb); + global_gizmogrouptype_hash = NULL; } /* called on initialize WM_init() */ void wm_gizmogrouptype_init(void) { - /* reserve size is set based on blender default setup */ - global_gizmogrouptype_hash = BLI_ghash_str_new_ex("wm_gizmogrouptype_init gh", 128); + /* reserve size is set based on blender default setup */ + global_gizmogrouptype_hash = BLI_ghash_str_new_ex("wm_gizmogrouptype_init gh", 128); } /** \} */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h index 6263bfaf58d..1a0babdccb5 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h @@ -18,7 +18,6 @@ * \ingroup wm */ - #ifndef __WM_GIZMO_INTERN_H__ #define __WM_GIZMO_INTERN_H__ @@ -32,10 +31,8 @@ struct wmKeyConfig; /* -------------------------------------------------------------------- */ /* wmGizmo */ - bool wm_gizmo_select_set_ex( - struct wmGizmoMap *gzmap, struct wmGizmo *gz, bool select, - bool use_array, bool use_callback); + struct wmGizmoMap *gzmap, struct wmGizmo *gz, bool select, bool use_array, bool use_callback); bool wm_gizmo_select_and_highlight(bContext *C, struct wmGizmoMap *gzmap, struct wmGizmo *gz); void wm_gizmo_calculate_scale(struct wmGizmo *gz, const bContext *C); @@ -43,76 +40,75 @@ void wm_gizmo_update(struct wmGizmo *gz, const bContext *C, const bool refresh_m int wm_gizmo_is_visible(struct wmGizmo *gz); enum { - WM_GIZMO_IS_VISIBLE_UPDATE = (1 << 0), - WM_GIZMO_IS_VISIBLE_DRAW = (1 << 1), + WM_GIZMO_IS_VISIBLE_UPDATE = (1 << 0), + WM_GIZMO_IS_VISIBLE_DRAW = (1 << 1), }; /* -------------------------------------------------------------------- */ /* wmGizmoGroup */ enum { - TWEAK_MODAL_CANCEL = 1, - TWEAK_MODAL_CONFIRM, - TWEAK_MODAL_PRECISION_ON, - TWEAK_MODAL_PRECISION_OFF, - TWEAK_MODAL_SNAP_ON, - TWEAK_MODAL_SNAP_OFF, + TWEAK_MODAL_CANCEL = 1, + TWEAK_MODAL_CONFIRM, + TWEAK_MODAL_PRECISION_ON, + TWEAK_MODAL_PRECISION_OFF, + TWEAK_MODAL_SNAP_ON, + TWEAK_MODAL_SNAP_OFF, }; -struct wmGizmoGroup *wm_gizmogroup_new_from_type( - struct wmGizmoMap *gzmap, struct wmGizmoGroupType *gzgt); +struct wmGizmoGroup *wm_gizmogroup_new_from_type(struct wmGizmoMap *gzmap, + struct wmGizmoGroupType *gzgt); void wm_gizmogroup_free(bContext *C, struct wmGizmoGroup *gzgroup); void wm_gizmogroup_gizmo_register(struct wmGizmoGroup *gzgroup, struct wmGizmo *gz); -struct wmGizmo *wm_gizmogroup_find_intersected_gizmo( - const struct wmGizmoGroup *gzgroup, struct bContext *C, const struct wmEvent *event, - int *r_part); -void wm_gizmogroup_intersectable_gizmos_to_list( - const struct wmGizmoGroup *gzgroup, struct ListBase *listbase); -bool wm_gizmogroup_is_visible_in_drawstep( - const struct wmGizmoGroup *gzgroup, const eWM_GizmoFlagMapDrawStep drawstep); - -void wm_gizmogrouptype_setup_keymap( - struct wmGizmoGroupType *gzgt, struct wmKeyConfig *keyconf); +struct wmGizmo *wm_gizmogroup_find_intersected_gizmo(const struct wmGizmoGroup *gzgroup, + struct bContext *C, + const struct wmEvent *event, + int *r_part); +void wm_gizmogroup_intersectable_gizmos_to_list(const struct wmGizmoGroup *gzgroup, + struct ListBase *listbase); +bool wm_gizmogroup_is_visible_in_drawstep(const struct wmGizmoGroup *gzgroup, + const eWM_GizmoFlagMapDrawStep drawstep); +void wm_gizmogrouptype_setup_keymap(struct wmGizmoGroupType *gzgt, struct wmKeyConfig *keyconf); /* -------------------------------------------------------------------- */ /* wmGizmoMap */ typedef struct wmGizmoMapSelectState { - struct wmGizmo **items; - int len, len_alloc; + struct wmGizmo **items; + int len, len_alloc; } wmGizmoMapSelectState; struct wmGizmoMap { - struct wmGizmoMapType *type; - ListBase groups; /* wmGizmoGroup */ - - /* private, update tagging (enum defined in C source). */ - char update_flag[WM_GIZMOMAP_DRAWSTEP_MAX]; - - /** Private, true when not yet used. */ - bool is_init; - - /** - * \brief Gizmo map runtime context - * - * Contains information about this gizmo-map. Currently - * highlighted gizmo, currently selected gizmos, ... - */ - struct { - /* we redraw the gizmo-map when this changes */ - struct wmGizmo *highlight; - /* User has clicked this gizmo and it gets all input. */ - struct wmGizmo *modal; - /* array for all selected gizmos */ - struct wmGizmoMapSelectState select; - /* cursor location at point of entering modal (see: WM_GIZMO_MOVE_CURSOR) */ - int event_xy[2]; - short event_grabcursor; - /* until we have nice cursor push/pop API. */ - int last_cursor; - } gzmap_context; + struct wmGizmoMapType *type; + ListBase groups; /* wmGizmoGroup */ + + /* private, update tagging (enum defined in C source). */ + char update_flag[WM_GIZMOMAP_DRAWSTEP_MAX]; + + /** Private, true when not yet used. */ + bool is_init; + + /** + * \brief Gizmo map runtime context + * + * Contains information about this gizmo-map. Currently + * highlighted gizmo, currently selected gizmos, ... + */ + struct { + /* we redraw the gizmo-map when this changes */ + struct wmGizmo *highlight; + /* User has clicked this gizmo and it gets all input. */ + struct wmGizmo *modal; + /* array for all selected gizmos */ + struct wmGizmoMapSelectState select; + /* cursor location at point of entering modal (see: WM_GIZMO_MOVE_CURSOR) */ + int event_xy[2]; + short event_grabcursor; + /* until we have nice cursor push/pop API. */ + int last_cursor; + } gzmap_context; }; /** @@ -122,13 +118,13 @@ struct wmGizmoMap { * \note There is only ever one of these for every (area, region) combination. */ struct wmGizmoMapType { - struct wmGizmoMapType *next, *prev; - short spaceid, regionid; - /* types of gizmo-groups for this gizmo-map type */ - ListBase grouptype_refs; + struct wmGizmoMapType *next, *prev; + short spaceid, regionid; + /* types of gizmo-groups for this gizmo-map type */ + ListBase grouptype_refs; - /* eGizmoMapTypeUpdateFlags */ - eWM_GizmoFlagMapTypeUpdateFlag type_update_flag; + /* eGizmoMapTypeUpdateFlags */ + eWM_GizmoFlagMapTypeUpdateFlag type_update_flag; }; void wm_gizmomap_select_array_clear(struct wmGizmoMap *gzmap); diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 112943a7dba..33c58f8563d 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -67,8 +67,8 @@ static ListBase gizmomaptypes = {NULL, NULL}; */ /* so operator removal can trigger update */ typedef enum eWM_GizmoFlagGroupTypeGlobalFlag { - WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT = (1 << 0), - WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE = (1 << 1), + WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT = (1 << 0), + WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE = (1 << 1), } eWM_GizmoFlagGroupTypeGlobalFlag; static eWM_GizmoFlagGroupTypeGlobalFlag wm_gzmap_type_update_flag = 0; @@ -77,12 +77,11 @@ static eWM_GizmoFlagGroupTypeGlobalFlag wm_gzmap_type_update_flag = 0; * Gizmo-map update tagging. */ enum { - /** #gizmomap_prepare_drawing has run */ - GIZMOMAP_IS_PREPARE_DRAW = (1 << 0), - GIZMOMAP_IS_REFRESH_CALLBACK = (1 << 1), + /** #gizmomap_prepare_drawing has run */ + GIZMOMAP_IS_PREPARE_DRAW = (1 << 0), + GIZMOMAP_IS_REFRESH_CALLBACK = (1 << 1), }; - /* -------------------------------------------------------------------- */ /** \name wmGizmoMap Selection Array API * @@ -92,181 +91,178 @@ enum { static void wm_gizmomap_select_array_ensure_len_alloc(wmGizmoMap *gzmap, int len) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - if (len <= msel->len_alloc) { - return; - } - msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * len); - msel->len_alloc = len; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + if (len <= msel->len_alloc) { + return; + } + msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * len); + msel->len_alloc = len; } void wm_gizmomap_select_array_clear(wmGizmoMap *gzmap) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - MEM_SAFE_FREE(msel->items); - msel->len = 0; - msel->len_alloc = 0; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + MEM_SAFE_FREE(msel->items); + msel->len = 0; + msel->len_alloc = 0; } void wm_gizmomap_select_array_shrink(wmGizmoMap *gzmap, int len_subtract) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - msel->len -= len_subtract; - if (msel->len <= 0) { - wm_gizmomap_select_array_clear(gzmap); - } - else { - if (msel->len < msel->len_alloc / 2) { - msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len); - msel->len_alloc = msel->len; - } - } + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + msel->len -= len_subtract; + if (msel->len <= 0) { + wm_gizmomap_select_array_clear(gzmap); + } + else { + if (msel->len < msel->len_alloc / 2) { + msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len); + msel->len_alloc = msel->len; + } + } } void wm_gizmomap_select_array_push_back(wmGizmoMap *gzmap, wmGizmo *gz) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - BLI_assert(msel->len <= msel->len_alloc); - if (msel->len == msel->len_alloc) { - msel->len_alloc = (msel->len + 1) * 2; - msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len_alloc); - } - msel->items[msel->len++] = gz; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + BLI_assert(msel->len <= msel->len_alloc); + if (msel->len == msel->len_alloc) { + msel->len_alloc = (msel->len + 1) * 2; + msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len_alloc); + } + msel->items[msel->len++] = gz; } void wm_gizmomap_select_array_remove(wmGizmoMap *gzmap, wmGizmo *gz) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - /* remove gizmo from selected_gizmos array */ - for (int i = 0; i < msel->len; i++) { - if (msel->items[i] == gz) { - for (int j = i; j < (msel->len - 1); j++) { - msel->items[j] = msel->items[j + 1]; - } - wm_gizmomap_select_array_shrink(gzmap, 1); - break; - } - } - + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + /* remove gizmo from selected_gizmos array */ + for (int i = 0; i < msel->len; i++) { + if (msel->items[i] == gz) { + for (int j = i; j < (msel->len - 1); j++) { + msel->items[j] = msel->items[j + 1]; + } + wm_gizmomap_select_array_shrink(gzmap, 1); + break; + } + } } /** \} */ - /* -------------------------------------------------------------------- */ /** \name wmGizmoMap * * \{ */ -static wmGizmoMap *wm_gizmomap_new_from_type_ex( - struct wmGizmoMapType *gzmap_type, - wmGizmoMap *gzmap) +static wmGizmoMap *wm_gizmomap_new_from_type_ex(struct wmGizmoMapType *gzmap_type, + wmGizmoMap *gzmap) { - gzmap->type = gzmap_type; - gzmap->is_init = true; - WM_gizmomap_tag_refresh(gzmap); - - /* create all gizmo-groups for this gizmo-map. We may create an empty one - * too in anticipation of gizmos from operators etc */ - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; gzgt_ref = gzgt_ref->next) { - wm_gizmogroup_new_from_type(gzmap, gzgt_ref->type); - } - - return gzmap; + gzmap->type = gzmap_type; + gzmap->is_init = true; + WM_gizmomap_tag_refresh(gzmap); + + /* create all gizmo-groups for this gizmo-map. We may create an empty one + * too in anticipation of gizmos from operators etc */ + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; + gzgt_ref = gzgt_ref->next) { + wm_gizmogroup_new_from_type(gzmap, gzgt_ref->type); + } + + return gzmap; } /** * Creates a gizmo-map with all registered gizmos for that type */ -wmGizmoMap *WM_gizmomap_new_from_type( - const struct wmGizmoMapType_Params *gzmap_params) +wmGizmoMap *WM_gizmomap_new_from_type(const struct wmGizmoMapType_Params *gzmap_params) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(gzmap_params); - wmGizmoMap *gzmap = MEM_callocN(sizeof(wmGizmoMap), "GizmoMap"); - wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); - return gzmap; + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(gzmap_params); + wmGizmoMap *gzmap = MEM_callocN(sizeof(wmGizmoMap), "GizmoMap"); + wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); + return gzmap; } static void wm_gizmomap_free_data(wmGizmoMap *gzmap) { - /* Clear first so further calls don't waste time trying to maintain correct array state. */ - wm_gizmomap_select_array_clear(gzmap); - - for (wmGizmoGroup *gzgroup = gzmap->groups.first, *gzgroup_next; gzgroup; gzgroup = gzgroup_next) { - gzgroup_next = gzgroup->next; - BLI_assert(gzgroup->parent_gzmap == gzmap); - wm_gizmogroup_free(NULL, gzgroup); - } - BLI_assert(BLI_listbase_is_empty(&gzmap->groups)); + /* Clear first so further calls don't waste time trying to maintain correct array state. */ + wm_gizmomap_select_array_clear(gzmap); + + for (wmGizmoGroup *gzgroup = gzmap->groups.first, *gzgroup_next; gzgroup; + gzgroup = gzgroup_next) { + gzgroup_next = gzgroup->next; + BLI_assert(gzgroup->parent_gzmap == gzmap); + wm_gizmogroup_free(NULL, gzgroup); + } + BLI_assert(BLI_listbase_is_empty(&gzmap->groups)); } void wm_gizmomap_remove(wmGizmoMap *gzmap) { - wm_gizmomap_free_data(gzmap); - MEM_freeN(gzmap); + wm_gizmomap_free_data(gzmap); + MEM_freeN(gzmap); } /** Re-create the gizmos (use when changing theme settings). */ void WM_gizmomap_reinit(wmGizmoMap *gzmap) { - wmGizmoMapType *gzmap_type = gzmap->type; - wm_gizmomap_free_data(gzmap); - memset(gzmap, 0x0, sizeof(*gzmap)); - wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); + wmGizmoMapType *gzmap_type = gzmap->type; + wm_gizmomap_free_data(gzmap); + memset(gzmap, 0x0, sizeof(*gzmap)); + wm_gizmomap_new_from_type_ex(gzmap_type, gzmap); } -wmGizmoGroup *WM_gizmomap_group_find( - struct wmGizmoMap *gzmap, - const char *idname) +wmGizmoGroup *WM_gizmomap_group_find(struct wmGizmoMap *gzmap, const char *idname) { - wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); - if (gzgt) { - return WM_gizmomap_group_find_ptr(gzmap, gzgt); - } - return NULL; + wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false); + if (gzgt) { + return WM_gizmomap_group_find_ptr(gzmap, gzgt); + } + return NULL; } -wmGizmoGroup *WM_gizmomap_group_find_ptr( - struct wmGizmoMap *gzmap, - const struct wmGizmoGroupType *gzgt) +wmGizmoGroup *WM_gizmomap_group_find_ptr(struct wmGizmoMap *gzmap, + const struct wmGizmoGroupType *gzgt) { - for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - if (gzgroup->type == gzgt) { - return gzgroup; - } - } - return NULL; + for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + if (gzgroup->type == gzgt) { + return gzgroup; + } + } + return NULL; } const ListBase *WM_gizmomap_group_list(wmGizmoMap *gzmap) { - return &gzmap->groups; + return &gzmap->groups; } bool WM_gizmomap_is_any_selected(const wmGizmoMap *gzmap) { - return gzmap->gzmap_context.select.len != 0; + return gzmap->gzmap_context.select.len != 0; } /** * \note We could use a callback to define bounds, for now just use matrix location. */ -bool WM_gizmomap_minmax( - const wmGizmoMap *gzmap, bool UNUSED(use_hidden), bool use_select, - float r_min[3], float r_max[3]) +bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, + bool UNUSED(use_hidden), + bool use_select, + float r_min[3], + float r_max[3]) { - if (use_select) { - int i; - for (i = 0; i < gzmap->gzmap_context.select.len; i++) { - minmax_v3v3_v3(r_min, r_max, gzmap->gzmap_context.select.items[i]->matrix_basis[3]); - } - return i != 0; - } - else { - bool ok = false; - BLI_assert(!"TODO"); - return ok; - } + if (use_select) { + int i; + for (i = 0; i < gzmap->gzmap_context.select.len; i++) { + minmax_v3v3_v3(r_min, r_max, gzmap->gzmap_context.select.items[i]->matrix_basis[3]); + } + return i != 0; + } + else { + bool ok = false; + BLI_assert(!"TODO"); + return ok; + } } /** @@ -278,124 +274,121 @@ bool WM_gizmomap_minmax( * TODO(campbell): this uses unreliable order, * best we use an iterator function instead of a hash. */ -static GHash *WM_gizmomap_gizmo_hash_new( - const bContext *C, wmGizmoMap *gzmap, - bool (*poll)(const wmGizmo *, void *), - void *data, const eWM_GizmoFlag flag_exclude) +static GHash *WM_gizmomap_gizmo_hash_new(const bContext *C, + wmGizmoMap *gzmap, + bool (*poll)(const wmGizmo *, void *), + void *data, + const eWM_GizmoFlag flag_exclude) { - GHash *hash = BLI_ghash_ptr_new(__func__); - - /* collect gizmos */ - for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - if (WM_gizmo_group_type_poll(C, gzgroup->type)) { - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - if (((flag_exclude == 0) || ((gz->flag & flag_exclude) == 0)) && - (!poll || poll(gz, data))) - { - BLI_ghash_insert(hash, gz, gz); - } - } - } - } - - return hash; + GHash *hash = BLI_ghash_ptr_new(__func__); + + /* collect gizmos */ + for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + if (WM_gizmo_group_type_poll(C, gzgroup->type)) { + for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + if (((flag_exclude == 0) || ((gz->flag & flag_exclude) == 0)) && + (!poll || poll(gz, data))) { + BLI_ghash_insert(hash, gz, gz); + } + } + } + } + + return hash; } void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap) { - if (gzmap) { - /* We might want only to refresh some, for tag all steps. */ - for (int i = 0; i < WM_GIZMOMAP_DRAWSTEP_MAX; i++) { - gzmap->update_flag[i] |= ( - GIZMOMAP_IS_PREPARE_DRAW | - GIZMOMAP_IS_REFRESH_CALLBACK); - } - } + if (gzmap) { + /* We might want only to refresh some, for tag all steps. */ + for (int i = 0; i < WM_GIZMOMAP_DRAWSTEP_MAX; i++) { + gzmap->update_flag[i] |= (GIZMOMAP_IS_PREPARE_DRAW | GIZMOMAP_IS_REFRESH_CALLBACK); + } + } } -static bool gizmo_prepare_drawing( - wmGizmoMap *gzmap, wmGizmo *gz, - const bContext *C, ListBase *draw_gizmos, - const eWM_GizmoFlagMapDrawStep drawstep) +static bool gizmo_prepare_drawing(wmGizmoMap *gzmap, + wmGizmo *gz, + const bContext *C, + ListBase *draw_gizmos, + const eWM_GizmoFlagMapDrawStep drawstep) { - int do_draw = wm_gizmo_is_visible(gz); - if (do_draw == 0) { - /* skip */ - } - else { - /* Ensure we get RNA updates */ - if (do_draw & WM_GIZMO_IS_VISIBLE_UPDATE) { - /* hover gizmos need updating, even if we don't draw them */ - wm_gizmo_update(gz, C, (gzmap->update_flag[drawstep] & GIZMOMAP_IS_PREPARE_DRAW) != 0); - } - if (do_draw & WM_GIZMO_IS_VISIBLE_DRAW) { - BLI_addhead(draw_gizmos, BLI_genericNodeN(gz)); - } - return true; - } - - return false; + int do_draw = wm_gizmo_is_visible(gz); + if (do_draw == 0) { + /* skip */ + } + else { + /* Ensure we get RNA updates */ + if (do_draw & WM_GIZMO_IS_VISIBLE_UPDATE) { + /* hover gizmos need updating, even if we don't draw them */ + wm_gizmo_update(gz, C, (gzmap->update_flag[drawstep] & GIZMOMAP_IS_PREPARE_DRAW) != 0); + } + if (do_draw & WM_GIZMO_IS_VISIBLE_DRAW) { + BLI_addhead(draw_gizmos, BLI_genericNodeN(gz)); + } + return true; + } + + return false; } /** * Update gizmos of \a gzmap to prepare for drawing. Adds all gizmos that * should be drawn to list \a draw_gizmos, note that added items need freeing. */ -static void gizmomap_prepare_drawing( - wmGizmoMap *gzmap, const bContext *C, ListBase *draw_gizmos, - const eWM_GizmoFlagMapDrawStep drawstep) +static void gizmomap_prepare_drawing(wmGizmoMap *gzmap, + const bContext *C, + ListBase *draw_gizmos, + const eWM_GizmoFlagMapDrawStep drawstep) { - if (!gzmap || BLI_listbase_is_empty(&gzmap->groups)) { - return; - } - - gzmap->is_init = false; - - wmGizmo *gz_modal = gzmap->gzmap_context.modal; - - /* only active gizmo needs updating */ - if (gz_modal) { - if ((gz_modal->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0) { - if (wm_gizmogroup_is_visible_in_drawstep(gz_modal->parent_gzgroup, drawstep)) { - if (gizmo_prepare_drawing(gzmap, gz_modal, C, draw_gizmos, drawstep)) { - gzmap->update_flag[drawstep] &= ~GIZMOMAP_IS_PREPARE_DRAW; - } - } - /* don't draw any other gizmos */ - return; - } - } - - for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - /* check group visibility - drawstep first to avoid unnecessary call of group poll callback */ - if (!wm_gizmogroup_is_visible_in_drawstep(gzgroup, drawstep) || - !WM_gizmo_group_type_poll(C, gzgroup->type)) - { - continue; - } - - /* needs to be initialized on first draw */ - /* XXX weak: Gizmo-group may skip refreshing if it's invisible (map gets untagged nevertheless) */ - if (gzmap->update_flag[drawstep] & GIZMOMAP_IS_REFRESH_CALLBACK) { - /* force refresh again. */ - gzgroup->init_flag &= ~WM_GIZMOGROUP_INIT_REFRESH; - } - /* Calls `setup`, `setup_keymap` and `refresh` if they're defined. */ - WM_gizmogroup_ensure_init(C, gzgroup); - - /* prepare drawing */ - if (gzgroup->type->draw_prepare) { - gzgroup->type->draw_prepare(C, gzgroup); - } - - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - gizmo_prepare_drawing(gzmap, gz, C, draw_gizmos, drawstep); - } - } - - gzmap->update_flag[drawstep] &= - ~(GIZMOMAP_IS_REFRESH_CALLBACK | - GIZMOMAP_IS_PREPARE_DRAW); + if (!gzmap || BLI_listbase_is_empty(&gzmap->groups)) { + return; + } + + gzmap->is_init = false; + + wmGizmo *gz_modal = gzmap->gzmap_context.modal; + + /* only active gizmo needs updating */ + if (gz_modal) { + if ((gz_modal->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL) == 0) { + if (wm_gizmogroup_is_visible_in_drawstep(gz_modal->parent_gzgroup, drawstep)) { + if (gizmo_prepare_drawing(gzmap, gz_modal, C, draw_gizmos, drawstep)) { + gzmap->update_flag[drawstep] &= ~GIZMOMAP_IS_PREPARE_DRAW; + } + } + /* don't draw any other gizmos */ + return; + } + } + + for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + /* check group visibility - drawstep first to avoid unnecessary call of group poll callback */ + if (!wm_gizmogroup_is_visible_in_drawstep(gzgroup, drawstep) || + !WM_gizmo_group_type_poll(C, gzgroup->type)) { + continue; + } + + /* needs to be initialized on first draw */ + /* XXX weak: Gizmo-group may skip refreshing if it's invisible (map gets untagged nevertheless) */ + if (gzmap->update_flag[drawstep] & GIZMOMAP_IS_REFRESH_CALLBACK) { + /* force refresh again. */ + gzgroup->init_flag &= ~WM_GIZMOGROUP_INIT_REFRESH; + } + /* Calls `setup`, `setup_keymap` and `refresh` if they're defined. */ + WM_gizmogroup_ensure_init(C, gzgroup); + + /* prepare drawing */ + if (gzgroup->type->draw_prepare) { + gzgroup->type->draw_prepare(C, gzgroup); + } + + for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + gizmo_prepare_drawing(gzmap, gz, C, draw_gizmos, drawstep); + } + } + + gzmap->update_flag[drawstep] &= ~(GIZMOMAP_IS_REFRESH_CALLBACK | GIZMOMAP_IS_PREPARE_DRAW); } /** @@ -404,362 +397,366 @@ static void gizmomap_prepare_drawing( */ static void gizmos_draw_list(const wmGizmoMap *gzmap, const bContext *C, ListBase *draw_gizmos) { - /* Can be empty if we're dynamically added and removed. */ - if ((gzmap == NULL) || BLI_listbase_is_empty(&gzmap->groups)) { - return; - } - - /* TODO this will need it own shader probably? don't think it can be handled from that point though. */ -/* const bool use_lighting = (U.gizmo_flag & V3D_GIZMO_SHADED) != 0; */ - - bool is_depth_prev = false; - - /* draw_gizmos contains all visible gizmos - draw them */ - for (LinkData *link = draw_gizmos->first, *link_next; link; link = link_next) { - wmGizmo *gz = link->data; - link_next = link->next; - - bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0; - - /* Weak! since we don't 100% support depth yet (select ignores depth) always show highlighted */ - if (is_depth && (gz->state & WM_GIZMO_STATE_HIGHLIGHT)) { - is_depth = false; - } - - if (is_depth == is_depth_prev) { - /* pass */ - } - else { - if (is_depth) { - GPU_depth_test(true); - } - else { - GPU_depth_test(false); - } - is_depth_prev = is_depth; - } - - /* XXX force AntiAlias Gizmos. */ - GPU_line_smooth(true); - GPU_polygon_smooth(true); - - gz->type->draw(C, gz); - - GPU_line_smooth(false); - GPU_polygon_smooth(false); - - /* free/remove gizmo link after drawing */ - BLI_freelinkN(draw_gizmos, link); - } - - if (is_depth_prev) { - GPU_depth_test(false); - } + /* Can be empty if we're dynamically added and removed. */ + if ((gzmap == NULL) || BLI_listbase_is_empty(&gzmap->groups)) { + return; + } + + /* TODO this will need it own shader probably? don't think it can be handled from that point though. */ + /* const bool use_lighting = (U.gizmo_flag & V3D_GIZMO_SHADED) != 0; */ + + bool is_depth_prev = false; + + /* draw_gizmos contains all visible gizmos - draw them */ + for (LinkData *link = draw_gizmos->first, *link_next; link; link = link_next) { + wmGizmo *gz = link->data; + link_next = link->next; + + bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0; + + /* Weak! since we don't 100% support depth yet (select ignores depth) always show highlighted */ + if (is_depth && (gz->state & WM_GIZMO_STATE_HIGHLIGHT)) { + is_depth = false; + } + + if (is_depth == is_depth_prev) { + /* pass */ + } + else { + if (is_depth) { + GPU_depth_test(true); + } + else { + GPU_depth_test(false); + } + is_depth_prev = is_depth; + } + + /* XXX force AntiAlias Gizmos. */ + GPU_line_smooth(true); + GPU_polygon_smooth(true); + + gz->type->draw(C, gz); + + GPU_line_smooth(false); + GPU_polygon_smooth(false); + + /* free/remove gizmo link after drawing */ + BLI_freelinkN(draw_gizmos, link); + } + + if (is_depth_prev) { + GPU_depth_test(false); + } } -void WM_gizmomap_draw( - wmGizmoMap *gzmap, const bContext *C, - const eWM_GizmoFlagMapDrawStep drawstep) +void WM_gizmomap_draw(wmGizmoMap *gzmap, + const bContext *C, + const eWM_GizmoFlagMapDrawStep drawstep) { - if (!WM_gizmo_context_check_drawstep(C, drawstep)) { - return; - } + if (!WM_gizmo_context_check_drawstep(C, drawstep)) { + return; + } - ListBase draw_gizmos = {NULL}; + ListBase draw_gizmos = {NULL}; - gizmomap_prepare_drawing(gzmap, C, &draw_gizmos, drawstep); - gizmos_draw_list(gzmap, C, &draw_gizmos); - BLI_assert(BLI_listbase_is_empty(&draw_gizmos)); + gizmomap_prepare_drawing(gzmap, C, &draw_gizmos, drawstep); + gizmos_draw_list(gzmap, C, &draw_gizmos); + BLI_assert(BLI_listbase_is_empty(&draw_gizmos)); } -static void gizmo_draw_select_3D_loop( - const bContext *C, ListBase *visible_gizmos, - const wmGizmo *gz_stop) +static void gizmo_draw_select_3D_loop(const bContext *C, + ListBase *visible_gizmos, + const wmGizmo *gz_stop) { - int select_id = 0; - wmGizmo *gz; - - /* TODO(campbell): this depends on depth buffer being written to, currently broken for the 3D view. */ - bool is_depth_prev = false; - bool is_depth_skip_prev = false; - - for (LinkData *link = visible_gizmos->first; link; link = link->next, select_id++) { - gz = link->data; - if (gz == gz_stop) { - break; - } - if (gz->type->draw_select == NULL) { - continue; - } - - bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0; - if (is_depth == is_depth_prev) { - /* pass */ - } - else { - if (is_depth) { - GPU_depth_test(true); - } - else { - GPU_depth_test(false); - } - is_depth_prev = is_depth; - } - bool is_depth_skip = (gz->flag & WM_GIZMO_SELECT_BACKGROUND) != 0; - if (is_depth_skip == is_depth_skip_prev) { - /* pass */ - } - else { - glDepthMask(!is_depth_skip); - is_depth_skip_prev = is_depth_skip; - } - - /* pass the selection id shifted by 8 bits. Last 8 bits are used for selected gizmo part id */ - - gz->type->draw_select(C, gz, select_id << 8); - } - - if (is_depth_prev) { - GPU_depth_test(false); - } - if (is_depth_skip_prev) { - glDepthMask(true); - } + int select_id = 0; + wmGizmo *gz; + + /* TODO(campbell): this depends on depth buffer being written to, currently broken for the 3D view. */ + bool is_depth_prev = false; + bool is_depth_skip_prev = false; + + for (LinkData *link = visible_gizmos->first; link; link = link->next, select_id++) { + gz = link->data; + if (gz == gz_stop) { + break; + } + if (gz->type->draw_select == NULL) { + continue; + } + + bool is_depth = (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_DEPTH_3D) != 0; + if (is_depth == is_depth_prev) { + /* pass */ + } + else { + if (is_depth) { + GPU_depth_test(true); + } + else { + GPU_depth_test(false); + } + is_depth_prev = is_depth; + } + bool is_depth_skip = (gz->flag & WM_GIZMO_SELECT_BACKGROUND) != 0; + if (is_depth_skip == is_depth_skip_prev) { + /* pass */ + } + else { + glDepthMask(!is_depth_skip); + is_depth_skip_prev = is_depth_skip; + } + + /* pass the selection id shifted by 8 bits. Last 8 bits are used for selected gizmo part id */ + + gz->type->draw_select(C, gz, select_id << 8); + } + + if (is_depth_prev) { + GPU_depth_test(false); + } + if (is_depth_skip_prev) { + glDepthMask(true); + } } -static int gizmo_find_intersected_3d_intern( - ListBase *visible_gizmos, const bContext *C, const int co[2], - const int hotspot, const wmGizmo *gz_stop) +static int gizmo_find_intersected_3d_intern(ListBase *visible_gizmos, + const bContext *C, + const int co[2], + const int hotspot, + const wmGizmo *gz_stop) { - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = CTX_wm_region(C); - View3D *v3d = sa->spacedata.first; - rcti rect; - /* Almost certainly overkill, but allow for many custom gizmos. */ - GLuint buffer[MAXPICKBUF]; - short hits; + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + View3D *v3d = sa->spacedata.first; + rcti rect; + /* Almost certainly overkill, but allow for many custom gizmos. */ + GLuint buffer[MAXPICKBUF]; + short hits; - BLI_rcti_init_pt_radius(&rect, co, hotspot); + BLI_rcti_init_pt_radius(&rect, co, hotspot); - ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); + ED_view3d_draw_setup_view( + CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); - GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0); - /* do the drawing */ - gizmo_draw_select_3D_loop(C, visible_gizmos, gz_stop); + GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0); + /* do the drawing */ + gizmo_draw_select_3D_loop(C, visible_gizmos, gz_stop); - hits = GPU_select_end(); + hits = GPU_select_end(); - if (hits > 0) { - GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits); - gizmo_draw_select_3D_loop(C, visible_gizmos, gz_stop); - GPU_select_end(); - } + if (hits > 0) { + GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits); + gizmo_draw_select_3D_loop(C, visible_gizmos, gz_stop); + GPU_select_end(); + } - ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); + ED_view3d_draw_setup_view( + CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); - const GLuint *hit_near = GPU_select_buffer_near(buffer, hits); + const GLuint *hit_near = GPU_select_buffer_near(buffer, hits); - return hit_near ? hit_near[3] : -1; + return hit_near ? hit_near[3] : -1; } /** * Try to find a 3D gizmo at screen-space coordinate \a co. Uses OpenGL picking. */ -static wmGizmo *gizmo_find_intersected_3d( - bContext *C, const int co[2], ListBase *visible_gizmos, - int *r_part) +static wmGizmo *gizmo_find_intersected_3d(bContext *C, + const int co[2], + ListBase *visible_gizmos, + int *r_part) { - wmGizmo *result = NULL; - int hit = -1; - - *r_part = 0; - - /* set up view matrices */ - view3d_operator_needs_opengl(C); - - /* Search for 3D gizmo's that use the 2D callback for checking intersections. */ - bool has_3d = false; - { - int select_id = 0; - for (LinkData *link = visible_gizmos->first; link; link = link->next, select_id++) { - wmGizmo *gz = link->data; - /* With both defined, favor the 3D, incase the gizmo can be used in 2D or 3D views. */ - if (gz->type->test_select && (gz->type->draw_select == NULL)) { - if ((*r_part = gz->type->test_select(C, gz, co)) != -1) { - hit = select_id; - result = gz; - break; - } - } - else { - has_3d = true; - } - } - } - - /* Search for 3D intersections if they're before 2D that have been found (if any). - * This way we always use the first hit. */ - if (has_3d) { - const int hotspot_radii[] = { - 3 * U.pixelsize, - /* This runs on mouse move, careful doing too many tests! */ - 10 * U.pixelsize, - }; - for (int i = 0; i < ARRAY_SIZE(hotspot_radii); i++) { - hit = gizmo_find_intersected_3d_intern(visible_gizmos, C, co, hotspot_radii[i], result); - if (hit != -1) { - break; - } - } - - if (hit != -1) { - LinkData *link = BLI_findlink(visible_gizmos, hit >> 8); - if (link != NULL) { - *r_part = hit & 255; - result = link->data; - } - else { - /* All gizmos should use selection ID they're given as part of the callback, - * if they don't it will attempt tp lookup non-existing index. */ - BLI_assert(0); - } - } - } - - return result; + wmGizmo *result = NULL; + int hit = -1; + + *r_part = 0; + + /* set up view matrices */ + view3d_operator_needs_opengl(C); + + /* Search for 3D gizmo's that use the 2D callback for checking intersections. */ + bool has_3d = false; + { + int select_id = 0; + for (LinkData *link = visible_gizmos->first; link; link = link->next, select_id++) { + wmGizmo *gz = link->data; + /* With both defined, favor the 3D, incase the gizmo can be used in 2D or 3D views. */ + if (gz->type->test_select && (gz->type->draw_select == NULL)) { + if ((*r_part = gz->type->test_select(C, gz, co)) != -1) { + hit = select_id; + result = gz; + break; + } + } + else { + has_3d = true; + } + } + } + + /* Search for 3D intersections if they're before 2D that have been found (if any). + * This way we always use the first hit. */ + if (has_3d) { + const int hotspot_radii[] = { + 3 * U.pixelsize, + /* This runs on mouse move, careful doing too many tests! */ + 10 * U.pixelsize, + }; + for (int i = 0; i < ARRAY_SIZE(hotspot_radii); i++) { + hit = gizmo_find_intersected_3d_intern(visible_gizmos, C, co, hotspot_radii[i], result); + if (hit != -1) { + break; + } + } + + if (hit != -1) { + LinkData *link = BLI_findlink(visible_gizmos, hit >> 8); + if (link != NULL) { + *r_part = hit & 255; + result = link->data; + } + else { + /* All gizmos should use selection ID they're given as part of the callback, + * if they don't it will attempt tp lookup non-existing index. */ + BLI_assert(0); + } + } + } + + return result; } /** * Try to find a gizmo under the mouse position. 2D intersections have priority over * 3D ones (could check for smallest screen-space distance but not needed right now). */ -wmGizmo *wm_gizmomap_highlight_find( - wmGizmoMap *gzmap, bContext *C, const wmEvent *event, - int *r_part) +wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap, + bContext *C, + const wmEvent *event, + int *r_part) { - wmGizmo *gz = NULL; - ListBase visible_3d_gizmos = {NULL}; - bool do_step[WM_GIZMOMAP_DRAWSTEP_MAX]; - - for (int i = 0; i < ARRAY_SIZE(do_step); i++) { - do_step[i] = WM_gizmo_context_check_drawstep(C, i); - } - - for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - - /* If it were important we could initialize here, - * but this only happens when events are handled before drawing, - * just skip to keep code-path for initializing gizmos simple. */ - if ((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0) { - continue; - } - - if (WM_gizmo_group_type_poll(C, gzgroup->type)) { - eWM_GizmoFlagMapDrawStep step; - if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { - step = WM_GIZMOMAP_DRAWSTEP_3D; - } - else { - step = WM_GIZMOMAP_DRAWSTEP_2D; - } - - if (do_step[step]) { - if ((gzmap->update_flag[step] & GIZMOMAP_IS_REFRESH_CALLBACK) && - (gzgroup->type->refresh != NULL)) - { - gzgroup->type->refresh(C, gzgroup); - /* cleared below */ - } - if (step == WM_GIZMOMAP_DRAWSTEP_3D) { - wm_gizmogroup_intersectable_gizmos_to_list(gzgroup, &visible_3d_gizmos); - } - else if (step == WM_GIZMOMAP_DRAWSTEP_2D) { - if ((gz = wm_gizmogroup_find_intersected_gizmo(gzgroup, C, event, r_part))) { - break; - } - } - } - } - } - - if (!BLI_listbase_is_empty(&visible_3d_gizmos)) { - /* 2D gizmos get priority. */ - if (gz == NULL) { - gz = gizmo_find_intersected_3d(C, event->mval, &visible_3d_gizmos, r_part); - } - BLI_freelistN(&visible_3d_gizmos); - } - - gzmap->update_flag[WM_GIZMOMAP_DRAWSTEP_3D] &= ~GIZMOMAP_IS_REFRESH_CALLBACK; - gzmap->update_flag[WM_GIZMOMAP_DRAWSTEP_2D] &= ~GIZMOMAP_IS_REFRESH_CALLBACK; - - return gz; + wmGizmo *gz = NULL; + ListBase visible_3d_gizmos = {NULL}; + bool do_step[WM_GIZMOMAP_DRAWSTEP_MAX]; + + for (int i = 0; i < ARRAY_SIZE(do_step); i++) { + do_step[i] = WM_gizmo_context_check_drawstep(C, i); + } + + for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + + /* If it were important we could initialize here, + * but this only happens when events are handled before drawing, + * just skip to keep code-path for initializing gizmos simple. */ + if ((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0) { + continue; + } + + if (WM_gizmo_group_type_poll(C, gzgroup->type)) { + eWM_GizmoFlagMapDrawStep step; + if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) { + step = WM_GIZMOMAP_DRAWSTEP_3D; + } + else { + step = WM_GIZMOMAP_DRAWSTEP_2D; + } + + if (do_step[step]) { + if ((gzmap->update_flag[step] & GIZMOMAP_IS_REFRESH_CALLBACK) && + (gzgroup->type->refresh != NULL)) { + gzgroup->type->refresh(C, gzgroup); + /* cleared below */ + } + if (step == WM_GIZMOMAP_DRAWSTEP_3D) { + wm_gizmogroup_intersectable_gizmos_to_list(gzgroup, &visible_3d_gizmos); + } + else if (step == WM_GIZMOMAP_DRAWSTEP_2D) { + if ((gz = wm_gizmogroup_find_intersected_gizmo(gzgroup, C, event, r_part))) { + break; + } + } + } + } + } + + if (!BLI_listbase_is_empty(&visible_3d_gizmos)) { + /* 2D gizmos get priority. */ + if (gz == NULL) { + gz = gizmo_find_intersected_3d(C, event->mval, &visible_3d_gizmos, r_part); + } + BLI_freelistN(&visible_3d_gizmos); + } + + gzmap->update_flag[WM_GIZMOMAP_DRAWSTEP_3D] &= ~GIZMOMAP_IS_REFRESH_CALLBACK; + gzmap->update_flag[WM_GIZMOMAP_DRAWSTEP_2D] &= ~GIZMOMAP_IS_REFRESH_CALLBACK; + + return gz; } void WM_gizmomap_add_handlers(ARegion *ar, wmGizmoMap *gzmap) { - LISTBASE_FOREACH (wmEventHandler *, handler_base, &ar->handlers) { - if (handler_base->type == WM_HANDLER_TYPE_GIZMO) { - wmEventHandler_Gizmo *handler = (wmEventHandler_Gizmo *)handler_base; - if (handler->gizmo_map == gzmap) { - return; - } - } - } - - wmEventHandler_Gizmo *handler = MEM_callocN(sizeof(*handler), __func__); - handler->head.type = WM_HANDLER_TYPE_GIZMO; - BLI_assert(gzmap == ar->gizmo_map); - handler->gizmo_map = gzmap; - BLI_addtail(&ar->handlers, handler); + LISTBASE_FOREACH (wmEventHandler *, handler_base, &ar->handlers) { + if (handler_base->type == WM_HANDLER_TYPE_GIZMO) { + wmEventHandler_Gizmo *handler = (wmEventHandler_Gizmo *)handler_base; + if (handler->gizmo_map == gzmap) { + return; + } + } + } + + wmEventHandler_Gizmo *handler = MEM_callocN(sizeof(*handler), __func__); + handler->head.type = WM_HANDLER_TYPE_GIZMO; + BLI_assert(gzmap == ar->gizmo_map); + handler->gizmo_map = gzmap; + BLI_addtail(&ar->handlers, handler); } -void wm_gizmomaps_handled_modal_update( - bContext *C, wmEvent *event, wmEventHandler_Op *handler) +void wm_gizmomaps_handled_modal_update(bContext *C, wmEvent *event, wmEventHandler_Op *handler) { - const bool modal_running = (handler->op != NULL); - - /* happens on render or when joining areas */ - if (!handler->context.region || !handler->context.region->gizmo_map) { - return; - } - - wmGizmoMap *gzmap = handler->context.region->gizmo_map; - wmGizmo *gz = wm_gizmomap_modal_get(gzmap); - ScrArea *area = CTX_wm_area(C); - ARegion *region = CTX_wm_region(C); - - wm_gizmomap_handler_context_op(C, handler); - - /* regular update for running operator */ - if (modal_running) { - wmGizmoOpElem *gzop = gz ? WM_gizmo_operator_get(gz, gz->highlight_part) : NULL; - if (gz && gzop && (gzop->type != NULL) && (gzop->type == handler->op->type)) { - wmGizmoFnModal modal_fn = gz->custom_modal ? gz->custom_modal : gz->type->modal; - if (modal_fn != NULL) { - int retval = modal_fn(C, gz, event, 0); - /* The gizmo is tried to the operator, we can't choose when to exit. */ - BLI_assert(retval & OPERATOR_RUNNING_MODAL); - UNUSED_VARS_NDEBUG(retval); - } - } - } - /* operator not running anymore */ - else { - wm_gizmomap_highlight_set(gzmap, C, NULL, 0); - if (gz) { - /* This isn't defined if it ends because of success of cancel, we may want to change. */ - bool cancel = true; - if (gz->type->exit) { - gz->type->exit(C, gz, cancel); - } - wm_gizmomap_modal_set(gzmap, C, gz, NULL, false); - } - } - - /* restore the area */ - CTX_wm_area_set(C, area); - CTX_wm_region_set(C, region); + const bool modal_running = (handler->op != NULL); + + /* happens on render or when joining areas */ + if (!handler->context.region || !handler->context.region->gizmo_map) { + return; + } + + wmGizmoMap *gzmap = handler->context.region->gizmo_map; + wmGizmo *gz = wm_gizmomap_modal_get(gzmap); + ScrArea *area = CTX_wm_area(C); + ARegion *region = CTX_wm_region(C); + + wm_gizmomap_handler_context_op(C, handler); + + /* regular update for running operator */ + if (modal_running) { + wmGizmoOpElem *gzop = gz ? WM_gizmo_operator_get(gz, gz->highlight_part) : NULL; + if (gz && gzop && (gzop->type != NULL) && (gzop->type == handler->op->type)) { + wmGizmoFnModal modal_fn = gz->custom_modal ? gz->custom_modal : gz->type->modal; + if (modal_fn != NULL) { + int retval = modal_fn(C, gz, event, 0); + /* The gizmo is tried to the operator, we can't choose when to exit. */ + BLI_assert(retval & OPERATOR_RUNNING_MODAL); + UNUSED_VARS_NDEBUG(retval); + } + } + } + /* operator not running anymore */ + else { + wm_gizmomap_highlight_set(gzmap, C, NULL, 0); + if (gz) { + /* This isn't defined if it ends because of success of cancel, we may want to change. */ + bool cancel = true; + if (gz->type->exit) { + gz->type->exit(C, gz, cancel); + } + wm_gizmomap_modal_set(gzmap, C, gz, NULL, false); + } + } + + /* restore the area */ + CTX_wm_area_set(C, area); + CTX_wm_region_set(C, region); } /** @@ -768,59 +765,59 @@ void wm_gizmomaps_handled_modal_update( */ bool wm_gizmomap_deselect_all(wmGizmoMap *gzmap) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - if (msel->items == NULL || msel->len == 0) { - return false; - } + if (msel->items == NULL || msel->len == 0) { + return false; + } - for (int i = 0; i < msel->len; i++) { - wm_gizmo_select_set_ex(gzmap, msel->items[i], false, false, true); - } + for (int i = 0; i < msel->len; i++) { + wm_gizmo_select_set_ex(gzmap, msel->items[i], false, false, true); + } - wm_gizmomap_select_array_clear(gzmap); + wm_gizmomap_select_array_clear(gzmap); - /* always return true, we already checked - * if there's anything to deselect */ - return true; + /* always return true, we already checked + * if there's anything to deselect */ + return true; } BLI_INLINE bool gizmo_selectable_poll(const wmGizmo *gz, void *UNUSED(data)) { - return (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_SELECT); + return (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_SELECT); } /** * Select all selectable gizmos in \a gzmap. * \return if selection has changed. */ -static bool wm_gizmomap_select_all_intern( - bContext *C, wmGizmoMap *gzmap) +static bool wm_gizmomap_select_all_intern(bContext *C, wmGizmoMap *gzmap) { - wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; - /* GHash is used here to avoid having to loop over all gizmos twice (once to - * get tot_sel for allocating, once for actually selecting). Instead we collect - * selectable gizmos in hash table and use this to get tot_sel and do selection */ - - GHash *hash = WM_gizmomap_gizmo_hash_new( - C, gzmap, gizmo_selectable_poll, NULL, WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT); - GHashIterator gh_iter; - int i; - bool changed = false; - - wm_gizmomap_select_array_ensure_len_alloc(gzmap, BLI_ghash_len(hash)); - - GHASH_ITER_INDEX (gh_iter, hash, i) { - wmGizmo *gz_iter = BLI_ghashIterator_getValue(&gh_iter); - WM_gizmo_select_set(gzmap, gz_iter, true); - } - /* highlight first gizmo */ - wm_gizmomap_highlight_set(gzmap, C, msel->items[0], msel->items[0]->highlight_part); - - BLI_assert(BLI_ghash_len(hash) == msel->len); - - BLI_ghash_free(hash, NULL, NULL); - return changed; + wmGizmoMapSelectState *msel = &gzmap->gzmap_context.select; + /* GHash is used here to avoid having to loop over all gizmos twice (once to + * get tot_sel for allocating, once for actually selecting). Instead we collect + * selectable gizmos in hash table and use this to get tot_sel and do selection */ + + GHash *hash = WM_gizmomap_gizmo_hash_new( + C, gzmap, gizmo_selectable_poll, NULL, WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT); + GHashIterator gh_iter; + int i; + bool changed = false; + + wm_gizmomap_select_array_ensure_len_alloc(gzmap, BLI_ghash_len(hash)); + + GHASH_ITER_INDEX(gh_iter, hash, i) + { + wmGizmo *gz_iter = BLI_ghashIterator_getValue(&gh_iter); + WM_gizmo_select_set(gzmap, gz_iter, true); + } + /* highlight first gizmo */ + wm_gizmomap_highlight_set(gzmap, C, msel->items[0], msel->items[0]->highlight_part); + + BLI_assert(BLI_ghash_len(hash) == msel->len); + + BLI_ghash_free(hash, NULL, NULL); + return changed; } /** @@ -831,25 +828,25 @@ static bool wm_gizmomap_select_all_intern( */ bool WM_gizmomap_select_all(bContext *C, wmGizmoMap *gzmap, const int action) { - bool changed = false; - - switch (action) { - case SEL_SELECT: - changed = wm_gizmomap_select_all_intern(C, gzmap); - break; - case SEL_DESELECT: - changed = wm_gizmomap_deselect_all(gzmap); - break; - default: - BLI_assert(0); - break; - } - - if (changed) { - WM_event_add_mousemove(C); - } - - return changed; + bool changed = false; + + switch (action) { + case SEL_SELECT: + changed = wm_gizmomap_select_all_intern(C, gzmap); + break; + case SEL_DESELECT: + changed = wm_gizmomap_deselect_all(gzmap); + break; + default: + BLI_assert(0); + break; + } + + if (changed) { + WM_event_add_mousemove(C); + } + + return changed; } /** @@ -858,244 +855,240 @@ bool WM_gizmomap_select_all(bContext *C, wmGizmoMap *gzmap, const int action) */ void wm_gizmomap_handler_context_op(bContext *C, wmEventHandler_Op *handler) { - bScreen *screen = CTX_wm_screen(C); - - if (screen) { - ScrArea *sa; - - for (sa = screen->areabase.first; sa; sa = sa->next) { - if (sa == handler->context.area) { - break; - } - } - if (sa == NULL) { - /* when changing screen layouts with running modal handlers (like render display), this - * is not an error to print */ - printf("internal error: modal gizmo-map handler has invalid area\n"); - } - else { - ARegion *ar; - CTX_wm_area_set(C, sa); - for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar == handler->context.region) { - break; - } - } - /* XXX no warning print here, after full-area and back regions are remade */ - if (ar) { - CTX_wm_region_set(C, ar); - } - } - } + bScreen *screen = CTX_wm_screen(C); + + if (screen) { + ScrArea *sa; + + for (sa = screen->areabase.first; sa; sa = sa->next) { + if (sa == handler->context.area) { + break; + } + } + if (sa == NULL) { + /* when changing screen layouts with running modal handlers (like render display), this + * is not an error to print */ + printf("internal error: modal gizmo-map handler has invalid area\n"); + } + else { + ARegion *ar; + CTX_wm_area_set(C, sa); + for (ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar == handler->context.region) { + break; + } + } + /* XXX no warning print here, after full-area and back regions are remade */ + if (ar) { + CTX_wm_region_set(C, ar); + } + } + } } void wm_gizmomap_handler_context_gizmo(bContext *UNUSED(C), wmEventHandler_Gizmo *UNUSED(handler)) { - /* pass */ + /* pass */ } bool WM_gizmomap_cursor_set(const wmGizmoMap *gzmap, wmWindow *win) { - wmGizmo *gz = gzmap->gzmap_context.highlight; - if (gz && gz->type->cursor_get) { - WM_cursor_set(win, gz->type->cursor_get(gz)); - return true; - } + wmGizmo *gz = gzmap->gzmap_context.highlight; + if (gz && gz->type->cursor_get) { + WM_cursor_set(win, gz->type->cursor_get(gz)); + return true; + } - return false; + return false; } -bool wm_gizmomap_highlight_set( - wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part) +bool wm_gizmomap_highlight_set(wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part) { - if ((gz != gzmap->gzmap_context.highlight) || - (gz && part != gz->highlight_part)) - { - if (gzmap->gzmap_context.highlight) { - gzmap->gzmap_context.highlight->state &= ~WM_GIZMO_STATE_HIGHLIGHT; - gzmap->gzmap_context.highlight->highlight_part = -1; - } - - gzmap->gzmap_context.highlight = gz; - - if (gz) { - gz->state |= WM_GIZMO_STATE_HIGHLIGHT; - gz->highlight_part = part; - gzmap->gzmap_context.last_cursor = -1; - - if (C && gz->type->cursor_get) { - wmWindow *win = CTX_wm_window(C); - gzmap->gzmap_context.last_cursor = win->cursor; - WM_cursor_set(win, gz->type->cursor_get(gz)); - } - } - else { - if (C && gzmap->gzmap_context.last_cursor != -1) { - wmWindow *win = CTX_wm_window(C); - WM_cursor_set(win, gzmap->gzmap_context.last_cursor); - } - } - - /* tag the region for redraw */ - if (C) { - ARegion *ar = CTX_wm_region(C); - ED_region_tag_redraw(ar); - } - - return true; - } - - return false; + if ((gz != gzmap->gzmap_context.highlight) || (gz && part != gz->highlight_part)) { + if (gzmap->gzmap_context.highlight) { + gzmap->gzmap_context.highlight->state &= ~WM_GIZMO_STATE_HIGHLIGHT; + gzmap->gzmap_context.highlight->highlight_part = -1; + } + + gzmap->gzmap_context.highlight = gz; + + if (gz) { + gz->state |= WM_GIZMO_STATE_HIGHLIGHT; + gz->highlight_part = part; + gzmap->gzmap_context.last_cursor = -1; + + if (C && gz->type->cursor_get) { + wmWindow *win = CTX_wm_window(C); + gzmap->gzmap_context.last_cursor = win->cursor; + WM_cursor_set(win, gz->type->cursor_get(gz)); + } + } + else { + if (C && gzmap->gzmap_context.last_cursor != -1) { + wmWindow *win = CTX_wm_window(C); + WM_cursor_set(win, gzmap->gzmap_context.last_cursor); + } + } + + /* tag the region for redraw */ + if (C) { + ARegion *ar = CTX_wm_region(C); + ED_region_tag_redraw(ar); + } + + return true; + } + + return false; } wmGizmo *wm_gizmomap_highlight_get(wmGizmoMap *gzmap) { - return gzmap->gzmap_context.highlight; + return gzmap->gzmap_context.highlight; } /** * Caller should call exit when (enable == False). */ void wm_gizmomap_modal_set( - wmGizmoMap *gzmap, bContext *C, wmGizmo *gz, const wmEvent *event, bool enable) + wmGizmoMap *gzmap, bContext *C, wmGizmo *gz, const wmEvent *event, bool enable) { - if (enable) { - BLI_assert(gzmap->gzmap_context.modal == NULL); - wmWindow *win = CTX_wm_window(C); - - WM_tooltip_clear(C, win); - - /* Use even if we don't have invoke, so we can setup data before an operator runs. */ - if (gz->parent_gzgroup->type->invoke_prepare) { - gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); - } - - if (gz->type->invoke && - (gz->type->modal || gz->custom_modal)) - { - const int retval = gz->type->invoke(C, gz, event); - if ((retval & OPERATOR_RUNNING_MODAL) == 0) { - return; - } - } - - gz->state |= WM_GIZMO_STATE_MODAL; - gzmap->gzmap_context.modal = gz; - - if ((gz->flag & WM_GIZMO_MOVE_CURSOR) && - (event->is_motion_absolute == false)) - { - WM_cursor_grab_enable(win, true, true, NULL); - copy_v2_v2_int(gzmap->gzmap_context.event_xy, &event->x); - gzmap->gzmap_context.event_grabcursor = win->grabcursor; - } - else { - gzmap->gzmap_context.event_xy[0] = INT_MAX; - } - - struct wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); - if (gzop && gzop->type) { - const int retval = WM_gizmo_operator_invoke(C, gz, gzop); - if ((retval & OPERATOR_RUNNING_MODAL) == 0) { - wm_gizmomap_modal_set(gzmap, C, gz, event, false); - } - - /* we failed to hook the gizmo to the operator handler or operator was cancelled, return */ - if (!gzmap->gzmap_context.modal) { - gz->state &= ~WM_GIZMO_STATE_MODAL; - MEM_SAFE_FREE(gz->interaction_data); - } - return; - } - } - else { - BLI_assert(ELEM(gzmap->gzmap_context.modal, NULL, gz)); - - /* deactivate, gizmo but first take care of some stuff */ - if (gz) { - gz->state &= ~WM_GIZMO_STATE_MODAL; - MEM_SAFE_FREE(gz->interaction_data); - } - gzmap->gzmap_context.modal = NULL; - - if (C) { - wmWindow *win = CTX_wm_window(C); - if (gzmap->gzmap_context.event_xy[0] != INT_MAX) { - /* Check if some other part of Blender (typically operators) - * have adjusted the grab mode since it was set. - * If so: warp, so we have a predictable outcome. */ - if (gzmap->gzmap_context.event_grabcursor == win->grabcursor) { - WM_cursor_grab_disable(win, gzmap->gzmap_context.event_xy); - } - else { - WM_cursor_warp(win, UNPACK2(gzmap->gzmap_context.event_xy)); - } - } - ED_region_tag_redraw(CTX_wm_region(C)); - WM_event_add_mousemove(C); - } - - gzmap->gzmap_context.event_xy[0] = INT_MAX; - } + if (enable) { + BLI_assert(gzmap->gzmap_context.modal == NULL); + wmWindow *win = CTX_wm_window(C); + + WM_tooltip_clear(C, win); + + /* Use even if we don't have invoke, so we can setup data before an operator runs. */ + if (gz->parent_gzgroup->type->invoke_prepare) { + gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); + } + + if (gz->type->invoke && (gz->type->modal || gz->custom_modal)) { + const int retval = gz->type->invoke(C, gz, event); + if ((retval & OPERATOR_RUNNING_MODAL) == 0) { + return; + } + } + + gz->state |= WM_GIZMO_STATE_MODAL; + gzmap->gzmap_context.modal = gz; + + if ((gz->flag & WM_GIZMO_MOVE_CURSOR) && (event->is_motion_absolute == false)) { + WM_cursor_grab_enable(win, true, true, NULL); + copy_v2_v2_int(gzmap->gzmap_context.event_xy, &event->x); + gzmap->gzmap_context.event_grabcursor = win->grabcursor; + } + else { + gzmap->gzmap_context.event_xy[0] = INT_MAX; + } + + struct wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part); + if (gzop && gzop->type) { + const int retval = WM_gizmo_operator_invoke(C, gz, gzop); + if ((retval & OPERATOR_RUNNING_MODAL) == 0) { + wm_gizmomap_modal_set(gzmap, C, gz, event, false); + } + + /* we failed to hook the gizmo to the operator handler or operator was cancelled, return */ + if (!gzmap->gzmap_context.modal) { + gz->state &= ~WM_GIZMO_STATE_MODAL; + MEM_SAFE_FREE(gz->interaction_data); + } + return; + } + } + else { + BLI_assert(ELEM(gzmap->gzmap_context.modal, NULL, gz)); + + /* deactivate, gizmo but first take care of some stuff */ + if (gz) { + gz->state &= ~WM_GIZMO_STATE_MODAL; + MEM_SAFE_FREE(gz->interaction_data); + } + gzmap->gzmap_context.modal = NULL; + + if (C) { + wmWindow *win = CTX_wm_window(C); + if (gzmap->gzmap_context.event_xy[0] != INT_MAX) { + /* Check if some other part of Blender (typically operators) + * have adjusted the grab mode since it was set. + * If so: warp, so we have a predictable outcome. */ + if (gzmap->gzmap_context.event_grabcursor == win->grabcursor) { + WM_cursor_grab_disable(win, gzmap->gzmap_context.event_xy); + } + else { + WM_cursor_warp(win, UNPACK2(gzmap->gzmap_context.event_xy)); + } + } + ED_region_tag_redraw(CTX_wm_region(C)); + WM_event_add_mousemove(C); + } + + gzmap->gzmap_context.event_xy[0] = INT_MAX; + } } wmGizmo *wm_gizmomap_modal_get(wmGizmoMap *gzmap) { - return gzmap->gzmap_context.modal; + return gzmap->gzmap_context.modal; } wmGizmo **wm_gizmomap_selected_get(wmGizmoMap *gzmap, int *r_selected_len) { - *r_selected_len = gzmap->gzmap_context.select.len; - return gzmap->gzmap_context.select.items; + *r_selected_len = gzmap->gzmap_context.select.len; + return gzmap->gzmap_context.select.items; } ListBase *wm_gizmomap_groups_get(wmGizmoMap *gzmap) { - return &gzmap->groups; + return &gzmap->groups; } -void WM_gizmomap_message_subscribe( - bContext *C, wmGizmoMap *gzmap, ARegion *ar, struct wmMsgBus *mbus) +void WM_gizmomap_message_subscribe(bContext *C, + wmGizmoMap *gzmap, + ARegion *ar, + struct wmMsgBus *mbus) { - for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - if ((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0 || - !WM_gizmo_group_type_poll(C, gzgroup->type)) - { - continue; - } - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { - if (gz->flag & WM_GIZMO_HIDDEN) { - continue; - } - WM_gizmo_target_property_subscribe_all(gz, mbus, ar); - } - if (gzgroup->type->message_subscribe != NULL) { - gzgroup->type->message_subscribe(C, gzgroup, mbus); - } - } + for (wmGizmoGroup *gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + if ((gzgroup->init_flag & WM_GIZMOGROUP_INIT_SETUP) == 0 || + !WM_gizmo_group_type_poll(C, gzgroup->type)) { + continue; + } + for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + if (gz->flag & WM_GIZMO_HIDDEN) { + continue; + } + WM_gizmo_target_property_subscribe_all(gz, mbus, ar); + } + if (gzgroup->type->message_subscribe != NULL) { + gzgroup->type->message_subscribe(C, gzgroup, mbus); + } + } } /** \} */ /* wmGizmoMap */ - /* -------------------------------------------------------------------- */ /** \name Tooltip Handling * * \{ */ -struct ARegion *WM_gizmomap_tooltip_init( - struct bContext *C, struct ARegion *ar, int *UNUSED(r_pass), double *UNUSED(pass_delay), bool *r_exit_on_event) +struct ARegion *WM_gizmomap_tooltip_init(struct bContext *C, + struct ARegion *ar, + int *UNUSED(r_pass), + double *UNUSED(pass_delay), + bool *r_exit_on_event) { - wmGizmoMap *gzmap = ar->gizmo_map; - *r_exit_on_event = true; - if (gzmap) { - wmGizmo *gz = gzmap->gzmap_context.highlight; - if (gz) { - return UI_tooltip_create_from_gizmo(C, gz); - } - } - return NULL; + wmGizmoMap *gzmap = ar->gizmo_map; + *r_exit_on_event = true; + if (gzmap) { + wmGizmo *gz = gzmap->gzmap_context.highlight; + if (gz) { + return UI_tooltip_create_from_gizmo(C, gz); + } + } + return NULL; } /** \} */ /* wmGizmoMapType */ @@ -1105,53 +1098,47 @@ struct ARegion *WM_gizmomap_tooltip_init( * * \{ */ -wmGizmoMapType *WM_gizmomaptype_find( - const struct wmGizmoMapType_Params *gzmap_params) +wmGizmoMapType *WM_gizmomaptype_find(const struct wmGizmoMapType_Params *gzmap_params) { - for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; gzmap_type = gzmap_type->next) { - if (gzmap_type->spaceid == gzmap_params->spaceid && - gzmap_type->regionid == gzmap_params->regionid) - { - return gzmap_type; - } - } - - return NULL; + for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; + gzmap_type = gzmap_type->next) { + if (gzmap_type->spaceid == gzmap_params->spaceid && + gzmap_type->regionid == gzmap_params->regionid) { + return gzmap_type; + } + } + + return NULL; } -wmGizmoMapType *WM_gizmomaptype_ensure( - const struct wmGizmoMapType_Params *gzmap_params) +wmGizmoMapType *WM_gizmomaptype_ensure(const struct wmGizmoMapType_Params *gzmap_params) { - wmGizmoMapType *gzmap_type = WM_gizmomaptype_find(gzmap_params); + wmGizmoMapType *gzmap_type = WM_gizmomaptype_find(gzmap_params); - if (gzmap_type) { - return gzmap_type; - } + if (gzmap_type) { + return gzmap_type; + } - gzmap_type = MEM_callocN(sizeof(wmGizmoMapType), "gizmotype list"); - gzmap_type->spaceid = gzmap_params->spaceid; - gzmap_type->regionid = gzmap_params->regionid; - BLI_addhead(&gizmomaptypes, gzmap_type); + gzmap_type = MEM_callocN(sizeof(wmGizmoMapType), "gizmotype list"); + gzmap_type->spaceid = gzmap_params->spaceid; + gzmap_type->regionid = gzmap_params->regionid; + BLI_addhead(&gizmomaptypes, gzmap_type); - return gzmap_type; + return gzmap_type; } void wm_gizmomaptypes_free(void) { - for (wmGizmoMapType *gzmap_type = gizmomaptypes.first, *gzmap_type_next; - gzmap_type; - gzmap_type = gzmap_type_next) - { - gzmap_type_next = gzmap_type->next; - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first, *gzgt_next; - gzgt_ref; - gzgt_ref = gzgt_next) - { - gzgt_next = gzgt_ref->next; - WM_gizmomaptype_group_free(gzgt_ref); - } - MEM_freeN(gzmap_type); - } + for (wmGizmoMapType *gzmap_type = gizmomaptypes.first, *gzmap_type_next; gzmap_type; + gzmap_type = gzmap_type_next) { + gzmap_type_next = gzmap_type->next; + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first, *gzgt_next; gzgt_ref; + gzgt_ref = gzgt_next) { + gzgt_next = gzgt_ref->next; + WM_gizmomaptype_group_free(gzgt_ref); + } + MEM_freeN(gzmap_type); + } } /** @@ -1159,14 +1146,16 @@ void wm_gizmomaptypes_free(void) */ void wm_gizmos_keymap(wmKeyConfig *keyconf) { - /* we add this item-less keymap once and use it to group gizmo-group keymaps into it */ - WM_keymap_ensure(keyconf, "Gizmos", 0, 0); - - for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; gzmap_type = gzmap_type->next) { - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; gzgt_ref = gzgt_ref->next) { - wm_gizmogrouptype_setup_keymap(gzgt_ref->type, keyconf); - } - } + /* we add this item-less keymap once and use it to group gizmo-group keymaps into it */ + WM_keymap_ensure(keyconf, "Gizmos", 0, 0); + + for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; + gzmap_type = gzmap_type->next) { + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; + gzgt_ref = gzgt_ref->next) { + wm_gizmogrouptype_setup_keymap(gzgt_ref->type, keyconf); + } + } } /** \} */ /* wmGizmoMapType */ @@ -1176,25 +1165,22 @@ void wm_gizmos_keymap(wmKeyConfig *keyconf) * * \{ */ - -void WM_gizmoconfig_update_tag_init( - wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt) +void WM_gizmoconfig_update_tag_init(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt) { - /* tag for update on next use */ - gzmap_type->type_update_flag |= (WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT); - gzgt->type_update_flag |= (WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT); + /* tag for update on next use */ + gzmap_type->type_update_flag |= (WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT); + gzgt->type_update_flag |= (WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT); - wm_gzmap_type_update_flag |= WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT; + wm_gzmap_type_update_flag |= WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT; } -void WM_gizmoconfig_update_tag_remove( - wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt) +void WM_gizmoconfig_update_tag_remove(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt) { - /* tag for update on next use */ - gzmap_type->type_update_flag |= WM_GIZMOMAPTYPE_UPDATE_REMOVE; - gzgt->type_update_flag |= WM_GIZMOMAPTYPE_UPDATE_REMOVE; + /* tag for update on next use */ + gzmap_type->type_update_flag |= WM_GIZMOMAPTYPE_UPDATE_REMOVE; + gzgt->type_update_flag |= WM_GIZMOMAPTYPE_UPDATE_REMOVE; - wm_gzmap_type_update_flag |= WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE; + wm_gzmap_type_update_flag |= WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE; } /** @@ -1203,64 +1189,57 @@ void WM_gizmoconfig_update_tag_remove( */ void WM_gizmoconfig_update(struct Main *bmain) { - if (G.background) { - return; - } - - if (wm_gzmap_type_update_flag == 0) { - return; - } - - if (wm_gzmap_type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE) { - for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; - gzmap_type; - gzmap_type = gzmap_type->next) - { - if (gzmap_type->type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE) { - gzmap_type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE; - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first, *gzgt_ref_next; - gzgt_ref; - gzgt_ref = gzgt_ref_next) - { - gzgt_ref_next = gzgt_ref->next; - if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_UPDATE_REMOVE) { - gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE; - WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt_ref->type); - } - } - } - } - - wm_gzmap_type_update_flag &= ~WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE; - } - - if (wm_gzmap_type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT) { - for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; - gzmap_type; - gzmap_type = gzmap_type->next) - { - const uchar type_update_all = WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT; - if (gzmap_type->type_update_flag & type_update_all) { - gzmap_type->type_update_flag &= ~type_update_all; - for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; - gzgt_ref; - gzgt_ref = gzgt_ref->next) - { - if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_KEYMAP_INIT) { - WM_gizmomaptype_group_init_runtime_keymap(bmain, gzgt_ref->type); - gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_KEYMAP_INIT; - } - - if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_UPDATE_INIT) { - WM_gizmomaptype_group_init_runtime(bmain, gzmap_type, gzgt_ref->type); - gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_INIT; - } - } - } - } - - wm_gzmap_type_update_flag &= ~WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT; - } + if (G.background) { + return; + } + + if (wm_gzmap_type_update_flag == 0) { + return; + } + + if (wm_gzmap_type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE) { + for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; + gzmap_type = gzmap_type->next) { + if (gzmap_type->type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE) { + gzmap_type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE; + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first, *gzgt_ref_next; + gzgt_ref; + gzgt_ref = gzgt_ref_next) { + gzgt_ref_next = gzgt_ref->next; + if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_UPDATE_REMOVE) { + gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_REMOVE; + WM_gizmomaptype_group_unlink(NULL, bmain, gzmap_type, gzgt_ref->type); + } + } + } + } + + wm_gzmap_type_update_flag &= ~WM_GIZMOMAPTYPE_GLOBAL_UPDATE_REMOVE; + } + + if (wm_gzmap_type_update_flag & WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT) { + for (wmGizmoMapType *gzmap_type = gizmomaptypes.first; gzmap_type; + gzmap_type = gzmap_type->next) { + const uchar type_update_all = WM_GIZMOMAPTYPE_UPDATE_INIT | WM_GIZMOMAPTYPE_KEYMAP_INIT; + if (gzmap_type->type_update_flag & type_update_all) { + gzmap_type->type_update_flag &= ~type_update_all; + for (wmGizmoGroupTypeRef *gzgt_ref = gzmap_type->grouptype_refs.first; gzgt_ref; + gzgt_ref = gzgt_ref->next) { + if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_KEYMAP_INIT) { + WM_gizmomaptype_group_init_runtime_keymap(bmain, gzgt_ref->type); + gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_KEYMAP_INIT; + } + + if (gzgt_ref->type->type_update_flag & WM_GIZMOMAPTYPE_UPDATE_INIT) { + WM_gizmomaptype_group_init_runtime(bmain, gzmap_type, gzgt_ref->type); + gzgt_ref->type->type_update_flag &= ~WM_GIZMOMAPTYPE_UPDATE_INIT; + } + } + } + } + + wm_gzmap_type_update_flag &= ~WM_GIZMOMAPTYPE_GLOBAL_UPDATE_INIT; + } } /** \} */ @@ -1274,19 +1253,19 @@ void WM_gizmoconfig_update(struct Main *bmain) void WM_reinit_gizmomap_all(Main *bmain) { - for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { - ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; - for (ARegion *ar = regionbase->first; ar; ar = ar->next) { - wmGizmoMap *gzmap = ar->gizmo_map; - if ((gzmap != NULL) && (gzmap->is_init == false)) { - WM_gizmomap_reinit(gzmap); - } - } - } - } - } + for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + for (ARegion *ar = regionbase->first; ar; ar = ar->next) { + wmGizmoMap *gzmap = ar->gizmo_map; + if ((gzmap != NULL) && (gzmap->is_init == false)) { + WM_gizmomap_reinit(gzmap); + } + } + } + } + } } /** \} */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c index d3c07a02440..f5ae5427ac7 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c @@ -46,260 +46,258 @@ BLI_INLINE wmGizmoProperty *wm_gizmo_target_property_array(wmGizmo *gz) { - return (wmGizmoProperty *)(POINTER_OFFSET(gz, gz->type->struct_size)); + return (wmGizmoProperty *)(POINTER_OFFSET(gz, gz->type->struct_size)); } wmGizmoProperty *WM_gizmo_target_property_array(wmGizmo *gz) { - return wm_gizmo_target_property_array(gz); + return wm_gizmo_target_property_array(gz); } wmGizmoProperty *WM_gizmo_target_property_at_index(wmGizmo *gz, int index) { - BLI_assert(index < gz->type->target_property_defs_len); - BLI_assert(index != -1); - wmGizmoProperty *gz_prop_array = wm_gizmo_target_property_array(gz); - return &gz_prop_array[index]; + BLI_assert(index < gz->type->target_property_defs_len); + BLI_assert(index != -1); + wmGizmoProperty *gz_prop_array = wm_gizmo_target_property_array(gz); + return &gz_prop_array[index]; } wmGizmoProperty *WM_gizmo_target_property_find(wmGizmo *gz, const char *idname) { - int index = BLI_findstringindex( - &gz->type->target_property_defs, idname, offsetof(wmGizmoPropertyType, idname)); - if (index != -1) { - return WM_gizmo_target_property_at_index(gz, index); - } - else { - return NULL; - } + int index = BLI_findstringindex( + &gz->type->target_property_defs, idname, offsetof(wmGizmoPropertyType, idname)); + if (index != -1) { + return WM_gizmo_target_property_at_index(gz, index); + } + else { + return NULL; + } } -void WM_gizmo_target_property_def_rna_ptr( - wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, - PointerRNA *ptr, PropertyRNA *prop, int index) +void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, + const wmGizmoPropertyType *gz_prop_type, + PointerRNA *ptr, + PropertyRNA *prop, + int index) { - wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); + wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); - /* if gizmo evokes an operator we cannot use it for property manipulation */ - BLI_assert(gz->op_data == NULL); + /* if gizmo evokes an operator we cannot use it for property manipulation */ + BLI_assert(gz->op_data == NULL); - gz_prop->type = gz_prop_type; + gz_prop->type = gz_prop_type; - gz_prop->ptr = *ptr; - gz_prop->prop = prop; - gz_prop->index = index; + gz_prop->ptr = *ptr; + gz_prop->prop = prop; + gz_prop->index = index; - if (gz->type->property_update) { - gz->type->property_update(gz, gz_prop); - } + if (gz->type->property_update) { + gz->type->property_update(gz, gz_prop); + } } void WM_gizmo_target_property_def_rna( - wmGizmo *gz, const char *idname, - PointerRNA *ptr, const char *propname, int index) + wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index) { - const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); - PropertyRNA *prop = RNA_struct_find_property(ptr, propname); - WM_gizmo_target_property_def_rna_ptr(gz, gz_prop_type, ptr, prop, index); + const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); + PropertyRNA *prop = RNA_struct_find_property(ptr, propname); + WM_gizmo_target_property_def_rna_ptr(gz, gz_prop_type, ptr, prop, index); } -void WM_gizmo_target_property_def_func_ptr( - wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type, - const wmGizmoPropertyFnParams *params) +void WM_gizmo_target_property_def_func_ptr(wmGizmo *gz, + const wmGizmoPropertyType *gz_prop_type, + const wmGizmoPropertyFnParams *params) { - wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); + wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); - /* if gizmo evokes an operator we cannot use it for property manipulation */ - BLI_assert(gz->op_data == NULL); + /* if gizmo evokes an operator we cannot use it for property manipulation */ + BLI_assert(gz->op_data == NULL); - gz_prop->type = gz_prop_type; + gz_prop->type = gz_prop_type; - gz_prop->custom_func.value_get_fn = params->value_get_fn; - gz_prop->custom_func.value_set_fn = params->value_set_fn; - gz_prop->custom_func.range_get_fn = params->range_get_fn; - gz_prop->custom_func.free_fn = params->free_fn; - gz_prop->custom_func.user_data = params->user_data; + gz_prop->custom_func.value_get_fn = params->value_get_fn; + gz_prop->custom_func.value_set_fn = params->value_set_fn; + gz_prop->custom_func.range_get_fn = params->range_get_fn; + gz_prop->custom_func.free_fn = params->free_fn; + gz_prop->custom_func.user_data = params->user_data; - if (gz->type->property_update) { - gz->type->property_update(gz, gz_prop); - } + if (gz->type->property_update) { + gz->type->property_update(gz, gz_prop); + } } -void WM_gizmo_target_property_def_func( - wmGizmo *gz, const char *idname, - const wmGizmoPropertyFnParams *params) +void WM_gizmo_target_property_def_func(wmGizmo *gz, + const char *idname, + const wmGizmoPropertyFnParams *params) { - const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); - WM_gizmo_target_property_def_func_ptr(gz, gz_prop_type, params); + const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); + WM_gizmo_target_property_def_func_ptr(gz, gz_prop_type, params); } -void WM_gizmo_target_property_clear_rna_ptr( - wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type) +void WM_gizmo_target_property_clear_rna_ptr(wmGizmo *gz, const wmGizmoPropertyType *gz_prop_type) { - wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); + wmGizmoProperty *gz_prop = WM_gizmo_target_property_at_index(gz, gz_prop_type->index_in_type); - /* if gizmo evokes an operator we cannot use it for property manipulation */ - BLI_assert(gz->op_data == NULL); + /* if gizmo evokes an operator we cannot use it for property manipulation */ + BLI_assert(gz->op_data == NULL); - gz_prop->type = NULL; + gz_prop->type = NULL; - gz_prop->ptr = PointerRNA_NULL; - gz_prop->prop = NULL; - gz_prop->index = -1; + gz_prop->ptr = PointerRNA_NULL; + gz_prop->prop = NULL; + gz_prop->index = -1; } -void WM_gizmo_target_property_clear_rna( - wmGizmo *gz, const char *idname) +void WM_gizmo_target_property_clear_rna(wmGizmo *gz, const char *idname) { - const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); - WM_gizmo_target_property_clear_rna_ptr(gz, gz_prop_type); + const wmGizmoPropertyType *gz_prop_type = WM_gizmotype_target_property_find(gz->type, idname); + WM_gizmo_target_property_clear_rna_ptr(gz, gz_prop_type); } - /** \} */ - /* -------------------------------------------------------------------- */ /** \name Property Access * \{ */ bool WM_gizmo_target_property_is_valid_any(wmGizmo *gz) { - wmGizmoProperty *gz_prop_array = wm_gizmo_target_property_array(gz); - for (int i = 0; i < gz->type->target_property_defs_len; i++) { - wmGizmoProperty *gz_prop = &gz_prop_array[i]; - if (WM_gizmo_target_property_is_valid(gz_prop)) { - return true; - } - } - return false; + wmGizmoProperty *gz_prop_array = wm_gizmo_target_property_array(gz); + for (int i = 0; i < gz->type->target_property_defs_len; i++) { + wmGizmoProperty *gz_prop = &gz_prop_array[i]; + if (WM_gizmo_target_property_is_valid(gz_prop)) { + return true; + } + } + return false; } bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop) { - return ((gz_prop->prop != NULL) || - (gz_prop->custom_func.value_get_fn && gz_prop->custom_func.value_set_fn)); + return ((gz_prop->prop != NULL) || + (gz_prop->custom_func.value_get_fn && gz_prop->custom_func.value_set_fn)); } -float WM_gizmo_target_property_float_get( - const wmGizmo *gz, wmGizmoProperty *gz_prop) +float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_prop) { - if (gz_prop->custom_func.value_get_fn) { - float value = 0.0f; - BLI_assert(gz_prop->type->array_length == 1); - gz_prop->custom_func.value_get_fn(gz, gz_prop, &value); - return value; - } - - if (gz_prop->index == -1) { - return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop); - } - else { - return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); - } + if (gz_prop->custom_func.value_get_fn) { + float value = 0.0f; + BLI_assert(gz_prop->type->array_length == 1); + gz_prop->custom_func.value_get_fn(gz, gz_prop, &value); + return value; + } + + if (gz_prop->index == -1) { + return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop); + } + else { + return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); + } } -void WM_gizmo_target_property_float_set( - bContext *C, const wmGizmo *gz, - wmGizmoProperty *gz_prop, const float value) +void WM_gizmo_target_property_float_set(bContext *C, + const wmGizmo *gz, + wmGizmoProperty *gz_prop, + const float value) { - if (gz_prop->custom_func.value_set_fn) { - BLI_assert(gz_prop->type->array_length == 1); - gz_prop->custom_func.value_set_fn(gz, gz_prop, &value); - return; - } - - /* reset property */ - if (gz_prop->index == -1) { - RNA_property_float_set(&gz_prop->ptr, gz_prop->prop, value); - } - else { - RNA_property_float_set_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index, value); - } - RNA_property_update(C, &gz_prop->ptr, gz_prop->prop); + if (gz_prop->custom_func.value_set_fn) { + BLI_assert(gz_prop->type->array_length == 1); + gz_prop->custom_func.value_set_fn(gz, gz_prop, &value); + return; + } + + /* reset property */ + if (gz_prop->index == -1) { + RNA_property_float_set(&gz_prop->ptr, gz_prop->prop, value); + } + else { + RNA_property_float_set_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index, value); + } + RNA_property_update(C, &gz_prop->ptr, gz_prop->prop); } -void WM_gizmo_target_property_float_get_array( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - float *value) +void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + float *value) { - if (gz_prop->custom_func.value_get_fn) { - gz_prop->custom_func.value_get_fn(gz, gz_prop, value); - return; - } - RNA_property_float_get_array(&gz_prop->ptr, gz_prop->prop, value); + if (gz_prop->custom_func.value_get_fn) { + gz_prop->custom_func.value_get_fn(gz, gz_prop, value); + return; + } + RNA_property_float_get_array(&gz_prop->ptr, gz_prop->prop, value); } -void WM_gizmo_target_property_float_set_array( - bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, - const float *value) +void WM_gizmo_target_property_float_set_array(bContext *C, + const wmGizmo *gz, + wmGizmoProperty *gz_prop, + const float *value) { - if (gz_prop->custom_func.value_set_fn) { - gz_prop->custom_func.value_set_fn(gz, gz_prop, value); - return; - } - RNA_property_float_set_array(&gz_prop->ptr, gz_prop->prop, value); + if (gz_prop->custom_func.value_set_fn) { + gz_prop->custom_func.value_set_fn(gz, gz_prop, value); + return; + } + RNA_property_float_set_array(&gz_prop->ptr, gz_prop->prop, value); - RNA_property_update(C, &gz_prop->ptr, gz_prop->prop); + RNA_property_update(C, &gz_prop->ptr, gz_prop->prop); } -bool WM_gizmo_target_property_float_range_get( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - float range[2]) +bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + float range[2]) { - if (gz_prop->custom_func.value_get_fn) { - if (gz_prop->custom_func.range_get_fn) { - gz_prop->custom_func.range_get_fn(gz, gz_prop, range); - return true; - } - else { - return false; - - } - } - - float step, precision; - RNA_property_float_ui_range(&gz_prop->ptr, gz_prop->prop, &range[0], &range[1], &step, &precision); - return true; + if (gz_prop->custom_func.value_get_fn) { + if (gz_prop->custom_func.range_get_fn) { + gz_prop->custom_func.range_get_fn(gz, gz_prop, range); + return true; + } + else { + return false; + } + } + + float step, precision; + RNA_property_float_ui_range( + &gz_prop->ptr, gz_prop->prop, &range[0], &range[1], &step, &precision); + return true; } -int WM_gizmo_target_property_array_length( - const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop) +int WM_gizmo_target_property_array_length(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop) { - if (gz_prop->custom_func.value_get_fn) { - return gz_prop->type->array_length; - } - return RNA_property_array_length(&gz_prop->ptr, gz_prop->prop); + if (gz_prop->custom_func.value_get_fn) { + return gz_prop->type->array_length; + } + return RNA_property_array_length(&gz_prop->ptr, gz_prop->prop); } /** \} */ - /* -------------------------------------------------------------------- */ /** \name Property Define * \{ */ -const wmGizmoPropertyType *WM_gizmotype_target_property_find( - const wmGizmoType *gzt, const char *idname) +const wmGizmoPropertyType *WM_gizmotype_target_property_find(const wmGizmoType *gzt, + const char *idname) { - return BLI_findstring(&gzt->target_property_defs, idname, offsetof(wmGizmoPropertyType, idname)); + return BLI_findstring(&gzt->target_property_defs, idname, offsetof(wmGizmoPropertyType, idname)); } -void WM_gizmotype_target_property_def( - wmGizmoType *gzt, const char *idname, int data_type, int array_length) +void WM_gizmotype_target_property_def(wmGizmoType *gzt, + const char *idname, + int data_type, + int array_length) { - wmGizmoPropertyType *mpt; - - BLI_assert(WM_gizmotype_target_property_find(gzt, idname) == NULL); - - const uint idname_size = strlen(idname) + 1; - mpt = MEM_callocN(sizeof(wmGizmoPropertyType) + idname_size, __func__); - memcpy(mpt->idname, idname, idname_size); - mpt->data_type = data_type; - mpt->array_length = array_length; - mpt->index_in_type = gzt->target_property_defs_len; - gzt->target_property_defs_len += 1; - BLI_addtail(&gzt->target_property_defs, mpt); + wmGizmoPropertyType *mpt; + + BLI_assert(WM_gizmotype_target_property_find(gzt, idname) == NULL); + + const uint idname_size = strlen(idname) + 1; + mpt = MEM_callocN(sizeof(wmGizmoPropertyType) + idname_size, __func__); + memcpy(mpt->idname, idname, idname_size); + mpt->data_type = data_type; + mpt->array_length = array_length; + mpt->index_in_type = gzt->target_property_defs_len; + gzt->target_property_defs_len += 1; + BLI_addtail(&gzt->target_property_defs, mpt); } /** \} */ @@ -308,47 +306,51 @@ void WM_gizmotype_target_property_def( /** \name Property Utilities * \{ */ -void WM_gizmo_do_msg_notify_tag_refresh( - bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val) +void WM_gizmo_do_msg_notify_tag_refresh(bContext *UNUSED(C), + wmMsgSubscribeKey *UNUSED(msg_key), + wmMsgSubscribeValue *msg_val) { - ARegion *ar = msg_val->owner; - wmGizmoMap *gzmap = msg_val->user_data; + ARegion *ar = msg_val->owner; + wmGizmoMap *gzmap = msg_val->user_data; - ED_region_tag_redraw(ar); - WM_gizmomap_tag_refresh(gzmap); + ED_region_tag_redraw(ar); + WM_gizmomap_tag_refresh(gzmap); } /** * Runs on the "prepare draw" pass, * drawing the region clears. */ -void WM_gizmo_target_property_subscribe_all( - wmGizmo *gz, struct wmMsgBus *mbus, ARegion *ar) +void WM_gizmo_target_property_subscribe_all(wmGizmo *gz, struct wmMsgBus *mbus, ARegion *ar) { - if (gz->type->target_property_defs_len) { - wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); - for (int i = 0; i < gz->type->target_property_defs_len; i++) { - wmGizmoProperty *gz_prop = &gz_prop_array[i]; - if (WM_gizmo_target_property_is_valid(gz_prop)) { - if (gz_prop->prop) { - WM_msg_subscribe_rna( - mbus, &gz_prop->ptr, gz_prop->prop, - &(const wmMsgSubscribeValue){ - .owner = ar, - .user_data = ar, - .notify = ED_region_do_msg_notify_tag_redraw, - }, __func__); - WM_msg_subscribe_rna( - mbus, &gz_prop->ptr, gz_prop->prop, - &(const wmMsgSubscribeValue){ - .owner = ar, - .user_data = gz->parent_gzgroup->parent_gzmap, - .notify = WM_gizmo_do_msg_notify_tag_refresh, - }, __func__); - } - } - } - } + if (gz->type->target_property_defs_len) { + wmGizmoProperty *gz_prop_array = WM_gizmo_target_property_array(gz); + for (int i = 0; i < gz->type->target_property_defs_len; i++) { + wmGizmoProperty *gz_prop = &gz_prop_array[i]; + if (WM_gizmo_target_property_is_valid(gz_prop)) { + if (gz_prop->prop) { + WM_msg_subscribe_rna(mbus, + &gz_prop->ptr, + gz_prop->prop, + &(const wmMsgSubscribeValue){ + .owner = ar, + .user_data = ar, + .notify = ED_region_do_msg_notify_tag_redraw, + }, + __func__); + WM_msg_subscribe_rna(mbus, + &gz_prop->ptr, + gz_prop->prop, + &(const wmMsgSubscribeValue){ + .owner = ar, + .user_data = gz->parent_gzgroup->parent_gzmap, + .notify = WM_gizmo_do_msg_notify_tag_refresh, + }, + __func__); + } + } + } + } } /** \} */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.c index b164d4c549f..fd8a01ca575 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_type.c @@ -45,7 +45,6 @@ #include "wm_gizmo_wmapi.h" #include "wm_gizmo_intern.h" - /** \name Gizmo Type Append * * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends. @@ -55,65 +54,65 @@ static GHash *global_gizmotype_hash = NULL; const wmGizmoType *WM_gizmotype_find(const char *idname, bool quiet) { - if (idname[0]) { - wmGizmoType *gzt; - - gzt = BLI_ghash_lookup(global_gizmotype_hash, idname); - if (gzt) { - return gzt; - } - - if (!quiet) { - printf("search for unknown gizmo '%s'\n", idname); - } - } - else { - if (!quiet) { - printf("search for empty gizmo\n"); - } - } - - return NULL; + if (idname[0]) { + wmGizmoType *gzt; + + gzt = BLI_ghash_lookup(global_gizmotype_hash, idname); + if (gzt) { + return gzt; + } + + if (!quiet) { + printf("search for unknown gizmo '%s'\n", idname); + } + } + else { + if (!quiet) { + printf("search for empty gizmo\n"); + } + } + + return NULL; } /* caller must free */ void WM_gizmotype_iter(GHashIterator *ghi) { - BLI_ghashIterator_init(ghi, global_gizmotype_hash); + BLI_ghashIterator_init(ghi, global_gizmotype_hash); } static wmGizmoType *wm_gizmotype_append__begin(void) { - wmGizmoType *gzt = MEM_callocN(sizeof(wmGizmoType), "gizmotype"); - gzt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoProperties); + wmGizmoType *gzt = MEM_callocN(sizeof(wmGizmoType), "gizmotype"); + gzt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_GizmoProperties); #if 0 - /* Set the default i18n context now, so that opfunc can redefine it if needed! */ - RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); - ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; + /* Set the default i18n context now, so that opfunc can redefine it if needed! */ + RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); + ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; #endif - return gzt; + return gzt; } static void wm_gizmotype_append__end(wmGizmoType *gzt) { - BLI_assert(gzt->struct_size >= sizeof(wmGizmo)); + BLI_assert(gzt->struct_size >= sizeof(wmGizmo)); - RNA_def_struct_identifier(&BLENDER_RNA, gzt->srna, gzt->idname); + RNA_def_struct_identifier(&BLENDER_RNA, gzt->srna, gzt->idname); - BLI_ghash_insert(global_gizmotype_hash, (void *)gzt->idname, gzt); + BLI_ghash_insert(global_gizmotype_hash, (void *)gzt->idname, gzt); } void WM_gizmotype_append(void (*gtfunc)(struct wmGizmoType *)) { - wmGizmoType *gzt = wm_gizmotype_append__begin(); - gtfunc(gzt); - wm_gizmotype_append__end(gzt); + wmGizmoType *gzt = wm_gizmotype_append__begin(); + gtfunc(gzt); + wm_gizmotype_append__end(gzt); } void WM_gizmotype_append_ptr(void (*gtfunc)(struct wmGizmoType *, void *), void *userdata) { - wmGizmoType *mt = wm_gizmotype_append__begin(); - gtfunc(mt, userdata); - wm_gizmotype_append__end(mt); + wmGizmoType *mt = wm_gizmotype_append__begin(); + gtfunc(mt, userdata); + wm_gizmotype_append__end(mt); } /** @@ -121,86 +120,85 @@ void WM_gizmotype_append_ptr(void (*gtfunc)(struct wmGizmoType *, void *), void */ static void gizmotype_free(wmGizmoType *gzt) { - if (gzt->ext.srna) { /* python gizmo, allocs own string */ - MEM_freeN((void *)gzt->idname); - } + if (gzt->ext.srna) { /* python gizmo, allocs own string */ + MEM_freeN((void *)gzt->idname); + } - BLI_freelistN(&gzt->target_property_defs); - MEM_freeN(gzt); + BLI_freelistN(&gzt->target_property_defs); + MEM_freeN(gzt); } /** * \param C: May be NULL. */ -static void gizmotype_unlink( - bContext *C, Main *bmain, wmGizmoType *gzt) +static void gizmotype_unlink(bContext *C, Main *bmain, wmGizmoType *gzt) { - /* Free instances. */ - for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { - ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; - for (ARegion *ar = lb->first; ar; ar = ar->next) { - wmGizmoMap *gzmap = ar->gizmo_map; - if (gzmap) { - wmGizmoGroup *gzgroup; - for (gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { - for (wmGizmo *gz = gzgroup->gizmos.first, *gz_next; gz; gz = gz_next) { - gz_next = gz->next; - BLI_assert(gzgroup->parent_gzmap == gzmap); - if (gz->type == gzt) { - WM_gizmo_unlink(&gzgroup->gizmos, gzgroup->parent_gzmap, gz, C); - ED_region_tag_redraw(ar); - } - } - } - } - } - } - } - } + /* Free instances. */ + for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) { + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + for (ARegion *ar = lb->first; ar; ar = ar->next) { + wmGizmoMap *gzmap = ar->gizmo_map; + if (gzmap) { + wmGizmoGroup *gzgroup; + for (gzgroup = gzmap->groups.first; gzgroup; gzgroup = gzgroup->next) { + for (wmGizmo *gz = gzgroup->gizmos.first, *gz_next; gz; gz = gz_next) { + gz_next = gz->next; + BLI_assert(gzgroup->parent_gzmap == gzmap); + if (gz->type == gzt) { + WM_gizmo_unlink(&gzgroup->gizmos, gzgroup->parent_gzmap, gz, C); + ED_region_tag_redraw(ar); + } + } + } + } + } + } + } + } } void WM_gizmotype_remove_ptr(bContext *C, Main *bmain, wmGizmoType *gzt) { - BLI_assert(gzt == WM_gizmotype_find(gzt->idname, false)); + BLI_assert(gzt == WM_gizmotype_find(gzt->idname, false)); - BLI_ghash_remove(global_gizmotype_hash, gzt->idname, NULL, NULL); + BLI_ghash_remove(global_gizmotype_hash, gzt->idname, NULL, NULL); - gizmotype_unlink(C, bmain, gzt); + gizmotype_unlink(C, bmain, gzt); - gizmotype_free(gzt); + gizmotype_free(gzt); } bool WM_gizmotype_remove(bContext *C, Main *bmain, const char *idname) { - wmGizmoType *gzt = BLI_ghash_lookup(global_gizmotype_hash, idname); + wmGizmoType *gzt = BLI_ghash_lookup(global_gizmotype_hash, idname); - if (gzt == NULL) { - return false; - } + if (gzt == NULL) { + return false; + } - WM_gizmotype_remove_ptr(C, bmain, gzt); + WM_gizmotype_remove_ptr(C, bmain, gzt); - return true; + return true; } static void wm_gizmotype_ghash_free_cb(wmGizmoType *mt) { - gizmotype_free(mt); + gizmotype_free(mt); } void wm_gizmotype_free(void) { - BLI_ghash_free(global_gizmotype_hash, NULL, (GHashValFreeFP)wm_gizmotype_ghash_free_cb); - global_gizmotype_hash = NULL; + BLI_ghash_free(global_gizmotype_hash, NULL, (GHashValFreeFP)wm_gizmotype_ghash_free_cb); + global_gizmotype_hash = NULL; } /* called on initialize WM_init() */ void wm_gizmotype_init(void) { - /* reserve size is set based on blender default setup */ - global_gizmotype_hash = BLI_ghash_str_new_ex("wm_gizmotype_init gh", 128); + /* reserve size is set based on blender default setup */ + global_gizmotype_hash = BLI_ghash_str_new_ex("wm_gizmotype_init gh", 128); } /** \} */ diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h index e23c3d77b7f..2aada0f202a 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h @@ -26,61 +26,60 @@ #include "BLI_compiler_attrs.h" /* wmGizmoGroup */ -typedef bool (*wmGizmoGroupFnPoll)( - const struct bContext *, struct wmGizmoGroupType *) - ATTR_WARN_UNUSED_RESULT; -typedef void (*wmGizmoGroupFnInit)( - const struct bContext *, struct wmGizmoGroup *); -typedef void (*wmGizmoGroupFnRefresh)( - const struct bContext *, struct wmGizmoGroup *); -typedef void (*wmGizmoGroupFnDrawPrepare)( - const struct bContext *, struct wmGizmoGroup *); -typedef void (*wmGizmoGroupFnInvokePrepare)( - const struct bContext *, struct wmGizmoGroup *, struct wmGizmo *); -typedef struct wmKeyMap *(*wmGizmoGroupFnSetupKeymap)( - const struct wmGizmoGroupType *, struct wmKeyConfig *) - ATTR_WARN_UNUSED_RESULT; -typedef void (*wmGizmoGroupFnMsgBusSubscribe)( - const struct bContext *, struct wmGizmoGroup *, struct wmMsgBus *); +typedef bool (*wmGizmoGroupFnPoll)(const struct bContext *, + struct wmGizmoGroupType *) ATTR_WARN_UNUSED_RESULT; +typedef void (*wmGizmoGroupFnInit)(const struct bContext *, struct wmGizmoGroup *); +typedef void (*wmGizmoGroupFnRefresh)(const struct bContext *, struct wmGizmoGroup *); +typedef void (*wmGizmoGroupFnDrawPrepare)(const struct bContext *, struct wmGizmoGroup *); +typedef void (*wmGizmoGroupFnInvokePrepare)(const struct bContext *, + struct wmGizmoGroup *, + struct wmGizmo *); +typedef struct wmKeyMap *(*wmGizmoGroupFnSetupKeymap)(const struct wmGizmoGroupType *, + struct wmKeyConfig *)ATTR_WARN_UNUSED_RESULT; +typedef void (*wmGizmoGroupFnMsgBusSubscribe)(const struct bContext *, + struct wmGizmoGroup *, + struct wmMsgBus *); /* wmGizmo */ /* See: wmGizmoType for docs on each type. */ -typedef void (*wmGizmoFnSetup)(struct wmGizmo *); -typedef void (*wmGizmoFnDraw)(const struct bContext *, struct wmGizmo *); -typedef void (*wmGizmoFnDrawSelect)(const struct bContext *, struct wmGizmo *, int); -typedef int (*wmGizmoFnTestSelect)(struct bContext *, struct wmGizmo *, const int mval[2]); -typedef int (*wmGizmoFnModal)(struct bContext *, struct wmGizmo *, const struct wmEvent *, eWM_GizmoFlagTweak); -typedef void (*wmGizmoFnPropertyUpdate)(struct wmGizmo *, struct wmGizmoProperty *); -typedef void (*wmGizmoFnMatrixBasisGet)(const struct wmGizmo *, float[4][4]); -typedef int (*wmGizmoFnInvoke)(struct bContext *, struct wmGizmo *, const struct wmEvent *); -typedef void (*wmGizmoFnExit)(struct bContext *, struct wmGizmo *, const bool); -typedef int (*wmGizmoFnCursorGet)(struct wmGizmo *); -typedef void (*wmGizmoFnSelectRefresh)(struct wmGizmo *); -typedef void (*wmGizmoFnFree)(struct wmGizmo *); +typedef void (*wmGizmoFnSetup)(struct wmGizmo *); +typedef void (*wmGizmoFnDraw)(const struct bContext *, struct wmGizmo *); +typedef void (*wmGizmoFnDrawSelect)(const struct bContext *, struct wmGizmo *, int); +typedef int (*wmGizmoFnTestSelect)(struct bContext *, struct wmGizmo *, const int mval[2]); +typedef int (*wmGizmoFnModal)(struct bContext *, + struct wmGizmo *, + const struct wmEvent *, + eWM_GizmoFlagTweak); +typedef void (*wmGizmoFnPropertyUpdate)(struct wmGizmo *, struct wmGizmoProperty *); +typedef void (*wmGizmoFnMatrixBasisGet)(const struct wmGizmo *, float[4][4]); +typedef int (*wmGizmoFnInvoke)(struct bContext *, struct wmGizmo *, const struct wmEvent *); +typedef void (*wmGizmoFnExit)(struct bContext *, struct wmGizmo *, const bool); +typedef int (*wmGizmoFnCursorGet)(struct wmGizmo *); +typedef void (*wmGizmoFnSelectRefresh)(struct wmGizmo *); +typedef void (*wmGizmoFnFree)(struct wmGizmo *); /* wmGizmoProperty ('value' type defined by 'wmGizmoProperty.data_type') */ -typedef void (*wmGizmoPropertyFnGet)( - const struct wmGizmo *, struct wmGizmoProperty *, - /* typically 'float *' */ - void *value); -typedef void (*wmGizmoPropertyFnSet)( - const struct wmGizmo *, struct wmGizmoProperty *, - /* typically 'const float *' */ - const void *value); -typedef void (*wmGizmoPropertyFnRangeGet)( - const struct wmGizmo *, struct wmGizmoProperty *, - /* typically 'float[2]' */ - void *range); -typedef void (*wmGizmoPropertyFnFree)( - const struct wmGizmo *, struct wmGizmoProperty *); +typedef void (*wmGizmoPropertyFnGet)(const struct wmGizmo *, + struct wmGizmoProperty *, + /* typically 'float *' */ + void *value); +typedef void (*wmGizmoPropertyFnSet)(const struct wmGizmo *, + struct wmGizmoProperty *, + /* typically 'const float *' */ + const void *value); +typedef void (*wmGizmoPropertyFnRangeGet)(const struct wmGizmo *, + struct wmGizmoProperty *, + /* typically 'float[2]' */ + void *range); +typedef void (*wmGizmoPropertyFnFree)(const struct wmGizmo *, struct wmGizmoProperty *); typedef struct wmGizmoPropertyFnParams { - wmGizmoPropertyFnGet value_get_fn; - wmGizmoPropertyFnSet value_set_fn; - wmGizmoPropertyFnRangeGet range_get_fn; - wmGizmoPropertyFnFree free_fn; - void *user_data; + wmGizmoPropertyFnGet value_get_fn; + wmGizmoPropertyFnSet value_set_fn; + wmGizmoPropertyFnRangeGet range_get_fn; + wmGizmoPropertyFnFree free_fn; + void *user_data; } wmGizmoPropertyFnParams; -#endif /* __WM_GIZMO_FN_H__ */ +#endif /* __WM_GIZMO_FN_H__ */ diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h index c7a6b816dd6..33c0d305e59 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h @@ -28,7 +28,6 @@ * Only included in wm.h and lower level files. */ - #ifndef __WM_GIZMO_WMAPI_H__ #define __WM_GIZMO_WMAPI_H__ @@ -39,7 +38,6 @@ struct wmGizmoMap; struct wmOperator; struct wmOperatorType; - /* -------------------------------------------------------------------- */ /* wmGizmo */ @@ -66,21 +64,26 @@ void wm_gizmomap_remove(struct wmGizmoMap *gzmap); void wm_gizmos_keymap(struct wmKeyConfig *keyconf); -void wm_gizmomaps_handled_modal_update( - bContext *C, struct wmEvent *event, struct wmEventHandler_Op *handler); +void wm_gizmomaps_handled_modal_update(bContext *C, + struct wmEvent *event, + struct wmEventHandler_Op *handler); void wm_gizmomap_handler_context_op(bContext *C, struct wmEventHandler_Op *handler); void wm_gizmomap_handler_context_gizmo(bContext *C, struct wmEventHandler_Gizmo *handler); -struct wmGizmo *wm_gizmomap_highlight_find( - struct wmGizmoMap *gzmap, bContext *C, const struct wmEvent *event, - int *r_part); -bool wm_gizmomap_highlight_set( - struct wmGizmoMap *gzmap, const bContext *C, - struct wmGizmo *gz, int part); +struct wmGizmo *wm_gizmomap_highlight_find(struct wmGizmoMap *gzmap, + bContext *C, + const struct wmEvent *event, + int *r_part); +bool wm_gizmomap_highlight_set(struct wmGizmoMap *gzmap, + const bContext *C, + struct wmGizmo *gz, + int part); struct wmGizmo *wm_gizmomap_highlight_get(struct wmGizmoMap *gzmap); -void wm_gizmomap_modal_set( - struct wmGizmoMap *gzmap, bContext *C, struct wmGizmo *gz, - const struct wmEvent *event, bool enable); +void wm_gizmomap_modal_set(struct wmGizmoMap *gzmap, + bContext *C, + struct wmGizmo *gz, + const struct wmEvent *event, + bool enable); struct wmGizmo *wm_gizmomap_modal_get(struct wmGizmoMap *gzmap); struct wmGizmo **wm_gizmomap_selected_get(wmGizmoMap *gzmap, int *r_selected_len); @@ -91,4 +94,4 @@ struct ListBase *wm_gizmomap_groups_get(wmGizmoMap *gzmap); void wm_gizmomaptypes_free(void); -#endif /* __WM_GIZMO_WMAPI_H__ */ +#endif /* __WM_GIZMO_WMAPI_H__ */ |