Exemplo n.º 1
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            // Line arround
            ctx.SetColor(Colors.DarkGray);

            // Drive line arround
            ctx.Rectangle(Bounds);
            ctx.Fill();

            ctx.SetColor(Colors.Gray);
            ctx.Rectangle(Bounds.Inflate(-margin, -margin));
            ctx.Fill();

            // Draw image
            ctx.DrawImage(Image.FromResource(Logo), 5.0, 5.0);

            // Draw text
            ctx.SetColor(Colors.White);
            TextLayout _layout = new TextLayout();
            _layout.Font = Font.WithSize(22);
            _layout.Text = Label;
            _layout.SetFontWeight(FontWeight.Bold, 0, Label.Length);

            // Cocoa layouts
            ctx.DrawTextLayout(_layout, 45, ((Config.Cocoa || Config.Gtk) ? 5 : 2));
        }
Exemplo n.º 2
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 ();
				}
			}
		}	
Exemplo n.º 3
0
 protected override void OnDraw(Context ctx, Rectangle dirtyRect)
 {
     ctx.SetColor(new Color(0.5, 0.5, 0.5));
     ctx.Rectangle(Bounds);
     ctx.Fill();
     ctx.SetColor(new Color(0.8, 0.8, 0.8));
     ctx.Rectangle(Bounds.Inflate(-margin, -margin));
     ctx.Fill();
     ctx.SetColor(highlight ? Color.BlendWith(Xwt.Drawing.Colors.White, 0.5) : Color);
     ctx.Rectangle(Bounds.Width / 2 - coreSize.Width / 2, Bounds.Height / 2 - coreSize.Height / 2, coreSize.Width, coreSize.Height);
     ctx.Fill();
 }
Exemplo n.º 4
0
        protected override void OnDraw(Xwt.Drawing.Context cr, Rectangle bound)
        {
            {
                cr.Rectangle(bound.X, bound.Y, bound.Width, bound.Height);
                cr.SetSourceColor(editor.ColorStyle.PlainText.Background);
                cr.Fill();
                using (var layout = PangoUtil.CreateLayout(editor))
                {
                    layout.Font = editor.Options.Font;

                    layout.Text = "000,00-00";
                    var mins = layout.GetSize();

                    var line      = editor.GetLine(editor.Caret.Line);
                    var visColumn = line.GetVisualColumn(editor.GetTextEditorData(), editor.Caret.Column);

                    if (visColumn != editor.Caret.Column)
                    {
                        layout.Text = editor.Caret.Line + "," + editor.Caret.Column + "-" + visColumn;
                    }
                    else
                    {
                        layout.Text = editor.Caret.Line + "," + editor.Caret.Column;
                    }

                    var statuss = layout.GetSize();

                    statuss.Width = System.Math.Max(statuss.Width, mins.Width);

                    statuss.Width += 8;
                    cr.MoveTo(Size.Width - statuss.Width, 0);
                    statuss.Width += 8;
                    cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground);
                    cr.ShowLayout(layout);

                    layout.Text = statusText ?? "";
                    var size = layout.GetSize();
                    var x    = System.Math.Min(0, -size.Width + Size.Width - editor.TextViewMargin.CharWidth - statuss.Width);
                    cr.MoveTo(x, 0);
                    cr.SetSourceColor(editor.ColorStyle.PlainText.Foreground);
                    cr.ShowLayout(layout);
                    if (ShowCaret)
                    {
                        if (editor.TextViewMargin.caretBlink)
                        {
                            cr.Rectangle(size.Width + x, 0, (int)editor.TextViewMargin.CharWidth, (int)editor.LineHeight);
                            cr.Fill();
                        }
                    }
                }
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 6
0
 protected internal override void DrawBackground(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
 {
     cr.Save();
     cr.SetColor(Colors.LightGray);
     cr.Rectangle(x, y, Width, height + 1);
     cr.Fill();
     cr.Restore();
 }
Exemplo n.º 7
0
 void DrawGutterBackground(Xwt.Drawing.Context cr, int line, double x, double y, double lineHeight)
 {
     if (editor.Caret.Line == line)
     {
         editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight);
         return;
     }
     cr.Rectangle(x, y, Width, lineHeight);
     cr.SetSourceColor(lineNumberBgGC);
     cr.Fill();
 }
Exemplo n.º 8
0
 public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics)
 {
     if (metrics.SelectionStart > 0)
     {
         return(true);
     }
     cr.SetSourceColor(color);
     cr.Rectangle(metrics.TextRenderStartPosition, y, metrics.TextRenderEndPosition - metrics.TextRenderStartPosition, editor.LineHeight);
     cr.Fill();
     return(true);
 }
Exemplo n.º 9
0
        public override bool DrawBackground(TextEditor editor, Xwt.Drawing.Context cr, MarginDrawMetrics metrics)
        {
            var width = metrics.Width;

            cr.Rectangle(metrics.X, metrics.Y, metrics.Width, metrics.Height);
            var lineNumberGC = editor.ColorStyle.LineNumbers.Foreground;

            cr.SetSourceColor(editor.Caret.Line == metrics.LineNumber ? editor.ColorStyle.LineMarker.Color : lineNumberGC);
            cr.Fill();

            return(true);
        }
