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 UpdateAlpha()
 {
     if (colorPicker != null)
     {
         if (colorPicker.SelectedBrush is GeoSolidBrush)
         {
             colorPicker.SelectedBrush = new GeoSolidBrush(GeoColor.FromArgb(Alpha, ((GeoSolidBrush)SelectedBrush).Color.RedComponent, ((GeoSolidBrush)SelectedBrush).Color.GreenComponent, ((GeoSolidBrush)SelectedBrush).Color.BlueComponent));
         }
         else if (colorPicker.SelectedBrush is GeoLinearGradientBrush)
         {
             GeoLinearGradientBrush gradientBrush = (GeoLinearGradientBrush)colorPicker.SelectedBrush;
             colorPicker.SelectedBrush = new GeoLinearGradientBrush(GeoColor.FromArgb(Alpha, gradientBrush.StartColor.RedComponent, gradientBrush.StartColor.GreenComponent, gradientBrush.StartColor.BlueComponent), gradientBrush.EndColor, gradientBrush.DirectionAngle);
         }
         else if (colorPicker.SelectedBrush is GeoHatchBrush)
         {
             GeoHatchBrush geoHatchBrush      = (GeoHatchBrush)colorPicker.SelectedBrush;
             GeoColor      newForegroundColor = new GeoColor(Alpha, geoHatchBrush.ForegroundColor.RedComponent, geoHatchBrush.ForegroundColor.GreenComponent, geoHatchBrush.ForegroundColor.BlueComponent);
             GeoColor      newBackgroundColor = new GeoColor(Alpha, geoHatchBrush.BackgroundColor.RedComponent, geoHatchBrush.BackgroundColor.GreenComponent, geoHatchBrush.BackgroundColor.BlueComponent);
             colorPicker.SelectedBrush = new GeoHatchBrush(geoHatchBrush.HatchStyle, newForegroundColor, newBackgroundColor);
         }
         RefreshPreviews();
     }
 }
Example #3
0
        protected override void DrawAreaCore(IEnumerable <ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            if (fillBrush == null)
            {
                fillBrush = new GeoSolidBrush(GeoColor.SimpleColors.Transparent);
            }

            int id = 0;

            if (outlinePen != null)
            {
                id = outlinePen.GetHashCode();
            }
            else if (fillBrush != null)
            {
                id = id ^ fillBrush.GetHashCode();
            }

            if (!styleUrlDictionary.ContainsKey(id))
            {
                GeoSolidBrush          brush         = fillBrush as GeoSolidBrush;
                GeoLinearGradientBrush gradientBrush = fillBrush as GeoLinearGradientBrush;
                GeoHatchBrush          hatchBrush    = fillBrush as GeoHatchBrush;
                string kmlStyle = string.Empty;
                if (gradientBrush != null)
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, gradientBrush.StartColor);
                }
                else if (hatchBrush != null)
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, hatchBrush.BackgroundColor);
                }
                else
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, brush.Color);
                }
                kmlBuilder.Append(kmlStyle);
                styleUrlDictionary.Add(id, string.Format("<styleUrl>#{0}</styleUrl>", id));
            }

            StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);

            contentStringBuilder.AppendLine();
            contentStringBuilder.AppendLine(@"<Placemark>");
            contentStringBuilder.AppendLine(styleUrlDictionary[id]);
            contentStringBuilder.AppendLine(@"<Polygon>");

            contentStringBuilder.AppendLine(extrudeString);
            contentStringBuilder.AppendLine(tessellateString);
            contentStringBuilder.AppendLine(altitudeModeString);

            bool firstCoordinates = true;

            foreach (ScreenPointF[] screenPoint in screenPoints)
            {
                if (firstCoordinates)
                {
                    contentStringBuilder.AppendLine(@"<outerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</outerBoundaryIs>");
                    firstCoordinates = false;
                }
                else
                {
                    contentStringBuilder.AppendLine(@"<innerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</innerBoundaryIs>");
                }
            }
            contentStringBuilder.AppendLine(@"</Polygon>");
            contentStringBuilder.AppendLine(@"</Placemark>");

            foreach (ScreenPointF[] screenPoint in screenPoints)
            {
                switch (Mode)
                {
                case AltitudeMode.Absolute:
                case AltitudeMode.RelativeToGround:
                    contentStringBuilder.AppendLine(@"<Placemark>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, ZHeight, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</Placemark>");
                    break;

                default:
                    break;
                }
            }
        }
