Ejemplo n.º 1
0
        public void SelectTiles(Point pixelPoint1, Point pixelPoint2)
        {
            pixelPoint1 = this.TilesetModel.Value.GetPoint(pixelPoint1);
            pixelPoint2 = this.TilesetModel.Value.GetPoint(pixelPoint2);
            GeneralTransform pixelToTile  = GeometryUtils.CreateTransform(this.itemTransform.pixelToTile);
            Point            tile1        = GeometryUtils.TransformInt(pixelToTile, pixelPoint1);
            Point            tile2        = GeometryUtils.TransformInt(pixelToTile, pixelPoint2);
            Point            topLeftTile  = GeometryUtils.TopLeftPoint(tile1, tile2);
            Point            topLeftPixel = GeometryUtils.TransformInt(pixelToTile.Inverse, topLeftTile);
            Size             tileSize     = GeometryUtils.ComputeSize(tile1, tile2);
            Size             pixelSize    = GeometryUtils.TransformInt(pixelToTile.Inverse, tileSize);

            DrawSelectLinesFromPixels(topLeftPixel, pixelSize);

            PaddedBrushModel brushModel = new PaddedBrushModel(this.TilesetModel.Value, (int)topLeftTile.X, (int)topLeftTile.Y);

            brushModel.SetSize(tileSize);
            Mat croppedImage = BrushUtils.CropImage(this.ItemImage.Value, topLeftPixel, pixelSize);

            if (this.TilesetModel.Value.IsTransparent.Value)
            {
                croppedImage = ImageUtils.ColorToTransparent(croppedImage, this.TilesetModel.Value.TransparentColor.Value);
            }
            brushModel.TileImage(croppedImage, topLeftPixel, this.TilesetModel.Value);

            this.eventAggregator.GetEvent <NewPaddedBrushEvent>().Publish(brushModel);
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var direction   = values[0] as ProgressDirection? ?? ProgressDirection.LeftToRight;
            var min         = values[1] as double? ?? 0;
            var max         = values[2] as double? ?? 0;
            var value       = values[3] as double? ?? 0;
            var totalWidth  = ((direction == ProgressDirection.LeftToRight || direction == ProgressDirection.RightToLeft) ? values[4] : values[5]) as double? ?? 0;
            var actualWidth = ((direction == ProgressDirection.LeftToRight || direction == ProgressDirection.RightToLeft) ? values[6] : values[7]) as double? ?? 0;
            var foreground  = values[8] as Brush;

            if (totalWidth == 0 || actualWidth == 0)
            {
                return(foreground);
            }

            var totalPercent = ((value - min) / (max - min));
            var percentWidth = totalWidth * totalPercent;
            var innerWidth   = percentWidth - ((totalWidth - actualWidth) / 2);

            if (innerWidth <= 0)
            {
                return(foreground);
            }
            else if (innerWidth >= actualWidth)
            {
                return(Brushes.White);
            }

            var innerPercent = innerWidth / actualWidth;

            switch (direction)
            {
            case ProgressDirection.RightToLeft:
                return(BrushUtils.GetStackedVisualBrush(foreground, Brushes.White, System.Windows.Controls.Orientation.Horizontal, 1 - innerPercent));

            case ProgressDirection.BottomToTop:
                return(BrushUtils.GetStackedVisualBrush(foreground, Brushes.White, System.Windows.Controls.Orientation.Vertical, 1 - innerPercent));

            case ProgressDirection.TopToBottom:
                return(BrushUtils.GetStackedVisualBrush(Brushes.White, foreground, System.Windows.Controls.Orientation.Vertical, innerPercent));

            default:
                return(BrushUtils.GetStackedVisualBrush(Brushes.White, foreground, System.Windows.Controls.Orientation.Horizontal, innerPercent));
            }
        }
Ejemplo n.º 3
0
        public ImageDrawing GetByID(int id, Point startPoint)
        {
            Point topLeftTile = GetPointByID(id);
            Size  sizeOfTile  = GetTileSize();

            RectangleGeometry geometry = new RectangleGeometry(new Rect(topLeftTile, sizeOfTile));

            Mat croppedImage = BrushUtils.CropImage(this.MatImage, topLeftTile, sizeOfTile);

            if (this.IsTransparent.Value)
            {
                croppedImage = ImageUtils.ColorToTransparent(croppedImage, this.TransparentColor.Value);
            }
            Rect         drawingRect = new Rect(startPoint, sizeOfTile);
            ImageDrawing drawing     = ImageUtils.MatToImageDrawing(croppedImage, drawingRect);

            return(drawing);
        }
