[Checkins] SVN: z3c.reference/branches/flash/flashsrc/ added flash sources for image crop tool

Johannes Faigle johannes.faigle at lovelysystems.com
Tue Aug 28 08:35:58 EDT 2007


Log message for revision 79306:
  added flash sources for image crop tool

Changed:
  A   z3c.reference/branches/flash/flashsrc/
  A   z3c.reference/branches/flash/flashsrc/BoundingBox.as
  A   z3c.reference/branches/flash/flashsrc/ImageClip.as
  A   z3c.reference/branches/flash/flashsrc/ImageMenu.as
  A   z3c.reference/branches/flash/flashsrc/ImageTool.as
  A   z3c.reference/branches/flash/flashsrc/main.as
  A   z3c.reference/branches/flash/flashsrc/z3cimage.fla

-=-
Added: z3c.reference/branches/flash/flashsrc/BoundingBox.as
===================================================================
--- z3c.reference/branches/flash/flashsrc/BoundingBox.as	                        (rev 0)
+++ z3c.reference/branches/flash/flashsrc/BoundingBox.as	2007-08-28 12:35:57 UTC (rev 79306)
@@ -0,0 +1,271 @@
+/**
+    class for altering the selection of an image
+    or to change the dimenstion.
+    
+    @author <manfred.schwendinger at lovelysystems.com>
+    @author <armin.wolf at lovelysystems.com>
+*/
+
+class BoundingBox extends MovieClip{
+    
+    public static var CORNERSIZE:Number = 8;  // with of one corner square
+    private static var COLOR:Number = 0x333333; // color of the borders etc.
+
+    public var tool:ImageTool; // a listener. 
+
+    private var x:Number;
+    private var y:Number;
+    
+    private var w:Number;
+    private var h:Number;
+    
+    private var border_mc:MovieClip;
+    
+    private var corner_lt:MovieClip;    // left top corner
+    private var corner_rt:MovieClip;    // right top corner
+    private var corner_lb:MovieClip;    // left bottom corner
+    private var corner_rb:MovieClip;    // right bottom corner
+    
+    private var aspect_ratio:Number;
+    private var force_aspect_ratio:Boolean;
+    private var force_size:Boolean;
+    
+	public function BoundingBox(){
+        
+        _x=(Stage.width/2);
+        _y=(Stage.height/2);
+        
+        w=10;
+        h=10;
+        
+        update();
+        
+        force_aspect_ratio=true;
+		Key.addListener(this);
+    
+    }
+    
+    public function get left():Number {return _x-(w/2)};
+    public function get top():Number {return _y-(h/2)};
+    public function get right():Number {return _x+(w/2)};
+    public function get bottom():Number {return _y+(h/2)};
+	
+    private function setX(val:Number){ 
+    	x=val; 
+	}
+    private function getX():Number{
+        return x;
+    }
+    
+    private function setY(val:Number){ 
+		y=val; 
+    }
+    private function getY():Number{
+        return y;
+    }
+    
+    public function setWidth(val:Number){ 
+        w=val; 
+        aspect_ratio = w/h;
+    }
+    public function getWidth():Number{
+        return w;
+    }
+    
+    public function setHeight(val:Number){ 
+        h=val; 
+        aspect_ratio = w/h;
+    }
+    public function getHeight():Number{
+        return h;
+    }
+    
+    public function setAspectForced(b:Boolean):Void{
+        force_aspect_ratio = b;
+        if (b==true) aspect_ratio=w/h;
+    }
+    
+    public function setSizeForced(b:Boolean):Void {
+        
+        if (b==false) {
+            force_size=false;
+            showCorners();
+        } else {
+            force_size=true;
+            hideCorners();
+        }
+    }
+    
+    /**
+        updates the positions of the buttons and draws the border
+    */
+    public function update(){
+        updateCorners();
+        updateBorder();
+        updateAfterEvent();
+    }
+    
+  
+    /**
+        called when a corner gets dragged.
+        calculates the new position of all other 
+        corners.
+    */
+
+    public function onCornerDrag(corner_mc):Void{ 
+        
+        //if (force_aspect_ratio) {
+                
+        
+        //} else {
+        
+            setWidth(Math.abs(this._xmouse) < (Stage.width/2)-tool.PADDING ? Math.abs(this._xmouse)*2 : ((Stage.width/2)-tool.PADDING)*2);
+            setHeight(Math.abs(this._ymouse) < (Stage.height/2)-tool.PADDING ? Math.abs(this._ymouse)*2 : ((Stage.height/2)-tool.PADDING)*2);
+            
+        //}
+        update();
+        
+        /*
+        if (corner_mc == corner_lt || corner_mc == corner_rt){
+            // one of the top corners
+            if (corner_mc == corner_lt){
+                // left top corner gets dragged
+                y = corner_mc._y;
+                h = corner_rb._y - corner_lt._y;
+                
+                if (force_aspect_ratio){
+                    w = h * aspect_ratio;
+                    x = corner_rb._x - w;
+                }
+                else{
+                    x = corner_mc._x;
+                    w = corner_rb._x - corner_lt._x;
+                }
+            }
+            else if (corner_mc == corner_rt){
+                // right top corner
+                y = corner_mc._y;                
+                h = corner_rb._y - corner_rt._y;
+                if (force_aspect_ratio){
+                    w = h * aspect_ratio;
+                }
+                else{
+                    w = corner_rt._x - corner_lt._x;
+                }
+            }
+            
+        }
+        else{
+            // one of the bottom corners
+            if (corner_mc == corner_lb){
+                // left bottom
+                x = corner_mc._x;
+                w = corner_rt._x - corner_mc._x;
+                h = corner_mc._y - corner_lt._y;
+            }
+            else if (corner_mc == corner_rb){
+                // right bottom
+                w = corner_mc._x - corner_lb._x;
+                h = corner_mc._y - corner_lt._y;
+                
+            }
+            if (force_aspect_ratio) h = w / aspect_ratio;
+        }
+        
+        center();
+        update();
+        
+        */
+        tool.onBoundingCornerDrag();     
+    }
+/*
+    public function onCornerDragBegin(corner_mc:MovieClip):Void{
+        tool.onBoundingCornerDragBegin(corner_mc);
+    }
+*/   
+    /**
+        creates a border and drag clip 
+        and puts the required events onto it. 
+    */
+    public function updateBorder() {
+        if (!border_mc) this.createEmptyMovieClip("border_mc", this.getNextHighestDepth());
+        
+        var point:flash.geom.Point=new flash.geom.Point(w/2, h/2);
+        
+        border_mc.clear();
+        border_mc.beginFill(0xFF0000, 0);
+        border_mc.lineStyle(0, COLOR);
+        
+        border_mc.moveTo(-point.x, -point.y);
+        border_mc.lineTo(point.x, -point.y);
+        border_mc.lineTo(point.x, point.y);
+        border_mc.lineTo(-point.x, point.y);
+        border_mc.lineTo(-point.x, -point.y);
+        
+       border_mc.endFill();
+        
+   }
+    
+    private function updateCorners() {
+        if (!corner_lt) createCornerClip("corner_lt");
+        if (!corner_rt) createCornerClip("corner_rt");
+        if (!corner_lb) createCornerClip("corner_lb");
+        if (!corner_rb) createCornerClip("corner_rb");
+        
+        var point:flash.geom.Point=new flash.geom.Point(w/2, h/2);
+                
+        corner_lt.pos(-point.x, -point.y);
+        corner_rt.pos(point.x, -point.y);
+        corner_lb.pos(-point.x, point.y);
+        corner_rb.pos(point.x, point.y);
+        
+    }
+    
+    /**
+        draws a border clips 
+        with a small square
+        the center of the square is the 0-point of the mc
+    */
+    public function createCornerClip(title:String):Void{
+        this.createEmptyMovieClip(title, this.getNextHighestDepth());
+        var clip_mc:MovieClip = this[title];
+        var s:Number = CORNERSIZE/2;
+        clip_mc.lineStyle(0, COLOR);
+        clip_mc.moveTo(-s, -s);
+        clip_mc.beginFill(COLOR);
+        clip_mc.lineTo(-s, s); clip_mc.lineTo(s, s);
+        clip_mc.lineTo(s, -s); clip_mc.lineTo(-s, -s);
+        clip_mc.endFill();
+        clip_mc.ptr = this;
+        clip_mc.onPress = function(){
+            this.startDrag();
+            this.ptr.onCornerDragBegin(this);
+            this.onMouseMove = function(){
+                this.ptr.onCornerDrag(this);
+            }
+            clip_mc.onMouseUp = function(){
+                this.ptr.onCornerDrag(this);
+                delete this.onMouseMove;
+                delete this.onMouseUp;
+                this.stopDrag();
+            }
+            
+        }
+        clip_mc.pos = function(x:Number, y:Number){ this._x = x; this._y = y; };
+    }
+    
+    private function showCorners() {
+        corner_lt._visible=true;
+        corner_rt._visible=true;
+        corner_lb._visible=true;
+        corner_rb._visible=true;  
+    }
+    
+    private function hideCorners() {
+        corner_lt._visible=false;
+        corner_rt._visible=false;
+        corner_lb._visible=false;
+        corner_rb._visible=false;  
+    }
+    
+}
\ No newline at end of file

