image.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 A thick wrapper around images.
  16. * @author robbyw@google.com (Robby Walker)
  17. */
  18. goog.provide('goog.graphics.ext.Image');
  19. goog.require('goog.graphics.ext.Element');
  20. /**
  21. * Wrapper for a graphics image element.
  22. * @param {goog.graphics.ext.Group} group Parent for this element.
  23. * @param {string} src The path to the image to display.
  24. * @constructor
  25. * @extends {goog.graphics.ext.Element}
  26. * @final
  27. */
  28. goog.graphics.ext.Image = function(group, src) {
  29. // Initialize with some stock values.
  30. var wrapper = group.getGraphicsImplementation().drawImage(
  31. 0, 0, 1, 1, src, group.getWrapper());
  32. goog.graphics.ext.Element.call(this, group, wrapper);
  33. };
  34. goog.inherits(goog.graphics.ext.Image, goog.graphics.ext.Element);
  35. /**
  36. * Redraw the image. Called when the coordinate system is changed.
  37. * @protected
  38. * @override
  39. */
  40. goog.graphics.ext.Image.prototype.redraw = function() {
  41. goog.graphics.ext.Image.superClass_.redraw.call(this);
  42. // Our position is already handled bu transform_.
  43. this.getWrapper().setSize(this.getWidth(), this.getHeight());
  44. };
  45. /**
  46. * Update the source of the image.
  47. * @param {string} src Source of the image.
  48. */
  49. goog.graphics.ext.Image.prototype.setSource = function(src) {
  50. this.getWrapper().setSource(src);
  51. };