Source: gesture/Touch.js

  1. /*
  2. * Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
  3. * by the Administrator of the National Aeronautics and Space Administration.
  4. * All rights reserved.
  5. *
  6. * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
  7. * Version 2.0 (the "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License
  9. * at http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. *
  16. * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
  17. * software:
  18. *
  19. * ES6-Promise – under MIT License
  20. * libtess.js – SGI Free Software License B
  21. * Proj4 – under MIT License
  22. * JSZip – under MIT License
  23. *
  24. * A complete listing of 3rd Party software notices and licenses included in
  25. * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
  26. * PDF found in code directory.
  27. */
  28. /**
  29. * @exports Touch
  30. */
  31. define([],
  32. function () {
  33. "use strict";
  34. /**
  35. * Constructs a touch point.
  36. * @alias Touch
  37. * @constructor
  38. * @classdesc Represents a touch point.
  39. * @param {Color} identifier A number uniquely identifying the touch point
  40. * @param {Number} clientX The X coordinate of the touch point's location.
  41. * @param {Number} clientY The Y coordinate of the touch point's location.
  42. */
  43. var Touch = function (identifier, clientX, clientY) {
  44. /**
  45. * A number uniquely identifying this touch point.
  46. * @type {Number}
  47. * @readonly
  48. */
  49. this.identifier = identifier;
  50. // Intentionally not documented.
  51. this._clientX = clientX;
  52. // Intentionally not documented.
  53. this._clientY = clientY;
  54. // Intentionally not documented.
  55. this._clientStartX = clientX;
  56. // Intentionally not documented.
  57. this._clientStartY = clientY;
  58. };
  59. Object.defineProperties(Touch.prototype, {
  60. /**
  61. * Indicates the X coordinate of this touch point's location.
  62. * @type {Number}
  63. * @memberof Touch.prototype
  64. */
  65. clientX: {
  66. get: function () {
  67. return this._clientX;
  68. },
  69. set: function (value) {
  70. this._clientX = value;
  71. }
  72. },
  73. /**
  74. * Indicates the Y coordinate of this touch point's location.
  75. * @type {Number}
  76. * @memberof Touch.prototype
  77. */
  78. clientY: {
  79. get: function () {
  80. return this._clientY;
  81. },
  82. set: function (value) {
  83. this._clientY = value;
  84. }
  85. },
  86. /**
  87. * Indicates this touch point's translation along the X axis since the touch started.
  88. * @type {Number}
  89. * @memberof Touch.prototype
  90. */
  91. translationX: {
  92. get: function () {
  93. return this._clientX - this._clientStartX;
  94. },
  95. set: function (value) {
  96. this._clientStartX = this._clientX - value;
  97. }
  98. },
  99. /**
  100. * Indicates this touch point's translation along the Y axis since the touch started.
  101. * @type {Number}
  102. * @memberof Touch.prototype
  103. */
  104. translationY: {
  105. get: function () {
  106. return this._clientY - this._clientStartY;
  107. },
  108. set: function (value) {
  109. this._clientStartY = this._clientY - value;
  110. }
  111. }
  112. });
  113. return Touch;
  114. });