Example #4
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 #5
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();
            }
        }
Example #6
0
        private static GeoCustomStyle GetGeoCustomStyle(GeoHatchBrush geoHatchBrush)
        {
            GeoCustomStyle geoCustomStyle = GeoCustomStyle.None;

            switch (geoHatchBrush.HatchStyle)
            {
            case GeoHatchStyle.BackwardDiagonal:
                geoCustomStyle = GeoCustomStyle.BackwardDiagonal;
                break;

            case GeoHatchStyle.Cross:
                geoCustomStyle = GeoCustomStyle.Cross;
                break;

            case GeoHatchStyle.DarkDownwardDiagonal:
                geoCustomStyle = GeoCustomStyle.DarkDownwardDiagonal;
                break;

            case GeoHatchStyle.DarkHorizontal:
                geoCustomStyle = GeoCustomStyle.DarkHorizontal;
                break;

            case GeoHatchStyle.DarkUpwardDiagonal:
                geoCustomStyle = GeoCustomStyle.DarkUpwardDiagonal;
                break;

            case GeoHatchStyle.DarkVertical:
                geoCustomStyle = GeoCustomStyle.DarkVertical;
                break;

            case GeoHatchStyle.DashedDownwardDiagonal:
                geoCustomStyle = GeoCustomStyle.DashedDownwardDiagonal;
                break;

            case GeoHatchStyle.DashedHorizontal:
                geoCustomStyle = GeoCustomStyle.DashedHorizontal;
                break;

            case GeoHatchStyle.DashedUpwardDiagonal:
                geoCustomStyle = GeoCustomStyle.DashedUpwardDiagonal;
                break;

            case GeoHatchStyle.DashedVertical:
                geoCustomStyle = GeoCustomStyle.DashedVertical;
                break;

            case GeoHatchStyle.DiagonalBrick:
                geoCustomStyle = GeoCustomStyle.DiagonalBrick;
                break;

            case GeoHatchStyle.DiagonalCross:
                geoCustomStyle = GeoCustomStyle.DiagonalCross;
                break;

            case GeoHatchStyle.Divot:
                geoCustomStyle = GeoCustomStyle.Divot;
                break;

            case GeoHatchStyle.DottedDiamond:
                geoCustomStyle = GeoCustomStyle.DottedDiamond;
                break;

            case GeoHatchStyle.DottedGrid:
                geoCustomStyle = GeoCustomStyle.DottedGrid;
                break;

            case GeoHatchStyle.ForwardDiagonal:
                geoCustomStyle = GeoCustomStyle.ForwardDiagonal;
                break;

            case GeoHatchStyle.Horizontal:
                geoCustomStyle = GeoCustomStyle.Horizontal;
                break;

            case GeoHatchStyle.HorizontalBrick:
                geoCustomStyle = GeoCustomStyle.HorizontalBrick;
                break;

            case GeoHatchStyle.LargeCheckerBoard:
                geoCustomStyle = GeoCustomStyle.LargeCheckerBoard;
                break;

            case GeoHatchStyle.LargeConfetti:
                geoCustomStyle = GeoCustomStyle.LargeConfetti;
                break;

            case GeoHatchStyle.LargeGrid:
                geoCustomStyle = GeoCustomStyle.LargeGrid;
                break;

            case GeoHatchStyle.LightDownwardDiagonal:
                geoCustomStyle = GeoCustomStyle.LightDownwardDiagonal;
                break;

            case GeoHatchStyle.LightHorizontal:
                geoCustomStyle = GeoCustomStyle.LightHorizontal;
                break;

            case GeoHatchStyle.LightUpwardDiagonal:
                geoCustomStyle = GeoCustomStyle.LightUpwardDiagonal;
                break;

            case GeoHatchStyle.LightVertical:
                geoCustomStyle = GeoCustomStyle.LightVertical;
                break;

            case GeoHatchStyle.Max:
                geoCustomStyle = GeoCustomStyle.Max;
                break;

            case GeoHatchStyle.Min:
                geoCustomStyle = GeoCustomStyle.Min;
                break;

            case GeoHatchStyle.NarrowHorizontal:
                geoCustomStyle = GeoCustomStyle.NarrowHorizontal;
                break;

            case GeoHatchStyle.NarrowVertical:
                geoCustomStyle = GeoCustomStyle.NarrowVertical;
                break;

            case GeoHatchStyle.OutlinedDiamond:
                geoCustomStyle = GeoCustomStyle.OutlinedDiamond;
                break;

            case GeoHatchStyle.Percent05:
                geoCustomStyle = GeoCustomStyle.Percent05;
                break;

            case GeoHatchStyle.Percent10:
                geoCustomStyle = GeoCustomStyle.Percent10;
                break;

            case GeoHatchStyle.Percent20:
                geoCustomStyle = GeoCustomStyle.Percent20;
                break;

            case GeoHatchStyle.Percent25:
                geoCustomStyle = GeoCustomStyle.Percent25;
                break;

            case GeoHatchStyle.Percent30:
                geoCustomStyle = GeoCustomStyle.Percent30;
                break;

            case GeoHatchStyle.Percent40:
                geoCustomStyle = GeoCustomStyle.Percent40;
                break;

            case GeoHatchStyle.Percent50:
                geoCustomStyle = GeoCustomStyle.Percent50;
                break;

            case GeoHatchStyle.Percent60:
                geoCustomStyle = GeoCustomStyle.Percent60;
                break;

            case GeoHatchStyle.Percent70:
                geoCustomStyle = GeoCustomStyle.Percent70;
                break;

            case GeoHatchStyle.Percent75:
                geoCustomStyle = GeoCustomStyle.Percent75;
                break;

            case GeoHatchStyle.Percent80:
                geoCustomStyle = GeoCustomStyle.Percent80;
                break;

            case GeoHatchStyle.Percent90:
                geoCustomStyle = GeoCustomStyle.Percent90;
                break;

            case GeoHatchStyle.Plaid:
                geoCustomStyle = GeoCustomStyle.Plaid;
                break;

            case GeoHatchStyle.Shingle:
                geoCustomStyle = GeoCustomStyle.Shingle;
                break;

            case GeoHatchStyle.SmallCheckerBoard:
                geoCustomStyle = GeoCustomStyle.SmallCheckerBoard;
                break;

            case GeoHatchStyle.SmallConfetti:
                geoCustomStyle = GeoCustomStyle.SmallConfetti;
                break;

            case GeoHatchStyle.SmallGrid:
                geoCustomStyle = GeoCustomStyle.SmallGrid;
                break;

            case GeoHatchStyle.SolidDiamond:
                geoCustomStyle = GeoCustomStyle.SolidDiamond;
                break;

            case GeoHatchStyle.Sphere:
                geoCustomStyle = GeoCustomStyle.Sphere;
                break;

            case GeoHatchStyle.Trellis:
                geoCustomStyle = GeoCustomStyle.Trellis;
                break;

            case GeoHatchStyle.Vertical:
                geoCustomStyle = GeoCustomStyle.Vertical;
                break;

            case GeoHatchStyle.Wave:
                geoCustomStyle = GeoCustomStyle.Wave;
                break;

            case GeoHatchStyle.Weave:
                geoCustomStyle = GeoCustomStyle.Weave;
                break;

            case GeoHatchStyle.WideDownwardDiagonal:
                geoCustomStyle = GeoCustomStyle.WideDownwardDiagonal;
                break;

            case GeoHatchStyle.WideUpwardDiagonal:
                geoCustomStyle = GeoCustomStyle.WideUpwardDiagonal;
                break;

            case GeoHatchStyle.ZigZag:
                geoCustomStyle = GeoCustomStyle.ZigZag;
                break;

            default:
                geoCustomStyle = GeoCustomStyle.None;
                break;
            }
            return(geoCustomStyle);
        }