~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/transform/transform_snap.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include "DNA_view3d_types.h"
48
48
#include "DNA_windowmanager_types.h"
49
49
 
50
 
#include "RNA_access.h"
51
 
 
52
50
#include "BLI_math.h"
53
51
#include "BLI_blenlib.h"
54
52
#include "BLI_utildefines.h"
59
57
#include "BKE_object.h"
60
58
#include "BKE_anim.h"  /* for duplis */
61
59
#include "BKE_context.h"
62
 
#include "BKE_tessmesh.h"
 
60
#include "BKE_editmesh.h"
63
61
#include "BKE_mesh.h"
64
62
 
 
63
#include "RNA_access.h"
 
64
 
 
65
#include "WM_types.h"
 
66
 
65
67
#include "ED_armature.h"
66
68
#include "ED_image.h"
67
69
#include "ED_mesh.h"
69
71
#include "ED_uvedit.h"
70
72
#include "ED_view3d.h"
71
73
 
72
 
#include "WM_types.h"
73
 
 
74
74
#include "UI_resources.h"
75
75
#include "UI_view2d.h"
76
76
 
78
78
 
79
79
#include "transform.h"
80
80
 
81
 
#define TRANSFORM_DIST_MAX_PX 1000
 
81
/* this should be passed as an arg for use in snap functions */
 
82
#undef BASACT
 
83
 
 
84
#define TRANSFORM_DIST_MAX_PX 1000.0f
 
85
#define TRANSFORM_SNAP_MAX_PX 100.0f
 
86
/* use half of flt-max so we can scale up without an exception */
82
87
 
83
88
/********************* PROTOTYPES ***********************/
84
89
 
103
108
 
104
109
/****************** IMPLEMENTATIONS *********************/
105
110
 
106
 
static int snapNodeTest(View2D *v2d, bNode *node, SnapMode mode);
 
111
static bool snapNodeTest(View2D *v2d, bNode *node, SnapMode mode);
107
112
static NodeBorder snapNodeBorder(int snap_node_mode);
108
113
 
109
114
#if 0
120
125
}
121
126
#endif
122
127
 
123
 
int validSnap(TransInfo *t)
 
128
bool validSnap(TransInfo *t)
124
129
{
125
130
        return (t->tsnap.status & (POINT_INIT | TARGET_INIT)) == (POINT_INIT | TARGET_INIT) ||
126
131
               (t->tsnap.status & (MULTI_POINTS | TARGET_INIT)) == (MULTI_POINTS | TARGET_INIT);
127
132
}
128
133
 
129
 
int activeSnap(TransInfo *t)
 
134
bool activeSnap(TransInfo *t)
130
135
{
131
136
        return (t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP || (t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT;
132
137
}
260
265
        }
261
266
}
262
267
 
263
 
int  handleSnapping(TransInfo *t, wmEvent *event)
 
