diff options
author | luchen@google.com <luchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 19:54:49 +0000 |
---|---|---|
committer | luchen@google.com <luchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 19:54:49 +0000 |
commit | 76b2ad7e89d95b6b3934563cf625dfc493fca4c5 (patch) | |
tree | 7eeace50e4484b07a813ced859ea401db31fef2d /o3d/samples/o3d-webgl-samples | |
parent | 1750a95d56338a475b83c929b0b7eed861199db5 (diff) | |
download | chromium_src-76b2ad7e89d95b6b3934563cf625dfc493fca4c5.zip chromium_src-76b2ad7e89d95b6b3934563cf625dfc493fca4c5.tar.gz chromium_src-76b2ad7e89d95b6b3934563cf625dfc493fca4c5.tar.bz2 |
Adding handlers to zoom in/out on scrollwheel event.
Questions:
- Is deltaY the correct field in which to store this event value?
- Is the 'wheel' addEventListener hook broken in the first place? Doesn't work for me on OSX, but might be working in Windows/Linux and don't know if this change would break it for those.
- It is necessary to cancel event bubbling for the onmousewheel event?
Review URL: http://codereview.chromium.org/2456004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/o3d-webgl-samples')
-rw-r--r-- | o3d/samples/o3d-webgl-samples/pool.html | 22 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl-samples/texturesamplers.html | 2 |
2 files changed, 20 insertions, 4 deletions
diff --git a/o3d/samples/o3d-webgl-samples/pool.html b/o3d/samples/o3d-webgl-samples/pool.html index cabe6d0..14eca54 100644 --- a/o3d/samples/o3d-webgl-samples/pool.html +++ b/o3d/samples/o3d-webgl-samples/pool.html @@ -894,6 +894,8 @@ function registerEventCallbacks() { o3djs.event.addEventListener(g_o3dElement, 'keypress', keyPressed); o3djs.event.addEventListener(g_o3dElement, 'keyup', keyUp); o3djs.event.addEventListener(g_o3dElement, 'keydown', keyDown); + + o3djs.event.addEventListener(g_o3dElement, 'wheel', scrollWheel); } @@ -1884,6 +1886,22 @@ function keyDown(event) { } } +function zoomIn() { + g_cameraInfo.targetPosition.radius *= 0.9; +} + +function zoomOut() { + g_cameraInfo.targetPosition.radius /= 0.9; +} + +function scrollWheel(event) { + if (event.deltaY > 0) { + zoomIn(); + } else { + zoomOut(); + } +} + function keyPressed(event) { var keyChar = String.fromCharCode(o3djs.event.getEventKeyChar(event)); keyChar = keyChar.toLowerCase(); @@ -1943,12 +1961,12 @@ function keyPressed(event) { case '=': case '+': - g_cameraInfo.targetPosition.radius *= 0.9; + zoomIn(); break; case '-': case '_': - g_cameraInfo.targetPosition.radius /= 0.9; + zoomOut(); break; case ' ': diff --git a/o3d/samples/o3d-webgl-samples/texturesamplers.html b/o3d/samples/o3d-webgl-samples/texturesamplers.html index 13ef9c9..13fec25 100644 --- a/o3d/samples/o3d-webgl-samples/texturesamplers.html +++ b/o3d/samples/o3d-webgl-samples/texturesamplers.html @@ -74,8 +74,6 @@ var g_finished = false; // for selenium testing function scrollMe(e) { g_eye = g_math.mulScalarVector((e.deltaY < 0 ? 11 : 13) / 12, g_eye); g_viewInfo.drawContext.view = g_math.matrix4.lookAt(g_eye, g_target, g_up); - // Prevents event from reaching up to the window, e.g. so page will not scroll - o3djs.event.cancel(e); } /** |