チェンジセット 1117

差分発生行の前後
無視リスト:
コミット日時:
2008/08/27 18:17:57 (5 年前)
コミッタ:
tasuku
ログメッセージ:

r68@poppop (orig r67): tasuku | 2008-06-02 02:55:06 +0900

  • new dotted lineTo/moveTo
  • support old log of version 0.0.1
  • debug PNG checker
ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/gunyarapaint/trunk/gunyarapaint/src/gplogplayer.mxml

    r1115 r1117  
    1818  import gunyarapaint.entities.GPLogger; 
    1919  import gunyarapaint.controls.GPCanvas; 
     20  import gunyarapaint.utils.MiscUtils; 
    2021 
     22  import mx.controls.Alert; 
    2123  import mx.events.FlexEvent; 
    2224  import mx.events.SliderEvent; 
     
    2931  private var postUrl:String; 
    3032 
     33  /*** debug ***/ 
     34  private var debugOekakiId:uint = 0; // 0でデバッグしない 
     35  private var commDebug:Com; 
     36  private var debugCheckPngUrl:String; 
     37  private var debugCheckPng:ByteArray; 
     38  /*** debug end ***/ 
     39 
    3140  public function init():void { 
    3241    this.enabled = false; 
    3342     
    3443    // for debug 
    35     // parameters['oelogUrl'] = 'http://dic.nicovideo.jp/oelog/3647'; 
     44    if (debugOekakiId != 0) { 
     45      parameters['oelogUrl'] = 'http://dic.nicovideo.jp/oelog/' + debugOekakiId; 
     46      debugCheckPngUrl = 'http://dic.nicovideo.jp/oekaki/' + debugOekakiId + '.png'; 
     47      commDebug = new Com(); 
     48      commDebug.sendGetUrlRequest(debugCheckPngUrl); 
     49      commDebug.addEventListener('completeGetData', function(evt:Event):void { debugCheckPng = commDebug.getData();}); 
     50    } 
    3651     
    3752    if (parameters['oelogUrl']) { 
     
    105120   
    106121  private function refButtonHandler(evt:Event):void { 
    107     Com.redirectOekakiForm(postUrl, oekakiId); 
     122    if (debugCheckPng) { 
     123      checkImage(); 
     124    } else if (postUrl) { 
     125      Com.redirectOekakiForm(postUrl, oekakiId); 
     126    } else { 
     127      Alert.show('続きが描けません!'); 
     128    } 
    108129  } 
    109130   
     
    111132    playButton.enabled = false; 
    112133    createLogCan(); 
    113     // FIXME:!!!!!!!! 
    114     // logcan.addEventListener('completePlayLog', completePlayLogHandler); 
     134    logcan.addEventListener('completePlayLog', completePlayLogHandler); 
    115135    logger.play(logcan, playSpeedHSlider.value); 
    116136  } 
    117    
     137     
    118138  private function completePlayLogHandler(evt:Event):void { 
    119139    playButton.enabled = true;     
    120   }     
     140  } 
     141   
     142  private function checkImage():void { 
     143    if (MiscUtils.compareObject( 
     144          logcan.getPNGImage(), debugCheckPng)) { 
     145      Alert.show('合ってる。'); 
     146    } else { 
     147      Alert.show('違うよ!'); 
     148    } 
     149  } 
    121150  ]]> 
    122151  </mx:Script> 
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint.as

    r1115 r1117  
    1 private const DEBUG:Boolean = true; 
     1private const DEBUG:Boolean = false; 
    22 
    33import flash.events.Event; 
     
    77import gunyarapaint.controls.GPCanvas; 
    88import gunyarapaint.entities.GPLogger; 
     9import gunyarapaint.utils.MiscUtils; 
    910 
    1011import mx.controls.Alert; 
     
    9596  if (DEBUG) { 
    9697    logPlayButton.addEventListener(FlexEvent.BUTTON_DOWN, playLogHandler); 
     98    checkPngButton.addEventListener(FlexEvent.BUTTON_DOWN, checkPngHandler); 
     99    logPlayButton.visible = true; 
     100    checkPngButton.visible = true; 
    97101  } 
    98102   
     
    239243} 
    240244 
     245private var logger:GPLogger; 
     246private var logcan:GPCanvas; 
     247 
    241248private function playLogHandler(evt:FlexEvent):void { 
    242   var logger:GPLogger = gpCanvas.logger; 
    243   var logcan:GPCanvas = logger.createViewerCanvas(null); 
     249  logger = gpCanvas.logger; 
     250  logcan = logger.createViewerCanvas(null); 
    244251  this.addChild(logcan); 
    245   logger.play(logcan, 100); 
    246 
     252  logger.play(logcan, 1000); 
     253
     254 
     255private function checkPngHandler(evt:FlexEvent):void { 
     256  if (MiscUtils.compareObject( 
     257        logcan.getPNGImage(), gpCanvas.getPNGImage())) { 
     258    Alert.show('合ってる。'); 
     259  } else { 
     260    Alert.show('違うよ!'); 
     261  } 
     262
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint.mxml

    r1115 r1117  
    3030    <mx:Button id="undoButton" x="469" y="36" label="アンドゥ" enabled="false" paddingLeft="3" paddingRight="3"/> 
    3131    <mx:Button id="redoButton" x="555" y="36" label="リドゥ" enabled="false" paddingLeft="3" paddingRight="3"/> 
    32     <mx:Button id="logPlayButton" x="610" y="36" label="ログプレイ"/> 
    3332  </mx:Canvas> 
    3433  <gpcontrol:PenDetailWindowControl id="penDetailWindow" x="10" y="101" layout="absolute" title="ペン"> 
     
    3635  <gpcontrol:GPCanvasWindowControl id="gpCanvasWindow" x="146" y="101" width="379" height="382" layout="absolute" title="キャンバス"> 
    3736  </gpcontrol:GPCanvasWindowControl> 
     37  <mx:Button id="logPlayButton" x="601" y="101" label="ログプレイ" visible="false"/> 
     38  <mx:Button id="checkPngButton" x="601" y="131" label="同一check" visible="false"/> 
    3839</mx:Application> 
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPCanvas.as

    r1115 r1117  
    224224        private var currentPoint:Point = new Point; 
    225225         
    226         public function moveTo(x:Number, y:Number):void { 
     226        // 0.0.1の互換性のため 
     227    public function oldMoveTo(x:Number, y:Number):void { 
    227228      lineShape.graphics.moveTo(x, y); 
    228229      setLineStyle(); 
     
    231232      isMoveTo = true; 
    232233      currentPoint.x = x; 
    233       currentPoint.y = y; 
    234         } 
    235         public function lineTo(x:Number, y:Number):void { 
    236           if (x == currentPoint.x && 
    237               y == currentPoint.y) { 
    238             return; 
    239           } 
     234      currentPoint.y = y;       
     235    } 
     236 
     237        public function moveTo(x:Number, y:Number):void { 
     238          x = Math.floor(x) + 0.5; 
     239      y = Math.floor(y) + 0.5; 
     240      oldMoveTo(x, y); 
     241        } 
     242 
     243    // 0.0.1の互換性のため 
     244    public function oldLineTo(x:Number, y:Number):void { 
    240245      lineShape.graphics.lineTo(x, y); 
    241246      logWrite(['lineTo', x, y]); 
    242247      isDrawnLine = true; 
    243248      currentPoint.x = x; 
    244       currentPoint.y = y; 
     249      currentPoint.y = y;       
     250    } 
     251         
     252        public function lineTo(x:Number, y:Number):void { 
     253      x = Math.floor(x) + 0.5; 
     254      y = Math.floor(y) + 0.5; 
     255          if (x == currentPoint.x && 
     256              y == currentPoint.y) { 
     257            return; 
     258          } 
     259          oldLineTo(x, y); 
    245260        } 
    246261         
    247262    public function drawRect(x:Number, y:Number, width:uint, height:uint):void { 
     263      x = Math.floor(x) + 0.5; 
     264      y = Math.floor(y) + 0.5; 
    248265      setLineStyle(); 
    249266      lineShape.graphics.drawRect(x, y, width, height); 
     
    256273    } 
    257274     
    258     public function drawCircle(x:Number, y:Number, radius:Number):void { 
     275    public function drawCircle(radius:Number):void { 
     276      var x:Number = currentPoint.x; 
     277      var y:Number = currentPoint.y; 
    259278      setLineStyle(); 
    260279      lineShape.graphics.drawCircle(x, y, radius); 
    261       logWrite(['drawCircle', x, y, radius]); 
     280      // moveToでx, yは保存されているので、半径のみ保存 
     281      logWrite(['drawCircle', radius]); 
    262282    } 
    263283     
     
    376396          return _log.getCompressedLog(); 
    377397        } 
     398        public function completePlayLog():void { 
     399      this.dispatchEvent(new Event('completePlayLog')); 
     400        } 
    378401  } 
    379402} 
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPCanvasWindowControl.as

    r1115 r1117  
    2121    public function GPCanvasWindowControl() { 
    2222      super(); 
     23      this.setStyle('backgroundColor', 0x000000); 
    2324      // this.setStyle('backgroundAlpha', 0); 
    2425 
     
    4950    } 
    5051     
     52    public function moveCanvas():void { 
     53      var deg:Number = _canvas.rotation; 
     54      var rad:Number = deg * Math.PI / 180; 
     55      var scale:Number = _container.scaleX; 
     56       
     57      // TODO: dasai 
     58      if (deg >= 0) { 
     59        if (deg <= 90) { 
     60          _container.x = (Math.sin(rad) * _canvas.canvasHeight * scale); 
     61          _container.y = 0; 
     62        } else { 
     63          _container.x = _canvas.canvasHeight * scale * Math.sin(rad) - Math.cos(rad) * _canvas.canvasWidth * scale; 
     64          _container.y = - Math.cos(rad) * _canvas.canvasHeight * scale; 
     65        } 
     66      } else { 
     67        if (deg >= -90) { 
     68          _container.x = 0; 
     69          _container.y = - Math.sin(rad) * _canvas.canvasWidth * scale; 
     70        } else { 
     71          _container.x = - Math.cos(rad) * _canvas.canvasWidth * scale; 
     72          _container.y = - Math.sin(rad) * _canvas.canvasWidth * scale - Math.cos(rad) * _canvas.canvasHeight * scale; 
     73        } 
     74      } 
     75    } 
     76     
    5177    public function zoomCanvas(m:Number):void { 
    5278      //_canvas.scaleX = m; 
     
    6086      _container.scaleX = m; 
    6187      _container.scaleY = m; 
     88      moveCanvas(); 
    6289      /* 
    6390      this.validateNow(); 
     
    79106    public function rotateCanvas(deg:int):void { 
    80107      _canvas.rotation = deg;       
    81       var rad:Number = deg * Math.PI / 180; 
    82       // TODO: dasai 
    83       if (deg >= 0) { 
    84         if (deg <= 90) { 
    85           _container.x = Math.sin(rad) * _canvas.canvasHeight * _container.scaleX; 
    86           _container.y = 0; 
    87         } else { 
    88           _container.x = _canvas.canvasHeight * Math.sin(rad) - Math.cos(rad) * _canvas.canvasWidth * _container.scaleX; 
    89           _container.y = - Math.cos(rad) * _canvas.canvasHeight * _container.scaleY; 
    90         } 
    91       } else { 
    92         if (deg >= -90) { 
    93           _container.x = 0; 
    94           _container.y = - Math.sin(rad) * _canvas.canvasWidth * _container.scaleY; 
    95         } else { 
    96           _container.x = - Math.cos(rad) * _canvas.canvasWidth * _container.scaleX; 
    97           _container.y = - Math.sin(rad) * _canvas.canvasWidth - Math.cos(rad) * _canvas.canvasHeight * _container.scaleY; 
    98         } 
    99       } 
    100     }     
    101   } 
     108      moveCanvas(); 
     109    } 
     110 } 
    102111} 
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPLogger.as

    r1115 r1117  
    167167          break; 
    168168        default: 
    169           Alert('対応していないラインスタイルがログされました!'); 
     169          Alert.show('対応していないラインスタイルがログされました!'); 
    170170          break; 
    171171        } 
     
    189189        break; 
    190190      case 'drawCircle': 
     191        // 直前のmoveToの座標を中心。よって、半径のみ保存 
    191192        writeByte(ACTION_DRAW_CIRCLE); 
     193        writeDouble(info[1]); 
    192194        break; 
    193195 
    194196      default: 
    195         Alert('対応していないアクションがログされました!'); 
     197        Alert.show('対応していないアクションがログされました!'); 
    196198        return; 
    197199      } 
     
    273275          switch (action) { 
    274276          case GPLogger.ACTION_MOVETO: 
    275             _playCanvas.moveTo(a[1], a[2]); 
     277            if (compatibility_0_0_1) { 
     278              _playCanvas.oldMoveTo(a[1], a[2]);               
     279            } else { 
     280              _playCanvas.moveTo(a[1] + 0.5, a[2] + 0.5); 
     281            } 
    276282            break; 
    277283          case GPLogger.ACTION_LINETO: 
    278             _playCanvas.lineTo(a[1], a[2]); 
    279             break; 
    280           case GPLogger.ACTION_DRAW_RECT: 
    281                 _playCanvas.drawRect(a[1], a[2], a[3], a[4]); 
    282                 break; 
     284            if (compatibility_0_0_1) { 
     285              _playCanvas.oldLineTo(a[1], a[2]); 
     286            } else { 
     287              _playCanvas.lineTo(a[1] + 0.5, a[2] + 0.5); 
     288            } 
     289            break; 
    283290          case GPLogger.ACTION_LINESTYLE: 
    284291            switch (a[1]) { 
     
    311318              break; 
    312319            default: 
    313               Alert('未対応のラインスタイルです。'); 
     320              Alert.show('未対応のラインスタイルです。'); 
    314321              break; 
    315322            } 
     
    328335            isBreak = true; 
    329336            break; 
     337          case GPLogger.ACTION_BEGIN_FILL: 
     338            _playCanvas.beginFill(a[1], a[2]); 
     339            break; 
     340          case GPLogger.ACTION_END_FILL: 
     341            _playCanvas.endFill(); 
     342            break; 
     343          case GPLogger.ACTION_DRAW_CIRCLE: 
     344            _playCanvas.drawCircle(a[1]); 
     345            break; 
    330346          default: 
    331             Alert('未対応のアクションです。'); 
     347            Alert.show('未対応のアクションです。'); 
    332348            break; 
    333349          } 
     
    339355        } else { 
    340356          flash.utils.clearInterval(playLogIntervalId); 
    341           // this.dispatchEvent(new Event('completePlayLog')); 
     357          _playCanvas.completePlayLog(); 
    342358          break; 
    343359        } 
     
    350366      var short:uint; 
    351367      var obj:Object; 
     368      var obj2:Object; 
     369      var obj3:Object; 
    352370       
    353371      try { 
     
    388406            obj = readBoolean(); 
    389407            break; 
     408          default: 
     409            Alert.show('未対応のラインスタイルです。'); 
     410            break; 
    390411          } 
    391412          return [ACTION_LINESTYLE, dx, obj]; 
     
    396417        case ACTION_REDO: 
    397418          return [ACTION_REDO]; 
     419        case ACTION_BEGIN_FILL: 
     420          obj = readUInt(); 
     421          obj2 = readDouble(); 
     422          return [ACTION_BEGIN_FILL, obj, obj2]; 
     423        case ACTION_END_FILL: 
     424          return [ACTION_END_FILL]; 
     425        case ACTION_DRAW_CIRCLE: 
     426          obj = readDouble(); 
     427          return [ACTION_DRAW_CIRCLE, obj]; 
    398428        default: 
    399429          if (byte & 0x80) { 
     
    422452            return [ACTION_MOVETO, preX, preY]; 
    423453          } else { 
     454            Alert.show('未対応のアクションです。'); 
    424455            // error 
    425456          } 
  • as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPPen.as

    r1115 r1117  
    192192        alpha = 0; 
    193193        _canvas.beginFill(color, tmpAlpha); 
    194         _canvas.drawCircle(evt.localX, evt.localY, thickness / 2); 
     194        _canvas.drawCircle(thickness / 2); 
    195195        _canvas.endFill(); 
    196196        alpha = tmpAlpha;