Inflate() public static method

Creates a that is inflated by the specified amount.

public static Inflate ( RectangleF rect, float x, float y ) : RectangleF
rect RectangleF
x float
y float
return RectangleF
 static public void DrawNode(ICanvas canvas, UnitPoint nodepoint)
 {
     RectangleF r = new RectangleF(canvas.ToScreen(nodepoint), new SizeF(0, 0));
     r.Inflate(3, 3);
     if (r.Right < 0 || r.Left > canvas.ClientRectangle.Width)
         return;
     if (r.Top < 0 || r.Bottom > canvas.ClientRectangle.Height)
         return;
     canvas.Graphics.FillRectangle(Brushes.White, r);
     r.Inflate(1, 1);
     canvas.Graphics.DrawRectangle(Pens.Black, ScreenUtils.ConvertRect(r));
 }
Example #2
0
        /// <summary>
        /// Draw a preview of the <see cref="ColorPair"/>
        /// </summary>
        /// <param name="e">The paint event args providing the <see cref="Graphics"/> and bounding
        /// rectangle</param>
        public override void PaintValue(PaintValueEventArgs e)
        {
            ColorPair colorPair = (ColorPair)e.Value ;

            using ( SolidBrush b = new SolidBrush(colorPair.Background)) {
                e.Graphics.FillRectangle(b, e.Bounds);
            }

            // Draw the text "ab" using the Foreground/Background values from the ColorPair
            using(SolidBrush b = new SolidBrush(colorPair.Foreground)) {
                using(Font f = new Font("Arial",6)) {
                    RectangleF temp = new RectangleF(e.Bounds.Left,e.Bounds.Top,e.Bounds.Height,e.Bounds.Width) ;
                    temp.Inflate(-2,-2) ;

                    // Set up how we want the text drawn
                    StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap) ;
                    format.Trimming = StringTrimming.EllipsisCharacter ;
                    format.Alignment = StringAlignment.Center ;
                    format.LineAlignment = StringAlignment.Center ;

                    // save the Smoothing mode of the Graphics object so we can restore it
                    SmoothingMode saveMode = e.Graphics.SmoothingMode ;
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias ;
                    e.Graphics.DrawString("ab",f,b,temp,format) ;
                    e.Graphics.SmoothingMode = saveMode ;
                }
            }
        }
        void TestStringWithOrigin(Graphics g)
        {
            for (int multiline = 0; multiline <= 1; ++multiline)
            {
                for (int h = (int)StringAlignment.Near; h <= (int)StringAlignment.Far; ++h)
                {
                    for (int v = (int)StringAlignment.Near; v <= (int)StringAlignment.Far; ++v)
                    {
                        var    fmt    = new StringFormat((StringAlignment)h, (StringAlignment)v);
                        PointF origin = new PointF(10 + multiline * 250 + h * 100, 10 + v * 100);

                        var txt = "test";
                        if (multiline == 1)
                        {
                            txt += "\nfoo bar";
                        }
                        var sz = g.MeasureString(txt, font);

                        var measuredBox = new RectangleF(origin, sz);
                        measuredBox.X -= h * sz.Width / 2;
                        measuredBox.Y -= v * sz.Height / 2;
                        g.FillRectangle(measuredBoxBrush, measuredBox);
                        g.DrawString(txt, font, textBrush, origin, fmt);

                        NSColor.Red.SetFill();
                        var originRect = new RectangleF(origin, new SD.SizeF());
                        originRect.Inflate(2, 2);
                        NSBezierPath.FillRect(originRect);
                    }
                }
            }
        }
Example #4
0
        public override bool Hit(Point p)
        {
            Point p1,p2, s;
            RectangleF r1, r2;
            float o,u;
            p1 = From.Point; p2 = To.Point;

            // p1 must be the leftmost point.
            if (p1.X > p2.X) { s = p2; p2 = p1; p1 = s; }

            r1 = new RectangleF(p1.X, p1.Y, 0, 0);
            r2 = new RectangleF(p2.X, p2.Y, 0, 0);
            r1.Inflate(3, 3);
            r2.Inflate(3, 3);
            //this is like a topological neighborhood
            //the connection is shifted left and right
            //and the point under consideration has to be in between.
            if (RectangleF.Union(r1, r2).Contains(p))
            {
                if (p1.Y < p2.Y) //SWNE
                {
                    o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
                    u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
                    return ((p.X > o) && (p.X < u));
                }
                else //NWSE
                {
                    o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
                    u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
                    return ((p.X > o) && (p.X < u));
                }
            }
            return false;
        }
Example #5
0
        public static Drawing.Bitmap BuildIcon(string tag, Guid componentId, int width = 24, int height = 24)
        {
            var bitmap = new Drawing.Bitmap(width, height);

            using (var g = Drawing.Graphics.FromImage(bitmap))
            {
                var textBrush = Drawing.Brushes.Black;
                if (Grasshopper.Instances.ComponentServer.EmitObjectIcon(componentId) is Drawing.Bitmap icon)
                {
                    textBrush = Drawing.Brushes.White;
                    g.DrawImage(icon, Drawing.Point.Empty);
                }
                else
                {
                    var iconBounds = new Drawing.RectangleF(0, 0, width, height);
                    iconBounds.Inflate(-0.5f, -0.5f);

                    using (var capsule = Grasshopper.GUI.Canvas.GH_Capsule.CreateCapsule(iconBounds, Grasshopper.GUI.Canvas.GH_Palette.Transparent))
                        capsule.Render(g, false, false, false);
                }

                DrawIconTag(g, textBrush, tag, width, height);
            }

            return(bitmap);
        }
Example #6
0
        public void Draw(System.Drawing.Graphics g, System.Drawing.RectangleF innerArea)
        {
            innerArea.Inflate(_shadowLength / 2, _shadowLength / 2); // Padding
            RectangleF outerArea = innerArea;

            outerArea.Inflate(_shadowLength, _shadowLength);

            _brush.Rectangle = outerArea;
            g.FillRectangle(_brush, outerArea);

            SolidBrush twhite = new SolidBrush(Color.FromArgb(128, 255, 255, 255));

            g.FillPolygon(twhite, new PointF[] {
                new PointF(outerArea.Left, outerArea.Top),                                      // upper left point
                new PointF(outerArea.Right, outerArea.Top),                                     // go to the right
                new PointF(innerArea.Right, innerArea.Top),                                     // go 45 deg left down in the upper right corner
                new PointF(innerArea.Left, innerArea.Top),                                      // upper left corner of the inner rectangle
                new PointF(innerArea.Left, innerArea.Bottom),                                   // lower left corner of the inner rectangle
                new PointF(outerArea.Left, outerArea.Bottom)                                    // lower left corner
            });

            SolidBrush tblack = new SolidBrush(Color.FromArgb(128, 0, 0, 0));

            g.FillPolygon(tblack, new PointF[] {
                new PointF(outerArea.Right, outerArea.Bottom),
                new PointF(outerArea.Right, outerArea.Top),
                new PointF(innerArea.Right, innerArea.Top),
                new PointF(innerArea.Right, innerArea.Bottom),                                    // upper left corner of the inner rectangle
                new PointF(innerArea.Left, innerArea.Bottom),                                     // lower left corner of the inner rectangle
                new PointF(outerArea.Left, outerArea.Bottom)                                      // lower left corner
            });
        }
 public System.Drawing.RectangleF MeasureItem(System.Drawing.Graphics g, System.Drawing.RectangleF innerArea)
 {
     innerArea.Inflate(_shadowLength / 2, _shadowLength / 2);
     innerArea.Width  += _shadowLength;
     innerArea.Height += _shadowLength;
     return(innerArea);
 }
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
            pevent.Graphics.Clear(Color.FromArgb(0));

            foreach (TabPage tab in this.TabPages)
            {
                Rectangle tabRect = GetTabRect(this.TabPages.IndexOf(tab));

                using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap))
                {
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    SizeF textSize = pevent.Graphics.MeasureString(tab.Text, this.Font);
                    RectangleF rc = new RectangleF(tabRect.Left + ((tabRect.Width / 2) - (textSize.Width / 2)), tabRect.Top + tabRect.Height / 2 - textSize.Height / 2, textSize.Width, textSize.Height);
                    rc.Inflate(4, 5);

                    GraphicsPath path = new GraphicsPath();
                    path.AddRectangle(rc);

                    using (PathGradientBrush brush = new PathGradientBrush(path))
                    {
                        brush.CenterColor = Color.FromArgb(192, tab == this.SelectedTab ? Color.Red : Color.Black);
                        brush.SurroundColors = new Color[] { Color.Black };
                        pevent.Graphics.FillRectangle(brush,rc);
                    }

                    var tc = new SolidBrush(Color.FromArgb(tab.ForeColor.A, tab.ForeColor.R, tab.ForeColor.G, tab.ForeColor.B));

                    pevent.Graphics.DrawString(tab.Text, this.Font, tc, rc, sf);

                }
            }
        }
