Cleanup: use wrapper function for gizmo group refresh

Allows for adding checks before/after refresh, not yet added.
This commit is contained in:
Campbell Barton 2019-12-19 00:42:54 +11:00
parent 838dc349ca
commit 5467f3de3a
3 changed files with 36 additions and 21 deletions

View File

@ -371,7 +371,6 @@ void WM_gizmo_group_type_reinit(struct Main *bmain, const char *idname);
/* Utilities */
bool WM_gizmo_context_check_drawstep(const struct bContext *C, eWM_GizmoFlagMapDrawStep step);
bool WM_gizmo_group_type_poll(const struct bContext *C, const struct wmGizmoGroupType *gzgt);
void WM_gizmo_group_remove_by_tool(struct bContext *C,
struct Main *bmain,
const struct wmGizmoGroupType *gzgt,
@ -379,4 +378,8 @@ void WM_gizmo_group_remove_by_tool(struct bContext *C,
void WM_gizmo_group_tag_remove(struct wmGizmoGroup *gzgroup);
/* Wrap Group Type Callbacks. */
bool WM_gizmo_group_type_poll(const struct bContext *C, const struct wmGizmoGroupType *gzgt);
void WM_gizmo_group_refresh(const struct bContext *C, struct wmGizmoGroup *gzgroup);
#endif /* __WM_GIZMO_API_H__ */

View File

@ -284,27 +284,11 @@ void WM_gizmogroup_ensure_init(const bContext *C, wmGizmoGroup *gzgroup)
/* 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);
}
WM_gizmo_group_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));
}
void WM_gizmo_group_remove_by_tool(bContext *C,
Main *bmain,
const wmGizmoGroupType *gzgt,
@ -1140,3 +1124,32 @@ void WM_gizmo_group_unlink_delayed_ptr_from_space(wmGizmoGroupType *gzgt,
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Gizmo Group Type Callback Wrappers
*
* \{ */
bool WM_gizmo_group_type_poll(const bContext *C, const 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));
}
void WM_gizmo_group_refresh(const bContext *C, wmGizmoGroup *gzgroup)
{
const wmGizmoGroupType *gzgt = gzgroup->type;
if (gzgt->refresh) {
gzgt->refresh(C, gzgroup);
}
}
/** \} */

View File

@ -730,9 +730,8 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap,
}
if (do_step[step]) {
if ((gzmap->update_flag[step] & GIZMOMAP_IS_REFRESH_CALLBACK) &&
(gzgroup->type->refresh != NULL)) {
gzgroup->type->refresh(C, gzgroup);
if (gzmap->update_flag[step] & GIZMOMAP_IS_REFRESH_CALLBACK) {
WM_gizmo_group_refresh(C, gzgroup);
/* cleared below */
}
if (step == WM_GIZMOMAP_DRAWSTEP_3D) {