My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
package com.minarto.display.pixelBender.alphaBlend
{

import com.minarto.display.pixelBender.colorConvert.ConvertColorJob;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;


/**
*
* @author Minarto
*
*/
public class AlphaBlendJobContainer extends AlphaBlendJobContainerBase
{
/**
*
*/
private var __eventBitmapData:BitmapData;
public function get eventBitmapData():BitmapData
{
return __eventBitmapData;
}


/**
*
*/
private var cBlendJob:ConvertColorJob;
private var uniqueColor:uint = 0xFF000000;


/**
*
*
*/
public function AlphaBlendJobContainer()
{
super();

mouseChildren = false;
}


override public function clear():void
{
uniqueColor = 0xFF000000;
__eventBitmapData.dispose();
}


/**
*
* @return
*
*/
public function getObject():DisplayObject
{
var color:uint = __eventBitmapData.getPixel32(mouseX, mouseY);
var item:BitmapItem;
var i:int = - 1;
var length:uint = numChildren;
while(++ i < length)
{
item = bitmapDatas[i];
if(item.uniqueColor == color) break;
}

return (i < length) ? item.sourceObject : null;
}


override public function add($obj:DisplayObject):DisplayObject
{
super.add($obj);

var item:BitmapItem = bitmapDatas[numChildren - 1];

var bd:BitmapData = item.bitmapData.clone();
cBlendJob = new ConvertColorJob(bd, bd.width, bd.height);
cBlendJob.sourceBitmapData = item.bitmapData;
item.uniqueColor = ++ uniqueColor;
cBlendJob.color = uniqueColor;
cBlendJob.start(true);
item.eventBitmapData = bd;

return $obj;
}


override public function addAt($obj:DisplayObject, $index:int):DisplayObject
{
super.addAt($obj, $index);

var item:BitmapItem = bitmapDatas[$index];

var bd:BitmapData = item.bitmapData.clone();
cBlendJob = new ConvertColorJob(bd, bd.width, bd.height);
cBlendJob.sourceBitmapData = item.bitmapData;
item.uniqueColor = ++ uniqueColor;
cBlendJob.color = uniqueColor;
cBlendJob.start(true);
item.eventBitmapData = bd;

return $obj;
}


override public function remove($obj:DisplayObject):DisplayObject
{
var i:int = - 1;
var length:uint = numChildren;
var item:BitmapItem;
while(++ i < length)
{
item = bitmapDatas[i];
if(item.sourceObject == $obj)
{
item.bitmapData.dispose();
item.eventBitmapData.dispose();

bitmapDatas.splice(i, 1);
break;
}
}

return $obj;
}


override public function removeAt($index:uint):DisplayObject
{
var item:BitmapItem = bitmapDatas[$index];
item.bitmapData.dispose();
item.eventBitmapData.dispose();

bitmapDatas.splice($index, 1);

return item.sourceObject;
}


override protected function drawIndex($index:uint):void
{
super.drawIndex($index);

var item:BitmapItem = bitmapDatas[$index];

var bd:BitmapData = item.eventBitmapData;
sourceRect.width = bd.width;
sourceRect.height = bd.height
desPoint.x = item.x;
desPoint.y = item.y;

var sBitmapData:BitmapData = new BitmapData(width, height, true, 0x00000000);
sBitmapData.copyPixels(bd, sourceRect, desPoint);

aBlendJob = new AlphaBlendJob(__eventBitmapData, width, height);
aBlendJob.bottomBitmapData = __eventBitmapData;
aBlendJob.topBitmapData = sBitmapData;
aBlendJob.start(true);
}


override protected function hnResize($e:Event):void
{
super.hnResize($e);
uniqueColor = 0xFF000000;
__eventBitmapData = new BitmapData(width, height, false, 0x00000000);
}
}
}

Change log

r41 by minarto76 on Feb 17, 2011   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r40 by minarto76 on Feb 16, 2011   Diff
[No log message]
r39 by minarto76 on Feb 16, 2011   Diff
[No log message]
r38 by minarto76 on Feb 16, 2011   Diff
[No log message]
All revisions of this file

File info

Size: 3964 bytes, 177 lines
Powered by Google Project Hosting