Exemplo n.º 1
0
        private static void DrawStyleSamples(Style style, int width, int height, PlatformGeoCanvas canvas)
        {
            var drawingRectangleF = new DrawingRectangleF(width * .5f, height * .5f, width, height);

            if (style is CompositeStyle)
            {
                foreach (var subStyle in ((CompositeStyle)style).Styles)
                {
                    DrawStyleSamples(subStyle, width, height, canvas);
                }
            }
            else if (style is ClassBreakStyle || style is ValueStyle || style is FilterStyle)
            {
                style.DrawSample(canvas, drawingRectangleF);
            }
            else if (style is DotDensityStyle)
            {
                var dotDensityStyle = ((DotDensityStyle)style).CustomPointStyle;
                DrawDotDensityStyle(dotDensityStyle, canvas, drawingRectangleF);
            }

            //RegexStyle is the Filter Style in Gis Editor
            else if (style is RegexStyle)
            {
                DrawStaticImage(canvas, "pack://,,,/GisEditorPluginCore;component/Images/FilterStyle.png", drawingRectangleF);
            }
            else
            {
                DrawNormalStyle(style, canvas, drawingRectangleF);
            }
        }
Exemplo n.º 2
0
        protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font)
        {
            Font f                = new Font(new FontFamily("Arial"), font.Size);
            Size size             = TextRenderer.MeasureText(text, f);
            DrawingRectangleF drf = new DrawingRectangleF(0, 0, size.Width, size.Height);

            return(drf);
        }
Exemplo n.º 3
0
 public static DrawingRectangleF ScaleRectangle(ref DrawingRectangleF rect, ref float amount)
 {
     return new DrawingRectangleF(
         rect.X + rect.Width * (1 - amount) / 2,
         rect.Y + rect.Height * (1 - amount) / 2,
         rect.Width * amount,
         rect.Height * amount);
 }
Exemplo n.º 4
0
        private static void DrawStaticImage(PlatformGeoCanvas canvas, string uri, DrawingRectangleF drawingRectangleF)
        {
            var streamInfo = System.Windows.Application.GetResourceStream(new Uri(uri, UriKind.RelativeOrAbsolute));

            if (streamInfo != null && streamInfo.Stream != null)
            {
                canvas.DrawScreenImage(new GeoImage(streamInfo.Stream), drawingRectangleF.CenterX, drawingRectangleF.CenterY, drawingRectangleF.Width, drawingRectangleF.Height, DrawingLevel.LevelOne, 0, 0, 0);
            }
        }
Exemplo n.º 5
0
        private RectangleShape ToWorldCoordinate(GeoCanvas canvas, DrawingRectangleF drawingRectangle)
        {
            PointShape upperLeftPoint  = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingRectangle.CenterX - drawingRectangle.Width / 2, drawingRectangle.CenterY - drawingRectangle.Height / 2, canvas.Width, canvas.Height);
            PointShape lowerRightPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingRectangle.CenterX + drawingRectangle.Width / 2, drawingRectangle.CenterY + drawingRectangle.Height / 2, canvas.Width, canvas.Height);

            RectangleShape worldRectangle = new RectangleShape(upperLeftPoint, lowerRightPoint);

            return(worldRectangle);
        }
        protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            TextStyle         textStyle   = GetTextStyle();
            DrawingRectangleF rect        = canvas.MeasureText(Title, TitleFont);
            ScreenPointF      screenPintF = GetDrawingLocation(canvas, rect.Width, rect.Height);

            float centerX = screenPintF.X;

            if (Location != AdornmentLocation.Center && Location != AdornmentLocation.LowerCenter && Location != AdornmentLocation.UpperCenter)
            {
                centerX += (float)(rect.Width * 0.5);
            }
            textStyle.DrawSample(canvas, new DrawingRectangleF(centerX, screenPintF.Y + (float)(rect.Height * 0.5), canvas.Width, canvas.Height));
        }