Exemplo n.º 10
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            ctx.Save();
            ctx.SetColor(editor.Options.Background);
            ctx.Rectangle(dirtyRect);
            ctx.Fill();
            ctx.Restore();

            UpdateMarginXOffsets();
            RenderMargins(ctx, dirtyRect);
        }
Exemplo n.º 11
0
		protected void InitBlank (int width = 50, int height = 50)
		{
			if (builder != null)
				builder.Dispose ();

			builder = new ImageBuilder (width, height);
			context = builder.Context;
			context.Rectangle (0, 0, width, height);
			context.SetColor (Colors.White);
			context.Fill ();
			context.SetColor (Colors.Black);
			context.SetLineWidth (1);
		}
Exemplo n.º 12
0
        protected void TestDrawing2(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();
            ctx.Translate(x, y);
            var arcColor = new Color(1, 0, 1);

            ctx.Arc(100, 100, 15, 0, 360);
            ctx.ClosePath();
            arcColor.Alpha = 0.4;
            ctx.SetColor(arcColor);
            ctx.StrokePreserve();
            ctx.Fill();

            ctx.Restore();
        }
Exemplo n.º 13
0
			protected override void OnDraw (Context ctx, Rectangle dirtyRect)
			{
				base.OnDraw (ctx, dirtyRect);

				ctx.Rectangle (0, 0, Size.Width, Size.Height);
				ctx.SetColor (Colors.LightGray);
				ctx.Fill ();

				ctx.SetColor (Colors.Black);
				using (var layout = new TextLayout (this))
				{
					layout.Text = text;
					ctx.DrawTextLayout (layout, new Point (0, 20));
				}
			}
Exemplo n.º 14
0
		internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y)
		{
			ctx.Rectangle (x, y, Width, Editor.LineHeight);
			ctx.SetColor (Style.HexOffsetBg);
			ctx.Fill ();

			if (line >= 0 && line * Editor.BytesInRow < Data.Length) {
				LayoutWrapper layout = GetLayout (line);
				var sz = layout.Layout.GetSize ();
				ctx.SetColor (line != Caret.Line ? Style.HexOffset : Style.HexOffsetHighlighted);
				ctx.DrawTextLayout (layout.Layout, x + Width - sz.Width - 4, y);
				if (layout.IsUncached)
					layout.Dispose ();
			}
		}
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
		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;
				}
			}
		}
Exemplo n.º 17
0
        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));
                }
            }
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        public virtual void Curves1(Context ctx, double x, double y)
        {
            ctx.Save ();
            ctx.Translate (x, y);

            ctx.SetLineWidth (1);
            Action curve1 = () => {
                ctx.MoveTo (0, 30);
                ctx.CurveTo (20, 0, 50, 0, 60, 25);
            };
            // curve2 with lineTo; curve1 is closed
            Action curve2 = () => {
                ctx.LineTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            Action paint = () => {
                curve1 ();
                curve2 ();
                ctx.ClosePath ();
                ctx.SetColor (new Color (0, 0, 0, .5));
                ctx.StrokePreserve ();
                ctx.SetColor (new Color (1, 0, 1, .5));
                ctx.Fill ();
            };
            paint ();

            ctx.Translate (0, 40);
            // curve2 with moveTo; curve1 is open
            curve2 = () => {
                ctx.MoveTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            paint ();
            ctx.Restore ();

            //Todo: same stuff with arc
        }
Exemplo n.º 20
0
        protected override sealed void OnDraw(Context ctx, Rectangle bounds)
        {
            var frame = GetFrame (ctx.ScaleFactor);
            var fixedWidth = frame.Bitmap.Width - 2 - frame.StretchableWidth;
            var fixedHeight = frame.Bitmap.Height - 2 - frame.StretchableHeight;
            double totalVariableWidth = bounds.Width - fixedWidth / frame.ScaleFactor;
            double totalVariableHeight = bounds.Height - fixedHeight / frame.ScaleFactor;
            double remainingVariableHeight = totalVariableHeight;

            double y = bounds.Y, yb = 1;
            int tileIndex = 0;

            ctx.Save ();
            if (totalVariableWidth < 0) {
                if (fixedWidth > 0)
                    ctx.Scale (bounds.Width / fixedWidth, 1);
                totalVariableWidth = 0;
            }
            if (totalVariableHeight < 0) {
                if (fixedHeight > 0)
                    ctx.Scale (1, bounds.Height / fixedHeight);
                totalVariableHeight = 0;
            }

            foreach (var vs in frame.VerticalSections) {

                double sh = CalcSectionSize (frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);

                double x = bounds.X, xb = 1;
                double remainingVariableWidth = totalVariableWidth;

                foreach (var hs in frame.HorizontalSections) {
                    var sourceRegion = new Rectangle (xb, yb, hs.Size, vs.Size);
                    double sw = CalcSectionSize (frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
                    var targetRegion = new Rectangle (x, y, sw, sh);

                    if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile) {
                        var t = GetTile (frame, tileIndex, sourceRegion);
                        ctx.DrawImage (t, targetRegion);
                    } else {
                        double pw = hs.Size / frame.ScaleFactor;
                        double ph = vs.Size / frame.ScaleFactor;
                        if (hs.Mode == RenderMode.Stretch) {
                            pw = targetRegion.Width;
                        }
                        if (vs.Mode == RenderMode.Stretch) {
                            ph = targetRegion.Height;
                        }

                        ctx.Save ();
                        ctx.Translate (targetRegion.Location);
                        targetRegion.Location = Point.Zero;
                        ctx.Pattern = new ImagePattern (GetTile (frame, tileIndex, sourceRegion).WithSize (pw, ph));
                        ctx.NewPath ();
                        ctx.Rectangle (targetRegion);
                        ctx.Fill ();
                        ctx.Restore ();
                    }
                    x += sw;
                    xb += hs.Size;
                    tileIndex++;
                }
                yb += vs.Size;
                y += sh;
            }
            ctx.Restore ();
        }
Exemplo n.º 21
0
        /// <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);
        }
Exemplo n.º 22
0
		internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y)
		{
			ctx.Rectangle (x, y, Width, Editor.LineHeight);
			ctx.SetColor (Style.HexDigitBg);
			ctx.Fill ();

			LayoutWrapper layout = GetLayout (line);
			if (!Data.IsSomethingSelected && !Caret.InTextEditor && line == Data.Caret.Line) {
				var column = (int)(Caret.Offset % BytesInRow);
				var xOffset = charWidth * column;
				ctx.Rectangle (x + xOffset, y, charWidth, Editor.LineHeight);
				ctx.SetColor (Style.HighlightOffset);
				ctx.Fill ();
			}
			ctx.SetColor (Style.HexDigit);
			ctx.DrawTextLayout (layout.Layout, x, y);
			if (layout.IsUncached)
				layout.Dispose ();
		}
Exemplo n.º 23
0
        /// <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 ();
        }
Exemplo n.º 24
0
		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 ();
		}
Exemplo n.º 25
0
        internal protected override void Draw(Xwt.Drawing.Context cr, Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var marker = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(m => m is MarginMarker && ((MarginMarker)m).CanDraw(this)) : null;

            if (marker != null)
            {
                bool hasDrawn = marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                if (!hasDrawn)
                {
                    marker = null;
                }
            }

            foldSegmentSize  = marginWidth * 4 / 6;
            foldSegmentSize -= (foldSegmentSize) % 2;

            Rectangle drawArea = new Rectangle(x, y, marginWidth, lineHeight);
            var       state    = editor.Document.GetLineState(lineSegment);

            bool isFoldStart  = false;
            bool isContaining = false;
            bool isFoldEnd    = false;

            bool isStartSelected      = false;
            bool isContainingSelected = false;
            bool isEndSelected        = false;

            if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount)
            {
                startFoldings.Clear();
                containingFoldings.Clear();
                endFoldings.Clear();
                foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment))
                {
                    if (segment.StartLine.Offset == lineSegment.Offset)
                    {
                        startFoldings.Add(segment);
                    }
                    else if (segment.EndLine.Offset == lineSegment.Offset)
                    {
                        endFoldings.Add(segment);
                    }
                    else
                    {
                        containingFoldings.Add(segment);
                    }
                }

                isFoldStart  = startFoldings.Count > 0;
                isContaining = containingFoldings.Count > 0;
                isFoldEnd    = endFoldings.Count > 0;

                isStartSelected      = this.lineHover != null && IsMouseHover(startFoldings);
                isContainingSelected = this.lineHover != null && IsMouseHover(containingFoldings);
                isEndSelected        = this.lineHover != null && IsMouseHover(endFoldings);
            }

            if (marker == null)
            {
                if (editor.GetTextEditorData().HighlightCaretLine&& editor.Caret.Line == line)
                {
                    editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight);
                }
                else
                {
                    var bgGC = foldBgGC;
                    if (editor.TextViewMargin.BackgroundRenderer != null)
                    {
                        if (isContainingSelected || isStartSelected || isEndSelected)
                        {
                            bgGC = foldBgGC;
                        }
                        else
                        {
                            bgGC = foldLineHighlightedGCBg;
                        }
                    }

                    cr.Rectangle(drawArea);
                    cr.SetSourceColor(bgGC);
                    cr.Fill();
                }
            }

            if (editor.Options.EnableQuickDiff)
            {
                if (state == TextDocument.LineState.Changed)
                {
                    cr.SetSourceColor(lineStateChangedGC);
                    cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight);
                    cr.Fill();
                }
                else if (state == TextDocument.LineState.Dirty)
                {
                    cr.SetSourceColor(lineStateDirtyGC);
                    cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight);
                    cr.Fill();
                }
            }

            if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount)
            {
                double foldSegmentYPos = y + System.Math.Floor(editor.LineHeight - foldSegmentSize) / 2;
                double xPos            = x + System.Math.Floor(marginWidth / 2) + 0.5;

                if (isFoldStart)
                {
                    bool isVisible         = true;
                    bool moreLinedOpenFold = false;
                    foreach (FoldSegment foldSegment in startFoldings)
                    {
                        if (foldSegment.IsFolded)
                        {
                            isVisible = false;
                        }
                        else
                        {
                            moreLinedOpenFold = foldSegment.EndLine.Offset > foldSegment.StartLine.Offset;
                        }
                    }
                    bool isFoldEndFromUpperFold = false;
                    foreach (FoldSegment foldSegment in endFoldings)
                    {
                        if (foldSegment.EndLine.Offset > foldSegment.StartLine.Offset && !foldSegment.IsFolded)
                        {
                            isFoldEndFromUpperFold = true;
                        }
                    }
                    DrawFoldSegment(cr, x, y, isVisible, isStartSelected);

                    if (isContaining || isFoldEndFromUpperFold)
                    {
                        cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, foldSegmentYPos - 2);
                    }
                    if (isContaining || moreLinedOpenFold)
                    {
                        cr.DrawLine(isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Y + drawArea.Height);
                    }
                }
                else
                {
                    if (isFoldEnd)
                    {
                        double yMid = System.Math.Floor(drawArea.Y + drawArea.Height / 2) + 0.5;
                        cr.DrawLine(isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + marginWidth - 2, yMid);
                        cr.DrawLine(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, yMid);

                        if (isContaining)
                        {
                            cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos, drawArea.Y + drawArea.Height);
                        }
                    }
                    else if (isContaining)
                    {
                        cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void Draw(Xwt.Drawing.Context cr, Rectangle area)
        {
            TextViewMargin textViewMargin = editor.TextViewMargin;
            ISyntaxMode    mode           = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document);

            TextViewMargin.LayoutWrapper lineLayout = null;
            double brightness = HslColor.Brightness(editor.ColorStyle.PlainText.Background);

            int colorCount = foldSegments.Count + 2;

            cr.SetColor(GetColor(-1, brightness, colorCount));
            cr.Rectangle(area);
            cr.Fill();
            var       rectangles         = new Rectangle[foldSegments.Count];
            const int xPadding           = 4;
            const int yPadding           = 2;
            const int rightMarginPadding = 16;

            for (int i = foldSegments.Count - 1; i >= 0; i--)
            {
                var segment = foldSegments[i];
                if (segment.IsInvalid)
                {
                    continue;
                }
                var segmentStartLine = segment.StartLine;
                var segmentEndLine   = segment.EndLine;

                int curWidth = 0;
                var endLine  = segmentEndLine.NextLine;
                var y        = editor.LineToY(segmentStartLine.LineNumber);
                if (y < editor.VAdjustment.Value)
                {
                    segmentStartLine = editor.GetLine(editor.YToLine(editor.VAdjustment.Value));
                    y = editor.LineToY(segmentStartLine.LineNumber);
                }

                for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Size.Height; curLine = curLine.NextLine)
                {
                    var curLayout = textViewMargin.CreateLinePartLayout(mode, curLine, curLine.Offset, curLine.Length, -1, -1);
                    var width     = (int)(curLayout.Width);
                    curWidth = System.Math.Max(curWidth, width);
                    y       += editor.GetLineHeight(curLine);
                }

                double xPos = textViewMargin.XOffset;
                double rectangleWidth = 0, rectangleHeight = 0;

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
                var rectangleStart = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X) - xPadding);

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);

                var rectangleEnd = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X) - xPadding));

                rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2;

                if (i < foldSegments.Count - 1)
                {
                    rectangleWidth = System.Math.Max((rectangles[i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth);
                }

                y = editor.LineToY(segment.StartLine.LineNumber);
                var yEnd = editor.LineToY(segment.EndLine.LineNumber + 1) + (segment.EndLine.LineNumber == editor.LineCount ? editor.LineHeight : 0);
                if (yEnd == 0)
                {
                    yEnd = editor.VAdjustment.UpperValue;
                }
                rectangleHeight = yEnd - y;

                rectangles[i] = new Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2);
            }

            for (int i = 0; i < foldSegments.Count; i++)
            {
                Rectangle clampedRect;
                var       rect = rectangles[i];

                if (i == foldSegments.Count - 1)
                {
                    /*					var radius = (int)(editor.Options.Zoom * 2);
                     *                  int w = 2 * radius;
                     *                  using (var shadow = new Blur (
                     *                      System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width),
                     *                      System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height),
                     *                      radius)) {
                     *                      using (var gctx = shadow.GetContext ()) {
                     *                          gctx.Color = new Color (0, 0, 0, 0);
                     *                          gctx.Fill ();
                     *
                     *                          var a = 0;
                     *                          var b = 0;
                     *                          DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2);
                     *                          var bg = editor.ColorStyle.Default.CairoColor;
                     *                          gctx.Color = new Color (bg.R, bg.G, bg.B, 0.6);
                     *                          gctx.Fill ();
                     *                      }
                     *
                     *                      cr.Save ();
                     *                      cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w);
                     *                      shadow.Draw (cr);
                     *                      cr.Restore ();
                     *                  }*/

                    var curPadSize = 1;

                    var age   = (DateTime.Now - startTime).TotalMilliseconds;
                    var alpha = 0.1;
                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize = (int)(3 + System.Math.Sin(System.Math.PI * animationState) * 3);
                        alpha      = 0.1 + (1.0 - animationState) / 5;
                    }

                    var bg = editor.ColorStyle.PlainText.Foreground;
                    cr.SetColor(bg.WithAlpha(alpha));
                    clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                    DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                    cr.Fill();

                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize  = (int)(2 + System.Math.Sin(System.Math.PI * animationState) * 2);
                        clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                        DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                        cr.SetSourceColor(GetColor(i, brightness, colorCount));
                        cr.Fill();

                        continue;
                    }
                }

                clampedRect = ClampRect(rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height, area);
                DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);

                cr.SetSourceColor(GetColor(i, brightness, colorCount));
                cr.Fill();
            }
        }
