Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormano-wii <germano.costa@ig.com.br>2019-10-28 15:51:53 +0300
committermano-wii <germano.costa@ig.com.br>2019-10-28 15:51:53 +0300
commitce0db668ec0410c8b2d41f605e2cf5e608df5082 (patch)
tree7269b7b71463e801193905c93da1eed60e112bda /source/blender/editors/transform
parenta83bbefec699b60a5f221a55e86998380cceb181 (diff)
Fix T50148: Header: Wrong rounding when moving frames
Deduplicate the code and use the same logic used to calculate individual elements in `t->values_final[0]`. Differential revision: https://developer.blender.org/D6135
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r--source/blender/editors/transform/transform.c61
-rw-r--r--source/blender/editors/transform/transform_snap.c44
2 files changed, 51 insertions, 54 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index b98c14150d5..07193bfb1e4 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -72,7 +72,6 @@
#include "ED_keyframing.h"
#include "ED_screen.h"
#include "ED_space_api.h"
-#include "ED_markers.h"
#include "ED_view3d.h"
#include "ED_mesh.h"
#include "ED_clip.h"
@@ -8881,38 +8880,7 @@ static short getAnimEdit_SnapMode(TransInfo *t)
static void doAnimEdit_SnapFrame(
TransInfo *t, TransData *td, TransData2D *td2d, AnimData *adt, short autosnap)
{
- /* snap key to nearest frame or second? */
- if (ELEM(autosnap, SACTSNAP_FRAME, SACTSNAP_SECOND)) {
- const Scene *scene = t->scene;
- const double secf = FPS;
- double val;
-
- /* convert frame to nla-action time (if needed) */
- if (adt) {
- val = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP);
- }
- else {
- val = *(td->val);
- }
-
- /* do the snapping to nearest frame/second */
- if (autosnap == SACTSNAP_FRAME) {
- val = floorf(val + 0.5);
- }
- else if (autosnap == SACTSNAP_SECOND) {
- val = (float)(floor((val / secf) + 0.5) * secf);
- }
-
- /* convert frame out of nla-action time */
- if (adt) {
- *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
- }
- else {
- *(td->val) = val;
- }
- }
- /* snap key to nearest marker? */
- else if (autosnap == SACTSNAP_MARKER) {
+ if (ELEM(autosnap, SACTSNAP_FRAME, SACTSNAP_SECOND, SACTSNAP_MARKER)) {
float val;
/* convert frame to nla-action time (if needed) */
@@ -8923,9 +8891,7 @@ static void doAnimEdit_SnapFrame(
val = *(td->val);
}
- /* snap to nearest marker */
- // TODO: need some more careful checks for where data comes from
- val = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val);
+ snapFrameTransform(t, autosnap, true, val, &val);
/* convert frame out of nla-action time */
if (adt) {
@@ -8998,31 +8964,20 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
const double secf = FPS;
float val = t->values_final[0];
- /* apply snapping + frame->seconds conversions */
- if (autosnap == SACTSNAP_STEP) {
- /* frame step */
- val = floorf(val + 0.5f);
- }
- else if (autosnap == SACTSNAP_TSTEP) {
- /* second step */
- val = floorf((double)val / secf + 0.5);
- }
- else if (autosnap == SACTSNAP_SECOND) {
- /* nearest second */
- val = (float)((double)val / secf);
- }
+ float snap_val;
+ snapFrameTransform(t, autosnap, false, val, &snap_val);
if (autosnap == SACTSNAP_FRAME) {
- BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 (%.4f)", (int)val, val);
+ BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.2f (%.4f)", snap_val, val);
}
else if (autosnap == SACTSNAP_SECOND) {
- BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 sec (%.4f)", (int)val, val);
+ BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.2f sec (%.4f)", snap_val, val);
}
else if (autosnap == SACTSNAP_TSTEP) {
- BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f sec", val);
+ BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f sec", snap_val);
}
else {
- BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val);
+ BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", snap_val);
}
}
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 9de3dfe0214..4f6c26a6391 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -57,6 +57,7 @@
#include "WM_types.h"
#include "ED_image.h"
+#include "ED_markers.h"
#include "ED_node.h"
#include "ED_uvedit.h"
#include "ED_view3d.h"
@@ -1468,7 +1469,7 @@ bool peelObjectsTransform(TransInfo *t,
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Nodes
+/** \name snap Nodes
* \{ */
static bool snapNodeTest(View2D *v2d, bNode *node, eSnapSelect snap_select)
@@ -1589,6 +1590,47 @@ bool snapNodesTransform(
r_node_border);
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name snap Frames
+ * \{ */
+
+/* This function is used by Animation Editor specific transform functions to do
+ * the Snap Keyframe to Nearest Frame/Marker
+ */
+void snapFrameTransform(TransInfo *t,
+ const eAnimEdit_AutoSnap autosnap,
+ const bool is_frame_value,
+ const float delta,
+ float *r_val)
+{
+ double val = delta;
+ switch (autosnap) {
+ case SACTSNAP_STEP:
+ case SACTSNAP_FRAME:
+ val = floor(val + 0.5);
+ break;
+ case SACTSNAP_MARKER:
+ /* snap to nearest marker */
+ // TODO: need some more careful checks for where data comes from
+ val = ED_markers_find_nearest_marker_time(&t->scene->markers, (float)val);
+ break;
+ case SACTSNAP_SECOND:
+ case SACTSNAP_TSTEP: {
+ /* second step */
+ const Scene *scene = t->scene;
+ const double secf = FPS;
+ val = floor((val / secf) + 0.5);
+ if (is_frame_value) {
+ val *= secf;
+ }
+ break;
+ }
+ }
+ *r_val = (float)val;
+}
+
/*================================================================*/
static void applyGridIncrement(