Added: z3c.reference/branches/flash/flashsrc/ImageClip.as
===================================================================
--- z3c.reference/branches/flash/flashsrc/ImageClip.as	                        (rev 0)
+++ z3c.reference/branches/flash/flashsrc/ImageClip.as	2007-08-28 12:35:57 UTC (rev 79306)
@@ -0,0 +1,180 @@
+ /**
+* Class ImageClip
+* This Class contains the image and functions to directly manipulate (zoom or rotate) the image
+*
+* @author viktor.sohm at lovelysystems.com
+* @author manfred.schwendinger at lovelysystems.com
+* @author armin.wolf at lovelysystems.com
+*/
+
+class ImageClip extends MovieClip{
+	
+    private var zoomer_mc:MovieClip;
+    public var tool:ImageTool;
+    private var mc_loader:MovieClipLoader;
+    private var mode:String;
+	private var mousePressed:Boolean;
+    
+    public function ImageClip(){
+        mc_loader = new MovieClipLoader();
+        mode = "crop";
+        this.createEmptyMovieClip("zoomer_mc", 1);
+        this.zoomer_mc.createEmptyMovieClip("rotator_mc", 1);
+        
+        var shadow=new flash.filters.DropShadowFilter(3);
+        filters=[shadow];
+        
+        
+    }
+    
+    public function get left():Number {return _x};
+    public function get top():Number {return _y};
+    public function get right():Number {return _x+getImageWidth()};
+    public function get bottom():Number {return _y+getImageHeight()};
+    
+    public function setMode(m:String):Void{
+        if (m==mode) return; // no change
+        mode = m;
+    }
+
+    public function getMcLoader():MovieClipLoader{
+        return mc_loader;
+    }
+    
+    /**
+	* Loads the image into the ImageClip Class
+	* @param needs the image path as parameter as String
+	*/
+	function loadImage(path:String):Void{
+        mc_loader.loadClip(path, this.zoomer_mc.rotator_mc);
+        mc_loader.addListener(this);
+	}
+    
+    public function getOriginalWidth():Number {
+        //return values depending on rotation
+        //return Math.abs(getRotation())==90 ? original_height : original_width;
+    
+        return getImageWidth()/getZoomFactor();
+    }
+    public function getOriginalHeight():Number {
+        return getImageHeight()/getZoomFactor();
+        //return Math.abs(getRotation())==90 ? original_width : original_height;
+    }
+    
+    
+    /**
+        @return the current zoom factor.
+        e.g. 2 if the image is twice as big as the original.
+    */
+    public function getZoomFactor():Number{
+        return this.zoomer_mc._xscale/100;
+    }
+    
+    public function getRotation():Number{
+        return this.zoomer_mc.rotator_mc._rotation;
+    }
+    
+	/**
+	* Zooms the Image
+	* @param needs a direction, and a zoom percentage given above
+    * @param amount:Number  how much should we scale e.g. 20%
+	*/
+	function zoomImage (dir:Number, amount:Number):Void{
+        
+        if (zoomer_mc._xscale+(amount*dir) <= 10 || zoomer_mc._xscale+(amount*dir) > 10000) return;
+    
+        this.zoomer_mc._xscale += amount*dir;
+        this.zoomer_mc._yscale += amount*dir;
+		
+		
+	}
+	
+	public function setZoomFactor(factor:Number):Void {
+	    
+	    if (factor > getZoomFactor()*100) zoomImage(factor-getZoomFactor()*100, 1);
+	    else zoomImage(getZoomFactor()*100-factor, -1);
+	    
+    }
+	
+	
+	public function setRotation(val:Number) {
+	    
+	    val = val % 360;
+	    val = val > 0 ? val : val + 360;
+	  /*  
+	    while (rot != val) {
+            var rot=rotateImage(1);
+        }
+	 */    
+	 //   trace("rotation delta: "+diff);
+	    
+    }
+	
+	/**
+	* Rotates the extern_mc
+	* @param needs a Direction to Rotate the Image in 90¡ Steps
+	*/
+	function rotateImage(dir:Number):Number{
+
+        var mc:MovieClip = zoomer_mc.rotator_mc;
+        mc._rotation += 90*dir;
+        
+        // make a num from 0 to 360
+        var rotation:Number = mc._rotation;
+        
+        while(rotation<0){ 
+            rotation+=360; 
+        }
+        while(rotation>=360){ 
+            rotation-=360; 
+        }
+
+        trace("rotation normalized: "+mc._rotation);
+        
+        mc._rotation = rotation;
+        
+        switch(rotation){
+            case 0:
+                mc._x = 0;
+                mc._y = 0;
+                break;
+            case 90:
+                mc._x = mc._width;
+                mc._y = 0;
+                break;
+            case 180:
+                mc._x = mc._width;
+                mc._y = mc._height;
+                break;
+            case 270:
+                mc._x = 0;
+                mc._y = mc._height;
+                break;
+            default:
+                trace("error: unexpected rotation angle: "+mc._rotation);
+                break;
+        }
+        return rotation;
+	}
+    
+    public function setImageWidth(w:Number):Void{
+        this.zoomer_mc._width = w;
+    }
+    
+    public function setImageHeight(h:Number):Void{
+        this.zoomer_mc._height = h;
+    }
+    
+    public function getImageWidth():Number{
+        return this.zoomer_mc._width;
+    }
+    public function getImageHeight():Number{
+        return this.zoomer_mc._height;
+    }
+
+    public function onMouseUp(){
+        this.stopDrag();
+		mousePressed=false;
+    }
+
+}


