Ejemplo n.º 1
0
        public void Update(TransitionType transitionType)
        {
            Int32      index      = 0;
            Storyboard storyboard = new Storyboard();

            if (previousStoryboard != null)
            {
                previousStoryboard.Pause();
            }

            /*    if(deferredTransition)
             *  {
             *      storyboard.BeginTime = Const.AnimationDelay;
             *  }*/

            foreach (Object datum in Data.List)
            {
                Ellipse ellipse = null;

                if (index < CircleCanvas.Children.Count)
                {
                    ellipse            = CircleCanvas.Children[index] as Ellipse;
                    ellipse.Visibility = Visibility.Visible;
                    ellipse.Fill       = ColorGetter == null ? new SolidColorBrush(Colors.LightGray) : new SolidColorBrush(ColorGetter(datum, index));

                    Double newRadius = RadiusGetter(datum, index);

                    ellipse.Height = newRadius;
                    ellipse.Width  = newRadius;

                    if (transitionType.HasFlag(TransitionType.Position))
                    {
                        Double newX = XGetter(datum, index) - newRadius / 2;
                        Double newY = YGetter(datum, index) - newRadius / 2;

                        if ((ellipse.RenderTransform as TranslateTransform).X != newX)
                        {
                            storyboard.Children.Add(Util.GenerateDoubleAnimation(ellipse.RenderTransform, "X", newX));
                        }
                        if ((ellipse.RenderTransform as TranslateTransform).Y != newY)
                        {
                            storyboard.Children.Add(Util.GenerateDoubleAnimation(ellipse.RenderTransform, "Y", newY));
                        }
                    }
                    else
                    {
                        (ellipse.RenderTransform as TranslateTransform).X = XGetter(datum, index) - newRadius / 2;
                        (ellipse.RenderTransform as TranslateTransform).Y = YGetter(datum, index) - newRadius / 2;
                    }

                    if (transitionType.HasFlag(TransitionType.Opacity))
                    {
                        if (OpacityGetter != null && OpacityGetter(datum, index) != ellipse.Opacity)
                        {
                            storyboard.Children.Add(Util.GenerateDoubleAnimation(ellipse, "Opacity", OpacityGetter == null ? 1.0 : OpacityGetter(datum, index)));
                        }
                    }
                    else
                    {
                        ellipse.Opacity = OpacityGetter == null ? 1.0 : OpacityGetter(datum, index);
                    }
                }
                else
                {
                    ellipse = new Ellipse()
                    {
                        RenderTransform = new TranslateTransform(),
                        Width           = RadiusGetter(datum, index),
                        Height          = RadiusGetter(datum, index),
                        Opacity         = 0,
                        Fill            = ColorGetter == null ? new SolidColorBrush(Colors.LightGray) : new SolidColorBrush(ColorGetter(datum, index))
                    };
                    //처음 추가는 opacity만 빼고 바로 설정

                    (ellipse.RenderTransform as TranslateTransform).X = XGetter(datum, index) - RadiusGetter(datum, index) / 2;
                    (ellipse.RenderTransform as TranslateTransform).Y = YGetter(datum, index) - RadiusGetter(datum, index) / 2;

                    if (transitionType.HasFlag(TransitionType.Opacity))
                    {
                        storyboard.Children.Add(Util.GenerateDoubleAnimation(ellipse, "Opacity", OpacityGetter == null ? 1.0 : OpacityGetter(datum, index)));
                    }
                    else
                    {
                        ellipse.Opacity = OpacityGetter == null ? 1.0 : OpacityGetter(datum, index);
                    }

                    CircleCanvas.Children.Add(ellipse);
                }

                index++;
            }
            storyboard.Begin();
            previousStoryboard = storyboard;

            for (Int32 i = CircleCanvas.Children.Count - 1; i >= index; --i)
            {
                Ellipse child = CircleCanvas.Children[i] as Ellipse;
                child.Visibility = Visibility.Collapsed;
                //CircleCanvas.Children.Remove(child);
            }
        }