Exemplo n.º 27
0
		protected internal override void Draw (Context drawable, Rectangle area, long line, double x, double y)
		{
			drawable.Rectangle (x, y, Width, Editor.LineHeight);
			drawable.SetColor (Style.HexDigitBg);
			drawable.Fill ();
		}
Exemplo n.º 28
0
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			double rwidth = Bounds.Width, rheight = Bounds.Height;
			
			if (autoStartY || autoEndY) {
				double nstartY = double.MaxValue;
				double nendY = double.MinValue;
				GetValueRange (AxisDimension.Y, out nstartY, out nendY);
				
				if (!autoStartY) nstartY = startY;
				if (!autoEndY) nendY = endY;
				if (nendY < nstartY) nendY = nstartY;
				
				if (nstartY != startY || nendY != endY) {
					yrangeChanged = true;
					startY = nstartY;
					endY = nendY;
				}
			}
			
			if (autoStartX || autoEndX) {
				double nstartX = double.MaxValue;
				double nendX = double.MinValue;
				GetValueRange (AxisDimension.X, out nstartX, out nendX);
				
				if (!autoStartX) nstartX = startX;
				if (!autoEndX) nendX = endX;
				if (nendX < nstartX) nendX = nstartX;
				
				if (nstartX != startX || nendX != endX) {
					xrangeChanged = true;
					startX = nstartX;
					endX = nendX;
				}
			}
			
			if (yrangeChanged) {
				FixOrigins ();
				double right = rwidth - 2 - AreaBorderWidth;
				left = AreaBorderWidth;
				left += MeasureAxisSize (ctx, AxisPosition.Left) + 1;
				right -= MeasureAxisSize (ctx, AxisPosition.Right) + 1;
				yrangeChanged = false;
				width = right - left + 1;
				if (width <= 0) width = 1;
			}
			
			if (xrangeChanged) {
				FixOrigins ();
				double bottom = rheight - 2 - AreaBorderWidth;
				top = AreaBorderWidth;
				bottom -= MeasureAxisSize (ctx, AxisPosition.Bottom);
				top += MeasureAxisSize (ctx, AxisPosition.Top);
				
				// Make room for cursor handles
				foreach (ChartCursor cursor in cursors) {
					if (cursor.Dimension == AxisDimension.X && top - AreaBorderWidth < cursor.HandleSize)
						top = cursor.HandleSize + AreaBorderWidth;
				}
				
				xrangeChanged = false;
				height = bottom - top + 1;
				if (height <= 0) height = 1;
			}
			
			if (AutoScaleMargin != 0 && height > 0) {
				double margin = (double)AutoScaleMargin * (endY - startY) / (double) height;
				if (autoStartY) startY -= margin;
				if (autoEndY) endY += margin;
			}

//			Console.WriteLine ("L:" + left + " T:" + top + " W:" + width + " H:" + height);
			
			// Draw the background

			if (backgroundDisplay == BackgroundDisplay.Gradient) {
				ctx.Rectangle (left - 1, top - 1, width + 2, height + 2);
				Gradient pat = new LinearGradient (left - 1, top - 1, left - 1, height + 2);
				pat.AddColorStop (0, backroundColor);
				Color endc = new Color (1,1,1);
				pat.AddColorStop (1, endc);
				ctx.Pattern = pat;
				ctx.Fill ();
			} else {
				ctx.Rectangle (left - 1, top - 1, width + 2, height + 2);
				ctx.SetColor (backroundColor);
				ctx.Fill ();
			}
//			win.DrawRectangle (Style.WhiteGC, true, left - 1, top - 1, width + 2, height + 2);
			ctx.SetColor (Colors.Black);
			ctx.Rectangle (left - AreaBorderWidth, top - AreaBorderWidth, width + AreaBorderWidth*2, height + AreaBorderWidth*2);
			ctx.Stroke ();
			
			// Draw selected area
			
			if (enableSelection) {
				int sx, sy, ex, ey;
				GetPoint (selectionStart.Value, selectionStart.Value, out sx, out sy);
				GetPoint (selectionEnd.Value, selectionEnd.Value, out ex, out ey);
				if (sx > ex) {
					int tmp = sx; sx = ex; ex = tmp;
				}
				ctx.SetColor (new Color (225d/255d, 225d/255d, 225d/255d));
				ctx.Rectangle (sx, top, ex - sx, height + 1);
				ctx.Fill ();
			}
			
			// Draw axes
			
			foreach (Axis ax in axis)
				DrawAxis (ctx, ax);
			
			// Draw values
			foreach (Serie serie in series)
				if (serie.Visible)
					DrawSerie (ctx, serie);

			// Draw cursors
			foreach (ChartCursor cursor in cursors)
				DrawCursor (ctx, cursor);
			
			// Draw cursor labels
			foreach (ChartCursor cursor in cursors)
				if (cursor.ShowValueLabel)
					DrawCursorLabel (ctx, cursor);
			
			((IDisposable)ctx).Dispose ();
		}
