diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-04-20 21:45:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-04-20 21:50:39 +0300 |
commit | 62e149881a311e2f2b41131eb201d86a59031c77 (patch) | |
tree | db6a018a720a99009420038d2d2b08da0fc4ce27 /source/blender/editors/space_view3d | |
parent | aa880bb815e7707255f7d450f4add1b042f119fa (diff) |
Fixes for backbuf selection logic
- Fix ED_view3d_backbuf_sample_rect, r_dist was set completely wrong.
- Avoid duplicate calculations picking the nearest edge.
- Bias against picking selected edges is now optional.
- Remove unused callback reading the backbuf.
- Remove unused strict option picking vertices.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 678daa6dd88..9fcdb77ef7f 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1552,16 +1552,14 @@ ImBuf *ED_view3d_backbuf_read(ViewContext *vc, short xmin, short ymin, short xma /* smart function to sample a rect spiralling outside, nice for backbuf selection */ unsigned int ED_view3d_backbuf_sample_rect( ViewContext *vc, const int mval[2], int size, - unsigned int min, unsigned int max, float *r_dist, const bool is_strict, - void *handle, bool (*indextest)(void *handle, unsigned int index)) + unsigned int min, unsigned int max, float *r_dist) { struct ImBuf *buf; - unsigned int *bufmin, *bufmax, *tbuf; + const unsigned int *bufmin, *bufmax, *tbuf; int minx, miny; int a, b, rc, nr, amount, dirvec[4][2]; int distance = 0; unsigned int index = 0; - bool indexok = false; amount = (size - 1) / 2; @@ -1586,20 +1584,20 @@ unsigned int ED_view3d_backbuf_sample_rect( for (a = 0; a < 2; a++) { for (b = 0; b < nr; b++, distance++) { - if (*tbuf && *tbuf >= min && *tbuf < max) { /* we got a hit */ - if (is_strict) { - indexok = indextest(handle, *tbuf - min + 1); - if (indexok) { - *r_dist = sqrtf((float)distance); - index = *tbuf - min + 1; - goto exit; - } - } - else { - *r_dist = sqrtf((float)distance); /* XXX, this distance is wrong - */ - index = *tbuf - min + 1; /* messy yah, but indices start at 1 */ - goto exit; - } + if (*tbuf && *tbuf >= min && *tbuf < max) { + /* we got a hit */ + + /* get x,y pixel coords from the offset */ + const float delta[2] = { + ((tbuf - buf->rect) % size) - (size / 2), + ((tbuf - buf->rect) / size) - (size / 2), + }; + + *r_dist = len_v2(delta); + + /* indices start at 1 here */ + index = (*tbuf - min) + 1; + goto exit; } tbuf += (dirvec[rc][0] + dirvec[rc][1]); |