[Bf-blender-cvs] [bcd78c9] gooseberry: Initialize the snaping aspect just once.
Antony Riakiotakis
noreply at git.blender.org
Thu Nov 20 18:39:46 CET 2014
Commit: bcd78c9311a4e89f04d4047233d40a091755d642
Author: Antony Riakiotakis
Date: Thu Nov 20 18:39:26 2014 +0100
Branches: gooseberry
https://developer.blender.org/rBbcd78c9311a4e89f04d4047233d40a091755d642
Initialize the snaping aspect just once.
===================================================================
M source/blender/editors/transform/transform.c
M source/blender/editors/transform/transform.h
M source/blender/editors/transform/transform_snap.c
===================================================================
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index c7352f2..d6097c7 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1990,6 +1990,35 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
}
}
+static void initSnappingAspect(TransInfo *t)
+{
+ if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
+ if (t->options & CTX_MASK) {
+ ED_space_image_get_aspect(t->sa->spacedata.first, t->snap_aspect, t->snap_aspect + 1);
+ }
+ else if (t->options & CTX_PAINT_CURVE) {
+ t->snap_aspect[0] = t->snap_aspect[1] = 1.0;
+ }
+ else {
+ ED_space_image_get_uv_aspect(t->sa->spacedata.first, t->snap_aspect, t->snap_aspect + 1);
+ }
+ }
+ else if ((t->spacetype == SPACE_IPO) && (t->mode == TFM_TRANSLATION)) {
+ View2D *v2d = &t->ar->v2d;
+ View2DGrid *grid;
+ SpaceIpo *sipo = t->sa->spacedata.first;
+ int unity = V2D_UNIT_VALUES;
+ int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
+
+ /* grid */
+ grid = UI_view2d_grid_calc(t->scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, t->ar->winx, t->ar->winy);
+
+ UI_view2d_grid_size(grid, t->snap_aspect, t->snap_aspect + 1);
+ UI_view2d_grid_free(grid);
+ }
+}
+
+
/* note: caller needs to free 't' on a 0 return */
bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event, int mode)
{
@@ -2057,6 +2086,11 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
else
unit_m3(t->spacemtx);
+ /* initialize snapping factors */
+ t->snap_aspect[0] = t->snap_aspect[1] = t->snap_aspect[2] = 1.0f;
+
+ initSnappingAspect(t);
+
createTransData(C, t); // make TransData structs from selection
if (t->total == 0) {
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index bc5c803..82c1a3f 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -332,6 +332,7 @@ typedef struct TransInfo {
short event_type; /* event->type used to invoke transform */
short idx_max; /* maximum index on the input vector */
float snap[3]; /* Snapping Gears */
+ float snap_aspect[3]; /* snapping aspect correction */
char frame_side; /* Mouse side of the cfra, 'L', 'R' or 'B' */
float viewmat[4][4]; /* copy from G.vd, prevents feedback, */
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 8ebed34..7d30e5f 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -2456,7 +2456,6 @@ int snapSequenceBounds(TransInfo *t, const int mval[2])
static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action)
{
int i;
- float asp[3] = {1.0f, 1.0f, 1.0f}; // TODO: Remove hard coded limit here (3)
if (max_index > 2) {
printf("applyGridIncrement: invalid index %d, clamping\n", max_index);
@@ -2466,34 +2465,8 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl
// Early bailing out if no need to snap
if (fac[action] == 0.0f)
return;
-
- /* evil hack - snapping needs to be adapted for image aspect ratio */
- if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
- if (t->options & CTX_MASK) {
- ED_space_image_get_aspect(t->sa->spacedata.first, asp, asp + 1);
- }
- else if (t->options & CTX_PAINT_CURVE) {
- asp[0] = asp[1] = 1.0;
- }
- else {
- ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1);
- }
- }
- else if ((t->spacetype == SPACE_IPO) && (t->mode == TFM_TRANSLATION)) {
- View2D *v2d = &t->ar->v2d;
- View2DGrid *grid;
- SpaceIpo *sipo = t->sa->spacedata.first;
- int unity = V2D_UNIT_VALUES;
- int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
-
- /* grid */
- grid = UI_view2d_grid_calc(t->scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, t->ar->winx, t->ar->winy);
-
- UI_view2d_grid_size(grid, &asp[0], &asp[1]);
- UI_view2d_grid_free(grid);
- }
for (i = 0; i <= max_index; i++) {
- val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f);
+ val[i] = fac[action] * t->snap_aspect[i] * floorf(val[i] / (fac[action] * t->snap_aspect[i]) + 0.5f);
}
}
More information about the Bf-blender-cvs
mailing list