/* File: Gfx.hx Date: 08/09/08 Author: Michael Norton Copyright 2008, all rights reserved Michael Norton, Black Hole Computing Use how you wish FREELY - permission required for commercial use */ import flash.display.BitmapData; import flash.display.Bitmap; import flash.geom.Rectangle; import flash.geom.Point; class Gfx { private var _offscreenBitmap:Bitmap; private var _offscreenBitmapData:BitmapData; private var _viewportBitmap:Bitmap; private var _viewportBitmapData:BitmapData; private var _viewport_height : Int; private var _viewport_width : Int; public function new( width: Int, height : Int ){ // create the offscreen buffer _offscreenBitmapData = new BitmapData(width, height, false, 0xffff00); _offscreenBitmap = new Bitmap(_offscreenBitmapData); // create the viewport buffer Gfx_setup_Viewport( width, height); // make the viewport active in Flash flash.Lib.current.addChild(_viewportBitmap); } // function setup_Viewport // define the dimension height x width in pixels // of the viewport. public function Gfx_setup_Viewport( width:Int, height:Int) { _viewport_height = height; _viewport_width = width; _viewportBitmapData = new BitmapData(width, height, false, 0x000000); _viewportBitmap = new Bitmap(_viewportBitmapData); } // END Gfx_setup_Viewport // function copy_Offscreen_to_Viewport // copy the _offscreenBitmapData to the _viewportBitmapData // ..updates the screen.. public function Gfx_copy_Offscreen_to_Viewport() { var srcRect = new Rectangle(0,0,256,192); var dstPt = new Point(0,0); // copy the offscreen bitmap data to the viewport bitmap data _viewportBitmapData.copyPixels( _offscreenBitmapData, srcRect, dstPt); } // END copy_Offscreen_to_Viewport // function copyPixels_to_Offscreen // public function Gfx_copyPixels_to_Offscreen( bitmapdata:BitmapData, srcRect:Rectangle, dstPt:Point ) { _offscreenBitmapData.copyPixels(bitmapdata, srcRect, dstPt ); } } // END class Gfx