public
Description: Github flash badge
Homepage: http://spinach.andascarygoat.com/tags/badjo
Clone URL: git://github.com/zmack/badjo.git
Search Repo:
Picklebutton resizing
zmack (author)
Sat May 03 11:09:34 -0700 2008
commit  d78f7e67afd085e5a2d721e31665499ac9b129a8
tree    cb66efed8615d0e68443d5eff89ee058cc6c200a
parent  82f4b90a3d58e194eda814c0bbcec0529e7b0515
...
36
37
38
 
39
40
41
...
66
67
68
69
 
70
71
72
...
36
37
38
39
40
41
42
...
67
68
69
 
70
71
72
73
0
@@ -36,6 +36,7 @@
0
     public function GithubBadge() {
0
       var user:String;
0
       addExternalInterface();
0
+ trace(stage.height + ' -- ' + stage.width);
0
 
0
       try {
0
         user = getParams().gitUser;
0
@@ -66,7 +67,7 @@
0
       if ( _pl != null ) _pl.parent.removeChild(_pl);
0
       _pl = new ProjectList()
0
 
0
- _pl.setHeader({image: SpriteWrapper(loadAvatar('http://www.gravatar.com/avatar/' + MD5.hash(user.email) + '?s=40')), text: user.name });
0
+ _pl.setHeader({image: SpriteWrapper(loadAvatar('http://www.gravatar.com/avatar/' + MD5.hash(user.email || '') + '?s=40')), text: user.name || user.login });
0
       user.repositories.forEach( function(repo:Object, index:uint, arr:Array):void {
0
         _pl.addButton({image: SpriteWrapper(new GithubBadgeSkin.PublicProject()), text: repo.name });
0
       });
...
6
7
8
 
 
9
10
11
12
 
13
 
14
15
16
 
17
18
19
20
21
 
22
23
24
...
31
32
33
 
34
35
36
37
38
39
...
39
40
41
 
42
43
44
45
 
 
46
47
48
 
 
49
50
51
 
 
 
 
 
 
 
 
52
53
54
55
56
...
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
66
 
67
68
69
70
71
72
 
 
 
 
73
74
75
...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
37
38
39
40
41
42
43
44
45
46
...
46
47
48
49
50
51
52
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
111
112
113
114
115
116
117
118
119
120
121
122
123
124
0
@@ -6,19 +6,25 @@
0
   import flash.text.StyleSheet;
0
   
0
   public class PickleButton extends Sprite {
0
+ public static const NORMAL_COLOR:uint = 0xFF00FF;
0
+ public static const SELECTED_COLOR:uint = 0x0F00F0;
0
     public var text:String;
0
     public var itemWidth:Number;
0
     public var itemHeight:Number;
0
     public var padding:Number;
0
+ public var parentItem:Object;
0
 
0
+ private var _backgroundColor:uint;
0
     private var _image:Sprite;
0
     private var _textField:TextField;
0
     private var _style:StyleSheet;
0
+ private var _resizeHeight:uint;
0
 
0
     public function PickleButton(options:Object) {
0
       this.itemWidth = options.width || 200;
0
       this.padding = options.padding || 5;
0
 
0
+ this._backgroundColor = PickleButton.NORMAL_COLOR;
0
       this._image = options.image || new Sprite();
0
       this._textField = this.createTextField();
0
       this._textField.htmlText = '<p>' + (options.text || 'No text specified') + '</p>';
0
@@ -31,6 +37,7 @@
0
     }
0
 
0
     public function drawBackground(color:uint = 0xFF00FF):void {
0
+ color = this._backgroundColor;
0
       this.graphics.clear();
0
       this.graphics.beginFill(color, 0.4);
0
       this.graphics.drawRoundRect(0, 0, this.itemWidth, this.itemHeight, 15, 15);
0
0
0
0
@@ -39,16 +46,28 @@
0
     private function addEvents():void {
0
       this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
0
       this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
0
+ this.addEventListener(MouseEvent.CLICK, onClick);
0
     }
0
 
0
     private function onMouseOver(e:MouseEvent):void {
0
- this.drawBackground(0x0F00F0);
0
+ this._backgroundColor = PickleButton.SELECTED_COLOR;
0
+ this.drawBackground();
0
     }
0
 
0
     private function onMouseOut(e:MouseEvent):void {
0
+ trace("And we're out");
0
+ this._backgroundColor = PickleButton.NORMAL_COLOR;
0
       this.drawBackground();
0
     }
0
 
0
+ private function onClick(e:MouseEvent):void {
0
+ if ( this.itemHeight == 50 ) {
0
+ resizeTo();
0
+ } else {
0
+ resizeTo(50);
0
+ }
0
+ }
0
+
0
     private function createTextField():TextField {
0
       var text:TextField = new TextField();
0
       
0
0
0
@@ -62,14 +81,44 @@
0
       return text;
0
     }
0
 
0
+ private function redraw():void {
0
+ this.drawBackground();
0
+ }
0
+
0
+ private function resizeTo(height:uint = 0):void {
0
+ var item:PickleButton = this;
0
+ height ||= this.getBaseHeight();
0
+ this._resizeHeight = height;
0
+
0
+ if ( !this.hasEventListener(Event.ENTER_FRAME) ) {
0
+ this.addEventListener(Event.ENTER_FRAME, this.resizer);
0
+ trace("Added listener");
0
+ }
0
+ }
0
+
0
+ private function resizer(e:Event):void {
0
+ if ( this.itemHeight != this._resizeHeight ) {
0
+ this.itemHeight += ( (itemHeight < this._resizeHeight)? 2 : -2 );
0
+ this.drawBackground();
0
+ (this.parentItem as ProjectList).redraw();
0
+ } else {
0
+ this.removeEventListener(Event.ENTER_FRAME, this.resizer);
0
+ trace("Removed listener");
0
+ }
0
+ }
0
+
0
     private function resizeComponents():void {
0
- this.itemHeight = this._image.height + this.padding * 2;
0
+ this.itemHeight = this.getBaseHeight();
0
       this._textField.x = this._image.width + this.padding;
0
       this._textField.width = this.itemWidth - this._image.width - this.padding;
0
       this._textField.height = this.itemHeight - this.padding * 1;
0
 
0
       this._image.x = this.padding;
0
       this._image.y = this.padding;
0
+ }
0
+
0
+ private function getBaseHeight() {
0
+ return this._image.height + this.padding * 2;
0
     }
0
 
0
     private function createStyleSheet():StyleSheet {
...
9
10
11
12
 
 
13
14
15
...
23
24
25
 
26
27
28
29
...
35
36
37
 
 
 
 
 
 
 
 
 
38
39
40
 
 
41
42
43
...
62
63
64
65
66
67
68
...
9
10
11
 
12
13
14
15
16
...
24
25
26
27
28
29
30
31
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
51
52
53
54
55
...
74
75
76
 
77
78
79
0
@@ -9,7 +9,8 @@
0
     public var listWidth:Number;
0
     public var lateralPadding:Number = 5;
0
     public var bottomPadding:Number = 5;
0
-
0
+
0
+ private var _items:Array;
0
     private var _headerText:TextField;
0
     private var _mask:Sprite;
0
     private var _container:Sprite;
0
@@ -23,6 +24,7 @@
0
       this._maximum_y = 0;
0
       this.backgroundColor = 0x00FFD0;
0
       this.listWidth = 210;
0
+ this._items = new Array();
0
 
0
       addChild(this._mask);
0
       addChild(this._container);
0
0
@@ -35,9 +37,19 @@
0
       this.graphics.drawRoundRect(0, 0, this.listWidth, this._maximum_y + this.bottomPadding, 15, 15);
0
     }
0
 
0
+ public function redraw():void {
0
+ this._maximum_y = AVATAR_SIZE + this.bottomPadding;
0
+ this._items.forEach( function(item:PickleButton, index:uint, arr:Array):void {
0
+ this.positionButton(item);
0
+ this._maximum_y = item.y + item.height;
0
+ }, this);
0
+ this.drawBackground();
0
+ }
0
+
0
     public function addButton(options:Object):PickleButton {
0
       var button:PickleButton = new PickleButton(options);
0
-
0
+ button.parentItem = this;
0
+ this._items.push(button);
0
       this._container.addChild(button)
0
       this.positionButton(button);
0
 
0
@@ -62,7 +74,6 @@
0
       this._maximum_y = AVATAR_SIZE + this.bottomPadding;
0
       options.image.y = this.bottomPadding;
0
       options.image.x = this.lateralPadding;
0
-
0
     }
0
 
0
     private function positionButton(button:PickleButton):void {

Comments

    No one has commented yet.