source: trunk/as3/com/jeroenwijering/views/PlaylistView.as @ 1

Revision 1, 5.1 KB checked in by jeroen, 5 years ago (diff)

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Display a searchbar and direct the search externally.
3**/
4package com.jeroenwijering.views {
5
6
7import com.jeroenwijering.events.*;
8import com.jeroenwijering.player.View;
9import com.jeroenwijering.views.PlaylistButton;
10import com.jeroenwijering.utils.Draw;
11import flash.display.MovieClip;
12import flash.events.MouseEvent;
13import flash.geom.Rectangle;
14import flash.utils.setInterval;
15import flash.utils.clearInterval;
16
17
18public class PlaylistView {
19
20
21        /** Reference to the view. **/
22        private var view:View;
23        /** Reference to the playlist MC. **/
24        private var clip:MovieClip;
25        /** Array with all button instances **/
26        private var buttons:Array;
27        /** Height of a button (to calculate scrolling) **/
28        private var buttonsize:Number;
29        /** Proportion between clip and mask. **/
30        private var proportion:Number;
31        /** Interval ID for scrolling **/
32        private var scrollInterval:Number;
33
34
35        public function PlaylistView(vie:View) {
36                view = vie;
37                clip = view.skin['playlist'];
38                clip.visible = false;
39                view.addControllerListener(ControllerEvent.ITEM,itemHandler);
40                view.addControllerListener(ControllerEvent.PLAYLIST,playlistHandler);
41                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler);
42                var btn = clip.scrollClip.getChildByName('button');
43                buttonsize = btn.height;
44                clip.scrollClip.removeChild(btn);
45                clip.scrollClip.mask = clip.scrollMask;
46                clip.scrollBar.buttonMode = true;
47                clip.scrollBar.mouseChildren = false;
48                clip.scrollBar.addEventListener(MouseEvent.MOUSE_DOWN,startHandler);
49                view.skin.addEventListener(MouseEvent.MOUSE_UP,stopHandler);
50        };
51
52
53        /** Setup all buttons in the playlist **/
54        private function buildList(clr:Boolean) {
55                var wid = clip.back.width;
56                var hei = clip.back.height;
57                proportion = view.playlist.length*buttonsize/hei;
58                if (proportion > 1) {
59                        wid -=20;
60                        buildScroller();
61                } else {
62                        clip.scrollBar.visible = false;
63                }
64                clip.scrollMask.height = hei;
65                clip.scrollMask.width = wid;
66                if(clr) {
67                        clip.scrollClip.y = 0;
68                        Draw.clear(clip.scrollClip);
69                        buttons = new Array();
70                }
71                for(var i=0; i<view.playlist.length; i++) {
72                        if(clr) {
73                                var btn = new PlaylistButton(i,wid,view);
74                                clip.scrollClip.addChild(btn);
75                                buttons.push(btn);
76                        } else {
77                                buttons[i].resize(wid);
78                                if(proportion > 1) {
79                                        scrollCheck();
80                                }
81                        }
82                }
83        };
84
85
86        /** Setup the scrollbar component **/
87        private function buildScroller() {
88                var scr = clip.scrollBar;
89                scr.visible = true;
90                scr.x = clip.back.width - scr.width;
91                var dif = clip.back.height - scr.height;
92                scr.back.height += dif;
93                scr.rail.height += dif;
94                scr.icon.height = Math.round(scr.rail.height/proportion);
95        };
96
97
98        /** Switch the currently active item */
99        private function itemHandler(evt:ControllerEvent) {
100                // code for highlighting a certain button.
101        };
102
103
104        /** New playlist loaded: rebuild the playclip. **/
105        private function playlistHandler(evt:ControllerEvent) {
106                buildList(true);
107        };
108
109
110        /** Process resizing requests **/
111        private function resizeHandler(evt:ControllerEvent) {
112                if(view.config['playlist'] == 'right') {
113                        clip.visible = true;
114                        clip.x = evt.data.width;
115                        clip.y = 0;
116                        clip.back.width = view.config['playlistsize'];
117                        clip.back.height = evt.data.height;
118                } else if (view.config['playlist'] == 'below') {
119                        clip.visible = true;
120                        clip.x = 0;
121                        clip.y = evt.data.height;
122                        if (view.config['controlbar'] == 'below') {
123                                clip.y += view.config['controlbarsize'];
124                        }
125                        clip.back.height = view.config['playlistsize'];
126                        clip.back.width = evt.data.width;
127                } else if (view.config['playlist'] == 'above') {
128                        clip.visible = true;
129                        var wid = evt.data.width-2*view.config['controlbarsize'];
130                        var hei = evt.data.height-2*view.config['controlbarsize'];
131                        if(evt.data.width > 640) { wid = 600; }
132                        if(view.config['controlbar'] == 'above') { hei -= 2*view.config['controlbarsize']; }
133                        clip.x = Math.round(evt.data.width/2 - wid/2);
134                        clip.y = view.config['controlbarsize'];
135                        clip.back.height = hei;
136                        clip.back.width = wid;
137                } else {
138                        clip.visible = false;
139                }
140                buildList(false);
141        };
142
143
144        /** Make sure the playlist is not out of range. **/
145        private function scrollCheck() {
146                var scr = clip.scrollBar;
147                if(clip.scrollClip.y > 0) {
148                        clip.scrollClip.y = 0;
149                        scr.icon.y = scr.rail.y;
150                } else if (clip.scrollClip.y < clip.scrollMask.height-clip.scrollClip.height) {
151                        scr.icon.y = scr.rail.y+scr.rail.height-scr.icon.height;
152                        clip.scrollClip.y = clip.scrollMask.height-clip.scrollClip.height;
153                }
154        };
155
156
157        /** Scrolling handler. **/
158        private function scrollHandler() {
159                var scr = clip.scrollBar;
160                var yps = scr.mouseY;
161                var ips = yps - scr.icon.height/2;
162                var cps = clip.scrollMask.y+clip.scrollMask.height/2-proportion*yps;
163                scr.icon.y = Math.round(ips - (ips-scr.icon.y)/1.5);
164                clip.scrollClip.y = Math.round((cps - (cps-clip.scrollClip.y)/1.5));
165                scrollCheck();
166        };
167
168
169        /** Start scrolling the playlist. **/
170        private function startHandler(evt:MouseEvent) {
171                clearInterval(scrollInterval);
172                scrollHandler();
173                scrollInterval = setInterval(scrollHandler,50);
174        };
175
176
177        /** Stop scrolling the playlist. **/
178        private function stopHandler(evt:MouseEvent) {
179                clearInterval(scrollInterval);
180        };
181
182
183
184
185};
186
187
188}
Note: See TracBrowser for help on using the repository browser.