Path: blob/trunk/third_party/closure/goog/graphics/ext/graphics.js
1865 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.131415/**16* @fileoverview Graphics surface type.17* @author [email protected] (Robby Walker)18*/192021goog.provide('goog.graphics.ext.Graphics');2223goog.require('goog.events');24goog.require('goog.events.EventType');25goog.require('goog.graphics');26goog.require('goog.graphics.ext.Group');27282930/**31* Wrapper for a graphics surface.32* @param {string|number} width The width in pixels. Strings33* expressing percentages of parent with (e.g. '80%') are also accepted.34* @param {string|number} height The height in pixels. Strings35* expressing percentages of parent with (e.g. '80%') are also accepted.36* @param {?number=} opt_coordWidth The coordinate width - if37* omitted or null, defaults to same as width.38* @param {?number=} opt_coordHeight The coordinate height. - if39* omitted or null, defaults to same as height.40* @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the41* document we want to render in.42* @param {boolean=} opt_isSimple Flag used to indicate the graphics object will43* be drawn to in a single pass, and the fastest implementation for this44* scenario should be favored. NOTE: Setting to true may result in45* degradation of text support.46* @constructor47* @extends {goog.graphics.ext.Group}48* @final49*/50goog.graphics.ext.Graphics = function(51width, height, opt_coordWidth, opt_coordHeight, opt_domHelper,52opt_isSimple) {53var surface = opt_isSimple ?54goog.graphics.createSimpleGraphics(55width, height, opt_coordWidth, opt_coordHeight, opt_domHelper) :56goog.graphics.createGraphics(57width, height, opt_coordWidth, opt_coordHeight, opt_domHelper);58this.implementation_ = surface;5960goog.graphics.ext.Group.call(this, null, surface.getCanvasElement());6162goog.events.listen(63surface, goog.events.EventType.RESIZE, this.updateChildren, false, this);64};65goog.inherits(goog.graphics.ext.Graphics, goog.graphics.ext.Group);666768/**69* The root level graphics implementation.70* @type {goog.graphics.AbstractGraphics}71* @private72*/73goog.graphics.ext.Graphics.prototype.implementation_;747576/**77* @return {goog.graphics.AbstractGraphics} The graphics implementation layer.78*/79goog.graphics.ext.Graphics.prototype.getImplementation = function() {80return this.implementation_;81};828384/**85* Changes the coordinate size.86* @param {number} coordWidth The coordinate width.87* @param {number} coordHeight The coordinate height.88*/89goog.graphics.ext.Graphics.prototype.setCoordSize = function(90coordWidth, coordHeight) {91this.implementation_.setCoordSize(coordWidth, coordHeight);92goog.graphics.ext.Graphics.superClass_.setSize.call(93this, coordWidth, coordHeight);94};959697/**98* @return {goog.math.Size} The coordinate size.99*/100goog.graphics.ext.Graphics.prototype.getCoordSize = function() {101return this.implementation_.getCoordSize();102};103104105/**106* Changes the coordinate system position.107* @param {number} left The coordinate system left bound.108* @param {number} top The coordinate system top bound.109*/110goog.graphics.ext.Graphics.prototype.setCoordOrigin = function(left, top) {111this.implementation_.setCoordOrigin(left, top);112};113114115/**116* @return {!goog.math.Coordinate} The coordinate system position.117*/118goog.graphics.ext.Graphics.prototype.getCoordOrigin = function() {119return this.implementation_.getCoordOrigin();120};121122123/**124* Change the size of the canvas.125* @param {number} pixelWidth The width in pixels.126* @param {number} pixelHeight The height in pixels.127*/128goog.graphics.ext.Graphics.prototype.setPixelSize = function(129pixelWidth, pixelHeight) {130this.implementation_.setSize(pixelWidth, pixelHeight);131132var coordSize = this.getCoordSize();133goog.graphics.ext.Graphics.superClass_.setSize.call(134this, coordSize.width, coordSize.height);135};136137138/**139* @return {goog.math.Size?} Returns the number of pixels spanned by the140* surface, or null if the size could not be computed due to the size being141* specified in percentage points and the component not being in the142* document.143*/144goog.graphics.ext.Graphics.prototype.getPixelSize = function() {145return this.implementation_.getPixelSize();146};147148149/**150* @return {number} The coordinate width of the canvas.151* @override152*/153goog.graphics.ext.Graphics.prototype.getWidth = function() {154return this.implementation_.getCoordSize().width;155};156157158/**159* @return {number} The coordinate width of the canvas.160* @override161*/162goog.graphics.ext.Graphics.prototype.getHeight = function() {163return this.implementation_.getCoordSize().height;164};165166167/**168* @return {number} Returns the number of pixels per unit in the x direction.169* @override170*/171goog.graphics.ext.Graphics.prototype.getPixelScaleX = function() {172return this.implementation_.getPixelScaleX();173};174175176/**177* @return {number} Returns the number of pixels per unit in the y direction.178* @override179*/180goog.graphics.ext.Graphics.prototype.getPixelScaleY = function() {181return this.implementation_.getPixelScaleY();182};183184185/**186* @return {Element} The root element of the graphics surface.187*/188goog.graphics.ext.Graphics.prototype.getElement = function() {189return this.implementation_.getElement();190};191192193/**194* Renders the underlying graphics.195*196* @param {Element} parentElement Parent element to render the component into.197*/198goog.graphics.ext.Graphics.prototype.render = function(parentElement) {199this.implementation_.render(parentElement);200};201202203/**204* Never transform a surface.205* @override206*/207goog.graphics.ext.Graphics.prototype.transform = goog.nullFunction;208209210/**211* Called from the parent class, this method resets any pre-computed positions212* and sizes.213* @protected214* @override215*/216goog.graphics.ext.Graphics.prototype.redraw = function() {217this.transformChildren();218};219220221