268
bool handleSnapping(TransInfo *t, const wmEvent *event)
264
269
{
265
 
        int status = 0;
 
270
        bool status = false;
266
271
 
267
272
#if 0 // XXX need a proper selector for all snap mode
268
273
        if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) {
282
287
void applyProject(TransInfo *t)
283
288
{
284
289
        /* XXX FLICKER IN OBJECT MODE */
285
 
        if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0) {
 
290
        if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0 && (t->con.mode & CON_APPLY) == 0) {
286
291
                TransData *td = t->data;
287
292
                float tvec[3];
288
293
                float imat[4][4];
295
300
 
296
301
                for (i = 0; i < t->total; i++, td++) {
297
302
                        float iloc[3], loc[3], no[3];
298
 
                        float mval[2];
299
 
                        int dist = TRANSFORM_DIST_MAX_PX;
 
303
                        float mval_fl[2];
 
304
                        float dist_px = TRANSFORM_DIST_MAX_PX;
300
305
                        
301
306
                        if (td->flag & TD_NOACTION)
302
307
                                break;
318
323
                                copy_v3_v3(iloc, td->ob->obmat[3]);
319
324
                        }
320
325
                        
321
 
                        if (ED_view3d_project_float_global(t->ar, iloc, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
322
 
                                if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeSelect)) {
 
326
                        if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
 
327
                                if (snapObjectsTransform(t, mval_fl, &dist_px, loc, no, t->tsnap.modeSelect)) {
323
328
//                                      if (t->flag & (T_EDIT|T_POSE)) {
324
329
//                                              mul_m4_v3(imat, loc);
325
330
//                                      }
368
373
void resetSnapping(TransInfo *t)
369
374
{
370
375
        t->tsnap.status = 0;
371
 
        t->tsnap.align = 0;
 
376
        t->tsnap.align = false;
372
377
        t->tsnap.project = 0;
373
378
        t->tsnap.mode = 0;
374
379
        t->tsnap.modeSelect = 0;
383
388
        t->tsnap.snapNodeBorder = 0;
384
389
}
385
390
 
386
 
int usingSnappingNormal(TransInfo *t)
 
391
bool usingSnappingNormal(TransInfo *t)
387
392
{
388
393
        return t->tsnap.align;
389
394
}
390
395
 
391
 
int validSnappingNormal(TransInfo *t)
 
396
bool validSnappingNormal(TransInfo *t)
392
397
{
393
398
        if (validSnap(t)) {
394
399
                if (dot_v3v3(t->tsnap.snapNormal, t->tsnap.snapNormal) > 0) {
395
 
                        return 1;
 
400
                        return true;
396
401
                }
397
402
        }
398
403
        
399
 
        return 0;
 
404
        return false;
400
405
}
401
406
 
402
407
static void initSnappingMode(TransInfo *t)
404
409
        ToolSettings *ts = t->settings;
405
410
        Object *obedit = t->obedit;
406
411
        Scene *scene = t->scene;
 
412
        Base *base_act = scene->basact;
407
413
 
408
414
        if (t->spacetype == SPACE_NODE) {
409
415
                /* force project off when not supported */
444
450
                }
445
451
                /* Particles edit mode*/
446
452
                else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
447
 
                         (obedit == NULL && BASACT && BASACT->object && BASACT->object->mode & OB_MODE_PARTICLE_EDIT))
 
453
                         (obedit == NULL && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
448
454
                {
449
455
                        t->tsnap.modeSelect = SNAP_ALL;
450
456
                }
598
604
        }
599
605
}
600
606
 
601
 
int updateSelectedSnapPoint(TransInfo *t)
 
607
bool updateSelectedSnapPoint(TransInfo *t)
602
608
{
603
 
        int status = 0;
 
609
        bool status = false;
604
610
        if (t->tsnap.status & MULTI_POINTS) {
605
611
                TransSnapPoint *p, *closest_p = NULL;
606
 
                int closest_dist = 0;
607
 
                int screen_loc[2];
 
612
                float closest_dist = TRANSFORM_SNAP_MAX_PX;
 
613
                const float mval_fl[2] = {t->mval[0], t->mval[1]};
 
614
                float screen_loc[2];
608
615
 
609
616
                for (p = t->tsnap.points.first; p; p = p->next) {
610
 
                        int dx, dy;
611
 
                        int dist;
 
617
                        float dist;
612
618
 
613
 
                        if (ED_view3d_project_int_global(t->ar, p->co, screen_loc, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) {
 
619
                        if (ED_view3d_project_float_global(t->ar, p->co, screen_loc, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) {
614
620
                                continue;
615
621
                        }
616
622
 
617
 
                        dx = t->mval[0] - screen_loc[0];
618
 
                        dy = t->mval[1] - screen_loc[1];
619
 
 
620
 
                        dist = dx * dx + dy * dy;
621
 
 
622
 
                        if (dist < 100 && (closest_p == NULL || closest_dist > dist)) {
 
623
                        dist = len_squared_v2v2(mval_fl, screen_loc);
 
624
 
 
625
                        if (dist < closest_dist) {
623
626
                                closest_p = p;
624
627
                                closest_dist = dist;
625
628
                        }
626
629
                }
627
630
 
628
631
                if (closest_p) {
629
 
                        status = t->tsnap.selectedPoint == closest_p ? 0 : 1;
 
632
                        status = (t->tsnap.selectedPoint != closest_p);
630
633
                        t->tsnap.selectedPoint = closest_p;
631
634
                }
632
635
        }
807
810
 
808
811
/********************** CALC **************************/
809
812
 
810
 
static void UNUSED_FUNCTION(CalcSnapGrid) (TransInfo * t, float *UNUSED(vec))
 
813
static void UNUSED_FUNCTION(CalcSnapGrid) (TransInfo *t, float *UNUSED(vec))
811
814
{
812
815
        snapGridAction(t, t->tsnap.snapPoint, BIG_GEARS);
813
816
}
818
821
                float loc[3];
819
822
                float no[3];
820
823
                float mval[2];
821
 
                int found = 0;
822
 
                int dist = SNAP_MIN_DISTANCE; // Use a user defined value here
 
824
                bool found = false;
 
825
                float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here
823
826
                
824
827
                mval[0] = t->mval[0];
825
828
                mval[1] = t->mval[1];
901
904
                                no[0] = 0.0;
902
905
                                no[1] = 0.0;
903
906
                                no[2] = 1.0;
904
 
                                found = 1;
 
907
                                found = true;
905
908
                        }
906
909
                        
907
910
                        BLI_freelistN(&depth_peels);
908
911
                }
909
912
                else {
910
 
                        found = snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeSelect);
 
913
                        found = snapObjectsTransform(t, mval, &dist_px, loc, no, t->tsnap.modeSelect);
911
914
                }
912
915
                
913
 
                if (found == 1) {
 
916
                if (found == true) {
914
917
                        float tangent[3];
915
918
                        
916
919
                        sub_v3_v3v3(tangent, loc, t->tsnap.snapPoint);
949
952
        }
950
953
        else if (t->spacetype == SPACE_NODE) {
951
954
                float loc[2];
952
 
                int dist = SNAP_MIN_DISTANCE; // Use a user defined value here
 
955
                float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here
953
956
                char node_border;
954
957
                
955
 
                if (snapNodesTransform(t, t->mval, &dist, loc, &node_border, t->tsnap.modeSelect)) {
 
958
                if (snapNodesTransform(t, t->mval, &dist_px, loc, &node_border, t->tsnap.modeSelect)) {
956
959
                        copy_v2_v2(t->tsnap.snapPoint, loc);
957
960
                        t->tsnap.snapNodeBorder = node_border;
958
961
                        
1144
1147
        }
1145
1148
}
1146
1149
 
1147
 
static int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2no[3], float obmat[4][4], float timat[3][3],
1148
 
                    const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval[2],
1149
 
                    float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
 
1150
static bool snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2no[3], float obmat[4][4], float timat[3][3],
 
1151
                     const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval_fl[2],
 
1152
                     float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth)
1150
1153
{
1151
1154
        float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3];
1152
1155
        int result;
1153
 
        int retval = 0;
 
1156
        bool retval = false;
1154
1157
        
1155
1158
        copy_v3_v3(ray_end, ray_normal_local);
1156
1159
        mul_v3_fl(ray_end, 2000);
1182
1185
                if (dot_v3v3(ray_normal_local, dvec) > 0) {
1183
1186
                        float location[3];
1184
1187
                        float new_depth;
1185
 
                        int screen_loc[2];
1186
 
                        int new_dist;
 
1188
                        float screen_loc[2];
 
1189
                        float new_dist;
1187
1190
                        
1188
1191
                        copy_v3_v3(location, intersect);
1189
1192
                        
1191
1194
                        
1192
1195
                        new_depth = len_v3v3(location, ray_start);
1193
1196
                        
1194
 
                        if (ED_view3d_project_int_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
1195
 
                                new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
 
1197
                        if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
 
1198
                                new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
1196
1199
                        }
1197
1200
                        else {
1198
1201
                                new_dist = TRANSFORM_DIST_MAX_PX;
1202
1205
                         * this takes care of series of connected edges a bit slanted w.r.t the viewport
1203
1206
                         * otherwise, it would stick to the verts of the closest edge and not slide along merrily 
1204
1207
                         * */
1205
 
                        if (new_dist <= *r_dist && new_depth < *r_depth * 1.001f) {
 
1208
                        if (new_dist <= *r_dist_px && new_depth < *r_depth * 1.001f) {
1206
1209
                                float n1[3], n2[3];
1207
1210
                                
1208
1211
                                *r_depth = new_depth;
1209
 
                                retval = 1;
 
1212
                                retval = true;
1210
1213
                                
1211
1214
                                sub_v3_v3v3(edge_loc, v1co, v2co);
1212
1215
                                sub_v3_v3v3(vec, intersect, v2co);
1223
1226
 
1224
1227
                                copy_v3_v3(r_loc, location);
1225
1228
                                
1226
 
                                *r_dist = new_dist;
 
1229
                                *r_dist_px = new_dist;
1227
1230
                        }
1228
1231
                }
1229
1232
        }
1231
1234
        return retval;
1232
1235
}
1233
1236
 
1234
 
static int snapVertex(ARegion *ar, float vco[3], short vno[3], float obmat[4][4], float timat[3][3],
1235
 
                      const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval[2],
1236
 
                      float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
 
1237
static bool snapVertex(ARegion *ar, float vco[3], short vno[3], float obmat[4][4], float timat[3][3],
 
1238
                       const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], const float mval_fl[2],
 
1239
                       float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth)
1237
1240
{
1238
 
        int retval = 0;
 
1241
        bool retval = false;
1239
1242
        float dvec[3];
1240
1243
        
1241
1244
        sub_v3_v3v3(dvec, vco, ray_start_local);
1243
1246
        if (dot_v3v3(ray_normal_local, dvec) > 0) {
1244
1247
                float location[3];
1245
1248
                float new_depth;
1246
 
                int screen_loc[2];
1247
 
                int new_dist;
 
1249
                float screen_loc[2];
 
1250
                float new_dist;
1248
1251
                
1249
1252
                copy_v3_v3(location, vco);
1250
1253
                
1252
1255
                
1253
1256
                new_depth = len_v3v3(location, ray_start);
1254
1257
                
1255
 
                if (ED_view3d_project_int_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
1256
 
                        new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
 
1258
                if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
 
1259
                        new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
1257
1260
                }
1258
1261
                else {
1259
1262
                        new_dist = TRANSFORM_DIST_MAX_PX;
1260
1263
                }
1261
1264
 
1262
1265
                
1263
 
                if (new_dist <= *r_dist && new_depth < *r_depth) {
 
1266
                if (new_dist <= *r_dist_px && new_depth < *r_depth) {
1264
1267
                        *r_depth = new_depth;
1265
 
                        retval = 1;
 
1268
                        retval = true;
1266
1269
                        
1267
1270
                        copy_v3_v3(r_loc, location);
1268
1271
                        
1272
1275
                                normalize_v3(r_no);
1273
1276
                        }
1274
1277
 
1275
 
                        *r_dist = new_dist;
 
1278
                        *r_dist_px = new_dist;
1276
1279
                }
1277
1280
        }
1278
1281
        
1279
1282
        return retval;
1280
1283
}
1281
1284
 
1282
 
static int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4],
1283
 
                        const float ray_start[3], const float ray_normal[3], const float mval[2],
1284
 
                        float r_loc[3], float *UNUSED(r_no), int *r_dist, float *r_depth)
 
1285
static bool snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4],
 
1286
                         const float ray_start[3], const float ray_normal[3], const float mval[2],
 
1287
                         float r_loc[3], float *UNUSED(r_no), float *r_dist_px, float *r_depth)
1285
1288
{
1286
1289
        float imat[4][4];
1287
1290
        float ray_start_local[3], ray_normal_local[3];
1288
 
        int retval = 0;
 
1291
        bool retval = false;
1289
1292
 
1290
1293
        invert_m4_m4(imat, obmat);
1291
1294
 
1304
1307
                                if ((eBone->flag & (BONE_HIDDEN_A | BONE_ROOTSEL | BONE_TIPSEL)) == 0) {
1305
1308
                                        switch (snap_mode) {
1306
1309
                                                case SCE_SNAP_MODE_VERTEX:
1307
 
                                                        retval |= snapVertex(ar, eBone->head, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
1308
 
                                                        retval |= snapVertex(ar, eBone->tail, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
 
1310
                                                        retval |= snapVertex(ar, eBone->head, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
 
1311
                                                        retval |= snapVertex(ar, eBone->tail, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
1309
1312
                                                        break;
1310
1313
                                                case SCE_SNAP_MODE_EDGE:
1311
 
                                                        retval |= snapEdge(ar, eBone->head, NULL, eBone->tail, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
 
1314
                                                        retval |= snapEdge(ar, eBone->head, NULL, eBone->tail, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
1312
1315
                                                        break;
1313
1316
                                        }
1314
1317
                                }
1328
1331
                                
1329
1332
                                switch (snap_mode) {
1330
1333
                                        case SCE_SNAP_MODE_VERTEX:
1331
 
                                                retval |= snapVertex(ar, head_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
1332
 
                                                retval |= snapVertex(ar, tail_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
 
1334
                                                retval |= snapVertex(ar, head_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
 
1335
                                                retval |= snapVertex(ar, tail_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
1333
1336
                                                break;
1334
1337
                                        case SCE_SNAP_MODE_EDGE:
1335
 
                                                retval |= snapEdge(ar, head_vec, NULL, tail_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist, r_depth);
 
1338
                                                retval |= snapEdge(ar, head_vec, NULL, tail_vec, NULL, obmat, NULL, ray_start, ray_start_local, ray_normal_local, mval, r_loc, NULL, r_dist_px, r_depth);
1336
1339
                                                break;
1337
1340
                                }
1338
1341
                        }
1342
1345
        return retval;
1343
1346
}
1344
1347
 
1345
 
static int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
1346
 
                           const float ray_start[3], const float ray_normal[3], const float mval[2],
1347
 
                           float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
 
1348
static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
 
1349
                            const float ray_start[3], const float ray_normal[3], const float mval[2],
 
1350
                            float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth)
1348
1351
{
1349
 
        int retval = 0;
 
1352
        bool retval = false;
1350
1353
        int totvert = dm->getNumVerts(dm);
1351
1354
        int totface = dm->getNumTessFaces(dm);
1352
1355
 
1391
1394
                                        bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6);
1392
1395
 
1393
1396
                                        hit.index = -1;
1394
 
                                        hit.dist = *r_depth * (*r_depth == FLT_MAX ? 1.0f : local_scale);
 
1397
                                        hit.dist = *r_depth * (*r_depth == TRANSFORM_DIST_MAX_RAY ? 1.0f : local_scale);
1395
1398
 
1396
1399
                                        if (treeData.tree && BLI_bvhtree_ray_cast(treeData.tree, ray_start_local, ray_normal_local, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) {
1397
1400
                                                if (hit.dist / local_scale <= *r_depth) {
1443
1446
                                                        else {
1444
1447
                                                                eve = EDBM_vert_at_index(em, index);
1445
1448
                                                                
1446
 
                                                                if (eve && (BM_elem_flag_test(eve, BM_ELEM_HIDDEN) || BM_elem_flag_test(eve, BM_ELEM_SELECT))) {
 
1449
                                                                if ((BM_elem_flag_test(eve, BM_ELEM_HIDDEN) ||
 
1450
                                                                     BM_elem_flag_test(eve, BM_ELEM_SELECT)))
 
1451
                                                                {
1447
1452
                                                                        test = 0;
1448
1453
                                                                }
1449
1454
                                                        }
1451
1456
                                                
1452
1457
                                                
1453
1458
                                                if (test) {
1454
 
                                                        retval |= snapVertex(ar, v->co, v->no, obmat, timat, ray_start, ray_start_local, ray_normal_local, mval, r_loc, r_no, r_dist, r_depth);
 
1459
                                                        retval |= snapVertex(ar, v->co, v->no, obmat, timat, ray_start, ray_start_local, ray_normal_local, mval, r_loc, r_no, r_dist_px, r_depth);
1455
1460
                                                }
1456
1461
                                        }
1457
1462
 
1472
1477
                                        }
1473
1478
                                        
1474
1479
                                        for (i = 0; i < totedge; i++) {
1475
 
                                                BMEdge *eed = NULL;
1476
1480
                                                MEdge *e = edges + i;
1477
1481
                                                
1478
1482
                                                test = 1; /* reset for every vert */
1489
1493
                                                                test = 0;
1490
1494
                                                        }
1491
1495
                                                        else {
1492
 
                                                                eed = EDBM_edge_at_index(em, index);
1493
 
                                                                
1494
 
                                                                if (eed && (BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
1495
 
                                                                            BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
1496
 
                                                                            BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)))
 
1496
                                                                BMEdge *eed = EDBM_edge_at_index(em, index);
 
1497
 
 
1498
                                                                if ((BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
 
1499
                                                                     BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
 
1500
                                                                     BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)))
1497
1501
                                                                {
1498
1502
                                                                        test = 0;
1499
1503
                                                                }
1501
1505
                                                }
1502
1506
 
1503
1507
                                                if (test) {
1504
 
                                                        retval |= snapEdge(ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no, obmat, timat, ray_start, ray_start_local, ray_normal_local, mval, r_loc, r_no, r_dist, r_depth);
 
1508
                                                        retval |= snapEdge(ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no, obmat, timat, ray_start, ray_start_local, ray_normal_local, mval, r_loc, r_no, r_dist_px, r_depth);
1505
1509
                                                }
1506
1510
                                        }
1507
1511
 
1514
1518
        return retval;
1515
1519
1516
1520
 
1517
 
static int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obmat[4][4],
1518
 
                      const float ray_start[3], const float ray_normal[3], const float mval[2],
1519
 
                      float r_loc[3], float r_no[3], int *r_dist, float *r_depth)
 
1521
static bool snapObject(Scene *scene, short snap_mode, ARegion *ar, Object *ob, float obmat[4][4], bool use_obedit,
 
1522
                       Object **r_ob, float r_obmat[4][4],
 
1523
                       const float ray_start[3], const float ray_normal[3], const float mval[2],
 
1524
                       float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth)
1520
1525
{
1521
 
        ToolSettings *ts = scene->toolsettings;
1522
 
        int retval = 0;
 
1526
        bool retval = false;
1523
1527
        
1524
1528
        if (ob->type == OB_MESH) {
1525
1529
                BMEditMesh *em;
1526
1530
                DerivedMesh *dm;
1527
1531
                
1528
 
                if (editobject) {
1529
 
                        em = BMEdit_FromObject(ob);
1530
 
                        /* dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); */
1531
 
                        dm = editbmesh_get_derived_base(ob, em); /* limitation, em & dm MUST have the same number of faces */
 
1532
                if (use_obedit) {
 
1533
                        em = BKE_editmesh_from_object(ob);
 
1534
                        dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
1532
1535
                }
1533
1536
                else {
1534
1537
                        em = NULL;
1535
1538
                        dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
1536
1539
                }
1537
1540
                
1538
 
                retval = snapDerivedMesh(ts->snap_mode, ar, ob, dm, em, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, r_depth);
 
1541
                retval = snapDerivedMesh(snap_mode, ar, ob, dm, em, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
1539
1542
 
1540
1543
                dm->release(dm);
1541
1544
        }
1542
1545
        else if (ob->type == OB_ARMATURE) {
1543
 
                retval = snapArmature(ts->snap_mode, ar, ob, ob->data, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, r_depth);
 
1546
                retval = snapArmature(snap_mode, ar, ob, ob->data, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_depth);
1544
1547
        }
1545
1548
        
 
1549
        if (retval) {
 
1550
                if (r_ob) {
 
1551
                        *r_ob = ob;
 
1552
                        copy_m4_m4(r_obmat, obmat);
 
1553
                }
 
1554
        }
 
1555
 
1546
1556
        return retval;
1547
1557
}
1548
1558
 
1549
 
static int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, const float mval[2],
1550
 
                       int *r_dist, float r_loc[3], float r_no[3], SnapMode mode)
 
1559
static bool snapObjectsRay(Scene *scene, short snap_mode, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit,
 
1560
                           Object **r_ob, float r_obmat[4][4],
 
1561
                           const float ray_start[3], const float ray_normal[3], float *r_ray_dist,
 
1562
                           const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
1551
1563
{
1552
1564
        Base *base;
1553
 
        float depth = FLT_MAX;
1554
 
        int retval = 0;
1555
 
        float ray_start[3], ray_normal[3];
1556
 
        
1557
 
        ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal);
 
1565
        bool retval = false;
1558
1566
 
1559
1567
        if (mode == SNAP_ALL && obedit) {
1560
1568
                Object *ob = obedit;
1561
1569
 
1562
 
                retval |= snapObject(scene, ar, ob, 1, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, &depth);
 
1570
                retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, true,
 
1571
                                     r_ob, r_obmat,
 
1572
                                     ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist);
1563
1573
        }
1564
1574
 
1565
1575
        /* Need an exception for particle edit because the base is flagged with BA_HAS_RECALC_DATA
1567
1577
         *
1568
1578
         * To solve that problem, we do it first as an exception. 
1569
1579
         * */
1570
 
        base = BASACT;
 
1580
        base = base_act;
1571
1581
        if (base && base->object && base->object->mode & OB_MODE_PARTICLE_EDIT) {
1572
1582
                Object *ob = base->object;
1573
 
                retval |= snapObject(scene, ar, ob, 0, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, &depth);
 
1583
                retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, false,
 
1584
                                     r_ob, r_obmat,
 
1585
                                     ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist);
1574
1586
        }
1575
1587
 
1576
1588
        for (base = FIRSTBASE; base != NULL; base = base->next) {
1577
 
                if ((BASE_VISIBLE(v3d, base)) &&
 
1589
                if ((BASE_VISIBLE_BGMODE(v3d, scene, base)) &&
1578
1590
                    (base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
1579
1591
 
1580
1592
                    ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
1581
 
                     (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != BASACT)))
 
1593
                     (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != base_act)))
1582
1594
                {
1583
1595
                        Object *ob = base->object;
1584
1596
                        
1587
1599
                                ListBase *lb = object_duplilist(scene, ob, FALSE);
1588
1600
                                
1589
1601
                                for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
1590
 
                                        Object *dob = dupli_ob->ob;
1591
 
                                        
1592
 
                                        retval |= snapObject(scene, ar, dob, 0, dupli_ob->mat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, &depth);
 
1602
                                        retval |= snapObject(scene, snap_mode, ar, dupli_ob->ob, dupli_ob->mat, false,
 
1603
                                                             r_ob, r_obmat,
 
1604
                                                             ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist);
1593
1605
                                }
1594
1606
                                
1595
1607
                                free_object_duplilist(lb);
1596
1608
                        }
1597
1609
                        
1598
 
                        retval |= snapObject(scene, ar, ob, 0, ob->obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, &depth);
 
1610
                        retval |= snapObject(scene, snap_mode, ar, ob, ob->obmat, false,
 
1611
                                             r_ob, r_obmat,
 
1612
                                             ray_start, ray_normal, mval, r_loc, r_no, r_dist_px, r_ray_dist);
1599
1613
                }
1600
1614
        }
1601
1615
        
1602
1616
        return retval;
1603
1617
}
1604
 
 
1605
 
int snapObjectsTransform(TransInfo *t, const float mval[2], int *r_dist, float r_loc[3], float r_no[3], SnapMode mode)
1606
 
{
1607
 
        return snapObjects(t->scene, t->view, t->ar, t->obedit, mval, r_dist, r_loc, r_no, mode);
1608
 
}
1609
 
 
1610
 
int snapObjectsContext(bContext *C, const float mval[2], int *r_dist, float r_loc[3], float r_no[3], SnapMode mode)
 
1618
static bool snapObjects(Scene *scene, short snap_mode, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit,
 
1619
                        const float mval[2], float *r_dist_px,
 
1620
                        float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode)
 
1621
{
 
1622
        float ray_start[3], ray_normal[3];
 
1623
 
 
1624
        if (ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal, true) == false) {
 
1625
                return false;
 
1626
        }
 
1627
 
 
1628
        return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit,
 
1629
                              NULL, NULL,
 
1630
                              ray_start, ray_normal, r_ray_dist,
 
1631
                              mval, r_dist_px, r_loc, r_no, mode);
 
1632
}
 
1633
 
 
1634
bool snapObjectsTransform(TransInfo *t, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
 
1635
{
 
1636
        float ray_dist = TRANSFORM_DIST_MAX_RAY;
 
1637
        return snapObjects(t->scene, t->scene->toolsettings->snap_mode, t->scene->basact, t->view, t->ar, t->obedit,
 
1638
                           mval, r_dist_px, r_loc, r_no, &ray_dist, mode);
 
1639
}
 
1640
 
 
1641
bool snapObjectsContext(bContext *C, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
1611
1642
{
1612
1643
        ScrArea *sa = CTX_wm_area(C);
1613
1644
        View3D *v3d = sa->spacedata.first;
1614
 
 
1615
 
        return snapObjects(CTX_data_scene(C), v3d, CTX_wm_region(C), CTX_data_edit_object(C), mval, r_dist, r_loc, r_no, mode);
 
1645
        Scene *scene = CTX_data_scene(C);
 
1646
        ARegion *ar = CTX_wm_region(C);
 
1647
        Object *obedit = CTX_data_edit_object(C);
 
1648
        float ray_dist = TRANSFORM_DIST_MAX_RAY;
 
1649
 
 
1650
        return snapObjects(scene, scene->toolsettings->snap_mode, scene->basact, v3d, ar, obedit,
 
1651
                           mval, r_dist_px, r_loc, r_no, &ray_dist, mode);
 
1652
}
 
1653
 
 
1654
bool snapObjectsEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode,
 
1655
                   const float mval[2], float *r_dist_px,
 
1656
                   float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode)
 
1657
{
 
1658
        return snapObjects(scene, snap_mode, base_act, v3d, ar, obedit,
 
1659
                           mval, r_dist_px,
 
1660
                           r_loc, r_no, r_ray_dist, mode);
 
1661
}
 
1662
bool snapObjectsRayEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode,
 
1663
                      Object **r_ob, float r_obmat[4][4],
 
1664
                      const float ray_start[3], const float ray_normal[3], float *r_ray_dist,
 
1665
                      const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
 
1666
{
 
1667
        return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit,
 
1668
                              r_ob, r_obmat,
 
1669
                              ray_start, ray_normal, r_ray_dist,
 
1670
                              mval, r_dist_px, r_loc, r_no, mode);
1616
1671
}
1617
1672
 
1618
1673
/******************** PEELING *********************************/
1667
1722
        peel->flag = 0;
1668
1723
}
1669
1724
 
