all repos — simplyrpg @ 05a250383b5037effb602fc3ca4d2bb1cdf4da90

Fork of https://github.com/harperd1/simplyRPG — multi-map VTT, token visibility, dark theme, stream HUD

libraries/EaselJS_docs/files/easeljs_display_BitmapText.js.html (view raw)

  1<!DOCTYPE html>
  2<html lang="en">
  3<head>
  4    <meta charset="utf-8">
  5    <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
  6    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
  7    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
  8    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
  9    <script src="../assets/js/yui-source.js"></script>
 10	<title>EaselJS v1.0.0 API Documentation : easeljs/display/BitmapText.js</title>
 11</head>
 12<body class="yui3-skin-sam">
 13
 14<div id="doc">
 15    <div id="hd" class="yui3-g header">
 16        <div class="yui3-u-3-4">
 17            
 18                <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
 19            
 20        </div>
 21        <div class="version">
 22            <em>API Documentation for: 1.0.0</em>
 23        </div>
 24    </div>
 25    <div id="bd" class="yui3-g">
 26
 27        <div class="yui3-u-1-4">
 28            <div id="docs-sidebar" class="sidebar apidocs">
 29                <div id="api-list">
 30    <h2 class="off-left">APIs</h2>
 31    <div id="api-tabview" class="tabview">
 32        <ul class="tabs">
 33            <li><a href="#api-classes">Classes</a></li>
 34        </ul>
 35
 36        <div id="api-tabview-filter">
 37            <input type="search" id="api-filter" placeholder="Type to filter APIs">
 38        </div>
 39
 40        <div id="api-tabview-panel">
 41            <ul id="api-classes" class="apis classes">
 42            
 43                <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
 44            
 45                <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
 46            
 47                <li><a href="../classes/Bitmap.html">Bitmap</a></li>
 48            
 49                <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
 50            
 51                <li><a href="../classes/BitmapText.html">BitmapText</a></li>
 52            
 53                <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
 54            
 55                <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
 56            
 57                <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
 58            
 59                <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
 60            
 61                <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
 62            
 63                <li><a href="../classes/Container.html">Container</a></li>
 64            
 65                <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
 66            
 67                <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
 68            
 69                <li><a href="../classes/DOMElement.html">DOMElement</a></li>
 70            
 71                <li><a href="../classes/EaselJS.html">EaselJS</a></li>
 72            
 73                <li><a href="../classes/Event.html">Event</a></li>
 74            
 75                <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
 76            
 77                <li><a href="../classes/Filter.html">Filter</a></li>
 78            
 79                <li><a href="../classes/Graphics.html">Graphics</a></li>
 80            
 81                <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
 82            
 83                <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
 84            
 85                <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
 86            
 87                <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
 88            
 89                <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
 90            
 91                <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
 92            
 93                <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
 94            
 95                <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
 96            
 97                <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
 98            
 99                <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100            
