root/as3/gunyarapaint/branches/gunyarapaint/framework/src/org/libspark/gunyarapaint/framework/commands/LineToCommand.as

リビジョン 3688, 2.6 kB (コミッタ: hkrn, コミット時期: 3 年 前)

forgot apply to LineToCommand#toString?

Line 
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 LineToCommand extends LineCommand implements ICommand
12     {
13         public static const ID:uint = 2;
14        
15         public function LineToCommand()
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 > 0) {
25                 if (m_compressedValue & 0x40) {
26                     bytes.position -= 1;
27                     var short:uint = bytes.readShort();
28                     x = (short << 18) >> 25;
29                     y = (short << 25) >> 25;
30                 }
31                 else {
32                     x = (m_compressedValue << 26) >> 29;
33                     y = (m_compressedValue << 29) >> 29;
34                 }
35                 m_compressedValue = 0;
36             }
37             else {
38                 x = bytes.readShort();
39                 y = bytes.readShort();
40             }
41             s_readCoordinateX += x;
42             s_readCoordinateY += y;
43         }
44        
45         public function write(bytes:ByteArray, args:Object):void
46         {
47             var dx:int = args.x - s_writeCoordinateX;
48             var dy:int = args.y - s_writeCoordinateY;
49             if (dx >= -4 && dx <= 3 && dy >= -4 && dy <= 3) {
50                 // dxもdyも3bitに収まる場合
51                 bytes.writeByte(0x80 | (dx << 3) & 0x38 | dy & 0x7);
52             }
53             else if (dx >= -64 && dx <= 63 && dy >= -64 && dy <= 63) {
54                 // dxもdyも7bitに収まる場合
55                 bytes.writeShort(0xc000 | (dx << 7) & 0x3f80 | dy & 0x7f);
56             }
57             else {
58                 bytes.writeByte(commandID);
59                 bytes.writeShort(dx);
60                 bytes.writeShort(dy);
61             }
62             s_writeCoordinateX = args.x;
63             s_writeCoordinateY = args.y;
64         }
65        
66         public function execute(painter:Painter):void
67         {
68             painter.lineTo(
69                 s_readCoordinateX || s_writeCoordinateX,
70                 s_readCoordinateY || s_writeCoordinateY
71             );
72         }
73        
74         public function toString():String
75         {
76             return "[LineToCommand"
77                 + " x=" + (s_readCoordinateX || s_writeCoordinateX)
78                 + ", y=" + (s_readCoordinateY || s_writeCoordinateY)
79                 + "]";
80         }
81        
82         public function get commandID():uint
83         {
84             return ID;
85         }
86     }
87 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。