Example #9
0
		/// <summary>
		///	Inflate Shared Method
		/// </summary>
		///
		/// <remarks>
		///	Produces a new RectangleF by inflating an existing 
		///	RectangleF by the specified coordinate values.
		/// </remarks>
		
		public static RectangleF Inflate (RectangleF rect, 
						  float x, float y)
		{
			RectangleF ir = new RectangleF (rect.X, rect.Y, rect.Width, rect.Height);
			ir.Inflate (x, y);
			return ir;
		}
Example #10
0
    GetRectangleTransformation
    (
        RectangleF rectangle1,
        RectangleF rectangle2
    )
    {
        Debug.Assert(rectangle1.Width >= 0);
        Debug.Assert(rectangle1.Height >= 0);
        Debug.Assert(rectangle2.Width >= 0);
        Debug.Assert(rectangle2.Height >= 0);

        // Handle collapsed rectangles, which can result, for example, when a
        // graph contains only one vertex.

        if (rectangle1.Width == 0)
        {
            rectangle1.Inflate(1, 0);
        }

        if (rectangle1.Height == 0)
        {
            rectangle1.Inflate(0, 1);
        }

        if (rectangle2.Width == 0)
        {
            rectangle2.Inflate(1, 0);
        }

        if (rectangle2.Height == 0)
        {
            rectangle2.Inflate(0, 1);
        }

        Matrix oMatrix = new Matrix(

            rectangle1,

            new PointF [] {
                rectangle2.Location,
                new PointF(rectangle2.Right, rectangle2.Top),
                new PointF(rectangle2.Left, rectangle2.Bottom)
                }
            );

        return (oMatrix);
    }
        public override bool Hit(System.Drawing.PointF p)
        {
            bool join = false;
            //			points = new PointF[2+insertionPoints.Count];
            //			points[0] = p1;
            //			points[2+insertionPoints.Count-1] = p2;
            //			for(int m=0; m<insertionPoints.Count; m++)
            //			{
            //				points[1+m] = (PointF)  insertionPoints[m];
            //			}
            PointF[] points = mPoints;

            PointF p1 = this.mConnection.From.AdjacentPoint;
            PointF p2 = this.mConnection.To.AdjacentPoint;

            PointF s;
                float o, u;
            RectangleF r1=RectangleF.Empty, r2=RectangleF.Empty, r3=RectangleF.Empty;

            //Tomas Kuchar wrote
            if (points == null)
                return join;

            for(int v = 0; v<points.Length-1; v++)
            {

                //this is the usual segment test
                //you can do this because the PointF object is a value type!
                p1 = points[v]; p2 = points[v+1];

                // p1 must be the leftmost point.
                if (p1.X > p2.X) { s = p2; p2 = p1; p1 = s; }

                r1 = new RectangleF(p1.X, p1.Y, 0, 0);
                r2 = new RectangleF(p2.X, p2.Y, 0, 0);
                r1.Inflate(3, 3);
                r2.Inflate(3, 3);
                //this is like a topological neighborhood
                //the connection is shifted left and right
                //and the point under consideration has to be in between.
                if (RectangleF.Union(r1, r2).Contains(p))
                {
                    if (p1.Y < p2.Y) //SWNE
                    {
                        o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
                        u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
                        join |= ((p.X > o) && (p.X < u));
                    }
                    else //NWSE
                    {
                        o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
                        u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
                        join |= ((p.X > o) && (p.X < u));
                    }
                }

            }
            return join;
        }
Example #12
0
        public DetectedFrame(RECTF r, float rs, DateTime t, Score s)
        {
            Region = r;
            Time   = t;
            Score  = s;

            Region.Inflate(rs, rs);
        }
Example #13
0
 private RectangleF GetOurRectangle()
 {
     RectangleF rectF = new RectangleF(this.Location, new SizeF(0, 0));
     float ratio = 1.0f / (float)OwnerList.ScaleFactor.Ratio;
     float ourSize = UI.ScaleWidth(size);
     rectF.Inflate(ratio * ourSize, ratio * ourSize);
     return rectF;
 }
        public override void DrawUserHeader(IGUIContext gfx, System.Drawing.RectangleF rect, string UserName)
        {
            gfx.DrawGrayButton(rect);

            if (rect.Width > 4)
            {
                rect.Offset(2, 1);
                rect.Inflate(-2, 0);
                gfx.DrawString(UserName, BaseFont, SummerGUI.Theme.Brushes.Base03, rect, m_UserHeaderFormat);
            }
        }
