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