public void DrawRectangleWithRuler (Cairo.Context cr, double x, Cairo.Rectangle area, Cairo.Color color, bool drawDefaultBackground)
		{
			bool isDefaultColor = color.R == defaultBgColor.R && color.G == defaultBgColor.G && color.B == defaultBgColor.B;
			if (isDefaultColor && !drawDefaultBackground)
				return;
			cr.Color = color;
			var left = (int)(area.X);
			var width = (int)area.Width + 1;
			if (textEditor.Options.ShowRuler) {
				var right = left + width;

				var divider = (int) (System.Math.Max (left, System.Math.Min (x + TextStartPosition + rulerX, right)));
				if (divider < right) {
					var beforeDividerWidth = divider - left;
					if (beforeDividerWidth > 0) {
						cr.Rectangle (left, area.Y, beforeDividerWidth, area.Height);
						cr.Fill ();
					}
					cr.Rectangle (divider, area.Y, right - divider, area.Height);
					cr.Color = DimColor (color);
					cr.Fill ();

					if (beforeDividerWidth > 0) {
						cr.DrawLine (
							ColorStyle.Ruler.Color,
							divider + 0.5, area.Y,
							divider + 0.5, area.Y + area.Height);
					}
					return;
				}
			}

			cr.Rectangle (left, area.Y, System.Math.Ceiling (area.Width), area.Height);
			cr.Fill ();
		}
Example #2
0
		public override void Draw (TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
		{
			int markerStart = line.Offset + startColumn;
			int markerEnd = line.Offset + endColumn;
	
			if (markerEnd < startOffset || markerStart > endOffset) 
				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;
				int x_pos = layout.IndexToPos (start - startOffset).X;
	
				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
	
				x_pos = layout.IndexToPos (end - startOffset).X;
	
				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}
	
			@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
			to = System.Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from < to) {
				cr.DrawLine (selected ? editor.ColorStyle.Selection.CairoColor : editor.ColorStyle.GetChunkStyle (style).CairoColor, @from, y + editor.LineHeight - 1, to, y + editor.LineHeight - 1);
			}
		}