Example #15
0
            protected override void Render(RectangleF sourceBounds, Matrix transform, Graphics g)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.Transform = transform;
                sourceBounds.Inflate(1, 1); // allow for pen widths
                g.SetClip(sourceBounds);

                foreach (IPrintingAdapter printingAdapter in m_viewingContext.Control.AsAll<IPrintingAdapter>())
                    printingAdapter.Print(this, g);
            }
        /// <summary>
        /// Shortens the height or narrows the width of a rectangle to match the specified aspect ratio.
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="aspectRatio"></param>
        /// <returns></returns>
        public static RectangleF ToAspectRatioB(RectangleF rectangle, float aspectRatio)
        {
            float projectedAspect = ((float)rectangle.Width / (float)rectangle.Height);

            if (aspectRatio > projectedAspect)
            {
#if !PocketPC
                rectangle.Inflate(0, (rectangle.Width / aspectRatio - rectangle.Height) * .5f);
#else
                return RectangleFHelper.Inflate(rectangle, 0, (rectangle.Width / aspectRatio - rectangle.Height) * .5f);
#endif
            }
            else if (aspectRatio < projectedAspect)
            {
#if !PocketPC
                rectangle.Inflate((aspectRatio * rectangle.Height - rectangle.Width) * .5f, 0);
#else
                return RectangleFHelper.Inflate(rectangle, (aspectRatio * rectangle.Height - rectangle.Width) * .5f, 0);
#endif
            }
            return rectangle;
        }
 public override void DrawGlyph(PaintEventArgs e, Rectangle bounds)
 {
     GraphicsPath path;
     int num = Math.Max(0, (bounds.Width - bounds.Height) / 2);
     int num2 = Math.Max(0, (bounds.Height - bounds.Width) / 2);
     bounds.Inflate(-num, -num2);
     if ((bounds.Width % 2) == 1)
     {
         bounds.Width--;
     }
     if ((bounds.Height % 2) == 1)
     {
         bounds.Height--;
     }
     if (bounds.Width > bounds.Height)
     {
         bounds.Width = bounds.Height;
     }
     if (bounds.Height > bounds.Width)
     {
         bounds.Height = bounds.Width;
     }
     bounds.Inflate(-2, -2);
     int width = bounds.Width;
     int num4 = width / 3;
     int num5 = width / 4;
     int num6 = bounds.X + (bounds.Width / 2);
     float x = bounds.X + (0.5f * (bounds.Width + 3));
     float num8 = x - 3f;
     SmoothingMode smoothingMode = e.Graphics.SmoothingMode;
     e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
     using (path = new GraphicsPath())
     {
         Point[] points = new Point[] { new Point(bounds.Left + num4, bounds.Bottom), new Point(bounds.Right - num4, bounds.Bottom), new Point(bounds.Right, bounds.Bottom - num4), new Point(bounds.Right, bounds.Top + num4), new Point(bounds.Right - num4, bounds.Top), new Point(bounds.Left + num4, bounds.Top), new Point(bounds.Left, bounds.Top + num4), new Point(bounds.Left, bounds.Bottom - num4) };
         path.AddLines(points);
         path.CloseAllFigures();
         e.Graphics.FillPath(Brushes.Red, path);
         e.Graphics.DrawPath(Pens.DarkGray, path);
     }
     using (path = new GraphicsPath())
     {
         PointF[] tfArray = new PointF[] { new PointF(num8, (float) ((bounds.Top + num5) - 1)), new PointF(x, (float) ((bounds.Top + num5) - 1)), new PointF(num6 + 1.2f, (-0.5f + bounds.Top) + ((bounds.Height * 2f) / 3f)), new PointF(num6 - 1.2f, (-0.5f + bounds.Top) + ((bounds.Height * 2f) / 3f)) };
         path.AddLines(tfArray);
         path.CloseAllFigures();
         e.Graphics.FillPath(Brushes.White, path);
     }
     RectangleF rect = new RectangleF((float) num6, (float) (bounds.Bottom - num5), 0f, 0f);
     rect.Inflate(1.5f, 1.5f);
     e.Graphics.FillEllipse(Brushes.White, rect);
     e.Graphics.SmoothingMode = smoothingMode;
 }
        public static Drawing.Bitmap BuildIcon(string tag, int width = 24, int height = 24)
        {
            var bitmap = new Drawing.Bitmap(width, height);

            using (var g = Drawing.Graphics.FromImage(bitmap))
            {
                var iconBounds = new Drawing.RectangleF(0, 0, width, height);
                iconBounds.Inflate(-0.5f, -0.5f);

                using (var capsule = Grasshopper.GUI.Canvas.GH_Capsule.CreateCapsule(iconBounds, Grasshopper.GUI.Canvas.GH_Palette.Transparent))
                    capsule.Render(g, false, false, false);

                g.SmoothingMode     = Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode   = Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                var rect = new Drawing.RectangleF(0.5f, 1.0f, width, height);

                var format = new Drawing.StringFormat()
                {
                    Alignment     = Drawing.StringAlignment.Center,
                    LineAlignment = Drawing.StringAlignment.Center,
                    Trimming      = Drawing.StringTrimming.Character,
                    FormatFlags   = Drawing.StringFormatFlags.NoWrap
                };

                float emSize = ((float)(width) / ((float)tag.Length));
                if (width == 24)
                {
                    switch (tag.Length)
                    {
                    case 1: emSize = 20.0f; break;

                    case 2: emSize = 13.0f; break;

                    case 3: emSize = 11.0f; break;

                    case 4: emSize = 8.0f; break;

                    default: emSize = 7.0f; break;
                    }
                }

                // Avoid using ClearType rendering on icons that the user can zoom in like icons on Grashopper components.
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                using (var Calibri = new System.Drawing.Font("Calibri", emSize, Drawing.GraphicsUnit.Pixel))
                    g.DrawString(tag, Calibri, Drawing.Brushes.Black, rect, format);
            }

            return(bitmap);
        }
Example #19
0
        public override void Draw(ICanvas canvas, RectangleF unitrect)
        {
            Color color = Color;
            Pen pen = canvas.CreatePen(color, Width);
            if (Highlighted || Selected)
            {
                pen = Canvas.DrawTools.DrawUtils.SelectedPen;
                //if (m_p1.IsEmpty == false) Canvas.DrawTools.DrawUtils.DrawNode(canvas, m_p1);
            }
            pen = new Pen(pen.Color, (float)6);

            unitrect.Inflate(3, 3);
            canvas.DrawArc(canvas,pen,m_p1,(float)0.05,0,360);
        }
Example #20
0
 public Maze(Size size)
 {
     MapSize = new Size(MazeSettings.CurrentRowSize, MazeSettings.CurrentColSize);
     MapRowData = new byte[MapSize.Width, MapSize.Height - 1]; // 横向门 --
     MapColData = new byte[MapSize.Width - 1, MapSize.Height]; // 纵向门 ||
     MapRect = new Rectangle(Point.Empty, MapSize);
     MzSize = size;
     MzBitmap = new Bitmap(size.Width, size.Height);
     MzGraphics = Graphics.FromImage(MzBitmap);
     MapRectF = new RectangleF(Point.Empty, MzSize);
     MapRectF.Inflate(-MazeSettings.CurrentBorderSize, -MazeSettings.CurrentBorderSize);
     PtStart = Point.Empty;
     PtEnd = new Point(MapSize.Width - 1, MapSize.Height - 1);
     GenerateGridLines();
     GenerateMaze();
 }
Example #21
0
        public static Drawing.Bitmap BuildIcon(string tag, int width = 24, int height = 24)
        {
            var bitmap = new Drawing.Bitmap(width, height);

            using (var g = Drawing.Graphics.FromImage(bitmap))
            {
                var iconBounds = new Drawing.RectangleF(0, 0, width, height);
                iconBounds.Inflate(-0.5f, -0.5f);

                using (var capsule = Grasshopper.GUI.Canvas.GH_Capsule.CreateCapsule(iconBounds, Grasshopper.GUI.Canvas.GH_Palette.Transparent))
                    capsule.Render(g, false, false, false);

                DrawIconTag(g, Drawing.Brushes.Black, tag, width, height);
            }

            return(bitmap);
        }
Example #22
0
        public RectangleF PaintSymbol(System.Drawing.Graphics g, System.Drawing.RectangleF bounds)
        {
            if (Shape != XYPlotScatterStyles.Shape.NoSymbol)
            {
                GraphicsState gs = g.Save();
                g.TranslateTransform(bounds.X + 0.5f * bounds.Width, bounds.Y + 0.5f * bounds.Height);
                Paint(g);
                g.Restore(gs);

                if (this.SymbolSize > bounds.Height)
                {
                    bounds.Inflate(0, this.SymbolSize - bounds.Height);
                }
            }

            return(bounds);
        }
Example #23
0
        public RectangleF PaintSymbol(System.Drawing.Graphics g, System.Drawing.RectangleF bounds)
        {
            if (_scatterSymbol is NoSymbol)
            {
                return(bounds);
            }

            var cachedPathData  = new CachedPathData();
            var cachedBrushData = new CachedBrushData();
            var scatterSymbol   = CalculateOverriddenScatterSymbol();

            CalculatePaths(scatterSymbol, _symbolSize, ref cachedPathData);
            CalculateBrushes(scatterSymbol, _color, cachedPathData, ref cachedBrushData);

            GraphicsState gs = g.Save();

            g.TranslateTransform(bounds.X + 0.5f * bounds.Width, bounds.Y + 0.5f * bounds.Height);

            if (null != cachedPathData.InsetPath)
            {
                g.FillPath(cachedBrushData.InsetBrush, cachedPathData.InsetPath);
            }

            if (null != cachedPathData.FillPath)
            {
                g.FillPath(cachedBrushData.FillBrush, cachedPathData.FillPath);
            }

            if (null != cachedPathData.FramePath)
            {
                g.FillPath(cachedBrushData.FrameBrush, cachedPathData.FramePath);
            }

            cachedBrushData.Clear();
            cachedPathData.Clear();

            g.Restore(gs);

            if (SymbolSize > bounds.Height)
            {
                bounds.Inflate(0, (float)(SymbolSize - bounds.Height));
            }

            return(bounds);
        }
        public ChartCanvas(RectangleF rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            this.AutoresizingMask = UIViewAutoresizing.All;
            this.BackColor = Color.Wheat;

            var panelRect = new RectangleF(rect.X,rect.Y,rect.Width,rect.Height-20 / UIScreen.MainScreen.Scale);
            panelRect.Inflate(-20 / UIScreen.MainScreen.Scale,-20 / UIScreen.MainScreen.Scale);
            panel1 = new PlotPanel(panelRect);
            panel1.BackColor = Color.AliceBlue;

            this.AddSubview(panel1);

            // Subscribing to a paint eventhandler to drawingPanel:
            panel1.Paint +=
                new PaintEventHandler(PlotPanelPaint);
        }