Property changes on: z3c.reference/branches/flash/flashsrc/ImageClip.as
___________________________________________________________________
Name: svn:executable
   + *

Added: z3c.reference/branches/flash/flashsrc/ImageMenu.as
===================================================================
--- z3c.reference/branches/flash/flashsrc/ImageMenu.as	                        (rev 0)
+++ z3c.reference/branches/flash/flashsrc/ImageMenu.as	2007-08-28 12:35:57 UTC (rev 79306)
@@ -0,0 +1,176 @@
+/**
+* Class ImageMenu
+* Menu - Class of the Flash ImageCrop Tool
+* 
+* @author viktor.sohm at lovelysystems.com
+*/
+
+class ImageMenu extends MovieClip {
+	
+	private var menuDrag_mc:MovieClip;
+	private var zoomIn_mc:MovieClip;
+	private var zoomOut_mc:MovieClip;
+	private var rotateLeft_mc:MovieClip;
+	private var rotateRight_mc:MovieClip;
+	private var menuAbort_mc:MovieClip;
+	private var menuAccept_mc:MovieClip;
+	private var cropsize_mc:MovieClip; //movieclip holding the textfields for manual size input
+	private var outputsize_mc:MovieClip;
+	
+	private var bg_mc:MovieClip;
+	
+	public var pointer;
+	
+	private var _eObj:Object;
+	private var _eFunc:Object;
+	private var _eArgs:Array;
+	
+	/**
+	* Initializes the functions of the Menu Icons and defines the menu Position
+	*/
+	function ImageMenu(){
+		trace("Menu Initialized");
+	}
+	
+	public function init(){
+		
+		bg_mc._width=Stage.width;
+		bg_mc._height=50;
+		this._y=Stage.height-50;
+		
+		
+		this.zoomOut_mc.pointer = this.pointer;
+		this.zoomOut_mc.mn = this;
+		
+		this.zoomIn_mc.pointer = this.pointer;
+		this.zoomIn_mc.mn = this;
+		
+		this.rotateLeft_mc.pointer = this.pointer;
+		this.rotateLeft_mc.mn = this;
+		
+		this.rotateRight_mc.pointer = this.pointer;
+		this.rotateRight_mc.mn = this;
+		
+		this.menuAbort_mc.pointer = this.pointer;
+		this.menuAbort_mc.mn = this;
+		
+		this.menuAccept_mc.pointer = this.pointer;
+		this.menuAccept_mc.mn = this;
+		
+		
+		/**
+		* Defines what happens when you press on the Drag Field (draggin of menu starts)
+		*/
+		this.menuDrag_mc.onPress = function(){
+			this._parent.startDrag(false);
+		}
+		
+		/**
+		* Defines waht happens when you release the Drag Field (drag stops)
+		*/
+		this.menuDrag_mc.onRelease = function(){
+			this._parent.stopDrag();
+		}
+		
+		/**
+		* Zoom In Event
+		*/
+		this.zoomIn_mc.onPress = function(){
+			this.mn.triggerOnEnterFrame(this.pointer, this.pointer.onZoomClicked, 1, 2);
+		}
+		this.zoomIn_mc.onRelease =  this.zoomIn_mc.onReleaseOutside = function() {
+	        this.mn.releaseOnEnterFrame();
+	    }
+		
+		/**
+		* Zoom out Event
+		*/
+		this.zoomOut_mc.onPress = function(){
+			this.mn.triggerOnEnterFrame(this.pointer, this.pointer.onZoomClicked, -1, 2);
+		}
+		this.zoomOut_mc.onRelease = this.zoomOut_mc.onReleaseOutside = function() {
+			this.mn.releaseOnEnterFrame();
+		}
+		
+		/**
+		* Rotate Left Button Event
+		*/
+		this.rotateLeft_mc.onRelease = function(){
+			this.pointer.onRotateClicked(-1);
+		}
+		
+		/**
+		* Rotate Right Button Event
+		*/
+		this.rotateRight_mc.onRelease = function(){
+			this.pointer.onRotateClicked(1);
+		}
+		
+		/**
+		* Reset / Abort Events
+		*/
+		this.menuAbort_mc.onRelease = function(){
+            // currently abused for testing!!!!!!
+			this.pointer.switchMode();
+		}
+		
+		/**
+		* Accept Event
+		*/
+		this.menuAccept_mc.onRelease = function(){
+			this.pointer.saveChanges();
+		}
+		
+	/*	
+		this.cropsize_mc.width_txt.ptr=this.pointer;
+		this.cropsize_mc.width_txt.onChanged=function() {
+		    //trace("width was changed: " + this.text);
+		    this.ptr.onManualCropSizeChange(this.text, this._parent.height_txt.text);
+		}
+		this.cropsize_mc.height_txt.ptr=this.pointer; 
+		this.cropsize_mc.height_txt.onChanged=function(){
+		    this.ptr.onManualCropSizeChange(this._parent.width_txt.text, this.text);
+		}
+		
+		this.outputsize_mc.width_txt.ptr=this.pointer;
+		this.outputsize_mc.width_txt.onChanged=function() {
+		    //trace("width was changed: " + this.text);
+		    this.ptr.onManualOutputSizeChange(this.text, this._parent.height_txt.text);
+		}
+		this.outputsize_mc.height_txt.ptr=this.pointer; 
+		this.outputsize_mc.height_txt.onChanged=function(){
+		    this.ptr.onManualOutputSizeChange(this._parent.width_txt.text, this.text);
+		}
+	*/	
+	}
+	
+	function setCropSizeValues(width:Number, height:Number) {
+	    this.cropsize_mc.width_txt.text=width;
+	    this.cropsize_mc.height_txt.text=height;
+	}
+	function updateOutputSizeValues(width:Number, height:Number) {
+	    this.outputsize_mc.width_txt.text=width;
+	    this.outputsize_mc.height_txt.text=height;
+	}
+	
+	private function triggerOnEnterFrame(eo:Object, ef:Function) {
+	    _eObj=eo;
+	    _eFunc=ef;
+	    _eArgs=arguments.slice(2);
+	    onEnterFrame=enterFrame;
+	}
+	
+	private function releaseOnEnterFrame() {
+	    
+	    trace("releasing Enterframe");
+	    
+	    _eObj=null;_eFunc=null;_eArgs=null
+	    onEnterFrame=null;
+	}
+	
+	private function enterFrame() {
+	    _eFunc.apply(_eObj, _eArgs);
+	} 
+
+
+}
\ No newline at end of file


