Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: samples/o3d-webgl/client.js

Issue 2456004: Adding zoom on scrollwheel event to Pool demo. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/o3d-webgl-samples/texturesamplers.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, Google Inc. 2 * Copyright 2010, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 y = event.pageY - pos.y; 833 y = event.pageY - pos.y;
834 } 834 }
835 return { x: x, y: y }; 835 return { x: x, y: y };
836 }; 836 };
837 837
838 838
839 /** 839 /**
840 * Wraps a user's event callback with one that properly computes 840 * Wraps a user's event callback with one that properly computes
841 * relative coordinates for the event. 841 * relative coordinates for the event.
842 * @param {!o3d.EventCallback} handler Function to call on event. 842 * @param {!o3d.EventCallback} handler Function to call on event.
843 * @param {boolean} doCancelEvent If event should be canceled after callback.
843 * @return {!o3d.EventCallback} Wrapped handler function. 844 * @return {!o3d.EventCallback} Wrapped handler function.
844 * @private 845 * @private
845 */ 846 */
846 o3d.Client.wrapEventCallback_ = function(handler) { 847 o3d.Client.wrapEventCallback_ = function(handler, doCancelEvent) {
847 return function(event) { 848 return function(event) {
848 event = o3d.Client.getEvent_(event); 849 event = o3d.Client.getEvent_(event);
849 var info = o3d.Client.getEventInfo_(event); 850 var info = o3d.Client.getEventInfo_(event);
850 var relativeCoords = o3d.Client.getRelativeCoordinates_(info); 851 var relativeCoords = o3d.Client.getRelativeCoordinates_(info);
851 event.x = relativeCoords.x; 852 event.x = relativeCoords.x;
852 event.y = relativeCoords.y; 853 event.y = relativeCoords.y;
854 // Invert value to meet contract for deltaY. @see event.js.
855 event.deltaY = -info.wheel;
853 handler(event); 856 handler(event);
857 if (doCancelEvent) {
858 o3djs.event.cancel(event);
859 }
854 }; 860 };
855 }; 861 };
856 862
857 863
858 /** 864 /**
859 * Sets a callback for a given event type. 865 * Sets a callback for a given event type.
860 * types. 866 * types.
861 * There can be only one callback for a given event type at a time; setting a 867 * There can be only one callback for a given event type at a time; setting a
862 * new one deletes the old one. 868 * new one deletes the old one.
863 * 869 *
864 * @param {string} type Type of event to set callback for. 870 * @param {string} type Type of event to set callback for.
865 * @param {!o3d.EventCallback} handler Function to call on event. 871 * @param {!o3d.EventCallback} handler Function to call on event.
866 */ 872 */
867 o3d.Client.prototype.setEventCallback = 873 o3d.Client.prototype.setEventCallback =
868 function(type, handler) { 874 function(type, handler) {
869 var listener = this.gl.hack_canvas; 875 var listener = this.gl.hack_canvas;
870 // TODO(petersont): Figure out a way for a canvas to listen to a key event 876 // TODO(petersont): Figure out a way for a canvas to listen to a key event
871 // directly. 877 // directly.
878
879 var isWheelEvent = type == 'wheel';
872 var forKeyEvent = type.substr(0, 3) == 'key'; 880 var forKeyEvent = type.substr(0, 3) == 'key';
873 if (forKeyEvent) { 881 if (forKeyEvent) {
874 listener = document; 882 listener = document;
875 } else { 883 } else {
876 handler = o3d.Client.wrapEventCallback_(handler); 884 handler = o3d.Client.wrapEventCallback_(handler, isWheelEvent);
877 } 885 }
878 listener.addEventListener(type, handler, true); 886 if (isWheelEvent) {
887 listener.addEventListener('DOMMouseScroll', handler, true);
888 listener.addEventListener('mousewheel', handler, true);
889 } else {
890 listener.addEventListener(type, handler, true);
891 }
879 }; 892 };
880 893
881 894
882 /** 895 /**
883 * Removes the previously-registered callback for an event of the given type. 896 * Removes the previously-registered callback for an event of the given type.
884 * @param {string} type Type of event to clear callback for. 897 * @param {string} type Type of event to clear callback for.
885 */ 898 */
886 o3d.Client.prototype.clearEventCallback = 899 o3d.Client.prototype.clearEventCallback =
887 function(type) { 900 function(type) {
901 //TODO(petersont): Same as TODO in setEventCallback above.
902 var listener = this.gl.hack_canvas;
903
904 var isWheelEvent = type == 'wheel';
888 var forKeyEvent = type.substr(0, 3) == 'key'; 905 var forKeyEvent = type.substr(0, 3) == 'key';
889 if (forKeyEvent) { 906 if (forKeyEvent) {
890 listener = document; 907 listener = document;
891 } 908 }
892 listener.removeEventListener(type); 909
910 if (isWheelEvent) {
911 listener.removeEventListener('DOMMouseScroll');
912 listener.removeEventListener('mousewheel');
913 } else {
914 listener.removeEventListener(type);
915 }
893 }; 916 };
894 917
895 918
896 /** 919 /**
897 * Sets the texture to use when a Texture or Sampler is missing while 920 * Sets the texture to use when a Texture or Sampler is missing while
898 * rendering. The default is a red texture with a yellow no symbol. 921 * rendering. The default is a red texture with a yellow no symbol.
899 * <span style="color:yellow; background-color: red;">&Oslash;. 922 * <span style="color:yellow; background-color: red;">&Oslash;.
900 * If you set it to null you'll get an error if you try to render something 923 * If you set it to null you'll get an error if you try to render something
901 * that is missing a needed Texture, Sampler or ParamSampler. 924 * that is missing a needed Texture, Sampler or ParamSampler.
902 * 925 *
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 o3d.Client.prototype.clientInfo = null; 1133 o3d.Client.prototype.clientInfo = null;
1111 1134
1112 1135
1113 /** 1136 /**
1114 * The canvas associated with this client. 1137 * The canvas associated with this client.
1115 * @type {Element} 1138 * @type {Element}
1116 */ 1139 */
1117 o3d.Client.prototype.canvas = null; 1140 o3d.Client.prototype.canvas = null;
1118 1141
1119 1142
OLDNEW
« no previous file with comments | « samples/o3d-webgl-samples/texturesamplers.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698