Example #25
0
        public override void Render(Graphics graphics, Map mapBox)
        {
            if (string.IsNullOrEmpty(Text))
                return;

            var measure = graphics.MeasureString(Text, SystemFonts.DefaultFont);

            var x = 25f;
            var y = (mapBox.Size.Height - measure.Height) - 20;

            var rectangle = new RectangleF(x, y, measure.Width, measure.Height); //25 from the bottom

            rectangle.Inflate(5, 3);
            
            graphics.FillRectangle(BgBrush, rectangle);
            //graphics.DrawRectangle(Pens.Black, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

            graphics.DrawString(Text, SystemFonts.DefaultFont, Brushes.Black, x, y);
        }
Example #26
0
		public override void PaintValue(PaintValueEventArgs e)
		{
			MindFusion.FlowChartX.ShapeTemplate shape = 
				e.Value as MindFusion.FlowChartX.ShapeTemplate;

			if (shape == null)
				return;

			// Draw the shape
			RectangleF rect = new RectangleF(
				(float)e.Bounds.Left, (float)e.Bounds.Top,
				(float)e.Bounds.Width - 1, (float)e.Bounds.Height - 1);
			rect.Inflate(-2, -2);
			MindFusion.FlowChartX.ShapeTemplate.PathData data =
				shape.initData(rect, 0);
			System.Drawing.Brush brush =
				new System.Drawing.SolidBrush(Color.LightSteelBlue);
			System.Drawing.Pen pen =
				new System.Drawing.Pen(Color.Black);

			System.Drawing.Drawing2D.SmoothingMode mode =
				e.Graphics.SmoothingMode;
			e.Graphics.SmoothingMode = 
				System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

			System.Drawing.Drawing2D.GraphicsPath path =
				shape.getPath(data, 0);
			e.Graphics.FillPath(brush, path);
			e.Graphics.DrawPath(pen, path);
			path.Dispose();

			path = shape.getDecorationPath(data, 0);
			if (path != null)
			{
				e.Graphics.DrawPath(pen, path);
				path.Dispose();
			}
			
			e.Graphics.SmoothingMode = mode;

            pen.Dispose();
			brush.Dispose();
		}
Example #27
0
        public override void Draw(ICanvas canvas, RectangleF unitrect)
        {
            Brush B = Brushes.Black;
            Color color = Color;
            Pen pen = canvas.CreatePen(color, Width);
            if (Highlighted || Selected)
            {
                pen = Canvas.DrawTools.DrawUtils.SelectedPen;
                B = Brushes.Magenta;
                //if (m_p1.IsEmpty == false) Canvas.DrawTools.DrawUtils.DrawNode(canvas, m_p1);
            }
            pen = new Pen(pen.Color, (float)6);

            unitrect.Inflate(3, 3);
            canvas.DrawArc(canvas, pen, m_p1, (float)0.03, 0, 360);
            float size = (canvas.ToScreen(new UnitPoint(m_p1.X + 1, m_p1.Y)).X - canvas.ToScreen(m_p1).X)/10;
            Font m_font = new System.Drawing.Font("Arial Black", size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            canvas.Graphics.DrawString("Line Config", m_font, B, canvas.ToScreen(new UnitPoint(m_p1.X - 0.4, m_p1.Y + 0.2)).X, canvas.ToScreen(new UnitPoint(m_p1.X - 0.3, m_p1.Y + 0.2)).Y);
        }
        public void Draw(System.Drawing.Graphics g, System.Drawing.RectangleF innerArea)
        {
            if (null == _cachedShadowBrush)
            {
                SetCachedBrushes();
            }

            innerArea.Inflate(_shadowLength / 2, _shadowLength / 2);

            // please note: m_Bounds is already extended to the shadow

            // first the shadow
            _cachedShadowBrush.Rectangle = innerArea;
            g.TranslateTransform(_shadowLength, _shadowLength);
            g.FillRectangle(_cachedShadowBrush, innerArea);
            g.TranslateTransform(-_shadowLength, -_shadowLength);

            _brush.Rectangle = innerArea;
            g.FillRectangle(_brush, innerArea);
            g.DrawRectangle(Pens.Black, innerArea.Left, innerArea.Top, innerArea.Width, innerArea.Height);
        }
        public override void Decorate(ImageDecoratorContext context)
        {
            Bitmap polaroidBorder = ResourceHelper.LoadAssemblyResourceBitmap("PostHtmlEditing.ImageEditing.Images.PolaroidBorder2.png");

            DropShadowBorderDecoratorSettings settings = new DropShadowBorderDecoratorSettings(context);

            Size originalSize = context.Image.Size;

            float scaleX = originalSize.Width / (float)PORTAL_RECT.Width;
            float scaleY = originalSize.Height / (float)PORTAL_RECT.Height;
            Size finalSize = new Size((int)(polaroidBorder.Width * scaleX), (int)(polaroidBorder.Height * scaleY));

            Bitmap output = new Bitmap(finalSize.Width, finalSize.Height);
            using (Graphics g = Graphics.FromImage(output))
            {
                using (SolidBrush b = new SolidBrush(settings.BackgroundColor))
                    g.FillRectangle(b, 0, 0, output.Width, output.Height);

                g.CompositingMode = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                RectangleF realPortal = new RectangleF(
                    PORTAL_RECT.X * scaleX,
                    PORTAL_RECT.Y * scaleY,
                    PORTAL_RECT.Width * scaleX,
                    PORTAL_RECT.Height * scaleY);

                realPortal.Inflate(1, 1);
                g.DrawImage(context.Image, realPortal, new RectangleF(0, 0, originalSize.Width, originalSize.Height), GraphicsUnit.Pixel);
                g.DrawImage(polaroidBorder, 0, 0, output.Width, output.Height);
            }

            context.Image = output;
            context.BorderMargin = new ImageBorderMargin(
                output.Width - originalSize.Width, output.Height - originalSize.Height,
                new BorderCalculation(output.Width / (float)originalSize.Width, output.Height / (float)originalSize.Height));

            HideHtmlBorder(context);
        }
Example #30
0
        /// <summary>
        /// Handles mouse movement
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            _highlightTimer.Stop();
            // Activate buttons only if the mouse is over them.  Inactivate them otherwise.
            bool invalid = UpdateHighlight(e.Location);

            

            // Sliders
            RectangleF area = new RectangleF();
            if (HorizontalSlider.IsDragging)
            {
                area = HorizontalSlider.Bounds;
                PointF loc = HorizontalSlider.Position;
                loc.X = e.X;
                HorizontalSlider.Position = loc;
                
                area = RectangleF.Union(area, HorizontalSlider.Bounds);     
            }
            area.Inflate(10F, 10F);
            if(invalid == false) Invalidate(new Region(area));
            if (VerticalSlider.IsDragging)
            {
                area = VerticalSlider.Bounds;
                PointF loc = VerticalSlider.Position;
                loc.Y = e.Y;
                VerticalSlider.Position = loc;
                area = RectangleF.Union(area, VerticalSlider.Bounds);
            }
            area.Inflate(10F, 10F);
            if(invalid == false) Invalidate(new Region(area));
            if (invalid) Invalidate();
            base.OnMouseMove(e);
            _highlightTimer.Start();
        }
        public void UpdateBoundingBox()
        {
            this.CenterPoint.X = TopLeftCorner.X + Width / 2;
            this.CenterPoint.Y = TopLeftCorner.Y + Height / 2;

            inflatedBox = new RectangleF(TopLeftCorner.X, TopLeftCorner.Y, Width, Height);
            inflatedBox.Inflate(View.ViewFactory.EdgeBoxWidth / 2, View.ViewFactory.EdgeBoxWidth / 2);
            RecomputeEdgePoints();
        }
Example #32
0
		public override void Draw(Graphics g)
		{
			//Show only if its collidable
			if (!HasPegInfo) {
				if (Level.ShowCollision && !Collision)
					return;
			}

			base.Draw(g);

			//Get the circle image
			Image circleImage = GetCircleImage();

			//Set the location
			PointF location = DrawLocation;

			//Set the draw bounds
			RectangleF drawbounds = new RectangleF(location.X - mRadius, location.Y - mRadius, mRadius * 2, mRadius * 2);


			if (Level.ShowCollision || (!HasPegInfo && circleImage == null)) {
				if (!Level.ShowPreview) {
					//Draw the collision white circle
					g.FillEllipse(Brushes.White, drawbounds);
				}
			} else {
				if (HasPegInfo) {
					//Draw the PeggleEdit style peg
					g.FillEllipse(new SolidBrush(PegInfo.GetOuterColour()), drawbounds);
					drawbounds.Inflate(-2, -2);
					g.FillEllipse(new SolidBrush(PegInfo.GetInnerColour()), drawbounds);
				} else {
					//Draw the circle image
					g.DrawImage(circleImage, location.X - (circleImage.Width / 2), location.Y - (circleImage.Height / 2), circleImage.Width, circleImage.Height);
				}
			}
		}
Example #33
0
		internal override RectangleF getRepaintRect(bool connected)
		{
			RectangleF result = new RectangleF(0, 0, 0, 0);

			if (!connected)
				result = getBoundingRect();
			else
			{
				RectangleF rc = getBoundingRect();
				InvalidAreaUpdater inv = new InvalidAreaUpdater(rc, false);
				visitHierarchy(inv);

				result = inv.getInvalidRect();
			}

			result.Inflate(flowChart.SelHandleSize, flowChart.SelHandleSize);

			if (selectedBoxes.Count > 0)
			{
				// some boxes might be rotated and their rotation handles
				// be quite outside the selection rectangle
				float infl = 6 * Constants.getMillimeter(flowChart.MeasureUnit);
				result.Inflate(infl, infl);
			}

			return result;
		}
        // draws a single char to the graphics object within specified rectangle
        // can be used with any graphical object
        public void DrawChar(ulong bits, Graphics g, Rectangle rect)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            float size = rect.Height / VSEGMENTS;       // height and width makes a square
            float space = (size * segmentSpace) / 2;    // space between segments

            using (SolidBrush segmentBrush = new SolidBrush(ForeColor))
            {
                for (int y = 0; y < VSEGMENTS; y++)         // vertical row
                {
                    for (int x = 0; x < HSEGMENTS; x++)     // horizontal row
                    {
                        if ((bits & 1) != 0)                // if bit 1 is set, fill segment
                        {
                            RectangleF segmentRect = new RectangleF(rect.X + x * size, y * size, size, size);
                            if ((space * 2) < size)         // don't inflate to zero
                                segmentRect.Inflate(-space, -space);
                            g.FillEllipse(segmentBrush, segmentRect);
                        }
                        bits = bits >> 1;                   // roll bits to the right
                    }
                }
            }
        }