Property changes on: z3c.reference/branches/flash/flashsrc/ImageMenu.as
___________________________________________________________________
Name: svn:executable
   + *

Added: z3c.reference/branches/flash/flashsrc/ImageTool.as
===================================================================
--- z3c.reference/branches/flash/flashsrc/ImageTool.as	                        (rev 0)
+++ z3c.reference/branches/flash/flashsrc/ImageTool.as	2007-08-28 12:35:57 UTC (rev 79306)
@@ -0,0 +1,642 @@
+/**
+* Class ImageTool 
+* is a tool for cropping images TTW
+*
+* @author <viktor.sohm at lovelysystems.com>
+* @author <manfred.schwendinger at lovelysystems.com>
+* @author <armin.wolf at lovelysystems.com>
+*/
+
+class ImageTool extends MovieClip{
+
+	public var crop_h:Number;
+	public var crop_w:Number; 
+	public var crop_x:Number;
+	public var crop_y:Number;
+
+	public var original_w:Number;
+	public var original_h:Number;
+	private var output_w:Number; //the output width
+    private var output_h:Number; //the output height
+    
+    private var output_ratio:Number=1;
+    private var force_size:Boolean;
+           
+    public var url:String; 
+
+  //public var rotation_factor:Number; // @comment: really required?
+    
+    public var rotation:Number;   
+	public var bounding_mc:BoundingBox;
+	
+	public var image_mc:ImageClip;
+    private var mask_mc:MovieClip;
+    private var blured_mc:MovieClip; //darkened movieclip
+	
+	private var ImageMenu:ImageMenu;
+    public var PADDING:Number=40;
+    
+  //private var draginfo:Object;
+    
+  //private var mode:String; // either "crop" or "scale"
+    
+	/**
+	 * Initializes the start Parameters and functions
+	*/
+	function ImageTool(){
+//        keepaspect = false; 
+        Stage.addListener(this);
+    }
+    
+/*   
+    public function setLockAspect(b:Boolean):Void{
+        keepaspect = b;
+    }
+*/    
+
+
+    /**
+        sets the dimension of the image. 
+        please set the size before initialization
+    
+    public function setSize(w:Number, h:Number):Void{
+        trace("setSize: "+w+"/"+h);
+        size_w = w;
+        size_h = h;
+    }
+    */
+    
+    /**
+        set the current crop position of your image
+    */
+    public function setCrop(x:Number, y:Number, w:Number, h:Number){
+        setCropPos(x, y);
+        crop_w = w;
+        crop_h = h;
+        
+        //aspectratio = crop_w / crop_h;
+    }
+    
+    public function setCropPos(x:Number, y:Number):Void{
+        crop_x = x;
+        crop_y = y;
+    }
+    
+    public function setUrl(u:String):Void{
+        url = u;
+    }
+    
+    public function initialize():Void{
+		
+        this.createEmptyMovieClip("stepper_mc", 0);
+        
+        trace("ImageTool load Image: "+url);
+		
+		var blured=this.attachMovie("BluredImageClip","blured_mc",1);
+        blured.tool=this;
+		blured.loadImage(url);
+		
+		
+		this.attachMovie("ImageClip","image_mc",3);
+        this.image_mc.getMcLoader().addListener(this);
+		this.image_mc.loadImage(url);
+		this.image_mc.tool=this;
+	
+		
+        this.createEmptyMovieClip("mask_mc", 4);
+        this.mask_mc.lineStyle(0, 0xFF0000, 0);
+        this.mask_mc.beginFill(0xFF0000, 10);
+        this.mask_mc.lineTo(crop_w, 0); this.mask_mc.lineTo(crop_w, crop_h); 
+        this.mask_mc.lineTo(0, crop_h); this.mask_mc.lineTo(0, 0); 
+        this.mask_mc.endFill();
+		this.mask_mc._x=crop_x;
+		this.mask_mc._y=crop_y;
+		this.image_mc.setMask(mask_mc);
+     
+        updateMask();
+        
+        this.attachMovie("ImageMenu","ImageMenu",this.getNextHighestDepth());
+        this.ImageMenu.pointer = this;
+        this.ImageMenu.init();
+		
+        this.attachMovie("BoundingBox", "bounding_mc", this.getNextHighestDepth());
+        bounding_mc.tool = this; //pass reference
+        
+        if (output_w && output_h) {
+            bounding_mc.setWidth(output_w);
+            bounding_mc.setHeight(output_h);
+            force_size=true;
+            bounding_mc.setSizeForced(true);
+            
+        }
+        
+        bounding_mc.update();
+      
+        //write the defaul output values into the textfields
+        //this.ImageMenu.updateOutputSizeValues(_level0.crop_w, _level0.crop_h);
+   }
+	
+   public function onLoadInit():Void{
+        
+        /*
+        if (crop_w == 0){
+            crop_w = this.image_mc.getImageWidth();
+            bounding_mc.setWidth(crop_w);
+            bounding_mc.update();
+        }
+        if (crop_h == 0){
+            crop_h = this.image_mc.getImageHeight();
+            bounding_mc.setHeight(crop_h);
+            bounding_mc.update();
+        }
+        if (size_w == 0){
+            size_w = this.image_mc.getImageWidth();
+        }
+        if (size_h == 0){
+            size_h = this.image_mc.getImageHeight();
+        }*/
+        
+        //apply the crop-position depending on the output-ratio
+        
+        //if ()var output_ratio=image_mc.getImageWidth()/
+        
+        //getURL("JavaScript:alert('output-ratio: "+output_ratio+"');");
+                
+        image_mc.setZoomFactor(Math.round(output_ratio*100));
+        blured_mc.setZoomFactor(Math.round(output_ratio*100));
+                        
+        image_mc._x=bounding_mc.left-(crop_x)//*output_ratio);
+        image_mc._y=bounding_mc.top-(crop_y)//*output_ratio);
+        
+        image_mc.setRotation(rotation);
+        blured_mc.setRotation(rotation);
+        
+        blured_mc._x=image_mc._x;blured_mc._y=image_mc._y;
+        updateMask();
+        
+    }
+    
+	/**
+	* gives the COMMAND to zoom the base image
+	* @param -1 stands for outzooming ( pic gets smaller) , 1 stands for inzooming (pic gets bigger) 
+	*/
+	function onZoomClicked(dir:Number, amt:Number){
+		
+		if (!amt) amt=10;
+		
+		//change the position of the image,
+		//so it zooms out of the center of the stage
+		
+		var middle_x=Stage.width/2;var middle_y=Stage.height/2;
+		var dx=middle_x-image_mc._x;var dy=middle_y-image_mc._y;
+		
+		var middle_x=Stage.width/2;var middle_y=Stage.height/2;
+		var dx=middle_x-image_mc._x;
+		var dy=middle_y-image_mc._y;
+		
+		//calculate the percentage
+		var px=dx/image_mc.getImageWidth();
+		var py=dy/image_mc.getImageHeight();
+		
+		this.image_mc.zoomImage(dir, amt);
+		
+		//now apply the new positions according to the percentage
+		image_mc._x=middle_x-(image_mc.getImageWidth()*px);
+		image_mc._y=middle_y-(image_mc.getImageHeight()*py);
+ 
+ 		if (image_mc.getImageHeight() < bounding_mc.getHeight())  {
+    		
+    		trace("image.height < bounding.height: " +force_size+".");
+    		
+    		if (force_size) {
+    		//resize image if output-size is locked
+    		    var needed_zoom=bounding_mc.getHeight()/image_mc.getOriginalHeight();
+                image_mc.setZoomFactor(Math.round(needed_zoom*100));
+                image_mc._y=(Stage.height/2)-(image_mc.getImageHeight()/2);
+            } else {
+            //resize bounding-box if size is not locked
+    		    bounding_mc.setHeight(image_mc.getImageHeight());
+    		    image_mc._y=(Stage.height/2)-(image_mc.getImageHeight()/2);
+    		}
+    		
+    	}
+		
+    	if (image_mc.getImageWidth() < bounding_mc.getWidth()) {
+    	    //resize image if output-size is locked
+    	    
+    	    trace("image.width < bounding.width: "+force_size+".");
+    	    
+    	    if (force_size) {
+    		    var needed_zoom=bounding_mc.getWidth()/image_mc.getOriginalWidth();
+                image_mc.setZoomFactor(Math.round(needed_zoom*100));
+                
+            } else {
+            //resize bounding-box
+    	        bounding_mc.setWidth(image_mc.getImageWidth());
+    	        image_mc._x=(Stage.width/2)-(image_mc.getImageWidth()/2);
+    	    }
+    	}
+		
+		setOutputSize(bounding_mc.getWidth(), bounding_mc.getHeight());
+        bounding_mc.update();
+		updateMask();
+		
+		if (bounding_mc.left < image_mc.left) image_mc._x=bounding_mc.left;
+        if (bounding_mc.right > image_mc.right) image_mc._x=bounding_mc.right-image_mc.getImageWidth();
+        if (bounding_mc.top < image_mc.top) image_mc._y=bounding_mc.top;
+        if (bounding_mc.bottom > image_mc.bottom) image_mc._y=bounding_mc.bottom-image_mc.getImageHeight();
+				
+		//update blured1
+		var ib=blured_mc;
+		ib._x=image_mc._x;
+		ib._y=image_mc._y;
+		ib.setZoomFactor(Math.round(image_mc.getZoomFactor()*100));
+	}
+	
+	/**
+	* gives the COMMAND to rotate the base image
+	* @param -1 stands for 90¡ left rotation, 1 stands for 90¡ to the right
+	*/
+	function onRotateClicked(dir:Number){
+		this.image_mc.rotateImage(dir);
+		this.blured_mc.rotateImage(dir);
+		trace("rotation: "+dir);
+		
+		
+		if (image_mc.getImageWidth() < bounding_mc.getWidth()) {
+		    var needed_zoom=bounding_mc.getWidth()/image_mc.getOriginalWidth();
+            image_mc.setZoomFactor(Math.round(needed_zoom*100));
+            image_mc._x=(Stage.width/2)-(image_mc.getImageWidth()/2);
+	    }
+	    if (image_mc.getImageHeight() < bounding_mc.getHeight()) {
+		    var needed_zoom=bounding_mc.getHeight()/image_mc.getOriginalHeight();
+            image_mc.setZoomFactor(Math.round(needed_zoom*100));
+            image_mc._y=(Stage.height/2)-(image_mc.getImageHeight()/2);
+	    }
+		
+		
+		//update blured1
+		var ib=blured_mc;
+		ib._x=image_mc._x;
+		ib._y=image_mc._y;
+		ib.setZoomFactor(Math.round(image_mc.getZoomFactor()*100));
+		
+		
+		//var rotation=image_mc.getRotation();
+		//if (Math.abs(rotation)==90) fitToWindow(image_mc.original_height, image_mc.original_width) //exchange width and height for fitting
+		//else fitToWindow(image_mc.original_width, image_mc.original_height);
+		
+		
+		//check for border overlaps after rotation
+	/*	if (image_mc._x < 0) image_mc._x=0;
+		if (image_mc._y < 0) image_mc._y=0;
+		
+		if (image_mc._x+image_mc._width > Stage.width) image_mc._x=Stage.width-image_mc._width;
+		if (image_mc._y+image_mc._height > Stage.height) image_mc._y=Stage.height-image_mc._height;
+	*/	
+	}
+    
+	/**
+        saves the changes (calls javascript)
+	*/
+	function saveChanges(){
+        
+        trace("\n\nsaveChanges");
+        trace("zoom factor: "+image_mc.getZoomFactor());
+        
+        
+        
+        /*
+        
+        crop_x = Math.round((bounding_mc.left-image_mc.left) / image_mc.getZoomFactor());
+        crop_y = Math.round((bounding_mc.top-image_mc.top) / image_mc.getZoomFactor());
+        
+        var rotation:Number = Math.round(image_mc.getRotation());
+        
+        var url_str:String = "javascript:cropImage("+crop_x+", "+crop_y; 
+        url_str+=", "+Math.round(bounding_mc.getWidth() / image_mc.getZoomFactor());
+        url_str+=", "+Math.round(bounding_mc.getHeight() / image_mc.getZoomFactor());
+        if (original_w != null) url_str+=", "+original_w;
+        if (original_h != null) url_str+=", "+original_h;
+        //if (output_w != null) url_str+=", "+output_w;
+        //if (output_h != null) url_str+=", "+output_h;
+        url_str+=", "+rotation;
+        
+        url_str+=")";
+        
+        */
+        
+        var url_str:String="";
+        
+        url_str+="JavaScript:cropImage(";
+        
+        crop_x = Math.round(bounding_mc.left-image_mc.left)//Math.round((bounding_mc.left-image_mc.left) / image_mc.getZoomFactor());
+        crop_y = Math.round(bounding_mc.top-image_mc.top)//Math.round((bounding_mc.top-image_mc.top) / image_mc.getZoomFactor());
+        
+        
+        var rotation:Number = (Math.round(image_mc.getRotation()) % 360)*-1; //seems like pil accepts rotation in the other direction
+        rotation = rotation > 0 ? rotation : rotation + 360;
+        
+        url_str += crop_x + ", ";        
+        url_str += crop_y + ", ";        
+        
+        url_str += output_w + ", ";
+        url_str += output_h + ", ";
+        
+        if (rotation==90 || rotation==270) {
+            url_str += Math.round(original_h * image_mc.getZoomFactor()) + ", ";
+            url_str += Math.round(original_w * image_mc.getZoomFactor()) + ", " ;
+        } else {
+            url_str += Math.round(original_w * image_mc.getZoomFactor()) + ", " ;
+            url_str += Math.round(original_h * image_mc.getZoomFactor()) + ", ";
+        }
+        
+        
+        url_str += rotation.toString() + ", ";
+        url_str += image_mc.getZoomFactor()+"";
+        
+        url_str+=");";
+        
+        // (590, 240, 260, 195, 600, 450, 0)
+        trace("url_str: "+url_str);
+        
+        if (System.capabilities.playerType == "External"){
+            // we are inside debug mode, so do not use getURL
+            return;
+        }
+        
+        getURL(url_str);
+	}
+    
+    public function setOutputSize(w:Number, h:Number){
+        
+        if ((w==NaN) && (h==NaN)) {
+            output_w=640;
+            output_h=480;
+        } else {
+            output_w = w;
+            output_h = h;
+        }
+    }
+    public function setOriginalSize(w:Number, h:Number) {
+        original_w=w;
+        original_h=h;
+    }
+    
+    public function setOutputRatio(r:Number) {
+       if (typeof(r)=="number") output_ratio=r;
+    }
+    
+    public function setRotation(r:Number) {
+        rotation=r;
+    }
+    
+    /**
+        gets called when the border from the boundingbox was
+        dragged. in scale mode the image moves together with the
+        bounding box
+    
+    public function onBoundingBorderDrag():Void{
+        if (mode == "scale"){
+            var relative_x = 0//bounding_mc.getX() - draginfo.x;
+            var relative_y = 0//bounding_mc.getY() - draginfo.y;
+            image_mc._x += relative_x;
+            image_mc._y += relative_y;
+            
+            draginfo.x = //bounding_mc.getX();
+            draginfo.y = //bounding_mc.getY();
+        }
+        updateMask();
+    }
+    
+    /**
+        the boundingborder begins to drag. so lets take a snapshot
+        from the positions for beeing able to move the image
+        relative to the position of the bounding box. 
+    
+    public function onBoundingBorderDragBegin():Void{
+        if (mode == "scale"){
+            draginfo = new Object();
+            draginfo.x = 0//bounding_mc.getX();
+            draginfo.y = 0//bounding_mc.getY();
+        }
+    }
+    
+    public function onBoundingBorderDragEnd():Void{
+    }
+    */
+    
+    
+    public function onBoundingCornerDrag():Void{
+    
+		// in momoriam: manfred ++++ *schnŸff*
+	/*	 
+        if (mode == "scale") {ý
+        
+            //trace("**************** onBoundingBorderDrag");
+        
+       // trace("old: "+draginfo.x+"/"+draginfo.y+" s: "+draginfo.w+"/"+draginfo.h+" img-size: "+draginfo.img_w+"/"+draginfo.img_h);
+        
+        //trace("new: "+//bounding_mc.getX()+"/"+//bounding_mc.getY()+" s: "+bounding_mc.getWidth()+"/"+bounding_mc.getHeight());
+        
+        var delta_x:Number = bounding_mc.getWidth() / draginfo.w;
+        //trace("deltax: "+delta_x);
+        
+        var img_x:Number = draginfo.x*(1 - delta_x) + draginfo.img_x * delta_x + 0//bounding_mc.getX() - draginfo.x;
+        var img_y:Number = draginfo.y*(1 - delta_x) + draginfo.img_y * delta_x + 0//bounding_mc.getY() - draginfo.y;
+        
+        image_mc._x = img_x;
+        image_mc._y = img_y;
+        
+        //trace("set new image pos: "+img_x + "/" + img_y);
+        
+        image_mc.setImageWidth(draginfo.img_w * delta_x);
+        image_mc.setImageHeight(draginfo.img_h * delta_x);
+        //trace("set new image w: "+draginfo.img_w+" * "+delta_x+" = "+(draginfo.img_w * delta_x)+" scalefactor: "+image_mc.getZoomFactor());
+    //    trace("set new image h: "+draginfo.img_h+" * "+delta_x+" = "+(draginfo.img_h * delta_x)+" scalefactor: "+image_mc.getZoomFactor());
+        
+        }
+    */    
+        
+        
+        if (bounding_mc.getWidth() > image_mc.getImageWidth()) {
+            var needed_zoom=bounding_mc.getWidth()/image_mc.getOriginalWidth();
+            image_mc.setZoomFactor(Math.round(needed_zoom*100));
+            blured_mc.setZoomFactor(Math.round(needed_zoom*100));
+        } else if (bounding_mc.getHeight() > image_mc.getImageHeight()) {
+            var needed_zoom=bounding_mc.getHeight()/image_mc.getOriginalHeight();
+            image_mc.setZoomFactor(Math.round(needed_zoom*100));
+            blured_mc.setZoomFactor(Math.round(needed_zoom*100));
+        } 
+        
+        if (bounding_mc.left < image_mc.left) image_mc._x=bounding_mc.left;
+        if (bounding_mc.right > image_mc.right) image_mc._x=bounding_mc.right-image_mc.getImageWidth();
+        if (bounding_mc.top < image_mc.top) image_mc._y=bounding_mc.top;
+        if (bounding_mc.bottom > image_mc.bottom) image_mc._y=bounding_mc.bottom-image_mc.getImageHeight();
+        
+        
+        blured_mc._x=image_mc._x;
+        blured_mc._y=image_mc._y;
+        
+        updateMask();
+        
+        setOutputSize(bounding_mc.getWidth(), bounding_mc.getHeight());
+		
+    }
+  /*
+    public function onBoundingCornerDragBegin(corner_mc:MovieClip):Void{
+        if (mode == "scale"){
+            this.rememberBounding(corner_mc);
+        }
+    }
+    
+    function rememberBounding(corner_mc:MovieClip):Void{
+        trace("\n\nremember bounding.........");
+        draginfo = new Object();
+        draginfo.corner_mc = corner_mc;
+        draginfo.x = //bounding_mc.getX();
+        draginfo.y = //bounding_mc.getY();
+        draginfo.w = bounding_mc.getWidth();
+        draginfo.h = bounding_mc.getHeight();
+        
+        draginfo.img_x = image_mc._x;
+        draginfo.img_y = image_mc._y;
+        draginfo.img_w = image_mc.getImageWidth();
+        draginfo.img_h = image_mc.getImageHeight();
+        trace("remembered image size: "+draginfo.img_w+"/"+draginfo.img_h);
+    }
+  */  
+    /**
+        resizes and repositions the mask
+    */
+    public function updateMask():Void{
+        mask_mc._x = bounding_mc.left;
+        mask_mc._y = bounding_mc.top;
+        mask_mc._width = bounding_mc.getWidth();
+        mask_mc._height = bounding_mc.getHeight();
+    }
+    
+    /**
+        called when the stage resizes. 
+    */
+    public function onResize():Void{
+        updateMask();
+    }
+    
+    public function getImageBounds():Object {
+        return image_mc.getBounds(_root);
+    }
+    
+    public function fitToWindow(iw:Number, ih:Number) {
+        //scale the image down if bigger than stage
+        
+        if (typeof(ih) != "number") var ih=image_mc.getOriginalHeight();
+        if (typeof(iw) != "number") var iw=image_mc.getOriginalWidth();
+        
+        trace("scaleToFitWindow: "+ih + "/" + iw);
+        
+        //save the boundingbox percentage (for relative zooming)
+        var b_bounds=bounding_mc.getBounds(image_mc);
+        var bounding_x = b_bounds.xMin+BoundingBox.CORNERSIZE/2;var bounding_y = b_bounds.yMin+BoundingBox.CORNERSIZE/2;
+        
+        var bpx = bounding_x/image_mc._width;var bpy = bounding_y/image_mc._height;
+		var bpw = (bounding_mc._width-BoundingBox.CORNERSIZE)/image_mc._width; var bph = (bounding_mc._height-BoundingBox.CORNERSIZE)/image_mc._height;
+        
+        
+        
+        if (ih > iw) {
+           //portrait format
+           
+           if (ih+(PADDING*2) > Stage.height) {
+               var needed_zoom = (Stage.height-(PADDING*2))/ih;
+               image_mc.setZoomFactor(Math.round(needed_zoom*100));
+               blured_mc.setZoomFactor(Math.round(needed_zoom*100));
+           }
+           
+        } else {
+            //landscape format
+            
+            trace("landscape format");
+            
+            if (iw+(PADDING*2) > Stage.width) {
+               
+               var needed_zoom = (Stage.width-(PADDING*2))/iw;
+               image_mc.setZoomFactor(Math.round(needed_zoom*100));
+               blured_mc.setZoomFactor(Math.round(needed_zoom*100));
+               //trace(needed_zoom);
+            }
+            
+        }
+        
+        //center the whole crap
+        image_mc._x=(Stage.width/2)-(image_mc.getImageWidth()/2)
+        image_mc._y=(Stage.height/2)-(image_mc.getImageHeight()/2)
+        
+        blured_mc._x=image_mc._x;
+        blured_mc._y=image_mc._y;
+        
+        //apply the boundingbox percentage;
+		//bounding_mc.setX(image_mc._x+(image_mc._width*bpx));
+		//bounding_mc.setY(image_mc._y+(image_mc._height*bpy));
+		bounding_mc.setWidth(image_mc._width*bpw);
+		bounding_mc.setHeight(image_mc._height*bph);
+        bounding_mc.update();
+        updateMask();
+    }
+    
+    
+    /*
+        called when the user enters a new size into the textfields in the menu
+    
+    
+    public function onManualCropSizeChange(entered_width:Number, entered_height:Number) {
+        //trace("onManualSizeChange: " + width + " / " + height);
+        
+        if (Math.abs(image_mc.getRotation())==90) {
+            var width=entered_height;
+            var height=entered_width;
+        } else {
+            var height=entered_height;
+            var width=entered_width;
+        }
+        
+            //adjust width and height to image measures
+        
+        if (width > image_mc.original_width) width=image_mc.original_width;    
+    
+        if ((width*image_mc.getZoomFactor() + //bounding_mc.getX()) > image_mc.getImageWidth()) {
+            //bounding_mc.setX(image_mc.getImageWidth()-width*image_mc.getZoomFactor()+image_mc._x);
+        }
+        
+        if (height > image_mc.original_height) height=image_mc.original_height;    
+
+        if ((height*image_mc.getZoomFactor() + //bounding_mc.getY()) > image_mc.getImageHeight()) {
+            //bounding_mc.setY(image_mc.getImageHeight()-height*image_mc.getZoomFactor()+image_mc._y);
+        }
+        
+        //update the values displayed in the input form
+      //  this.ImageMenu.setCropSizeValues(width, height);
+        
+        output_w=width;
+        output_h=height;
+        
+        bounding_mc.setWidth(width*image_mc.getZoomFactor());
+        bounding_mc.setHeight(height*image_mc.getZoomFactor());
+        bounding_mc.update();
+        bounding_mc.setAspectForced(true);
+        
+        updateMask();
+    
+    }
+    
+    public function onManualOutputSizeChange(width:Number, height:Number) {
+        
+        
+        bounding_mc.setWidth(width);
+        bounding_mc.setHeight(height);
+        
+        bounding_mc.update();
+        updateMask();
+    }
+    */
+}


