source: trunk/as3/com/jeroenwijering/utils/Stretcher.as @ 210

Revision 210, 1.7 KB checked in by jeroen, 4 years ago (diff)

added a dock feature and hooks for it in the cc,ad,hd plugins. also added a title to the playbutton and colorization of display icons.

Line 
1/**
2* Simple class that handles stretching of displayelements.
3**/
4package com.jeroenwijering.utils {
5
6
7import flash.display.DisplayObject;
8
9
10public class Stretcher {
11
12
13        /** Stretches the clip nonuniform to fit the container. **/
14        public static var EXACTFIT:String = "exactfit";
15        /** Stretches the clip uniform to fill the container, with parts being cut off. **/
16        public static var FILL:String = "fill";
17        /** No stretching, but the clip is placed in the center of the container. **/
18        public static var NONE:String = "none";
19        /** Stretches the clip uniform to fit the container, with bars added. **/
20        public static var UNIFORM:String = "uniform";
21
22
23        /**
24        * Resize a displayobject to the display, depending on the stretching.
25        *
26        * @param clp    The display element to resize.
27        * @param wid    The target width.
28        * @param hei    The target height.
29        * @param typ    The stretching type.
30 *      **/
31        public static function stretch(clp:DisplayObject,wid:Number,hei:Number,typ:String='uniform'):void {
32                var xsc:Number = wid/clp.width;
33                var ysc:Number = hei/clp.height;
34                switch(typ.toLowerCase()) {
35                        case 'exactfit':
36                                clp.width = wid;
37                                clp.height = hei;
38                                break;
39                        case 'fill':
40                                if(xsc > ysc) {
41                                        clp.width *= xsc;
42                                        clp.height *= xsc;
43                                } else {
44                                        clp.width *= ysc;
45                                        clp.height *= ysc;
46                                }
47                                break;
48                        case 'none':
49                                clp.scaleX = 1;
50                                clp.scaleY = 1;
51                                break;
52                        case 'uniform':
53                        default:
54                                if(xsc > ysc) {
55                                        clp.width *= ysc;
56                                        clp.height *= ysc;
57                                } else {
58                                        clp.width *= xsc;
59                                        clp.height *= xsc;
60                                }
61                                break;
62                }
63                clp.x = Math.round(wid/2 - clp.width/2);
64                clp.y = Math.round(hei/2 - clp.height/2);
65                clp.width = Math.ceil(clp.width);
66                clp.height = Math.ceil(clp.height);
67        };
68
69}
70
71
72}
Note: See TracBrowser for help on using the repository browser.