Exemplo n.º 7
0
        private static string WrapText(GeoCanvas canvas, RectangleShape drawingBoundingBox, GeoFont drawingFont, string text)
        {
            StringBuilder sb = new StringBuilder();

            //ScreenPointF textCenterOnScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.GetCenterPoint(), canvas.Width, canvas.Height);
            DrawingRectangleF drawingRect        = canvas.MeasureText(text, drawingFont);
            ScreenPointF      upperLeftOnScreen  = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.UpperLeftPoint, canvas.Width, canvas.Height);
            ScreenPointF      lowerRightOnScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.UpperRightPoint, canvas.Width, canvas.Height);
            int drawingRectWidthOnScreen         = (int)(lowerRightOnScreen.X - upperLeftOnScreen.X);

            Graphics  g         = Graphics.FromImage(new Bitmap(1, 1));
            FontStyle fontStyle = GetFontStyleFromDrawingFontStyle(drawingFont.Style);

            SizeF textSize = g.MeasureString(text, new Font(drawingFont.FontName, drawingFont.Size, fontStyle), new PointF(), StringFormat.GenericTypographic);

            if (drawingRect.Width > drawingRectWidthOnScreen)
            {
                text = text.Replace("\n", " ");
                text = text.Replace("\r", " ");
                text = text.Replace(".", ". ");
                text = text.Replace(">", "> ");
                text = text.Replace("\t", " ");
                text = text.Replace(",", ", ");
                text = text.Replace(";", "; ");
                text = text.Replace("<br>", " ");

                int      maxStringLength = GetMaxStringLength(text, textSize.Width, drawingRectWidthOnScreen);
                string[] texts           = Wrap(text, maxStringLength);
                foreach (string item in texts)
                {
                    if (item == "")
                    {
                        sb.Append(item);
                    }
                    else
                    {
                        sb.AppendLine(item);
                    }
                }
            }
            else
            {
                sb.Append(text);
            }

            return(sb.ToString());
        }
