| 1 |
package org.libspark.gunyarapaint.ui.v1 |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.display.Sprite; |
|---|
| 4 |
import flash.events.Event; |
|---|
| 5 |
import flash.events.MouseEvent; |
|---|
| 6 |
import flash.geom.Rectangle; |
|---|
| 7 |
|
|---|
| 8 |
import mx.controls.Alert; |
|---|
| 9 |
import mx.core.Application; |
|---|
| 10 |
import mx.core.UIComponent; |
|---|
| 11 |
|
|---|
| 12 |
import org.libspark.gunyarapaint.framework.AuxLineView; |
|---|
| 13 |
import org.libspark.gunyarapaint.framework.AuxPixelView; |
|---|
| 14 |
import org.libspark.gunyarapaint.framework.TransparentBitmap; |
|---|
| 15 |
import org.libspark.gunyarapaint.framework.ui.IApplication; |
|---|
| 16 |
|
|---|
| 17 |
internal class Canvas extends UIComponent |
|---|
| 18 |
{ |
|---|
| 19 |
public function Canvas() |
|---|
| 20 |
{ |
|---|
| 21 |
var app:IApplication = IApplication(Application.application); |
|---|
| 22 |
var rect:Rectangle = new Rectangle(0, 0, app.canvasWidth, app.canvasHeight); |
|---|
| 23 |
var transparent:TransparentBitmap = new TransparentBitmap(rect); |
|---|
| 24 |
m_auxLine = new AuxLineView(rect); |
|---|
| 25 |
m_auxPixel = new AuxPixelView(rect); |
|---|
| 26 |
m_auxLine.visible = true; |
|---|
| 27 |
m_auxPixel.visible = false; |
|---|
| 28 |
|
|---|
| 29 |
addChild(transparent); |
|---|
| 30 |
addChild(app.canvasView); |
|---|
| 31 |
addChild(m_auxLine); |
|---|
| 32 |
addChild(m_auxPixel); |
|---|
| 33 |
addEventListener(Event.REMOVED_FROM_STAGE, onRemove); |
|---|
| 34 |
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); |
|---|
| 35 |
|
|---|
| 36 |
super(); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
public function updateAuxViews():void |
|---|
| 40 |
{ |
|---|
| 41 |
m_auxLine.update(); |
|---|
| 42 |
m_auxPixel.update(); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
public function set auxBoxVisible(value:Boolean):void |
|---|
| 46 |
{ |
|---|
| 47 |
m_auxLine.boxVisible = m_auxPixel.boxVisible = value; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
public function set auxSkewVisible(value:Boolean):void |
|---|
| 51 |
{ |
|---|
| 52 |
m_auxLine.skewVisible = m_auxPixel.skewVisible = value; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
public function set auxDivideCount(value:uint):void |
|---|
| 56 |
{ |
|---|
| 57 |
m_auxLine.divideCount = m_auxPixel.divideCount = value; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public function set auxLineAlpha(value:Number):void |
|---|
| 61 |
{ |
|---|
| 62 |
m_auxLine.lineAlpha = m_auxPixel.lineAlpha = value; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
public function set auxLineColor(value:uint):void |
|---|
| 66 |
{ |
|---|
| 67 |
m_auxLine.lineColor = m_auxPixel.lineColor = value; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
public function set enableAuxPixel(value:Boolean):void |
|---|
| 71 |
{ |
|---|
| 72 |
m_auxLine.visible = value ? false : true; |
|---|
| 73 |
m_auxPixel.visible = value ? true : false; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
private function onRemove(event:Event):void |
|---|
| 77 |
{ |
|---|
| 78 |
var app:IApplication = IApplication(Application.application); |
|---|
| 79 |
removeMouseEvents(app.canvasView); |
|---|
| 80 |
removeEventListener(Event.REMOVED_FROM_STAGE, onRemove); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
private function onMouseDown(event:MouseEvent):void |
|---|
| 84 |
{ |
|---|
| 85 |
var app:gunyarapaint = gunyarapaint(Application.application); |
|---|
| 86 |
var cv:Sprite = app.canvasView; |
|---|
| 87 |
try { |
|---|
| 88 |
app.module.start(event.localX, event.localY); |
|---|
| 89 |
cv.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); |
|---|
| 90 |
cv.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); |
|---|
| 91 |
cv.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); |
|---|
| 92 |
} catch (e:Error) { |
|---|
| 93 |
removeMouseEvents(cv); |
|---|
| 94 |
Alert.show(e.message, app.moduleName); |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
private function onMouseMove(event:MouseEvent):void |
|---|
| 99 |
{ |
|---|
| 100 |
var app:IApplication = IApplication(Application.application); |
|---|
| 101 |
app.module.move(event.localX, event.localY); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
private function onMouseUp(event:MouseEvent):void |
|---|
| 105 |
{ |
|---|
| 106 |
var app:IApplication = IApplication(Application.application); |
|---|
| 107 |
removeMouseEvents(app.canvasView); |
|---|
| 108 |
app.module.stop(event.localX, event.localY); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
private function onMouseOut(event:MouseEvent):void |
|---|
| 112 |
{ |
|---|
| 113 |
var app:IApplication = IApplication(Application.application); |
|---|
| 114 |
removeMouseEvents(app.canvasView); |
|---|
| 115 |
app.module.interrupt(event.localX, event.localY); |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
private function removeMouseEvents(cv:Sprite):void |
|---|
| 119 |
{ |
|---|
| 120 |
cv.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); |
|---|
| 121 |
cv.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); |
|---|
| 122 |
cv.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
private var m_auxLine:AuxLineView; |
|---|
| 126 |
private var m_auxPixel:AuxPixelView; |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|