Example #3
0
		public void DrawRectangleWithRuler (Cairo.Context cr, double x, Cairo.Rectangle area, Cairo.Color color, bool drawDefaultBackground)
		{
			bool isDefaultColor = color.R == defaultBgColor.R && color.G == defaultBgColor.G && color.B == defaultBgColor.B;
			if (isDefaultColor && !drawDefaultBackground)
				return;
			cr.Color = color;
			double xp = /*System.Math.Floor*/ (area.X);
			
			if (textEditor.Options.ShowRuler) {
				double divider = System.Math.Max (area.X, System.Math.Min (x + TextStartPosition + rulerX, area.X + area.Width));
				if (divider < area.X + area.Width) {
					cr.Rectangle (xp, area.Y, divider - area.X, area.Height);
					cr.Fill ();
					
					cr.Rectangle (divider, area.Y, area.X + area.Width - divider, area.Height);
					cr.Color = DimColor (color);
					cr.Fill ();
					cr.DrawLine (ColorStyle.Ruler, divider, area.Y, divider, area.Y + area.Height);
					return;
				}
			}
			cr.Rectangle (xp, area.Y, area.Width, area.Height);
			cr.Fill ();
		}
        /// <summary>
        /// Draw a Grid
        /// </summary>
        /// <param name="dc"></param>
        public override void Draw(Cairo.Context dc)
        {
            var lBB = GetBB();
            dc.Rectangle(lBB.ToCairoRectangle());//DashedPen, 

            dc.DrawLine(lBB.X + lBB.Width / 2, lBB.Y, lBB.X + lBB.Width / 2, lBB.Y + lBB.Height); //DashedPen, 
            dc.DrawLine(lBB.X, lBB.Y + lBB.Height/2, lBB.X + lBB.Width , lBB.Y + lBB.Height/2);  //DashedPen, 
        }
        public override void Draw(Cairo.Context dc)
        {
            Pen p = IsDashed ? PensAndBrushes.DashedPen : ThePen;
            float R = (float) (center-p1).Length;   // the radius of the circle
            var diag = new System.Windows.Vector(R,R);
            Rect re = new System.Windows.Rect(center+diag, center-diag);  // BB of the circle
            System.Windows.Vector v1 = p1 - center, v2 = p2 - center;


            if (IsPie)
            {
                dc.DrawLine(center, p1); //p, 
                dc.DrawLine(center, p2); //p, 
            }

            float angle2 = (float)( Math.Atan2(v2.Y, v2.X) *180 / Math.PI);
            float angle1 = (float)( Math.Atan2(v1.Y, v1.X) *180 / Math.PI);
            float angle = angle2 - angle1;
            float bngle = angle + (angle>0?-360:360);


            if (     ( IsLargeArc && Math.Abs(angle) < 180)
                 ||  (!IsLargeArc && Math.Abs(angle) > 180) )
                angle = bngle;

            if (re.Height * re.Width > 0)
            {
                dc.Arc( re.Center().X, re.Center().Y, re.Width/2, angle1, angle);//p, // hack
            }
            /* TODO
            context.BeginFigure(p1, false, IsPie);
            
            SweepDirection sd;
            if ((v1.X * v2.Y - v1.Y * v2.X > 0) != LargeArc)
                sd = SweepDirection.Clockwise;
            else
                sd = SweepDirection.Counterclockwise;

            context.ArcTo(p2, new Size(r, r), 0, LargeArc, sd, true, false);*/

            
        }
        public override void Draw(Cairo.Context dc)
        {
            Pen p = IsSelected ? SelPen : StdPen;
            Rect lBB = GetBB(Parent.Height);

            // draw lines
            if (L1Visible)
                dc.DrawLine(L1Origin, lBB.Center()); //DashedPen, 
            if (L2Visible)
                dc.DrawLine(L2Origin, lBB.Center()); //DashedPen, 

            // draw CP
            dc.FillEllipse(lBB); //Brushes.Gray, 
            dc.DrawEllipse(lBB); //p, 


        }
        public List<double> Spokes { get; set; }    // the angles of the spokes, in radians


        //public double R { get { return TheShape.R; } set { TheShape.R = value; } }
        //public Point Center { get { return TheShape.Center; } set { TheShape.Center = value; } }
        //public List<double> Spokes { get { return TheShape.Spokes; } set { TheShape.Spokes = value; } }    // the angles of the spokes, in radians

        /// <summary>
        /// Draw an arc
        /// </summary>
        /// <param name="dc"></param>
        public override void Draw(Cairo.Context dc)
        {
            if (R == 0 || Spokes == null || Spokes.Count < 2 || ThePen == null)
                return;

            dc.DrawLine(Center, spokep(0)); //ThePen, 

            for (int i = 1; i < Spokes.Count; i++)
            {
                if (Math.Abs(Spokes[i] - Spokes[i - 1]) > 2 * Math.PI - .001)
                {
                    // Display a circle
                    double ControlPointRatio = (Math.Sqrt(2) - 1) * 4 / 3;

                    var x0 = (float)(Center.X - R);
                    var x1 = (float)(Center.X - R * ControlPointRatio);
                    var x2 = (float)(Center.X);
                    var x3 = (float)(Center.X + R * ControlPointRatio);
                    var x4 = (float)(Center.X + R);

                    var y0 = (float)( Center.Y - R);
                    var y1 = (float)(Center.Y - R * ControlPointRatio);
                    var y2 = (float)(Center.Y);
                    var y3 = (float)(Center.Y + R * ControlPointRatio);
                    var y4 = (float)(Center.Y + R);

                    System.Windows.Point[] pts = new System.Windows.Point[] { new System.Windows.Point(x2, y0), new System.Windows.Point(x3, y0), new System.Windows.Point(x4, y1), 
                        new System.Windows.Point(x4, y2), new System.Windows.Point(x1, y4), new System.Windows.Point(x0, y3), new System.Windows.Point(x0, y2),
                        new System.Windows.Point(x0, y1), new System.Windows.Point(x1, y0), new System.Windows.Point(x2, y0) };

                    dc.DrawBeziers(pts); //ThePen, 

                    /* context.BeginFigure(new Point(x2, y0), true, true);
                    context.BezierTo(new Point(x3, y0), new Point(x4, y1), new Point(x4, y2), true, true);
                    context.BezierTo(new Point(x4, y3), new Point(x3, y4), new Point(x2, y4), true, true);
                    context.BezierTo(new Point(x1, y4), new Point(x0, y3), new Point(x0, y2), true, true);
                    context.BezierTo(new Point(x0, y1), new Point(x1, y0), new Point(x2, y0), true, true); */

                }
                else
                {
                    bool largearc = Math.Abs(Spokes[i] - Spokes[i - 1]) > Math.PI;
                   /* SweepDirection sd = SweepDirection.Counterclockwise;
                    if (Spokes[i] < Spokes[i - 1])
                        sd = SweepDirection.Clockwise;

                    dc.DrawArc(ThePen, (float)Center.X, (float(Center.Y), (float)R, (float)R, )
                    context.ArcTo(spokep(i), new Size(R, R), 0, largearc, sd, true, false);*/
                    //TODO:support
                }

                dc.DrawLine(Center, spokep(i));//ThePen, 

            }
        }
		internal protected override void Draw (Cairo.Context cr, Cairo.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;
			
			Cairo.Rectangle drawArea = new Cairo.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);
					}
				}
			}
		}
  /*
  public override void SetSelColor()
  {
      Stroke = new SolidColorBrush(Properties.Settings.Default.Overlay_CoordSelColor);
  }
  public override void SetStdColor()
  {
      Stroke = new SolidColorBrush(Properties.Settings.Default.Overlay_CoordColor);
  }
  */
 
  /// <summary>
  /// Draw an X
  /// </summary>
  /// <param name="dc"></param>
  public override void Draw(Cairo.Context dc)
  {
      Pen p = IsSelected ? SelPen : StdPen;
      Rect lBB = GetBB(Parent.Height);
      dc.SetSourceRGB(1, 0, 0); // todo
      dc.DrawLine(lBB.TopLeft, lBB.BottomRight);
      dc.DrawLine(lBB.BottomLeft, lBB.TopRight);
  }
		void DrawFoldSegment (Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected)
		{
			var drawArea = new Cairo.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);
		}
