Introduction

You are currently browsing the weblog archives for November, 2003.

Archive for November, 2003

Friday, November 28th, 2003

The Rectangle and Polygon-Class

Got nothing to say to these classes!

The Rectangle-Class:

import drawingAPI.GeometryShape;
import asset.Point;
import asset.Size;

class drawingAPI.Rectangle extends GeometryShape{
        public var type:String = “Rectangle“;

        public function Rectangle(Void){
                addPoint(new Point());
                addPoint(new Point());
                addPoint(new Point());
                addPoint(new Point());
        }
        public function resize(Void):Void{
                draw();
        }
        public function set width(aWidth:Number):Void{
                getPointByNumber(1).x = aWidth;
                getPointByNumber(2).x = aWidth;
        }
        public function get width():Number{
                return getPointByNumber(1).x;
        }
        public function set height(aHeight:Number):Void{
                getPointByNumber(2).y = aHeight;
                getPointByNumber(3).y = aHeight;
        }
        public function get height():Number{
                return getPointByNumber(2).y;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                width = aWidth;
                height = aHeight;
        }
        public function getSize(Void):Object{
                return new Size(width, height);
        }
}

The Polygon-Class:

import drawingAPI.GeometryShape;
import asset.Point;
import asset.Size;

class drawingAPI.Polygon extends GeometryShape{
        public var type:String = “Polygon“;

        public function Polygon(Void){
        }
        public function draw(Void):Void{
                super.draw();
                if(size.width == null) size.width = mc._width;
                if(size.width == null) size.height = mc._height;
                applySize();
        }
        public function resize(Void):Void{
                applySize();
        }
        public function set width(aWidth:Number):Void{
                size.width = aWidth;
        }
        public function get width():Number{
                return size.width;
        }
        public function set height(aHeight:Number):Void{
                size.height = aHeight;
        }
        public function get height():Number{
                return size.height;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                width = aWidth;
                height = aHeight;
        }
        public function getSize(Void):Object{
                return size;
        }

        public function addPoint(aPoint:Point):Number{
                points.push(aPoint);
                return points.length-1;
        }
        public function removePoint(aPoint:Point):Void{
                var i:Number = 0;
                while(i < points.length){
                        if(points[i] == aPoint){
                                points[i].remove();
                                points.splice(i, 1);
                        }
                        i++;
                }
        }
        public function removePointByNumber(aNumber:Number):Void{
                points.splice(aNumber, 1);
        }

        private function applySize(Void):Void{
                mc._width = size.width;
                mc._height = size.height;
        }
}
Friday, November 28th, 2003

The Border, Fill and GradientFill-Class

The documentation will to come soon.

The Border-Class:

import asset.Point;
import drawingAPI.Shape;

class drawingAPI.Border extends Graphic{
        public var type:String = “Border“;

        public var master:Shape;

        private var thickness:Number;
        private var color:Number;
        private var alpha:Number;

        public function Border(aThickness:Number, aColor:Number, anAlphaValue:Number){
                thickness = aThickness;
                color = aColor;
                alpha = anAlphaValue;
        }
        public function draw(Void):Void{
                var i:Number = 1;
                var point:Point;
                mc.lineStyle(thickness, color, alpha);
                point = master.getPointByNumber(0);
                mc.moveTo(point.x, point.y);
                while(i < master.getPointsTotal()){
                        point = master.getPointByNumber(i);
                        mc.lineTo(point.x, point.y);
                        i++;
                }
                point = master.getPointByNumber(0);
                mc.lineTo(point.x, point.y);
        }
        public function clear(Void):Void{
                mc.clear();
        }

        public function setThickness(aThickness:Number):Void{
                thickness = aThickness;
        }
        public function getThickness(Void):Number{
                return thickness;
        }
        public function setColor(aColor:Number):Void{
                color = aColor;
        }
        public function getColor(Void):Number{
                return color;
        }
        public function setAlpha(anAlphaValue:Number):Void{
                alpha = anAlphaValue;
        }
        public function getAlpha(Void):Number{
                return alpha;
        }
}

The Fill-Class:

import asset.Point;
import drawingAPI.Shape;

class drawingAPI.Fill extends Graphic{
        public var type:String = “Fill“;

        public var master:Shape

        private var color:Number;
        private var alpha:Number;
        private var sizeRedundance:Number;