Ejemplo n.º 2
0
        public void Update(TransitionType transitionType)
        {
            if (previousStoryboard != null)
            {
                previousStoryboard.Pause();
            }
            Storyboard sb = new Storyboard()
            {
                ///BeginTime = Const.AnimationDelay
            };

            Int32 index = 0;

            foreach (Object datum in Data.List)
            {
                Path   path;
                Object localDatum = datum;

                if (LineCanvas.Children.Count > index)
                {
                    path            = LineCanvas.Children[index] as Path;
                    path.Visibility = Visibility.Visible;
                }
                else
                {
                    path = new Path()
                    {
                        StrokeStartLineCap = PenLineCap.Round,
                        StrokeEndLineCap   = PenLineCap.Round,
                        Stroke             = StrokeGetter == null ? new SolidColorBrush(Colors.LightGray) : new SolidColorBrush(StrokeGetter(datum, index)),
                        StrokeThickness    = StrokeThicknessGetter == null ? 2 : StrokeThicknessGetter(datum, index),
                        Opacity            = 0
                    };

                    if (LinePointerPressed != null)
                    {
                        path.PointerPressed += delegate(object sender, PointerRoutedEventArgs e)
                        {
                            LinePointerPressed(path, e, localDatum);
                        };
                    }

                    if (LinePointerReleased != null)
                    {
                        path.PointerReleased += delegate(object sender, PointerRoutedEventArgs e)
                        {
                            LinePointerReleased(path, e, localDatum);
                        };
                    }

                    if (LineTapped != null)
                    {
                        path.Tapped += delegate(object sender, TappedRoutedEventArgs e)
                        {
                            LineTapped(path, e, localDatum);
                        };
                    }

                    LineCanvas.Children.Add(path);
                }

                List <Point> points = CoordinateGetter(datum, index);

                if (points.Count == 0)
                {
                    throw new Exception("No coordinate found");
                }


                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures = new PathFigureCollection();
                PathFigure pathFigure = null;

                foreach (Point point in points)
                {
                    if (point.X < 0)
                    {
                        if (pathFigure != null)
                        {
                            pathGeometry.Figures.Add(pathFigure);
                            pathFigure = null;
                        }
                    }
                    else
                    {
                        if (pathFigure == null)
                        {
                            pathFigure            = new PathFigure();
                            pathFigure.StartPoint = point;
                        }
                        else
                        {
                            LineSegment lineSegment = new LineSegment();
                            lineSegment.Point = point;
                            pathFigure.Segments.Add(lineSegment);
                        }
                    }
                }

                if (pathFigure != null)
                {
                    pathGeometry.Figures.Add(pathFigure);
                }

                path.Data = pathGeometry;

                if (transitionType.HasFlag(TransitionType.Opacity))
                {
                    sb.Children.Add(Util.GenerateDoubleAnimation(path, "Opacity", OpacityGetter == null ? 1 : OpacityGetter(datum, index)));
                }
                else
                {
                    path.Opacity = OpacityGetter == null ? 1 : OpacityGetter(datum, index);
                }

                if (transitionType.HasFlag(TransitionType.Color))
                {
                    sb.Children.Add(Util.GenerateColorAnimation(path, "(Path.Fill).(SolidColorBrush.Color)",
                                                                StrokeGetter == null ? Colors.LightGray : StrokeGetter(datum, index)));
                }
                else
                {
                    path.Stroke = StrokeGetter == null ? new SolidColorBrush(Colors.LightGray) : new SolidColorBrush(StrokeGetter(datum, index));
                }
                index++;
            }

            previousStoryboard = sb;
            sb.Begin();

            for (Int32 i = LineCanvas.Children.Count - 1; i >= index; i--)
            {
                LineCanvas.Children[i].Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 3
0
        public void Update(TransitionType transitionType)
        {
            Storyboard sb = new Storyboard();

            Int32 index = 0;

            foreach (Object datum in Data.List)
            {
                Border    border;
                TextBlock textBlock;

                if (index >= TextCanvas.Children.Count) // 없는 사각형은 새로 만듦
                {
                    border = new Border();

                    if (WidthGetter != null)
                    {
                        border.Width = WidthGetter(datum, index);
                    }
                    if (HeightGetter != null)
                    {
                        border.Height = HeightGetter(datum, index);
                    }

                    textBlock = new TextBlock()
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Text       = TextGetter(datum, index),
                        Foreground = ColorGetter == null ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(ColorGetter(datum, index))
                    };

                    border.Child = textBlock;

                    Canvas.SetLeft(border, XGetter(datum, index));
                    Canvas.SetTop(border, YGetter(datum, index));

                    TextCanvas.Children.Add(border);
                    textBlocks.Add(textBlock);

                    border.Measure(new Size(Double.MaxValue, Double.MaxValue));

                    textBlock.Opacity = OpacityGetter(textBlock, datum, index);
                }
                else
                {
                    border    = TextCanvas.Children[index] as Border;
                    textBlock = border.Child as TextBlock;

                    if (WidthGetter != null)
                    {
                        border.Width = WidthGetter(datum, index);
                    }
                    if (HeightGetter != null)
                    {
                        border.Height = HeightGetter(datum, index);
                    }
                    textBlock.Text       = TextGetter(datum, index);
                    textBlock.Foreground = ColorGetter == null ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(ColorGetter(datum, index));

                    if (transitionType.HasFlag(TransitionType.Position))
                    {
                        sb.Children.Add(Util.GenerateDoubleAnimation(border, "(Canvas.Left)", XGetter(datum, index)));
                        sb.Children.Add(Util.GenerateDoubleAnimation(border, "(Canvas.Top)", YGetter(datum, index)));
                    }
                    else
                    {
                        Canvas.SetLeft(border, XGetter(datum, index));
                        Canvas.SetTop(border, YGetter(datum, index));
                    }

                    //textBlock.Measure(new Size(10000, 10000));
                    if (transitionType.HasFlag(TransitionType.Opacity) && OpacityGetter != null && textBlock.Opacity != OpacityGetter(textBlock, datum, index))
                    {
                        sb.Children.Add(Util.GenerateDoubleAnimation(textBlock, "Opacity", OpacityGetter(textBlock, datum, index)));
                    }
                    else
                    {
                        textBlock.Opacity = OpacityGetter(textBlock, datum, index);
                    }
                }

                index++;
            }

            for (Int32 i = TextCanvas.Children.Count - 1; i >= index; --i)
            {
                TextCanvas.Children.RemoveAt(i);
                textBlocks.RemoveAt(i);
            }

            if (previousStoryboard != null)
            {
                previousStoryboard.Pause();
            }
            if (sb.Children.Count > 0)
            {
                sb.Begin();
                previousStoryboard = sb;
            }
        }
Ejemplo n.º 4
0
        public void Update(TransitionType transitionType)
        {
            Int32      index = 0;
            Storyboard sb    = new Storyboard()
            {
            };

            /***
             * 현재 데이터: Data.List
             * 현재 화면상 요소: RectangleCanvas.Children
             * 화면 상 요소 의 데이터는 Tag로 참조 가능
             ***/

            Boolean[] flag = new Boolean[Data.List.Count];

            List <Rectangle> exitSelection     = new List <Rectangle>();
            Dictionary <Object, Rectangle> map = new Dictionary <object, Rectangle>();

            foreach (UIElement ele in RectangleCanvas.Children)
            {
                Rectangle rect = ele as Rectangle;
                if (rect.Tag != null)
                {
                    map[rect.Tag] = rect;
                }
            }

            foreach (Object datum in Data.List)
            {
                Object matchedKey = null, matchedValue = null;
                foreach (Object key in map.Keys)
                {
                    if (key.Equals(datum))
                    {
                        matchedKey   = key;
                        matchedValue = map[key];
                        break;
                    }
                }
                if (matchedValue != null) // 이미 있음 -> update
                {
                    Rectangle rect = matchedValue as Rectangle;
                    rect.Tag        = datum;
                    rect.Visibility = Visibility.Visible;

                    Double newWidth = WidthGetter(datum, index);
                    if (newWidth != rect.Width)
                    {
                        if (transitionType.HasFlag(TransitionType.Size))
                        {
                            sb.Children.Add(Util.GenerateDoubleAnimation(rect.RenderTransform, "ScaleX", newWidth));
                        }
                        else
                        {
                            (rect.RenderTransform as CompositeTransform).ScaleX = newWidth;
                        }
                    }

                    Double newHeight = HeightGetter(datum, index);
                    if (newHeight != rect.Height)
                    {
                        if (transitionType.HasFlag(TransitionType.Size))
                        {
                            sb.Children.Add(Util.GenerateDoubleAnimation(rect.RenderTransform, "ScaleY", newHeight));
                        }
                        else
                        {
                            (rect.RenderTransform as CompositeTransform).ScaleY = newHeight;
                        }
                    }

                    Double newX = XGetter(datum, index);
                    if (newX != (rect.RenderTransform as CompositeTransform).TranslateX)
                    {
                        if (transitionType.HasFlag(TransitionType.Position))
                        {
                            sb.Children.Add(Util.GenerateDoubleAnimation(rect.RenderTransform, "TranslateX", newX));
                        }
                        else
                        {
                            (rect.RenderTransform as CompositeTransform).TranslateX = newX;
                        }
                    }

                    Double newY = YGetter(datum, index);
                    if (newY != (rect.RenderTransform as CompositeTransform).TranslateY)
                    {
                        if (transitionType.HasFlag(TransitionType.Position))
                        {
                            sb.Children.Add(Util.GenerateDoubleAnimation(rect.RenderTransform, "TranslateY", newY));
                        }
                        else
                        {
                            (rect.RenderTransform as CompositeTransform).TranslateY = newY;
                        }
                    }

                    Color newColor = ColorGetter(datum, index);
                    if (newColor != (rect.Fill as SolidColorBrush).Color)
                    {
                        if (transitionType.HasFlag(TransitionType.Color))
                        {
                            sb.Children.Add(Util.GenerateColorAnimation(rect, "(Rectangle.Fill).(SolidColorBrush.Color)", newColor));
                        }
                        else
                        {
                            rect.Fill = new SolidColorBrush(newColor);
                        }
                    }

                    if (OpacityGetter != null)
                    {
                        Double newOpacity = OpacityGetter(datum, index);
                        if (newOpacity != rect.Opacity)
                        {
                            if (transitionType.HasFlag(TransitionType.Opacity))
                            {
                                sb.Children.Add(Util.GenerateDoubleAnimation(rect, "Opacity", newOpacity));
                            }
                            else
                            {
                                rect.Opacity = newOpacity;
                            }
                        }
                    }

                    map.Remove(matchedKey);
                }
                else // 없음 -> enter
                {
                    Rectangle rect = null;

                    IEnumerable <Rectangle> empty = RectangleCanvas.Children.Where(ele => (ele as Rectangle).Tag == null).Select(ele => ele as Rectangle);

                    if (empty.Count() > 0)
                    {
                        rect            = empty.First();
                        rect.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        rect = new Rectangle();
                        RectangleCanvas.Children.Add(rect);
                    }

                    Object localDatum = datum;

                    rect.Width           = 1; //WidthGetter(datum, index),
                    rect.Height          = 1; //HeightGetter(datum, index),
                    rect.Fill            = ColorGetter == null ? new SolidColorBrush(Colors.LightGray) : new SolidColorBrush(ColorGetter(datum, index));
                    rect.Opacity         = OpacityGetter == null ? 1 : OpacityGetter(datum, index);
                    rect.RenderTransform = new CompositeTransform();
                    rect.Tag             = localDatum;

                    rect.Tapped += delegate(object sender, TappedRoutedEventArgs e)
                    {
                        if (RectangleTapped != null)
                        {
                            RectangleTapped(rect, e, rect.Tag);
                        }
                    };

                    if (RectangleManipulationDelta != null)
                    {
                        rect.ManipulationMode   = ManipulationModes.TranslateY | ManipulationModes.System;
                        rect.ManipulationDelta += delegate(object sender, ManipulationDeltaRoutedEventArgs e)
                        {
                            RectangleManipulationDelta(sender, e, rect.Tag);
                        };
                    }

                    if (RectangleManipulationCompleted != null)
                    {
                        rect.ManipulationCompleted += delegate(object sender, ManipulationCompletedRoutedEventArgs e)
                        {
                            RectangleManipulationCompleted(sender, e, rect.Tag);
                        };
                    }

                    (rect.RenderTransform as CompositeTransform).TranslateX = XGetter(datum, index);
                    (rect.RenderTransform as CompositeTransform).TranslateY = YGetter(datum, index);
                    (rect.RenderTransform as CompositeTransform).ScaleX     = WidthGetter(datum, index);
                    (rect.RenderTransform as CompositeTransform).ScaleY     = HeightGetter(datum, index);
                }

                index++;
            }

            foreach (KeyValuePair <Object, Rectangle> kv in map)
            {
                kv.Value.Visibility = Visibility.Collapsed;
                kv.Value.Tag        = null;
            }

            if (previousStoryboard != null)
            {
                previousStoryboard.Pause();
            }
            if (sb.Children.Count > 0)
            {
                sb.Begin();
                previousStoryboard = sb;
            }
        }