Example #1
0
        private void ChangeColorFromColorPicker(Control colorPicker, EventArgs e)
        {
            if (colorPicker is SolidColorPicker)
            {
                SolidColorPicker solidColorPicker = (SolidColorPicker)colorPicker;
                Color            newColor         = solidColorPicker.SelectedColor;
                GeoColor         newGeoColor      = GeoColor2MediaColorConverter.ConvertBack(newColor);

                hatchColorPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));
                gradientPicker.SyncBaseColor(DrawingColorToMediaColorConverter.ConvertBack(newColor));

                SelectedBrush = new GeoSolidBrush(newGeoColor);
            }
            else if (colorPicker is HatchPicker)
            {
                HatchPicker hatchPicker = (HatchPicker)colorPicker;
                System.Drawing.Drawing2D.HatchStyle drawingHatchStyle = hatchPicker.SelectedHatchStyle;
                GeoHatchStyle geoHatchStyle = GeoHatchStyle2DrawingHatchStyle.ConvertBack(drawingHatchStyle);

                //solidColorPicker.SyncBaseColor(hatchPicker.ForegroundColor);
                gradientPicker.SyncBaseColor(hatchPicker.ForegroundColor);

                SelectedBrush = new GeoHatchBrush(geoHatchStyle, GeoColor2DrawingColorConverter.ConvertBack(hatchPicker.ForegroundColor)
                                                  , GeoColor2DrawingColorConverter.ConvertBack(hatchColorPicker.BackgroundColor));
            }
            else if (colorPicker is TexturePicker)
            {
                PropertyChangedEventArgs args          = (PropertyChangedEventArgs)e;
                TexturePicker            texturePicker = (TexturePicker)colorPicker;
                if (args.PropertyName == "SelectedBrush")
                {
                    ImageBrush mediaBrush = texturePicker.SelectedBrush as ImageBrush;
                    if (mediaBrush != null)
                    {
                        BitmapImage imageSource = (BitmapImage)mediaBrush.ImageSource;
                        if (imageSource != null)
                        {
                            SelectedBrush = new GeoTextureBrush(new GeoImage(imageSource.UriSource.LocalPath));
                        }
                    }
                }
            }
            else if (colorPicker is DrawingLinearGradientBrushPicker)
            {
                DrawingLinearGradientBrushPicker linearPicker = (DrawingLinearGradientBrushPicker)colorPicker;
                LinearGradientBrushEntity        brushEntity  = linearPicker.SelectedBrush;

                solidColorPicker.SyncBaseColor(brushEntity.StartColor);
                hatchColorPicker.SyncBaseColor(brushEntity.StartColor);

                SelectedBrush = new GeoLinearGradientBrush(GeoColor2DrawingColorConverter.ConvertBack(brushEntity.StartColor),
                                                           GeoColor2DrawingColorConverter.ConvertBack(brushEntity.EndColor),
                                                           brushEntity.Angle);
            }
        }
Example #2
0
        private void SetSelectedBrush(GeoBrush geoBrush)
        {
            if (!isTemplateApplied)
            {
                return;
            }

            if (geoBrush is GeoSolidBrush)
            {
                SelectTabItem(solidColorBrushTabItem);
                Color selectedMediaColor = GeoColor2MediaColorConverter.Convert(((GeoSolidBrush)geoBrush).Color);
                if (solidColorPicker.SelectedColor != selectedMediaColor)
                {
                    solidColorPicker.SelectedColor = selectedMediaColor;
                }
            }
            else if (geoBrush is GeoLinearGradientBrush)
            {
                SelectTabItem(gradientTabItem);
                GeoLinearGradientBrush geoGradientBrush  = (GeoLinearGradientBrush)geoBrush;
                System.Drawing.Color   drawingStartColor = GeoColor2DrawingColorConverter.Convert(geoGradientBrush.StartColor);
                System.Drawing.Color   drawingEndColor   = GeoColor2DrawingColorConverter.Convert(geoGradientBrush.EndColor);

                if (gradientPicker.SelectedBrush.StartColor != drawingStartColor ||
                    gradientPicker.SelectedBrush.EndColor != drawingEndColor ||
                    gradientPicker.SelectedBrush.Angle - geoGradientBrush.DirectionAngle > 1)
                {
                    gradientPicker.SelectedBrush = new LinearGradientBrushEntity
                    {
                        StartColor = drawingStartColor,
                        EndColor   = drawingEndColor,
                        Angle      = (int)geoGradientBrush.DirectionAngle
                    }
                }
                ;
            }
            else if (geoBrush is GeoHatchBrush)
            {
                GeoHatchBrush geoHatchBrush = (GeoHatchBrush)geoBrush;
                SelectTabItem(hatchBrushTabItem);
                System.Drawing.Drawing2D.HatchStyle drawingHatchStyle = GeoHatchStyle2DrawingHatchStyle.Convert(geoHatchBrush.HatchStyle);
                System.Drawing.Color drawingBackgroundColor           = GeoColor2DrawingColorConverter.Convert(geoHatchBrush.BackgroundColor);
                System.Drawing.Color drawingForegroundColor           = GeoColor2DrawingColorConverter.Convert(geoHatchBrush.ForegroundColor);

                if (hatchColorPicker.SelectedHatchStyle != drawingHatchStyle ||
                    drawingBackgroundColor != hatchColorPicker.BackgroundColor ||
                    drawingForegroundColor != hatchColorPicker.ForegroundColor)
                {
                    hatchColorPicker.BackgroundColor    = drawingBackgroundColor;
                    hatchColorPicker.ForegroundColor    = drawingForegroundColor;
                    hatchColorPicker.SelectedHatchStyle = drawingHatchStyle;
                }
            }
            else if (geoBrush is GeoTextureBrush)
            {
                SelectTabItem(textureTabItem);
                textureTabItem.IsSelected = true;
                GeoTextureBrush geoTextureBrush = (GeoTextureBrush)geoBrush;
                if (textureColorPicker.SelectedBrush == null || !textureColorPicker.SelectedBrush.GetValue(Canvas.TagProperty).Equals(geoTextureBrush.GeoImage.GetPathFilename()))
                {
                    textureColorPicker.SelectedBrush = GeoTextureBrushToImageBrushConverter.Convert(geoTextureBrush);
                }
            }
        }
Example #3
0
        private void RefreshPreviews()
        {
            System.Drawing.Bitmap bitmap       = new System.Drawing.Bitmap(20, 20);
            MemoryStream          streamSource = new MemoryStream();

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

            try
            {
                if (SelectedBrush is GeoSolidBrush)
                {
                    GeoColor geoColor = ((GeoSolidBrush)SelectedBrush).Color;
                    Alpha = geoColor.AlphaComponent;
                    ((GeoSolidBrush)SelectedBrush).Color = new GeoColor(Alpha, ((GeoSolidBrush)SelectedBrush).Color);
                    geoColor = ((GeoSolidBrush)SelectedBrush).Color;

                    PreviewSourceName = Color.FromArgb(geoColor.AlphaComponent, geoColor.RedComponent, geoColor.GreenComponent, geoColor.BlueComponent).ToString();
                    g.FillRectangle(new System.Drawing.SolidBrush(GeoColor2DrawingColorConverter.Convert(geoColor)), new System.Drawing.Rectangle(0, 0, 20, 20));
                }
                else if (SelectedBrush is GeoHatchBrush)
                {
                    PreviewSourceName = ((GeoHatchBrush)SelectedBrush).HatchStyle.ToString();
                    GeoHatchBrush geoHatchBrush = (GeoHatchBrush)SelectedBrush;
                    Alpha = geoHatchBrush.ForegroundColor.AlphaComponent;
                    System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush(
                        GeoHatchStyle2DrawingHatchStyle.Convert(geoHatchBrush.HatchStyle),
                        GeoColor2DrawingColorConverter.Convert(geoHatchBrush.ForegroundColor),
                        GeoColor2DrawingColorConverter.Convert(geoHatchBrush.BackgroundColor));

                    g.FillRectangle(hatchBrush, new System.Drawing.Rectangle(0, 0, 20, 20));
                }
                else if (SelectedBrush is GeoTextureBrush)
                {
                    string fileName = ((GeoTextureBrush)SelectedBrush).GeoImage.GetPathFilename();
                    PreviewSourceName = new System.IO.FileInfo(fileName).Name;
                    System.Drawing.Image im = System.Drawing.Image.FromStream(((GeoTextureBrush)SelectedBrush).GeoImage.GetImageStream(new PlatformGeoCanvas()));
                    g.DrawImage(im, new System.Drawing.Rectangle(0, 0, 20, 20));
                }
                else if (SelectedBrush is GeoLinearGradientBrush)
                {
                    GeoLinearGradientBrush gradientBrush = (GeoLinearGradientBrush)SelectedBrush;
                    Alpha             = gradientBrush.StartColor.AlphaComponent;
                    PreviewSourceName = String.Format("Gradients Angle:{2}",
                                                      GeoColor2MediaColorConverter.Convert(gradientBrush.StartColor),
                                                      GeoColor2MediaColorConverter.Convert(gradientBrush.EndColor),
                                                      gradientBrush.DirectionAngle);
                    System.Drawing.Drawing2D.LinearGradientBrush drawingGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
                        new System.Drawing.Rectangle(0, 0, 20, 20),
                        GeoColor2DrawingColorConverter.Convert(gradientBrush.StartColor),
                        GeoColor2DrawingColorConverter.Convert(gradientBrush.EndColor),
                        gradientBrush.DirectionAngle);

                    g.FillRectangle(drawingGradientBrush, new System.Drawing.Rectangle(0, 0, 20, 20));
                }

                g.Flush();
                bitmap.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png);
                streamSource.Seek(0, SeekOrigin.Begin);
                BitmapImage imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.StreamSource = streamSource;
                imageSource.EndInit();
                imageSource.Freeze();

                PreviewSource = imageSource;
            }
            finally
            {
                bitmap.Dispose();
                g.Dispose();
            }
        }