Example #35
0
        /// <returns>true, if the selection should continue in the background of the bar.</returns>
        public bool MouseDown(MouseEventArgs e, Size parentControlSize, Vector2 clickPos)
        {
            _selectionMode = SelectionMode.None;
            _overallDelta  = 0;

            // check if the mouse click was in the bar area
            RectangleF barArea       = getBarArea(parentControlSize);
            RectangleF selectionArea = barArea;

            selectionArea.Inflate(10.0f, _selectionMaxPixelDistanceForMove * 0.8f);
            if (!selectionArea.Contains(e.Location))
            {
                return(true);
            }

            switch (e.Button)
            {
            case MouseButtons.Left:
                // check if the mouse click was on one of the two sliders
                float distanceToSelectedLimit0 = Math.Abs(e.Y - ToVisualY(barArea, _selectedLimit0));
                float distanceToSelectedLimit1 = Math.Abs(e.Y - ToVisualY(barArea, _selectedLimit1));
                if (distanceToSelectedLimit0 < distanceToSelectedLimit1)
                {
                    if (distanceToSelectedLimit0 < _selectionMaxPixelDistanceForMove)
                    {
                        _selectionMode = SelectionMode.SelectedLimit0;
                    }
                }
                else
                {
                    if (distanceToSelectedLimit1 < _selectionMaxPixelDistanceForMove)
                    {
                        _selectionMode = SelectionMode.SelectedLimit1;
                    }
                }

                // check if a the click happend on a room
                if (barArea.Contains(e.Location) && _selectionMode == SelectionMode.None)
                {
                    for (int groupIndex = 0; groupIndex < GroupCount; ++groupIndex)
                    {
                        RectangleF groupArea = groupGetArea(barArea, groupIndex);
                        if (groupArea.Contains(e.Location))
                        {
                            _groupMouseClicked = groupIndex;

                            float mouseDepth = FromVisualY(barArea, e.Y);
                            List <List <RelevantRoom> > roomSequences = groupBuildRoomSequences(clickPos, groupIndex);
                            float sequenceWidth = groupArea.Width / roomSequences.Count;
                            for (int i = 0; i < roomSequences.Count; ++i)
                            {
                                float posX0 = groupArea.X + sequenceWidth * i;
                                float posX1 = groupArea.X + sequenceWidth * (i + 1);
                                if (e.X >= posX0 && e.X <= posX1)
                                {
                                    for (int j = roomSequences[i].Count - 1; j >= 0; --j)
                                    {
                                        if (mouseDepth <= roomSequences[i][j].MaxDepth && mouseDepth >= roomSequences[i][j].MinDepth)
                                        {
                                            _roomMouseClicked = roomSequences[i][j].Room;
                                            _roomMouseOffset  = mouseDepth - _roomMouseClicked.Position.Y;

                                            // If multiple rooms are selected, don't reset selection.
                                            if (_editor.SelectedRooms.Count <= 1 || !_editor.SelectedRooms.Contains(_roomMouseClicked))
                                            {
                                                SelectedRoom?.Invoke(new[] { _roomMouseClicked });
                                            }

                                            InvalidateParent?.Invoke();
                                            _selectionMode = SelectionMode.RoomMove;
                                            return(false);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }

                    selectionArea.Y      = ToVisualY(barArea, Math.Max(_selectedLimit0, _selectedLimit1));
                    selectionArea.Height = Math.Abs(ToVisualY(barArea, _selectedLimit0) - ToVisualY(barArea, _selectedLimit1));

                    if (selectionArea.Contains(e.Location))
                    {
                        _barMouseOffset = distanceToSelectedLimit0;
                        _selectionMode  = SelectionMode.SelectedLimitBoth;
                    }
                }
                break;

            case MouseButtons.Middle:
            case MouseButtons.XButton1:
            case MouseButtons.XButton2:
                for (int groupIndex = 0; groupIndex < DepthProbes.Count; ++groupIndex)
                {
                    RectangleF groupArea = groupGetArea(barArea, groupIndex);
                    if (groupArea.Contains(e.Location))
                    {
                        DepthProbes.RemoveAt(groupIndex);
                        InvalidateParent?.Invoke();
                        break;
                    }
                }
                break;
            }

            return(false);
        }
Example #36
0
        public override bool IsClicked(Point pos)
        {
            // Create an array containing all the points in the path
            Point[] pathPoints = new Point[points.Count + 1];
            pathPoints[0] = location;
            Array.Copy(points.ToArray(), 0, pathPoints, 1, points.Count);

            // Loop through all the line segments and check if `pos` is close enough to one of them
            for(int i = 0; i < pathPoints.Length - 1; ++i)
            {
                RectangleF bounds = new RectangleF(
                    new Point(Math.Min(pathPoints[i].X, pathPoints[i + 1].X), Math.Min(pathPoints[i].Y, pathPoints[i + 1].Y)),
                    new Size(Math.Abs(pathPoints[i].X - pathPoints[i + 1].X), Math.Abs(pathPoints[i].Y - pathPoints[i + 1].Y)));
                bounds.Inflate(ALLOWED_ERROR + penWidth / 2, ALLOWED_ERROR + penWidth / 2);
                if(bounds.Contains(pos) && LayerLine.DistanceToLine(pathPoints[i], pathPoints[i + 1], pos) < ALLOWED_ERROR + penWidth / 2)
                    return true;
            }

            // No line segment found that is close enough, so we return false
            return false;
        }
Example #37
0
        public async Task MemoryRenderTarget_2DInitError()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            // Ensure that any async disposal is  done before we create a new GraphicsCore
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();

            GDI.Bitmap?screenshot = null;
            using (TestUtilities.FailTestOnInternalExceptions())
                using (GraphicsCore.AutomatedTest_NewTestEnvironment())
                {
                    await GraphicsCore.Loader
                    .ConfigureLoading(settings => settings.ThrowD2DInitDeviceError = true)
                    .LoadAsync();

                    Assert.IsTrue(GraphicsCore.IsLoaded);
                    Assert.IsFalse(GraphicsCore.Current.DefaultDevice !.Supports2D);

                    using (var solidBrush = new SolidBrushResource(Color4.Gray))
                        using (var textFormat = new TextFormatResource("Arial", 36))
                            using (var textBrush = new SolidBrushResource(Color4.RedColor))

                                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                                {
                                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                                    // Get and configure the camera
                                    var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                                    camera.Position = new Vector3(0f, 5f, -7f);
                                    camera.Target   = new Vector3(0f, 0f, 0f);
                                    camera.UpdateCamera();

                                    // 2D rendering is made here
                                    var d2dDrawingLayer = new Custom2DDrawingLayer(graphics =>
                                    {
                                        var d2dRectangle = new GDI.RectangleF(10, 10, 236, 236);
                                        graphics.Clear(Color4.LightBlue);
                                        graphics.FillRoundedRectangle(
                                            d2dRectangle, 30, 30,
                                            solidBrush);

                                        d2dRectangle.Inflate(-10, -10);
                                        graphics.DrawText("Hello Direct2D!", textFormat, d2dRectangle, textBrush);
                                    });

                                    // Define scene
                                    await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                                    {
                                        var resD2DTexture = manipulator.AddResource(
                                            _ => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                                        var resD2DMaterial = manipulator.AddStandardMaterialResource(resD2DTexture);
                                        var resGeometry    = manipulator.AddResource(
                                            _ => new GeometryResource(new CubeGeometryFactory()));

                                        var newMesh           = manipulator.AddMeshObject(resGeometry, resD2DMaterial);
                                        newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                                        newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                                    });

                                    // Take screenshot
                                    await memRenderTarget.AwaitRenderAsync();

                                    screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");
                                }
                }

            // Calculate and check difference
            Assert.IsNotNull(screenshot);
            var isNearEqual = BitmapComparison.IsNearEqual(
                screenshot, TestUtilities.LoadBitmapFromResource("ErrorHandling", "SimpleObject.png"));

            Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
        }
Example #38
0
 public System.Drawing.RectangleF MeasureItem(System.Drawing.Graphics g, System.Drawing.RectangleF innerArea)
 {
     innerArea.Inflate(3.0f * _shadowLength / 2, 3.0f * _shadowLength / 2);
     return(innerArea);
 }
Example #39
0
        public void Paint(ChartPaintEventArgs e)
        {
            var g = e.Graphics;
                var chart = e.Chart;

                // dragging outline / trail
                if (DraggedRect != RectangleF.Empty)
                    g.DrawRectangle(Pens.Red, DraggedRect);

                // insertion indicator line
                if (Row != int.MinValue)
                {
                    float y = e.Chart._ChartRowToChartCoord(Row) + e.Chart.BarHeight / 2.0f;
                    g.DrawLine(Pens.CornflowerBlue, new PointF(0, y), new PointF(e.Chart.Width, y));
                }

                // tool tip
                if (_mToolTipMouse != Point.Empty && _mToolTipText != string.Empty)
                {
                    var size = g.MeasureString(_mToolTipText, chart.Font).ToSize();
                    var tooltiprect = new RectangleF(_mToolTipMouse, size);
                    tooltiprect.Offset(0, -tooltiprect.Height);
                    var textstart = new PointF(tooltiprect.Left, tooltiprect.Top);
                    tooltiprect.Inflate(5, 5);
                    g.FillRectangle(Brushes.LightYellow, tooltiprect);
                    g.DrawString(_mToolTipText, chart.Font, Brushes.Black, textstart);
                }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("jumpmap", Response))
            {
                return;
            }

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            //
            // Jump
            //
            int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12);

            //
            // Content & Coordinates
            //
            Selector selector;
            Location loc;
            if (Request.HttpMethod == "POST")
            {
                Sector sector;
                try
                {
                    sector = GetPostedSector();
                }
                catch (Exception ex)
                {
                    SendError(400, "Invalid request", ex.Message);
                    return;
                }

                if (sector == null)
                {
                    SendError(400, "Invalid request", "Either file or data must be supplied in the POST data.");
                    return;
                }

                int hex = GetIntOption("hex", Astrometrics.SectorCentralHex);
                loc = new Location(new Point(0, 0), hex);
                selector = new HexSectorSelector(resourceManager, sector, loc.HexLocation, jump);
            }
            else
            {
                SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

                if (HasOption("sector") && HasOption("hex"))
                {
                    string sectorName = GetStringOption("sector");
                    int hex = GetIntOption("hex", 0);
                    loc = new Location(map.FromName(sectorName).Location, hex);
                }
                else if (HasOption("sx") && HasOption("sy") && HasOption("hx") && HasOption("hy"))
                {
                    int sx = GetIntOption("sx", 0);
                    int sy = GetIntOption("sy", 0);
                    int hx = GetIntOption("hx", 0);
                    int hy = GetIntOption("hy", 0);
                    loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy);
                }
                else if (HasOption("x") && HasOption("y"))
                {
                    loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0));
                }
                else
                {
                    loc = new Location(map.FromName("Spinward Marches").Location, 1910);
                }
                selector = new HexSelector(map, resourceManager, loc, jump);
            }

            //
            // Scale
            //
            double scale = Util.Clamp(GetDoubleOption("scale", 64), MinScale, MaxScale);

            //
            // Options & Style
            //
            MapOptions options = MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.ForceHexes;
            Stylesheet.Style style = Stylesheet.Style.Poster;
            ParseOptions(ref options, ref style);

            //
            // Border
            //
            bool border = GetBoolOption("border", defaultValue: true);

            //
            // Clip
            //
            bool clip = GetBoolOption("clip", defaultValue: true);

            //
            // What to render
            //

            RectangleF tileRect = new RectangleF();

            Point coords = Astrometrics.LocationToCoordinates(loc);
            tileRect.X = coords.X - jump - 1;
            tileRect.Width = jump + 1 + jump;
            tileRect.Y = coords.Y - jump - 1;
            tileRect.Height = jump + 1 + jump;

            // Account for jagged hexes
            tileRect.Y += (coords.X % 2 == 0) ? 0 : 0.5f;
            tileRect.Inflate(0.35f, 0.15f);

            Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY));

            // Construct clipping path
            List<Point> clipPath = new List<Point>(jump * 6 + 1);
            Point cur = coords;
            for (int i = 0; i < jump; ++i)
            {
                // Move J parsecs to the upper-left (start of border path logic)
                cur = Astrometrics.HexNeighbor(cur, 1);
            }
            clipPath.Add(cur);
            for (int dir = 0; dir < 6; ++dir)
            {
                for (int i = 0; i < jump; ++i)
                {
                    cur = Astrometrics.HexNeighbor(cur, (dir + 3) % 6); // Clockwise from upper left
                    clipPath.Add(cur);
                }
            }

            Stylesheet styles = new Stylesheet(scale, options, style);

            // If any names are showing, show them all
            if (styles.worldDetails.HasFlag(WorldDetails.KeyNames))
            {
                styles.worldDetails |= WorldDetails.AllNames;
            }

            // Compute path
            float[] edgeX, edgeY;
            RenderUtil.HexEdges(styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex,
                out edgeX, out edgeY);
            PointF[] boundingPathCoords;
            byte[] boundingPathTypes;
            PathUtil.ComputeBorderPath(clipPath, edgeX, edgeY, out boundingPathCoords, out boundingPathTypes);

            Render.RenderContext ctx = new Render.RenderContext();
            ctx.resourceManager = resourceManager;
            ctx.selector = selector;
            ctx.tileRect = tileRect;
            ctx.scale = scale;
            ctx.options = options;
            ctx.styles = styles;
            ctx.tileSize = tileSize;
            ctx.border = border;

            ctx.clipPath = clip ? new XGraphicsPath(boundingPathCoords, boundingPathTypes, XFillMode.Alternate) : null;
            ProduceResponse("Jump Map", ctx, tileSize, transparent: clip);
        }
Example #41
0
        public void draw(Graphics g, PointF autoScrollPosition)
        {
            Pen pen;
            Brush brush;
            if (selected)
            {
                pen = tabela.ItemBorderSelectedPen;
                brush = tabela.ItemTextSelectedBrush;
            }
            else
            {
                pen = tabela.ItemBorderPen;
                brush = tabela.ItemTextBrush;
            }
            Font f = tabela.ItemFont;
            Font fBold = tabela.ItemBoldFont;
            Font fVrednostPreskoka = tabela.VrednostPreskokaFont;

            RectangleF rect = new RectangleF(location, size);
            rect.Offset(autoScrollPosition.X, autoScrollPosition.Y);

            g.FillRectangle(tabela.ItemBackroundBrush, rect);

            string number = broj.ToString() + '.';

            if (cutted)
            {
                g.DrawRectangle(tabela.EraseBorderPen, rect.X, rect.Y, rect.Width, rect.Height);
                DashStyle style = pen.DashStyle;
                pen.DashStyle = DashStyle.Dot;
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                pen.DashStyle = style;
            }
            else
            {
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
            }
            g.DrawString(number, f, brush, (RectangleF)rect);

            if (element != null)
            {
                string naziv = element.Naziv;
                if (naziv != "")
                    naziv += '\n';
                naziv += element.EngleskiNaziv;
                string nazivGim = element.NazivPoGimnasticaru;

                float nazivHeigth = 0.0f;
                // TODO2: Probaj da razdvojis srpski i engleski naziv (linijom ili malim razmakom)
                if (naziv != "")
                {
                    float xNaziv = rect.X + g.MeasureString(number + new String(' ', 3), f).Width;
                    nazivHeigth = g.MeasureString(
                        naziv, f, new SizeF(rect.Right - xNaziv, rect.Height)).Height;
                    RectangleF nazivRect = new RectangleF(xNaziv, rect.Y,
                        rect.Right - xNaziv, nazivHeigth);
                    g.DrawString(naziv, f, brush, nazivRect);
                }
                float nazivGimHeigth = 0.0f;
                if (nazivGim != "")
                {
                    nazivGim = "(" + nazivGim + ")";
                    nazivGimHeigth = g.MeasureString(nazivGim, fBold, rect.Size).Height;
                    nazivGimHeigth *= 2;
                    RectangleF nazivGimRect = new RectangleF(rect.X, rect.Y + nazivHeigth,
                        rect.Width, nazivGimHeigth);
                    StringFormat fmt = new StringFormat();
                    fmt.Alignment = StringAlignment.Center;
                    fmt.LineAlignment = StringAlignment.Center;
                    g.DrawString(nazivGim, fBold, brush, nazivGimRect, fmt);
                }

                if (Image != null)
                {
                    float textHeigth = nazivHeigth + nazivGimHeigth;
                    PointF imageTopLeft = new PointF(rect.Left, rect.Top + textHeigth);
                    SizeF imageSize = new SizeF(rect.Width, rect.Height - textHeigth);
                    RectangleF imageRect = new RectangleF(imageTopLeft, imageSize);
                    float hRedukcija =
                        imageRect.Width - imageRect.Width * Slika.ProcenatRedukcije / 100f;
                    float vRedukcija =
                        imageRect.Height - imageRect.Height * Slika.ProcenatRedukcije / 100f;
                    imageRect.Inflate(- hRedukcija / 2, - vRedukcija / 2);
                    imageRect.Inflate(-Math.Max(imageRect.Width / 50, 1),
                        -Math.Max(imageRect.Height / 50, 1));
                    if (selected)
                        PictureBoxPlus.scaleImageIsotropically(g, SelectedImage, imageRect);
                    else
                        PictureBoxPlus.scaleImageIsotropically(g, Image, imageRect);
                }

                RectangleF vaRect = RectangleF.Empty;
                if (element.Sprava == Sprava.Preskok && element.VrednostPreskoka != null)
                {
                    string vrednost = element.VrednostPreskoka.ToString();
                    SizeF vrednostSize = g.MeasureString(vrednost, fVrednostPreskoka);
                    PointF vrednostLoc = new PointF(rect.X, rect.Bottom - vrednostSize.Height);
                    vaRect = new RectangleF(vrednostLoc, vrednostSize);
                    //g.DrawRectangle(pen, vaRect.X, vaRect.Y, vaRect.Width, vaRect.Height);
                    g.DrawString(vrednost, fVrednostPreskoka, brush, vaRect);
                }

                if (element.Varijante.Count > 0)
                {
                    string va = "VA";
                    SizeF vaSize = g.MeasureString(va, f);
                    PointF vaLoc;
                    if (vaRect != RectangleF.Empty)
                        vaLoc = new PointF(vaRect.Right, rect.Bottom - vaSize.Height);
                    else
                        vaLoc = new PointF(rect.X, rect.Bottom - vaSize.Height);
                    vaRect = new RectangleF(vaLoc, vaSize);
                    g.DrawRectangle(pen, vaRect.X, vaRect.Y, vaRect.Width, vaRect.Height);
                    g.DrawString(va, f, brush, vaRect);
                }

                if (element.VideoKlipovi.Count > 0)
                {
                    string vi = "VI";
                    SizeF viSize = g.MeasureString(vi, f);
                    PointF viLoc;
                    if (vaRect != RectangleF.Empty)
                        viLoc = new PointF(vaRect.Right, rect.Bottom - viSize.Height);
                    else
                        viLoc = new PointF(rect.X, rect.Bottom - viSize.Height);
                    RectangleF viRect = new RectangleF(viLoc, viSize);
                    g.DrawRectangle(pen, viRect.X, viRect.Y, viRect.Width, viRect.Height);
                    g.DrawString(vi, f, brush, viRect);
                }
            }
        }
Example #42
0
 public void DrawArc(ICanvas canvas, Pen pen, UnitPoint center, float radius, float startAngle, float sweepAngle)
 {
     PointF p1 = ToScreen(center);
     radius = (float)Math.Round(ToScreen(radius));
     RectangleF r = new RectangleF(p1, new SizeF());
     r.Inflate(radius, radius);
     if (radius > 0 && radius < 1e8f )
         canvas.Graphics.DrawArc(pen, r, -startAngle, -sweepAngle);
 }
