Advertisement
Guest User

blender ruler enhancement

a guest
Apr 17th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.45 KB | None | 0 0
  1. Index: source/blender/editors/include/ED_transform.h
  2. ===================================================================
  3. --- source/blender/editors/include/ED_transform.h   (revision 56109)
  4. +++ source/blender/editors/include/ED_transform.h   (working copy)
  5. @@ -174,7 +174,8 @@
  6.  typedef enum SnapMode {
  7.     SNAP_ALL = 0,
  8.     SNAP_NOT_SELECTED = 1,
  9. -   SNAP_NOT_OBEDIT = 2
  10. +   SNAP_NOT_OBEDIT = 2,
  11. +   SNAP_ONLY_SELECTED = 3
  12.  } SnapMode;
  13.  
  14.  #define SNAP_MIN_DISTANCE 30
  15. Index: source/blender/editors/space_view3d/view3d_ruler.c
  16. ===================================================================
  17. --- source/blender/editors/space_view3d/view3d_ruler.c  (revision 56109)
  18. +++ source/blender/editors/space_view3d/view3d_ruler.c  (working copy)
  19. @@ -61,7 +61,7 @@
  20.  #include "ED_transform.h"
  21.  
  22.  static bool ED_view3d_snap_co(bContext *C, float r_co[3], const float co_ss[2], float r_no[3],
  23. -                              bool use_vert, bool use_edge, bool use_face)
  24. +                              bool snap_to_selected, bool use_vert, bool use_edge, bool use_face)
  25.  {
  26.     float dist_px = 12;  /* snap dist */
  27.     float r_no_dummy[3];
  28. @@ -72,19 +72,21 @@
  29.     View3D *v3d = CTX_wm_view3d(C);
  30.     ARegion *ar = CTX_wm_region(C);
  31.     struct Object *obedit = CTX_data_edit_object(C);
  32. +  
  33. +   SnapMode snap_mode = snap_to_selected ? SNAP_ONLY_SELECTED : SNAP_ALL;
  34.  
  35.     /* try snap edge, then face if it fails */
  36.     if (use_vert) {
  37.         ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_VERTEX,
  38. -                           co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
  39. +                           co_ss, &dist_px, r_co, r_no_ptr, snap_mode);
  40.     }
  41.     if (use_edge && (ret == false)) {
  42.         ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_EDGE,
  43. -                           co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
  44. +                           co_ss, &dist_px, r_co, r_no_ptr, snap_mode);
  45.     }
  46.     if (use_face && (ret == false)) {
  47.         ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE,
  48. -                           co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
  49. +                           co_ss, &dist_px, r_co, r_no_ptr, snap_mode);
  50.     }
  51.  
  52.     return ret;
  53. @@ -156,6 +158,7 @@
  54.     int flag;
  55.     int snap_flag;
  56.     int state;
  57. +   int     snap_to_selected;
  58.  
  59.     /* --- */
  60.     ARegion *ar;
  61. @@ -685,7 +688,7 @@
  62.             co_other = ruler_item->co[ruler_item->co_index == 0 ? 2 : 0];
  63.  
  64.             if (ED_view3d_snap_co(C, co, mval_fl, ray_normal,
  65. -                                 false, false, true))
  66. +                                 ruler_info->snap_to_selected, false, false, true))
  67.             {
  68.                 negate_v3(ray_normal);
  69.                 /* add some bias */
  70. @@ -697,7 +700,7 @@
  71.         else if (do_snap) {
  72.             const float mval_fl[2] = {UNPACK2(mval)};
  73.             ED_view3d_snap_co(C, co, mval_fl, NULL,
  74. -                             true, true, true);
  75. +                             ruler_info->snap_to_selected, true, true, true);
  76.         }
  77.         return true;
  78.     }
  79. @@ -706,16 +709,23 @@
  80.     }
  81.  }
  82.  
  83. -static void view3d_ruler_header_update(ScrArea *sa)
  84. +static void view3d_ruler_header_update(ScrArea *sa, RulerInfo *ruler_info)
  85.  {
  86. -   const char *text = "Ctrl+LMB: Add, "
  87. -                      "Del: Remove, "
  88. -                      "Ctrl+Drag: Snap, "
  89. -                      "Shift+Drag: Thickness, "
  90. -                      "Ctrl+C: Copy Value, "
  91. -                      "Enter: Store,  "
  92. -                      "Esc: Cancel";
  93. +   char text[1024];
  94. +   const char *snap_mode_str = ruler_info->snap_to_selected ? "To-Selected" : "To-All";
  95. +   const char *template =
  96. +       "Ctrl+LMB: Add, "
  97. +       "Del: Remove, "
  98. +       "Ctrl+Drag: Snap, "
  99. +       "Shift+Drag: Thickness, "
  100. +       "Ctrl+C: Copy Value, "
  101. +       "Enter: Store,  "
  102. +       "Esc: Cancel, "
  103. +       "Ctrl+S: Toggle snap mode, "
  104. +       "SnapMode: %s";
  105.  
  106. +   sprintf(text, template, snap_mode_str);
  107. +
  108.     ED_area_headerprint(sa, text);
  109.  }
  110.  
  111. @@ -741,7 +751,7 @@
  112.     ruler_info->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ruler_info_draw_pixel,
  113.                                                                ruler_info, REGION_DRAW_POST_PIXEL);
  114.  
  115. -   view3d_ruler_header_update(sa);
  116. +   view3d_ruler_header_update(sa, ruler_info);
  117.  
  118.     WM_cursor_modal(win, BC_CROSSCURSOR);
  119.     WM_event_add_modal_handler(C, op);
  120. @@ -866,6 +876,15 @@
  121.                 }
  122.             }
  123.             break;
  124. +       case SKEY:
  125. +       {
  126. +           if (event->ctrl && event->val == KM_RELEASE) {
  127. +               ruler_info->snap_to_selected = !ruler_info->snap_to_selected;
  128. +               fprintf(stderr, "toggling snap_to_selected\n");
  129. +               do_draw = true;
  130. +           }
  131. +           break;
  132. +       }
  133.         case CKEY:
  134.         {
  135.             if (event->ctrl) {
  136. @@ -880,6 +899,7 @@
  137.                     WM_clipboard_text_set((void *) numstr, false);
  138.                 }
  139.             }
  140. +           break;
  141.         }
  142.         case RIGHTCTRLKEY:
  143.         case LEFTCTRLKEY:
  144. @@ -934,7 +954,7 @@
  145.     if (do_draw) {
  146.         ScrArea *sa = CTX_wm_area(C);
  147.  
  148. -       view3d_ruler_header_update(sa);
  149. +       view3d_ruler_header_update(sa, ruler_info);
  150.  
  151.         /* all 3d views draw rulers */
  152.         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
  153. Index: source/blender/editors/transform/transform_snap.c
  154. ===================================================================
  155. --- source/blender/editors/transform/transform_snap.c   (revision 56109)
  156. +++ source/blender/editors/transform/transform_snap.c   (working copy)
  157. @@ -1577,6 +1577,7 @@
  158.             (base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
  159.  
  160.             ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
  161. +            (mode == SNAP_ONLY_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 1) ||
  162.              (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != base_act)))
  163.         {
  164.             Object *ob = base->object;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement