| 1 |
package org.libspark.gunyarapaint.controls |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.display.Sprite; |
|---|
| 4 |
import flash.events.MouseEvent; |
|---|
| 5 |
import flash.geom.Rectangle; |
|---|
| 6 |
|
|---|
| 7 |
import mx.core.UIComponent; |
|---|
| 8 |
|
|---|
| 9 |
import org.libspark.gunyarapaint.controls.IDelegate; |
|---|
| 10 |
import org.libspark.gunyarapaint.framework.AuxBitmap; |
|---|
| 11 |
import org.libspark.gunyarapaint.framework.TransparentBitmap; |
|---|
| 12 |
|
|---|
| 13 |
internal class GPCanvas extends UIComponent |
|---|
| 14 |
{ |
|---|
| 15 |
private var m_aux:AuxBitmap; |
|---|
| 16 |
private var m_delegate:IDelegate; |
|---|
| 17 |
|
|---|
| 18 |
public function GPCanvas(delegate:IDelegate) |
|---|
| 19 |
{ |
|---|
| 20 |
var rect:Rectangle = new Rectangle(0, 0, delegate.recorder.width, delegate.recorder.height); |
|---|
| 21 |
var transparent:TransparentBitmap = new TransparentBitmap(rect); |
|---|
| 22 |
m_aux = new AuxBitmap(rect); |
|---|
| 23 |
m_delegate = delegate; |
|---|
| 24 |
|
|---|
| 25 |
addChild(transparent); |
|---|
| 26 |
addChild(delegate.recorder.painter.view); |
|---|
| 27 |
addChild(m_aux); |
|---|
| 28 |
|
|---|
| 29 |
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); |
|---|
| 30 |
addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); |
|---|
| 31 |
addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); |
|---|
| 32 |
|
|---|
| 33 |
super(); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
public function get auxBitmap():AuxBitmap |
|---|
| 37 |
{ |
|---|
| 38 |
return m_aux; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
private function mouseDownHandler(evt:MouseEvent):void |
|---|
| 42 |
{ |
|---|
| 43 |
m_delegate.module.start(evt.localX, evt.localY); |
|---|
| 44 |
m_delegate.recorder.painter.view.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
private function mouseMoveHandler(evt:MouseEvent):void |
|---|
| 48 |
{ |
|---|
| 49 |
m_delegate.module.move(evt.localX, evt.localY); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
private function mouseUpHandler(evt:MouseEvent):void |
|---|
| 53 |
{ |
|---|
| 54 |
m_delegate.recorder.painter.view.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); |
|---|
| 55 |
m_delegate.module.stop(evt.localX, evt.localY); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
private function mouseOutHandler(evt:MouseEvent):void |
|---|
| 59 |
{ |
|---|
| 60 |
m_delegate.module.interrupt(evt.localX, evt.localY); |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|