|
| 1 | +goog.provide('acgraph.vector.SimpleText'); |
| 2 | + |
| 3 | +goog.require('acgraph.utils.IdGenerator'); |
| 4 | +goog.require('acgraph.vector.Element'); |
| 5 | +goog.require('goog.math.Rect'); |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + Text class.<br> |
| 11 | + <b>Do not invoke constructor directly.</b> Use {@link acgraph.vector.Stage#text} or |
| 12 | + {@link acgraph.vector.Layer#text} to create layer or stage bound text. |
| 13 | + <br/> Use {@link acgraph.text} to create unbound text. |
| 14 | + @see acgraph.vector.Stage#text |
| 15 | + @see acgraph.vector.Layer#text |
| 16 | + @see acgraph.text |
| 17 | + @name acgraph.vector.SimpleText |
| 18 | + @constructor |
| 19 | + @extends {acgraph.vector.Element} |
| 20 | + */ |
| 21 | +acgraph.vector.SimpleText = function() { |
| 22 | + /** |
| 23 | + * Element bounds. |
| 24 | + * acgraph.vector.Element.DirtyState.DATA must be set with any changes. |
| 25 | + * @type {goog.math.Rect} |
| 26 | + * @protected |
| 27 | + */ |
| 28 | + this.bounds = new goog.math.Rect(0, 0, 0, 0); |
| 29 | + |
| 30 | + goog.base(this); |
| 31 | +}; |
| 32 | +goog.inherits(acgraph.vector.SimpleText, acgraph.vector.Element); |
| 33 | + |
| 34 | + |
| 35 | +/** |
| 36 | + * Text. |
| 37 | + * @type {?string} |
| 38 | + * @private |
| 39 | + */ |
| 40 | +acgraph.vector.SimpleText.prototype.text_ = null; |
| 41 | + |
| 42 | + |
| 43 | +/** |
| 44 | + * Supported states. Inherited from Element and text data added. |
| 45 | + * @type {number} |
| 46 | + */ |
| 47 | +acgraph.vector.SimpleText.prototype.SUPPORTED_DIRTY_STATES = |
| 48 | + acgraph.vector.Element.prototype.SUPPORTED_DIRTY_STATES | |
| 49 | + acgraph.vector.Element.DirtyState.DATA; |
| 50 | + |
| 51 | + |
| 52 | +/** @inheritDoc */ |
| 53 | +acgraph.vector.SimpleText.prototype.getElementTypePrefix = function() { |
| 54 | + return acgraph.utils.IdGenerator.ElementTypePrefix.SIMPLE_TEXT; |
| 55 | +}; |
| 56 | + |
| 57 | + |
| 58 | +/** @inheritDoc */ |
| 59 | +acgraph.vector.SimpleText.prototype.getBoundsWithoutTransform = function() { |
| 60 | + return this.bounds.clone(); |
| 61 | +}; |
| 62 | + |
| 63 | + |
| 64 | +/** @inheritDoc */ |
| 65 | +acgraph.vector.SimpleText.prototype.getBoundsWithTransform = acgraph.vector.SimpleText.prototype.getBoundsWithoutTransform; |
| 66 | + |
| 67 | + |
| 68 | +/** |
| 69 | + Get current text. |
| 70 | + @param {string=} opt_value . |
| 71 | + @return {string|acgraph.vector.SimpleText} . |
| 72 | + */ |
| 73 | +acgraph.vector.SimpleText.prototype.text = function(opt_value) { |
| 74 | + if (goog.isDef(opt_value)) { |
| 75 | + if (opt_value != this.text_) { |
| 76 | + this.text_ = String(opt_value); |
| 77 | + var stageSuspended = !this.getStage() || this.getStage().isSuspended(); |
| 78 | + if (!stageSuspended) this.getStage().suspend(); |
| 79 | + this.setDirtyState(acgraph.vector.Element.DirtyState.DATA); |
| 80 | + if (!stageSuspended) this.getStage().resume(); |
| 81 | + } |
| 82 | + return this; |
| 83 | + } |
| 84 | + return this.text_; |
| 85 | +}; |
| 86 | + |
| 87 | + |
| 88 | +//---------------------------------------------------------------------------------------------------------------------- |
| 89 | +// |
| 90 | +// DOM element creation |
| 91 | +// |
| 92 | +//---------------------------------------------------------------------------------------------------------------------- |
| 93 | +/** @inheritDoc */ |
| 94 | +acgraph.vector.SimpleText.prototype.createDomInternal = function() { |
| 95 | + return acgraph.getRenderer().createTextElement(); |
| 96 | +}; |
| 97 | + |
| 98 | + |
| 99 | +/** @inheritDoc */ |
| 100 | +acgraph.vector.SimpleText.prototype.renderInternal = function() { |
| 101 | + if (this.hasDirtyState(acgraph.vector.Element.DirtyState.DATA)) { |
| 102 | + acgraph.getRenderer().setTextData(this); |
| 103 | + this.clearDirtyState(acgraph.vector.Element.DirtyState.DATA); |
| 104 | + } |
| 105 | + |
| 106 | + goog.base(this, 'renderInternal'); |
| 107 | +}; |
| 108 | + |
| 109 | + |
| 110 | +/** @inheritDoc */ |
| 111 | +acgraph.vector.SimpleText.prototype.renderTransformation = function() { |
| 112 | + this.clearDirtyState(acgraph.vector.Element.DirtyState.TRANSFORMATION); |
| 113 | + this.clearDirtyState(acgraph.vector.Element.DirtyState.PARENT_TRANSFORMATION); |
| 114 | +}; |
| 115 | + |
| 116 | + |
| 117 | +//exports |
| 118 | +(function() { |
| 119 | + var proto = acgraph.vector.SimpleText.prototype; |
| 120 | + proto['text'] = proto.text; |
| 121 | + goog.exportSymbol('acgraph.vector.SimpleText', acgraph.vector.SimpleText); |
| 122 | +})(); |
0 commit comments