My favorites | Sign in
Project Logo
                
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package org.goverla.skins {

import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Shape;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.getDefinitionByName;

import mx.core.Container;
import mx.core.FlexLoader;
import mx.core.IChildList;
import mx.core.mx_internal;
import mx.resources.ResourceBundle;
import mx.resources.ResourceManager;
import mx.skins.Border;
import mx.styles.ISimpleStyleClient;
import mx.utils.StringUtil;

use namespace mx_internal;

/**
* PatternRectangularBorder is "copy-paste" style extended class from
* Adobe's mx.skins.RectangularBorder. Because of crap design of RectangularBorder class we can't extend it
* by OOP nature =(.
* So we can see here a lot of unknown stuff. I havn't a lot of time to clear this class.
*/
public class PatternRectangularBorder extends Border {

loadResources();

private static var resourceNotLoaded:String;

private static function loadResources() : void {
resourceNotLoaded = ResourceManager.getInstance().getString("skins", "notLoaded");
}

mx_internal var loader:Loader;

mx_internal function get hasBackgroundImage():Boolean {
return backgroundImage != null;
}

mx_internal function get backgroundImageRect():Rectangle {
return _backgroundImageRect;
}

mx_internal function set backgroundImageRect(value:Rectangle):void
{
_backgroundImageRect = value;

invalidateDisplayList();
}

public function PatternRectangularBorder()
{
super();

addEventListener(Event.REMOVED, removedHandler);
}

override protected function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void
{
if (!parent)
return;

var newStyle:Object = getStyle("backgroundImage");
if (newStyle != backgroundImageStyle)
{
backgroundImageStyle = newStyle;
backgroundImage = null;

var cls:Class;

if (newStyle && newStyle as Class)
{
cls = Class(newStyle);
initBackgroundImage(new cls());
}
else if (newStyle && newStyle is String)
{
try
{
cls = Class(getDefinitionByName(String(newStyle)));
}
catch(e:Error)
{
// ignore
}

if (cls)
{
var newStyleObj:DisplayObject = new cls();
initBackgroundImage(newStyleObj);
}
else
{
loader = new FlexLoader();
loader.contentLoaderInfo.addEventListener(
Event.COMPLETE, completeEventHandler);
loader.contentLoaderInfo.addEventListener(
IOErrorEvent.IO_ERROR, errorEventHandler);
loader.contentLoaderInfo.addEventListener(
ErrorEvent.ERROR, errorEventHandler);
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
loader.load(new URLRequest(String(newStyle)), loaderContext);
}
}
else if (newStyle)
{
throw new Error(StringUtil.substitute(resourceNotLoaded, newStyle));
}
} else {
if (backgroundImage)
{
initBackgroundImage(backgroundImage);
}
}
}

private function initBackgroundImage(image:DisplayObject):void
{
backgroundImage = image;

if (image is Loader)
{
backgroundImageWidth = Loader(image).contentLoaderInfo.width;
backgroundImageHeight = Loader(image).contentLoaderInfo.height;
}
else
{
backgroundImageWidth = backgroundImage.width;
backgroundImageHeight = backgroundImage.height;

if (image is ISimpleStyleClient)
{
ISimpleStyleClient(image).styleName = styleName;
}
}

// New code for pattern support

var backgroundImageData : BitmapData = new BitmapData(backgroundImageWidth, backgroundImageHeight);
backgroundImageData.draw(backgroundImage);

graphics.clear();
graphics.beginBitmapFill(backgroundImageData);

var backgroundRepeat : String = getStyle("backgroundRepeat") as String;
switch (backgroundRepeat) {
case null :
case "repeat" :
graphics.drawRect(0, 0, this.width, this.height);
break;

case "repeat-y" :
graphics.drawRect(0, 0, backgroundImageWidth, this.height);
break;

case "repeat-x" :
graphics.drawRect(0, 0, this.width, backgroundImageHeight);
break;
}
}

private function errorEventHandler(event : Event) : void
{
// Ignore errors that occure during background image loading.
}

private function completeEventHandler(event : Event) : void
{
if (!parent)
return;

var target:DisplayObject = DisplayObject(LoaderInfo(event.target).loader);
initBackgroundImage(target);
dispatchEvent(event.clone());
}

private function removedHandler(event : Event) : void
{
var childrenList:IChildList = parent is Container ?
Container(parent).rawChildren :
IChildList(parent);

if (backgroundImage)
{
childrenList.removeChild(backgroundImage);
backgroundImage = null;
}

if (backgroundMask)
{
childrenList.removeChild(backgroundMask);
backgroundMask = null;
}
}

private var backgroundImageStyle:Object

private var backgroundImageWidth:Number;

private var backgroundImageHeight:Number;

private var backgroundImage:DisplayObject;

private var _backgroundImageRect:Rectangle;

private var backgroundMask:Shape;

}

}
Show details Hide details

Change log

r26 by maxym.hryniv on Jan 05, 2008   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r15 by tearaway.tea on Nov 07, 2007   Diff
+ ApplicationManager
+ PatternRectangularBorder
All revisions of this file

File info

Size: 5909 bytes, 222 lines
Hosted by Google Code