コード例 #1
0
 internal protected override void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
 {
     cr.MoveTo(x + 0.5, y);
     cr.LineTo(x + 0.5, y + lineHeight);
     cr.SetSourceColor(color);
     cr.Stroke();
 }
コード例 #2
0
        public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();
            ctx.Translate(x + 30, y + 30);
            ctx.SetLineWidth(3);

            // Rotation

            double end = 270;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(30, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();
                ctx.Restore();
            }

            //ctx.ResetTransform();
            ctx.Restore();
        }
コード例 #3
0
ファイル: ReferencePainter.cs プロジェクト: git-thinh/limada
        public virtual void SpeedTest(Xwt.Drawing.Context ctx, double sx, double sy)
        {
            ctx.Save();

            ctx.Translate(sx, sy);

            var n  = 1000;
            var ll = 80;
            var p  = new Point(0, 0);

            for (double i = 1; i < n; i++)
            {
                ctx.MoveTo(p.X, p.Y);

                ctx.SetColor(new Color(i / n, i / n, i / n));

                ctx.LineTo(p.X + ll, p.Y + ll);
                ctx.Stroke();

                if (p.Y + ll > this.Bounds.Bottom)
                {
                    p.Y  = 0;
                    p.X += ll + 5;
                }
                else
                {
                    p.Y++;
                }
            }

            ctx.Restore();
        }
コード例 #4
0
ファイル: HelperMethods.cs プロジェクト: radtek/datawf
 public static void DrawLine(this Xwt.Drawing.Context cr, Color color, double x1, double y1, double x2, double y2)
 {
     cr.SetSourceColor(color);
     cr.MoveTo(x1, y1);
     cr.LineTo(x2, y2);
     cr.Stroke();
 }
コード例 #5
0
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            if (Bounds.IsEmpty)
            {
                return;
            }

            ctx.Rectangle(0, 0, Bounds.Width, Bounds.Height);
            Gradient g = null;

            if (Linear)
            {
                g = new LinearGradient(0, 0, Bounds.Width, Bounds.Height);
            }
            else
            {
                g = new RadialGradient(Bounds.Width / 2, Bounds.Height / 2, Bounds.Width / 2, Bounds.Width / 2, Bounds.Height / 2, Bounds.Width / 4);
            }
            g.AddColorStop(0, new Color(1, 0, 0));
            g.AddColorStop(1, new Color(0, 1, 0));
            ctx.Pattern = g;
            ctx.Fill();

            Rectangle r = rect.Inflate(5, 5);

            ctx.Rectangle(r);
            ctx.SetColor(new Color(0, 0, 1));
            ctx.SetLineWidth(1);
            ctx.Stroke();
        }
コード例 #6
0
ファイル: FoldMarkerMargin.cs プロジェクト: radtek/datawf
        void DrawFoldSegment(Xwt.Drawing.Context ctx, double x, double y, bool isOpen, bool isSelected)
        {
            var drawArea = new Rectangle(System.Math.Floor(x + (Width - foldSegmentSize) / 2) + 0.5,
                                         System.Math.Floor(y + (editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);

            ctx.Rectangle(drawArea);
            ctx.SetSourceColor(isOpen ? foldBgGC : foldToggleMarkerBackground);
            ctx.FillPreserve();
            ctx.SetSourceColor(isSelected ? foldLineHighlightedGC : foldLineGC);
            ctx.Stroke();

            ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                         drawArea.X + drawArea.Width * 2 / 10,
                         drawArea.Y + drawArea.Height / 2,
                         drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
                         drawArea.Y + drawArea.Height / 2);

            if (!isOpen)
            {
                ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                             drawArea.X + drawArea.Width / 2,
                             drawArea.Y + drawArea.Height * 2 / 10,
                             drawArea.X + drawArea.Width / 2,
                             drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10);
            }
        }
コード例 #7
0
        public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y)
        {
            // draws a line along the x-axis from (0,0) to (r,0) with a constant translation and an increasing
            // rotational component. This composite transform is then applied to a vertical line, with inverse
            // color, and an additional x-offset, to form a mirror image figure for easy visual comparison.
            // These transformed points must be drawn with the identity CTM, hence the Restore() each time.

            ctx.Save();                 // save caller's context (assumed to be the Identity CTM)
            ctx.SetLineWidth(3);        // should align exactly if drawn with half-pixel coordinates

            // Vector length (pixels) and rotation limit (degrees)
            double r   = 30;
            double end = 270;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();                     // save context and identity CTM for each line

                // Set up translation to centre point of first figure, ensuring pixel alignment
                ctx.Translate(x + 30.5, y + 30.5);
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(r, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();                   // stroke first figure with composite Translation and Rotation CTM

                // Generate mirror image figure as a visual test of TransformPoints
                Point   p0 = new Point(0, 0);
                Point   p1 = new Point(0, -r);
                Point[] p  = new Point[] { p0, p1 };
                ctx.TransformPoints(p);         // using composite transformation

                ctx.Restore();                  // restore identity CTM
                ctx.Save();                     // save again (to restore after additional Translation)

                ctx.Translate(2 * r + 1, 0);    // extra x-offset to clear first figure
                ctx.MoveTo(p[0]);
                ctx.LineTo(p[1]);
                c = 1 - c;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();           // stroke transformed points with offset in CTM

                ctx.Restore();          // restore identity CTM for next line
            }
            ctx.Restore();              // restore caller's context
        }
コード例 #8
0
ファイル: NotebookSample.cs プロジェクト: sandeep-datta/xwt
 protected override void OnDraw(Context ctx)
 {
     ctx.SetLineWidth (5);
     ctx.SetColor (new Color (1.0f, 0f, 0.5f));
     ctx.Rectangle (5, 5, 200, 100);
     ctx.FillPreserve ();
     ctx.SetColor (new Color (0f, 0f, 1f));
     ctx.Stroke ();
 }
コード例 #9
0
		public void PatternsAndImages (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			ctx.SetColor (Colors.Black);
			// Dashed lines

			ctx.SetLineWidth (2);
			ctx.SetLineDash (15, 10, 10, 5, 5);
			ctx.Rectangle (10, 10, 100, 100);
			ctx.Stroke ();
			ctx.SetLineDash (0);
			
			// Image
			var arcColor = new Color (1, 0, 1);
			ImageBuilder ib = new ImageBuilder (30, 30);
			ib.Context.Arc (15, 15, 15, 0, 360);
			ib.Context.SetColor (arcColor);
			ib.Context.Fill ();
			ib.Context.SetColor (Colors.DarkKhaki);
			ib.Context.Rectangle (0, 0, 5, 5);
			ib.Context.Fill ();
			var img = ib.ToVectorImage ();
			ctx.DrawImage (img, 0, 0);
			ctx.DrawImage (img, 0, 50, 50, 10);
			
			ctx.Arc (100, 100, 15, 0, 360);
			arcColor.Alpha = 0.4;
			ctx.SetColor (arcColor);
			ctx.Fill ();
			
			// ImagePattern
			
			ctx.Save ();
			
			ctx.Translate (x + 130, y);
			ctx.Pattern = new ImagePattern (img);
			ctx.Rectangle (0, 0, 100, 100);
			ctx.Fill ();
			ctx.Restore ();
			
			ctx.Restore ();
			
			// Setting pixels
			
			ctx.SetLineWidth (1);
			for (int i=0; i<50;i++) {
				for (var j=0; j<50;j++) {
					Color c = Color.FromHsl (0.5, (double)i / 50d, (double)j / 50d);
					ctx.Rectangle (i, j, 1, 1);
					ctx.SetColor (c);
					ctx.Fill ();
				}
			}
		}	
コード例 #10
0
ファイル: EmptyControl.cs プロジェクト: fourtf/4Plug
 protected override void OnDraw(Context ctx, Rectangle dirtyRect)
 {
     if (Window?.DrawRedDebugOutline ?? false)
     {
         ctx.SetColor(Colors.Blue);
         ctx.Rectangle(0, 0, Bounds.Width, Bounds.Height);
         ctx.Stroke();
         ctx.SetColor(Colors.Black);
     }
 }
コード例 #11
0
ファイル: UnderlineMarker.cs プロジェクト: radtek/datawf
        void InternalDraw(int markerStart, int markerEnd, TextEditor editor, Xwt.Drawing.Context cr, TextLayout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (markerStart >= markerEnd)
            {
                return;
            }
            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;
                double /*lineNr,*/ x_pos;

                x_pos = layout.GetCoordinateFromIndex(start - startOffset).X;
                @from = startXPos + (int)(x_pos);

                x_pos = layout.GetCoordinateFromIndex(end - startOffset).X;

                to = startXPos + (int)(x_pos);
            }
            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from >= to)
            {
                return;
            }
            double height = editor.LineHeight / 5;

            if (selected)
            {
                cr.SetSourceColor(editor.ColorStyle.SelectedText.Foreground);
            }
            else
            {
                cr.SetSourceColor(ColorName == null ? Color : editor.ColorStyle.GetChunkStyle(ColorName).Foreground);
            }
            if (Wave)
            {
                //Pango.CairoHelper.ShowErrorUnderline(cr, @from, y + editor.LineHeight - height, to - @from, height);
            }
            else
            {
                cr.SetLineWidth(1);
                cr.MoveTo(@from, y + editor.LineHeight - 1.5);
                cr.LineTo(to, y + editor.LineHeight - 1.5);
                cr.Stroke();
            }
        }