1670
 
static int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
1671
 
                           const float ray_start[3], const float ray_normal[3], const float UNUSED(mval[2]),
1672
 
                           ListBase *depth_peels)
 
1725
static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
 
1726
                            const float ray_start[3], const float ray_normal[3], const float UNUSED(mval[2]),
 
1727
                            ListBase *depth_peels)
1673
1728
{
1674
 
        int retval = 0;
 
1729
        bool retval = false;
1675
1730
        int totvert = dm->getNumVerts(dm);
1676
1731
        int totface = dm->getNumTessFaces(dm);
1677
1732
        
1776
1831
        return retval;
1777
1832
1778
1833
 
1779
 
static int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase *depth_peels, const float mval[2], SnapMode mode)
 
1834
static bool peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit,
 
1835
                        ListBase *depth_peels, const float mval[2], SnapMode mode)
1780
1836
{
1781
1837
        Base *base;
1782
 
        int retval = 0;
 
1838
        bool retval = false;
1783
1839
        float ray_start[3], ray_normal[3];
1784
1840
        
1785
 
        ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal);
 
1841
        if (ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal, true) == false) {
 
1842
                return false;
 
1843
        }
1786
1844
 
1787
1845
        for (base = scene->base.first; base != NULL; base = base->next) {
1788
1846
                if (BASE_SELECTABLE(v3d, base)) {
1798
1856
                                        if (dob->type == OB_MESH) {
1799
1857
                                                BMEditMesh *em;
1800
1858
                                                DerivedMesh *dm = NULL;
1801
 
                                                int val;
 
1859
                                                bool val;
1802
1860
 
1803
1861
                                                if (dob != obedit) {
1804
1862
                                                        dm = mesh_get_derived_final(scene, dob, CD_MASK_BAREMESH);
1806
1864
                                                        val = peelDerivedMesh(dob, dm, dob->obmat, ray_start, ray_normal, mval, depth_peels);
1807
1865
                                                }
1808
1866
                                                else {
1809
 
                                                        em = BMEdit_FromObject(dob);
 
1867
                                                        em = BKE_editmesh_from_object(dob);
1810
1868
                                                        dm = editbmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH);
1811
1869
                                                        
1812
1870
                                                        val = peelDerivedMesh(dob, dm, dob->obmat, ray_start, ray_normal, mval, depth_peels);
1822
1880
                        }
1823
1881
                        
1824
1882
                        if (ob->type == OB_MESH) {
1825
 
                                int val = 0;
 
1883
                                bool val = false;
1826
1884
 
1827
1885
                                if (ob != obedit && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) || ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT))) {
1828
1886
                                        DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
1831
1889
                                        dm->release(dm);
1832
1890
                                }
