예제 #1
0
        private void StartOpacityAnimations(VisualImage visualImage)
        {
            var batch            = visualImage.ForegroundVisual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            var opacityAnimation = visualImage.ForegroundVisual.Compositor.CreateScalarKeyFrameAnimation();

            opacityAnimation.InsertKeyFrame(0f, 0f);
            opacityAnimation.InsertKeyFrame(1f, 1f);
            opacityAnimation.Duration = TimeSpan.FromMilliseconds(400);

            var visual = ElementCompositionPreview.GetElementVisual(visualImage);

            visual.StartAnimation(nameof(Visual.Opacity), opacityAnimation);

            var opacityHideAnimation = _floatingVisual.Compositor.CreateScalarKeyFrameAnimation();

            opacityHideAnimation.InsertKeyFrame(0f, 1f);
            opacityHideAnimation.InsertKeyFrame(1f, 0f);
            opacityHideAnimation.Duration = TimeSpan.FromMilliseconds(400);

            _floatingVisual.StartAnimation(nameof(Visual.Opacity), opacityHideAnimation);

            batch.Completed += (sender, args) =>
            {
                ElementCompositionPreview.SetElementChildVisual(_hostFrame, null);
                _floatingVisual?.Dispose();
                _floatingVisual = null;
            };
            batch.End();
        }
예제 #2
0
        public void AttachVisual(VisualImage visualImage)
        {
            if (_floatingVisual == null)
            {
                throw new InvalidOperationException("No floating visual set");
            }

            visualImage.ImageLoaded += VisualImageOnImageLoaded;
            visualImage.ImageUri     = _floatingVisualUri;
            visualImage.Opacity      = 0;
        }
예제 #3
0
        void UpdateImageQuick(int firstSymbol, int lastSymbolExclusive)
        {
            var clipRect = new Rectangle(0, 0, VisualImage.Size.Width, VisualImage.Size.Height);

            int[] imagePixels;
            using (VisualImage.LockPixels(out imagePixels))
            {
                Parallel.For(firstSymbol, lastSymbolExclusive,
                             index =>
                {
                    var cellX = index % ColumnsCount;
                    var cellY = index / ColumnsCount;
                    var point = new Point(cellX * CellSize, cellY * CellSize - VerticalShift);

                    if (index >= Controller.AvailableSymbols.Count)
                    {
                        SymbolsPainter.PaintSymbol(' ', imagePixels, VisualImage.Size, point, clipRect, PlainFontColor, PlainBackground);
                    }
                    else
                    {
                        var symbolSelectionPair = Controller.AvailableSymbols[index];

                        var highlight = cellX == HighlightedCell.X && cellY == HighlightedCell.Y;
                        int background, fontColor;
                        if (symbolSelectionPair.Value)
                        {
                            background = highlight ? HighlightedSelectedBackground : SelectedBackground;
                            fontColor  = highlight ? HighlightedSelectedFontColor : SelectedFontColor;
                        }
                        else
                        {
                            background = highlight ? HighlightedPlainBackground : PlainBackground;
                            fontColor  = highlight ? HighlightedPlainFontColor : PlainFontColor;
                        }

                        SymbolsPainter.PaintSymbol(symbolSelectionPair.Key, imagePixels, VisualImage.Size, point, clipRect, fontColor, background);
                    }
                });
            }
        }
예제 #4
0
        public void DetachVisual(VisualImage source)
        {
            if (_floatingVisual != null)
            {
                throw new InvalidOperationException("A floating visual is already in use");
            }

            _floatingVisual       = source.ForegroundVisual.Compositor.CreateSpriteVisual();
            _floatingVisual.Size  = source.ForegroundVisual.Size;
            _floatingVisual.Brush = source.ForegroundVisual.Brush;

            // Determine the offset from the host to the source element used in the transition
            var coordinate = source.TransformToVisual(_hostFrame);
            var position   = coordinate.TransformPoint(new Point(0, 0));

            // Set the sprite to that offset relative to the host
            _floatingVisual.Offset = new Vector3((float)position.X + source.ForegroundVisual.Offset.X,
                                                 (float)position.Y + source.ForegroundVisual.Offset.Y, 0);
            _floatingVisualUri = source.ImageUri;

            // Set the sprite as the content under the host
            ElementCompositionPreview.SetElementChildVisual(_hostFrame, _floatingVisual);
        }
        private static void ToggleHorizontalAlignment(VisualImage visualImage)
        {
            switch (visualImage.ImageHorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                visualImage.ImageHorizontalAlignment = HorizontalAlignment.Center;
                break;

            case HorizontalAlignment.Center:
                visualImage.ImageHorizontalAlignment = HorizontalAlignment.Right;
                break;

            case HorizontalAlignment.Right:
                visualImage.ImageHorizontalAlignment = HorizontalAlignment.Left;
                break;

            case HorizontalAlignment.Stretch:
                visualImage.ImageHorizontalAlignment = HorizontalAlignment.Left;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }