/// <summary>
        /// Constructor for a LayoutManager instance.
        /// </summary>
        /// <param name="pTarget">Target canvas which will hold all photo slices and this manager will take effect on.</param>
        /// <param name="pDataSource">Data source for this manager instance.</param>
        /// <param name="pBtnSortCanvas">Sort layout trigger canvas.</param>
        /// <param name="pBtnRandomCanvas">Random layout trigger canvas.</param>
        /// <param name="pZoomOutTrigger">Zoomout trigter canvas.</param>
        /// <param name="pSortNavi">Sort navigator.</param>
        public LayoutManager(Canvas pTarget, PhotoDataSet pDataSource, Canvas pBtnSortCanvas, Canvas pBtnRandomCanvas, Canvas pZoomOutTrigger, SortNavigator pSortNavi, GenuineSlice pGenuineSlice, TracingIcon pTracingIcon, Image pScreenArrowLeft, Image pScreenArrowRight)
        {
            _target           = pTarget;
            _targetShadow     = pTarget.FindName("PhotoHolderShadow") as Canvas;
            _sortNavi         = pSortNavi;
            _dataSource       = pDataSource;
            _zoomOutTrigger   = pZoomOutTrigger;
            _btnSort          = pBtnSortCanvas;
            _btnSort.Cursor   = Cursors.Hand;
            _btnRandom        = pBtnRandomCanvas;
            _btnRandom.Cursor = Cursors.Hand;
            _genuineSlice     = pGenuineSlice;
            _isSliceRequest   = false;
            _tracingMouse     = pTracingIcon;
            _screenArrowLeft  = pScreenArrowLeft;
            _screenArrowRight = pScreenArrowRight;

            // Generate random & sort params
            GenerateLayoutPostion();
            // Fill thums to thumHolder
            FillThumHolder();

            // Event register.
            _target.MouseLeftButtonUp         += new MouseEventHandler(_target_MouseLeftButtonUp);
            _zoomOutTrigger.MouseLeftButtonUp += new MouseEventHandler(_zoomOutTrigger_MouseLeftButtonUp);
            _zoomInStoryboard                   = _target.FindName("ZoomIn") as Storyboard;
            _zoomOutStoryboard                  = _target.FindName("ZoomOut") as Storyboard;
            _rotateToAngleStoryboard            = _target.FindName("RotateToAngle") as Storyboard;
            _animateToPositionStoryboard        = _target.FindName("AnimateToPosition") as Storyboard;
            _zoomInStoryboard.Completed        += new EventHandler(_zoomInStoryboard_Completed);
            _zoomOutStoryboard.Completed       += new EventHandler(_zoomOutStoryboard_Completed);
            _layoutStandByStoryboard            = _target.FindName("LayoutStandBy") as Storyboard;
            _layoutStandByStoryboard.Completed += new EventHandler(_layoutStandByStoryboard_Completed);

            _btnSort.MouseLeftButtonUp   += new MouseEventHandler(_btnSort_MouseLeftButtonUp);
            _btnSort.MouseEnter          += new MouseEventHandler(_btnSort_MouseEnter);
            _btnSort.MouseLeave          += new EventHandler(_btnSort_MouseLeave);
            _btnRandom.MouseLeftButtonUp += new MouseEventHandler(_btnRandom_MouseLeftButtonUp);
            _btnRandom.MouseEnter        += new MouseEventHandler(_btnRandom_MouseEnter);
            _btnRandom.MouseLeave        += new EventHandler(_btnRandom_MouseLeave);

            _screenArrowLeft.MouseLeftButtonUp  += new MouseEventHandler(_screenArrowLeft_MouseLeftButtonUp);
            _screenArrowRight.MouseLeftButtonUp += new MouseEventHandler(_screenArrowRight_MouseLeftButtonUp);

            // By default, enter sorted layout.
            _status     = AlbumStatus.Hanging; // clear status
            Status      = AlbumStatus.Sorted;
            _zoomStatus = ZoomStatus.Out;
        }
 protected void SetZoomStatus(float zCoord)
 {
     if (zCoord == minDistance)
     {
         Zoom = ZoomStatus.ZoomAtMin;
     }
     else if (zCoord == maxDistance)
     {
         Zoom = ZoomStatus.ZoomAtMax;
     }
     else
     {
         Zoom = ZoomStatus.Middle;
     }
 }
        // this method performs an automatic camera movement (up or down, between cameraMaxDistance (far from the world) and cameraMinDistance (near the world))
        IEnumerator SmoothCameraMover(ZoomStatus zoomStatus)
        {
            Vector3 cameraPosition  = controlledCamera.transform.position;
            float   startPosition   = cameraPosition.z;
            float   currentPosition = cameraPosition.z;
            float   endPosition     = zoomStatus == ZoomStatus.ZoomAtMin ? minDistance : maxDistance;
            float   currentTime     = 0;

            while (currentPosition != endPosition)
            {
                yield return(null);

                currentTime     += Time.deltaTime;
                currentPosition  = Mathf.Clamp(Mathf.Lerp(startPosition, endPosition, currentTime / smoothMoveDuration), maxDistance, minDistance);
                cameraPosition.z = currentPosition;
                controlledCamera.transform.position = cameraPosition;
                SetZoomStatus(cameraPosition.z);
            }
            GlobalManager.MInstantMessage.DeliverMessage(zoomStatus == ZoomStatus.ZoomAtMin ? InstantMessageType.WorldCameraZoomedAtMin : InstantMessageType.WorldCameraZoomedAtMax, this);
        }
Beispiel #4
0
 void _zoomInStoryboard_Completed(object sender, EventArgs e)
 {
     _isSliceRequest = false;
     _zoomStatus = ZoomStatus.In;
 }
Beispiel #5
0
        /// <summary>
        /// Constructor for a LayoutManager instance.
        /// </summary>
        /// <param name="pTarget">Target canvas which will hold all photo slices and this manager will take effect on.</param>
        /// <param name="pDataSource">Data source for this manager instance.</param>
        /// <param name="pBtnSortCanvas">Sort layout trigger canvas.</param>
        /// <param name="pBtnRandomCanvas">Random layout trigger canvas.</param>
        /// <param name="pZoomOutTrigger">Zoomout trigter canvas.</param>
        /// <param name="pSortNavi">Sort navigator.</param>
        public LayoutManager(Canvas pTarget, PhotoDataSet pDataSource, Canvas pBtnSortCanvas, Canvas pBtnRandomCanvas, Canvas pZoomOutTrigger, SortNavigator pSortNavi, GenuineSlice pGenuineSlice, TracingIcon pTracingIcon, Image pScreenArrowLeft, Image pScreenArrowRight)
        {
            _target = pTarget;
            _targetShadow = pTarget.FindName("PhotoHolderShadow") as Canvas;
            _sortNavi = pSortNavi;
            _dataSource = pDataSource;
            _zoomOutTrigger = pZoomOutTrigger;
            _btnSort = pBtnSortCanvas;
            _btnSort.Cursor = Cursors.Hand;
            _btnRandom = pBtnRandomCanvas;
            _btnRandom.Cursor = Cursors.Hand;
            _genuineSlice = pGenuineSlice;
            _isSliceRequest = false;
            _tracingMouse = pTracingIcon;
            _screenArrowLeft = pScreenArrowLeft;
            _screenArrowRight = pScreenArrowRight;

            // Generate random & sort params
            GenerateLayoutPostion();
            // Fill thums to thumHolder
            FillThumHolder();

            // Event register.
            _target.MouseLeftButtonUp += new MouseEventHandler(_target_MouseLeftButtonUp);
            _zoomOutTrigger.MouseLeftButtonUp += new MouseEventHandler(_zoomOutTrigger_MouseLeftButtonUp);
            _zoomInStoryboard = _target.FindName("ZoomIn") as Storyboard;
            _zoomOutStoryboard = _target.FindName("ZoomOut") as Storyboard;
            _rotateToAngleStoryboard = _target.FindName("RotateToAngle") as Storyboard;
            _animateToPositionStoryboard = _target.FindName("AnimateToPosition") as Storyboard;
            _zoomInStoryboard.Completed += new EventHandler(_zoomInStoryboard_Completed);
            _zoomOutStoryboard.Completed += new EventHandler(_zoomOutStoryboard_Completed);
            _layoutStandByStoryboard = _target.FindName("LayoutStandBy") as Storyboard;
            _layoutStandByStoryboard.Completed += new EventHandler(_layoutStandByStoryboard_Completed);

            _btnSort.MouseLeftButtonUp += new MouseEventHandler(_btnSort_MouseLeftButtonUp);
            _btnSort.MouseEnter += new MouseEventHandler(_btnSort_MouseEnter);
            _btnSort.MouseLeave += new EventHandler(_btnSort_MouseLeave);
            _btnRandom.MouseLeftButtonUp += new MouseEventHandler(_btnRandom_MouseLeftButtonUp);
            _btnRandom.MouseEnter += new MouseEventHandler(_btnRandom_MouseEnter);
            _btnRandom.MouseLeave += new EventHandler(_btnRandom_MouseLeave);

            _screenArrowLeft.MouseLeftButtonUp += new MouseEventHandler(_screenArrowLeft_MouseLeftButtonUp);
            _screenArrowRight.MouseLeftButtonUp += new MouseEventHandler(_screenArrowRight_MouseLeftButtonUp);

            // By default, enter sorted layout.
            _status = AlbumStatus.Hanging;     // clear status
            Status = AlbumStatus.Sorted;
            _zoomStatus = ZoomStatus.Out;
        }