コード例 #12
0
ファイル: DrawingFigures.cs プロジェクト: m13253/xwt
		/// <summary>
		/// Visual test for pixel alignment and odd/even line widths
		/// </summary>
		public void Lines (Context ctx)
		{
			ctx.Save ();

			ctx.SetColor (Colors.Black);

			int nPairs = 4;
			double length = 90;
			double gap = 2;

			// set half-pixel y-coordinate for sharp single-pixel-wide line
			// on first line of Canvas, extending to match line pairs below
			ctx.SetLineWidth (1);
			double x = 0;
			double y = 0.5;
			double end = x + 2*(length - 1) + gap;
			ctx.MoveTo (x, y);
			ctx.LineTo (end, y);
			ctx.Stroke ();

			// draw pairs of lines with odd and even widths,
			// each pair aligned on half-pixel y-coordinates
			y = 4.5;
			for (int w = 1; w <= nPairs; ++w) {
				x = 0;
				ctx.SetLineWidth (w);
				ctx.MoveTo (x, y);
				ctx.RelLineTo (length-1, 0);
				ctx.Stroke ();

				ctx.SetLineWidth (w + 1);
				x += (gap + length - 1);
				ctx.MoveTo (x, y);
				ctx.RelLineTo (length-1, 0);
				ctx.Stroke ();
				y += w * 2 + gap;
			}

			ctx.Restore ();
		}
コード例 #13
0
ファイル: ListView1.cs プロジェクト: nbros/xwt
        protected override void OnDraw(Context ctx, Rectangle cellArea)
        {
            var pct = GetValue (ValueField);
            var size = (cellArea.Width * pct) / 100f;
            cellArea.Width = (int) size;

            ctx.SetLineWidth (1);
            ctx.Rectangle (cellArea.Inflate (-0.5, -0.5));
            ctx.SetColor (Colors.LightBlue);
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Gray);
            ctx.Stroke ();
        }
コード例 #14
0
ファイル: TextLinkEditMode.cs プロジェクト: radtek/datawf
        public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics)
        {
            var caretOffset = editor.Caret.Offset - BaseOffset;

            foreach (var link in mode.Links)
            {
                if (!link.IsEditable)
                {
                    continue;
                }
                bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset;
                foreach (TextSegment segment in link.Links)
                {
                    if ((BaseOffset + segment.Offset <= metrics.TextStartOffset && metrics.TextStartOffset < BaseOffset + segment.EndOffset) || (metrics.TextStartOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < metrics.TextEndOffset))
                    {
                        int strOffset    = BaseOffset + segment.Offset - metrics.TextStartOffset;
                        int strEndOffset = BaseOffset + segment.EndOffset - metrics.TextStartOffset;

                        var x_pos  = metrics.Layout.Layout.IndexToPos(strOffset).X;
                        var x_pos2 = metrics.Layout.Layout.IndexToPos(strEndOffset).X;

                        x_pos  = (int)(x_pos);
                        x_pos2 = (int)(x_pos2);
                        Color fillGc, rectangleGc;
                        if (segment == link.PrimaryLink)
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                        }
                        else
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.SecondColor : editor.ColorStyle.SecondaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.Color : editor.ColorStyle.SecondaryTemplate.Color;
                        }

                        // Draw segment
                        double x1 = metrics.TextRenderStartPosition + x_pos - 1;
                        double x2 = metrics.TextRenderStartPosition + x_pos2 - 1 + 0.5;

                        cr.Rectangle(x1 + 0.5, y + 0.5, x2 - x1, editor.LineHeight - 1);

                        cr.SetSourceColor(fillGc);
                        cr.FillPreserve();

                        cr.SetSourceColor(rectangleGc);
                        cr.Stroke();
                    }
                }
            }
            return(true);
        }
コード例 #15
0
ファイル: ImageScaling.cs プロジェクト: m13253/xwt
		protected override void OnDraw (Context ctx, Rectangle bounds)
		{
			var lineWidth = bounds.Width / 32d;
			var section = ((bounds.Width / 2) - lineWidth / 2) / 3;

			ctx.SetLineWidth (lineWidth);

			ctx.SetColor (Colors.Black);
			ctx.Arc (bounds.Center.X, bounds.Center.Y, 1, 0, 360);
			ctx.Stroke ();
			
			ctx.SetColor (Colors.Red);
			ctx.Arc (bounds.Center.X, bounds.Center.Y, section, 0, 360);
			ctx.Stroke ();

			ctx.SetColor (Colors.Green);
			ctx.Arc (bounds.Center.X, bounds.Center.Y, section * 2, 0, 360);
			ctx.Stroke ();

			ctx.SetColor (Colors.Blue);
			ctx.Arc (bounds.Center.X, bounds.Center.Y, section * 3, 0, 360);
			ctx.Stroke ();
		}
コード例 #16
0
ファイル: DrawingTransforms.cs プロジェクト: d5nguyenvan/xwt
        public virtual void Rotate(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();
            ctx.Translate(x + 30, y + 30);
            ctx.SetLineWidth(3);

            // Rotation

            double end = 270;
            double r   = 30;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(r, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();

                // Visual test for TransformPoints
                Point   p0 = new Point(0, 0);
                Point   p1 = new Point(0, -r);
                Point[] p  = new Point[] { p0, p1 };
                ctx.TransformPoints(p);
                ctx.ResetTransform();
                ctx.Translate(2 * r + 1, 0);
                ctx.MoveTo(p[0]);
                ctx.LineTo(p[1]);
                c = 1 - c;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();
                ctx.Restore();
            }
            ctx.Restore();
        }
コード例 #17
0
ファイル: CanvasWithWidget.cs プロジェクト: Clancey/xwt
        protected override void OnDraw(Xwt.Drawing.Context ctx, Rectangle dirtyRect)
        {
            ctx.Rectangle(0, 0, Bounds.Width, Bounds.Height);
            var g = new LinearGradient(0, 0, Bounds.Width, Bounds.Height);

            g.AddColorStop(0, new Color(1, 0, 0));
            g.AddColorStop(1, new Color(0, 1, 0));
            ctx.Pattern = g;
            ctx.Fill();

            Rectangle r = rect.Inflate(5, 5);

            ctx.Rectangle(r);
            ctx.SetColor(new Color(0, 0, 1));
            ctx.SetLineWidth(1);
            ctx.Stroke();
        }
コード例 #18
0
ファイル: IconMargin.cs プロジェクト: Kalnor/monodevelop
		internal protected override void Draw (Context win, Rectangle area, long line, double x, double y)
		{
			win.Rectangle (x, y, Width, Editor.LineHeight);
			win.SetColor (Style.IconBarBg);
			win.Fill ();
			win.MoveTo (x + Width - 1, y);
			win.LineTo (x + Width - 1, y + Editor.LineHeight);
			win.SetColor (Style.IconBarSeperator);
			win.Stroke ();

			foreach (long bookmark in Data.Bookmarks) {
				if (line * Editor.BytesInRow <= bookmark && bookmark < line * Editor.BytesInRow + Editor.BytesInRow) {
					DrawBookmark (win, x, y);
					return;
				}
			}
		}
コード例 #19
0
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw(ctx);
            ctx.Translate(30, 30);
            double end = 270;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(30, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();
                ctx.Restore();
            }
        }
コード例 #20
0
ファイル: IconMargin.cs プロジェクト: radtek/datawf
        internal protected override void Draw(Xwt.Drawing.Context ctx, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            bool backgroundIsDrawn = false;

            if (lineSegment != null)
            {
                foreach (var marker in lineSegment.Markers)
                {
                    var marginMarker = marker as MarginMarker;
                    if (marginMarker != null && marginMarker.CanDrawBackground(this))
                    {
                        backgroundIsDrawn = marginMarker.DrawBackground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                    }
                }
            }

            if (!backgroundIsDrawn)
            {
                ctx.Rectangle(x, y, Width, lineHeight);
                ctx.SetSourceColor(backgroundColor);
                ctx.Fill();

                ctx.MoveTo(x + Width - 0.5, y);
                ctx.LineTo(x + Width - 0.5, y + lineHeight);
                ctx.SetSourceColor(separatorColor);
                ctx.Stroke();
            }

            if (lineSegment != null && line <= editor.Document.LineCount)
            {
                foreach (var marker in lineSegment.Markers)
                {
                    var marginMarker = marker as MarginMarker;
                    if (marginMarker != null && marginMarker.CanDrawForeground(this))
                    {
                        marginMarker.DrawForeground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                    }
                }
                if (DrawEvent != null)
                {
                    DrawEvent(this, new BookmarkMarginDrawEventArgs(editor, ctx, lineSegment, line, x, y));
                }
            }
        }
コード例 #21
0
ファイル: GroupContainer.cs プロジェクト: fourtf/4Plug
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.SetColor(Colors.Gray);
            ctx.SetLineWidth(1);

            ctx.RoundRectangle(0, Padding.Top / 2 - .5, Width - 4.5, Height - Padding.Bottom * 1.5, 3);
            ctx.Stroke();

            var tl = new TextLayout(this) { Text = title, Width = Width - Padding.Left - Padding.Right / 2 };

            ctx.SetColor(Colors.White);
            ctx.Rectangle(Padding.Left, 0, tl.GetSize().Width, Padding.Top);
            ctx.Fill();

            ctx.SetColor(Colors.Black);
            ctx.DrawTextLayout(tl, Padding.Left, 0);
        }
コード例 #22
0
        protected void TestDrawing1(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();
            ctx.Translate(x, y);

            var r = 5;
            var l = 10;
            var t = 10;
            var w = 50;
            var h = 30;


            // top left
            //ctx.Arc(l + r, t + r, r, 180, 270);
            ctx.Rectangle(l, t, w, h);
            ctx.SetColor(Colors.Black);
            ctx.Stroke();

            ctx.Restore();
        }
コード例 #23
0
        protected override void OnDraw(Xwt.Drawing.Context cr, Rectangle rect)
        {
            if (BorderVisible)
            {
                {
                    cr.SetLineWidth(1);

                    var alloc  = rect;
                    var right  = alloc.RightInside();
                    var bottom = alloc.BottomInside();

                    cr.SharpLineX(alloc.X, alloc.Y, alloc.X, bottom);
                    cr.SharpLineX(right, alloc.Y, right, bottom);

                    cr.SharpLineY(alloc.X, alloc.Y, right, alloc.Y);
                    cr.SharpLineY(alloc.X, bottom, right, bottom);

                    cr.SetColor(Colors.Gray);
                    cr.Stroke();
                }
            }
        }
コード例 #24
0
ファイル: ListView1.cs プロジェクト: KonajuGames/xwt
        protected override void OnDraw(Context ctx, Rectangle cellArea)
        {
            ctx.Rectangle (BackgroundBounds);
            ctx.SetColor (new Color (0.9, 0.9, 0.9));
            ctx.Fill ();

            ctx.Rectangle (Bounds);
            ctx.SetColor (new Color (0.7, 0.7, 0.7));
            ctx.Fill ();

            var pct = GetValue (ValueField);
            var size = (cellArea.Width * pct.Value) / 100f;
            cellArea.Width = (int) size;

            ctx.SetLineWidth (1);
            ctx.Rectangle (cellArea.Inflate (-0.5, -0.5));
            ctx.SetColor (Selected ? Colors.Blue : Colors.LightBlue);
            ctx.FillPreserve ();
            ctx.SetColor (Colors.Gray);
            ctx.Stroke ();

            if (pct.YPos != -1) {
                ctx.MoveTo (cellArea.Right, Bounds.Y + pct.YPos);
                ctx.Arc (cellArea.Right, Bounds.Y + pct.YPos, 2.5, 0, 360);
                ctx.SetColor (Colors.Red);
                ctx.Fill ();
            }
        }
コード例 #25
0
ファイル: DrawingFigures.cs プロジェクト: m13253/xwt
		public virtual void Rectangles (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			// Simple rectangles
			
			ctx.SetLineWidth (1);
			ctx.Rectangle (0, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.SetLineWidth (3);
			ctx.Rectangle (0, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.Restore ();
			
			// Rectangle with hole
			ctx.Save ();
			ctx.Translate (x + 50, y);
			
			ctx.Rectangle (0, 0, 40, 40);
			ctx.MoveTo (35, 35);
			ctx.RelLineTo (0, -20);
			ctx.RelLineTo (-20, 0);
			ctx.RelLineTo (0, 20);
			ctx.ClosePath ();
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Restore ();
			
			// Rounded Rectangle with Arcs
			ctx.Save ();
			ctx.Translate (x + 120, y);
			
			var r = 5;
			var l = 0;
			var t = 0;
			var w = 50;
			var h = 30;

			ctx.SetColor (Colors.Black);
			// top left  
			ctx.Arc (l + r, t + r, r, 180, 270);
			// top right 
			ctx.Arc (l + w - r, t + r, r, 270, 0);
			// bottom right  
			ctx.Arc (l + w - r, t + h - r, r, 0, 90);
			// bottom left 
			ctx.Arc (l + r, t + h - r, r, 90, 180);
			
			ctx.ClosePath ();
			ctx.StrokePreserve ();
			ctx.SetColor (Colors.AntiqueWhite);
			ctx.Fill ();
			ctx.Restore ();
		}
コード例 #26
0
ファイル: HorizontalLine.cs プロジェクト: hwthomas/XwPlot
        /// <summary>
        /// Draws the horizontal line plot using the Context and the x and y axes specified
        /// </summary>
        /// <param name="ctx">The Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double xMin = xAxis.PhysicalMin.X;
            double xMax = xAxis.PhysicalMax.X;

            xMin += pixelIndent_;
            xMax -= pixelIndent_;

            double length = Math.Abs (xMax - xMin);
            double lengthDiff = length - length*scale_;
            double indentAmount = lengthDiff/2;

            xMin += indentAmount;
            xMax -= indentAmount;

            double yPos = yAxis.WorldToPhysical (value_, false).Y;

            ctx.Save ();
            ctx.SetLineWidth (1);
            ctx.SetColor (color_);
            ctx.MoveTo (xMin, yPos);
            ctx.LineTo (xMax, yPos);
            ctx.Stroke ();
            ctx.Restore ();

            // todo:  clip and proper logic for flipped axis min max.
        }
コード例 #27
0
ファイル: ColorSelector.cs プロジェクト: m13253/xwt
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			if (colorBox == null) {
				using (var ib = new ImageBuilder (size, size)) {
					for (int i=0; i<size; i++) {
						for (int j=0; j<size; j++) {
							ib.Context.Rectangle (i, j, 1, 1);
							ib.Context.SetColor (GetColor (i,j));
							ib.Context.Fill ();
						}
					}

					if (ParentWindow != null)
						colorBox = ib.ToBitmap (this); // take screen scale factor into account
					else
						colorBox = ib.ToBitmap ();
				}
			}
			ctx.DrawImage (colorBox, padding, padding);
			ctx.SetLineWidth (1);
			ctx.SetColor (Colors.Black);
			ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4);
			ctx.Stroke ();
		}
コード例 #28
0
ファイル: DrawingText.cs プロジェクト: sergueik/xwt_swd
        void DrawText(Context ctx, TextLayout tl, ref double y)
        {
            double x = 10;
            var s = tl.GetSize ();
            var rect = new Rectangle (x, y, s.Width, s.Height).Inflate (0.5, 0.5);
            ctx.SetLineWidth (1);
            ctx.SetColor (Colors.Blue);
            ctx.Rectangle (rect);
            ctx.Stroke ();
            ctx.SetColor (Colors.Black);
            ctx.DrawTextLayout (tl, x, y);

            y += s.Height + 20;
        }
コード例 #29
0
ファイル: Axis.cs プロジェクト: hwthomas/XwPlot
        /// <summary>
        /// Draw a tick on the axis.
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw.</param>
        /// <param name="w">The tick position in world coordinates.</param>
        /// <param name="size">The size of the tick (in pixels)</param>
        /// <param name="text">The text associated with the tick</param>
        /// <param name="textOffset">The Offset to draw from the auto calculated position</param>
        /// <param name="axisPhysMin">The minimum physical extent of the axis</param>
        /// <param name="axisPhysMax">The maximum physical extent of the axis</param>
        /// <param name="boundingBox">out: The bounding rectangle for the tick and tickLabel drawn</param>
        /// <param name="labelOffset">out: offset from the axies required for axis label</param>
        public virtual void DrawTick( 
			Context ctx, 
			double w,
			double size,
			string text,
			Point textOffset,
			Point axisPhysMin,
			Point axisPhysMax,
			out Point labelOffset,
			out Rectangle boundingBox )
        {
            // determine physical location where tick touches axis.
            Point tickStart = WorldToPhysical (w, axisPhysMin, axisPhysMax, true);

            // determine offset from start point.
            Point  axisDir = Utils.UnitVector (axisPhysMin, axisPhysMax);

            // rotate axisDir anti-clockwise by TicksAngle radians to get tick direction. Note that because
            // the physical (pixel) origin is at the top left, a RotationTransform by a positive angle will
            // be clockwise.  Consequently, for anti-clockwise rotations, use cos(A-B), sin(A-B) formulae
            double x1 = Math.Cos (TicksAngle) * axisDir.X + Math.Sin (TicksAngle) * axisDir.Y;
            double y1 = Math.Cos (TicksAngle) * axisDir.Y - Math.Sin (TicksAngle) * axisDir.X;

            // now get the scaled tick vector.
            Point tickVector = new Point (TickScale * size * x1, TickScale * size * y1);

            if (TicksCrossAxis) {
                tickStart.X -= tickVector.X / 2;
                tickStart.Y -= tickVector.Y / 2;
            }

            // and the end point [point off axis] of tick mark.
            Point  tickEnd = new Point (tickStart.X + tickVector.X, tickStart.Y + tickVector.Y);

            // and draw it
            ctx.SetLineWidth (1);
            ctx.SetColor (LineColor);
            ctx.MoveTo (tickStart.X+0.5, tickStart.Y+0.5);
            ctx.LineTo (tickEnd.X+0.5, tickEnd.Y+0.5);
            ctx.Stroke ();

            // calculate bounds of tick.
            double minX = Math.Min (tickStart.X, tickEnd.X);
            double minY = Math.Min (tickStart.Y, tickEnd.Y);
            double maxX = Math.Max (tickStart.X, tickEnd.X);
            double maxY = Math.Max (tickStart.Y, tickEnd.Y);
            boundingBox = new Rectangle (minX, minY, maxX-minX, maxY-minY);

            // by default, label offset from axis is 0. TODO: revise this.
            labelOffset = new Point (-tickVector.X, -tickVector.Y);

            // ------------------------

            // now draw associated text.

            // **** TODO ****
            // The following code needs revising. A few things are hard coded when
            // they should not be. Also, angled tick text currently just works for
            // the bottom x-axis. Also, it's a bit hacky.

            if (text != "" && !HideTickText) {
                TextLayout layout = new TextLayout ();
                layout.Font = tickTextFontScaled;
                layout.Text = text;
                Size textSize = layout.GetSize ();

                // determine the center point of the tick text.
                double textCenterX;
                double textCenterY;

                // if text is at pointy end of tick.
                if (!TickTextNextToAxis) {
                    // offset due to tick.
                    textCenterX = tickStart.X + tickVector.X*1.2;
                    textCenterY = tickStart.Y + tickVector.Y*1.2;

                    // offset due to text box size.
                    textCenterX += 0.5 * x1 * textSize.Width;
                    textCenterY += 0.5 * y1 * textSize.Height;
                }
                    // else it's next to the axis.
                else {
                    // start location.
                    textCenterX = tickStart.X;
                    textCenterY = tickStart.Y;

                    // offset due to text box size.
                    textCenterX -= 0.5 * x1 * textSize.Width;
                    textCenterY -= 0.5 * y1 * textSize.Height;

                    // bring text away from the axis a little bit.
                    textCenterX -= x1*(2.0+FontScale);
                    textCenterY -= y1*(2.0+FontScale);
                }

                // If tick text is angled..
                if (TickTextAngle != 0) {

                    // determine the point we want to rotate text about.
                    Point textScaledTickVector = new Point (
                                                TickScale * x1 * (textSize.Height/2),
                                                TickScale * y1 * (textSize.Height/2) );
                    Point rotatePoint;
                    if (TickTextNextToAxis) {
                        rotatePoint = new Point (
                                            tickStart.X - textScaledTickVector.X,
                                            tickStart.Y - textScaledTickVector.Y);
                    }
                    else {
                        rotatePoint = new Point (
                                            tickEnd.X + textScaledTickVector.X,
                                            tickEnd.Y + textScaledTickVector.Y);
                    }

                    double actualAngle;
                    if (FlipTickText) {
                        double radAngle = TickTextAngle * Math.PI / 180;
                        rotatePoint.X += textSize.Width * Math.Cos (radAngle);
                        rotatePoint.Y += textSize.Width * Math.Sin (radAngle);
                        actualAngle = TickTextAngle + 180;
                    }
                    else {
                        actualAngle = TickTextAngle;
                    }

                    ctx.Save ();

                    ctx.Translate (rotatePoint.X, rotatePoint.Y);
                    ctx.Rotate (actualAngle);

                    Point [] recPoints = new Point [2];
                    recPoints[0] = new Point (0.0, -textSize.Height/2);
                    recPoints[1] = new Point (textSize.Width, textSize.Height);
                    ctx.TransformPoints (recPoints);

                    double t_x1 = Math.Min (recPoints[0].X, recPoints[1].X);
                    double t_x2 = Math.Max (recPoints[0].X, recPoints[1].X);
                    double t_y1 = Math.Min (recPoints[0].Y, recPoints[1].Y);
                    double t_y2 = Math.Max (recPoints[0].Y, recPoints[1].Y);

                    boundingBox = Rectangle.Union (boundingBox, new Rectangle (t_x1, t_y1, (t_x2-t_x1), (t_y2-t_y1)));

                    ctx.DrawTextLayout (layout, 0, -textSize.Height/2);

                    t_x2 -= tickStart.X;
                    t_y2 -= tickStart.Y;
                    t_x2 *= 1.25;
                    t_y2 *= 1.25;

                    labelOffset = new Point (t_x2, t_y2);

                    ctx.Restore ();

                    //ctx.Rectangle (boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height);
                    //ctx.Stroke ();

                }
                else 				{
                    double bx1 = (textCenterX - textSize.Width/2);
                    double by1 = (textCenterY - textSize.Height/2);
                    double bx2 = textSize.Width;
                    double by2 = textSize.Height;

                    Rectangle drawRect = new Rectangle (bx1, by1, bx2, by2);
                    // ctx.Rectangle (drawRect);

                    boundingBox = Rectangle.Union (boundingBox, drawRect);

                    // ctx.Rectangle (boundingBox);

                    ctx.DrawTextLayout (layout, bx1, by1);

                    textCenterX -= tickStart.X;
                    textCenterY -= tickStart.Y;
                    textCenterX *= 2.3;
                    textCenterY *= 2.3;

                    labelOffset = new Point (textCenterX, textCenterY);
                }
            }
        }
コード例 #30
0
ファイル: LinePlot.cs プロジェクト: parnham/NPlot
        /// <summary>
        /// Draws the line plot using the Context and Physical Axes provided
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        /// <param name="drawShadow">If true draw the shadow for the line. If false, draw line.</param>
        public void DrawLineOrShadow(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis, bool drawShadow)
        {
            SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);

            ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis);

            int numberPoints = data.Count;

            if (data.Count == 0) {
                return;
            }

            ctx.Save ();
            ctx.SetLineWidth (lineWidth_);

            // clipping is now handled assigning a clip region in the
            // graphic object before this call
            if (numberPoints == 1) {
                Point physical = t.Transform (data[0]);

                if (drawShadow) {
                    ctx.SetColor (shadowColor_);
                    ctx.MoveTo (physical.X - 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y);
                    ctx.LineTo (physical.X + 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y);
                    ctx.Stroke ();
                }
                else {
                    ctx.SetColor (lineColor_);
                    ctx.MoveTo (physical.X-0.5, physical.Y);
                    ctx.LineTo (physical.X+0.5, physical.Y);
                    ctx.Stroke ();
                }
            }
            else {
                // prepare for clipping
                double leftCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMin, false);
                double rightCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMax, false);
                if (leftCutoff > rightCutoff) {
                    Utils.Swap (ref leftCutoff, ref rightCutoff);
                }
                if (drawShadow) {
                    // correct cut-offs
                    double shadowCorrection =
                        xAxis.PhysicalToWorld (ShadowOffset, false) - xAxis.PhysicalToWorld (new Point(0,0), false);
                    leftCutoff -= shadowCorrection;
                    rightCutoff -= shadowCorrection;
                }

                for (int i = 1; i < numberPoints; ++i) {
                    // check to see if any values null. If so, then continue.
                    double dx1 = data[i-1].X;
                    double dx2 = data[i].X;
                    double dy1 = data[i-1].Y;
                    double dy2 = data[i].Y;
                    if (Double.IsNaN(dx1) || Double.IsNaN(dy1) || Double.IsNaN(dx2) || Double.IsNaN(dy2)) {
                        continue;
                    }

                    // do horizontal clipping here, to speed up
                    if ((dx1 < leftCutoff && dx2 < leftCutoff) || (rightCutoff < dx1 && rightCutoff < dx2)) {
                        continue;
                    }

                    // else draw line.
                    Point p1 = t.Transform (data[i-1]);
                    Point p2 = t.Transform (data[i]);

                    // when very far zoomed in, points can fall ontop of each other,
                    // and g.DrawLine throws an overflow exception
                    if (p1.Equals(p2)) {
                        continue;
                    }

                    if (drawShadow) {
                        ctx.SetColor (shadowColor_);
                        ctx.MoveTo (p1.X + ShadowOffset.X, p1.Y + ShadowOffset.Y);
                        ctx.LineTo (p2.X + ShadowOffset.X, p2.Y + ShadowOffset.Y);
                        ctx.Stroke ();
                    }
                    else {
                        ctx.SetColor (lineColor_);
                        ctx.MoveTo (p1.X, p1.Y);
                        ctx.LineTo (p2.X, p2.Y);
                        ctx.Stroke ();
                    }
                }
            }
            ctx.Restore ();
        }
コード例 #31
0
ファイル: CandlePlot.cs プロジェクト: hwthomas/XwPlot
        /// <summary>
        /// Draws the candle plot with the specified Drawing Context and X,Y axes
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The physical X-Axis to draw against</param>
        /// <param name="yAxis">The physical Y-Axis to draw against</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            CandleDataAdapter cd = new CandleDataAdapter (DataSource, DataMember,
                AbscissaData, OpenData, LowData, HighData, CloseData);

            double offset = 0;
            if (Centered) {
                offset = CalculatePhysicalSeparation (cd,xAxis)/2;
            }

            double addAmount = StickWidth/2;
            double stickWidth = StickWidth;

            if (StickWidth == AutoScaleStickWidth) {
                // default
                addAmount = 2;
                stickWidth = 4;

                double minDist = CalculatePhysicalSeparation (cd, xAxis);

                addAmount = minDist / 3;
                stickWidth = addAmount * 2;
            }

            ctx.Save ();
            ctx.SetLineWidth (1);

            /*
            // brant hyatt proposed.
            if (Style == Styles.Stick)
            {
                p.Width = stickWidth;
                addAmount = stickWidth + 2;
            }
            */

            for (int i=0; i<cd.Count; ++i) {

                PointOLHC point = (PointOLHC)cd [i];
                if ((!double.IsNaN (point.Open)) && (!double.IsNaN(point.High))
                 && (!double.IsNaN (point.Low)) && (!double.IsNaN(point.Close))) {
                    double xPos = (xAxis.WorldToPhysical (point.X, false)).X;

                    if (xPos + offset + addAmount < xAxis.PhysicalMin.X || xAxis.PhysicalMax.X < xPos + offset - addAmount) {
                        continue;
                    }

                    double yLo  = (yAxis.WorldToPhysical (point.Low,  false)).Y;
                    double yHi  = (yAxis.WorldToPhysical (point.High, false)).Y;
                    double yOpn = (yAxis.WorldToPhysical (point.Open, false)).Y;
                    double yCls = (yAxis.WorldToPhysical (point.Close,false)).Y;

                    if (Style == Styles.Stick) {
                        /*
                        // brant hyatt proposed.
                        if (i > 0)
                        {
                            if ( ((PointOLHC)cd[i]).Close > ((PointOLHC)cd[i-1]).Close)
                            {
                                p.Color = BullishColor;
                            }
                            else
                            {
                                p.Color = BearishColor;
                            }
                        }
                        */
                        ctx.SetColor (Color);
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);		// Low to High line

                        ctx.MoveTo (xPos-addAmount+offset, yOpn);
                        ctx.LineTo (xPos+offset, yOpn);		// Open line

                        ctx.MoveTo (xPos+addAmount+offset, yCls);
                        ctx.LineTo (xPos+offset, yCls);		// Close line
                        ctx.Stroke ();
                    }
                    else if (Style == Styles.Filled) {
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);
                        ctx.Stroke ();
                        if (yOpn > yCls) {
                            ctx.SetColor (BullishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yCls, stickWidth, yOpn - yCls);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else if (yOpn < yCls) {
                            ctx.SetColor (BearishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yOpn, stickWidth, yCls - yOpn);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else {	// Cls == Opn
                            ctx.MoveTo (xPos-addAmount+offset, yOpn);
                            ctx.LineTo (xPos-addAmount+stickWidth+offset, yCls);
                            ctx.Stroke ();
                        }
                    }
                }
            }
            ctx.Restore ();
        }
コード例 #32
0
ファイル: ArrowItem.cs プロジェクト: hwthomas/XwPlot
        /// <summary>
        /// Draws the arrow on a plot surface.
        /// </summary>
        /// <param name="ctx">the Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
        {
            if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin) {
                return;
            }
            if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin) {
                return;
            }

            ctx.Save ();

            TextLayout layout = new TextLayout ();
            layout.Font = textFont_;
            layout.Text = text_;

            double angle = angle_;
            if (angle_ < 0.0) {
                int mul = -(int)(angle_ / 360.0) + 2;
                angle = angle_ + 360.0 * (double)mul;
            }

            double normAngle = (double)angle % 360.0;	// angle in range 0 -> 360.

            Point toPoint = new Point (
                xAxis.WorldToPhysical (to_.X, true).X,
                yAxis.WorldToPhysical (to_.Y, true).Y);

            double xDir = Math.Cos (normAngle * 2.0 * Math.PI / 360.0);
            double yDir = Math.Sin (normAngle * 2.0 * Math.PI / 360.0);

            toPoint.X += xDir*headOffset_;
            toPoint.Y += yDir*headOffset_;

            double xOff = physicalLength_ * xDir;
            double yOff = physicalLength_ * yDir;

            Point fromPoint = new Point(
                (int)(toPoint.X + xOff),
                (int)(toPoint.Y + yOff) );

            ctx.SetLineWidth (1);
            ctx.SetColor (arrowColor_);
            ctx.MoveTo (fromPoint);
            ctx.LineTo (toPoint);
            ctx.Stroke ();

            xOff = headSize_ * Math.Cos ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
            yOff = headSize_ * Math.Sin ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff, toPoint.Y + yOff);

            double xOff2 = headSize_ * Math.Cos ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
            double yOff2 = headSize_ * Math.Sin ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff2, toPoint.Y + yOff2);
            ctx.LineTo (toPoint);
            ctx.ClosePath ();
            ctx.SetColor (arrowColor_);
            ctx.Fill ();

            Size textSize = layout.GetSize ();
            Size halfSize = new Size (textSize.Width/2, textSize.Height/2);

            double quadrantSlideLength = halfSize.Width + halfSize.Height;

            double quadrantD = normAngle / 90.0;		// integer part gives quadrant.
            int quadrant = (int)quadrantD;				// quadrant in.
            double prop = quadrantD - (double)quadrant;	// proportion of way through this qadrant.
            double dist = prop * quadrantSlideLength;	// distance along quarter of bounds rectangle.

            // now find the offset from the middle of the text box that the
            // rear end of the arrow should end at (reverse this to get position
            // of text box with respect to rear end of arrow).
            //
            // There is almost certainly an elgant way of doing this involving
            // trig functions to get all the signs right, but I'm about ready to
            // drop off to sleep at the moment, so this blatent method will have
            // to do.
            Point offsetFromMiddle = new Point (0, 0);
            switch (quadrant) {
            case 0:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( -halfSize.Width + dist, halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( -halfSize.Width, - dist );
                }
                break;
            case 1:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( halfSize.Width, halfSize.Height - dist );
                }
                else {
                    offsetFromMiddle = new Point ( dist, halfSize.Height );
                }
                break;
            case 2:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( halfSize.Width - dist, -halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( halfSize.Width, -dist );
                }
                break;
            case 3:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( -halfSize.Width, -halfSize.Height + dist );
                }
                else {
                    offsetFromMiddle = new Point ( -dist, -halfSize.Height );
                }
                break;
            default:
                throw new XwPlotException( "Programmer error." );
            }

            ctx.SetColor (textColor_);
            double x = fromPoint.X - halfSize.Width - offsetFromMiddle.X;
            double y = fromPoint.Y - halfSize.Height + offsetFromMiddle.Y;
            ctx.DrawTextLayout (layout, x, y);

            ctx.Restore ();
        }
コード例 #33
0
ファイル: ColorSelector.cs プロジェクト: dellis1972/xwt
 protected override void OnDraw(Context ctx, Rectangle dirtyRect)
 {
     if (colorBox == null) {
         using (var ib = new ImageBuilder (size, size)) {
             for (int i=0; i<size; i++) {
                 for (int j=0; j<size; j++) {
                     ib.Context.Rectangle (i, j, 1, 1);
                     ib.Context.SetColor (GetColor (i,j));
                     ib.Context.Fill ();
                 }
             }
             colorBox = ib.ToImage ();
         }
     }
     ctx.DrawImage (colorBox, padding, padding);
     ctx.SetLineWidth (1);
     ctx.SetColor (Colors.Black);
     ctx.Rectangle (selection.X + padding - 2 + 0.5, selection.Y + padding - 2 + 0.5, 4, 4);
     ctx.Stroke ();
 }
コード例 #34
0
ファイル: IconMargin.cs プロジェクト: Kalnor/monodevelop
		void DrawBookmark (Context cr, double x, double y)
		{
			var color1 = Style.BookmarkColor1;
			var color2 = Style.BookmarkColor2;
			
			DrawRoundRectangle (cr, x + 1, y + 1, 8, Width - 4, Editor.LineHeight - 4);
			using (var pat = new LinearGradient (x + Width / 4, y, x + Width / 2, y + Editor.LineHeight - 4)) {
				pat.AddColorStop (0, color1);
				pat.AddColorStop (1, color2);
				cr.Pattern = pat;
				cr.FillPreserve ();
			}
			
			using (var pat = new LinearGradient (x, y + Editor.LineHeight, x + Width, y)) {
				pat.AddColorStop (0, color2);
				//pat.AddColorStop (1, color1);
				cr.Pattern = pat;
				cr.Stroke ();
			}
		}
コード例 #35
0
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw(ctx);

            // Simple rectangles

            ctx.SetLineWidth(1);
            ctx.Rectangle(100, 5, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Fill();

            ctx.Rectangle(115, 5, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Stroke();

            //

            ctx.SetLineWidth(3);
            ctx.Rectangle(100, 20, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Fill();

            ctx.Rectangle(115, 20, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Stroke();

            // Rectangle with hole

            ctx.Rectangle(10, 100, 40, 40);
            ctx.MoveTo(45, 135);
            ctx.RelLineTo(0, -20);
            ctx.RelLineTo(-20, 0);
            ctx.RelLineTo(0, 20);
            ctx.ClosePath();
            ctx.SetColor(Color.Black);
            ctx.Fill();

            // Dashed lines

            ctx.SetLineDash(15, 10, 10, 5, 5);
            ctx.Rectangle(100, 100, 100, 100);
            ctx.Stroke();
            ctx.SetLineDash(0);

            ImageBuilder ib = new ImageBuilder(30, 30, ImageFormat.ARGB32);

            ib.Context.Arc(15, 15, 15, 0, 360);
            ib.Context.SetColor(new Color(1, 0, 1));
            ib.Context.Rectangle(0, 0, 5, 5);
            ib.Context.Fill();
            var img = ib.ToImage();

            ctx.DrawImage(img, 90, 90);
            ctx.DrawImage(img, 90, 140, 50, 10);

            ctx.Arc(190, 190, 15, 0, 360);
            ctx.SetColor(new Color(1, 0, 1, 0.4));
            ctx.Fill();

            ctx.Save();
            ctx.Translate(90, 220);
            ctx.Pattern = new ImagePattern(img);
            ctx.Rectangle(0, 0, 100, 70);
            ctx.Fill();
            ctx.Restore();

            ctx.Translate(30, 30);
            double end = 270;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(30, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();
                ctx.Restore();
            }

            ctx.ResetTransform();
        }
コード例 #36
0
        public virtual void Scale(Context ctx, double ax, double ay)
        {
            ctx.Save ();
            ctx.Translate (ax, ay);
            ctx.SetColor (Colors.Black);
            ctx.SetLineWidth (1);

            var x = 0d;
            var y = 0d;
            var w = 10d;
            var inc = .1d;
            for (var i = inc; i < 3.5d; i +=inc) {
                ctx.Save ();
                ctx.Scale (i, i);
                ctx.Rectangle (x, y, w, w);
                ctx.SetColor (Colors.Yellow.WithAlpha (1 / i));
                ctx.FillPreserve ();
                ctx.SetColor (Colors.Red.WithAlpha (1 / i));
                ctx.Stroke ();
                ctx.MoveTo (x += w * inc, y += w * inc / 3);
                ctx.Restore ();

            }

            ctx.Restore ();
        }
コード例 #37
0
ファイル: LegendBase.cs プロジェクト: parnham/NPlot
        /// <summary>
        /// Draw The legend
        /// </summary>
        /// <param name="ctx">The Drawing Context with on which to draw</param>
        /// <param name="position">The position of the top left of the axis.</param>
        /// <param name="plots">Array of plot objects to appear in the legend.</param>
        /// <param name="scale">if the legend is set to scale, the amount to scale by.</param>
        /// <returns>bounding box</returns>
        public Rectangle Draw(Context ctx, Point position, ArrayList plots, double scale )
        {
            // first of all determine the Font to use in the legend.
            Font textFont;
            if (AutoScaleText) {
                textFont = font_.WithScaledSize (scale);
            }
            else {
                textFont = font_;
            }

            ctx.Save ();

            // determine max width and max height of label strings and
            // count the labels.
            int labelCount = 0;
            int unnamedCount = 0;
            double maxHt = 0;
            double maxWd = 0;
            TextLayout layout = new TextLayout ();
            layout.Font = textFont;

            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }
                layout.Text = label;
                Size labelSize = layout.GetSize ();
                if (labelSize.Height > maxHt) {
                    maxHt = labelSize.Height;
                }
                if (labelSize.Width > maxWd) {
                    maxWd = labelSize.Width;
                }
                ++labelCount;
            }

            bool extendingHorizontally = numberItemsHorizontally_ == -1;
            bool extendingVertically = numberItemsVertically_ == -1;

            // determine width in legend items count units.
            int widthInItemCount = 0;
            if (extendingVertically) {
                if (labelCount >= numberItemsHorizontally_) {
                    widthInItemCount = numberItemsHorizontally_;
                }
                else {
                    widthInItemCount = labelCount;
                }
            }
            else if (extendingHorizontally) {
                widthInItemCount = labelCount / numberItemsVertically_;
                if (labelCount % numberItemsVertically_ != 0)
                    widthInItemCount += 1;
            }
            else {
                throw new NPlotException( "logic error in legend base" );
            }

            // determine height of legend in items count units.
            int heightInItemCount = 0;
            if (extendingHorizontally) {
                if (labelCount >= numberItemsVertically_) {
                    heightInItemCount = numberItemsVertically_;
                }
                else {
                    heightInItemCount = labelCount;
                }
            }
            else {		// extendingVertically
                heightInItemCount = labelCount / numberItemsHorizontally_;
                if (labelCount % numberItemsHorizontally_ != 0)
                    heightInItemCount += 1;
            }

            double lineLength = 20;
            double hSpacing = (int)(5.0f * scale);
            double vSpacing = (int)(3.0f * scale);
            double boxWidth = (int) ((float)widthInItemCount * (lineLength + maxWd + hSpacing * 2.0f ) + hSpacing);
            double boxHeight = (int)((float)heightInItemCount * (maxHt + vSpacing) + vSpacing);

            double totalWidth = boxWidth;
            double totalHeight = boxHeight;

            // draw box around the legend.
            if (BorderStyle == BorderType.Line) {
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();
            }
            else if (BorderStyle == BorderType.Shadow) {
                double offset = (4.0 * scale);
                Color shade = Colors.Gray;
                shade.Alpha = 0.5;
                ctx.SetColor (Colors.Gray);
                ctx.Rectangle (position.X+offset, position.Y+offset, boxWidth, boxHeight);
                ctx.Fill ();
                ctx.SetColor (bgColor_);
                ctx.Rectangle (position.X, position.Y, boxWidth, boxHeight);
                ctx.FillPreserve ();
                ctx.SetColor (borderColor_);
                ctx.Stroke ();

                totalWidth += offset;
                totalHeight += offset;
            }

            /*
               else if ( this.BorderStyle == BorderType.Curved )
               {
                   // TODO. make this nice.
               }
            */
            else {
                // do nothing.
            }

            // now draw entries in box..
            labelCount = 0;
            unnamedCount = 0;

            int plotCount = -1;
            for (int i=0; i<plots.Count; ++i) {
                if (!(plots[i] is IPlot)) {
                    continue;
                }

                IPlot p = (IPlot)plots[i];

                if (!p.ShowInLegend) {
                    continue;
                }

                plotCount += 1;

                double xpos, ypos;
                if (extendingVertically) {
                    xpos = plotCount % numberItemsHorizontally_;
                    ypos = plotCount / numberItemsHorizontally_;
                }
                else {
                    xpos = plotCount / numberItemsVertically_;
                    ypos = plotCount % numberItemsVertically_;
                }

                double lineXPos = (position.X + hSpacing + xpos * (lineLength + maxWd + hSpacing * 2.0));
                double lineYPos = (position.Y + vSpacing + ypos * (vSpacing + maxHt));
                p.DrawInLegend (ctx, new Rectangle (lineXPos, lineYPos, lineLength, maxHt));

                double textXPos = lineXPos + hSpacing + lineLength;
                double textYPos = lineYPos;
                string label = p.Label;
                if (label == "") {
                    unnamedCount += 1;
                    label = "Series " + unnamedCount.ToString();
                }

                layout.Text = label;
                ctx.DrawTextLayout (layout, textXPos, textYPos);

                ++labelCount;
            }
            ctx.Restore ();
            return new Rectangle (position.X, position.Y, totalWidth, totalHeight);
        }
コード例 #38
0
ファイル: Axis.cs プロジェクト: hwthomas/XwPlot
        /// <summary>
        /// Draw the axis. This involves three steps:
        ///	 (1) Draw the axis line.
        ///	 (2) Draw the tick marks.
        ///	 (3) Draw the label.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="physicalMin">The physical position corresponding to the world minimum of the axis.</param>
        /// <param name="physicalMax">The physical position corresponding to the world maximum of the axis.</param>
        /// <param name="boundingBox">out The bounding rectangle of the axis including axis line, label, tick marks and tick mark labels</param>
        public virtual void Draw(Context ctx, Point physicalMin, Point physicalMax, out Rectangle boundingBox)
        {
            // calculate the bounds of the axis line only.
            double x1 = Math.Min (physicalMin.X, physicalMax.X);
            double x2 = Math.Max (physicalMin.X, physicalMax.X);
            double y1 = Math.Min (physicalMin.Y, physicalMax.Y);
            double y2 = Math.Max (physicalMin.Y, physicalMax.Y);
            Rectangle bounds = new Rectangle (x1, y1, x2-x1, y2-y1);

            if (!Hidden) {
                // (1) Draw the axis line.
                ctx.Save ();
                ctx.SetLineWidth (1);
                ctx.SetColor (LineColor);
                ctx.MoveTo (physicalMin.X+0.5, physicalMin.Y+0.5);
                ctx.LineTo (physicalMax.X+0.5, physicalMax.Y+0.5);
                ctx.Stroke ();
                ctx.Restore ();

                // (2) draw tick marks (subclass responsibility).

                object labelOffset;
                object tickBounds;
                DrawTicks (ctx, physicalMin, physicalMax, out labelOffset, out tickBounds);

                // (3) draw the axis label
                object labelBounds = null;
                if (!HideTickText) {
                    labelBounds = DrawLabel (ctx, (Point)labelOffset, physicalMin, physicalMax);
                }

                // (4) merge bounds and return.
                if (labelBounds != null) {
                    bounds = Rectangle.Union (bounds, (Rectangle)labelBounds);
                }

                if (tickBounds != null) {
                    bounds = Rectangle.Union (bounds, (Rectangle)tickBounds);
                }
            }
            boundingBox = bounds;
        }
コード例 #39
0
ファイル: DrawingFigures.cs プロジェクト: m13253/xwt
		public virtual void Curves2 (Context ctx, double sx, double sy)
		{
			ctx.Save ();
			ctx.Translate (sx, sy);
			ctx.SetColor (Colors.Black);
			
			double x = 0, y = 40;
			double x1 = y - x, y1 = x1 + y, x2 = x + y, y2 = x, x3 = y1, y3 = y;

			ctx.MoveTo (x, y);
			ctx.CurveTo (x1, y1, x2, y2, x3, y3);

			ctx.SetLineWidth (2.0);
			ctx.Stroke ();

			ctx.SetColor (new Color (1, 0.2, 0.2, 0.6));
			ctx.SetLineWidth (1.0);
			ctx.MoveTo (x, y);
			ctx.LineTo (x1, y1);
			ctx.MoveTo (x2, y2);
			ctx.LineTo (x3, y3);
			ctx.Stroke ();
			
			ctx.Restore ();
		}
コード例 #40
0
ファイル: BasicChart.cs プロジェクト: m13253/xwt
		void DrawCursor (Context ctx, ChartCursor cursor)
		{
			ctx.SetColor (cursor.Color);
			
			double x, y;
			GetPoint (cursor.Value, cursor.Value, out x, out y);
				
			if (cursor.Dimension == AxisDimension.X) {
				double cy = top - AreaBorderWidth - 1;
				ctx.MoveTo (x, cy);
				ctx.LineTo (x + (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.LineTo (x - (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.ClosePath ();
				if (activeCursor == cursor)
					ctx.FillPreserve ();
				ctx.Stroke ();
				ctx.MoveTo (x, top);
				ctx.RelLineTo (0, height);
				ctx.Stroke ();
			} else {
				throw new NotSupportedException ();
			}
		}
コード例 #41
0
ファイル: DrawingFigures.cs プロジェクト: m13253/xwt
		public void Path (Context ctx, double px, double py)
		{
			ctx.Save ();
			ctx.Translate (px, py);

			var path = new DrawingPath ();

			path.MoveTo (0.44, 18);
			path.LineTo (-1, 18);
			path.LineTo (-1, 26);
			path.LineTo (0.44, 26);
			path.LineTo (0, 42);
			path.LineTo (29, 21.98);
			path.LineTo (29, 21.98);
			path.LineTo (0, 2);
			path.LineTo (0.44, 18);

			ctx.AppendPath (path);
			ctx.SetColor (Colors.Black);
			ctx.SetLineWidth (2);
			ctx.Stroke ();

			var path2 = path.CopyPath ();

			path2.LineTo (15, 8);
			path2.ClosePath ();

			ctx.Rotate (180);
			ctx.AppendPath (path2);
			ctx.SetColor (Colors.Red);
			ctx.SetLineDash (0, 5);
			ctx.Stroke ();

			ctx.Restore ();
		}
コード例 #42
0
        public virtual void Texts(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();

            ctx.Translate(x, y);

            ctx.SetColor(Colors.Black);

            var col1 = new Rectangle();
            var col2 = new Rectangle();

            var text = new TextLayout();

            text.Font = this.Font.WithSize(24);
            Console.WriteLine(text.Font.Size);

            // first text
            text.Text = "Lorem ipsum dolor sit amet,";
            var size1 = text.GetSize();

            col1.Width   = size1.Width;
            col1.Height += size1.Height + 10;
            ctx.DrawTextLayout(text, 0, 0);


            // proofing width; test should align with text above
            ctx.SetColor(Colors.DarkMagenta);
            text.Text  = "consetetur sadipscing elitr, sed diam nonumy";
            text.Width = col1.Width;
            var size2 = text.GetSize();

            ctx.DrawTextLayout(text, 0, col1.Bottom);
            col1.Height += size2.Height + 10;

            ctx.SetColor(Colors.Black);

            // proofing scale, on second col
            ctx.Save();
            ctx.SetColor(Colors.Red);
            col2.Left = col1.Right + 10;

            text.Text = "eirmod tempor invidunt ut.";

            var scale = 1.2;

            text.Width = text.Width / scale;
            var size3 = text.GetSize();

            col2.Height = size3.Height * scale;
            col2.Width  = size3.Width * scale + 5;
            ctx.Scale(scale, scale);
            ctx.DrawTextLayout(text, col2.Left / scale, col2.Top / scale);
            ctx.Restore();

            // proofing heigth, on second col
            ctx.Save();
            ctx.SetColor(Colors.DarkCyan);
            text.Text = "Praesent ac lacus nec dolor pulvinar feugiat a id elit.";
            var size4 = text.GetSize();

            text.Height   = size4.Height / 2;
            text.Trimming = TextTrimming.WordElipsis;
            ctx.DrawTextLayout(text, col2.Left, col2.Bottom + 5);

            ctx.SetLineWidth(1);
            ctx.SetColor(Colors.Blue);
            ctx.Rectangle(new Rectangle(col2.Left, col2.Bottom + 5, text.Width, text.Height));
            ctx.Stroke();
            ctx.Restore();

            // drawing col line
            ctx.SetLineWidth(1);

            ctx.SetColor(Colors.Black.WithAlpha(.5));
            ctx.MoveTo(col1.Right + 5, col1.Top);
            ctx.LineTo(col1.Right + 5, col1.Bottom);
            ctx.Stroke();
            ctx.MoveTo(col2.Right + 5, col2.Top);
            ctx.LineTo(col2.Right + 5, col2.Bottom);
            ctx.Stroke();
            ctx.SetColor(Colors.Black);

            // proofing rotate, and printing size to see the values
            ctx.Save();

            text.Font = this.Font.WithSize(10);
            text.Text = string.Format("Size 1 {0}\r\nSize 2 {1}\r\nSize 3 {2} Scale {3}",
                                      size1, size2, size3, scale);
            text.Width  = -1;            // this clears textsize
            text.Height = -1;
            ctx.Rotate(5);
            // maybe someone knows a formula with angle and textsize to calculyte ty
            var ty = 30;

            ctx.DrawTextLayout(text, ty, col1.Bottom + 10);

            ctx.Restore();

            // scale example here:

            ctx.Restore();

            TextLayout tl0 = new TextLayout(this);

            tl0.Font = this.Font.WithSize(10);
            tl0.Text = "This text contains attributes.";
            tl0.SetUnderline(0, "This".Length);
            tl0.SetForeground(new Color(0, 1.0, 1.0), "This ".Length, "text".Length);
            tl0.SetBackground(new Color(0, 0, 0), "This ".Length, "text".Length);
            tl0.SetFontWeight(FontWeight.Bold, "This text ".Length, "contains".Length);
            tl0.SetFontStyle(FontStyle.Italic, "This text ".Length, "contains".Length);
            tl0.SetStrikethrough("This text contains ".Length, "attributes".Length);

            ctx.DrawTextLayout(tl0, col2.Left, col2.Bottom + 100);


            // Text boces

            y = 180;

            // Without wrapping

            TextLayout tl = new TextLayout(this);

            tl.Text = "Stright text";
            DrawText(ctx, tl, ref y);

            // With wrapping

            tl       = new TextLayout(this);
            tl.Text  = "The quick brown fox jumps over the lazy dog";
            tl.Width = 100;
            DrawText(ctx, tl, ref y);

            // With blank lines

            tl       = new TextLayout(this);
            tl.Text  = "\nEmpty line above\nLine break above\n\nEmpty line above\n\n\nTwo empty lines above\nEmpty line below\n";
            tl.Width = 200;
            DrawText(ctx, tl, ref y);
        }
コード例 #43
0
ファイル: ScanView.cs プロジェクト: jfreax/BAIMP
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (image != null) {
                if (Heighlighted && IsThumbnail) {
                    ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3);
                    ctx.SetColor(Colors.LightSteelBlue);
                    ctx.Fill();
                }

                ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3));

                if (mask != null && ShowMask) {
                    ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6);
                }
            }

            if (isEditMode) {
                Point scaleFactor = new Point(
                                        scan.Size.Width / image.Size.Width,
                                        scan.Size.Height / image.Size.Height);
                ctx.SetColor(Mask.maskColor);

                foreach (MaskEntry p in scan.Mask.MaskPositions) {
                    switch (p.type) {
                    case MaskEntryType.Point:
                        ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2);
                        ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        ctx.Stroke();

                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Fill();

                        ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        break;
                    case MaskEntryType.Space:
                        ctx.Stroke();
                        ctx.ClosePath();
                        break;
                    case MaskEntryType.Delete:
                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Save();
                        ctx.Clip();
                        int newX = (int) Math.Min(Math.Max(
                                       p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width);
                        int newY = (int) Math.Min(Math.Max(
                                       p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height);

                        using (ImageBuilder ib =
                                   new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) {
                            BitmapImage bi = ib.ToBitmap();
                            image.WithBoxSize(image.Size).ToBitmap().CopyArea(
                                newX, newY,
                                (int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2),
                                bi, 0, 0);
                            ctx.DrawImage(bi, new Point(newX, newY));
                        }
                        ctx.Restore();
                        ctx.ClosePath();
                        break;
                    }
                }

                ctx.Stroke();

                if (mousePosition != Point.Zero) {
                    ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                    ctx.Fill();

                    if (mousePositionStart != Point.Zero) {
                        ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2);
                        ctx.SetColor(Mask.maskColor);
                        ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                        ctx.Fill();
                        ctx.MoveTo(mousePosition);
                        ctx.LineTo(mousePositionStart);
                        ctx.Stroke();
                    }
                }
            }
        }
コード例 #44
0
ファイル: ColorSelector.cs プロジェクト: m13253/xwt
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			double width = Size.Width - padding * 2;
			int range = (int)Size.Height - padding * 2;
			for (int n=0; n < range; n++) {
				ctx.Rectangle (padding, padding + n, width, 1);
				ctx.SetColor (Color.FromHsl (hue, saturation, (double)(range - n - 1) / (double)(range - 1)));
				ctx.Fill ();
			}
			ctx.Rectangle (0.5, padding + (int)(((double)range) * (1-light)) + 0.5 - 2, Size.Width - 1, 4);
			ctx.SetColor (Colors.Black);
			ctx.SetLineWidth (1);
			ctx.Stroke ();
		}
コード例 #45
0
ファイル: ListViewCellBounds.cs プロジェクト: m13253/xwt
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			base.OnDraw (ctx, dirtyRect);
			ctx.Save ();

			if (parent.CurrentRow < 0)
				return;

			var row_bounds = parent.ListView.GetRowBounds (parent.CurrentRow, false);
			var row_bg_bounds = parent.ListView.GetRowBounds (parent.CurrentRow, true);

			if (TrackerBg != null) {
				ctx.DrawImage (TrackerBg, row_bg_bounds, new Rectangle (0, 0, row_bg_bounds.Width, row_bg_bounds.Height));
			}

			foreach (var col in parent.ListView.Columns) {
				foreach (var cell in col.Views) {
					var cell_bg_bounds = parent.ListView.GetCellBounds (parent.CurrentRow, cell, true);
					var cell_bounds = parent.ListView.GetCellBounds (parent.CurrentRow, cell, false);
					cell_bounds.Y -= row_bg_bounds.Y;
					cell_bounds.X += parent.ListView.HorizontalScrollControl.Value;
					cell_bg_bounds.Y -= row_bg_bounds.Y;
					cell_bg_bounds.X += parent.ListView.HorizontalScrollControl.Value;
					ctx.SetColor (Colors.Red);
					ctx.Rectangle (cell_bg_bounds);
					ctx.Stroke ();
					ctx.SetColor (Colors.Green);
					ctx.Rectangle (cell_bounds);
					ctx.Stroke ();
				}
			}

			row_bounds.Y -= row_bg_bounds.Y;
			row_bounds.X += parent.ListView.HorizontalScrollControl.Value;
			row_bg_bounds.Y = 0;
			row_bg_bounds.X += parent.ListView.HorizontalScrollControl.Value;

			ctx.SetColor (Colors.Red);
			ctx.Rectangle (row_bg_bounds);
			ctx.Stroke ();

			ctx.SetColor (Colors.Blue);
			ctx.Rectangle (row_bounds);
			ctx.Stroke ();
			ctx.Restore ();
		}