Example #43
0
		public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp)
		{

			if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle))
				return;

			// draw the outer border
			Rectangle button_bounds = dtp.ClientRectangle;
			DateTimePickerDrawBorder (dtp, dc, clip_rectangle);

			// deflate by the border width
			if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
				button_bounds.Inflate (-2,-2);
				if (!dtp.ShowUpDown) {
					DateTimePickerDrawDropDownButton (dtp, dc, clip_rectangle);
				} else {
					ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal;
					ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal;
					Rectangle up_bounds = dtp.drop_down_arrow_rect;
					Rectangle down_bounds = dtp.drop_down_arrow_rect;

					up_bounds.Height = up_bounds.Height / 2;
					down_bounds.Y = up_bounds.Height;
					down_bounds.Height = dtp.Height - up_bounds.Height;
					if (down_bounds.Height > up_bounds.Height)
					{
						down_bounds.Y += 1;
						down_bounds.Height -= 1;
					}

					up_bounds.Inflate (-1, -1);
					down_bounds.Inflate (-1, -1);

					ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state);
					ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state);
				}
			}

			// render the date part
			if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
				return;

			// fill the background
			dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);

			// Update date_area_rect if we are drawing the checkbox
			Rectangle date_area_rect = dtp.date_area_rect;
			if (dtp.ShowCheckBox) {
				Rectangle check_box_rect = dtp.CheckBoxRect;
				date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
				date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;

				ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
				CPDrawCheckBox(dc, check_box_rect, bs);

				if (dtp.is_checkbox_selected)
					CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
			}

			// render each text part
			using (StringFormat text_format = StringFormat.GenericTypographic)
			{
				text_format.LineAlignment = StringAlignment.Near;
				text_format.Alignment = StringAlignment.Near;
				text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
				text_format.FormatFlags &= ~StringFormatFlags.NoClip;

				// Calculate the rectangles for each part 
				if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
				{
					Graphics gr = dc;
					for (int i = 0; i < dtp.part_data.Length; i++)
					{
						DateTimePicker.PartData fd = dtp.part_data[i];
						RectangleF text_rect = new RectangleF();
						string text = fd.GetText(dtp.Value);
						text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
						if (!fd.is_literal)
							text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);

						if (i > 0) {
							text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
						} else {
							text_rect.X = date_area_rect.X;
						}
						text_rect.Y = 2;
						text_rect.Inflate (1, 0);
						fd.drawing_rectangle = text_rect;
					}
				}
				
				// draw the text part
				Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ?
						SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false
				RectangleF clip_rectangleF = clip_rectangle;

				for (int i = 0; i < dtp.part_data.Length; i++)
				{
					DateTimePicker.PartData fd = dtp.part_data [i];
					string text;

					if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle))
						continue;

					text = dtp.editing_part_index == i ? dtp.editing_text : fd.GetText (dtp.Value);

					PointF text_position = new PointF ();
					SizeF text_size;
					RectangleF text_rect;

					text_size = dc.MeasureString (text, dtp.Font, 250, text_format);
					text_position.X = (fd.drawing_rectangle.Left + fd.drawing_rectangle.Width / 2) - text_size.Width / 2;
					text_position.Y = (fd.drawing_rectangle.Top + fd.drawing_rectangle.Height / 2) - text_size.Height / 2;
					text_rect = new RectangleF (text_position, text_size);
					text_rect = RectangleF.Intersect (text_rect, date_area_rect);
					
					if (text_rect.IsEmpty)
						break;

					if (text_rect.Right >= date_area_rect.Right)
						text_format.FormatFlags &= ~StringFormatFlags.NoClip;
					else
						text_format.FormatFlags |= StringFormatFlags.NoClip;
					
					if (fd.Selected) {
						dc.FillRectangle (SystemBrushes.Highlight, text_rect);
						dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format);
					
					} else {
						dc.DrawString (text, dtp.Font, text_brush, text_rect, text_format);
					}

					if (fd.drawing_rectangle.Right > date_area_rect.Right)
						break; // the next part would be not be visible, so don't draw anything more.
				}
			}
		}
Example #44
0
        public override void Draw(RectangleF rectB)
        {
            CGColorSpace cs = null;
            CGContext ctx = null;
            RectangleF bds;

            ctx = UIGraphics.GetCurrentContext ();
            cs = CGColorSpace.CreateDeviceRGB ();

            if (Vertical){
                ctx.TranslateCTM (0, Bounds.Height);
                ctx.ScaleCTM (1, -1);
                bds = Bounds;
            } else {
                ctx.TranslateCTM (0, Bounds.Height);
                ctx.RotateCTM ((float)Math.PI/2);
                bds = new RectangleF (0, 0, Bounds.Height, Bounds.Width);
            }

            ctx.SetFillColorSpace (cs);
            ctx.SetStrokeColorSpace (cs);

            if (NumLights == 0){
                float currentTop = 0;

                if (BgColor != null){
                    BgColor.SetColor ();
                    ctx.FillRect (bds);
                }

                foreach (var thisTresh in ColorThresholds){
                    var val = Math.Min (thisTresh.MaxValue, Level);

                    var rect = new RectangleF (0, bds.Height * currentTop, bds.Width, bds.Height * (val - currentTop));
                    thisTresh.Color.SetColor ();
                    ctx.FillRect (rect);

                    if (Level < thisTresh.MaxValue)
                        break;
                    currentTop = val;
                }

                if (BorderColor != null){
                    BorderColor.SetColor ();
                    bds.Inflate (-0.5f, -0.5f);
                    ctx.StrokeRect (bds);
                }
            } else {
                float lightMinVal = 0;
                float insetAmount, lightVSpace;
                int peakLight = -1;

                lightVSpace = bds.Height / (float) NumLights;
                if (lightVSpace < 4)
                    insetAmount = 0;
                else if (lightVSpace < 8)
                    insetAmount = 0.5f;
                else
                    insetAmount = 1;

                if (PeakLevel > 0){
                    peakLight = (int) PeakLevel * NumLights;
                    if (peakLight >= NumLights)
                        peakLight = NumLights-1;
                }

                for (int light_i = 0; light_i< NumLights; light_i++){
                    float lightMaxVal = (light_i + 1) / (float)NumLights;
                    float lightIntensity;
                    RectangleF lightRect;
                    UIColor lightColor;

                    if (light_i == peakLight){
                        lightIntensity = 1;
                    } else {
                        lightIntensity = (Level - lightMinVal) / (lightMaxVal - lightMinVal);
                        lightIntensity = Clamp (0, lightIntensity, 1);
                        if (!VariableLightIntensity && lightIntensity > 0)
                            lightIntensity = 1;
                    }

                    lightColor = ColorThresholds [0].Color;
                    int color_i = 0;
                    for (; color_i < ColorThresholds.Length-1; color_i++){
                        var thisTresh = ColorThresholds [color_i];
                        var nextTresh = ColorThresholds [color_i+1];
                        if (thisTresh.MaxValue < lightMaxVal)
                            lightColor = nextTresh.Color;
                    }

                    lightRect = new RectangleF (0, bds.Height * color_i / (float) NumLights,
                                                bds.Width, bds.Height * (1f / NumLights));
                    lightRect.Inflate (-insetAmount, -insetAmount);
                    if (BgColor != null){
                        BgColor.SetColor ();
                        ctx.FillRect (lightRect);
                    }
                    if (lightIntensity == 1){
                        lightColor.SetColor ();
                        ctx.FillRect (lightRect);
                    } else if (lightIntensity > 0){
                        using (var clr = new CGColor (lightColor.CGColor, lightIntensity)){
                            ctx.SetFillColorWithColor (clr);
                            ctx.FillRect (lightRect);
                        }
                    }

                    if (BorderColor != null){
                        BorderColor.SetColor ();
                        lightRect.Inflate (-0.5f, -0.5f);
                        ctx.StrokeRect (lightRect);
                    }

                    lightMinVal = lightMaxVal;
                }
            }
            cs.Dispose ();
        }