Example #11
0
		internal protected override void Draw (Cairo.Context cr, Cairo.Rectangle area, LineSegment lineSegment, int line, double x, double y, double lineHeight)
		{
			foldSegmentSize = marginWidth * 4 / 6;
			foldSegmentSize -= (foldSegmentSize) % 2;
			
			Cairo.Rectangle drawArea = new Cairo.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 (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);
			}
			
			var bgGC = foldBgGC;
			if (editor.TextViewMargin.BackgroundRenderer != null) {
				if (isContainingSelected || isStartSelected || isEndSelected) {
					bgGC = foldBgGC;
				} else {
					bgGC = foldLineHighlightedGCBg;
				}
			}
			
			cr.Rectangle (drawArea);
			cr.Color = bgGC;
			cr.Fill ();
			
			if (state == TextDocument.LineState.Changed) {
				cr.Color = lineStateChangedGC;
				cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
				cr.Fill ();
			} else if (state == TextDocument.LineState.Dirty) {
				cr.Color = lineStateDirtyGC;
				cr.Rectangle (x + 1, y, marginWidth / 3, lineHeight);
				cr.Fill ();
			}
			
			if (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 = drawArea.Y + drawArea.Height / 2;
						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 + 1, xPos, drawArea.Y + drawArea.Height);
					} else if (isContaining) {
						cr.DrawLine (isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);
					}

				}
			}
		}
Example #12
0
		public override void Draw (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			var startOffset = metrics.TextStartOffset;
			int endOffset = metrics.TextEndOffset;
			double startXPos = metrics.TextRenderStartPosition;
			double endXPos = metrics.TextRenderEndPosition;
			var layout = metrics.Layout.Layout;
			int markerStart = line.Offset + startColumn;
			int markerEnd = line.Offset + endColumn;
	
			if (markerEnd < startOffset || markerStart > endOffset) 
				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;
				int x_pos = layout.IndexToPos (start - startOffset).X;
	
				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
	
				x_pos = layout.IndexToPos (end - startOffset).X;
	
				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}
	
			@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
			to = System.Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from < to) {
				cr.DrawLine (editor.ColorStyle.GetForeground (editor.ColorStyle.GetChunkStyle (style)), @from + 0.5, y + editor.LineHeight - 1.5, to + 0.5, y + editor.LineHeight - 1.5);
			}
		}
Example #13
0
 public Size Measure(Cairo.Context c, Control control)
 {
     Line line = control as Line;
     Cairo.PointD p1 = new Cairo.PointD (line.Location.X ,line.Location.Y);
     Cairo.PointD p2 = new Cairo.PointD (line.End.X, line.End.Y);
     var r = c.DrawLine (p1, p2, line.BackgroundColor.ToCairoColor (), line.LineWidth, line.LineType, false);
     return new Size (r.Width, r.Height);
 }
Example #14
0
 public void Render(Cairo.Context c, Control control)
 {
     Line line = control as Line;
     Cairo.PointD p1 = new Cairo.PointD (line.Location.X ,line.Location.Y);
     Cairo.PointD p2 = new Cairo.PointD (line.End.X, line.End.Y);
     c.DrawLine (p1, p2, line.BackgroundColor.ToCairoColor (), line.LineWidth, line.LineType, true);
 }