Permalink
Browse files

ImageGallery working prototype

  • Loading branch information...
1 parent 6c7f4d2 commit c566ca7d88285c4e679d46733c6cf55270b4a4c2 @mstandio committed Aug 17, 2012
View
@@ -52,6 +52,7 @@
<!-- SWC Libraries -->
<libraryPaths>
<element path="lib\tweener.swc" />
+ <element path="lib\GIFPlayer-0.6.swc" />
<element path="testlib\flexunit-4.0.0.swc" />
<element path="testlib\flexunit-uilistener-4.0.0.swc" />
<element path="testlib\hamcrest-1.0.2.swc" />
@@ -12,15 +12,15 @@
</panoramas>
<modules>
<ImageGallery path="~modules/imagegallery/ImageGallery-1.0.swf">
- <window align="horizontal:center,vertical:middle"/>
+ <window align="horizontal:center,vertical:middle" alpha="0.5"/>
<close path="~media/images/misc/close.png" move="vertical:-10,horizontal:10"/>
- <viewer path="~modules/imagegallery/images/buttons_dark_40x40.png"/>
+ <viewer path="~modules/imagegallery/images/buttons_dark_40x40.png" throbber="~media/images/misc/throbber-circles.gif"/>
<groups>
<group id="g1">
<image path="~media/images/maps/map1.jpg"/>
<image path="~media/images/maps/map2.jpg"/>
- <image path="~media/thumbs/kiev.jpg"/>
- <image path="~media/thumbs/park.jpg"/>
+ <image path="~media/images/thumbs/kiev.jpg"/>
+ <image path="~media/images/thumbs/park.jpg"/>
</group>
<group id="g2">
<image path="~media/thumbs/kiev.jpg"/>
View
Binary file not shown.
@@ -0,0 +1,142 @@
+/*
+Copyright 2012 Marek Standio.
+
+This file is part of SaladoPlayer.
+
+SaladoPlayer is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License,
+or (at your option) any later version.
+
+SaladoPlayer is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty
+of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with SaladoPlayer. If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.panozona.modules.imagegallery.controller {
+
+ import com.panozona.modules.imagegallery.events.ImageEvent;
+ import com.panozona.modules.imagegallery.events.ViewerEvent;
+ import com.panozona.modules.imagegallery.events.WindowEvent;
+ import com.panozona.modules.imagegallery.model.structure.Image;
+ import com.panozona.modules.imagegallery.view.ImageView;
+ import com.panozona.player.module.data.property.Size;
+ import com.panozona.player.module.Module;
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.DisplayObject;
+ import flash.display.Loader;
+ import flash.display.LoaderInfo;
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.events.TimerEvent;
+ import flash.net.URLRequest;
+ import flash.utils.Timer;
+
+ public class ImageController {
+
+ private var imageLoader:Loader;
+ private var displayObject:DisplayObject;
+ private var displayObjectInitSize:Size;
+
+ private var _imageView:ImageView;
+ private var _module:Module;
+ private var _throbberDelayTimer:Timer;
+
+ public function ImageController(imageView:ImageView, module:Module) {
+ _imageView = imageView;
+ _module = module;
+
+ _imageView.imagegalleryData.viewerData.addEventListener(ViewerEvent.CHANGED_CURRENT_IMAGE_INDEX, handleCurrentImageIndexChange, false, 0, true);
+ _imageView.imagegalleryData.windowData.addEventListener(WindowEvent.CHANGED_CURRENT_SIZE, handleWindowSizeChange, false, 0, true);
+ _imageView.imagegalleryData.imageData.addEventListener(ImageEvent.CHANGED_MAX_SIZE, handleMaxSizeChange, false, 0, true);
+
+ imageLoader = new Loader();
+ imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imageLost, false, 0, true);
+ imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded, false, 0, true);
+
+ if (_imageView.imagegalleryData.viewerData.viewer.throbber != null ) {
+ _throbberDelayTimer = new Timer(500, 1);
+ _throbberDelayTimer.addEventListener(TimerEvent.TIMER, timesUp, false, 0, true);
+ }
+ }
+
+ private function imageLost(e:IOErrorEvent):void {
+ if (_imageView.imagegalleryData.viewerData.viewer.throbber != null) {
+ _throbberDelayTimer.stop();
+ }
+ _module.printError("Could not load image: " + e.text);
+ _imageView.imagegalleryData.imageData.isShowingThrobber = false;
+ }
+
+ private function imageLoaded(e:Event):void {
+ if (_imageView.imagegalleryData.viewerData.viewer.throbber != null) {
+ _throbberDelayTimer.stop();
+ }
+ _imageView.imagegalleryData.imageData.isShowingThrobber = false;
+ displayObject = imageLoader.content;
+ if (displayObject is Bitmap) {
+ (displayObject as Bitmap).smoothing = true;
+ }
+ while (_imageView.numChildren) {
+ _imageView.removeChildAt(0);
+ }
+ displayObjectInitSize = new Size(displayObject.width, displayObject.height);
+ _imageView.addChild(displayObject);
+ handleWindowSizeChange();
+ }
+
+ private function handleCurrentImageIndexChange(e:Event = null):void {
+ if (_imageView.imagegalleryData.viewerData.viewer.throbber != null) {
+ _throbberDelayTimer.reset();
+ _throbberDelayTimer.start();
+ }
+ imageLoader.unload();
+ var path:String = _imageView.imagegalleryData.viewerData.getGroupById(
+ _imageView.imagegalleryData.viewerData.currentGroupId).getChildrenOfGivenClass(Image)
+ [_imageView.imagegalleryData.viewerData.currentImageIndex].path;
+ imageLoader.load(new URLRequest(path));
+ }
+ private function timesUp(e:Event):void {
+ _imageView.imagegalleryData.imageData.isShowingThrobber = true;
+ }
+
+ private function handleWindowSizeChange(event:Event = null):void {
+ if (displayObject == null) {
+ return;
+ }
+ var maxSize:Size = new Size(_imageView.imagegalleryData.windowData.currentSize.width - 20,
+ _imageView.imagegalleryData.windowData.currentSize.height - 20);
+ if (displayObjectInitSize.width <= maxSize.width && displayObjectInitSize.height <= maxSize.height ) {
+ displayObject.scaleX = displayObject.scaleY = 1;
+ } else {
+ if (maxSize.width > maxSize.height) {
+ if (displayObjectInitSize.width < (displayObjectInitSize.height)) {
+ displayObject.scaleX = maxSize.width / displayObjectInitSize.width;
+ displayObject.scaleY = displayObject.scaleX;
+ } else {
+ displayObject.scaleY = maxSize.height / displayObjectInitSize.height
+ displayObject.scaleX = displayObject.scaleY;
+ }
+ } else {
+ if (displayObjectInitSize.width > (displayObjectInitSize.height)) {
+ displayObject.scaleX = maxSize.width / displayObjectInitSize.width;
+ displayObject.scaleY = displayObject.scaleX;
+ } else {
+ displayObject.scaleY = maxSize.height / displayObjectInitSize.height
+ displayObject.scaleX = displayObject.scaleY;
+ }
+ }
+ }
+ displayObject.x = (_imageView.imagegalleryData.windowData.currentSize.width - displayObject.width) * 0.5
+ displayObject.y = (_imageView.imagegalleryData.windowData.currentSize.height - displayObject.height) * 0.5
+ }
+
+ private function handleMaxSizeChange(event:Event = null):void {
+
+ }
+ }
+}
@@ -18,6 +18,7 @@ along with SaladoPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package com.panozona.modules.imagegallery.controller {
+ import com.panozona.modules.imagegallery.events.ImageEvent;
import com.panozona.modules.imagegallery.events.ViewerEvent;
import com.panozona.modules.imagegallery.events.WindowEvent;
import com.panozona.modules.imagegallery.model.ButtonData;
@@ -37,6 +38,7 @@ package com.panozona.modules.imagegallery.controller {
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
+ import org.bytearray.gif.player.GIFPlayer;
public class ViewerController {
@@ -47,7 +49,7 @@ package com.panozona.modules.imagegallery.controller {
private var buttonPrevController:ButtonController;
private var buttonNextController:ButtonController;
- private var imageLoader:Loader;
+ private var imageController:ImageController;
private var _viewerView:ViewerView;
private var _module:Module;
@@ -57,31 +59,35 @@ package com.panozona.modules.imagegallery.controller {
_viewerView = viewerView;
buttonSize = new Size(30,30);
-
buttonControllers = new Vector.<ButtonController>();
+ imageController = new ImageController(_viewerView.imageView, _module);
+
_viewerView.buttonPrev.buttonData.onRelease = getImageIndexIncrementer(-1);
_viewerView.buttonNext.buttonData.onRelease = getImageIndexIncrementer(1);
buttonPrevController = new ButtonController(_viewerView.buttonPrev, _module);
buttonNextController = new ButtonController(_viewerView.buttonNext, _module);
- imageLoader = new Loader();
- imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imageLost, false, 0, true);
- imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded, false, 0, true);
-
_viewerView.imagegalleryData.viewerData.addEventListener(ViewerEvent.CHANGED_CURRENT_GROUP_ID, handleCurrentGroupIdChange, false, 0, true);
_viewerView.imagegalleryData.viewerData.addEventListener(ViewerEvent.CHANGED_CURRENT_IMAGE_INDEX, handleCurrentImageIndexChange, false, 0, true);
_viewerView.imagegalleryData.windowData.addEventListener(WindowEvent.CHANGED_CURRENT_SIZE, handleWindowSizeChange, false, 0, true);
- handleWindowSizeChange();
-
var panoramaEventClass:Class = ApplicationDomain.currentDomain.getDefinition("com.panozona.player.manager.events.PanoramaEvent") as Class;
_module.saladoPlayer.manager.addEventListener(panoramaEventClass.PANORAMA_LOADED, onPanoramaLoaded, false, 0, true);
var buttonsLoader:Loader = new Loader();
buttonsLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, buttonsImageLost, false, 0, true);
buttonsLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, buttonsImageLoaded, false, 0, true);
buttonsLoader.load(new URLRequest(_viewerView.imagegalleryData.viewerData.viewer.path));
+
+ if (_viewerView.imagegalleryData.viewerData.viewer.throbber != null) {
+ _viewerView.imagegalleryData.imageData.addEventListener(ImageEvent.CHANGED_IS_THROBBER_SHOWING, handleThrobberShowingChange, false, 0, true);
+ _viewerView.gifPlayer.addEventListener(IOErrorEvent.IO_ERROR, throbberLost, false, 0, true);
+ _viewerView.gifPlayer.addEventListener(Event.COMPLETE, throbberLoaded, false, 0, true);
+ _viewerView.gifPlayer.load(new URLRequest(_viewerView.imagegalleryData.viewerData.viewer.throbber));
+ }
+
+ handleWindowSizeChange();
}
private function onPanoramaLoaded(loadPanoramaEvent:Object):void {
@@ -93,7 +99,7 @@ package com.panozona.modules.imagegallery.controller {
}
private function buttonsImageLost(e:IOErrorEvent):void {
- (e.target as LoaderInfo).removeEventListener(IOErrorEvent.IO_ERROR, buttonsImageLost);
+ (e.target as org.bytearray.gif.player.GIFPlayer).removeEventListener(IOErrorEvent.IO_ERROR, buttonsImageLost);
(e.target as LoaderInfo).removeEventListener(Event.COMPLETE, buttonsImageLoaded);
_module.printError(e.text);
}
@@ -107,12 +113,13 @@ package com.panozona.modules.imagegallery.controller {
buttonSize.height = Math.ceil((buttonsBitmapData.height - 1) / 2);
if (_viewerView.imagegalleryData.viewerData.currentGroupId != null) {
updateButtonsBar();
- updateButtonBarSelection();
+ handleCurrentImageIndexChange();
}
_viewerView.buttonPrev.bitmapDataPlain = getButtonBitmap(0);
_viewerView.buttonPrev.bitmapDataActive = getButtonBitmap(2);
_viewerView.buttonNext.bitmapDataPlain = getButtonBitmap(0);
_viewerView.buttonNext.bitmapDataActive = getButtonBitmap(2);
+ handleWindowSizeChange();
}
private function getImageIndexIncrementer(value:Number):Function {
@@ -121,6 +128,26 @@ package com.panozona.modules.imagegallery.controller {
}
}
+ private function throbberLost(e:IOErrorEvent):void {
+ (e.target as GIFPlayer).removeEventListener(IOErrorEvent.IO_ERROR, throbberLost);
+ (e.target as GIFPlayer).removeEventListener(Event.COMPLETE, throbberLoaded);
+ }
+
+ private function throbberLoaded(e:Event):void {
+ (e.target as GIFPlayer).removeEventListener(IOErrorEvent.IO_ERROR, throbberLost);
+ (e.target as GIFPlayer).removeEventListener(Event.COMPLETE, throbberLoaded);
+ handleWindowSizeChange();
+ handleThrobberShowingChange();
+ }
+
+ private function handleThrobberShowingChange(e:Event=null):void {
+ if (_viewerView.imagegalleryData.imageData.isShowingThrobber) {
+ _viewerView.throbberStart()
+ } else {
+ _viewerView.throbberStop();
+ }
+ }
+
private function incrementImageIndex(value:Number):void {
var imagesNumber:Number = _viewerView.imagegalleryData.viewerData.getGroupById(
_viewerView.imagegalleryData.viewerData.currentGroupId).getChildrenOfGivenClass(Image).length;
@@ -140,9 +167,19 @@ package com.panozona.modules.imagegallery.controller {
}
private function handleCurrentGroupIdChange(e:Event):void {
- if (buttonsBitmapData != null) {
- buildButtonsBar();
- updateButtonsBar();
+ if (_viewerView.imagegalleryData.viewerData.getGroupById(_viewerView.imagegalleryData.viewerData.currentGroupId)
+ .getChildrenOfGivenClass(Image).length > 1) {
+ if (buttonsBitmapData != null) {
+ _viewerView.buttonBar.visible = true;
+ _viewerView.buttonPrev.visible = true;
+ _viewerView.buttonNext.visible = true;
+ buildButtonsBar();
+ updateButtonsBar();
+ }
+ } else {
+ _viewerView.buttonBar.visible = false;
+ _viewerView.buttonPrev.visible = false;
+ _viewerView.buttonNext.visible = false;
}
_viewerView.imagegalleryData.viewerData.currentImageIndex = 0;
}
@@ -200,16 +237,7 @@ package com.panozona.modules.imagegallery.controller {
return bmd;
}
- private function handleCurrentImageIndexChange(e:Event):void {
- updateButtonBarSelection();
- imageLoader.unload();
- var path:String = _viewerView.imagegalleryData.viewerData.getGroupById(
- _viewerView.imagegalleryData.viewerData.currentGroupId).getChildrenOfGivenClass(Image)
- [_viewerView.imagegalleryData.viewerData.currentImageIndex].path;
- //imageLoader.load(new URLRequest(path));
- }
-
- private function updateButtonBarSelection():void {
+ private function handleCurrentImageIndexChange(e:Event = null):void {
for ( var i:int = 0; i < _viewerView.buttonBar.numChildren; i++) {
var buttonView:ButtonView = _viewerView.buttonBar.getChildAt(i) as ButtonView;
if (buttonView.buttonData.imageIndex == _viewerView.imagegalleryData.viewerData.currentImageIndex) {
@@ -226,21 +254,17 @@ package com.panozona.modules.imagegallery.controller {
_viewerView.graphics.drawRect(0, 0, _viewerView.imagegalleryData.windowData.currentSize.width, _viewerView.imagegalleryData.windowData.currentSize.height);
_viewerView.graphics.endFill();
- _viewerView.buttonPrev.x = buttonSize.width * 1.5;
- _viewerView.buttonNext.x = _viewerView.imagegalleryData.windowData.currentSize.width - buttonSize.width * 1.5
+ _viewerView.buttonPrev.x = buttonSize.width * 1.25;
+ _viewerView.buttonNext.x = _viewerView.imagegalleryData.windowData.currentSize.width - buttonSize.width * 1.25
_viewerView.buttonPrev.y = (_viewerView.imagegalleryData.windowData.currentSize.height - buttonSize.height) * 0.5;
_viewerView.buttonNext.y = _viewerView.buttonPrev.y;
_viewerView.buttonPrev.rotationY = 180;
_viewerView.buttonBar.x = (_viewerView.imagegalleryData.windowData.currentSize.width - _viewerView.buttonBar.width) * 0.5;
- _viewerView.buttonBar.y = _viewerView.imagegalleryData.windowData.currentSize.height - buttonSize.height * 1.5;
- }
-
- private function imageLost(e:IOErrorEvent):void {
- _module.printError("Could not load image: " + e.text);
- }
-
- private function imageLoaded(e:Event):void {
- //view.addChildAt((e.target as LoaderInfo).content, 0);
+ _viewerView.buttonBar.y = _viewerView.imagegalleryData.windowData.currentSize.height - buttonSize.height * 1.25;
+ if (_viewerView.imagegalleryData.viewerData.viewer.throbber) {
+ _viewerView.gifPlayer.x = (_viewerView.imagegalleryData.windowData.currentSize.width - _viewerView.gifPlayer.width) * 0.5;
+ _viewerView.gifPlayer.y = (_viewerView.imagegalleryData.windowData.currentSize.height - _viewerView.gifPlayer.height) * 0.5;
+ }
}
}
}
@@ -0,0 +1,32 @@
+/*
+Copyright 2012 Marek Standio.
+
+This file is part of SaladoPlayer.
+
+SaladoPlayer is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published
+by the Free Software Foundation, either version 3 of the License,
+or (at your option) any later version.
+
+SaladoPlayer is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty
+of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with SaladoPlayer. If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.panozona.modules.imagegallery.events{
+
+ import flash.events.Event;
+
+ public class ImageEvent extends Event {
+
+ public static const CHANGED_MAX_SIZE:String = "chngdMaxSize";
+ public static const CHANGED_IS_THROBBER_SHOWING:String = "chngdThrShow";
+
+ public function ImageEvent( type:String) {
+ super(type);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit c566ca7

Please sign in to comment.