1833
1891
                                else if (ob == obedit && mode != SNAP_NOT_OBEDIT) {
1834
 
                                        BMEditMesh *em = BMEdit_FromObject(ob);
 
1892
                                        BMEditMesh *em = BKE_editmesh_from_object(ob);
1835
1893
                                        DerivedMesh *dm = editbmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH);
1836
1894
                                        
1837
1895
                                        val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels);
1850
1908
        return retval;
1851
1909
}
1852
1910
 
1853
 
int peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, const float mval[2], SnapMode mode)
 
1911
bool peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, const float mval[2], SnapMode mode)
1854
1912
{
1855
1913
        return peelObjects(t->scene, t->view, t->ar, t->obedit, depth_peels, mval, mode);
1856
1914
}
1857
1915
 
1858
 
int peelObjectsContext(bContext *C, ListBase *depth_peels, const float mval[2], SnapMode mode)
 
1916
bool peelObjectsContext(bContext *C, ListBase *depth_peels, const float mval[2], SnapMode mode)
1859
1917
{
 
1918
        Scene *scene = CTX_data_scene(C);
1860
1919
        ScrArea *sa = CTX_wm_area(C);
1861
1920
        View3D *v3d = sa->spacedata.first;
 
1921
        ARegion *ar = CTX_wm_region(C);
 
1922
        Object *obedit = CTX_data_edit_object(C);
1862
1923
 
1863
 
        return peelObjects(CTX_data_scene(C), v3d, CTX_wm_region(C), CTX_data_edit_object(C), depth_peels, mval, mode);
 
1924
        return peelObjects(scene, v3d, ar, obedit, depth_peels, mval, mode);
1864
1925
}
1865
1926
 
