| 1 | /** |
|---|
| 2 | * Display user interface management of the players MCV pattern. |
|---|
| 3 | * |
|---|
| 4 | * @author Jeroen Wijering |
|---|
| 5 | * @version 1.8 |
|---|
| 6 | **/ |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | import com.jeroenwijering.players.*; |
|---|
| 10 | import com.jeroenwijering.utils.*; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | class com.jeroenwijering.players.DisplayView extends AbstractView { |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | /** reference to the imageloader object **/ |
|---|
| 17 | private var imageLoader:ImageLoader; |
|---|
| 18 | /** Reference to the currently active item **/ |
|---|
| 19 | private var currentItem; |
|---|
| 20 | /** Reference to the currently active item **/ |
|---|
| 21 | private var itemSize:Array; |
|---|
| 22 | /** Reference to the currently active item **/ |
|---|
| 23 | private var thumbSize:Array; |
|---|
| 24 | /** Starting position of the players **/ |
|---|
| 25 | private var startPos:Array; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | /** Constructor **/ |
|---|
| 29 | function DisplayView(ctr:AbstractController,cfg:Object,fed:Object) { |
|---|
| 30 | super(ctr,cfg,fed); |
|---|
| 31 | Stage.addListener(this); |
|---|
| 32 | itemSize = new Array(config['displaywidth'],config['displayheight']); |
|---|
| 33 | thumbSize = new Array(config['displaywidth'],config['displayheight']); |
|---|
| 34 | var ref = this; |
|---|
| 35 | var tgt = config["clip"]; |
|---|
| 36 | imageLoader = new ImageLoader(tgt.display.thumb); |
|---|
| 37 | imageLoader.onLoadFinished = function() { |
|---|
| 38 | ref.thumbSize = new Array(this.targetClip._width, |
|---|
| 39 | this.targetClip._height); |
|---|
| 40 | ref.scaleClip(tgt.display.thumb,this.targetClip._width, |
|---|
| 41 | this.targetClip._height); |
|---|
| 42 | } |
|---|
| 43 | startPos = new Array(tgt._x,tgt._y); |
|---|
| 44 | setColorsClicks(); |
|---|
| 45 | setDimensions(); |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /** Sets up colors and clicks of all display items. **/ |
|---|
| 50 | private function setColorsClicks() { |
|---|
| 51 | var ref = this; |
|---|
| 52 | // background |
|---|
| 53 | var tgt = config["clip"].back; |
|---|
| 54 | tgt.col = new Color(tgt); |
|---|
| 55 | tgt.col.setRGB(config["backcolor"]); |
|---|
| 56 | // display items |
|---|
| 57 | tgt = config["clip"].display; |
|---|
| 58 | tgt.col = new Color(tgt.back); |
|---|
| 59 | tgt.col.setRGB(config["screencolor"]); |
|---|
| 60 | tgt.setMask(config["clip"].mask); |
|---|
| 61 | if(config["showicons"] == "false") { |
|---|
| 62 | tgt.playicon._visible = false; |
|---|
| 63 | tgt.muteicon._visible = false; |
|---|
| 64 | } |
|---|
| 65 | tgt.activity._visible = false; |
|---|
| 66 | tgt.link.tabEnabled = false; |
|---|
| 67 | if(config["autostart"] == "muted") { |
|---|
| 68 | tgt.link.onRelease = function() { |
|---|
| 69 | ref.sendEvent("volume",80); |
|---|
| 70 | ref.firstClick(); |
|---|
| 71 | }; |
|---|
| 72 | } else if (config["autostart"] == "false") { |
|---|
| 73 | tgt.muteicon._visible = false; |
|---|
| 74 | tgt.link.onRelease = function() { |
|---|
| 75 | ref.sendEvent("playpause"); |
|---|
| 76 | ref.firstClick(); |
|---|
| 77 | }; |
|---|
| 78 | } else { |
|---|
| 79 | ref.firstClick(); |
|---|
| 80 | } |
|---|
| 81 | if(config["logo"] != "undefined") { |
|---|
| 82 | var lll = new ImageLoader(tgt.logo,"none"); |
|---|
| 83 | lll.onLoadFinished = function() { |
|---|
| 84 | tgt.logo._x = ref.config["displaywidth"] - |
|---|
| 85 | tgt.logo._width - 10; |
|---|
| 86 | tgt.logo._y = 10; |
|---|
| 87 | }; |
|---|
| 88 | lll.loadImage(config["logo"]); |
|---|
| 89 | } |
|---|
| 90 | }; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | /** Sets up dimensions of all controlbar items. **/ |
|---|
| 94 | private function setDimensions() { |
|---|
| 95 | var tgt = config["clip"].back; |
|---|
| 96 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 97 | config["clip"]._x = config["clip"]._y = 0; |
|---|
| 98 | tgt._width = Stage.width; |
|---|
| 99 | tgt._height = Stage.height; |
|---|
| 100 | } else { |
|---|
| 101 | config["clip"]._x = startPos[0]; |
|---|
| 102 | config["clip"]._y = startPos[1]; |
|---|
| 103 | tgt._width = config["width"]; |
|---|
| 104 | tgt._height = config["height"]; |
|---|
| 105 | } |
|---|
| 106 | tgt = config["clip"].display; |
|---|
| 107 | scaleClip(tgt.thumb,thumbSize[0],thumbSize[1]); |
|---|
| 108 | scaleClip(tgt.image,itemSize[0],itemSize[1]); |
|---|
| 109 | scaleClip(tgt.video,itemSize[0],itemSize[1]); |
|---|
| 110 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 111 | tgt.youtube.setSize(Stage.width,Stage.height); |
|---|
| 112 | } else { |
|---|
| 113 | tgt.youtube.setSize(config['displaywidth'],config['displayheight']); |
|---|
| 114 | } |
|---|
| 115 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 116 | config["clip"].mask._width = |
|---|
| 117 | tgt.back._width = tgt.link._width = Stage.width; |
|---|
| 118 | config["clip"].mask._height = |
|---|
| 119 | tgt.back._height = tgt.link._height = Stage.height; |
|---|
| 120 | } else { |
|---|
| 121 | config["clip"].mask._width = |
|---|
| 122 | tgt.back._width = tgt.link._width = config["displaywidth"]; |
|---|
| 123 | config["clip"].mask._height = |
|---|
| 124 | tgt.back._height = tgt.link._height = config["displayheight"]; |
|---|
| 125 | } |
|---|
| 126 | tgt.playicon._x = tgt.activity._x = tgt.muteicon._x = |
|---|
| 127 | Math.round(tgt.back._width/2); |
|---|
| 128 | tgt.playicon._y = tgt.activity._y = tgt.muteicon._y = |
|---|
| 129 | Math.round(tgt.back._height/2); |
|---|
| 130 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 131 | tgt.playicon._xscale = tgt.playicon._yscale = |
|---|
| 132 | tgt.muteicon._xscale = tgt.muteicon._yscale = |
|---|
| 133 | tgt.activity._xscale = tgt.activity._yscale = 200; |
|---|
| 134 | tgt.logo._x = Stage.width - tgt.logo._width - 20; |
|---|
| 135 | tgt.logo._y = 20; |
|---|
| 136 | } else { |
|---|
| 137 | tgt.playicon._xscale = tgt.playicon._yscale = |
|---|
| 138 | tgt.muteicon._xscale = tgt.muteicon._yscale = |
|---|
| 139 | tgt.activity._xscale = tgt.activity._yscale = 100; |
|---|
| 140 | if(tgt.logo._height > 1) { |
|---|
| 141 | tgt.logo._x= config["displaywidth"]-tgt.logo._width -10; |
|---|
| 142 | tgt.logo._y = 10; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | }; |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | /** Show and hide the play/pause button and show activity icon **/ |
|---|
| 149 | private function setState(stt:Number) { |
|---|
| 150 | var tgt = config["clip"].display; |
|---|
| 151 | switch(stt) { |
|---|
| 152 | case 0: |
|---|
| 153 | if (config["linkfromdisplay"] == "false" && |
|---|
| 154 | config["showicons"] == "true") { |
|---|
| 155 | tgt.playicon._visible = true; |
|---|
| 156 | } |
|---|
| 157 | tgt.activity._visible = false; |
|---|
| 158 | break; |
|---|
| 159 | case 1: |
|---|
| 160 | tgt.playicon._visible = false; |
|---|
| 161 | if (config["showicons"] == "true" && feeder.feed[currentItem]['type'] != 'youtube') { |
|---|
| 162 | tgt.activity._visible = true; |
|---|
| 163 | } |
|---|
| 164 | break; |
|---|
| 165 | case 2: |
|---|
| 166 | tgt.playicon._visible = false; |
|---|
| 167 | tgt.activity._visible = false; |
|---|
| 168 | break; |
|---|
| 169 | } |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | /** save size information and rescale accordingly **/ |
|---|
| 174 | private function setSize(wid:Number,hei:Number) { |
|---|
| 175 | itemSize = new Array (wid,hei); |
|---|
| 176 | var tgt = config["clip"].display; |
|---|
| 177 | scaleClip(tgt.image,itemSize[0],itemSize[1]); |
|---|
| 178 | scaleClip(tgt.video,itemSize[0],itemSize[1]); |
|---|
| 179 | tgt.youtube.setSize(config['displaywidth'],config['displayheight']); |
|---|
| 180 | }; |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | /** Scale movie according to overstretch setting **/ |
|---|
| 184 | private function scaleClip(tgt:MovieClip,wid:Number,hei:Number):Void { |
|---|
| 185 | var tcf = tgt.mc._currentframe; |
|---|
| 186 | tgt.mc.gotoAndStop(1); |
|---|
| 187 | var stw = config["displaywidth"]; |
|---|
| 188 | var sth = config["displayheight"]; |
|---|
| 189 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 190 | stw = Stage.width; |
|---|
| 191 | sth = Stage.height; |
|---|
| 192 | } |
|---|
| 193 | var xsr = stw/wid; |
|---|
| 194 | var ysr = sth/hei; |
|---|
| 195 | var mxm = Math.max(xsr,ysr); |
|---|
| 196 | if ((Math.abs(xsr-ysr)/mxm < 0.1 && config["overstretch"] != "none") |
|---|
| 197 | || config["overstretch"] == "fit") { |
|---|
| 198 | tgt._width = stw; |
|---|
| 199 | tgt._height = sth; |
|---|
| 200 | } else if (xsr < ysr && config["overstretch"] == "false" || |
|---|
| 201 | ysr < xsr && config["overstretch"] == "true") { |
|---|
| 202 | tgt._width = wid*xsr; |
|---|
| 203 | tgt._height = hei*xsr; |
|---|
| 204 | } else if(config["overstretch"] == "none") { |
|---|
| 205 | tgt._width = wid; |
|---|
| 206 | tgt._height = hei; |
|---|
| 207 | } else { |
|---|
| 208 | tgt._width = wid*ysr; |
|---|
| 209 | tgt._height = hei*ysr; |
|---|
| 210 | } |
|---|
| 211 | tgt._x = stw/2 - tgt._width/2; |
|---|
| 212 | tgt._y = sth/2 - tgt._height/2; |
|---|
| 213 | tgt.mc.gotoAndPlay(tcf); |
|---|
| 214 | }; |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | /** Load Thumbnail image if available. **/ |
|---|
| 218 | private function setItem(idx:Number) { |
|---|
| 219 | currentItem = idx; |
|---|
| 220 | var tgt = config["clip"].display; |
|---|
| 221 | if(feeder.feed[idx]["image"] == "undefined") { |
|---|
| 222 | tgt.thumb.clear(); |
|---|
| 223 | tgt.thumb._visible = false; |
|---|
| 224 | } else { |
|---|
| 225 | imageLoader.loadImage(feeder.feed[idx]["image"]); |
|---|
| 226 | tgt.thumb._visible = true; |
|---|
| 227 | } |
|---|
| 228 | }; |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | /** OnResize Handler: catches stage resizing **/ |
|---|
| 232 | public function onResize() { |
|---|
| 233 | if(config['displayheight'] >= config["height"]) { |
|---|
| 234 | config["height"] = config["displayheight"] = Stage.height; |
|---|
| 235 | if(config['displaywidth'] == config["width"]) { |
|---|
| 236 | config["displaywidth"] = Stage.width; |
|---|
| 237 | } |
|---|
| 238 | config["width"] = Stage.width; |
|---|
| 239 | } |
|---|
| 240 | setDimensions(); |
|---|
| 241 | }; |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | /** Catches fullscreen escape **/ |
|---|
| 245 | public function onFullScreen(fs:Boolean) { |
|---|
| 246 | if(fs == false) { setDimensions(); } |
|---|
| 247 | }; |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | /** Catches the first display click to reset unmute / displayclick **/ |
|---|
| 251 | private function firstClick() { |
|---|
| 252 | var ref = this; |
|---|
| 253 | var tgt = config["clip"].display; |
|---|
| 254 | tgt.playicon._visible = false; |
|---|
| 255 | tgt.muteicon._visible = false; |
|---|
| 256 | if(config["linkfromdisplay"] == "true") { |
|---|
| 257 | tgt.link.onRelease = function() { |
|---|
| 258 | ref.sendEvent("getlink",ref.currentItem); |
|---|
| 259 | }; |
|---|
| 260 | } else { |
|---|
| 261 | tgt.link.onRelease = function() { |
|---|
| 262 | ref.sendEvent("playpause",1); |
|---|
| 263 | }; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | }; |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | } |
|---|