Exemplo n.º 8
0
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingRectangleF)
        {
            RectangleShape rectangle = ToWorldCoordinate(canvas, drawingRectangleF);

            Feature feature = new Feature(rectangle.GetCenterPoint());

            feature.ColumnValues.Add(TextColumnName, "A");
            Feature[] features = new Feature[1] {
                feature
            };
            IconTextStyle style = (IconTextStyle)CloneDeep();

            style.SuppressPartialLabels  = false;
            style.PointPlacement         = PointPlacement.Center;
            style.IsLabelFunctionEnabled = false;
            style.Draw(features, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
        }
Exemplo n.º 9
0
        public Notification(string message, DrawingRectangleF screenArea, NotificationType type = NotificationType.Message)
            : base()
        {
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(message), "Notification message should not be null or empty.");
            this.IsVisible = true;
            this.IsActive = true;
            this.IsRounded = false;
            this.LayoutOption = LayoutType.Vertical;
            this.ResizeOption = ResizeOptions.WrapChildren;
            this.HorizontalAlignment = Controls.HorizontalAlignment.Center;
            this.VerticalAlignment = Controls.VerticalAlignment.Center;
            this.DrawBackground = true;
            this.DrawBorder = true;
            _buttonAction = () => { this.Close(); };

            Position = screenArea.Position;
            Size = screenArea.Size;

            var label = new Label() {
                Text = message,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            label.Size = Size;
            AddControl(label);

            switch (type) {
                case NotificationType.Message:
                    var button = new Button(_buttonAction) {
                        Text = "Ok",
                        Size = new Vector2(this.Width / 4f, DEFAULT_BUTTON_HEIGHT),
                        VerticalAlignment = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Center
                    };
                    AddControl(button);
                    break;

                case NotificationType.Temporary:
                    this.Expires = true;
                    this.Duration = Notification.TemporaryNotificationDuration;
                    break;
            }
        }
Exemplo n.º 10
0
        public static SizeF Measure(this LegendItem legendItem, GeoCanvas geoCanvas)
        {
            DrawingRectangleF rect = geoCanvas.MeasureText(legendItem.TextStyle.TextColumnName, legendItem.TextStyle.Font);

            float width = rect.Width;

            width += legendItem.LeftPadding;
            width += legendItem.ImageLeftPadding;
            width += legendItem.ImageWidth;
            width += legendItem.ImageRightPadding;
            width += legendItem.TextLeftPadding;
            width += legendItem.TextRightPadding;
            width += legendItem.RightPadding;

            float imageHeight = legendItem.ImageTopPadding + legendItem.ImageHeight + legendItem.ImageBottomPadding;
            float textHeight  = legendItem.TextTopPadding + rect.Height + legendItem.TextBottomPadding;
            float height      = imageHeight > textHeight ? imageHeight : textHeight;

            return(new SizeF(width, height));
        }
Exemplo n.º 11
0
        private void ConvertTextToAnnotation(string valueStyleMatchColumnName, TextStyle textStyle, Feature feature, string annotationText)
        {
            PlatformGeoCanvas canvas = new PlatformGeoCanvas
            {
                CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed,
                DrawingQuality     = DrawingQuality.HighSpeed,
                SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed
            };

            double width       = GisEditor.ActiveMap.ActualWidth;
            double height      = GisEditor.ActiveMap.ActualHeight;
            Bitmap nativeImage = new Bitmap((int)width, (int)height);

            canvas.BeginDrawing(nativeImage, GisEditor.ActiveMap.CurrentExtent, GisEditor.ActiveMap.MapUnit);
            DrawingRectangleF rectangle = canvas.MeasureText(annotationText, textStyle.Font);

            Type       type   = textStyle.GetType();
            MethodInfo method = type.GetMethod("GetLabelingCandidates", BindingFlags.Instance | BindingFlags.NonPublic);

            if (method != null)
            {
                Collection <LabelingCandidate> candidates = method.Invoke(textStyle, new object[] { feature, canvas }) as Collection <LabelingCandidate>;
                if (candidates != null)
                {
                    foreach (var candidate in candidates)
                    {
                        foreach (var labelInfo in candidate.LabelInformation)
                        {
                            ScreenPointF point = new ScreenPointF((float)labelInfo.PositionInScreenCoordinates.X + rectangle.Width / 2 + 3, (float)labelInfo.PositionInScreenCoordinates.Y - rectangle.Height / 2);

                            PointShape pointShape   = ExtentHelper.ToWorldCoordinate(GisEditor.ActiveMap.CurrentExtent, point, (float)width, (float)height);
                            Feature    pointFeature = new Feature(pointShape);
                            pointFeature.Id = pointShape.Id;
                            pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.valueStyleMatchColumnName] = valueStyleMatchColumnName;
                            pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]  = annotationText;
                            CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures[pointShape.Id] = pointFeature;
                        }
                    }
                }
            }
        }
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingExtent)
        {
            base.DrawSampleCore(canvas, drawingExtent);
            PointShape upperLeftPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX - drawingExtent.Width / 2, drawingExtent.CenterY - drawingExtent.Height / 2, canvas.Width, canvas.Height);
            PointShape lowerRightPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX + drawingExtent.Width / 2, drawingExtent.CenterY + drawingExtent.Height / 2, canvas.Width, canvas.Height);
            RectangleShape rectangle = new RectangleShape(upperLeftPoint, lowerRightPoint);
            rectangle.ScaleDown(10);

            // Here draw the points on Legend Image
            Random random = new Random(DateTime.Now.Millisecond);
            Collection<BaseShape> drawingPoints = new Collection<BaseShape>();
            for (int i = 0; i < DrawingPointsNumber; i++)
            {
                double x = rectangle.LowerLeftPoint.X + random.NextDouble() * (rectangle.Width);
                double y = rectangle.LowerLeftPoint.Y + random.NextDouble() * (rectangle.Height);
                drawingPoints.Add(new PointShape(x, y));
            }
            TextStyle textStyle = new TextStyle(DrawingPointsNumber.ToString(), new GeoFont("Arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.FromArgb(180, GeoColor.FromHtml("#d3d3d3"))));
            textStyle.DrawSample(canvas, drawingExtent);
            CustomPointStyle.Draw(drawingPoints, canvas, new Collection<SimpleCandidate>(), new Collection<SimpleCandidate>());
        }
Exemplo n.º 13
0
        protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font)
        {
            Bitmap   bitmap   = null;
            Graphics graphics = null;
            SizeF    size;

            try
            {
                bitmap = new Bitmap(1, 1);
                bitmap.SetResolution(Dpi, Dpi);
                graphics = Graphics.FromImage(bitmap);

                size = graphics.MeasureString(text, GetGdiPlusFontFromGeoFont(font), new PointF(), StringFormat.GenericTypographic);
                if (size.Width == 0 && size.Height != 0 && text.Length != 0)
                {
                    size.Width = 1;
                }
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                size = new SizeF(1, 1);
            }
            finally
            {
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }

            DrawingRectangleF drawingRectangleF = new DrawingRectangleF(size.Width / 2, size.Height / 2, size.Width, size.Height);

            return(drawingRectangleF);
        }