Exemplo n.º 29
0
        /// <summary>
        /// Draw the the PlotSurface2D and contents (axes, drawables, and legend) using the
        /// Drawing Context supplied and the bounding rectangle for the PlotSurface to cover
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="bounds">The rectangle within which to draw</param>
        public void Draw(Context ctx, Rectangle bounds)
        {
            Point titleOrigin = Point.Zero;

            ctx.Save ();

            // determine font sizes and tick scale factor.
            double scale = DetermineScaleFactor (bounds.Width, bounds.Height);

            // if there is nothing to plot, draw title and return.
            if (drawables.Count == 0) {
                // draw title
                //TODO: Title should be centred here - not its origin
                Point origin = Point.Zero;
                titleOrigin.X = bounds.Width/2;
                titleOrigin.Y = bounds.Height/2;
                DrawTitle (ctx, titleOrigin, scale);
                ctx.Restore ();
                return;
            }

            // determine the [non physical] axes to draw based on the axis properties set.
            Axis xAxis1 = null;
            Axis xAxis2 = null;
            Axis yAxis1 = null;
            Axis yAxis2 = null;
            DetermineAxesToDraw (out xAxis1, out xAxis2, out yAxis1, out yAxis2);

            // apply scale factor to axes as desired.

            if (xAxis1.AutoScaleTicks) {
                xAxis1.TickScale = scale;
            }
            if (xAxis1.AutoScaleText) {
                xAxis1.FontScale = scale;
            }
            if (yAxis1.AutoScaleTicks) {
                yAxis1.TickScale = scale;
            }
            if (yAxis1.AutoScaleText) {
                yAxis1.FontScale = scale;
            }
            if (xAxis2.AutoScaleTicks) {
                xAxis2.TickScale = scale;
            }
            if (xAxis2.AutoScaleText) {
                xAxis2.FontScale = scale;
            }
            if (yAxis2.AutoScaleTicks) {
                yAxis2.TickScale = scale;
            }
            if (yAxis2.AutoScaleText) {
                yAxis2.FontScale = scale;
            }

            // determine the default physical positioning of those axes.
            PhysicalAxis pXAxis1 = null;
            PhysicalAxis pYAxis1 = null;
            PhysicalAxis pXAxis2 = null;
            PhysicalAxis pYAxis2 = null;
            DeterminePhysicalAxesToDraw (
                bounds, xAxis1, xAxis2, yAxis1, yAxis2,
                out pXAxis1, out pXAxis2, out pYAxis1, out pYAxis2 );

            double oldXAxis2Height = pXAxis2.PhysicalMin.Y;

            // Apply axes constraints
            for (int i=0; i<axesConstraints.Count; ++i) {
                ((AxesConstraint)axesConstraints[i]).ApplyConstraint(
                    pXAxis1, pYAxis1, pXAxis2, pYAxis2 );
            }

            // draw legend if have one.
            // Note: this will update axes if necessary.
            Point legendPosition = new Point(0,0);
            if (legend != null) {
                legend.UpdateAxesPositions (
                    pXAxis1, pYAxis1, pXAxis2, pYAxis2,
                    drawables, scale, padding, bounds,
                    out legendPosition );
            }

            double newXAxis2Height = pXAxis2.PhysicalMin.Y;
            double titleExtraOffset = oldXAxis2Height - newXAxis2Height;

            // now we are ready to define the bounding box for the plot area (to use in clipping
            // operations.
            plotAreaBoundingBoxCache = new Rectangle (
                Math.Min (pXAxis1.PhysicalMin.X, pXAxis1.PhysicalMax.X),
                Math.Min (pYAxis1.PhysicalMax.Y, pYAxis1.PhysicalMin.Y),
                Math.Abs (pXAxis1.PhysicalMax.X - pXAxis1.PhysicalMin.X + 1),
                Math.Abs (pYAxis1.PhysicalMin.Y - pYAxis1.PhysicalMax.Y + 1)
            );
            bbXAxis1Cache = pXAxis1.GetBoundingBox ();
            bbXAxis2Cache = pXAxis2.GetBoundingBox ();
            bbYAxis1Cache = pYAxis1.GetBoundingBox ();
            bbYAxis2Cache = pYAxis2.GetBoundingBox ();

            // Fill in the background.
            if (plotBackImage != null) {
                Rectangle imageRect = (Rectangle)plotAreaBoundingBoxCache;
                ctx.DrawImage (Utils.TiledImage (plotBackImage , imageRect.Size), imageRect);
            }
            //else if (plotBackBrush_ != null) {
            //	g.FillRectangle(
            //		plotBackBrush_.Get( (Rectangle)plotAreaBoundingBoxCache ),
            //		(Rectangle)plotAreaBoundingBoxCache );
            //}
            else {
                ctx.SetColor (plotBackColor);
                ctx.Rectangle ((Rectangle)plotAreaBoundingBoxCache);
                ctx.Fill ();
            }

            // draw title at centre of Physical X-axis and at top of plot

            titleOrigin.X = (pXAxis2.PhysicalMax.X + pXAxis2.PhysicalMin.X)/2.0;
            titleOrigin.Y = bounds.Top + padding - titleExtraOffset;
            Size s = DrawTitle (ctx, titleOrigin, scale);

            bbTitleCache = new Rectangle (titleOrigin.X-s.Width/2, titleOrigin.Y, s.Width, s.Height);

            // draw drawables..
            bool legendDrawn = false;

            for (int i_o = 0; i_o < ordering.Count; ++i_o) {

                int i = (int)ordering.GetByIndex (i_o);
                double zOrder = (double)ordering.GetKey (i_o);
                if (zOrder > legendZOrder) {
                    // draw legend.
                    if (!legendDrawn && legend != null) {
                        legend.Draw (ctx, legendPosition, drawables, scale);
                        legendDrawn = true;
                    }
                }

                IDrawable drawable = (IDrawable)drawables[i];
                XAxisPosition xap = (XAxisPosition)xAxisPositions[i];
                YAxisPosition yap = (YAxisPosition)yAxisPositions[i];

                PhysicalAxis drawXAxis;
                PhysicalAxis drawYAxis;

                if (xap == XAxisPosition.Bottom) {
                    drawXAxis = pXAxis1;
                }
                else {
                    drawXAxis = pXAxis2;
                }

                if (yap == YAxisPosition.Left) {
                    drawYAxis = pYAxis1;
                }
                else {
                    drawYAxis = pYAxis2;
                }

                // set the clipping region.. (necessary for zoom)
                ///TODO:	g.Clip = new Region((Rectangle)plotAreaBoundingBoxCache);
                // plot.
                drawable.Draw (ctx, drawXAxis, drawYAxis);
                // reset it..
                //g.ResetClip();
            }

            if (!legendDrawn && legend != null) {
                legend.Draw (ctx, legendPosition, drawables, scale);
            }

            // cache the physical axes we used on this draw;
            pXAxis1Cache = pXAxis1;
            pYAxis1Cache = pYAxis1;
            pXAxis2Cache = pXAxis2;
            pYAxis2Cache = pYAxis2;

            // now draw axes.
            Rectangle axisBounds;
            pXAxis1.Draw (ctx, out axisBounds);
            pXAxis2.Draw (ctx, out axisBounds);
            pYAxis1.Draw (ctx, out axisBounds);
            pYAxis2.Draw (ctx, out axisBounds);

            #if DEBUG_BOUNDING_BOXES
            ctx.SetColor (Colors.Orange);
            ctx.Rectangle ((Rectangle)bbXAxis1Cache);
            ctx.Rectangle ((Rectangle)bbXAxis2Cache);
            ctx.Rectangle ((Rectangle)bbYAxis1Cache);
            ctx.Rectangle ((Rectangle)bbYAxis2Cache);
            ctx.Stroke ();
            ctx.SetColor (Colors.Red);
            ctx.Rectangle ((Rectangle)plotAreaBoundingBoxCache);
            ctx.Rectangle ((Rectangle)bbTitleCache);
            ctx.Stroke ();
            #endif
            ctx.Restore ();
        }
