static bool CreateFoldAnimation(ref BookItem fold, BookItem back_fold, Vector2 start, Vector2 target)
 {
     if (fold != null)
     {
         if (fold.DragStart != start)
         {
             //BookItem back_fold = this.Back(fold);
             if (back_fold != null)
             {
                 back_fold.DragCurrent = fold.DragCurrent = back_fold.DragStart = fold.DragStart = start;
                 //BookItem backItem = this.Back(fold);
                 if (LinearTransition(fold, back_fold, (double)0.0, target))
                 {
                     //this.BeginRendering();
                     return(true);
                 }
             }
             // this.LinearTransition(fold, start, target);
         }
         else
         {
             if (fold.Time == 1.0)
             {
                 fold.Time = 0.0;
             }
             //BookItem backItem = this.Back(fold);
             if (LinearTransition(fold, back_fold, fold.Time, target))
             {
                 //this.BeginRendering();
                 return(true);
             }
         }
     }
     return(false);
 }
 // Methods
 private static void AddShadow(BookItem element, Vector2 point, Vector2 dir, Size size, bool showOuterShadows, bool showInnerShadows)
 {
     if (!showInnerShadows && !showOuterShadows)
     {
         element.Effect = (null);
     }
     else
     {
         Size s     = new Size((element.Direction == Dock.Left) ? ((double)0f) : ((double)8f), (element.Direction == Dock.Top) ? ((double)0f) : ((double)8f));
         Size size3 = size;
         size.Width  = (size.Width + (s.Width + ((element.Direction == Dock.Right) ? ((double)0f) : ((double)8f))));
         size.Height = (size.Height + (s.Height + ((element.Direction == Dock.Bottom) ? ((double)0f) : ((double)8f))));
         Vector2    v      = point + new Vector2(s);
         FoldEffect effect = element.Effect as FoldEffect;
         if (effect == null)
         {
             element.Effect = (effect = new FoldEffect());
         }
         effect.Size         = size;
         effect.ContentSize  = size3;
         effect.Padding      = s;
         effect.RectAB       = (Point)dir;
         effect.RectC        = -dir.Dot(v);
         effect.OuterShadows = showOuterShadows ? 0.125f : 0f;
         effect.InnerShadows = showInnerShadows ? 0.006666667f : 0f;
     }
 }
        private void Reset(BookItem element)
        {
            element.DragStart       = element.DragCurrent = new Vector2();
            element.Path            = null;
            element.TransitionFront = false;
            element.Time            = 0.0;
            int index = base.ItemContainerGenerator.IndexFromContainer(element);
            int num2  = this.PagePosition(index);

            if (this.Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                Grid.SetColumn(element, num2);
                Grid.SetRowSpan(element, 2);
                Grid.SetRow(element, 0);
                Grid.SetColumnSpan(element, 1);
                element.Direction = (num2 == 0) ? Dock.Right : Dock.Left;
            }
            else
            {
                Grid.SetRow(element, num2);
                Grid.SetColumnSpan(element, 2);
                Grid.SetColumn(element, 0);
                Grid.SetRowSpan(element, 1);
                element.Direction = (num2 == 0) ? Dock.Bottom : Dock.Top;
            }
        }
 private void OnMouseDragEnd(object sender, MouseDragEventArgs e)
 {
     if (this._dragged != null)
     {
         BookItem item      = this.Back(this._dragged);
         Vector2  dragStart = this._dragged.DragStart;
         Vector2  vector2   = new Vector2(e.GetPosition(this)) / base.RenderSize;
         Vector2  vector3   = new Vector2(0.5, 0.5);
         if (((this.Orientation == System.Windows.Controls.Orientation.Horizontal) && (Math.Sign((double)(vector2.X - vector3.X)) != Math.Sign((double)(this._dragged.DragStart.X - vector3.X)))) || ((this.Orientation == null) && (Math.Sign((double)(vector2.Y - vector3.Y)) != Math.Sign((double)(this._dragged.DragStart.Y - vector3.Y)))))
         {
             dragStart        = VectorHelper.Symmetry(new Size(1.0, 1.0), item.Direction, dragStart);
             dragStart        = VectorHelper.Flip(new Size(1.0, 1.0), this._dragged.Direction, dragStart);
             this.CurrentPage = base.ItemContainerGenerator.IndexFromContainer(item);
         }
         BookItem backItem = this.Back(this._dragged);
         if (LinearTransition(this._dragged, backItem, (double)0.0, dragStart))
         {
             this.BeginRendering();
         }
         this._dragged = null;
         if (this.DragPageFinished != null)
         {
             this.DragPageFinished(this, new BookDragPageFinishedEventArgs(this.CurrentPage));
         }
     }
 }
        private void OnMouseDragStart(object sender, MouseDragEventArgs e)
        {
            Point position = e.GetPosition(this);
            int   index    = this.CurrentPage - this.PagePosition(this.CurrentPage);

            if (((this.Orientation == System.Windows.Controls.Orientation.Horizontal) && (position.X > (base.RenderSize.Width / 2.0))) || ((this.Orientation == null) && (position.Y > (base.RenderSize.Height / 2.0))))
            {
                index++;
            }
            this._dragged = base.ItemContainerGenerator.ContainerFromIndex(index) as BookItem;
            if (this._dragged != null)
            {
                BookItem item = this.Back(this._dragged);
                if (item == null)
                {
                    this._dragged = null;
                }
                else
                {
                    this.InstantUndoFold();
                    this._dragged.TransitionFront = false;
                    item.TransitionFront          = true;
                    this._dragged.DragStart       = item.DragStart = this._dragged.DragCurrent = item.DragCurrent = new Vector2(position) / base.RenderSize;
                    this.SortPages(this.PagePosition(index) == 1);
                    this.BeginRendering();
                    if (this.DragPageStarted != null)
                    {
                        this.DragPageStarted(this, EventArgs.Empty);
                    }
                }
            }
        }
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            BookItem item2 = element as BookItem;

            item2.Style = (this.ItemContainerStyle);
            this.Reset(item2);
            this.SortPages(true);
            UIElement element2 = item as UIElement;

            if ((element2 == null) || (GetApplyPageTemplate(element2) == ApplyPageTemplate.True))
            {
                switch (item2.Direction)
                {
                case Dock.Left:
                case Dock.Top:
                    item2.ControlTemplate = PlatformIndependent.AdjustContentControlTemplate(this.RightPageTemplate);
                    break;

                case Dock.Right:
                case Dock.Bottom:
                    item2.ControlTemplate = PlatformIndependent.AdjustContentControlTemplate(this.LeftPageTemplate);
                    break;
                }
                item2.InitializeContentControlPart();
            }
        }
        //private void SetCurrentPage(int value)
        //{
        //    this._ignorePageChange = true;
        //    this.CurrentPage = value;
        //    this._ignorePageChange = false;
        //}



        private void SortPages(bool forward)
        {
            if (_bIsLayout1Page)
            {
                int num  = forward ? base.Items.Count : 0;
                int num2 = base.Items.Count - num;
                for (int i = 0; i < base.Items.Count; i++)
                {
                    BookItem item = BookItemFromIndex(i);
                    if (item == null)
                    {
                        return;
                    }
                    int num4   = this.PagePosition(i);
                    int zindex = (num4 == 0) ? (num + (i / 2)) : (num2 - (i / 2));
                    Canvas.SetZIndex(item, zindex);
                }
            }
            else
            {//not tested
                for (int i = 0; i < base.Items.Count; i++)
                {
                    BookItem item = BookItemFromIndex(i);
                    if (item == null)
                    {
                        return;
                    }
                    int zindex = i;
                    Canvas.SetZIndex(item, zindex);
                }
            }
        }
