From 96ae34b70fdee3a3028e42f5bfdd627db7c7e8fe Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 16 Oct 2014 21:00:48 +0400 Subject: [PATCH] fixed a bug in jli.getElementOrigin(..) that prevented it from returning negative values... Signed-off-by: Alex A. Naanou --- ui (gen4)/experiments/scale-origin.html | 32 +++++++++++++------------ ui (gen4)/lib/jli.js | 2 +- ui (gen4)/viewer.js | 10 ++++---- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/ui (gen4)/experiments/scale-origin.html b/ui (gen4)/experiments/scale-origin.html index 9ada033b..5c0b2457 100755 --- a/ui (gen4)/experiments/scale-origin.html +++ b/ui (gen4)/experiments/scale-origin.html @@ -88,7 +88,6 @@ function setScale(s){ // The goal of the experiment is to make this do it's thing without // changing element's screen position // -// XXX this does not work of position is negative... function setOrigin(l, t, no_comp){ var block = $('.block') var o = getElementOrigin(block) @@ -99,9 +98,6 @@ function setOrigin(l, t, no_comp){ var offset = getElementOffset(block) // calculate the offset change and compensate... - // XXX this breaks with negative values... - // - starts moving around - // - the secondary pointer goes crazy... var cl = offset.left + ((o.left - o.left*s) - (l - l*s)) var ct = offset.top + ((o.top - o.top*s) - (t - t*s)) @@ -115,21 +111,24 @@ function setOrigin(l, t, no_comp){ } -// center a specific point (default: origin) +// Center a block to a point... +// +// If not coordinates are given then center to element origin... // // NOTE: scale indicates the source coordinate scale, if set to 1 t and -// l will 1:1 to screen, and if set the the same scale as the element +// l will 1:1 to screen, and if set to the same scale as the element // then t and l will be 1:1 to the element... // supported keywords: // 'screen' // 'elem' function centerBlock(l, t, scale){ - scale = scale == true || scale == 'screen' ? 1 - : scale == 'elem' ? null - : scale - - var s = getElementScale(block) var block = $('.block') + var s = getElementScale(block) + + scale = scale == 'screen' ? 1 + : scale == 'elem' ? s + : s + var offset = getElementOffset(block) var bo = block.offset() @@ -142,14 +141,17 @@ function centerBlock(l, t, scale){ // normalize the l,t to element scale... if(l != null && t != null){ - l = scale != null ? (l/s)*scale : l - t = scale != null ? (t/s)*scale : t var w = block.width() var h = block.height() o = { - top: t*s + (h - h*s) / (w / o.left), - left: l*s + (w - w*s) / (h / o.left), + // target offset scale... + top: t*scale + // set origin to top left corner of element (compensate + // for scaling)... + + (h - h*s) / (w / o.left), + left: l*scale + + (w - w*s) / (h / o.left), } } diff --git a/ui (gen4)/lib/jli.js b/ui (gen4)/lib/jli.js index b8aaf590..730e65ed 100755 --- a/ui (gen4)/lib/jli.js +++ b/ui (gen4)/lib/jli.js @@ -514,7 +514,7 @@ var getElementOrigin = makeCSSVendorAttrGetter( 'transformOrigin', {top: 0, left: 0}, function(data){ - res = /([0-9.]*(px|%)) ([0-9.]*(px|%))/.exec(data) + res = /(-?[0-9.]*(px|%)) (-?[0-9.]*(px|%))/.exec(data) return { left: res[1].slice(-2) == 'px' ? parseFloat(res[1]) : res[1], top: res[3].slice(-2) == 'px' ? parseFloat(res[3]) : res[3], diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index 7853e12b..de1597be 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -417,15 +417,17 @@ actions.Actions(Client, { this.ribbons.setBaseRibbon(r) }], - // XXX need screen width in images... + // XXX test... prevScreen: ['Focus previous image one screen width away', function(){ - // XXX + var s = Math.floor(this.ribbons.getScreenWidthImages()) + this.focusImage(this.data.getImage('current', -s)) }], - // XXX need screen width in images... + // XXX test... nextScreen: ['Focus next image one screen width away', function(){ - // XXX + var s = Math.floor(this.ribbons.getScreenWidthImages()) + this.focusImage(this.data.getImage('current', s)) }], // zooming...