Exemplo n.º 30
0
		void DrawCursorLabel (Context ctx, ChartCursor cursor)
		{
			ctx.SetColor (cursor.Color);
			
			int x, y;
			GetPoint (cursor.Value, cursor.Value, out x, out y);

			if (cursor.Dimension == AxisDimension.X) {
			
				string text;
				
				if (cursor.LabelAxis != null) {
					double minStep = GetMinTickStep (cursor.Dimension);
					TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator (minStep);
					tenum.Init (cursor.Value);
					text = tenum.CurrentLabel;
				} else {
					text = GetValueLabel (cursor.Dimension, cursor.Value);
				}
				
				if (text != null && text.Length > 0) {
					TextLayout layout = new TextLayout ();
					layout.Font = chartFont;
					layout.Text = text;
					
					Size ts = layout.GetSize ();
					double tl = x - ts.Width/2;
					double tt = top + 4;
					if (tl + ts.Width + 2 >= left + width) tl = left + width - ts.Width - 1;
					if (tl < left + 1) tl = left + 1;
					ctx.SetColor (Colors.White);
					ctx.Rectangle (tl - 1, tt - 1, ts.Width + 2, ts.Height + 2);
					ctx.Fill ();
					ctx.Rectangle (tl - 2, tt - 2, ts.Width + 3, ts.Height + 3);
					ctx.SetColor (Colors.Black);
					ctx.DrawTextLayout (layout, tl, tt);
				}
			} else {
				throw new NotSupportedException ();
			}
		}
Exemplo n.º 31
0
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			ctx.Rectangle (dirtyRect);
			ctx.SetColor (Colors.Red);
			ctx.Fill ();
		}
		void FillCellBackground (Context ctx, Color color)
		{
			ctx.Rectangle (BackgroundBounds);
			ctx.SetColor (color);
			ctx.Fill ();
		}
Exemplo n.º 33
0
		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 ();
		}
