Cleanup: move gizmo sort functions into an API
authorCampbell Barton <ideasman42@gmail.com>
Thu, 18 Oct 2018 00:26:03 +0000 (11:26 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 18 Oct 2018 00:50:22 +0000 (11:50 +1100)
source/blender/editors/mesh/editmesh_extrude_gizmo.c
source/blender/windowmanager/gizmo/WM_gizmo_api.h
source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c

index e0b1f5e9916f1a5d96f10899fe9c3f7173aa0b56..83c88b94aceb37b47287b06d9735da6af8b8346c 100644 (file)
@@ -337,15 +337,6 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
        }
 }
 
-static int gizmo_cmp_temp_f(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;
-}
-
 static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
 {
        GizmoExtrudeGroup *ggd = gzgroup->customdata;
@@ -365,9 +356,9 @@ static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzg
        {
                RegionView3D *rv3d = CTX_wm_region_view3d(C);
                LISTBASE_FOREACH (wmGizmo *, gz, &gzgroup->gizmos) {
-                       gz->temp.f = -dot_v3v3(rv3d->viewinv[2], gz->matrix_offset[3]);
+                       gz->temp.f = dot_v3v3(rv3d->viewinv[2], gz->matrix_offset[3]);
                }
-               BLI_listbase_sort(&gzgroup->gizmos, gizmo_cmp_temp_f);
+               BLI_listbase_sort(&gzgroup->gizmos, WM_gizmo_cmp_temp_fl_reverse);
        }
 }
 
index 153840986efbf8efe72b377ab1b24d0fd081a14f..9f05437eaa871ab2e9a7fa01b3da3542ede5c87f 100644 (file)
@@ -240,6 +240,9 @@ struct wmKeyMap *WM_gizmogroup_keymap_common(
 struct wmKeyMap *WM_gizmogroup_keymap_common_select(
         const struct wmGizmoGroupType *gzgt, struct wmKeyConfig *config);
 
+/* Sort utilities for use with 'BLI_listbase_sort'. */
+int WM_gizmo_cmp_temp_fl(const void *gz_a_ptr, const void *gz_b_ptr);
+int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr);
 
 /* -------------------------------------------------------------------- */
 /* wmGizmoMap */
index 9cc8bacd20b9dca96e690e39374507bb2c780342..90a0ff8b6518ea047536177107bbdb82f5894536 100644 (file)
@@ -147,6 +147,24 @@ void wm_gizmogroup_gizmo_register(wmGizmoGroup *gzgroup, wmGizmo *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;
+}
+
+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;
+}
+
 wmGizmo *wm_gizmogroup_find_intersected_gizmo(
         const wmGizmoGroup *gzgroup, bContext *C, const wmEvent *event,
         int *r_part)