home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.graphics
- {
- import com.livebrush.events.UpdateEvent;
- import com.livebrush.graphics.canvas.BitmapLayer;
- import com.livebrush.graphics.canvas.Canvas;
- import com.livebrush.graphics.canvas.CanvasManager;
- import com.livebrush.graphics.canvas.Layer;
- import com.livebrush.graphics.canvas.LineLayer;
- import com.livebrush.ui.UI;
- import com.livebrush.utils.Model;
- import com.livebrush.utils.Update;
- import com.livebrush.utils.View;
- import flash.display.Bitmap;
- import flash.utils.getTimer;
-
- public class CanvasView extends View
- {
- public var canvas:Canvas;
-
- public function CanvasView(canvasManager:Model)
- {
- super(canvasManager);
- this.init();
- }
-
- override public function die() : void
- {
- controller.die();
- }
-
- override protected function createView() : void
- {
- this.canvas = new Canvas(this.canvasManager);
- }
-
- public function get layers() : Array
- {
- return this.canvasManager.layers;
- }
-
- public function get aboveLayerComp() : Bitmap
- {
- return this.canvas.aboveLayerComp;
- }
-
- public function toggleMasterComp(b:Boolean) : void
- {
- this.canvas.masterComp.visible = b;
- }
-
- override protected function registerController() : void
- {
- }
-
- private function updateCanvasDisplay() : void
- {
- var d:int = 0;
- var layer:Layer = null;
- var s:int = getTimer();
- var layersChanged:Boolean = false;
- this.canvas.clearBitmap(this.masterComp);
- this.canvas.clearBitmap(this.belowLayerComp);
- this.canvas.clearBitmap(this.aboveLayerComp);
- this.canvas.clearBitmap(this.sampleLayerComp);
- for(d = 0; d < this.layers.length; d++)
- {
- layer = this.getLayer(d);
- try
- {
- if(layer is LineLayer)
- {
- if(layer.enabled)
- {
- if(Layer.isLineLayer(layer))
- {
- this.cacheLayer(layer as LineLayer);
- }
- else
- {
- this.cacheLayer(layer as BitmapLayer);
- }
- layersChanged = true;
- }
- }
- layer.visible = true;
- }
- catch(e:Error)
- {
- }
- if(layer.enabled)
- {
- layer.drawTo(this.masterComp);
- }
- if(d < this.canvasManager.bottomActiveLayerDepth)
- {
- if(layer.enabled)
- {
- layer.drawTo(this.belowLayerComp);
- }
- if(layer.enabled)
- {
- layer.drawTo(this.sampleLayerComp);
- }
- layer.visible = false;
- }
- else if(d >= this.canvasManager.bottomActiveLayerDepth && d <= this.canvasManager.topActiveLayerDepth)
- {
- if(layer.enabled)
- {
- layer.drawTo(this.sampleLayerComp);
- }
- layer.visible = true;
- }
- else if(d > this.canvasManager.topActiveLayerDepth)
- {
- if(layer.enabled)
- {
- layer.drawTo(this.aboveLayerComp);
- }
- layer.visible = false;
- }
- }
- this.belowLayerComp.visible = true;
- this.aboveLayerComp.visible = true;
- this.toggleMasterComp(true);
- UI.setStatus("Ready");
- }
-
- override public function update(update:Update = null) : void
- {
- if(update.type == UpdateEvent.CANVAS)
- {
- this.updateCanvasDisplay();
- }
- }
-
- public function showAllLayers() : void
- {
- var layer:Layer = null;
- this.toggleMasterComp(false);
- this.belowLayerComp.visible = this.aboveLayerComp.visible = false;
- for(var d:int = 0; d < this.layers.length; d++)
- {
- this.getLayer(d).visible = true;
- }
- }
-
- public function get belowLayerComp() : Bitmap
- {
- return this.canvas.belowLayerComp;
- }
-
- public function get masterComp() : Bitmap
- {
- return this.canvas.masterComp;
- }
-
- public function resize() : void
- {
- this.canvas.x = 0.7 + this.canvas.offset.x;
- this.canvas.y = 30.7 + this.canvas.offset.y;
- }
-
- public function get canvasManager() : CanvasManager
- {
- return CanvasManager(model);
- }
-
- public function get sampleLayerComp() : Bitmap
- {
- return this.canvas.sampleLayerComp;
- }
-
- override protected function init() : void
- {
- this.createView();
- }
-
- private function getLayer(depth:int) : Layer
- {
- var layer:Layer = null;
- for(var i:int = 0; i < this.layers.length; i++)
- {
- if(this.layers[i].depth == depth)
- {
- layer = this.layers[i];
- }
- }
- return layer;
- }
-
- public function setup() : void
- {
- this.createController();
- this.registerController();
- }
-
- private function cacheLayer(layer:Layer) : void
- {
- if(layer.loaded)
- {
- if(!layer.cached)
- {
- layer.updateDisplay();
- }
- }
- }
-
- override protected function createController() : void
- {
- controller = new CanvasController(this);
- }
- }
- }
-
-