lineargradient.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Represents a gradient to be used with a Graphics implementor.
  16. * @author arv@google.com (Erik Arvidsson)
  17. */
  18. goog.provide('goog.graphics.LinearGradient');
  19. goog.require('goog.asserts');
  20. goog.require('goog.graphics.Fill');
  21. /**
  22. * Creates an immutable linear gradient fill object.
  23. *
  24. * @param {number} x1 Start X position of the gradient.
  25. * @param {number} y1 Start Y position of the gradient.
  26. * @param {number} x2 End X position of the gradient.
  27. * @param {number} y2 End Y position of the gradient.
  28. * @param {string} color1 Start color of the gradient.
  29. * @param {string} color2 End color of the gradient.
  30. * @param {?number=} opt_opacity1 Start opacity of the gradient, both or neither
  31. * of opt_opacity1 and opt_opacity2 have to be set.
  32. * @param {?number=} opt_opacity2 End opacity of the gradient.
  33. * @constructor
  34. * @extends {goog.graphics.Fill}
  35. * @deprecated goog.graphics is deprecated. It existed to abstract over browser
  36. * differences before the canvas tag was widely supported. See
  37. * http://en.wikipedia.org/wiki/Canvas_element for details.
  38. * @final
  39. */
  40. goog.graphics.LinearGradient = function(
  41. x1, y1, x2, y2, color1, color2, opt_opacity1, opt_opacity2) {
  42. /**
  43. * Start X position of the gradient.
  44. * @type {number}
  45. * @private
  46. */
  47. this.x1_ = x1;
  48. /**
  49. * Start Y position of the gradient.
  50. * @type {number}
  51. * @private
  52. */
  53. this.y1_ = y1;
  54. /**
  55. * End X position of the gradient.
  56. * @type {number}
  57. * @private
  58. */
  59. this.x2_ = x2;
  60. /**
  61. * End Y position of the gradient.
  62. * @type {number}
  63. * @private
  64. */
  65. this.y2_ = y2;
  66. /**
  67. * Start color of the gradient.
  68. * @type {string}
  69. * @private
  70. */
  71. this.color1_ = color1;
  72. /**
  73. * End color of the gradient.
  74. * @type {string}
  75. * @private
  76. */
  77. this.color2_ = color2;
  78. goog.asserts.assert(
  79. goog.isNumber(opt_opacity1) == goog.isNumber(opt_opacity2),
  80. 'Both or neither of opt_opacity1 and opt_opacity2 have to be set.');
  81. /**
  82. * Start opacity of the gradient.
  83. * @type {?number}
  84. * @private
  85. */
  86. this.opacity1_ = goog.isDef(opt_opacity1) ? opt_opacity1 : null;
  87. /**
  88. * End opacity of the gradient.
  89. * @type {?number}
  90. * @private
  91. */
  92. this.opacity2_ = goog.isDef(opt_opacity2) ? opt_opacity2 : null;
  93. };
  94. goog.inherits(goog.graphics.LinearGradient, goog.graphics.Fill);
  95. /**
  96. * @return {number} The start X position of the gradient.
  97. */
  98. goog.graphics.LinearGradient.prototype.getX1 = function() {
  99. return this.x1_;
  100. };
  101. /**
  102. * @return {number} The start Y position of the gradient.
  103. */
  104. goog.graphics.LinearGradient.prototype.getY1 = function() {
  105. return this.y1_;
  106. };
  107. /**
  108. * @return {number} The end X position of the gradient.
  109. */
  110. goog.graphics.LinearGradient.prototype.getX2 = function() {
  111. return this.x2_;
  112. };
  113. /**
  114. * @return {number} The end Y position of the gradient.
  115. */
  116. goog.graphics.LinearGradient.prototype.getY2 = function() {
  117. return this.y2_;
  118. };
  119. /**
  120. * @override
  121. */
  122. goog.graphics.LinearGradient.prototype.getColor1 = function() {
  123. return this.color1_;
  124. };
  125. /**
  126. * @override
  127. */
  128. goog.graphics.LinearGradient.prototype.getColor2 = function() {
  129. return this.color2_;
  130. };
  131. /**
  132. * @return {?number} The start opacity of the gradient.
  133. */
  134. goog.graphics.LinearGradient.prototype.getOpacity1 = function() {
  135. return this.opacity1_;
  136. };
  137. /**
  138. * @return {?number} The end opacity of the gradient.
  139. */
  140. goog.graphics.LinearGradient.prototype.getOpacity2 = function() {
  141. return this.opacity2_;
  142. };