チェンジセット 1171
- コミット日時:
- 2008/08/27 18:21:50 (5 年前)
- ファイル:
-
- as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPCanvas.as (更新) (8 diffs)
- as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPLayerWindowControlScript.as (更新) (3 diffs)
- as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPLayer.as (更新) (2 diffs)
- as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPLayerArray.as (更新) (6 diffs)
- as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPUndoBuffer.as (追加)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPCanvas.as
r1164 r1171 15 15 import gunyarapaint.entities.GPLogger; 16 16 import gunyarapaint.entities.GPPen; 17 import gunyarapaint.entities.GPUndoBuffer; 17 18 18 19 import mx.core.UIComponent; … … 37 38 private var _pen:GPPen = null; 38 39 private var _prePen:GPPen = null; 40 private var _undoBuffer:GPUndoBuffer; 39 41 40 42 private var _canvasWindowControl:GPCanvasWindowControl = null; // キャンバスのウィンドウ。描画時のみ 41 42 43 private var protectCanvas:Boolean = false; // 描画をするかどうか。スクロールバーやlayerのD&Dから保護 44 45 private var _layerWindow:GPLayerWindowControl; // レイヤのコントロール 43 46 44 47 public function GPCanvas(width:uint, height:uint, undoBufferSize:uint, logger:GPLogger, baseData:BitmapData, initPen:GPPen) … … 68 71 canWidth = baseData.width; 69 72 canHeight = baseData.height; 70 _layers = new GPLayerArray([baseData], canWidth, canHeight, undoBufferSize);73 _layers = new GPLayerArray([baseData], 0, canWidth, canHeight); 71 74 } else { 72 75 canWidth = width; 73 76 canHeight = height; 74 _layers = new GPLayerArray(null, canWidth, canHeight, undoBufferSize);77 _layers = new GPLayerArray(null, 0, canWidth, canHeight); 75 78 } 76 79 this.width = canWidth; … … 106 109 // ペン関連の初期化 107 110 pen = initPen; 111 _undoBuffer = new GPUndoBuffer(undoBufferSize, _layers); 108 112 109 113 super(); 110 114 } 111 115 112 public function combineLayers():void { 113 // TODO: remove it! 114 /* 115 var a:Array = _layers.combinedDrawBitmapData; 116 combinedLowerBitmap.bitmapData = a[0]; 117 combinedUpperBitmap.bitmapData = a[1]; 118 */ 116 public function set layerWindow(lw:GPLayerWindowControl):void { 117 _layerWindow = lw; 118 } 119 120 public function replaceLayerArray(a:GPLayerArray):void { 121 var index:int = getChildIndex(_layers.view); 122 removeChildAt(index); 123 addChildAt(a.view, index); 124 _layers = a; 125 _pen.layers = a; 126 _layerWindow.layers = a; 119 127 } 120 128 … … 269 277 if (c) { 270 278 _layers.draw(c, null, null, _pen.blendMode, null, false); 279 _undoBuffer.push(_layers); 271 280 afterDrawBitmap(); 272 281 logWrite(['floodFill', x, y]); … … 344 353 // 描画 345 354 _layers.draw(_pen.drawShape, null, null, _pen.blendMode, null, false); 355 _undoBuffer.push(_layers); 346 356 logWrite(['drawShapeOnBitmap']); 347 357 afterDrawBitmap(); … … 349 359 350 360 public function afterDrawBitmap():void { 351 // レイヤ統合して表示を更新して352 combineLayers();353 361 // 描画用シェイプは空にしておく 354 362 _pen.clearDrawShape(); … … 365 373 } 366 374 public function undo():void { 367 _layers.undo(); 368 combineLayers(); 375 replaceLayerArray(_undoBuffer.undo()); 369 376 this.dispatchEvent(new Event('changeUndoRedo')); 370 377 logWrite(['undo', x, y]); 371 378 } 372 379 public function redo():void { 373 _layers.redo(); 374 combineLayers(); 380 replaceLayerArray(_undoBuffer.redo()); 375 381 this.dispatchEvent(new Event('changeUndoRedo')); 376 382 logWrite(['redo', x, y]); 377 383 } 378 379 384 380 385 public function getUndoCount():uint { 381 // FIXME: 直接聞くようにすべき 382 return _layers.getUndoCount(); 386 return _undoBuffer.getUndoCount(); 383 387 } 384 388 public function getRedoCount():uint { 385 // FIXME: 直接聞くようにすべき 386 return _layers.getRedoCount(); 389 return _undoBuffer.getRedoCount(); 387 390 } 388 391 as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/controls/GPLayerWindowControlScript.as
r1167 r1171 56 56 _canvas = can; 57 57 _layers = can.layers; 58 can.layerWindow = this; 58 59 this.enabled = true; 59 syncWithLayersAlphaBlend Canvas();60 syncWithLayersAlphaBlend(); 60 61 layerDataGrid.selectedIndex = 0; 61 62 /* … … 66 67 } 67 68 69 public function set layers(a:GPLayerArray):void { 70 _layers = a; 71 syncWithLayersAlphaBlend(); 72 } 73 68 74 private function itemFocusHandler(evt:mx.events.DataGridEvent):void { 69 75 _layers.targetIndex = evt.currentTarget.selectedItem.index; 70 syncWithAlphaBlend Canvas();76 syncWithAlphaBlend(); 71 77 } 72 78 73 private function syncWithAlphaBlend Canvas():void {79 private function syncWithAlphaBlend():void { 74 80 syncWithAlpha(); 75 81 syncWithBlend(); 76 syncWithCanvas();77 82 } 78 83 79 private function syncWithLayersAlphaBlend Canvas():void {84 private function syncWithLayersAlphaBlend():void { 80 85 syncWithLayers(); 81 86 syncWithAlpha(); 82 87 syncWithBlend(); 83 syncWithCanvas();84 88 } 85 89 … … 101 105 } 102 106 private function syncWithCanvas():void { 103 _canvas.combineLayers();107 // _layers = _canvas.layers; 104 108 } 105 109 106 110 private function newLayerHandler(evt:Event):void { 107 111 _layers.pushBlank(); 108 syncWithLayersAlphaBlend Canvas();112 syncWithLayersAlphaBlend(); 109 113 } 110 114 111 115 private function copyLayerHandler(evt:Event):void { 112 116 _layers.copy(layerDataGrid.selectedItem.index); 113 syncWithLayersAlphaBlend Canvas();117 syncWithLayersAlphaBlend(); 114 118 } 115 119 116 120 private function deleteLayerHandler(evt:Event):void { 117 121 _layers.remove(layerDataGrid.selectedItem.index); 118 syncWithLayersAlphaBlend Canvas();122 syncWithLayersAlphaBlend(); 119 123 } 120 124 121 125 private function mergeLayerHandler(evt:Event):void { 122 126 _layers.mergeWithBelow(layerDataGrid.selectedItem.index); 123 syncWithLayersAlphaBlend Canvas();127 syncWithLayersAlphaBlend(); 124 128 } 125 129 as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPLayer.as
r1162 r1171 42 42 _lock = lock; 43 43 _mask = mask; 44 _blendMode = blendMode; 45 _alpha = alpha; 44 _colorTransform = new ColorTransform(); 45 _bitmap = new Bitmap(_bitmapData); 46 this.blendMode = blendMode; 47 this.alpha = alpha; 46 48 if (name) { 47 49 _name = name; … … 49 51 _name = 'レイヤ' + _index; 50 52 } 51 _colorTransform = new ColorTransform();52 _bitmap = new Bitmap(_bitmapData);53 53 } 54 54 as3/gunyarapaint/trunk/gunyarapaint/src/gunyarapaint/entities/GPLayerArray.as
r1165 r1171 11 11 12 12 import mx.controls.Alert; 13 13 14 14 // Arrayの継承はしない, IListを実装すればdataProviderに直指定できるけど、めんどい。 15 15 public class GPLayerArray … … 18 18 private var _targetIndex:uint; // 現在描画対象となっているレイヤ番号(1 startがいいかな?) 19 19 private var _width:uint, _height:uint; // キャンバスサイズ 20 21 private var _undoRingBuffer:Array;22 private var _undoIndex:uint;23 private var _undoFirstIndex:uint;24 private var _undoLastIndex:uint;25 private var _undoBufferSize:uint;26 20 27 21 private var _combinedBitmapData:BitmapData; … … 29 23 private var _targetSprite:Sprite; // 描画対象のBitmapと描画用Shapeを子に持つSprite。 30 24 31 public function GPLayerArray(a:Array, w:uint, h:uint, undoBufferSize:uint) {25 public function GPLayerArray(a:Array, targetIndex:uint, w:uint, h:uint) { 32 26 _width = w; 33 27 _height = h; 34 28 _targetIndex = 0; 35 _undoBufferSize = undoBufferSize + 1; // 現状を保持する分を追加36 29 _view = new Sprite(); 37 30 _view.mouseEnabled = false; // マウスイベント取りません! 38 31 if (a) { 39 32 _a = a; 33 _targetIndex = targetIndex; 34 for (var i:uint = 0; i < a.length; i++) { 35 _view.addChild(a[i].bitmap); 36 } 40 37 } else { 41 38 _a = new Array(); … … 43 40 _a[0].name = '背景'; 44 41 } 45 _undoRingBuffer = new Array(_undoBufferSize); 46 initUndoRingBuffer(); 47 recombine(); 48 } 49 50 private function initUndoRingBuffer():void { 51 _undoIndex = 0; 52 _undoFirstIndex = 0; 53 _undoLastIndex = 0; 54 _undoRingBuffer[0] = targetLayer.clone(); 55 } 42 recombine(); 43 } 44 45 public function clone():GPLayerArray { 46 var a:Array = new Array(); 47 for (var i:uint = 0; i < _a.length; i++) { 48 a[i] = _a[i].clone(); 49 } 50 return new GPLayerArray(a, _targetIndex, _width, _height); 51 } 56 52 57 53 public function pushBlank():void { … … 160 156 public function draw(source:IBitmapDrawable, matrix:Matrix = null, colorTransform:ColorTransform = null, blendMode:String = null, clipRect:Rectangle = null, smoothing:Boolean = false):void { 161 157 _a[_targetIndex].draw(source, matrix, colorTransform, blendMode, clipRect, smoothing); 162 addUndo();163 recombine();164 }165 166 public function undo():void {167 if (_undoIndex == _undoFirstIndex) {168 return;169 } else if (_undoIndex == 0) {170 _undoIndex = _undoBufferSize - 1;171 } else {172 _undoIndex--;173 }174 var undoData:GPLayer = _undoRingBuffer[_undoIndex];175 _a[undoData.index] = undoData.clone();176 recombine();177 }178 179 public function redo():void {180 if (_undoIndex == _undoLastIndex) {181 return;182 }183 _undoIndex = (_undoIndex + 1) % _undoBufferSize;184 var undoData:GPLayer = _undoRingBuffer[_undoIndex];185 _a[undoData.index] = undoData.clone();186 158 recombine(); 187 159 } … … 191 163 _a[i].index = i; 192 164 } 193 }194 195 private function addUndo():void {196 // リングバッファに追加して197 _undoIndex = (_undoIndex + 1) % _undoBufferSize;198 _undoRingBuffer[_undoIndex] = targetLayer.clone();199 _undoLastIndex = _undoIndex;200 if (_undoIndex == _undoFirstIndex) {201 // バッファ1周したのでずらす202 _undoFirstIndex = (_undoFirstIndex + 1) % _undoBufferSize;203 }204 }205 206 public function getUndoCount():uint {207 var ret:int = _undoIndex - _undoFirstIndex;208 return ret < 0 ? ret + _undoBufferSize : ret;209 }210 211 public function getRedoCount():uint {212 var ret:int = _undoLastIndex - _undoIndex;213 return ret < 0 ? ret + _undoBufferSize : ret;214 165 } 215 166