Beispiel #6
0
 void _zoomOutStoryboard_Completed(object sender, EventArgs e)
 {
     _zoomStatus = ZoomStatus.Out;
 }
 void _zoomInStoryboard_Completed(object sender, EventArgs e)
 {
     _isSliceRequest = false;
     _zoomStatus     = ZoomStatus.In;
 }
 void _zoomOutStoryboard_Completed(object sender, EventArgs e)
 {
     _zoomStatus = ZoomStatus.Out;
 }
        // message handling
        void OnWorldZoomCamera(object sender, InstantMessageArgs args)
        {
            ZoomStatus zoomStatus = args.type == InstantMessageType.WorldZoomCameraAtMin ? ZoomStatus.ZoomAtMin : ZoomStatus.ZoomAtMax;

            StartCoroutine(SmoothCameraMover(zoomStatus));
        }
        void OnWorldAutoZoomCamera(object sender, InstantMessageArgs args)
        {
            ZoomStatus zoomStatus = Zoom == ZoomStatus.ZoomAtMin ? ZoomStatus.ZoomAtMax : ZoomStatus.ZoomAtMin;

            StartCoroutine(SmoothCameraMover(zoomStatus));
        }
Beispiel #11
0
    /// <summary>
    /// Scrolls the camera based on the amount that the mouse wheel has scrolled.
    /// </summary>
    /// <param name="delta">The mouse wheel's y delta.</param>
    private void ScrollCamera(float delta)
    {
        // add our new delta
        zoomEnergy += delta;

        // cap the energy
        if (zoomEnergy > 4f)
        {
            zoomEnergy = 4f;
        }
        else if (zoomEnergy < -4f)
        {
            zoomEnergy = -4f;
        }

        // almost everything takes this
        float timeAndEnergy = Time.deltaTime * zoomEnergy;

        // calculate the common movement factor
        float movement = ZOOM_SHIFT_HEIGHT * timeAndEnergy;

        // the current position of the camera
        Vector3 position = transform.position;

        // only rotate the camera if we're not going to cause the camera to drop out of zoom mode
        if (position.y < ZOOM_SHIFT_HEIGHT)
        {
            cameraRotation.x += MOUSE_SCROLLRATE * timeAndEnergy;
        }

        // actually update the rotation of the camera
        ZoomStatus status = GetZoomStatus();

        // clamp the rotation to [minPitch, maxPitch]
        if (cameraRotation.x < MIN_PITCH)
        {
            cameraRotation.x = MIN_PITCH;
        }
        else if (cameraRotation.x > MAX_PITCH)
        {
            cameraRotation.x = MAX_PITCH;
        }

        // if we're in free mode (both pitch and zoom can change) OR we're too low, but also zooming out
        if (status == ZoomStatus.FREE)
        {
            // add the extra information just for this method
            movement += timeAndEnergy * (45f * Mathf.Sin(transform.eulerAngles.x * Mathf.Deg2Rad));

            transform.Translate(0f, 0f, movement);

            position.y = ZOOM_FUNCTION_CONSTANT * Mathf.Pow(cameraRotation.x - 5, 2) + MIN_HEIGHT;
        }
        // if we're in zoom only mode OR we're too high, but also zooming in
        else if (status == ZoomStatus.ZOOM_ONLY)
        {
            // subtraction because zoomEnergy < 0 when zooming out (i.e going UP)
            position.y -= movement;

            cameraRotation.x = MAX_PITCH;
        }
        else if (status == ZoomStatus.TOO_LOW)
        {
            zoomEnergy       = 0f;
            position.y       = Mathf.Max(position.y, MIN_HEIGHT);
            cameraRotation.x = Mathf.Max(cameraRotation.x, MIN_PITCH);
        }
        else if (status == ZoomStatus.TOO_HIGH)
        {
            zoomEnergy       = 0f;
            position.y       = Mathf.Min(position.y, MAX_HEIGHT);
            cameraRotation.x = Mathf.Min(cameraRotation.x, MAX_PITCH);
        }

        // update our transform
        transform.position    = position;
        transform.eulerAngles = cameraRotation;

        // bring it closer to zero
        if (zoomEnergy < 0)
        {
            zoomEnergy = Mathf.Min(0f, zoomEnergy + (ZOOM_FRICTION * Time.deltaTime));
        }
        else if (zoomEnergy > 0)
        {
            zoomEnergy = Mathf.Max(0f, zoomEnergy - (ZOOM_FRICTION * Time.deltaTime));
        }
    }