1866
1927
/******************** NODES ***********************************/
1867
1928
 
1868
 
static int snapNodeTest(View2D *v2d, bNode *node, SnapMode mode)
 
1929
static bool snapNodeTest(View2D *v2d, bNode *node, SnapMode mode)
1869
1930
{
1870
1931
        /* node is use for snapping only if a) snap mode matches and b) node is inside the view */
1871
1932
        return ((mode == SNAP_NOT_SELECTED && !(node->flag & NODE_SELECT)) ||
1887
1948
        return 0;
1888
1949
}
1889
1950
 
1890
 
static int snapNode(ToolSettings *ts, SpaceNode *UNUSED(snode), ARegion *ar, bNode *node, const int mval[2],
1891
 
                    float r_loc[2], int *r_dist, char *r_node_border)
 
1951
static bool snapNode(ToolSettings *ts, SpaceNode *UNUSED(snode), ARegion *ar, bNode *node, const int mval[2],
 
1952
                     float r_loc[2], float *r_dist_px, char *r_node_border)
1892
1953
{
1893
1954
        View2D *v2d = &ar->v2d;
1894
1955
        NodeBorder border = snapNodeBorder(ts->snap_node_mode);
1895
 
        int retval = 0;
 
1956
        bool retval = false;
1896
1957
        rcti totr;
1897
1958
        int new_dist;
1898
1959
        
1901
1962
        
1902
1963
        if (border & NODE_LEFT) {
1903
1964
                new_dist = abs(totr.xmin - mval[0]);
1904
 
                if (new_dist < *r_dist) {
 
1965
                if (new_dist < *r_dist_px) {
1905
1966
                        UI_view2d_region_to_view(v2d, totr.xmin, mval[1], &r_loc[0], &r_loc[1]);
1906
 
                        *r_dist = new_dist;
 
1967
                        *r_dist_px = new_dist;
1907
1968
                        *r_node_border = NODE_LEFT;
1908
 
                        retval = 1;
 
1969
                        retval = true;
1909
1970
                }
1910
1971
        }
1911
1972
        
1912
1973
        if (border & NODE_RIGHT) {
1913
1974
                new_dist = abs(totr.xmax - mval[0]);
1914
 
                if (new_dist < *r_dist) {
 
1975
                if (new_dist < *r_dist_px) {
1915
1976
                        UI_view2d_region_to_view(v2d, totr.xmax, mval[1], &r_loc[0], &r_loc[1]);
1916
 
                        *r_dist = new_dist;
 
1977
                        *r_dist_px = new_dist;
1917
1978
                        *r_node_border = NODE_RIGHT;
1918
 
                        retval = 1;
 
1979
                        retval = true;
1919
1980
                }
1920
1981
        }
1921
1982
        
1922
1983
        if (border & NODE_BOTTOM) {
1923
1984
                new_dist = abs(totr.ymin - mval[1]);
1924
 
                if (new_dist < *r_dist) {
 
1985
                if (new_dist < *r_dist_px) {
1925
1986
                        UI_view2d_region_to_view(v2d, mval[0], totr.ymin, &r_loc[0], &r_loc[1]);
1926
 
                        *r_dist = new_dist;
 
1987
                        *r_dist_px = new_dist;
1927
1988
                        *r_node_border = NODE_BOTTOM;
1928
 
                        retval = 1;
 
1989
                        retval = true;
1929
1990
                }
1930
1991
        }
1931
1992
        
1932
1993
        if (border & NODE_TOP) {
1933
1994
                new_dist = abs(totr.ymax - mval[1]);
1934
 
                if (new_dist < *r_dist) {
 
1995
                if (new_dist < *r_dist_px) {
1935
1996
                        UI_view2d_region_to_view(v2d, mval[0], totr.ymax, &r_loc[0], &r_loc[1]);
1936
 
                        *r_dist = new_dist;
 
1997
                        *r_dist_px = new_dist;
1937
1998
                        *r_node_border = NODE_TOP;
1938
 
                        retval = 1;
 
1999
                        retval = true;
1939
2000
                }
1940
2001
        }
1941
2002
        
1942
2003
        return retval;
1943
2004
}
1944
2005
 
1945
 
static int snapNodes(ToolSettings *ts, SpaceNode *snode, ARegion *ar, const int mval[2],
1946
 
                     int *r_dist, float r_loc[2], char *r_node_border, SnapMode mode)
 
2006
static bool snapNodes(ToolSettings *ts, SpaceNode *snode, ARegion *ar, const int mval[2],
 
2007
                     float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode)
1947
2008
{
1948
2009
        bNodeTree *ntree = snode->edittree;
1949
2010
        bNode *node;
1950
 
        int retval = 0;
 
2011
        bool retval = false;
1951
2012
        
1952
2013
        *r_node_border = 0;
1953
2014
        
1954
2015
        for (node = ntree->nodes.first; node; node = node->next) {
1955
2016
                if (snapNodeTest(&ar->v2d, node, mode))
1956
 
                        retval |= snapNode(ts, snode, ar, node, mval, r_loc, r_dist, r_node_border);
 
2017
                        retval |= snapNode(ts, snode, ar, node, mval, r_loc, r_dist_px, r_node_border);
1957
2018
        }
1958
2019
        
1959
2020
        return retval;
1960
2021
}
1961
2022
 
1962
 
int snapNodesTransform(TransInfo *t, const int mval[2], int *r_dist, float r_loc[2], char *r_node_border, SnapMode mode)
 
2023
bool snapNodesTransform(TransInfo *t, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode)
1963
2024
{
1964
 
        return snapNodes(t->settings, t->sa->spacedata.first, t->ar, mval, r_dist, r_loc, r_node_border, mode);
 
2025
        return snapNodes(t->settings, t->sa->spacedata.first, t->ar, mval, r_dist_px, r_loc, r_node_border, mode);
1965
2026
}
1966
2027
 
1967
 
int snapNodesContext(bContext *C, const int mval[2], int *r_dist, float r_loc[2], char *r_node_border, SnapMode mode)
 
2028
bool snapNodesContext(bContext *C, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode)
1968
2029
{
1969
2030
        Scene *scene = CTX_data_scene(C);
1970
 
        return snapNodes(scene->toolsettings, CTX_wm_space_node(C), CTX_wm_region(C), mval, r_dist, r_loc, r_node_border, mode);
 
2031
        ARegion *ar = CTX_wm_region(C);
 
2032
        return snapNodes(scene->toolsettings, CTX_wm_space_node(C), ar, mval, r_dist_px, r_loc, r_node_border, mode);
1971
2033
}
1972
2034
 
1973
2035
/*================================================================*/