| 1 |
package org.libspark.gunyarapaint.framework.commands |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.utils.ByteArray; |
|---|
| 4 |
|
|---|
| 5 |
import org.libspark.gunyarapaint.framework.Painter; |
|---|
| 6 |
|
|---|
| 7 |
/** |
|---|
| 8 |
* @private |
|---|
| 9 |
* |
|---|
| 10 |
*/ |
|---|
| 11 |
public final class MoveToCommand extends LineCommand implements ICommand |
|---|
| 12 |
{ |
|---|
| 13 |
public static const ID:uint = 1; |
|---|
| 14 |
|
|---|
| 15 |
public function MoveToCommand() |
|---|
| 16 |
{ |
|---|
| 17 |
super(); |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
public function read(bytes:ByteArray):void |
|---|
| 21 |
{ |
|---|
| 22 |
var x:int = 0; |
|---|
| 23 |
var y:int = 0; |
|---|
| 24 |
if (m_compressedValue) { |
|---|
| 25 |
bytes.position -= 1; |
|---|
| 26 |
var short:uint = bytes.readShort(); |
|---|
| 27 |
x = (short << 18) >> 25; |
|---|
| 28 |
y = (short << 25) >> 25; |
|---|
| 29 |
m_compressedValue = 0; |
|---|
| 30 |
} |
|---|
| 31 |
else { |
|---|
| 32 |
x = bytes.readShort(); |
|---|
| 33 |
y = bytes.readShort(); |
|---|
| 34 |
} |
|---|
| 35 |
s_readCoordinateX += x; |
|---|
| 36 |
s_readCoordinateY += y; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
public function write(bytes:ByteArray, args:Object):void |
|---|
| 40 |
{ |
|---|
| 41 |
var dx:int = args.x - s_writeCoordinateX; |
|---|
| 42 |
var dy:int = args.y - s_writeCoordinateY; |
|---|
| 43 |
if (dx >= -64 && dx <= 63 && dy >= -64 && dy <= 63) { |
|---|
| 44 |
// dxもdyも7bitに収まる場合 |
|---|
| 45 |
bytes.writeShort(0x4000 | (dx << 7) & 0x3f80 | dy & 0x7f); |
|---|
| 46 |
} |
|---|
| 47 |
else { |
|---|
| 48 |
bytes.writeByte(commandID); |
|---|
| 49 |
bytes.writeShort(dx); |
|---|
| 50 |
bytes.writeShort(dy); |
|---|
| 51 |
} |
|---|
| 52 |
s_writeCoordinateX = args.x; |
|---|
| 53 |
s_writeCoordinateY = args.y; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
public function execute(painter:Painter):void |
|---|
| 57 |
{ |
|---|
| 58 |
painter.moveTo( |
|---|
| 59 |
s_readCoordinateX || s_writeCoordinateX, |
|---|
| 60 |
s_readCoordinateY || s_writeCoordinateY |
|---|
| 61 |
); |
|---|
| 62 |
painter.startDrawingSession(); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
public function get commandID():uint |
|---|
| 66 |
{ |
|---|
| 67 |
return ID; |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|