Exemplo n.º 14
0
        private float GetFontSizeByBoundingBox(GeoCanvas canvas, GeoFont font, string drawingText, RectangleShape boundingBox)
        {
            float rtn = font.Size;

            ScreenPointF boundingBoxPointFUL = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.UpperLeftPoint, canvas.Width, canvas.Height);
            ScreenPointF boundingBoxPointFUR = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.UpperRightPoint, canvas.Width, canvas.Height);
            ScreenPointF boundingBoxPointFLL = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.LowerLeftPoint, canvas.Width, canvas.Height);

            double widthInScreen  = boundingBoxPointFUR.X - boundingBoxPointFUL.X;
            double heightInScreen = boundingBoxPointFLL.Y - boundingBoxPointFUL.Y;

            DrawingRectangleF textRectInScreen = canvas.MeasureText(drawingText, font);

            if (textRectInScreen.Width > widthInScreen || textRectInScreen.Height > heightInScreen)
            {
                while (textRectInScreen.Width > widthInScreen || textRectInScreen.Height > heightInScreen)
                {
                    rtn = rtn * 9 / 10;
                    textRectInScreen = canvas.MeasureText(drawingText, new GeoFont(font.FontName, rtn, font.Style));
                }
            }
            else
            {
                while (textRectInScreen.Width < widthInScreen && textRectInScreen.Height < heightInScreen)
                {
                    rtn = rtn * 10 / 9;
                    textRectInScreen = canvas.MeasureText(drawingText, new GeoFont(font.FontName, rtn, font.Style));
                }
                rtn = rtn * 9 / 10;
            }
            if (rtn > maxFontSize)
            {
                rtn = maxFontSize;
            }

            return(rtn);
        }