Ejemplo n.º 4
0
        public object GetCurrentValue(Brush defaultOriginValue, Brush defaultDestinationValue, AnimationClock animationClock)
        {
            if (!animationClock.CurrentProgress.HasValue)
            {
                return(Brushes.Transparent);
            }

            defaultOriginValue      = this.From ?? defaultOriginValue;
            defaultDestinationValue = this.To ?? defaultDestinationValue;

            if (animationClock.CurrentProgress.Value == 0)
            {
                return(defaultOriginValue);
            }
            if (animationClock.CurrentProgress.Value == 1)
            {
                return(defaultDestinationValue);
            }

            if (To != null)
            {
                if (defaultDestinationValue is SolidColorBrush && ((SolidColorBrush)defaultDestinationValue).Color.A < 255 &&
                    (!(defaultOriginValue is SolidColorBrush) || (((SolidColorBrush)defaultOriginValue).Color.A == 255)))
                {
                    return(BrushUtils.GetVisualBrush(defaultDestinationValue, defaultOriginValue, 1 - animationClock.CurrentProgress.Value));
                }
                else
                {
                    return(BrushUtils.GetVisualBrush(defaultOriginValue, defaultDestinationValue, animationClock.CurrentProgress.Value));
                }
            }
            else
            {
                if (defaultOriginValue is SolidColorBrush && ((SolidColorBrush)defaultOriginValue).Color.A < 255 &&
                    (!(defaultDestinationValue is SolidColorBrush) || (((SolidColorBrush)defaultDestinationValue).Color.A == 255)))
                {
                    return(BrushUtils.GetVisualBrush(defaultOriginValue, defaultDestinationValue, animationClock.CurrentProgress.Value));
                }
                else
                {
                    return(BrushUtils.GetVisualBrush(defaultDestinationValue, defaultOriginValue, 1 - animationClock.CurrentProgress.Value));
                }
            }
        }
Ejemplo n.º 5
0
        public void TileImage(Mat tilesImage, Point pixelPoint, TilesetModel tilesetModel)
        {
            this.Tiles.Clear();
            int colCount = tilesImage.Cols / this.TileWidth.Value;
            int rowCount = tilesImage.Rows / this.TileHeight.Value;

            for (int rowIndex = 0; rowIndex < rowCount; ++rowIndex)
            {
                for (int colIndex = 0; colIndex < colCount; ++colIndex)
                {
                    Size         tileSize     = this.GetTileSize();
                    Point        topLeftPoint = new Point(colIndex * this.TileWidth.Value, rowIndex * this.TileHeight.Value);
                    Mat          tileImage    = BrushUtils.CropImage(tilesImage, topLeftPoint, tileSize);
                    Rect         drawingRect  = new Rect(topLeftPoint, tileSize);
                    ImageDrawing drawing      = ImageUtils.MatToImageDrawing(tileImage, drawingRect);

                    Point offsetPoint = Point.Add(pixelPoint, (Vector)topLeftPoint);
                    int   tileID      = tilesetModel.GetID(offsetPoint);
                    int   tilesetID   = tilesetModel.ID;
                    Tile  tile        = new Tile(drawing, tilesetID, tileID);
                    this.Tiles.Add(tile);
                }
            }
        }
Ejemplo n.º 6
0
        private static void OnHoverBrushPercentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var button = (RepeatButton)d;

            if (button == null)
            {
                return;
            }

            var buttonStyle = GetRepeatButtonStyle(button);

            var oldValue = (double)e.OldValue;
            var newValue = (double)e.NewValue;

            var previousForeground  = GetPreviousForeground(button);
            var previousBorderBrush = GetPreviousBorderBrush(button);
            var previousBackground  = GetPreviousBackground(button);

            var hoverBrush = GetHoverBrush(button);

            if (newValue == 0)
            {
                if (buttonStyle != RepeatButtonStyle.Standard)
                {
                    button.Foreground = previousForeground;
                }

                if (buttonStyle == RepeatButtonStyle.Standard || buttonStyle == RepeatButtonStyle.Hollow)
                {
                    button.Background = previousBackground;
                }

                button.BorderBrush = previousBorderBrush;
                return;
            }
            if (oldValue == 0)
            {
                previousForeground  = button.Foreground;
                previousBorderBrush = button.BorderBrush;
                previousBackground  = button.Background;

                SetPreviousForeground(button, previousForeground);
                SetPreviousBorderBrush(button, previousBorderBrush);
                SetPreviousBackground(button, previousBackground);
            }

            if (buttonStyle == RepeatButtonStyle.Standard || buttonStyle == RepeatButtonStyle.Hollow)
            {
                button.Background = BrushUtils.GetBrush(newValue, previousBackground, hoverBrush);
            }

            if (buttonStyle == RepeatButtonStyle.Hollow)
            {
                button.Foreground = BrushUtils.GetBrush(newValue, previousForeground, Brushes.White);
            }
            else if (buttonStyle != RepeatButtonStyle.Standard)
            {
                button.Foreground = BrushUtils.GetBrush(newValue, previousForeground, hoverBrush);
            }

            button.BorderBrush = BrushUtils.GetBrush(newValue, previousBorderBrush, hoverBrush);
        }
Ejemplo n.º 7
0
 public static SolidColorBrush CloneBrush(this SolidColorBrush brush)
 {
     return(BrushUtils.CloneBrush(brush));
 }