        public function Fill(aColor:Number, anAlphaValue:Number, aSizeRedundance:Number){
                color = aColor;
                alpha = anAlphaValue;
                sizeRedundance = aSizeRedundance;
        }
        public function draw(Void):Void{
                var i:Number = 1;
                var point:Point;
                mc.beginFill(color, alpha);
                point = master.getPointByNumber(0);
                mc.moveTo(point.x, point.y);
                while(i < master.getPointsTotal()){
                        point = master.getPointByNumber(i);
                        mc.lineTo(point.x, point.y);
                        i++;
                }
                point = master.getPointByNumber(0);
                mc.lineTo(point.x, point.y);
                mc.endFill();

                resize();
                x = sizeRedundance/2;
                y = sizeRedundance/2;
                move();
        }
        public function clear(Void):Void{
                mc.clear();
        }

        public function setColor(aColor:Number):Void{
                color = aColor;
        }
        public function getColor(Void):Number{
                return color;
        }
        public function setAlpha(anAlphaValue:Number):Void{
                alpha = anAlphaValue;
        }
        public function getAlpha(Void):Number{
                return alpha;
        }
        public function setSizeRedundance(aSizeRedundance:Number):Void{
                sizeRedundance = aSizeRedundance;
        }
        public function getSizeRedundance(Void):Number{
                return sizeRedundance;
        }

        private function resize(Void):Void{
                mc._width = master.width-sizeRedundance;
                mc._height = master.height-sizeRedundance;
        }
}

The GradientFill-Class:

import asset.Point;
import drawingAPI.Shape;

class drawingAPI.GradientFill extends Graphic{
        public var type:String = “Fill“;

        public var master:Shape

        private var fillType:String;
        private var colors:Array;
        private var alphas:Array;
        private var ratios:Array;
        private var matrix:Object;

        private var sizeRedundance:Number;

        public function GradientFill(aFillType:String, someColors:Array, someAlphaValues:Array, someRatios:Array, aMatrix:Object, aSizeRedundance:Number){
                fillType = aFillType;
                colors = someColors;
                alphas = someAlphaValues;
                ratios = someRatios;
                matrix = aMatrix
                sizeRedundance = aSizeRedundance;
        }
        public function draw(Void):Void{
                var i:Number = 1;
                var point:Point;
                mc.beginGradientFill(fillType, colors, alphas, ratios, matrix);
                point = master.getPointByNumber(0);
                mc.moveTo(point.x, point.y);
                while(i < master.getPointsTotal()){
                        point = master.getPointByNumber(i);
                        mc.lineTo(point.x, point.y);
                        i++;
                }
                point = master.getPointByNumber(0);
                mc.lineTo(point.x, point.y);
                mc.endFill();

                resize();
                x = sizeRedundance/2;
                y = sizeRedundance/2;
                move();
        }
        public function clear(Void):Void{
                mc.clear();
        }

        public function setFillType(aFillType:String):Void{
                fillType = aFillType;
        }
        public function getFillType(Void):String{
                return fillType;
        }
        public function setColors(someColors:Array):Void{
                colors = someColors;
        }
        public function getColors(Void):Array{
                return colors;
        }
        public function setAlphas(someAlphaValues:Array):Void{
                alphas = someAlphaValues;
        }
        public function getAlphas(Void):Array{
                return alphas;
        }
        public function setRatios(someRatios:Array):Void{
                ratios = someRatios;
        }
        public function getRatios(Void):Array{
                return ratios;
        }
        public function setMatrix(aMatrix:Object):Void{
                matrix = aMatrix;
        }
        public function getMatrix(Void):Object{
                return matrix;
        }
        public function setSizeRedundance(aSizeRedundance:Number):Void{
                sizeRedundance = aSizeRedundance;
        }
        public function getSizeRedundance(Void):Number{
                return sizeRedundance;
        }

        private function resize(Void):Void{
                mc._width = master.width-sizeRedundance;
                mc._height = master.height-sizeRedundance;
        }
}
Friday, November 28th, 2003

The basic drawingAPI classes

These are the basic classes the drawingAPI uses. The must be in a folder called drawingAPI.
For all these who are new on this blog. These classes only work with the VisibleObject-Class. To get an idea what I’m talking about go a few steps backwards to the VisibleObject-entries.
Ok back to the topic. Here the classes.

The Shape-Class:

import asset.ShapeProperties;

class drawingAPI.Shape extends Graphic{
        public var type:String = “Shape“;

        public var border:Boolean;
        public var fill:Boolean;

        public var addBorder:Function;
        public var removeBorder:Function;

        public var addFill:Function;
        public var removeFill:Function;

        public var getPointByNumber:Function;
        public var getPointsTotal:Function;

        private var properties:ShapeProperties;

        public function Shape(Void){
                properties = new ShapeProperties(true, true);
        }
}

