protected override bool OnExposeEvent(Gdk.EventExpose evnt) { base.OnExposeEvent(evnt); if (size == Gdk.Size.Empty) { return(true); } var preview_size = Gdk.Size.Empty; var widget_size = GdkWindow.GetBounds(); // Figure out the dimensions of the preview to draw if (size.Width <= max_size && size.Height <= max_size) { preview_size = size; } else if (size.Width > size.Height) { preview_size = new Gdk.Size(max_size, (int)(max_size / ((float)size.Width / (float)size.Height))); } else { preview_size = new Gdk.Size((int)(max_size / ((float)size.Height / (float)size.Width)), max_size); } using (var g = Gdk.CairoHelper.Create(GdkWindow)) { var r = new Cairo.Rectangle((widget_size.Width - preview_size.Width) / 2, (widget_size.Height - preview_size.Height) / 2, preview_size.Width, preview_size.Height); if (color.A == 0) { // Fill with transparent checkerboard pattern using (var grid = GdkExtensions.CreateTransparentColorSwatch(false)) using (var surf = grid.ToSurface()) using (var pattern = surf.ToTiledPattern()) g.FillRectangle(r, pattern); } else { // Fill with selected color g.FillRectangle(r, color); } // Draw our canvas drop shadow g.DrawRectangle(new Cairo.Rectangle(r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2), new Cairo.Color(.5, .5, .5), 1); g.DrawRectangle(new Cairo.Rectangle(r.X - 2, r.Y - 2, r.Width + 4, r.Height + 4), new Cairo.Color(.8, .8, .8), 1); g.DrawRectangle(new Cairo.Rectangle(r.X - 3, r.Y - 3, r.Width + 6, r.Height + 6), new Cairo.Color(.9, .9, .9), 1); } return(true); }
/// <summary> /// Gets the lines that are visible in the given view area. /// </summary> /// <param name="viewArea">The view area.</param> /// <param name="startLine">The start line.</param> /// <param name="endLine">The end line.</param> public override void GetLineLayoutRange( Rectangle viewArea, out int startLine, out int endLine) { // Make sure we're on the proper thread. CheckGuiThread(); // We need to get a write lock on the entire cache to avoid // anything else making changes. using (new ReadLock(access)) { // Start the start and end line to the first one. startLine = endLine = 0; // Go through and find the lines that are within range of the // view port. int height = 0; double bottom = viewArea.Y + viewArea.Height; for (int lineIndex = 0; lineIndex < lines.Count; lineIndex++) { // Get the line for the current index. CachedLine line = GetCachedLine(lineIndex); // If the line is current below the view port, then update // the two lines. endLine = lineIndex; if (height < viewArea.Y) { // We are below the line, so update it. startLine = lineIndex; } if (height > bottom) { break; } // Update the line height. height += line.Height; } } // Process any queued changes. ProcessQueuedLineChanges(); }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); // Insert layout code here. this.graphRect = new Cairo.Rectangle(20, 4, allocation.Width - 24, allocation.Height - 24); this.scaleRectX = new Cairo.Rectangle(20, allocation.Height - 20, allocation.Width - 24, 16); this.scaleRectY = new Cairo.Rectangle(4, 4, 16, allocation.Height - 24); }
/// <summary> /// Gets the lines that are visible in the given view area. /// </summary> /// <param name="viewArea">The view area.</param> /// <param name="startLine">The start line.</param> /// <param name="endLine">The end line.</param> public virtual void GetLineLayoutRange( Rectangle viewArea, out int startLine, out int endLine) { // Reset the start line to negative to indicate we don't have a // visible line yet. startLine = -1; // Go through all the lines until we find one that is in the range. int currentY = 0; int lineCount = LineBuffer.LineCount; for (int line = 0; line < lineCount; line++) { // Get the height for this line. int height = GetLineLayoutHeight(line); // If we don't have a starting line, then check to see if this // line is visible. if (startLine < 0) { if (currentY + height >= viewArea.Y) { startLine = line; } } // Set the end line equal to the current line so it moves forward // until we break out. endLine = line; // Add the height to the current Y offset. If it exceeds the // viewport, then we are done. currentY += height; if (currentY > viewArea.Y + viewArea.Height) { // We are done, so return the values. return; } } // If we got this far, nothing is visible. startLine = endLine = 0; return; }
public override void Draw(Cairo.Context cr, Cairo.Rectangle erea) { MonoTextEditor editor = mode.editor; double y = editor.LineToY(mode.CurrentInsertionPoint.Line) - editor.VAdjustment.Value; double x = GetLineIndentationStart(); double x2 = editor.Allocation.Width - mode.HelpWindow.Allocation.Width - InsertionCursorEditMode.HelpWindowMargin * 2; cr.MoveTo(x, y); cr.LineTo(x2, y); cr.SetSourceColor(LineColor); cr.Stroke(); // DrawArrow (cr, x - 4, y); }
public void ZoomToRectangle(Cairo.Rectangle rect) { double ratio; if (document.ImageSize.Width / rect.Width <= document.ImageSize.Height / rect.Height) { ratio = document.ImageSize.Width / rect.Width; } else { ratio = document.ImageSize.Height / rect.Height; } (PintaCore.Actions.View.ZoomComboBox.ComboBox as Gtk.ComboBoxEntry).Entry.Text = String.Format("{0:F}%", ratio * 100.0); Gtk.Main.Iteration(); //Force update of scrollbar upper before recenter RecenterView(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); }
public void ZoomToRectangle(Cairo.Rectangle rect) { double ratio; if (document.ImageSize.Width / rect.Width <= document.ImageSize.Height / rect.Height) { ratio = document.ImageSize.Width / rect.Width; } else { ratio = document.ImageSize.Height / rect.Height; } PintaCore.Actions.View.ZoomComboBox.ComboBox.Entry.Text = ViewActions.ToPercent(ratio); Gtk.Main.Iteration(); //Force update of scrollbar upper before recenter RecenterView(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); }
internal protected override void Draw(Cairo.Context ctx, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { bool backgroundIsDrawn = false; if (lineSegment != null) { foreach (var marker in editor.Document.GetMarkersOrderedByInsertion(lineSegment)) { 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 editor.Document.GetMarkersOrderedByInsertion(lineSegment)) { 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)); } } }
private void Crop(Cairo.Rectangle rectangle) { var normalizedRectangle = CairoHelpers.NormalizeRectangle(rectangle); var croppedScreenshot = new Pixbuf( this.screenshot, (int)normalizedRectangle.X, (int)normalizedRectangle.Y, (int)normalizedRectangle.Width, (int)normalizedRectangle.Height); if (croppedScreenshot == null) { return; } var snippingWindow = this.Parent as SnippingWindow; var imagePath = ScreenshotHelpers.SaveAndReturnPath(croppedScreenshot); if (!string.IsNullOrEmpty(imagePath)) { if (SettingsFeature.Settings.CopyToClipboard) { ScreenshotHelpers.CopyToClipboard(this, croppedScreenshot); } this.Close(snippingWindow); snippingWindow.UpdateInsightsImage(imagePath); snippingWindow.OpenInsights(); } else { this.Close(snippingWindow); var md = new MessageDialog(snippingWindow.Toplevel as Gtk.Window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Empty); md.Text = "Error ocurred during snip. Please try again."; md.Response += (o, args) => { md.Destroy(); }; md.Show(); } }
private void DrawBorder(PageItem pi, Cairo.Context g, Cairo.Rectangle r) { if (r.Height <= 0 || r.Width <= 0) // no bounding box to use { return; } double right = r.X + r.Width; double bottom = r.Y + r.Height; StyleInfo si = pi.SI; DrawLine(si.BColorTop.ToCairoColor(), si.BStyleTop, si.BWidthTop, g, r.X, r.Y, right, r.Y); DrawLine(si.BColorRight.ToCairoColor(), si.BStyleRight, si.BWidthRight, g, right, r.Y, right, bottom); DrawLine(si.BColorLeft.ToCairoColor(), si.BStyleLeft, si.BWidthLeft, g, r.X, r.Y, r.X, bottom); DrawLine(si.BColorBottom.ToCairoColor(), si.BStyleBottom, si.BWidthBottom, g, r.X, bottom, right, bottom); //if (si.) { // g.DrawRoundedRectangle (r, 8, si.BColorTop.ToCairoColor (), 1); //} }
public override void Draw(Cairo.Context cr, Cairo.Rectangle erea) { TextEditor editor = mode.editor; double y = editor.LineToY(mode.CurrentInsertionPoint.Line) - editor.VAdjustment.Value; double x1, x2, d; CalculateLineStarts(out x1, out x2, out d); cr.MoveTo(x1, y + d); cr.LineTo(x1, y); cr.LineTo(x2, y); cr.LineTo(x2, y - d); cr.Color = new Cairo.Color(1.0, 0, 0); cr.Stroke(); DrawArrow(cr, x1 - 4, y); }
internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { var extendingMarker = lineSegment != null ? (IExtendingTextLineMarker)editor.Document.GetMarkers(lineSegment).FirstOrDefault(l => l is IExtendingTextLineMarker) : null; bool isSpaceAbove = extendingMarker != null ? extendingMarker.IsSpaceAbove : false; var gutterMarker = lineSegment != null ? (MarginMarker)editor.Document.GetMarkers(lineSegment).FirstOrDefault(marker => marker is MarginMarker && ((MarginMarker)marker).CanDraw(this)) : null; if (gutterMarker != null && gutterMarker.CanDrawBackground(this)) { bool hasDrawn = gutterMarker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); if (!hasDrawn) { DrawGutterBackground(cr, line, x, y, lineHeight); } } else { DrawGutterBackground(cr, line, x, y, lineHeight); } if (gutterMarker != null && gutterMarker.CanDrawForeground(this)) { gutterMarker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); return; } if (line <= editor.Document.LineCount) { // Due to a mac? gtk bug I need to re-create the layout here // otherwise I get pango exceptions. using (var layout = editor.LayoutCache.RequestLayout()) { layout.FontDescription = gutterFont; layout.Width = (int)Width; layout.Alignment = Pango.Alignment.Right; layout.SetText(line.ToString()); cr.Save(); cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y + (isSpaceAbove ? lineHeight - editor.LineHeight : 0)); cr.SetSourceColor(lineNumberGC); cr.ShowLayout(layout); cr.Restore(); } } }
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; bool drawBackground = true; if (marker != null && marker.CanDrawBackground(this)) { drawBackground = !marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } if (drawBackground) { DrawMarginBackground(cr, line, x, y, lineHeight); } if (marker != null && marker.CanDrawForeground(this)) { marker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } }
private void DrawString(PageText pt, Cairo.Context g, Cairo.Rectangle r) { switch (pt.SI.WritingMode) { case WritingModeEnum.lr_tb: DrawStringHorizontal(pt, g, r); break; case WritingModeEnum.tb_rl: DrawStringTBRL(pt, g, r); break; case WritingModeEnum.tb_lr: DrawStringTBLR(pt, g, r); break; default: throw new NotSupportedException($"Writing mode {pt.SI.WritingMode} is not supported"); } }
private void DrawImage(PageImage pi, Cairo.Context g, Cairo.Rectangle r) { // Stream strm = null; // System.Drawing.Image im = null; Gdk.Pixbuf im = null; try { // strm = new MemoryStream (pi.ImageData); // im = System.Drawing.Image.FromStream (strm); im = new Gdk.Pixbuf(pi.ImageData); DrawImageSized(pi, im, g, r); } finally { // if (strm != null) // strm.Close(); if (im != null) { im.Dispose(); } } }
void DrawRoundedRectangle(Cairo.Context c, Cairo.Rectangle rect) { double x = rect.X; double y = rect.Y; double width = rect.Width; double height = rect.Height; double radius = 5; c.MoveTo(x, y + radius); c.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); c.LineTo(x + width - radius, y); c.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); c.LineTo(x + width, y + height - radius); c.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); c.LineTo(x + radius, y + height); c.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); c.ClosePath(); c.Color = new Cairo.Color(161 / 255.0, 40 / 255.0, 48 / 255.0); c.Fill(); }
internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { var gutterMarker = lineSegment != null ? (IGutterMarker)lineSegment.Markers.FirstOrDefault(marker => marker is IGutterMarker) : null; if (gutterMarker != null) { gutterMarker.DrawLineNumber(editor, Width, cr, area, lineSegment, line, x, y, lineHeight); return; } if (editor.Caret.Line == line) { editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight); } else { cr.Rectangle(x, y, Width, lineHeight); cr.Color = lineNumberBgGC; cr.Fill(); } if (line <= editor.Document.LineCount) { // Due to a mac? gtk bug I need to re-create the layout here // otherwise I get pango exceptions. using (var layout = PangoUtil.CreateLayout(editor)) { layout.FontDescription = gutterFont; layout.Width = (int)Width; layout.Alignment = Pango.Alignment.Right; layout.SetText(line.ToString()); cr.Save(); cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y + (lineHeight - fontHeight) / 2); cr.Color = lineNumberGC; cr.ShowLayout(layout); cr.Restore(); } } }
internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight) { cr.Rectangle(x, y, Width, lineHeight); cr.Color = lineNumberBgGC; cr.Fill(); if (line <= editor.Document.LineCount) { // Due to a mac? gtk bug I need to re-create the layout here // otherwise I get pango exceptions. using (var layout = PangoUtil.CreateLayout(editor)) { layout.FontDescription = editor.Options.Font; layout.Width = (int)Width; layout.Alignment = Pango.Alignment.Right; layout.SetText(line.ToString()); cr.Save(); cr.Translate(x + (int)Width + (editor.Options.ShowFoldMargin ? 0 : -2), y); cr.Color = editor.Caret.Line == line ? lineNumberHighlightGC : lineNumberGC; cr.ShowLayout(layout); cr.Restore(); } } }
// public double Width // { // get { return this.width; } // set { this.width = value; } // } // // public double Height // { // get { return this.height; } // set { this.height = value; } // } // // public double X // { // get { return this.x; } // set { this.x = value; } // } // // public double Y // { // get { return this.y; } // set { this.y = value; } // } // // public double LineWidth // { // get { return this.lineWidth; } // set { this.lineWidth = value; } // } // // public double[] FillColor // { // get { return this.fillColor; } // set { this.fillColor = value; } // } // // public double FillOpacity // { // get { return this.fillOpacity; } // set { this.fillOpacity = value; } // } // // public double[] StrokeColor // { // get { return this.strokeColor; } // set { this.strokeColor = value; } // } // // public double StrokeOpacity // { // get { return this.strokeOpacity; } // set { this.strokeOpacity = value; } // } public void Draw(Gtk.PrintContext context) { Cairo.Context con = context.CairoContext; Cairo.Rectangle cairoRectangle = new Cairo.Rectangle(new Cairo.Point((int)this.x, (int)this.y), this.width, this.height); con.Rectangle(cairoRectangle); con.Color = new Cairo.Color(this.fillColor[0], this.fillColor[1], this.fillColor[2], this.fillOpacity); con.FillPreserve(); con.LineWidth = this.lineWidth; con.Color = new Cairo.Color(this.strokeColor[0], this.strokeColor[1], this.strokeColor[2], this.strokeOpacity); con.Stroke(); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); using (Cairo.Context g = CairoHelper.Create(GdkWindow)) { Cairo.Rectangle ourRect = Rectangle.Inflate(GdkWindow.GetBounds(), -1, -1).ToCairoRectangle(); double diameter = Math.Min(ourRect.Width, ourRect.Height); double radius = (diameter / 2.0); Cairo.PointD center = new Cairo.PointD( (float)(ourRect.X + radius), (float)(ourRect.Y + radius)); double theta = (this.angleValue * 2.0 * Math.PI) / 360.0; Cairo.Rectangle ellipseRect = new Cairo.Rectangle(ourRect.Location(), diameter, diameter); Cairo.Rectangle ellipseOutlineRect = ellipseRect; g.DrawEllipse(ellipseOutlineRect, new Cairo.Color(.1, .1, .1), 1); double endPointRadius = radius - 2; Cairo.PointD endPoint = new Cairo.PointD( (float)(center.X + (endPointRadius * Math.Cos(theta))), (float)(center.Y - (endPointRadius * Math.Sin(theta)))); float gripSize = 2.5f; Cairo.Rectangle gripEllipseRect = new Cairo.Rectangle(center.X - gripSize, center.Y - gripSize, gripSize * 2, gripSize * 2); g.FillEllipse(gripEllipseRect, new Cairo.Color(.1, .1, .1)); g.DrawLine(center, endPoint, new Cairo.Color(.1, .1, .1), 1); } return(true); }
public void ubicar_rectangulo_casillero(Cairo.Rectangle r, Obstaculo original, char tipo) { Point inicio = ubicar_punto_casillero((int)r.X, (int)r.Y); Point fin = ubicar_punto_casillero((int)r.Width, (int)r.Height); for (int x = inicio.X; x <= fin.X; x++) { for (int y = inicio.Y; y <= fin.Y; y++) { if (tipo == 'r') { matrix [x] [y].rectangulos.Add(original); } if (tipo == 'c') { matrix [x] [y].circulos.Add(original); } if (tipo == 'l') { matrix [x] [y].lineas.Add(original); } } } }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { using (var ctx = Gdk.CairoHelper.Create (evnt.Window)) { ctx.LineWidth = 1; var rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); var shadowColor = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.ShadowColor); int inset = 2; var ss = Styles.WelcomeScreen.Pad.ShadowSize; var r = new Cairo.Rectangle (rect.X + ss + 0.5, rect.Y + ss + 0.5, rect.Width - ss * 2 - 1, rect.Height - ss * 2 - 1); var sr = new Cairo.Rectangle (r.X + inset, r.Y + inset + Styles.WelcomeScreen.Pad.ShadowVerticalOffset, r.Width - inset * 2, r.Height - inset * 2); int size = Styles.WelcomeScreen.Pad.ShadowSize; double alpha = 0.2; double alphaDec = 0.2 / (double)size; for (int n=0; n<size; n++) { sr = new Cairo.Rectangle (sr.X - 1, sr.Y - 1, sr.Width + 2, sr.Height + 2); CairoExtensions.RoundedRectangle (ctx, sr.X, sr.Y, sr.Width, sr.Height, 4); shadowColor.A = alpha; ctx.SetSourceColor (shadowColor); ctx.Stroke (); alpha -= alphaDec; } CairoExtensions.RoundedRectangle (ctx, r.X, r.Y, r.Width, r.Height, 4); ctx.SetSourceColor (CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.BackgroundColor)); ctx.FillPreserve (); ctx.SetSourceColor (CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.BorderColor)); ctx.Stroke (); } PropagateExpose (Child, evnt); return true; }
private void ProcessPage(Cairo.Context g, IEnumerable p) { foreach (PageItem pi in p) { if (pi is PageTextHtml) { // PageTextHtml is actually a composite object (just like a page) ProcessHtml(pi as PageTextHtml, g); continue; } if (pi is PageLine) { PageLine pl = pi as PageLine; DrawLine( pl.SI.BColorLeft.ToCairoColor(), pl.SI.BStyleLeft, pl.SI.BWidthLeft, g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2) ); continue; } // RectangleF rect = new RectangleF(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H)); Cairo.Rectangle rect = new Cairo.Rectangle(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H)); if (pi.SI.BackgroundImage != null) { // put out any background image PageImage i = pi.SI.BackgroundImage; DrawImage(i, g, rect); continue; } if (pi is PageText) { PageText pt = pi as PageText; DrawString(pt, g, rect); } if (pi is PageImage) { PageImage i = pi as PageImage; DrawImage(i, g, rect); } if (pi is PageRectangle) { //DrawBackground(g, rect, pi.SI); } // else if (pi is PageEllipse) // { // PageEllipse pe = pi as PageEllipse; // DrawEllipse(pe, g, rect); // } // else if (pi is PagePie) // { // PagePie pp = pi as PagePie; // DrawPie(pp, g, rect); // } // else if (pi is PagePolygon) // { // PagePolygon ppo = pi as PagePolygon; // FillPolygon(ppo, g, rect); // } // else if (pi is PageCurve) // { // PageCurve pc = pi as PageCurve; // DrawCurve(pc.SI.BColorLeft, pc.SI.BStyleLeft, pc.SI.BWidthLeft, // g, pc.Points, pc.Offset, pc.Tension); // } // DrawBorder(pi, g, rect); } }
internal protected override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine 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 isSelected = false; int nextDepth = 0; if (line <= editor.Document.LineCount) { containingFoldings.Clear (); startFoldings.Clear (); foreach (FoldSegment segment in editor.Document.GetFoldingContaining (lineSegment)) { if (segment.StartLine == lineSegment) startFoldings.Add (segment); containingFoldings.Add (segment); } nextDepth = containingFoldings.Count; if (lineSegment.NextLine != null) nextDepth = editor.Document.GetFoldingContaining (lineSegment.NextLine).Count (); isSelected = containingFoldings.Contains (hoverSegment); } var bgGC = foldLineHighlightedGC; if (editor.TextViewMargin.BackgroundRenderer != null) { if (isSelected) { bgGC = foldLineHighlightedGCBg; } else { bgGC = foldBgGC; } } else { HslColor col = foldLineHighlightedGCBg; if (col.L < 0.5) { col.L = System.Math.Min (1.0, col.L + containingFoldings.Count / 15.0); } else { col.L = System.Math.Max (0.0, col.L - containingFoldings.Count / 15.0); } bgGC = col; } cr.Rectangle (drawArea); cr.Color = bgGC; cr.Fill (); if (editor.TextViewMargin.BackgroundRenderer == null) { int delta = nextDepth - containingFoldings.Count (); if (delta != 0) { HslColor col = foldLineHighlightedGCBg; if (col.L < 0.5) { col.L = System.Math.Min (1.0, col.L + (nextDepth - delta * 1.5) / 15.0); } else { col.L = System.Math.Max (0.0, col.L - (nextDepth - delta * 1.5) / 15.0); } cr.Color = col; cr.MoveTo (x, y + lineHeight - 0.5); cr.LineTo (x + marginWidth, y + lineHeight - 0.5); cr.Stroke (); } } 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) { bool isVisible = true; foreach (FoldSegment foldSegment in startFoldings) { if (foldSegment.IsFolded) { isVisible = false; } } if (!isVisible) { DrawClosedFolding (cr, bgGC, x, y); } else { if (hoverSegment != null && editor.TextViewMargin.BackgroundRenderer != null) { if (hoverSegment.StartLine == lineSegment) { DrawUpFolding (cr, bgGC, x, y); } else if (hoverSegment.EndLine == lineSegment) { DrawDownFolding (cr, bgGC, x, y); } } } } }
public abstract void Draw(Cairo.Context cr, Cairo.Rectangle erea);
void GenerateRoomComponents() { if (Room == null) { return; } roomComponents = new List <RoomComponent>(); hoveringComponent = null; // We only draw the 1 component if we're editing a warp destination if (EditingWarpDestination != null) { WarpDestRoomComponent com = new WarpDestRoomComponent(this, EditingWarpDestination); com.SelectedEvent += (sender, args) => { WarpEditor.SetSelectedWarp(com.warp); }; roomComponents.Add(com); goto addedAllComponents; // I love being evil } if (ViewObjects && ObjectGroupEditor.TopObjectGroup != null) { foreach (ObjectGroup group in ObjectGroupEditor.TopObjectGroup.GetAllGroups()) { for (int i = 0; i < group.GetNumObjects(); i++) { ObjectDefinition obj = group.GetObject(i); if (!obj.HasXY()) { continue; } ObjectRoomComponent com = new ObjectRoomComponent(obj); com.SelectedEvent += (sender, args) => { ObjectGroupEditor.SelectObject(obj.ObjectGroup, obj.Index); }; roomComponents.Add(com); } } } if (ViewWarps) { int index = 0; WarpGroup group = room.GetWarpGroup(); foreach (Warp warp in group.GetWarps()) { Action <int, int, int, int> addWarpComponent = (x, y, width, height) => { var rect = new Cairo.Rectangle(x, y, width, height); var com = new WarpSourceRoomComponent(this, warp, index, rect); com.SelectedEvent += (sender, args) => { WarpEditor.SetWarpIndex(com.index); }; roomComponents.Add(com); }; if (warp.WarpSourceType == WarpSourceType.Standard) { int middle; if (Room.Width == 15) // Large room { middle = ((Room.Width + 1) / 2) * 16; } else // Small room { middle = ((Room.Width + 1) / 2) * 16 + 8; } int right = Room.Width * 16; int bottom = Room.Height * 16 - 8; if (warp.TopLeft) { addWarpComponent(0, -8, middle, 16); } if (warp.TopRight) { addWarpComponent(middle, -8, right - middle, 16); } if (warp.BottomLeft) { addWarpComponent(0, bottom, middle, 16); } if (warp.BottomRight) { addWarpComponent(middle, bottom, right - middle, 16); } if (!warp.TopLeft && !warp.TopRight && !warp.BottomLeft && !warp.BottomRight) { addWarpComponent(0, 16 * 13, Room.Width * 16, 32); } } else if (warp.WarpSourceType == WarpSourceType.Pointed) { addWarpComponent(warp.SourceX * TileWidth, warp.SourceY * TileHeight, TileWidth, TileHeight); } index++; } } if (ViewChests) { if (Room.Chest != null) { ChestRoomComponent com = new ChestRoomComponent(Room.Chest); roomComponents.Add(com); } } addedAllComponents: // The "selectedComponent" now refers to an old object. Look for the corresponding new // object. RoomComponent newSelectedComponent = null; foreach (RoomComponent com in roomComponents) { if (com.Compare(selectedComponent)) { newSelectedComponent = com; break; } } selectedComponent = newSelectedComponent; QueueDraw(); }
void DrawAlphaBetaMarker (Cairo.Context c, ref Cairo.PointD bottomRight, string text) { c.SelectFontFace (SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); c.SetFontSize (SplashFontSize); // Create a rectangle larger than the text so we can have a nice border var extents = c.TextExtents (text); var x = bottomRight.X - extents.Width * 1.3; var y = bottomRight.Y - extents.Height * 1.5; var rectangle = new Cairo.Rectangle (x, y, bottomRight.X - x, bottomRight.Y - y); // Draw the background color the text will be overlaid on DrawRoundedRectangle (c, rectangle); // Calculate the offset the text will need to be at to be centralised // in the border x = x + extents.XBearing + (rectangle.Width - extents.Width) / 2; y = y - extents.YBearing + (rectangle.Height - extents.Height) / 2; c.MoveTo (x, y); // Draw the text c.Color = new Cairo.Color (1, 1, 1); c.ShowText (text); bottomRight.Y -= rectangle.Height - 2; }
void DrawDownFolding (Cairo.Context cr, Cairo.Color col, double x, double y) { 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); cr.MoveTo (new Cairo.PointD (drawArea.X, drawArea.Y + drawArea.Height)); cr.LineTo (new Cairo.PointD (drawArea.X + drawArea.Width / 2, drawArea.Y)); cr.LineTo (new Cairo.PointD (drawArea.X + drawArea.Width, drawArea.Y + drawArea.Height)); cr.ClosePath (); cr.Color = GetColor (col); cr.Fill (); }
private void DrawString(PageText pt, Cairo.Context g, Cairo.Rectangle r) { StyleInfo si = pt.SI; string s = pt.Text; g.Save(); layout = Pango.CairoHelper.CreateLayout(g); // Font drawFont = null; // StringFormat drawFormat = null; // Brush drawBrush = null; // STYLE // System.Drawing.FontStyle fs = 0; // if (si.FontStyle == FontStyleEnum.Italic) // fs |= System.Drawing.FontStyle.Italic; //Pango fonts are scaled to 72dpi, Windows fonts uses 96dpi float fontsize = (si.FontSize * 72 / 96); var font = Pango.FontDescription.FromString(string.Format("{0} {1}", si.GetFontFamily().Name, fontsize * PixelsX(1))); if (si.FontStyle == FontStyleEnum.Italic) font.Style = Pango.Style.Italic; // // switch (si.TextDecoration) // { // case TextDecorationEnum.Underline: // fs |= System.Drawing.FontStyle.Underline; // break; // case TextDecorationEnum.LineThrough: // fs |= System.Drawing.FontStyle.Strikeout; // break; // case TextDecorationEnum.Overline: // case TextDecorationEnum.None: // break; // } // WEIGHT // switch (si.FontWeight) // { // case FontWeightEnum.Bold: // case FontWeightEnum.Bolder: // case FontWeightEnum.W500: // case FontWeightEnum.W600: // case FontWeightEnum.W700: // case FontWeightEnum.W800: // case FontWeightEnum.W900: // fs |= System.Drawing.FontStyle.Bold; // break; // default: // break; // } // try // { // drawFont = new Font(si.GetFontFamily(), si.FontSize, fs); // si.FontSize already in points // } // catch (ArgumentException) // { // drawFont = new Font("Arial", si.FontSize, fs); // if this fails we'll let the error pass thru // } //font.AbsoluteSize = (int)(PixelsX (si.FontSize)); switch (si.FontWeight) { case FontWeightEnum.Bold: case FontWeightEnum.Bolder: case FontWeightEnum.W500: case FontWeightEnum.W600: case FontWeightEnum.W700: case FontWeightEnum.W800: case FontWeightEnum.W900: font.Weight = Pango.Weight.Bold; break; } Pango.FontDescription oldfont = layout.FontDescription; layout.FontDescription = font; // ALIGNMENT // drawFormat = new StringFormat(); // switch (si.TextAlign) // { // case TextAlignEnum.Right: // drawFormat.Alignment = StringAlignment.Far; // break; // case TextAlignEnum.Center: // drawFormat.Alignment = StringAlignment.Center; // break; // case TextAlignEnum.Left: // default: // drawFormat.Alignment = StringAlignment.Near; // break; // } switch (si.TextAlign) { case TextAlignEnum.Right: layout.Alignment = Pango.Alignment.Right; break; case TextAlignEnum.Center: layout.Alignment = Pango.Alignment.Center; break; case TextAlignEnum.Left: default: layout.Alignment = Pango.Alignment.Left; break; } layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2)); // layout.Width = (int)Pango.Units.FromPixels((int)r.Width); layout.SetText(s); // if (pt.SI.WritingMode == WritingModeEnum.tb_rl) // { // drawFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; // drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical; // } // switch (si.VerticalAlign) // { // case VerticalAlignEnum.Bottom: // drawFormat.LineAlignment = StringAlignment.Far; // break; // case VerticalAlignEnum.Middle: // drawFormat.LineAlignment = StringAlignment.Center; // break; // case VerticalAlignEnum.Top: // default: // drawFormat.LineAlignment = StringAlignment.Near; // break; // } // Pango.Rectangle logical; Pango.Rectangle ink; layout.GetExtents(out ink, out logical); double height = logical.Height / Pango.Scale.PangoScale; double y = 0; switch (si.VerticalAlign) { case VerticalAlignEnum.Top: y = r.Y + si.PaddingTop; break; case VerticalAlignEnum.Middle: y = r.Y + (r.Height - height) / 2; break; case VerticalAlignEnum.Bottom: y = r.Y + (r.Height - height) - si.PaddingBottom; break; } // draw the background DrawBackground(g, r, si); // adjust drawing rectangle based on padding // Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + si.PaddingLeft, // r.Y + si.PaddingTop, // r.Width - si.PaddingLeft - si.PaddingRight, // r.Height - si.PaddingTop - si.PaddingBottom); Cairo.Rectangle box = new Cairo.Rectangle( r.X + si.PaddingLeft + 1, y, r.Width, r.Height); //drawBrush = new SolidBrush(si.Color); g.Color = si.Color.ToCairoColor(); // if (pt.NoClip) // request not to clip text // { // g.DrawString(pt.Text, drawFont, drawBrush, new PointF(r.Left, r.Top), drawFormat); // //HighlightString(g, pt, new RectangleF(r.Left, r.Top, float.MaxValue, float.MaxValue),drawFont, drawFormat); // } // else // { // g.DrawString(pt.Text, drawFont, drawBrush, r2, drawFormat); // //HighlightString(g, pt, r2, drawFont, drawFormat); // } g.MoveTo(box.X, box.Y); Pango.CairoHelper.ShowLayout(g, layout); layout.FontDescription = oldfont; g.Restore(); }
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNr, double x, double y, double _lineHeight) { // double xStart = System.Math.Max (area.X, XOffset); // xStart = System.Math.Max (0, xStart); var correctedXOffset = System.Math.Floor (XOffset) - 1; var lineArea = new Cairo.Rectangle (correctedXOffset, y, textEditor.Allocation.Width - correctedXOffset, _lineHeight); int width, height; double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale; defaultBgColor = Document.ReadOnly ? ColorStyle.BackgroundReadOnly.Color : ColorStyle.PlainText.Background; // Draw the default back color for the whole line. Colors other than the default // background will be drawn when rendering the text chunks. if (BackgroundRenderer == null) DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true); bool isSelectionDrawn = false; // Check if line is beyond the document length if (line == null) { var marker = Document.GetExtendingTextMarker (lineNr); if (marker != null) marker.Draw (textEditor, cr, lineNr, lineArea); return; } IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line); int offset = line.Offset; int caretOffset = Caret.Offset; bool isEolFolded = false; restart: int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNr) DrawCaretLineMarker (cr, x, y, TextStartPosition, _lineHeight); foreach (FoldSegment folding in foldings) { int foldOffset = folding.StartLine.Offset + folding.Column - 1; if (foldOffset < offset) continue; if (folding.IsFolded) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight); offset = folding.EndLine.Offset + folding.EndColumn - 1; markerLayout.SetText (folding.Description); markerLayout.GetSize (out width, out height); bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment); double pixelX = 0.5 + System.Math.Floor (pangoPosition / Pango.Scale.PangoScale); double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom; double pixelWidth = System.Math.Floor ((pangoPosition + width) / Pango.Scale.PangoScale - pixelX + foldXMargin * 2); var foldingRectangle = new Cairo.Rectangle ( pixelX, y, pixelWidth, this.LineHeight); if (BackgroundRenderer == null && isFoldingSelected) { cr.Color = SelectionColor.Background; cr.Rectangle (foldingRectangle); cr.Fill (); } if (isFoldingSelected && SelectionColor.TransparentForeground) { cr.Color = ColorStyle.CollapsedText.Foreground; } else { cr.Color = isFoldingSelected ? SelectionColor.Foreground : ColorStyle.CollapsedText.Foreground; } var boundingRectangleHeight = foldingRectangle.Height - 1; var boundingRectangleY = System.Math.Floor (foldingRectangle.Y + (foldingRectangle.Height - boundingRectangleHeight) / 2); RoundedRectangle (cr, System.Math.Floor (foldingRectangle.X) + 0.5, boundingRectangleY + 0.5, System.Math.Floor (foldingRectangle.Width - cr.LineWidth), System.Math.Floor (boundingRectangleHeight - cr.LineWidth), LineHeight / 8, CairoCorners.All, false); cr.Stroke (); cr.Save (); cr.Translate ( pangoPosition / Pango.Scale.PangoScale + foldXMargin, System.Math.Floor (boundingRectangleY + (boundingRectangleHeight - System.Math.Floor (height / Pango.Scale.PangoScale)) / 2)); cr.ShowLayout (markerLayout); cr.Restore (); if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description)) { var cx = (int)(pangoPosition / Pango.Scale.PangoScale); SetVisibleCaretPosition (cx, y, cx, y); } pangoPosition += foldingRectangle.Width * Pango.Scale.PangoScale; if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description)) { var cx = (int)(pangoPosition / Pango.Scale.PangoScale); SetVisibleCaretPosition (cx, y, cx, y); } if (folding.EndLine != line) { line = folding.EndLine; lineNr = line.LineNumber; foldings = Document.GetStartFoldings (line); isEolFolded = line.Length <= folding.EndColumn; goto restart; } isEolFolded = line.Length <= folding.EndColumn; } } // Draw remaining line - must be called for empty line parts as well because the caret may be at this positon // and the caret position is calculated in DrawLinePart. if (line.EndOffsetIncludingDelimiter - offset >= 0) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight); } bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length); var lx = (int)(pangoPosition / Pango.Scale.PangoScale); lineArea = new Cairo.Rectangle (lx, lineArea.Y, textEditor.Allocation.Width - lx, lineArea.Height); if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) { DocumentLocation start = textEditor.MainSelection.Anchor; DocumentLocation end = textEditor.MainSelection.Lead; DocumentLocation visStart = textEditor.LogicalToVisualLocation (start); DocumentLocation visEnd = textEditor.LogicalToVisualLocation (end); double x1 = this.ColumnToX (line, visStart.Column); double x2 = this.ColumnToX (line, visEnd.Column); if (x1 > x2) { var tmp = x1; x1 = x2; x2 = tmp; } x1 += correctedXOffset - textEditor.HAdjustment.Value; x2 += correctedXOffset - textEditor.HAdjustment.Value; if (x2 > lineArea.X && BackgroundRenderer == null) { if (x1 - lineArea.X > 0) { DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x1 - lineArea.X, lineArea.Height), defaultBgColor, false); lineArea = new Cairo.Rectangle (x1, lineArea.Y, lineArea.Width, lineArea.Height); } DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.Background, false); lineArea = new Cairo.Rectangle (x2, lineArea.Y, textEditor.Allocation.Width - lineArea.X, lineArea.Height); } } if (!isSelectionDrawn && BackgroundRenderer == null) { if (isEolSelected) { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) var eolStartX = System.Math.Floor (pangoPosition / Pango.Scale.PangoScale); lineArea = new Cairo.Rectangle ( eolStartX, lineArea.Y, textEditor.Allocation.Width - eolStartX, lineArea.Height); DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.Background, false); if (line.Length == 0) DrawIndent (cr, GetLayout (line), line, lx, y); } else if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Caret.Line != lineNr) { LayoutWrapper wrapper = GetLayout (line); if (wrapper.EolSpanStack != null) { foreach (var span in wrapper.EolSpanStack) { var spanStyle = textEditor.ColorStyle.GetChunkStyle (span.Color); if (spanStyle == null) continue; if (!spanStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (spanStyle.Background)) { DrawRectangleWithRuler (cr, x, lineArea, spanStyle.Background, false); break; } } } } else { double xPos = pangoPosition / Pango.Scale.PangoScale; DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos, _lineHeight); } } if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never) { if (!isEolFolded && isEolSelected || textEditor.Options.ShowWhitespaces == ShowWhitespaces.Always) if (!(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection)) DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y); } var extendingMarker = Document.GetExtendingTextMarker (lineNr); if (extendingMarker != null) extendingMarker.Draw (textEditor, cr, lineNr, lineArea); if (BackgroundRenderer == null) { var metrics = new EndOfLineMetrics { LineSegment = line, TextRenderEndPosition = TextStartPosition + pangoPosition / Pango.Scale.PangoScale, LineHeight = _lineHeight }; foreach (var marker in line.Markers) { marker.DrawAfterEol (textEditor, cr, y, metrics); } } lastLineRenderWidth = pangoPosition / Pango.Scale.PangoScale; if (textEditor.HAdjustment.Value > 0) { cr.LineWidth = textEditor.Options.Zoom; for (int i = 0; i < verticalShadowAlphaTable.Length; i++) { cr.Color = new Cairo.Color (0, 0, 0, 1 - verticalShadowAlphaTable[i]); cr.MoveTo (x + i * cr.LineWidth + 0.5, y); cr.LineTo (x + i * cr.LineWidth + 0.5, y + 1 + _lineHeight); cr.Stroke (); } } }
protected abstract void Draw(Cairo.Context context, Cairo.Rectangle area);
public static Cairo.Rectangle ClampRect(double x, double y, double r, double w, double h, Cairo.Rectangle area) { var x1 = x; var y1 = y; var x2 = x + w; var y2 = y + h; x1 = System.Math.Max(x1, area.X - r); y1 = System.Math.Max(y1, area.Y - r); x2 = System.Math.Min(x2, area.Width + r); y2 = System.Math.Min(y2, area.Height + r); return(new Cairo.Rectangle(x1, y1, x2 - x1, y2 - y1)); }
public void Draw (Cairo.Context cr, Cairo.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.SetSourceColor (GetColor (-1, brightness, colorCount)); cr.Rectangle (area); cr.Fill (); var rectangles = new Cairo.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.Allocation.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 / Pango.Scale.PangoScale) - 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 / Pango.Scale.PangoScale) - 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.Upper; rectangleHeight = yEnd - y; rectangles[i] = new Cairo.Rectangle (xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2); } for (int i = 0; i < foldSegments.Count; i++) { Cairo.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 Cairo.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 Cairo.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.SetSourceRGBA (bg.R, bg.G, bg.B, 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 (); } }
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); }
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); } } } }
private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r) { double height, width; // some work variables StyleInfo si = pi.SI; // adjust drawing rectangle based on padding // System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft), // r.Top + PixelsY(si.PaddingTop), // r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), // r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft), r.Y + PixelsY(si.PaddingTop), r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle ir; // int work rectangle switch (pi.Sizing) { case ImageSizingEnum.AutoSize: // // Note: GDI+ will stretch an image when you only provide // // the left/top coordinates. This seems pretty stupid since // // it results in the image being out of focus even though // // you don't want the image resized. // if (g.DpiX == im.HorizontalResolution && // g.DpiY == im.VerticalResolution) float imwidth = PixelsX(im.Width); float imheight = PixelsX(im.Height); ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), imwidth, imheight); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); //g.DrawImage(im, ir); im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper); g.DrawPixbufRect(im, ir); break; case ImageSizingEnum.Clip: // Region saveRegion = g.Clip; g.Save(); // Region clipRegion = new Region(g.Clip.GetRegionData()); // clipRegion.Intersect(r2); // g.Clip = clipRegion; g.Rectangle(r2); g.Clip(); // if (dpiX == im.HorizontalResolution && // dpiY == im.VerticalResolution) ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), im.Width, im.Height); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); // g.DrawImage(im, ir); g.DrawPixbufRect(im, ir); // g.Clip = saveRegion; g.Restore(); break; case ImageSizingEnum.FitProportional: double ratioIm = (float)im.Height / (float)im.Width; double ratioR = r2.Height / r2.Width; height = r2.Height; width = r2.Width; if (ratioIm > ratioR) { // this means the rectangle width must be corrected width = height * (1 / ratioIm); } else if (ratioIm < ratioR) { // this means the ractangle height must be corrected height = width * ratioIm; } r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height); g.DrawPixbufRect(im, r2); break; case ImageSizingEnum.Fit: default: g.DrawPixbufRect(im, r2); break; } }
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, LineSegment line, int lineNr, double x, double y, double _lineHeight) { // double xStart = System.Math.Max (area.X, XOffset); // xStart = System.Math.Max (0, xStart); var lineArea = new Cairo.Rectangle (XOffset - 1, y, textEditor.Allocation.Width - XOffset + 1, _lineHeight); int width, height; double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale; defaultBgColor = Document.ReadOnly ? ColorStyle.ReadOnlyTextBg : ColorStyle.Default.CairoBackgroundColor; // Draw the default back color for the whole line. Colors other than the default // background will be drawn when rendering the text chunks. DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true); bool isSelectionDrawn = false; if (BackgroundRenderer != null) BackgroundRenderer.Draw (cr, area, line, x, y, _lineHeight); // Check if line is beyond the document length if (line == null) { if (textEditor.Options.ShowInvalidLines) DrawInvalidLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y); var marker = Document.GetExtendingTextMarker (lineNr); if (marker != null) marker.Draw (textEditor, cr, lineNr, lineArea); return; } IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line); int offset = line.Offset; int caretOffset = Caret.Offset; bool isEolFolded = false; restart: int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn); foreach (FoldSegment folding in foldings) { int foldOffset = folding.StartLine.Offset + folding.Column - 1; if (foldOffset < offset) continue; if (folding.IsFolded) { DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width); offset = folding.EndLine.Offset + folding.EndColumn; markerLayout.SetText (folding.Description); markerLayout.GetSize (out width, out height); bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment); double pixelX = pangoPosition / Pango.Scale.PangoScale; double pixelWidth = (pangoPosition + width) / Pango.Scale.PangoScale - pixelX; var foldingRectangle = new Cairo.Rectangle (pixelX + 0.5, y + 0.5, pixelWidth - cr.LineWidth, this.LineHeight - cr.LineWidth); if (BackgroundRenderer == null) { cr.Color = isFoldingSelected ? SelectionColor.CairoBackgroundColor : defaultBgColor; cr.Rectangle (foldingRectangle); cr.Fill (); } cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor; cr.Rectangle (foldingRectangle); cr.Stroke (); cr.Save (); cr.Translate (pangoPosition / Pango.Scale.PangoScale, y); cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor; cr.ShowLayout (markerLayout); cr.Restore (); if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description)) SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y); pangoPosition += width; if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description)) SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y); if (folding.EndLine != line) { line = folding.EndLine; lineNr = Document.OffsetToLineNumber (line.Offset); foldings = Document.GetStartFoldings (line); isEolFolded = line.Length <= folding.EndColumn; goto restart; } isEolFolded = line.Length <= folding.EndColumn; } } // Draw remaining line - must be called for empty line parts as well because the caret may be at this positon // and the caret position is calculated in DrawLinePart. if (line.EndOffsetIncludingDelimiter - offset >= 0) DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width); bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length); lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale, lineArea.Height); if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) { DocumentLocation start = textEditor.MainSelection.Anchor; DocumentLocation end = textEditor.MainSelection.Lead; DocumentLocation visStart = textEditor.LogicalToVisualLocation (start); DocumentLocation visEnd = textEditor.LogicalToVisualLocation (end); double x1 = this.ColumnToX (line, visStart.Column); double x2 = this.ColumnToX (line, visEnd.Column); if (x1 > x2) { var tmp = x1; x1 = x2; x2 = tmp; } x1 += XOffset - textEditor.HAdjustment.Value; x2 += XOffset - textEditor.HAdjustment.Value; if (x2 > lineArea.X) { if (x1 - lineArea.X > 0) { DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x1 - lineArea.X, lineArea.Height), defaultBgColor, false); lineArea = new Cairo.Rectangle (x1, lineArea.Y, lineArea.Width, lineArea.Height); } DrawRectangleWithRuler (cr, x, new Cairo.Rectangle (lineArea.X, lineArea.Y, x2 - lineArea.X, lineArea.Height), this.SelectionColor.CairoBackgroundColor, false); lineArea = new Cairo.Rectangle (x2, lineArea.Y, textEditor.Allocation.Width - lineArea.X, lineArea.Height); } } if (!isSelectionDrawn) { if (isEolSelected) { if (!Platform.IsMac) { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1, lineArea.Height); } else { // prevent "gaps" in the selection drawing ('fuzzy' lines problem) lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale - 1, lineArea.Y, textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale + 1, lineArea.Height); } DrawRectangleWithRuler (cr, x, lineArea, this.SelectionColor.CairoBackgroundColor, false); } else if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Caret.Line != lineNr) { LayoutWrapper wrapper = GetLayout (line); if (wrapper.EolSpanStack != null) { foreach (var span in wrapper.EolSpanStack) { var spanStyle = textEditor.ColorStyle.GetChunkStyle (span.Color); if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) { DrawRectangleWithRuler (cr, x, lineArea, spanStyle.CairoBackgroundColor, false); break; } } } } else { double xPos = pangoPosition / Pango.Scale.PangoScale; DrawCaretLineMarker (cr, xPos, y, lineArea.X + lineArea.Width - xPos); } } if (!isEolFolded && textEditor.Options.ShowEolMarkers) DrawEolMarker (cr, line, isEolSelected, pangoPosition / Pango.Scale.PangoScale, y); var extendingMarker = Document.GetExtendingTextMarker (lineNr); if (extendingMarker != null) extendingMarker.Draw (textEditor, cr, lineNr, lineArea); lastLineRenderWidth = pangoPosition / Pango.Scale.PangoScale; }
public Cairo.Rectangle GetNextRect() { Cairo.Rectangle rectangle; rect = rfx_message_get_rect(msg, irects++); rectangle = new Cairo.Rectangle((double) rect->x, (double) rect->y, (double) rect->width, (double) rect->height); return rectangle; }
void UpdateRect() { rect = new Cairo.Rectangle(X - rect.Width / 2.0, Y - rect.Height / 2.0, rect.Width, rect.Height); }
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); } } } }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated (allocation); // Insert layout code here. this.graphRect = new Cairo.Rectangle(20, 4, allocation.Width - 24, allocation.Height - 24); this.scaleRectX = new Cairo.Rectangle(20, allocation.Height - 20, allocation.Width - 24, 16); this.scaleRectY = new Cairo.Rectangle(4, 4, 16, allocation.Height - 24); }
/// <summary> /// User has double clicked somewhere on a graph. /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void OnMouseDoubleClick(object sender, OxyMouseDownEventArgs e) { Point Location = new Point((int)e.Position.X, (int)e.Position.Y); Cairo.Rectangle plotRect = this.plot1.Model.PlotArea.ToRect(false); Rectangle plotArea = new Rectangle((int)plotRect.X, (int)plotRect.Y, (int)plotRect.Width, (int)plotRect.Height); if (plotArea.Contains(Location)) { Cairo.Rectangle legendRect = this.plot1.Model.LegendArea.ToRect(true); Rectangle legendArea = new Rectangle((int)legendRect.X, (int)legendRect.Y, (int)legendRect.Width, (int)legendRect.Height); if (legendArea.Contains(Location)) { int y = Convert.ToInt32(Location.Y - this.plot1.Model.LegendArea.Top); int itemHeight = Convert.ToInt32(this.plot1.Model.LegendArea.Height) / this.plot1.Model.Series.Count; int seriesIndex = y / itemHeight; if (this.OnLegendClick != null) { LegendClickArgs args = new LegendClickArgs(); args.seriesIndex = seriesIndex; args.controlKeyPressed = e.IsControlDown; this.OnLegendClick.Invoke(sender, args); } } else { if (this.OnPlotClick != null) { this.OnPlotClick.Invoke(sender, e); } } } else { Rectangle leftAxisArea = new Rectangle(0, plotArea.Y, plotArea.X, plotArea.Height); Rectangle titleArea = new Rectangle(plotArea.X, 0, plotArea.Width, plotArea.Y); Rectangle topAxisArea = new Rectangle(plotArea.X, 0, plotArea.Width, 0); if (this.GetAxis(Models.Graph.Axis.AxisType.Top) != null) { titleArea = new Rectangle(plotArea.X, 0, plotArea.Width, plotArea.Y / 2); topAxisArea = new Rectangle(plotArea.X, plotArea.Y / 2, plotArea.Width, plotArea.Y / 2); } Rectangle rightAxisArea = new Rectangle(plotArea.Right, plotArea.Top, MainWidget.Allocation.Width - plotArea.Right, plotArea.Height); Rectangle bottomAxisArea = new Rectangle(plotArea.Left, plotArea.Bottom, plotArea.Width, MainWidget.Allocation.Height - plotArea.Bottom); if (titleArea.Contains(Location)) { if (this.OnTitleClick != null) { this.OnTitleClick(sender, e); } } if (this.OnAxisClick != null) { if (leftAxisArea.Contains(Location)) { this.OnAxisClick.Invoke(Models.Graph.Axis.AxisType.Left); } else if (topAxisArea.Contains(Location)) { this.OnAxisClick.Invoke(Models.Graph.Axis.AxisType.Top); } else if (rightAxisArea.Contains(Location)) { this.OnAxisClick.Invoke(Models.Graph.Axis.AxisType.Right); } else if (bottomAxisArea.Contains(Location)) { this.OnAxisClick.Invoke(Models.Graph.Axis.AxisType.Bottom); } } } }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { base.OnExposeEvent (evnt); if (size == Gdk.Size.Empty) return true; var preview_size = Gdk.Size.Empty; var widget_size = GdkWindow.GetBounds (); // Figure out the dimensions of the preview to draw if (size.Width <= max_size && size.Height <= max_size) preview_size = size; else if (size.Width > size.Height) preview_size = new Gdk.Size (max_size, (int)(max_size / ((float)size.Width / (float)size.Height))); else preview_size = new Gdk.Size ((int)(max_size / ((float)size.Height / (float)size.Width)), max_size); using (var g = Gdk.CairoHelper.Create (GdkWindow)) { var r = new Cairo.Rectangle ((widget_size.Width - preview_size.Width) / 2, (widget_size.Height - preview_size.Height) / 2, preview_size.Width, preview_size.Height); if (color.A == 0) { // Fill with transparent checkerboard pattern using (var grid = GdkExtensions.CreateTransparentColorSwatch (false)) using (var surf = grid.ToSurface ()) using (var pattern = surf.ToTiledPattern ()) g.FillRectangle (r, pattern); } else { // Fill with selected color g.FillRectangle (r, color); } // Draw our canvas drop shadow g.DrawRectangle (new Cairo.Rectangle (r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2), new Cairo.Color (.5, .5, .5), 1); g.DrawRectangle (new Cairo.Rectangle (r.X - 2, r.Y - 2, r.Width + 4, r.Height + 4), new Cairo.Color (.8, .8, .8), 1); g.DrawRectangle (new Cairo.Rectangle (r.X - 3, r.Y - 3, r.Width + 6, r.Height + 6), new Cairo.Color (.9, .9, .9), 1); } return true; }
public void Draw(Cairo.Context cr, Cairo.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.SetSourceColor(GetColor(-1, brightness, colorCount)); cr.Rectangle(area); cr.Fill(); var rectangles = new Cairo.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.Allocation.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 / Pango.Scale.PangoScale) - 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 / Pango.Scale.PangoScale) - 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.Upper; } rectangleHeight = yEnd - y; rectangles[i] = new Cairo.Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2); } for (int i = 0; i < foldSegments.Count; i++) { Cairo.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 Cairo.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 Cairo.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.SetSourceRGBA(bg.R, bg.G, bg.B, 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(); } }
public NRect(double x, double y, double width, double height) { _rect = new Cairo.Rectangle(x, y, width, height); }
void DecorateMatchingBracket (Cairo.Context ctx, LayoutWrapper layout, int offset, int length, double xPos, double y, int selectionStart, int selectionEnd) { uint curIndex = 0, byteIndex = 0; if (offset <= highlightBracketOffset && highlightBracketOffset <= offset + length) { int index = highlightBracketOffset - offset; Pango.Rectangle rect = layout.Layout.IndexToPos ((int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex)); var bracketMatch = new Cairo.Rectangle (xPos + rect.X / Pango.Scale.PangoScale + 0.5, y + 0.5, (rect.Width / Pango.Scale.PangoScale) - 1, (rect.Height / Pango.Scale.PangoScale) - 1); if (BackgroundRenderer == null) { ctx.Color = this.ColorStyle.BraceMatchingRectangle.Color; ctx.Rectangle (bracketMatch); ctx.FillPreserve (); ctx.Color = this.ColorStyle.BraceMatchingRectangle.SecondColor; ctx.Stroke (); } } }
protected override bool OnExposeEvent (Gdk.EventExpose ev) { base.OnExposeEvent (ev); using (Cairo.Context g = CairoHelper.Create (GdkWindow)) { Cairo.Rectangle ourRect = Rectangle.Inflate (GdkWindow.GetBounds (), -1, -1).ToCairoRectangle (); double diameter = Math.Min (ourRect.Width, ourRect.Height); double radius = (diameter / 2.0); Cairo.PointD center = new Cairo.PointD ( (float)(ourRect.X + radius), (float)(ourRect.Y + radius)); double theta = (this.angleValue * 2.0 * Math.PI) / 360.0; Cairo.Rectangle ellipseRect = new Cairo.Rectangle (ourRect.Location (), diameter, diameter); Cairo.Rectangle ellipseOutlineRect = ellipseRect; g.DrawEllipse (ellipseOutlineRect, new Cairo.Color (.1, .1, .1), 1); double endPointRadius = radius - 2; Cairo.PointD endPoint = new Cairo.PointD ( (float)(center.X + (endPointRadius * Math.Cos (theta))), (float)(center.Y - (endPointRadius * Math.Sin (theta)))); float gripSize = 2.5f; Cairo.Rectangle gripEllipseRect = new Cairo.Rectangle (center.X - gripSize, center.Y - gripSize, gripSize * 2, gripSize * 2); g.FillEllipse (gripEllipseRect, new Cairo.Color (.1, .1, .1)); g.DrawLine (center, endPoint, new Cairo.Color (.1, .1, .1), 1); } return true; }
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); Document.LineState state = editor.Document.GetLineState(line); 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 == Document.LineState.Changed) { cr.Color = lineStateChangedGC; cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight); cr.Fill(); } else if (state == Document.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); } } } }
public override void DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset) { try { double fromX, toX; GetLineDrawingPosition (metrics, startOffset, out fromX, out toX); fromX = Math.Max (fromX, editor.TextViewMargin.XOffset); toX = Math.Max (toX, editor.TextViewMargin.XOffset); if (fromX < toX) { var bracketMatch = new Cairo.Rectangle (fromX + 0.5, metrics.LineYRenderStartPosition + 0.5, toX - fromX - 1, editor.LineHeight - 2); if (editor.TextViewMargin.BackgroundRenderer == null) { cr.SetSourceColor (editor.ColorStyle.BraceMatchingRectangle.Color); cr.Rectangle (bracketMatch); cr.FillPreserve (); cr.SetSourceColor (editor.ColorStyle.BraceMatchingRectangle.SecondColor); cr.Stroke (); } } } catch (Exception e) { LoggingService.LogError ($"Error while drawing bracket matcher ({this}) startOffset={startOffset} lineCharLength={metrics.Layout.LineChars.Length}", e); } }
internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight) { drawer.Draw(cr, area, line, lineNumber, x, y, lineHeight); }
public virtual void Popup () { if (editor.GdkWindow == null){ editor.Realized += HandleRealized; return; } bounds = CalculateInitialBounds (); //GTK uses integer position coords, so round fractions down, we'll add them back later as draw offsets int x = (int) System.Math.Floor (bounds.X); int y = (int) System.Math.Floor (bounds.Y); //capture any lost fractions to pass as an offset to Draw userspaceArea = new Cairo.Rectangle (bounds.X - x, bounds.Y - y, bounds.Width, bounds.Height); //lose half-pixels on the expansion, it's not a big deal xExpandedOffset = (int) (System.Math.Floor (ExpandWidth / 2d)); yExpandedOffset = (int) (System.Math.Floor (ExpandHeight / 2d)); //round the width/height up to make sure we have room for restored fractions int width = System.Math.Max (1, (int) (System.Math.Ceiling (bounds.Width) + ExpandWidth)); int height = System.Math.Max (1, (int) (System.Math.Ceiling (bounds.Height) + ExpandHeight)); this.SetSizeRequest (width, height); editor.TextArea.AddTopLevelWidget (this, x - xExpandedOffset, y - yExpandedOffset); stage.AddOrReset (this, Duration); stage.Play (); Show (); }