Property changes on: z3c.reference/branches/flash/flashsrc/ImageTool.as
___________________________________________________________________
Name: svn:executable
   + *

Added: z3c.reference/branches/flash/flashsrc/main.as
===================================================================
--- z3c.reference/branches/flash/flashsrc/main.as	                        (rev 0)
+++ z3c.reference/branches/flash/flashsrc/main.as	2007-08-28 12:35:57 UTC (rev 79306)
@@ -0,0 +1,37 @@
+Stage.align = "LT";
+Stage.scaleMode = "noScale";
+		
+		
+// Debug Block Start
+if (System.capabilities.playerType == "External"){
+    if (!_level0.url) _level0.url="testimage.jpg";
+    
+    //default values
+    if (!_level0.crop_x) _level0.crop_x = 100;
+    if (!_level0.crop_y) _level0.crop_y = 100;
+    if (!_level0.crop_w) _level0.crop_w = 100;
+    if (!_level0.crop_h) _level0.crop_h = 100;
+    if (!_level0.original_w) _level0.original_w = 600;
+    if (!_level0.original_h) _level0.original_h = 400;
+    //if (!_level0.output_w) _level0.output_w = 200;
+    //if (!_level0.output_h) _level0.output_h = 50;
+    if (!_level0.zoomfactor) _level0.zoomfactor=0.33;
+    if (!_level0.rotation) _level0.rotation=90;
+}
+// Debug Block End
+
+
+// create an instance of the z3c Image Tool
+var tool:ImageTool = ImageTool(_root.attachMovie("BaseClip","BaseClip", _root.getNextHighestDepth()));
+
+tool.setOutputSize(parseInt(_level0.output_w), parseInt(_level0.output_h));
+tool.setOriginalSize(parseInt(_level0.original_w), parseInt(_level0.original_h));
+tool.setCrop(parseInt(_level0.crop_x), parseInt(_level0.crop_y), parseInt(_level0.crop_w), parseInt(_level0.crop_h));
+tool.setUrl(_level0.url);
+tool.setRotation(parseInt(rotation)*-1); //PIL rotates opposite to flash
+tool.setOutputRatio(parseFloat(_level0.zoomfactor));
+tool.initialize();
+stop();
+
+
+

Added: z3c.reference/branches/flash/flashsrc/z3cimage.fla
===================================================================
(Binary files differ)


Property changes on: z3c.reference/branches/flash/flashsrc/z3cimage.fla
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream



More information about the Checkins mailing list