The ShapeComposite-Class:

import drawingAPI.Shape;
import drawingAPI.Border;
import drawingAPI.Fill;

class drawingAPI.ShapeComposite extends Shape/*, Picture*/{// [multiple inheritance]
        public var type:String = “ShapeComposite“;

        public var composite:Picture;

        public function ShapeComposite(Void){
                composite = new Picture();
        }
        public function draw(Void):Void{
                composite.draw();
                resize();
        }
        public function clear(Void):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.clear();
                        i++;
                }
        }
        public function resize(Void):Void{
                mc._width = size.width;
                mc._height = size.height;
        }

        public function set width(aWidth:Number):Void{
                size.width = aWidth;
        }
        public function get width():Number{
                return size.width;
        }
        public function set height(aHeight:Number):Void{
                size.height = aHeight;
        }
        public function get height():Number{
                return size.height;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                size.width = aWidth;
                size.height = aHeight;
        }
        public function getSize(Void):Object{
                return size;
        }

        public function set fill(aBoolean:Boolean):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.fill = aBoolean;
                        i++;
                }
                properties.fill = aBoolean;
        }
        public function get fill():Boolean{
                return properties.fill;
        }

        public function set border(aBoolean:Boolean):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.border = aBoolean;
                        i++;
                }
                properties.border = aBoolean;
        }
        public function get border():Boolean{
                return properties.border;
        }

        public function addShape(aChild:Shape):Number{
                return composite.addGraphic(aChild);
        }
        public function removeShape(aChild:Shape):Void{
                composite.removeGraphic(aChild);
        }
        public function removeShapeByNumber(aNumber:Number):Void{
                composite.removeGraphicByNumber(aNumber);
        }
        public function getShapeByNumber(aNumber:Number)/*:Shape*/{// [type mismatch]
                return composite.getGraphicByNumber(aNumber);
        }
        public function getShapesTotal(Void):Number{
                return composite.getGraphicsTotal();
        }

        private function defineWidth(Void):Void{
                size.width = mc._width;
        }
        private function defineHeight(Void):Void{
                size.height = mc._height;
        }

        private function createMatrix(Void):Void{
                composite.setContainer(mc);
                composite.create();
        }
}

The GeometryShape-Class:

import drawingAPI.ShapeComposite;
import drawingAPI.Shape;
import drawingAPI.Border;
import drawingAPI.Fill;
import drawingAPI.GradientFill;
import asset.Point;

class drawingAPI.GeometryShape extends Shape{
        public var type:String = “GeometryShape“;

        private var points:Array;
        private var fillComposite:Picture;
        private var borderComposite:Picture;

        public function GeometryShape(Void){
                points = new Array();
                fillComposite = new Picture();
                borderComposite = new Picture();
        }
        public function draw(Void):Void{
                if(properties.fill) fillComposite.draw();
                else fillComposite.clear();
                if(properties.border) borderComposite.draw();
                else borderComposite.clear();
        }
        public function set fill(aBoolean:Boolean):Void{
                properties.fill = aBoolean;
        }
        public function get fill():Boolean{
                return properties.fill;
        }
        public function set border(aBoolean:Boolean):Void{
                properties.border = aBoolean;
        }
        public function get border():Boolean{
                return properties.border;
        }
        // border
        public function addBorder(aBorder:Border):Void{
                aBorder.master = this;
                borderComposite.addGraphic(aBorder);
        }
        public function removeBorder(aBorder:Border):Void{
                borderComposite.removeGraphic(aBorder);
        }
        // remark: fill and gradientFill should be handled all the same
        //         that means: you should be able to add a gradientFill or a normal fill with the addFill-method
        // fill
        public function addFill(aFill:Fill):Void{
                aFill.master = this;
                fillComposite.addGraphic(aFill);
        }
        public function removeFill(aFill:Fill):Void{
                fillComposite.removeGraphic(aFill);
        }
        // gradientFill
        public function addGradientFill(aGradientFill:GradientFill):Void{
                aGradientFill.master = this;
                fillComposite.addGraphic(aGradientFill);
        }
        public function removeGradientFill(aGradientFill:GradientFill):Void{
                fillComposite.removeGraphic(aGradientFill);
        }

        public function getPointsTotal(Void):Number{
                return points.length;
        }
        public function getPointByNumber(aNumber:Number):Point{
                return points[aNumber];
        }

        private function addPoint(aPoint:Point):Number{
                points.push(aPoint);
                return points.length-1;
        }