Exemplo n.º 15
0
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingExtent)
        {
            base.DrawSampleCore(canvas, drawingExtent);
            PointShape     upperLeftPoint  = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX - drawingExtent.Width / 2, drawingExtent.CenterY - drawingExtent.Height / 2, canvas.Width, canvas.Height);
            PointShape     lowerRightPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX + drawingExtent.Width / 2, drawingExtent.CenterY + drawingExtent.Height / 2, canvas.Width, canvas.Height);
            RectangleShape rectangle       = new RectangleShape(upperLeftPoint, lowerRightPoint);

            rectangle.ScaleDown(10);

            // Here draw the points on Legend Image
            Random random = new Random(DateTime.Now.Millisecond);
            Collection <BaseShape> drawingPoints = new Collection <BaseShape>();

            for (int i = 0; i < DrawingPointsNumber; i++)
            {
                double x = rectangle.LowerLeftPoint.X + random.NextDouble() * (rectangle.Width);
                double y = rectangle.LowerLeftPoint.Y + random.NextDouble() * (rectangle.Height);
                drawingPoints.Add(new PointShape(x, y));
            }
            TextStyle textStyle = new TextStyle(DrawingPointsNumber.ToString(), new GeoFont("Arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.FromArgb(180, GeoColor.FromHtml("#d3d3d3"))));

            textStyle.DrawSample(canvas, drawingExtent);
            CustomPointStyle.Draw(drawingPoints, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
        }
Exemplo n.º 16
0
        internal unsafe void DrawSprite(BaseTexture texture, CubeMapFace?face, ref DrawingRectangleF destination, bool scaleDestination, ref DrawingRectangle?sourceRectangle, Color color, float rotation, ref Vector2 origin, SpriteEffects effects, float depth)
        {
            // Check that texture is not null
            if (texture == null || texture.NativePointer == IntPtr.Zero)
            {
                throw new ArgumentNullException("texture");
            }

            // Make sure that Begin was called
            if (!isBeginCalled)
            {
                throw new InvalidOperationException("Begin must be called before draw");
            }

            // Resize the buffer of SpriteInfo
            if (spriteQueueCount >= spriteQueue.Length)
            {
                Array.Resize(ref spriteQueue, spriteQueue.Length * 2);
            }

            // Gets the resource information from the view (width, height).
            // Cache the result in order to avoid this request if the texture is reused
            // inside a same Begin/End block.
            TextureInfo textureInfo;

            if (!textureInfos.TryGetValue(texture.NativePointer.ToInt64(), out textureInfo))
            {
                textureInfo.Texture = texture;
                textureInfo.Face    = face;

                SurfaceDescription description2D;
                if (face.HasValue)
                {
                    Surface cubeSurface = ((CubeTexture)texture).GetCubeMapSurface(face.Value, 0);
                    description2D = cubeSurface.Description;
                    cubeSurface.Dispose();
                }
                else
                {
                    description2D = ((Texture)texture).GetLevelDescription(0);
                }

                textureInfo.Width  = description2D.Width;
                textureInfo.Height = description2D.Height;

                textureInfos.Add(texture.NativePointer.ToInt64(), textureInfo);
            }

            // Put values in next SpriteInfo
            fixed(SpriteInfo *spriteInfo = &(spriteQueue[spriteQueueCount]))
            {
                float width;
                float height;

                // If the source rectangle has a value, then use it.
                if (sourceRectangle.HasValue)
                {
                    DrawingRectangle rectangle = sourceRectangle.Value;
                    spriteInfo->Source.X = rectangle.X;
                    spriteInfo->Source.Y = rectangle.Y;
                    width  = rectangle.Width;
                    height = rectangle.Height;
                }
                else
                {
                    // Else, use directly the size of the texture
                    spriteInfo->Source.X = 0.0f;
                    spriteInfo->Source.Y = 0.0f;
                    width  = textureInfo.Width;
                    height = textureInfo.Height;
                }

                // Sets the width and height
                spriteInfo->Source.Width  = width;
                spriteInfo->Source.Height = height;

                // Scale the destination box
                if (scaleDestination)
                {
                    destination.Width  *= width;
                    destination.Height *= height;
                }

                // Sets the destination
                spriteInfo->Destination = destination;

                // Copy all other values.
                spriteInfo->Origin.X      = origin.X;
                spriteInfo->Origin.Y      = origin.Y;
                spriteInfo->Rotation      = rotation;
                spriteInfo->Depth         = depth;
                spriteInfo->SpriteEffects = effects;
                spriteInfo->Color         = color;
            }

            // If we are in immediate mode, render the sprite directly
            if (spriteSortMode == SpriteSortMode.Immediate)
            {
                DrawBatchPerTexture(ref textureInfo, spriteQueue, 0, 1);
            }
            else
            {
                if (spriteTextures.Length < spriteQueue.Length)
                {
                    Array.Resize(ref spriteTextures, spriteQueue.Length);
                }
                spriteTextures[spriteQueueCount] = textureInfo;
                spriteQueueCount++;
            }
        }
Exemplo n.º 17
0
        private static void DrawNormalStyle(this Style style, PlatformGeoCanvas canvas, DrawingRectangleF drawingRectangleF)
        {
            try
            {
                if (style is LineStyle)
                {
                    LineStyle lineStyle = (LineStyle)style;

                    if (lineStyle.CenterPen.Width <= 2 && lineStyle.InnerPen.Width <= 2 && lineStyle.OuterPen.Width <= 2)
                    {
                        lineStyle = (LineStyle)lineStyle.CloneDeep();

                        lineStyle.CenterPen.Width += 1;
                        lineStyle.InnerPen.Width  += 1;
                        lineStyle.OuterPen.Width  += 1;

                        LineShape line = GenerateStraightHorizontalLineShape(canvas.CurrentWorldExtent);
                        line.Rotate(line.GetCenterPoint(), 270);
                        lineStyle.Draw(new BaseShape[] { line }, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
                    }
                    else
                    {
                        lineStyle.DrawSample(canvas, drawingRectangleF);
                    }
                }
                else if (style is FontPointStyle)
                {
                    var fontStyle = (FontPointStyle)style;
                    var tmpsize   = fontStyle.CharacterFont.Size;
                    if (tmpsize > 26)
                    {
                        fontStyle.CharacterFont = new GeoFont(fontStyle.CharacterFont.FontName, 26, fontStyle.CharacterFont.Style);
                    }
                    fontStyle.DrawSample(canvas, drawingRectangleF);
                    if (tmpsize > 26)
                    {
                        fontStyle.CharacterFont = new GeoFont(fontStyle.CharacterFont.FontName, tmpsize, fontStyle.CharacterFont.Style);
                    }
                }
                else if (style is PointStyle)
                {
                    var pointStyle    = (PointStyle)style;
                    var tmpSymbolSize = pointStyle.SymbolSize;
                    if (tmpSymbolSize > 22)
                    {
                        pointStyle.SymbolSize = 22;
                    }
                    pointStyle.DrawSample(canvas, drawingRectangleF);
                    if (tmpSymbolSize > 22)
                    {
                        pointStyle.SymbolSize = tmpSymbolSize;
                    }
                }
                else if (style != null)
                {
                    style.DrawSample(canvas, drawingRectangleF);
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 18
0
        private static void DrawDotDensityStyle(PointStyle pointStyle, PlatformGeoCanvas canvas, DrawingRectangleF drawingRectangleF)
        {
            if (pointStyle == null)
            {
                return;
            }

            var    tmpSymbolSize     = pointStyle.SymbolSize;
            var    tmpSymbolPenWidth = pointStyle.SymbolPen.Width;
            var    tmpFontSize       = pointStyle.CharacterFont.Size;
            Bitmap originalBitmap    = null;
            Bitmap newBitmap         = null;

            try
            {
                var customerSymbolStyle = pointStyle as SymbolPointStyle;
                if (customerSymbolStyle != null)
                {
                    originalBitmap            = canvas.ToNativeImage(customerSymbolStyle.Image) as Bitmap;
                    newBitmap                 = new Bitmap(originalBitmap, 9, 9);
                    customerSymbolStyle.Image = canvas.ToGeoImage(newBitmap);
                }
                else
                {
                    pointStyle.SymbolSize      = 3;
                    pointStyle.SymbolPen.Width = 1;
                    pointStyle.CharacterFont   = new GeoFont(pointStyle.CharacterFont.FontName, 6, pointStyle.CharacterFont.Style);
                }

                var     halfWidth  = drawingRectangleF.Width * 0.5f;
                var     halfHeight = drawingRectangleF.Height * 0.5f;
                float[] centersX   = new float[7];
                float[] centersY   = new float[7];
                centersX[0] = halfWidth * 0.5f - 1;
                centersY[0] = halfHeight * 0.5f - 1;
                centersX[1] = centersX[0] + 2;
                centersY[1] = centersY[0] + 2;
                centersX[2] = halfWidth;
                centersY[2] = halfHeight;
                centersX[3] = halfWidth + halfWidth * 0.5f;
                centersY[3] = halfHeight;
                centersX[4] = halfWidth + halfWidth * 0.5f;
                centersY[4] = halfHeight + halfHeight * 0.5f;
                centersX[5] = centersX[4] - 1;
                centersY[5] = centersY[4] - 1;
                centersX[6] = centersX[4] + 1;
                centersY[6] = centersY[4] + 1;
                for (int i = 0; i < 7; i++)
                {
                    float centerX = centersX[i];
                    float centerY = centersY[i];
                    if (pointStyle != null)
                    {
                        pointStyle.DrawSample(canvas, new DrawingRectangleF(centerX, centerY, 11, 11));
                    }
                }

                if (originalBitmap != null)
                {
                    customerSymbolStyle.Image = canvas.ToGeoImage(originalBitmap);
                }
                else
                {
                    pointStyle.SymbolSize      = tmpSymbolSize;
                    pointStyle.SymbolPen.Width = tmpSymbolPenWidth;
                    pointStyle.CharacterFont   = new GeoFont(pointStyle.CharacterFont.FontName, tmpFontSize, pointStyle.CharacterFont.Style);
                }
            }
            finally
            {
                if (originalBitmap != null)
                {
                    originalBitmap.Dispose();
                }
                if (newBitmap != null)
                {
                    newBitmap.Dispose();
                }
            }
        }
Exemplo n.º 19
0
        public override void Update(long ticks)
        {
            base.Update(ticks);
            if (_recalculateGeometry) {
                if (_backgroundGeometry != null && !_backgroundGeometry.IsDisposed)
                    _backgroundGeometry.Dispose();

                var rect = new DrawingRectangleF(0f, 0f, Width, Height);
                if (IsRounded) {
                    _backgroundGeometry = new RoundedRectangleGeometry(_assetManager.Factory2D, new RoundedRectangle() {
                        Rect = rect,
                        RadiusX = ControlManager.Config.WindowCornerRadius,
                        RadiusY = ControlManager.Config.WindowCornerRadius
                    });
                } else {
                    _backgroundGeometry = new RectangleGeometry(_assetManager.Factory2D, rect);
                }
                _recalculateGeometry = false;
            }
            if (_hasTextChanged && !String.IsNullOrEmpty(_text)) {
                if (RenderedText != null && !RenderedText.IsDisposed)
                    RenderedText.Dispose();

                RenderedText = _assetManager.MakeTextLayout(Font.Resource, _text, Width, Height);
                RenderedText.TextAlignment = this.TextAlignment;
                RenderedText.ParagraphAlignment = this.ParagraphAlignment;
                _hasTextChanged = false;
            }
            if (IsActive) {
                CurrentFontBrush = _activeFontBrush;
                if (IsPressed) {
                    CurrentBackgroundBrush = _pressedBackgroundBrush;
                    CurrentBorderBrush = _pressedBorderBrush;
                    CurrentBitmap = _pressedTexture;
                } else {
                    CurrentBackgroundBrush = _activeBackgroundBrush;
                    CurrentBorderBrush = _activeBorderBrush;
                    CurrentBitmap = _activeTexture;
                }
            } else {
                CurrentBackgroundBrush = _inactiveBackgroundBrush;
                CurrentBorderBrush = _inactiveBorderBrush;
                CurrentFontBrush = _inactiveFontBrush;
                CurrentBitmap = _inactiveTexture;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.
        /// </summary>
        /// <param name="texture">A texture.</param>
        /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
        /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. </param>
        /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
        /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
        /// <param name="origin">The sprite origin; the default is (0,0) which represents the upper-left corner.</param>
        /// <param name="scale">Scale factor.</param>
        /// <param name="effects">Effects to apply.</param>
        /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
        public void Draw(Texture texture, Vector2 position, DrawingRectangle?sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            var destination = new DrawingRectangleF(position.X, position.Y, scale.X, scale.Y);

            DrawSprite(texture, null, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
        }
Exemplo n.º 21
0
        internal void InternalDraw(ref StringProxy text, SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, ref Vector2 scale, SpriteEffects spriteEffects, float depth)
        {
            var baseOffset = origin;
            //baseOffset.Y += globalBaseOffsetY;

            // If the text is mirrored, offset the start position accordingly.
            if (spriteEffects != SpriteEffects.None)
            {
                baseOffset -= MeasureString(ref text)*axisIsMirroredTable[(int) spriteEffects & 3];
            }

            var localScale = scale;


            // Draw each character in turn.
            ForEachGlyph(ref text, (ref SpriteFontData.Glyph glyph, float x, float y) =>
                                       {
                                           var offset = new Vector2(x, y + glyph.Offset.Y);
                                           Vector2.Modulate(ref offset, ref axisDirectionTable[(int) spriteEffects & 3], out offset);
                                           Vector2.Add(ref offset, ref baseOffset, out offset);


                                           if (spriteEffects != SpriteEffects.None)
                                           {
                                               // For mirrored characters, specify bottom and/or right instead of top left.
                                               var glyphRect = new Vector2(glyph.Subrect.Right - glyph.Subrect.Left, glyph.Subrect.Top - glyph.Subrect.Bottom);
                                               Vector2.Modulate(ref glyphRect, ref axisIsMirroredTable[(int) spriteEffects & 3], out offset);
                                           }
                                           var destination = new DrawingRectangleF(position.X, position.Y, localScale.X, localScale.Y);
                                           DrawingRectangle? sourceRectangle = glyph.Subrect;
                                           spriteBatch.DrawSprite(textures[glyph.BitmapIndex], ref destination, true, ref sourceRectangle, color, rotation, ref offset, spriteEffects, depth);
                                       });
        }
        //internal static void ActiveMap_MapClick(object sender, MapClickWpfMapEventArgs e)
        internal static void ActiveMap_MapClick(object sender, MapMouseClickInteractiveOverlayEventArgs e)
        {
            if (ViewModel.IsInModifyMode)
            {
                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Open();
                RectangleShape clickBuffer = GetClickBuffer(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY);

                #region save feature ids to exclude temporary.

                var tmpFeatureIdsToExclude = new Collection <string>();
                foreach (var id in ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude)
                {
                    tmpFeatureIdsToExclude.Add(id);
                }
                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Clear();

                #endregion save feature ids to exclude temporary.

                var foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.QueryTools
                                   .GetFeaturesIntersecting(clickBuffer, ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.GetDistinctColumnNames()).FirstOrDefault(tmpFeature => !tmpFeatureIdsToExclude.Contains(tmpFeature.Id));

                if (foundFeature == default(Feature))
                {
                    PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas();
                    foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures
                                   .Where(tmpFeature => tmpFeature.ColumnValues.ContainsKey(AnnotationTrackInteractiveOverlay.AnnotationTextColumnName) &&
                                          !String.IsNullOrEmpty(tmpFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]))
                                   .FirstOrDefault(textFeature =>
                    {
                        if (tmpFeatureIdsToExclude.Contains(textFeature.Id))
                        {
                            return(false);
                        }

                        TextStyle textStyle = ViewModel.CurrentAnnotationOverlay
                                              .GetSpecificTextStyle(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.ValueStyleMatchColumnName]);

                        DrawingRectangleF textArea = geoCanvas.MeasureText(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]
                                                                           , textStyle.Font);

                        PointShape textScreenPoint = GisEditor.ActiveMap.ToScreenCoordinate((PointShape)textFeature.GetShape());

                        double left   = textScreenPoint.X;
                        double top    = textScreenPoint.Y;
                        double right  = textScreenPoint.X + textArea.Width;
                        double bottom = textScreenPoint.Y + textArea.Height;

                        string placementString = textStyle.PointPlacement.ToString();
                        if (placementString.Contains("Left"))
                        {
                            left = textScreenPoint.X - textArea.Width;
                        }

                        if (placementString.Contains("Upper"))
                        {
                            top = textScreenPoint.Y - textArea.Height;
                        }

                        PointShape upperLeft  = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(left, top));
                        PointShape lowerRight = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(right, bottom));

                        RectangleShape textWorldArea = new RectangleShape(upperLeft, lowerRight);
                        return(textWorldArea.Intersects(new PointShape(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY)));
                    });
                }

                #region restore feature ids to exclude

                foreach (var id in tmpFeatureIdsToExclude)
                {
                    ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(id);
                }

                #endregion restore feature ids to exclude

                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Close();

                if (foundFeature != default(Feature))
                {
                    var isShiftDown = Keyboard.Modifiers == ModifierKeys.Shift;
                    if (!isShiftDown)
                    {
                        CommitEdit(false);
                    }

                    bool isEditing = true;
                    if (!ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Contains(foundFeature.Id))
                    {
                        ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(foundFeature.Id);
                    }
                    else
                    {
                        isEditing = false;
                        if (isShiftDown)
                        {
                            ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Remove(foundFeature.Id);
                            if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Contains(foundFeature.Id))
                            {
                                ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Remove(foundFeature.Id);
                            }
                        }
                    }

                    if (isEditing)
                    {
                        SetAnnotationToEditMode(foundFeature);
                    }

                    ViewModel.CurrentEditOverlay.CalculateAllControlPoints();
                    ViewModel.CurrentAnnotationOverlay.Refresh();
                    ViewModel.CurrentEditOverlay.Refresh();
                    ViewModel.SyncUIState();
                    ViewModel.TakeSnapshot();
                }
                else
                {
                    if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Count > 0 ||
                        (MarkerHelper.CurrentMarkerOverlay != null && MarkerHelper.CurrentMarkerOverlay.Markers.Count > 0))
                    {
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => CommitEdit()));
                    }
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, source rectangle, color, rotation, origin, effects and layer.
        /// </summary>
        /// <param name="texture">A texture.</param>
        /// <param name="destinationRectangle">A rectangle that specifies (in screen coordinates) the destination for drawing the sprite. If this rectangle is not the same size as the source rectangle, the sprite will be scaled to fit.</param>
        /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. </param>
        /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
        /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
        /// <param name="origin">The sprite origin; the default is (0,0) which represents the upper-left corner.</param>
        /// <param name="effects">Effects to apply.</param>
        /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
        public void Draw(Texture texture, DrawingRectangle destinationRectangle, DrawingRectangle?sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth)
        {
            var destination = new DrawingRectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);

            DrawSprite(texture, null, ref destination, false, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
        }
Exemplo n.º 24
0
        public void Draw(CubeTexture texture, CubeMapFace face, DrawingRectangle destinationRectangle, Color color)
        {
            var destination = new DrawingRectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);

            DrawSprite(texture, face, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, SpriteEffects.None, 0f);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, and color.
        /// </summary>
        /// <param name="texture">A texture.</param>
        /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
        /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. </param>
        /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
        public void Draw(Texture texture, Vector2 position, DrawingRectangle?sourceRectangle, Color color)
        {
            var destination = new DrawingRectangleF(position.X, position.Y, 1f, 1f);

            DrawSprite(texture, null, ref destination, true, ref sourceRectangle, color, 0f, ref vector2Zero, SpriteEffects.None, 0f);
        }