예제 #1
0
        public void Config(Size pageSize)
        {
            Contract.Requires(pageSize.IsValid());
            Debug.Assert(m_flipper == null);

            PageWidth = pageSize.Width;
            PageHeight = pageSize.Height;
            PageDoubleWidth = pageSize.Width * 2;
            m_turningPageBack.Clip = new RectangleGeometry() { Rect = new Rect(new Point(), pageSize) };

            // TODO: HotSpot support need to be enabled with page content model
            m_flipper = new PageFlipper(pageSize, null, m_pageTop, m_curlShadow, m_shadow);

            m_flipper.IsAnimatingChanged += (sender, args) =>
            {
                if (!m_flipper.IsAnimating)
                {
                    m_working = false;
                    var stillWorking = startDance();
                    if (!stillWorking)
                    {
                        OnDoneFlipping();
                    }
                }
            };

            m_turningPageBack.RenderTransform = m_flipper.FlippingPageBackTransform;
            m_page2nd.Clip = m_flipper.NextPageClip;
            m_pageTop.Clip = m_flipper.PageHolderClip;

            m_contentBitmapLeft = new WriteableBitmap((int)pageSize.Width, (int)pageSize.Height);
            m_contentBitmapRight = new WriteableBitmap((int)pageSize.Width, (int)pageSize.Height);
            m_currentContentSnapshot = new WriteableBitmap((int)pageSize.Width * 2, (int)pageSize.Height);
            m_nextContentSnapshot = new WriteableBitmap((int)pageSize.Width * 2, (int)pageSize.Height);

#if FUNKY
      var stack = new StackPanel() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Opacity = .67 };

      (new WriteableBitmap[] { m_currentContentSnapshot, m_nextContentSnapshot, m_contentBitmapLeft, m_contentBitmapRight }).ForEach(wp => {
        var image = new Image() { Source = wp, Stretch = Stretch.UniformToFill, Height = 150, Width = 200 };
        stack.Children.Add(image);
      });

      ((Grid)Content).Children.Add(stack);

#endif

            m_leftImage.Source = m_contentBitmapLeft;
            m_rightImage.Source = m_contentBitmapRight;
        }
예제 #2
0
        /// <summary>
        ///     Returns the scale factor by which an object of size <paramref name="source"/>
        ///     should be scaled to fit within an object of size <param name="target"/>.
        /// </summary>
        /// <param name="target">The target size.</param>
        /// <param name="size2">The source size.</param>
        public static double ScaleToFit(Size target, Size source)
        {
            Contract.Requires(target.IsValid());
            Contract.Requires(source.IsValid());
            Contract.Requires(target.Width > 0);
            Contract.Requires(source.Width > 0);

            double targetHWR = target.Height / target.Width;
            double sourceHWR = source.Height / source.Width;

            if (targetHWR > sourceHWR)
            {
                return target.Width / source.Width;
            }
            else
            {
                return target.Height / source.Height;
            }
        }
예제 #3
0
 public static Vector Subtract(this Size size, Size other)
 {
     Contract.Requires(size.IsValid());
     Contract.Requires(other.IsValid());
     Contract.Ensures(Contract.Result<Vector>().IsValid());
     return new Vector(size.Width - other.Width, size.Height - other.Height);
 }
예제 #4
0
파일: PageFlipper.cs 프로젝트: edealbag/bot
        public PageFlipper(Size pageSize, UIElement hotCorner, UIElement pageHolder, FrameworkElement curlShadow, FrameworkElement dropShadow)
        {
            Contract.Requires(pageSize.IsValid());
            m_pageSize = pageSize;

            m_hotCorner = hotCorner;

            m_curlShadow = curlShadow;
            m_dropShadow = dropShadow;

            // can be null
            m_pageHolder = pageHolder;

            #region helper values
            m_pageHalfHeight = m_pageSize.Height * .5;
            m_origin = new Point(m_pageSize.Width, m_pageSize.Height / 2.0);
            m_pageDiagonal = Math.Sqrt(m_pageSize.Width * m_pageSize.Width + m_pageSize.Height * m_pageSize.Height);
            m_pointLeft = new Point(-m_pageSize.Width, m_pageHalfHeight);
            m_pointRight = new Point(m_pageSize.Width, m_pageHalfHeight);
            #endregion

            #region clips and transforms

            m_pageTransformGroup = new TransformGroup();
            m_pageTransformGroup.Children.Add(new TranslateTransform() { Y = -m_pageSize.Height });
            m_pageTransformGroup.Children.Add(m_pageRotateTransform = new RotateTransform());
            m_pageTransformGroup.Children.Add(m_pageTranslateTransform = new TranslateTransform());

            m_pageHolderClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width, m_pageSize.Height * 2) };
            m_nextPageClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width * 2, m_pageSize.Height * 2) };

            if (m_curlShadow != null)
            {
                var group = new TransformGroup();
                group.Children.Add(m_curlShadowRotate = new RotateTransform());
                group.Children.Add(m_curlShadowTranslate = new TranslateTransform());
                m_curlShadow.RenderTransform = group;

                m_curlShadow.Height = m_pageDiagonal * 1.5;
                m_curlShadowRotate.CenterX = m_curlShadow.Width;
                m_curlShadowRotate.CenterY = m_pageDiagonal;

                m_curlShadowTranslate.Y = m_pageSize.Height - m_pageDiagonal;
            }

            if (m_dropShadow != null)
            {
                //m_dropShadowBlurEffect = new BlurEffect() { Radius = 20 };
                //m_dropShadow.Effect = m_dropShadowBlurEffect;
                m_dropShadow.RenderTransform = m_pageTransformGroup;
                m_dropShadow.Width = m_pageSize.Width;
                m_dropShadow.Height = m_pageSize.Height;
            }

            #endregion

            // MOST OF THE LOADED FUNCTION IS USED TO SET LOOK UP VALUES
            // BASED ON THE pageWidth AND pageHeight INITIALLY DEFINED.
            // POSITION THE PAGE AND SPINE VISUALS ACCORDINGLY
            m_mouse.X = m_pageSize.Width - 1;
            m_mouse.Y = m_pageHalfHeight - 1;
            m_follow = m_mouse;

            #region mouse handlers

            if (m_hotCorner != null && m_pageHolder != null)
            {
                m_hotCorner.MouseMove += (sender, e) =>
                {
                    m_animating = false;
                    m_listener.StartListening();
                    Point testBounds = (Point)e.GetPosition(m_pageHolder).Subtract(m_origin);
                    if (testBounds.X > m_pageSize.Width && testBounds.Y > m_pageHalfHeight)
                    {
                        m_mouse = m_pointRight;
                    }
                    else
                    {
                        m_mouse = testBounds;
                    }
                };

                m_hotCorner.MouseLeftButtonDown += (sender, e) =>
                {
                    m_hotCorner.CaptureMouse();
                };

                m_hotCorner.MouseLeftButtonUp += (sender, e) =>
                {
                    m_listener.StartListening();
                    m_hotCorner.ReleaseMouseCapture();
                    m_mouse = (m_mouse.X < 0) ? m_pointLeft : m_pointRight;
                };

                m_hotCorner.MouseLeave += (sender, e) =>
                {
                    m_listener.StartListening();
                    m_mouse = m_pointRight;
                };
            }

            #endregion

            m_listener.Rendering += (sender, args) => updateUI();
            m_listener.IsListeningChanged += (sender, args) =>
            {
                var handler = IsAnimatingChanged;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            };
        }