        private function createMatrix(Void):Void{
                fillComposite.setContainer(mc);
                fillComposite.create();

                borderComposite.setContainer(mc);
                borderComposite.create();
        }
}
Friday, November 28th, 2003

A Few Assets

The following classes are a few basics the drawingAPI uses. They must all be in a folder named asset.

The Point-Class:

class asset.Point{
        public var x:Number = null;
        public var y:Number = null;

        public function Point(aXPosition:Number, aYPosition:Number){
                setPosition(aXPosition, aYPosition);
        }
        public function setPosition(aXPosition:Number, aYPosition:Number):Void{
                x = aXPosition;
                y = aYPosition;
        }
        public function moveBy(aX:Number, aY:Number):Void{
                x += aX;
                y += aY;
        }
}

The Size-Class:

class asset.Size{
        public var width:Number = null;
        public var height:Number = null;

        public function Size(aWidth:Number, aHeight:Number){
                width = aWidth;
                height = aHeight;
        }
}

The ShapeProperties-Class:

class asset.ShapeProperties{
        public var border:Boolean = null;
        public var fill:Boolean = null;

        public function ShapeProperties(a:Boolean, b:Boolean){
                border = a;
                fill = b;
        }
}
Friday, November 28th, 2003

The Graphic, Picture and AttachedObjectClass

A added a few classes to my VisibleObject-Project. A Graphic, a Picture and an AttachedObject-Class. They aren’t ducumented yet.

The Graphic-Class:

import asset.Size;

class Graphic extends VisibleObject{
        public var type:String = “Graphic“;

        private var size:Size;

        public var resize:Function;

        public var width:Number;
        public var height:Number;

        public var setSize:Function;
        public var getSize:Function;

        private var defineWidth:Function;
        private var defineHeight:Function;

        public function Graphic(Void){
                size = new Size();
        }
        public function create(Void):Void{
                super.create();
                if(size.width == null) defineWidth();
                if(size.width == null) defineHeight();
        }
}

The Picture-Class:

class Picture extends Graphic/*, VisibleComposite*/{// the first problem [multiple inheritance]
        public var type:String = “Picture“;

        public var composite:VisibleComposite;

        public function Picture(Void){
                composite = new VisibleComposite();
        }
        public function draw(Void):Void{
                composite.draw();
                resize();
                mc._visible = true;
        }
        public function clear(Void):Void{
                mc._visible = false;
        }
        public function resize(Void):Void{
                mc._width = size.width;
                mc._height = size.height;
        }

        public function set width(aWidth:Number):Void{
                size.width = aWidth;
        }
        public function get width():Number{
                return size.width;
        }
        public function set height(aHeight:Number):Void{
                size.height = aHeight;
        }
        public function get height():Number{
                return size.height;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                size.width = aWidth;
                size.height = aHeight;
        }
        public function getSize(Void):Object{
                return size;
        }

        public function addGraphic(aChild:Graphic):Number{
                return composite.addChild(aChild);
        }
        public function removeGraphic(aChild:Graphic):Void{
                composite.removeChild(aChild);
        }
        public function removeGraphicByNumber(aNumber:Number):Void{
                composite.removeChildByNumber(aNumber);
        }
        public function getGraphicByNumber(aNumber:Number)/*:Graphic*/{// damn the second problem [type mismatch]
                return composite.getChildByNumber(aNumber);
        }
        public function getGraphicsTotal(Void):Number{
                return composite.getChildsTotal();
        }

        private function defineWidth(Void):Void{
                size.width = mc._width;
        }
        private function defineHeight(Void):Void{
                size.height = mc._height;
        }

        private function createMatrix(Void):Void{
                composite.setContainer(mc);
                composite.create();
        }
}

The AttachedObject-Class:

import asset.Size;

class AttachedObject extends Graphic{
        public var type:String = “AttachedObject“;

        public function AttachedObject(Void){
        }
        public function draw(Void):Void{
                resize();
                mc._visible = true;
        }
        public function clear(Void):Void{
                mc._visible = false;
        }
        public function resize(Void):Void{
                mc._width = size.width;
                mc._height = size.height;
        }

        public function set width(aWidth:Number):Void{
                size.width = aWidth;
        }
        public function get width():Number{
                return size.width;
        }
        public function set height(aHeight:Number):Void{
                size.height = aHeight;
        }
        public function get height():Number{
                return size.height;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                size.width = aWidth;
                size.height = aHeight;
        }
        public function getSize(Void):Size{
                return size;
        }

        private function defineWidth(Void):Void{
                size.width = mc._width;
        }
        private function defineHeight(Void):Void{
                size.height = mc._height;
        }
}