Exemplo n.º 34
0
Arquivo: Boxes.cs Projeto: joncham/xwt
 protected override void OnDraw(Context ctx)
 {
     ctx.SetColor (new Color (0.5, 0.5, 0.5));
     ctx.Rectangle (Bounds);
     ctx.Fill ();
     ctx.SetColor (new Color (0.8, 0.8, 0.8));
     ctx.Rectangle (Bounds.Inflate (-margin, -margin));
     ctx.Fill ();
     ctx.SetColor (Color);
     ctx.Rectangle (Bounds.Width / 2 - coreSize.Width / 2, Bounds.Height / 2 - coreSize.Height / 2, coreSize.Width, coreSize.Height);
     ctx.Fill ();
 }
Exemplo n.º 35
0
        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 ();
            }
        }
Exemplo n.º 36
0
			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 ();
				}
			}
Exemplo n.º 37
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            ctx.Save ();
            ctx.Translate (-hscroll.Value, -vscroll.Value);
            ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
            ctx.SetColor (Xwt.Drawing.Colors.White);
            ctx.Fill ();
            ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
            ctx.SetColor (new Color (0,0,1));
            ctx.Fill ();
            ctx.Restore ();

            ctx.Rectangle (0, 0, Bounds.Width, 30);
            ctx.SetColor (new Color (1, 0, 0, 0.5));
            ctx.Fill ();
        }
Exemplo n.º 38
0
        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();
                    }
                }
            }
        }
Exemplo n.º 39
0
        protected sealed override void OnDraw(Context ctx, Rectangle bounds)
        {
            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            var    frame                   = GetFrame(ctx.ScaleFactor);
            var    fixedWidth              = frame.Bitmap.Width - 2 - frame.StretchableWidth;
            var    fixedHeight             = frame.Bitmap.Height - 2 - frame.StretchableHeight;
            double totalVariableWidth      = bounds.Width - fixedWidth / frame.ScaleFactor;
            double totalVariableHeight     = bounds.Height - fixedHeight / frame.ScaleFactor;
            double remainingVariableHeight = totalVariableHeight;

            double y = bounds.Y, yb = 1;
            int    tileIndex = 0;

            ctx.Save();
            if (totalVariableWidth < 0)
            {
                if (fixedWidth > 0)
                {
                    ctx.Scale(bounds.Width / fixedWidth, 1);
                }
                totalVariableWidth = 0;
            }
            if (totalVariableHeight < 0)
            {
                if (fixedHeight > 0)
                {
                    ctx.Scale(1, bounds.Height / fixedHeight);
                }
                totalVariableHeight = 0;
            }

            foreach (var vs in frame.VerticalSections)
            {
                double sh = CalcSectionSize(frame, vs, totalVariableHeight, frame.StretchableHeight, ref remainingVariableHeight);

                double x = bounds.X, xb = 1;
                double remainingVariableWidth = totalVariableWidth;

                foreach (var hs in frame.HorizontalSections)
                {
                    var    sourceRegion = new Rectangle(xb, yb, hs.Size, vs.Size);
                    double sw           = CalcSectionSize(frame, hs, totalVariableWidth, frame.StretchableWidth, ref remainingVariableWidth);
                    var    targetRegion = new Rectangle(x, y, sw, sh);

                    if (vs.Mode != RenderMode.Tile && hs.Mode != RenderMode.Tile)
                    {
                        var t = GetTile(frame, tileIndex, sourceRegion);
                        ctx.DrawImage(t, targetRegion);
                    }
                    else
                    {
                        double pw = hs.Size / frame.ScaleFactor;
                        double ph = vs.Size / frame.ScaleFactor;
                        if (hs.Mode == RenderMode.Stretch)
                        {
                            pw = targetRegion.Width;
                        }
                        if (vs.Mode == RenderMode.Stretch)
                        {
                            ph = targetRegion.Height;
                        }

                        if (pw <= 0 || ph <= 0)
                        {
                            continue;
                        }

                        ctx.Save();
                        ctx.Translate(targetRegion.Location);
                        targetRegion.Location = Point.Zero;
                        ctx.Pattern           = new ImagePattern(GetTile(frame, tileIndex, sourceRegion).WithSize(pw, ph));
                        ctx.NewPath();
                        ctx.Rectangle(targetRegion);
                        ctx.Fill();
                        ctx.Restore();
                    }
                    x  += sw;
                    xb += hs.Size;
                    tileIndex++;
                }
                yb += vs.Size;
                y  += sh;
            }
            ctx.Restore();
        }
Exemplo n.º 40
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();
        }
Exemplo n.º 41
0
		protected override void OnDraw (Context ctx, Rectangle dirtyRect)
		{
			ctx.Rectangle (Bounds);
			ctx.SetColor (Colors.White);
			ctx.Fill ();
			
			ctx.MoveTo (0, 0);
			ctx.LineTo (Size.Width, 0);
			ctx.LineTo (0, Size.Height);
			ctx.LineTo (0, 0);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (Bounds);
			ctx.SetColor (color);
			ctx.Fill ();
		}
Exemplo n.º 42
0
        protected override void OnDraw(Context ctx)
        {
            ctx.Translate (-hscroll.Value, -vscroll.Value);
            ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
            ctx.SetColor (Color.White);
            ctx.Fill ();
            ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
            ctx.SetColor (new Color (0,0,1));
            ctx.Fill ();
            ctx.ResetTransform ();

            ctx.Rectangle (0, 0, Bounds.Width, 30);
            ctx.SetColor (new Color (1, 0, 0, 0.5));
            ctx.Fill ();
        }