101                <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102            
103                <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104            
105                <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106            
107                <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108            
109                <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110            
111                <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112            
113                <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114            
115                <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116            
117                <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118            
119                <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120            
121                <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122            
123                <li><a href="../classes/Point.html">Point</a></li>
124            
125                <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126            
127                <li><a href="../classes/Shadow.html">Shadow</a></li>
128            
129                <li><a href="../classes/Shape.html">Shape</a></li>
130            
131                <li><a href="../classes/Sprite.html">Sprite</a></li>
132            
133                <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134            
135                <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136            
137                <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138            
139                <li><a href="../classes/Stage.html">Stage</a></li>
140            
141                <li><a href="../classes/StageGL.html">StageGL</a></li>
142            
143                <li><a href="../classes/Text.html">Text</a></li>
144            
145                <li><a href="../classes/Ticker.html">Ticker</a></li>
146            
147                <li><a href="../classes/Touch.html">Touch</a></li>
148            
149                <li><a href="../classes/UID.html">UID</a></li>
150            
151                <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152            
153                <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154            
155                <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156            
157            </ul>
158
159            <ul id="api-modules" class="apis modules">
160            
161                <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162            
163                <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164            
165            </ul>
166        </div>
167    </div>
168</div>
169
170            </div>
171        </div>
172        <div class="yui3-u-3-4">
173            <div id="api-options">
174        Show:
175        <label for="api-show-inherited">
176            <input type="checkbox" id="api-show-inherited" checked>
177            Inherited
178        </label>
179
180        <label for="api-show-protected">
181            <input type="checkbox" id="api-show-protected">
182            Protected
183        </label>
184
185        <label for="api-show-private">
186            <input type="checkbox" id="api-show-private">
187            Private
188        </label>
189        <label for="api-show-deprecated">
190            <input type="checkbox" id="api-show-deprecated">
191            Deprecated
192        </label>
193
194    </div>
195            <div class="apidocs">
196                <div id="docs-main">
197                    <div class="content source-content">
198                        <script>
199	var name = easeljs/display/BitmapText.js      
200</script>
201<h1 class="file-heading">File:BitmapText.js</h1>
202
203<div class="file">
204    <pre class="code prettyprint linenums">
205/*
206* BitmapText
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the &quot;Software&quot;), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233this.createjs = this.createjs || {};
234
235(function () {
236	&quot;use strict&quot;;
237
238
239// constructor:
240	/**
241	 * Displays text using bitmap glyphs defined in a sprite sheet. Multi-line text is supported using new line characters,
242	 * but automatic wrapping is not supported. See the {{#crossLink &quot;BitmapText/spriteSheet:property&quot;}}{{/crossLink}}
243	 * property for more information on defining glyphs.
244	 *
245	 * &lt;strong&gt;Important:&lt;/strong&gt; While BitmapText extends Container, it is not designed to be used as one.
246	 * As such, methods like addChild and removeChild are disabled.
247	 *
248	 *
249	 * @class BitmapText
250	 * @extends DisplayObject
251	 * @param {String} [text=&quot;&quot;] The text to display.
252	 * @param {SpriteSheet} [spriteSheet=null] The spritesheet that defines the character glyphs.
253	 * @constructor
254	 **/
255	function BitmapText(text, spriteSheet) {
256		this.Container_constructor();
257		
258		
259	// public properties:
260		/**
261		 * The text to display.
262		 * @property text
263		 * @type String
264		 * @default &quot;&quot;
265		 **/
266		this.text = text||&quot;&quot;;
267		
268		/**
269		 * A SpriteSheet instance that defines the glyphs for this bitmap text. Each glyph/character
270		 * should have a single frame animation defined in the sprite sheet named the same as
271		 * corresponding character. For example, the following animation definition:
272		 *
273		 * 		&quot;A&quot;: {frames: [0]}
274		 *
275		 * would indicate that the frame at index 0 of the spritesheet should be drawn for the &quot;A&quot; character. The short form
276		 * is also acceptable:
277		 * 
278		 * 		&quot;A&quot;: 0
279		 *
280		 * Note that if a character in the text is not found in the sprite sheet, it will also
281		 * try to use the alternate case (upper or lower).
282		 *
283		 * See SpriteSheet for more information on defining sprite sheet data.
284		 * @property spriteSheet
285		 * @type SpriteSheet
286		 * @default null
287		 **/
288		this.spriteSheet = spriteSheet;
289	
290		/**
291		 * The height of each line of text. If 0, then it will use a line height calculated
292		 * by checking for the height of the &quot;1&quot;, &quot;T&quot;, or &quot;L&quot; character (in that order). If
293		 * those characters are not defined, it will use the height of the first frame of the
294		 * sprite sheet.
295		 * @property lineHeight
296		 * @type Number
297		 * @default 0
298		 **/
299		this.lineHeight = 0;
300	
301		/**
302		 * This spacing (in pixels) will be added after each character in the output.
303		 * @property letterSpacing
304		 * @type Number
305		 * @default 0
306		 **/
307		this.letterSpacing = 0;
308	
309		/**
310		 * If a space character is not defined in the sprite sheet, then empty pixels equal to
311		 * spaceWidth will be inserted instead. If 0, then it will use a value calculated
312		 * by checking for the width of the &quot;1&quot;, &quot;l&quot;, &quot;E&quot;, or &quot;A&quot; character (in that order). If
313		 * those characters are not defined, it will use the width of the first frame of the
314		 * sprite sheet.
315		 * @property spaceWidth
316		 * @type Number
317		 * @default 0
318		 **/
319		this.spaceWidth = 0;
320		
321		
322	// private properties:
323	 	/**
324		 * @property _oldProps
325		 * @type Object
326		 * @protected
327		 **/
328		this._oldProps = {text:0,spriteSheet:0,lineHeight:0,letterSpacing:0,spaceWidth:0};
329
330		/**
331		 * Used to track the object which this class attached listeners to, helps optimize listener attachment.
332		 * @property _oldStage
333		 * @type Stage
334		 * @protected
335		 */
336		this._oldStage = null;
337		/**
338		 * The event listener proxy triggered drawing draw for special circumstances.
339		 * @property _drawAction
340		 * @type function
341		 * @protected
342		 */
343		this._drawAction = null;
344	}
345	var p = createjs.extend(BitmapText, createjs.Container);
346
347// static properties:
348	/**
349	 * BitmapText uses Sprite instances to draw text. To reduce the creation and destruction of instances (and thus garbage collection), it maintains
350	 * an internal object pool of sprite instances to reuse. Increasing this value can cause more sprites to be
351	 * retained, slightly increasing memory use, but reducing instantiation.
352	 * @property maxPoolSize
353	 * @type Number
354	 * @static
355	 * @default 100
356	 **/
357	BitmapText.maxPoolSize = 100;
358	
359	/**
360	 * Sprite object pool.
361	 * @type {Array}
362	 * @static
363	 * @private
364	 */
365	BitmapText._spritePool = [];
366
367	
368// public methods:
369	/**
370	 * Docced in superclass.
371	 **/
372	p.draw = function(ctx, ignoreCache) {
373		if (this.DisplayObject_draw(ctx, ignoreCache)) { return; }
374		this._updateState();
375		this.Container_draw(ctx, ignoreCache);
376	};
377	
378	/**
379	 * Docced in superclass.
380	 **/
381	p.getBounds = function() {
382		this._updateText();
383		return this.Container_getBounds();
384	};
385	
386	/**
387	 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
388	 * This does not account for whether it would be visible within the boundaries of the stage.
389	 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
390	 * @method isVisible
391	 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
392	 **/
393	p.isVisible = function() {
394		var hasContent = this.cacheCanvas || (this.spriteSheet &amp;&amp; this.spriteSheet.complete &amp;&amp; this.text);
395		return !!(this.visible &amp;&amp; this.alpha &gt; 0 &amp;&amp; this.scaleX !== 0 &amp;&amp; this.scaleY !== 0 &amp;&amp; hasContent);
396	};
397	
398	p.clone = function() {
399		return this._cloneProps(new BitmapText(this.text, this.spriteSheet));
400	};
401	
402	/**
403	 * &lt;strong&gt;Disabled in BitmapText.&lt;/strong&gt;
404	 * @method addChild
405	 **/
406	/**
407	 * &lt;strong&gt;Disabled in BitmapText.&lt;/strong&gt;
408	 * @method addChildAt
409	 **/
410	/**
411	 * &lt;strong&gt;Disabled in BitmapText.&lt;/strong&gt;
412	 * @method removeChild
413	 **/
414	/**
415	 * &lt;strong&gt;Disabled in BitmapText.&lt;/strong&gt;
416	 * @method removeChildAt
417	 **/
418	/**
419	 * &lt;strong&gt;Disabled in BitmapText.&lt;/strong&gt;
420	 * @method removeAllChildren
421	 **/
422	p.addChild = p.addChildAt = p.removeChild = p.removeChildAt = p.removeAllChildren = function() {};
423
424
425// private methods:
426	/**
427	 * Docced in superclass.
428	 **/
429	p._updateState = function() {
430		this._updateText();
431	};
432
433 	/**
434	 * @method _cloneProps
435	 * @param {BitmapText} o
436	 * @return {BitmapText} o
437	 * @protected
438	 **/
439	p._cloneProps = function(o) {
440		this.Container__cloneProps(o);
441		o.lineHeight = this.lineHeight;
442		o.letterSpacing = this.letterSpacing;
443		o.spaceWidth = this.spaceWidth;
444		return o;
445	};
446	
447	/**
448	 * @method _getFrameIndex
449	 * @param {String} character
450	 * @param {SpriteSheet} spriteSheet
451	 * @return {Number}
452	 * @protected
453	 **/
454	p._getFrameIndex = function(character, spriteSheet) {
455		var c, o = spriteSheet.getAnimation(character);
456		if (!o) {
457			(character != (c = character.toUpperCase())) || (character != (c = character.toLowerCase())) || (c=null);
458			if (c) { o = spriteSheet.getAnimation(c); }
459		}
460		return o &amp;&amp; o.frames[0];
461	};
462	
463	/**
464	 * @method _getFrame
465	 * @param {String} character
466	 * @param {SpriteSheet} spriteSheet
467	 * @return {Object}
468	 * @protected
469	 **/
470	p._getFrame = function(character, spriteSheet) {
471		var index = this._getFrameIndex(character, spriteSheet);
472		return index == null ? index : spriteSheet.getFrame(index);
473	};
474
475	/**
476	 * @method _getLineHeight
477	 * @param {SpriteSheet} ss
478	 * @return {Number}
479	 * @protected
480	 **/
481	p._getLineHeight = function(ss) {
482		var frame = this._getFrame(&quot;1&quot;,ss) || this._getFrame(&quot;T&quot;,ss) || this._getFrame(&quot;L&quot;,ss) || ss.getFrame(0);
483		return frame ? frame.rect.height : 1;
484	};
485
486	/**
487	 * @method _getSpaceWidth
488	 * @param {SpriteSheet} ss
489	 * @return {Number}
490	 * @protected
491	 **/
492	p._getSpaceWidth = function(ss) {
493		var frame = this._getFrame(&quot;1&quot;,ss) || this._getFrame(&quot;l&quot;,ss) || this._getFrame(&quot;e&quot;,ss) || this._getFrame(&quot;a&quot;,ss) || ss.getFrame(0);
494		return frame ? frame.rect.width : 1;
495	};
496
497	/**
498	 * @method _updateText
499	 * @protected
500	 **/
501	p._updateText = function() {
502		var x=0, y=0, o=this._oldProps, change=false, spaceW=this.spaceWidth, lineH=this.lineHeight, ss=this.spriteSheet;
503		var pool=BitmapText._spritePool, kids=this.children, childIndex=0, numKids=kids.length, sprite;
504		
505		for (var n in o) {
506			if (o[n] != this[n]) {
507				o[n] = this[n];
508				change = true;
509			}
510		}
511		if (!change) { return; }
512		
513		var hasSpace = !!this._getFrame(&quot; &quot;, ss);
514		if (!hasSpace &amp;&amp; !spaceW) { spaceW = this._getSpaceWidth(ss); }
515		if (!lineH) { lineH = this._getLineHeight(ss); }
516		
517		for(var i=0, l=this.text.length; i&lt;l; i++) {
518			var character = this.text.charAt(i);
519			if (character == &quot; &quot; &amp;&amp; !hasSpace) {
520				x += spaceW;
521				continue;
522			} else if (character==&quot;\n&quot; || character==&quot;\r&quot;) {
523				if (character==&quot;\r&quot; &amp;&amp; this.text.charAt(i+1) == &quot;\n&quot;) { i++; } // crlf
524				x = 0;
525				y += lineH;
526				continue;
527			}
528
529			var index = this._getFrameIndex(character, ss);
530			if (index == null) { continue; }
531			
532			if (childIndex &lt; numKids) {
533				sprite = kids[childIndex];
534			} else {
535				kids.push(sprite = pool.length ? pool.pop() : new createjs.Sprite());
536				sprite.parent = this;
537				numKids++;
538			}
539			sprite.spriteSheet = ss;
540			sprite.gotoAndStop(index);
541			sprite.x = x;
542			sprite.y = y;
543			childIndex++;
544			
545			x += sprite.getBounds().width + this.letterSpacing;
546		}
547		while (numKids &gt; childIndex) {
548			 // faster than removeChild.
549			pool.push(sprite = kids.pop());
550			sprite.parent = null;
551			numKids--;
552		}
553		if (pool.length &gt; BitmapText.maxPoolSize) { pool.length = BitmapText.maxPoolSize; }
554	};
555
556
557	createjs.BitmapText = createjs.promote(BitmapText, &quot;Container&quot;);
558}());
559
560    </pre>
561</div>
562
563                    </div>
564                </div>
565            </div>
566        </div>
567    </div>
568</div>
569<script src="../assets/vendor/prettify/prettify-min.js"></script>
570<script>prettyPrint();</script>
571<script src="../assets/js/yui-prettify.js"></script>
572<script src="../assets/../api.js"></script>
573<script src="../assets/js/api-filter.js"></script>
574<script src="../assets/js/api-list.js"></script>
575<script src="../assets/js/api-search.js"></script>
576<script src="../assets/js/apidocs.js"></script>
577</body>
578</html>