1 /*
  2  *Copyright (c) 2009, TellurianRing.com
  3  *All rights reserved.
  4  *
  5  *Redistribution and use in source and binary forms, with or without modification,
  6  *are permitted provided that the following conditions are met:
  7  *
  8  *   Redistributions of source code must retain the above copyright notice, this
  9  *   list of conditions and the following disclaimer.
 10  *   Redistributions in binary form must reproduce the above copyright notice,
 11  *   this list of conditions and the following disclaimer in the documentation
 12  *   and/or other materials provided with the distribution.
 13  *   Neither the name of the Organization (TellurianRing.com) nor the names of
 14  *   its contributors may be used to endorse or promote products derived from
 15  *   this software without specific prior written permission.
 16  *
 17  *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 18  *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19  *WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20  *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 21  *ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22  *(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23  *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 24  *ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25  *(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 26  *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27  */
 28 /**
 29  * @class This Content simply prints out the current frames per second.
 30  * @extends Text
 31  * @param {Object} _details A JSON object. This content has the same properties as the Text
 32  *        object.
 33  * <table cellpadding="0" cellspacing="1" border="0" class="constructor_details">
 34  *    <tr><th>Property</th>        <th>Required</th> <th>Default</th></tr>
 35  *    <tr><td>text</td>            <td>no</td>       <td>"FPS: "</td></tr>
 36  * </table>
 37  * "text" is prepended to the actual FPS value: "[text][FPS]"
 38  * @see Text for other properties, and styling information.
 39  * @example // Creates a new FPS object
 40  * FPS({ x: 10, y: 16 })
 41  * <div id="fps_example_1"></div>
 42  * <script type="text/javascript">
 43  *    Stage({
 44  *       container_id: "fps_example_1",
 45  *       width: 100, height: 100,
 46  *       scene: Scene({
 47  *          content: [
 48  *             FPS({ x: 10, y: 16 })
 49  *          ]
 50  *       })
 51  *    });
 52  * </script>
 53  * @requires <a href="http://www.mozilla.com/firefox">Firefox 3.5.x</a>, <a href="http://www.apple.com/safari/download">Safari</a>, or <a href="http://www.google.com/chrome">Google Chrome</a>
 54  */
 55 function FPS(_details) { // {{{
 56    function _FPS(_details) { // {{{
 57       // Private Members {{{
 58       var text = check(_details.text, "FPS: ");
 59       var updates = 0;
 60       var that = this;
 61       // }}} Private Members
 62       
 63       // Public Members {{{
 64       this.update = function(_run_time) {
 65          this.setText(text + (updates++ / (_run_time / Units.seconds)));
 66          if(exists(_details.update)) {
 67             _details.update.apply(this, arguments);
 68          }
 69       }
 70       // }}} Public Members
 71    } // }}} _FPS
 72    Text(_details).extend(_FPS);
 73    var theFps = new _FPS(_details);
 74    return theFps;
 75 } // }}} FPS
 76 // These properties are for jEdit - Programmer's Text Editor.
 77 // Load this file in jEdit to see what they do.
 78 // ::folding=explicit:mode=javascript:noTabs=true:collapseFolds=4::
 79