1  /**
     2   * properties.TextShortcuts
     3   * Special properties for the Tweener class to handle MovieClip filters
     4   * The function names are strange/inverted because it makes for easier debugging (alphabetic order). They're only for internal use (on this class) anyways.
     5   *
     6   * @author		Zeh Fernando, Nate Chatellier, Arthur Debert
     7   * @version		1.0.0
     8   */
     9  
    10  import caurina.transitions.Tweener;
    11  import caurina.transitions.AuxFunctions;
    12  
    13  class caurina.transitions.properties.TextShortcuts {
    14  
    15  	/**
    16  	 * There's no constructor.
    17  	 */
    18  	public function TextShortcuts () {
    19  		trace ("This is an static class and should not be instantiated.")
    20  	}
    21  
    22  	/**
    23  	 * Registers all the special properties to the Tweener class, so the Tweener knows what to do with them.
    24  	 */
    25  	public static function init():Void {
    26  		// Normal properties
    27  		Tweener.registerSpecialProperty("_text", _text_get, _text_set, undefined, _text_preProcess);
    28  //		Tweener.registerSpecialPropertyModifier("_text", _text_modifier, _text_get);
    29  
    30  		// TextFormat-based properties
    31  		Tweener.registerSpecialPropertySplitter("_text_color",		_generic_color_splitter, ["_text_color_r", "_text_color_g", "_text_color_b"]);
    32  		Tweener.registerSpecialProperty("_text_color_r",			_textFormat_property_get,	_textFormat_property_set,	["color", true, "r"]);
    33  		Tweener.registerSpecialProperty("_text_color_g",			_textFormat_property_get,	_textFormat_property_set,	["color", true, "g"]);
    34  		Tweener.registerSpecialProperty("_text_color_b",			_textFormat_property_get,	_textFormat_property_set,	["color", true, "b"]);
    35  		Tweener.registerSpecialProperty("_text_indent",				_textFormat_property_get,	_textFormat_property_set,	["indent"]);
    36  		Tweener.registerSpecialProperty("_text_leading",			_textFormat_property_get,	_textFormat_property_set,	["leading"]);
    37  		Tweener.registerSpecialProperty("_text_leftMargin",			_textFormat_property_get,	_textFormat_property_set,	["leftMargin"]);
    38  		Tweener.registerSpecialProperty("_text_letterSpacing",		_textFormat_property_get,	_textFormat_property_set,	["letterSpacing"]);
    39  		Tweener.registerSpecialProperty("_text_rightMargin",		_textFormat_property_get,	_textFormat_property_set,	["rightMargin"]);
    40  		Tweener.registerSpecialProperty("_text_size",				_textFormat_property_get,	_textFormat_property_set,	["size"]);
    41  
    42  	}
    43  
    44  
    45  	// ==================================================================================================================================
    46  	// NORMAL SPECIAL PROPERTY functions ------------------------------------------------------------------------------------------------
    47  
    48  	// ----------------------------------------------------------------------------------------------------------------------------------
    49  	// _text
    50  
    51  	/**
    52  	 * Returns the current frame number from the movieclip timeline
    53  	 *
    54  	 * @param		p_obj				Object		MovieClip object
    55  	 * @return							Number		The current frame
    56  	 */
    57  	public static function _text_get (p_obj:Object, p_parameters:Array, p_extra:Object):Number {
    58  		//return p_obj._currentFrame;
    59  		return -p_obj.text.length;
    60  	}
    61  
    62  	/**
    63  	 * Sets the timeline frame
    64  	 *
    65  	 * @param		p_obj				Object		MovieClip object
    66  	 * @param		p_value				Number		New frame number
    67  	 */
    68  	public static function _text_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object):Void {
    69  		//p_obj.gotoAndStop(Math.round(p_value));
    70  		//p_obj.text = 
    71  		if (p_value < 0) {
    72  			// Old text
    73  			p_obj.text = p_extra.oldText.substr(0, -Math.round(p_value));
    74  		} else {
    75  			// New text
    76  			p_obj.text = p_extra.newText.substr(0, Math.round(p_value));
    77  		}
    78  	}
    79  
    80  	public static function _text_preProcess (p_obj:Object, p_parameters:Array, p_originalValueComplete:Object, p_extra:Object): Number {
    81  		p_extra.oldText = p_obj.text;
    82  		p_extra.newText = p_originalValueComplete;
    83  		return p_extra.newText.length;
    84  	}
    85  
    86  	// ==================================================================================================================================
    87  	// PROPERTY GROUPING/SPLITTING functions --------------------------------------------------------------------------------------------
    88  
    89  	// ----------------------------------------------------------------------------------------------------------------------------------
    90  	// generic splitters
    91  
    92  	/**
    93  	 * A generic color splitter - from 0xrrggbb to r, g, b with the name of the parameters passed
    94  	 *
    95  	 * @param		p_value				Number		The original _color value
    96  	 * @return							Array		An array containing the .name and .value of all new properties
    97  	 */
    98  	public static function _generic_color_splitter (p_value:Number, p_parameters:Array):Array {
    99  		var nArray:Array = new Array();
   100  		nArray.push({name:p_parameters[0], value:AuxFunctions.numberToR(p_value)});
   101  		nArray.push({name:p_parameters[1], value:AuxFunctions.numberToG(p_value)});
   102  		nArray.push({name:p_parameters[2], value:AuxFunctions.numberToB(p_value)});
   103  		return nArray;
   104  	}
   105  
   106  
   107  	// ==================================================================================================================================
   108  	// NORMAL SPECIAL PROPERTY functions ------------------------------------------------------------------------------------------------
   109  
   110  	/**
   111  	 * Generic function for the textformat properties
   112  	 */
   113  	public static function _textFormat_property_get (p_obj:Object, p_parameters:Array):Number {
   114  		var fmt:TextFormat = p_obj.getTextFormat();
   115  		var propertyName:String = p_parameters[0];
   116  		var isColor:Boolean = p_parameters[1];
   117  		if (!isColor) {
   118  			// Standard property
   119  			return (fmt[propertyName]);
   120  		} else {
   121  			// Composite, color channel
   122  			var colorComponent:String = p_parameters[2];
   123  			if (colorComponent == "r") return AuxFunctions.numberToR(fmt[propertyName]);
   124  			if (colorComponent == "g") return AuxFunctions.numberToG(fmt[propertyName]);
   125  			if (colorComponent == "b") return AuxFunctions.numberToB(fmt[propertyName]);
   126  		}
   127  
   128  		return null;
   129  	}
   130  
   131  	public static function _textFormat_property_set (p_obj:Object, p_value:Number, p_parameters:Array):Void {
   132  		var fmt:TextFormat = p_obj.getTextFormat();
   133  		var propertyName:String = p_parameters[0];
   134  		var isColor:Boolean = p_parameters[1];
   135  		if (!isColor) {
   136  			// Standard property
   137  			fmt[propertyName] = p_value;
   138  		} else {
   139  			// Composite, color channel
   140  			var colorComponent:String = p_parameters[2];
   141  			if (colorComponent == "r") fmt[propertyName] = (fmt[propertyName] & 0xffff) | (p_value << 16);
   142  			if (colorComponent == "g") fmt[propertyName] = (fmt[propertyName] & 0xff00ff) | (p_value << 8);
   143  			if (colorComponent == "b") fmt[propertyName] = (fmt[propertyName] & 0xffff00) | p_value;
   144  		}
   145  		
   146  		p_obj.setTextFormat(fmt);
   147  		p_obj.setNewTextFormat(fmt);
   148  
   149  	}
   150  
   151  }
   152