-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameBoyAdvanceCanvas.as
73 lines (59 loc) · 1.47 KB
/
GameBoyAdvanceCanvas.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
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.geom.Rectangle;
public class GameBoyAdvanceCanvas extends Bitmap {
//PUBLIC:
public var bm:Bitmap;
public var bmData:BitmapData;
public var canvasX;
public var canvasY;
public var canvasWidth:int;
public var canvasHeight:int;
//PRIVATE
private var rect:Rectangle;
/*
RULE: 4 segments per pixel
0 = Alpha
1 = Red
2 = Green
3 = Blue
*/
private var bitmapBuffer:ByteArray;
public function GameBoyAdvanceCanvas(w,h) {
// constructor code
this.canvasWidth = w;
this.canvasHeight = h;
bmData = new BitmapData(canvasWidth, canvasHeight, true, 0xFFCCCCCC);
rect = new Rectangle(0,0,canvasWidth,canvasHeight);
bitmapBuffer = bmData.getPixels(rect);
this.bitmapData = bmData;
bitmapBuffer.position = 0;
}
public function setPixel(xVal,val){
this.bitmapBuffer[xVal] = val;
}
public function getBufferLength(){
return bitmapBuffer.length;
}
public function setSeg(i,v){
bitmapBuffer[i] = v;
}
public function refresh(){
bitmapBuffer.position = 0;
bmData.setPixels(rect, bitmapBuffer);
this.bitmapData = bmData;
}
public function setPixels(buf:ByteArray){
buf.position = 0;
bmData.lock();
bmData.setPixels(rect, buf);
bmData.unlock();
this.bitmapData = bmData;
}
public function getBuffer():ByteArray{
return bitmapBuffer;
}
}
}