Exemple #8
0
        public override void Turn(BookItem item, bool showOuterShadows, bool showInnerShadows, Size bookSize)
        {
            Size size = item.RenderSize;

            if (size.Width == 0.0)
            {
                size = ((item.Direction == Dock.Left) || (item.Direction == Dock.Right)) ? new Size(bookSize.Width / 2.0, bookSize.Height) : new Size(bookSize.Width, bookSize.Height / 2.0);
            }
            if (!item.TransitionFront)
            {
                item.RenderTransform = (null);
                item.Clip            = (null);
                AddShadow(item, VectorHelper.Center(size, item.Direction), VectorHelper.Direction(item.Direction), size, showOuterShadows, showInnerShadows);
                if (item.DragStart == item.DragCurrent)
                {
                    return;
                }
            }

            if (item.index == 0)
            {
                int a = 0;
            }
            if (item.index == 1)
            {
                int b = 0;
            }

            Dock    direction = item.TransitionFront ? item.Direction : this.Opposite(item.Direction);
            Vector2 p         = item.DragStart * bookSize;

            p = VectorHelper.Symmetry(bookSize, direction, p);
            p = VectorHelper.Flip(bookSize, direction, p);
            p = VectorHelper.LocalCoords(size, direction, p);
            Vector2 drag = VectorHelper.LocalCoords(size, direction, item.DragCurrent * bookSize);

            drag = BoundDrag(size, direction, p, drag);
            Vector2 vector3    = VectorHelper.Symmetry(size, direction, p);
            Vector2 vector4    = (Vector2)((drag + vector3) / 2.0);
            Vector2 point      = VectorHelper.Center(size, direction);
            Vector2 vector10   = (drag != vector3) ? (vector3 - drag) : (drag - point);
            Vector2 normalized = vector10.Normalized;
            Vector2 vector7    = VectorHelper.Symmetry(size, direction, vector4);

            if (item.TransitionFront)
            {
                TransformGroup group = new TransformGroup();
                group.Children.Add(VectorHelper.Reflection(VectorHelper.Direction(direction), point));
                group.Children.Add(VectorHelper.Reflection(normalized, vector4));
                item.RenderTransform = (group);
                Vector2 dir      = VectorHelper.DirectionSymmetry(direction, normalized);
                Vector2 midpoint = showInnerShadows ? (vector7 - ((Vector2)(dir * 150.0))) : vector7;
                item.Clip = (Clip(midpoint, dir, size));
                AddShadow(item, vector7, dir, size, showOuterShadows, showInnerShadows);
            }
            else
            {
                item.Clip = (Clip(VectorHelper.Flip(size, direction, vector7), -normalized, size));
            }
        }
 private void UndoFold()
 {
     if (this._fold != null)
     {
         this.LinearTransition(this._fold, (double)(1.0 - this._fold.Time), this._fold.DragStart);
         this._fold = null;
     }
 }
        private bool IsVisible(BookItem element)
        {
            if (element == null)
            {
                return(false);
            }
            BookItem item = this.Top(element);

            return(((this.IsTransitioning(element) || this.IsTransitioning(item)) || this.IsCurrent(element)) || (((item != null) && item.IsTransparent) && this.IsVisible(item)));
        }
        private void LinearTransition(BookItem item, Vector2 start, Vector2 target)
        {
            BookItem item2 = this.Back(item);

            if (item2 != null)
            {
                item2.DragCurrent = item.DragCurrent = item2.DragStart = item.DragStart = start;
                this.LinearTransition(item, (double)0.0, target);
            }
        }
        private void CircleTransition(BookItem item, BookZone zone)
        {
            Vector2  center;
            Vector2  start;
            Vector2  target;
            double   radius;
            BookItem item2 = this.Back(item);

            if (item2 != null)
            {
                //<>c__DisplayClass6 class2;
                center = new Vector2();
                if (this.Orientation == System.Windows.Controls.Orientation.Horizontal)
                {
                    center = ((zone == BookZone.TopLeft) || (zone == BookZone.TopRight)) ? new Vector2(0.5, -0.5) : new Vector2(0.5, 1.5);
                }
                else
                {
                    center = ((zone == BookZone.TopLeft) || (zone == BookZone.BottomLeft)) ? new Vector2(-0.5, 0.5) : new Vector2(1.5, 0.5);
                }
                start = new Vector2();
                switch (zone)
                {
                case BookZone.BottomLeft:
                    start = new Vector2(0.0, 1.0);
                    break;

                case BookZone.TopRight:
                    start = new Vector2(1.0, 0.0);
                    break;

                case BookZone.BottomRight:
                    start = new Vector2(1.0, 1.0);
                    break;
                }
                target = VectorHelper.Flip(new Size(1.0, 1.0), item.Direction, start);
                Vector2 vector = center - start;
                radius                = vector.Length;
                item2.DragCurrent     = item.DragCurrent = item2.DragStart = item.DragStart = start;
                item2.TransitionFront = true;
                item.TransitionFront  = false;
                item2.Time            = item.Time = 0.0;
                item2.Path            = item.Path = (double t) =>
                {
                    if (t != 1.0)
                    {
                        Vector2 vector2 = ((Vector2)((target * t) + (start * (1.0 - t)))) - center;
                        return(((Vector2)(vector2.Normalized * radius)) + center);
                    }
                    return(target);
                };

                this.BeginRendering();
            }
        }
 private void OnItemContainerStyleChanged(Style oldValue)
 {
     for (int i = 0; i < base.Items.Count; i++)
     {
         BookItem item = base.ItemContainerGenerator.ContainerFromIndex(i) as BookItem;
         if (item != null)
         {
             item.Style = (this.ItemContainerStyle);
         }
     }
 }
 private void UpdatePosition(BookItem element, double deltaTime)
 {
     if (element.Path != null)
     {
         element.Time        = Math.Min((double)(element.Time + (deltaTime / ((double)this.TurnInterval))), (double)1.0);
         element.DragCurrent = element.Path.Invoke(element.Time);
         if (element.Time == 1.0)
         {
             element.Path = null;
         }
     }
 }
 private void UndoFold()
 {
     if (this._fold != null)
     {
         BookItem backItem = this.Back(this._fold);
         if (LinearTransition(this._fold, backItem, (double)(1.0 - this._fold.Time), this._fold.DragStart))
         {
             this.BeginRendering();
         }
         this._fold = null;
     }
 }
 private void Reset()
 {
     for (int i = 0; i < base.Items.Count; i++)
     {
         BookItem element = base.ItemContainerGenerator.ContainerFromIndex(i) as BookItem;
         if (element != null)
         {
             this.Reset(element);
         }
     }
     this.SortPages(true);
     this.BeginRendering();
 }
 private BookItem Relative(BookItem item, int back, int forward)
 {
     if (item != null)
     {
         int index = base.ItemContainerGenerator.IndexFromContainer(item);
         int num2  = this.PagePosition(index);
         index += (num2 == 0) ? back : forward;
         if ((index >= 0) && (index < base.Items.Count))
         {
             return(base.ItemContainerGenerator.ContainerFromIndex(index) as BookItem);
         }
     }
     return(null);
 }
 private void Reset()
 {
     for (int i = 0; i < base.Items.Count; i++)
     {
         BookItem element = BookItemFromIndex(i);
         if (element != null)
         {
             this.Reset(element);
             //element.index = i;
         }
     }
     this.SortPages(true);
     this.BeginRendering();
 }
        private bool CastShadow(BookItem element)
        {
            BookItem item = this.Top(element);

            if (this.IsVisible(item) && !this.IsTransitioning(item))
            {
                return(false);
            }
            if ((this.Bottom(element) != null) && this.IsTransitioning(element))
            {
                return(element.TransitionFront);
            }
            return(true);
        }
        private void Fold(BookZone zone)
        {
            int     index   = this.CurrentPage - this.PagePosition(this.CurrentPage);
            Vector2 start   = new Vector2();
            Vector2 target  = new Vector2();
            Vector2 vector3 = new Vector2(this.FoldSize / base.RenderSize.Width, this.FoldSize / base.RenderSize.Height);

            switch (zone)
            {
            case BookZone.BottomLeft:
                index += (this.Orientation == System.Windows.Controls.Orientation.Horizontal) ? 0 : 1;
                start  = new Vector2(0.0, 1.0);
                target = new Vector2(vector3.X, 1.0 - vector3.Y);
                break;

            case BookZone.TopLeft:
                start  = new Vector2();
                target = vector3;
                break;

            case BookZone.TopRight:
                index += (this.Orientation == System.Windows.Controls.Orientation.Horizontal) ? 1 : 0;
                start  = new Vector2(1.0, 0.0);
                target = new Vector2(1.0 - vector3.X, vector3.Y);
                break;

            case BookZone.BottomRight:
                index++;
                start  = new Vector2(1.0, 1.0);
                target = new Vector2(1.0, 1.0) - vector3;
                break;
            }
            this.SortPages(this.PagePosition(index) == 1);
            this._fold = base.ItemContainerGenerator.ContainerFromIndex(index) as BookItem;
            if (this._fold != null)
            {
                if (this._fold.DragStart != start)
                {
                    this.LinearTransition(this._fold, start, target);
                }
                else
                {
                    if (this._fold.Time == 1.0)
                    {
                        this._fold.Time = 0.0;
                    }
                    this.LinearTransition(this._fold, this._fold.Time, target);
                }
            }
        }
        private bool IsCurrent(BookItem item)
        {
            if (item == null)
            {
                return(false);
            }
            int index = IndexFromBookItem(item);

            index -= this.PagePosition(index);//get index of the left page
            if (this.CurrentPage != index)
            {
                return(this.CurrentPage == (index + 1));
            }
            return(true);
        }
        private void OnLayoutUpdated(object sender, EventArgs e)
        {
            for (int i = 0; i < base.Items.Count; i++)
            {
                BookItem element = BookItemFromIndex(i);
                element.index = i;
            }

            if (base.RenderSize != this._size)
            {
                this._size = base.RenderSize;

                this.BeginRendering();
            }
        }
        private bool IsCurrent(BookItem item)
        {
            if (item == null)
            {
                return(false);
            }
            int index = base.ItemContainerGenerator.IndexFromContainer(item);

            index -= this.PagePosition(index);
            if (this.CurrentPage != index)
            {
                return(this.CurrentPage == (index + 1));
            }
            return(true);
        }
        private void UpdateTransition(BookItem element)
        {
            BookTransition transition = element.Transition ?? this.Transition;

            if (this.IsVisible(element))
            {
                element.Visibility = System.Windows.Visibility.Visible;
                element.UpdateLayout();
                transition.Turn(element, this.ShowOuterShadows && this.CastShadow(element), this.ShowInnerShadows, base.RenderSize);
            }
            else
            {
                element.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
        private bool TurnPage(BookZone zone)
        {
            bool     forward = ((this.Orientation == System.Windows.Controls.Orientation.Horizontal) && ((zone == BookZone.BottomRight) || (zone == BookZone.TopRight))) || ((this.Orientation == null) && ((zone == BookZone.BottomLeft) || (zone == BookZone.BottomRight)));
            int      num     = (this.CurrentPage - this.PagePosition(this.CurrentPage)) + (forward ? 1 : 0);
            BookItem item    = base.ItemContainerGenerator.ContainerFromIndex(num) as BookItem;

            if ((this.Back(item) != null) && (this._dragged == null))
            {
                this.InstantUndoFold();
                this.SortPages(forward);
                this.CircleTransition(item, zone);
                this.SetCurrentPage(this.CurrentPage + (forward ? 2 : -2));
                return(true);
            }
            return(false);
        }
        private void SortPages(bool forward)
        {
            int num  = forward ? base.Items.Count : 0;
            int num2 = base.Items.Count - num;

            for (int i = 0; i < base.Items.Count; i++)
            {
                BookItem item = base.ItemContainerGenerator.ContainerFromIndex(i) as BookItem;
                if (item == null)
                {
                    return;
                }
                int num4 = this.PagePosition(i);
                Canvas.SetZIndex(item, (num4 == 0) ? (num + (i / 2)) : (num2 - (i / 2)));
            }
        }
 private void InstantUndoFold()
 {
     if (this._fold != null)
     {
         BookItem item = this.Back(this._fold);
         if (item != null)
         {
             item.TransitionFront       = true;
             this._fold.TransitionFront = false;
             item.Time = this._fold.Time = 0.0;
             this._fold.DragCurrent = item.DragCurrent = this._fold.DragStart;
             item.Path = (Func <double, Vector2>)(this._fold.Path = null);
             this.BeginRendering();
         }
         this._fold = null;
     }
 }
        private void LinearTransition(BookItem item, double time, Vector2 target)
        {
            BookItem item2 = this.Back(item);

            if (item2 != null)
            {
                //<>c__DisplayClass3 class2;
                item2.TransitionFront = true;
                item.TransitionFront  = false;
                item2.Time            = item.Time = time;
                Vector2 start = item.DragCurrent;
                //item2.Path = item.Path = new Func<double, Vector2>(class2, (IntPtr) this.<LinearTransition>b__0);
                item2.Path = item.Path = (double t) =>
                {
                    return((Vector2)((target * t) + (start * (1.0 - t))));
                };
                this.BeginRendering();
            }
        }
 /// <summary>
 /// general update function, has respondsibility for:
 ///  + update transition
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CompositionTarget_Rendering(object sender, EventArgs e)
 {
     if (this._rendering)
     {
         DateTime now  = DateTime.Now;
         TimeSpan span = (TimeSpan)(now - this._lastUpdate);
         double   totalMilliseconds = span.TotalMilliseconds;
         this._lastUpdate = now;
         bool bIsAllElementHavePath     = false;
         bool bIsAllElementNoTransition = true;
         for (int i = 0; i < base.Items.Count; i++)
         {
             BookItem element = base.ItemContainerGenerator.ContainerFromIndex(i) as BookItem;
             if (element == null)
             {
                 return;
             }
             bIsAllElementHavePath = bIsAllElementHavePath || (element.Path != null);
             this.UpdatePosition(element, totalMilliseconds);
             bIsAllElementNoTransition = bIsAllElementNoTransition && !this.IsTransitioning(element);
         }
         for (int j = 0; j < base.Items.Count; j++)
         {
             BookItem item2 = base.ItemContainerGenerator.ContainerFromIndex(j) as BookItem;
             this.UpdateTransition(item2);
         }
         if (!bIsAllElementHavePath)
         {
             //this._rendering = false;
             //CompositionTarget.Rendering -= (new EventHandler(this.CompositionTarget_Rendering));
             if ((this.ShowPageFold == PageFoldVisibility.Always) && bIsAllElementNoTransition)
             {
                 this.Fold(BookZone.BottomRight);
             }
         }
     }
     else
     {
     }
 }
        private bool IsTransitioning(BookItem item)
        {
            if (item == null)
            {
                return(false);
            }
            BookItem item2 = this.Back(item);

            if (item2 == null)
            {
                return(false);
            }
            Dock    direction = item.TransitionFront ? item.Direction : item2.Direction;
            Vector2 p         = VectorHelper.Symmetry(new Size(1.0, 1.0), direction, item.DragStart);

            p = VectorHelper.Flip(new Size(1.0, 1.0), direction, p);
            if (item == null)
            {
                return(false);
            }
            return((item.Path != null) || ((item.DragCurrent != item.DragStart) && (item.DragCurrent != p)));
        }