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); } }
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(); } }
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; } } }
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); } } }
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(); } }