コード例 #46
0
ファイル: HorizontalLine.cs プロジェクト: hwthomas/XwPlot
 /// <summary>
 /// Draws a representation of the horizontal line in the legend.
 /// </summary>
 /// <param name="ctx">The Drawing Context with which to draw</param>
 /// <param name="startEnd">A rectangle specifying the bounds of the area in the legend set aside for drawing</param>
 public void DrawInLegend(Context ctx, Rectangle startEnd)
 {
     ctx.Save ();
     ctx.MoveTo (startEnd.Left, (startEnd.Top + startEnd.Bottom)/2);
     ctx.LineTo (startEnd.Right, (startEnd.Top + startEnd.Bottom)/2);
     ctx.SetColor (color_);
     ctx.SetLineWidth (1);
     ctx.Stroke ();
     ctx.Restore ();
 }
コード例 #47
0
ファイル: RoundedFrameBox.cs プロジェクト: kdubau/monodevelop
			void Draw (Context ctx, bool fill)
			{
				var parent = (RoundedFrameBox)Parent;
				var border = parent.BorderSpacing;
				var radius = parent.cornerRadius;
				var rect = Bounds;

				ctx.MoveTo (rect.X, rect.Y);



				if (border.Top > 0) {
					ctx.NewPath ();
					if (radius.TopLeft > 0)
						ctx.Arc (rect.Left + radius.TopLeft + border.Left / 2, rect.Top + radius.TopLeft + border.Top / 2, radius.TopLeft, 180, 270);
					else
						PathTo (ctx, rect.Left, rect.Top + border.Top / 2, fill);

					if (radius.TopRight > 0) {
						ctx.LineTo (rect.Right - (radius.TopRight + border.Right / 2), rect.Top + border.Top / 2);
						ctx.Arc (rect.Right - (radius.TopRight + border.Right / 2), rect.Top + radius.TopRight + border.Top / 2, radius.TopRight, 270, 0);
					} else
						ctx.LineTo (rect.Right, rect.Top + border.Top / 2);
				} else
					PathTo (ctx, rect.Right - border.Right / 2, rect.Top, fill);

				if (border.Right > 0)
					// TODO: round corners if top/bottom border disabled
					ctx.LineTo (rect.Right - border.Right / 2, rect.Bottom - (border.Bottom > 0 ? radius.BottomRight : 0));
				else
					PathTo (ctx, rect.Right - border.Right / 2, rect.Bottom - (border.Bottom > 0 ? radius.BottomRight : 0), fill);

				if (border.Bottom > 0) {
					if (radius.BottomRight > 0)
						ctx.Arc (rect.Right - (radius.BottomRight + border.Right / 2), rect.Bottom - (radius.BottomRight + border.Bottom / 2), radius.BottomRight, 0, 90);
					else
						PathTo (ctx, rect.Right, rect.Bottom - border.Bottom / 2, fill);

					if (radius.BottomLeft > 0) {
						ctx.LineTo (rect.Left + (radius.BottomLeft + border.Left / 2), rect.Bottom - border.Bottom / 2);
						ctx.Arc (rect.Left + radius.BottomLeft + border.Left / 2, rect.Bottom - (radius.BottomLeft + border.Bottom / 2), radius.BottomLeft, 90, 180);
					} else
						ctx.LineTo (rect.Left + border.Left / 2, rect.Bottom - border.Bottom / 2);
				} else
					PathTo (ctx, rect.Left + border.Left / 2, rect.Bottom - border.Bottom / 2, fill);

				if (border.Left > 0)
					// TODO: round corners if top/bottom border disabled
					ctx.LineTo (rect.Left + border.Left / 2, rect.Top + (border.Top > 0 ? radius.TopLeft : 0));
				else
					PathTo (ctx, rect.Left + border.Left / 2, rect.Top + (border.Top > 0 ? radius.TopLeft : 0), fill);

				if (fill) {
					ctx.SetColor (parent.innerColor);
					ctx.Fill ();
				} else {
					ctx.SetColor (parent.borderColor);
					ctx.SetLineWidth (parent.borderWidth);
					ctx.Stroke ();
				}
			}