internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor) { Gdk.Pixbuf result = null; Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId); if (iconset != null) { // Find the size that better fits the requested size Gtk.IconSize gsize = Util.GetBestSizeFit(width); result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor); if (result == null || result.Width < width * scaleFactor) { var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes); if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize) { // Don't dispose the previous result since the icon is owned by the IconSet result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null); } } } if (result == null && Gtk.IconTheme.Default.HasIcon(stockId)) { result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0); } if (result == null) { // render a custom gtk-missing-image icon // if Gtk.Stock.MissingImage is not found int w = (int)width; int h = (int)height; #if XWT_GTK3 Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h); Cairo.Context cr = new Cairo.Context(s); cr.SetSourceRGB(255, 255, 255); cr.Rectangle(0, 0, w, h); cr.Fill(); cr.SetSourceRGB(0, 0, 0); cr.LineWidth = 1; cr.Rectangle(0.5, 0.5, w - 1, h - 1); cr.Stroke(); cr.SetSourceRGB(255, 0, 0); cr.LineWidth = 3; cr.LineCap = Cairo.LineCap.Round; cr.LineJoin = Cairo.LineJoin.Round; cr.MoveTo(w / 4, h / 4); cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4); cr.MoveTo(w / 4, (h - 1) - h / 4); cr.LineTo((w - 1) - w / 4, h / 4); cr.Stroke(); result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h); #else Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h); Gdk.GC gc = new Gdk.GC(pmap); gc.RgbFgColor = new Gdk.Color(255, 255, 255); pmap.DrawRectangle(gc, true, 0, 0, w, h); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1)); gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round); gc.RgbFgColor = new Gdk.Color(255, 0, 0); pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4))); pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4))); result = Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h); #endif } return(result); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Cairo.Context cr = Gdk.CairoHelper.Create(e.Window); Gdk.Rectangle area = e.Area; if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage)) { Pango.Layout messageLayout = new Pango.Layout(this.PangoContext); messageLayout.Alignment = Pango.Alignment.Center; messageLayout.Width = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale); if (!string.IsNullOrEmpty(CustomMessage)) { messageLayout.SetText(CustomMessage); } else { messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document.")); } cr.MoveTo(Allocation.Width * 1 / 6, 12); cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); Pango.CairoHelper.ShowLayout(cr, messageLayout); messageLayout.Dispose(); ((IDisposable)cr).Dispose(); return(true); } var backColor = Style.Base(StateType.Normal).ToCairoColor(); cr.SetSourceColor(backColor); cr.Rectangle(area.X, area.Y, area.Width, area.Height); cr.Fill(); int xpos = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0); int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0); int ypos = -vadjustment; ToolboxWidgetCategory lastCategory = null; int lastCategoryYpos = 0; cr.LineWidth = 1; Iterate(ref xpos, ref ypos, (category, itemDimension) => { ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension))) { return(true); } cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.SetSourceColor(Ide.Gui.Styles.PadCategoryBackgroundColor.ToCairoColor()); cr.Fill(); if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand) { cr.MoveTo(xpos, ypos + 0.5); cr.LineTo(itemDimension.Width, ypos + 0.5); } cr.MoveTo(0, ypos + itemDimension.Height - 0.5); cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5); cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor()); cr.Stroke(); headerLayout.SetMarkup(category.Text); int width, height; cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryLabelColor.ToCairoColor()); headerLayout.GetPixelSize(out width, out height); cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2))); Pango.CairoHelper.ShowLayout(cr, headerLayout); var img = category.IsExpanded ? discloseUp : discloseDown; cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2)); lastCategory = category; lastCategoryYpos = ypos + itemDimension.Height; return(true); }, (curCategory, item, itemDimension) => { if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension))) { return(true); } var icon = item.Icon; if (!icon.HasFixedSize) { var maxIconSize = Math.Min(itemDimension.Width, itemDimension.Height); var fittingIconSize = maxIconSize > 32 ? Xwt.IconSize.Large : maxIconSize > 16 ? Xwt.IconSize.Medium : Xwt.IconSize.Small; icon = item.Icon.WithSize(fittingIconSize); } if (item == SelectedItem) { icon = icon.WithStyles("sel"); cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.Fill(); } if (listMode || !curCategory.CanIconizeItems) { cr.DrawImage(this, icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - icon.Height) / 2)); layout.SetMarkup(item.Text); layout.Width = (int)((itemDimension.Width - ItemIconTextItemSpacing - iconSize.Width - ItemLeftPadding * 2) * Pango.Scale.PangoScale); layout.GetPixelSize(out var width, out var height); cr.SetSourceColor(Style.Text(item != SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor()); cr.MoveTo(xpos + ItemLeftPadding + iconSize.Width + ItemIconTextItemSpacing, ypos + Math.Round((double)(itemDimension.Height - height) / 2)); Pango.CairoHelper.ShowLayout(cr, layout); } else { cr.DrawImage(this, icon, xpos + Math.Round((itemDimension.Width - icon.Width) / 2), ypos + Math.Round((itemDimension.Height - icon.Height) / 2)); } if (item == mouseOverItem) { cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor()); cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1); cr.Stroke(); } return(true); }); ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (lastCategory != null && lastCategory.AnimatingExpand) { // Closing line when animating the last group of the toolbox cr.MoveTo(area.X, ypos + 0.5); cr.RelLineTo(area.Width, 0); cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor()); cr.Stroke(); } ((IDisposable)cr).Dispose(); return(true); }
public static void DrawLine(this Cairo.Context dc, System.Windows.Point p1, System.Windows.Point p2) { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); }
protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context context) { context.LineWidth = 1; var alloc = ChildAllocation; var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize; var r = results.Where(res => res.Item2.Count > 0).ToArray(); if (r.Any()) { context.SetSourceColor(lightSearchBackground); context.Rectangle(Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height); context.Fill(); context.SetSourceColor(darkSearchBackground); context.Rectangle(Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height); context.Fill(); context.MoveTo(0.5 + Allocation.X + adjustedMarginSize, 0); context.LineTo(0.5 + Allocation.X + adjustedMarginSize, Allocation.Height); context.SetSourceColor(separatorLine); context.Stroke(); } else { context.SetSourceRGB(1, 1, 1); context.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); context.Fill(); } double y = alloc.Y + yMargin; int w, h; if (topItem != null) { headerLayout.SetText(GettextCatalog.GetString("Top Result")); headerLayout.GetPixelSize(out w, out h); context.MoveTo(alloc.Left + headerMarginSize - w - xMargin, y); context.SetSourceColor(headerColor); Pango.CairoHelper.ShowLayout(context, headerLayout); var category = topItem.Category; var dataSrc = topItem.DataSource; var i = topItem.Item; double x = alloc.X + xMargin + headerMarginSize; context.SetSourceRGB(0, 0, 0); layout.SetMarkup(GetRowMarkup(dataSrc[i])); layout.GetPixelSize(out w, out h); if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) { context.SetSourceColor(selectionBackgroundColor); context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h); context.Fill(); context.SetSourceRGB(1, 1, 1); } var px = dataSrc[i].Icon; if (px != null) { context.DrawImage(this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2); x += px.Width + iconTextSpacing + marginIconSpacing; } context.MoveTo(x, y); context.SetSourceRGB(0, 0, 0); Pango.CairoHelper.ShowLayout(context, layout); y += h + itemSeparatorHeight; } foreach (var result in r) { var category = result.Item1; var dataSrc = result.Item2; if (dataSrc.Count == 0) { continue; } if (dataSrc.Count == 1 && topItem != null && topItem.DataSource == dataSrc) { continue; } headerLayout.SetText(category.Name); headerLayout.GetPixelSize(out w, out h); if (y + h > Allocation.Height) { break; } context.MoveTo(alloc.X + headerMarginSize - w - xMargin, y); context.SetSourceColor(headerColor); Pango.CairoHelper.ShowLayout(context, headerLayout); layout.Width = Pango.Units.FromPixels(Allocation.Width - adjustedMarginSize - 35); for (int i = 0; i < maxItems && i < dataSrc.Count; i++) { if (topItem != null && topItem.Category == category && topItem.Item == i) { continue; } double x = alloc.X + xMargin + headerMarginSize; context.SetSourceRGB(0, 0, 0); layout.SetMarkup(GetRowMarkup(dataSrc[i])); layout.GetPixelSize(out w, out h); if (y + h + itemSeparatorHeight > Allocation.Height) { break; } if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) { context.SetSourceColor(selectionBackgroundColor); context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h); context.Fill(); context.SetSourceRGB(1, 1, 1); } var px = dataSrc[i].Icon; if (px != null) { context.DrawImage(this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2); x += px.Width + iconTextSpacing + marginIconSpacing; } context.MoveTo(x, y); context.SetSourceRGB(0, 0, 0); Pango.CairoHelper.ShowLayout(context, layout); y += h + itemSeparatorHeight; } if (result != r.Last()) { y += categorySeparatorHeight; } } if (y == alloc.Y + yMargin) { context.SetSourceRGB(0, 0, 0); layout.SetMarkup(isInSearch ? GettextCatalog.GetString("Searching...") : GettextCatalog.GetString("No matches")); context.MoveTo(alloc.X + xMargin, y); Pango.CairoHelper.ShowLayout(context, layout); } }
/// <summary> /// Prints the data of the chart /// </summary> /// <param name="height">Height of drawing area.</param> /// <param name="width">Width of drawing area.</param> /// <param name="canvas">The cairo context.</param> void DrawData(int height, int width, Cairo.Context canvas) { //Variable used for start a line Boolean Comienzo = true; canvas.LineWidth = 3; canvas.SetSourceRGB(0, 0, 0); //Functions for calculate the data // Se usa para calcular la ecuacion de la recta con Punto - Pendiente Func <LineData, LineData, double> Pendiente = (d1, d2) => { double toret = (double)(((d2.Y - d1.Y) / (d2.X - d1.X))); return(toret); }; Func <LineData, LineData, double, double> Yvalue = (d1, d2, x) => { double toret = Pendiente(d1, d2) * (x - d1.X) + d1.Y; if (toret < MinYValue) { toret = MinYValue; } return(toret); }; //If dont exist Custom Data Set, Default set wil be Draw. Boolean drawSetDefault = (GetSetCount() == 0); foreach (String key in data.Keys) { if (key.Equals("Default") && !drawSetDefault) { continue; } for (double x = MinXValue; x <= MaxXValue; x += ((MaxXValue - MinXValue) / ((double)(MaxXValue - MinXValue) * 10))) { double drawXPosition = ((XEnd - XStart) * ((x - MinXValue) / (MaxXValue - MinXValue))); drawXPosition += XStart; LineData[] lineData = GetDataBeteewn(x, key); if (lineData[0] != null && lineData[1] != null) { double yValue = Yvalue(lineData[0], lineData[1], x); double drawYPosition = ((YEnd - YStart) * ((Yvalue(lineData[0], lineData[1], x) - MinYValue) / (MaxYValue - MinYValue))); drawYPosition = YEnd - drawYPosition; //drawYPosition = 100; if (Comienzo) { if (yValue < MaxYValue) { canvas.MoveTo(drawXPosition, drawYPosition); Comienzo = false; } } else { if (yValue < MaxYValue) { if (key.Equals("Default")) { canvas.SetSourceRGB(0, 0, 0); } else { canvas.SetSourceRGB(ColorSets[key].R, ColorSets[key].G, ColorSets[key].B); } //Console.WriteLine(ColorSets[key].R + " " + ColorSets[key].G + " " + ColorSets[key].B); canvas.LineTo(drawXPosition, drawYPosition); } else { if (key.Equals("Default")) { canvas.SetSourceRGB(0, 0, 0); } else { canvas.SetSourceRGB(ColorSets[key].R, ColorSets[key].G, ColorSets[key].B); } canvas.Stroke(); Comienzo = true; } } } } canvas.Stroke(); } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.SetSourceRGB(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.SetSourceRGB(1, 1, 1); cr.Fill(); } // use a fixed size revision to get a approx. revision width layout.SetText("88888888"); layout.GetPixelSize(out revisionWidth, out h); layout.SetText(TruncRevision(ann.Revision)); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); const int dateRevisionSpacing = 16; if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); // use a fixed size date to get a approx. date width layout.SetText(new DateTime(1999, 10, 10).ToShortDateString()); layout.GetPixelSize(out dateWidth, out h); layout.SetText(dateTime); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } using (var authorLayout = PangoUtil.CreateLayout(this)) { var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom)); authorLayout.FontDescription = description; authorLayout.SetText(ann.Author); authorLayout.GetPixelSize(out authorWidth, out h); var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing; /* if (authorWidth > maxWidth) { * int idx = ann.Author.IndexOf ('<'); * if (idx > 0) * authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx)); * authorLayout.GetPixelSize (out authorWidth, out h); * }*/ cr.Save(); cr.Rectangle(0, 0, maxWidth, Allocation.Height); cr.Clip(); cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2)); cr.SetSourceRGB(0, 0, 0); cr.ShowLayout(authorLayout); cr.ResetClip(); cr.Restore(); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart, false); if (!string.IsNullOrEmpty(msg)) { msg = FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.SetSourceColor(color); } else { cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95)); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.SetSourceRGB(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
public override bool DrawBackground(TextEditor editor, Cairo.Context g, double y, LineMetrics metrics) { if (!IsVisible) { return(false); } bool markerShouldDrawnAsHidden = cache.CurrentSelectedTextMarker != null && cache.CurrentSelectedTextMarker != this; if (metrics.LineSegment.Markers.Any(m => m is DebugTextMarker)) { return(false); } EnsureLayoutCreated(editor); double x = editor.TextViewMargin.XOffset; int right = editor.Allocation.Width; bool isCaretInLine = metrics.TextStartOffset <= editor.Caret.Offset && editor.Caret.Offset <= metrics.TextEndOffset; int errorCounterWidth = GetErrorCountBounds(metrics).Item1; double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, editor.TextViewMargin.XOffset + editor.LineHeight / 2); bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != Mono.TextEditor.SelectionMode.Block ? editor.SelectionRange.Contains(lineSegment.Offset + lineSegment.Length) : false; int active = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1; bool highlighted = active == 0 && isCaretInLine; // draw background if (!markerShouldDrawnAsHidden) { DrawRectangle(g, x, y, right, editor.LineHeight); g.SetSourceColor(LineColor.Color); g.Fill(); if (metrics.Layout.StartSet || metrics.SelectionStart == metrics.TextEndOffset) { double startX; double endX; if (metrics.SelectionStart != metrics.TextEndOffset) { var start = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionStartIndex); startX = (int)(start.X / Pango.Scale.PangoScale); var end = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionEndIndex); endX = (int)(end.X / Pango.Scale.PangoScale); } else { startX = x2; endX = startX; } if (editor.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block && startX == endX) { endX = startX + 2; } startX += metrics.TextRenderStartPosition; endX += metrics.TextRenderStartPosition; startX = Math.Max(editor.TextViewMargin.XOffset, startX); // clip region to textviewmargin start if (isEolSelected) { endX = editor.Allocation.Width + (int)editor.HAdjustment.Value; } if (startX < endX) { DrawRectangle(g, startX, y, endX - startX, editor.LineHeight); g.SetSourceColor(GetLineColor(highlighted, true)); g.Fill(); } } DrawErrorMarkers(editor, g, metrics, y); } double y2 = y + 0.5; double y2Bottom = y2 + editor.LineHeight - 1; var selected = isEolSelected; var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + metrics.Layout.Width; if (x2 < lineTextPx) { x2 = lineTextPx; } if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); if (divider >= x2) { g.MoveTo(new Cairo.PointD(divider + 0.5, y2)); g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom)); g.SetSourceColor(GetLineColorBorder(highlighted, selected)); g.Stroke(); } } return(true); }
void DrawFocus(Gdk.Window window, Color c) { int x, y, width, height; window.GetPosition(out x, out y); window.GetSize(out width, out height); System.Drawing.Rectangle r = new System.Drawing.Rectangle(x, y, width, height); using (Cairo.Context context = Gdk.CairoHelper.Create(window)) { uint b = mainBox.BorderWidth; // Top using (Cairo.Gradient gradient = createGradient(0.0, 0.0, 0, b, c)) { context.SetSource(gradient); context.MoveTo(0, 0); context.LineTo(r.Width, 0); context.LineTo(r.Width - b + 1, b); context.LineTo(b - 1, b); context.ClosePath(); context.Fill(); } // Left using (Cairo.Gradient gradient = createGradient(0.0, 0.0, b, 0, c)) { context.SetSource(gradient); context.MoveTo(0, 0); context.LineTo(b, b - 1); context.LineTo(b, r.Height - b + 1); context.LineTo(0, r.Height); context.ClosePath(); context.Fill(); } // Bottom using (Cairo.Gradient gradient = createGradient(0.0, r.Height, 0, r.Height - b, c)) { context.SetSource(gradient); context.MoveTo(0, r.Height); context.LineTo(b - 1, r.Height - b); context.LineTo(r.Width - b + 1, r.Height - b); context.LineTo(r.Width, r.Height); context.ClosePath(); context.Fill(); } // Right using (Cairo.Gradient gradient = createGradient(r.Width, 0, r.Width - b, 0, c)) { context.SetSource(gradient); context.MoveTo(r.Width, 0); context.LineTo(r.Width - b, b - 1); context.LineTo(r.Width - b, r.Height - b + 1); context.LineTo(r.Width, r.Height); context.ClosePath(); context.Fill(); } } }
void InternalDraw(int markerStart, int markerEnd, MonoTextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) { if (markerStart >= markerEnd) { return; } double @from; double to; if (markerStart < startOffset && endOffset < markerEnd) { @from = startXPos; to = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; int /*lineNr,*/ x_pos; 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) { return; } double height = editor.LineHeight / 5; // TODO : EditorTheme : Does that look ok ? // if (selected) { // cr.SetSourceColor (editor.EditorTheme.SelectedText.Foreground); //} else { if (ColorName == null) { cr.SetSourceColor(Color); } else { HslColor color; editor.EditorTheme.TryGetColor(ColorName, out color); cr.SetSourceColor(color); } //} if (Wave) { Pango.CairoHelper.ShowErrorUnderline(cr, @from, y + editor.TextViewMargin.UnderlinePosition, to - @from, height); } else { cr.LineWidth = editor.TextViewMargin.UnderLineThickness; cr.MoveTo(@from, y + editor.TextViewMargin.UnderlinePosition - 0.5); cr.LineTo(to, y + editor.TextViewMargin.UnderlinePosition - 0.5); cr.Stroke(); } }
internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor) { Gdk.Pixbuf result = null; Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId); if (iconset != null) { // Find the size that better fits the requested size Gtk.IconSize gsize = Util.GetBestSizeFit (width); result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor); if (result == null || result.Width < width * scaleFactor) { var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes); if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize) // Don't dispose the previous result since the icon is owned by the IconSet result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null); } } if (result == null && Gtk.IconTheme.Default.HasIcon (stockId)) result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0); if (result == null) { // render a custom gtk-missing-image icon // if Gtk.Stock.MissingImage is not found int w = (int)width; int h = (int)height; #if XWT_GTK3 Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h); Cairo.Context cr = new Cairo.Context(s); cr.SetSourceRGB(255, 255, 255); cr.Rectangle(0, 0, w, h); cr.Fill(); cr.SetSourceRGB(0, 0, 0); cr.LineWidth = 1; cr.Rectangle(0.5, 0.5, w - 1, h - 1); cr.Stroke(); cr.SetSourceRGB(255, 0, 0); cr.LineWidth = 3; cr.LineCap = Cairo.LineCap.Round; cr.LineJoin = Cairo.LineJoin.Round; cr.MoveTo(w / 4, h / 4); cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4); cr.MoveTo(w / 4, (h - 1) - h / 4); cr.LineTo((w - 1) - w / 4, h / 4); cr.Stroke(); result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h); #else using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h)) using (Gdk.GC gc = new Gdk.GC (pmap)) { gc.RgbFgColor = new Gdk.Color (255, 255, 255); pmap.DrawRectangle (gc, true, 0, 0, w, h); gc.RgbFgColor = new Gdk.Color (0, 0, 0); pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1)); gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round); gc.RgbFgColor = new Gdk.Color (255, 0, 0); pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4))); pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4))); result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h); } #endif } return result; }
public void Read(string fontFileName, char character, int fontSize) { Typeface typeFace; using (var fs = Utility.ReadFile(Utility.FontDir + fontFileName)) { var reader = new OpenFontReader(); typeFace = reader.Read(fs); } Glyph glyph = typeFace.Lookup(character); // read polygons and bezier segments var polygons = new List <List <Point> >(); var bezierSegments = new List <(Point, Point, Point)>(); GlyphLoader.Read(glyph, out polygons, out bezierSegments); //print to test output for (int i = 0; i < polygons.Count; i++) { o.WriteLine("Polygon " + i); var polygon = polygons[i]; foreach (var p in polygon) { o.WriteLine("{0}, {1}", (int)p.X, (int)p.Y); } o.WriteLine(""); } foreach (var segment in bezierSegments) { o.WriteLine("<{0}, {1}> <{2}, {3}> <{4}, {5}>", (int)segment.Item1.X, (int)segment.Item1.Y, (int)segment.Item2.X, (int)segment.Item2.Y, (int)segment.Item3.X, (int)segment.Item3.Y); } o.WriteLine(""); //FIXME move/scale the rendered glyph to visible region of the cairo surface. // draw to an image using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000)) using (Cairo.Context g = new Cairo.Context(surface)) { for (int i = 0; i < polygons.Count; i++) { var polygon = polygons[i]; g.MoveTo(polygon[0].X, polygon[0].Y); foreach (var point in polygon) { g.LineTo(point.X, point.Y); } g.ClosePath(); } g.SetSourceColor(new Cairo.Color(0, 0, 0)); g.LineWidth = 2; g.StrokePreserve(); g.SetSourceColor(new Cairo.Color(0.8, 0, 0)); g.Fill(); foreach (var segment in bezierSegments) { var p0 = segment.Item1; var c = segment.Item2; var p1 = segment.Item3; g.MoveTo(p0.X, p0.Y); g.QuadraticTo(c.X, c.Y, p1.X, p1.Y); } g.SetSourceColor(new Cairo.Color(0.5, 0.5, 0)); g.Stroke(); var path = string.Format("D:\\ImGui.UnitTest\\GlyphReaderFacts.TheReadMethod.Read_{0}_{1}_{2}.png", fontFileName, character, fontSize); surface.WriteToPng(path); Util.OpenImage(path); // Now inspect the image to check whether the glyph is correct // TODO Are there a better way to do such kind of unit-test? } }
void DrawValue(Cairo.Context ctx, Gdk.GC gc, DateTime initialTime, int ytop, int lx, int tx, ref int ty, ref int maxx, ref int maxy, int indent, CounterValueInfo val) { Gdk.Color color; if (val.Counter != null) { color = val.Counter.GetColor(); } else { color = Style.Black; } // Draw text gc.RgbFgColor = color; double ms = (val.Time - initialTime).TotalMilliseconds; string txt = (ms / 1000).ToString("0.00000") + ": " + (val.Duration.TotalMilliseconds / 1000).ToString("0.00000") + " " + val.Trace; layout.SetText(txt); GdkWindow.DrawLayout(gc, tx + indent, ty, layout); int tw, th; layout.GetPixelSize(out tw, out th); if (tx + tw + indent > maxx) { maxx = tx + tw + indent; } HotSpot hp = AddHotSpot(tx + indent, ty, tw, th); int tempTy = ty; hp.Action = delegate { int ytm = ytop + (int)((ms * scale) / 1000); SetBaseTime((int)(tempTy + (th / 2) + 0.5) - ytm); }; hp.OnMouseOver += delegate { overValue = val; QueueDraw(); }; hp.Action += delegate { focusedValue = val; QueueDraw(); }; // Draw time marker int ytime = ytop + (int)((ms * scale) / 1000) + baseTime; if (val == focusedValue || val == overValue) { ctx.NewPath(); double dx = val == focusedValue ? 0 : 2; ctx.Rectangle(lx + 0.5 + dx - SelectedValuePadding, ytime + 0.5, LineEndWidth - dx * 2 + SelectedValuePadding, ((val.Duration.TotalMilliseconds * scale) / 1000)); HslColor hsl = color; hsl.L = val == focusedValue ? 0.9 : 0.8; ctx.SetSourceColor(hsl); ctx.Fill(); } ctx.NewPath(); ctx.LineWidth = 1; ctx.MoveTo(lx + 0.5, ytime + 0.5); ctx.LineTo(lx + LineEndWidth + 0.5, ytime + 0.5); ctx.LineTo(tx - 3 - LineEndWidth + 0.5, ty + (th / 2) + 0.5); ctx.LineTo(tx + indent - 3 + 0.5, ty + (th / 2) + 0.5); ctx.SetSourceColor(color.ToCairoColor()); ctx.Stroke(); // Expander bool incLine = true; if (val.CanExpand) { double ex = tx + indent - 3 - ExpanderSize - 2 + 0.5; double ey = ty + (th / 2) - (ExpanderSize / 2) + 0.5; hp = AddHotSpot(ex, ey, ExpanderSize, ExpanderSize); DrawExpander(ctx, ex, ey, val.Expanded, false); hp.OnMouseOver = delegate { using (Cairo.Context c = CairoHelper.Create(GdkWindow)) { DrawExpander(c, ex, ey, val.Expanded, true); } }; hp.OnMouseLeave = delegate { using (Cairo.Context c = CairoHelper.Create(GdkWindow)) { DrawExpander(c, ex, ey, val.Expanded, false); } }; hp.Action = delegate { ToggleExpand(val); }; if (val.Expanded && val.ExpandedTimerTraces.Count > 0) { ty += th + LineSpacing; foreach (CounterValueInfo cv in val.ExpandedTimerTraces) { DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, indent + ChildIndent, cv); } incLine = false; } } if (incLine) { ty += th + LineSpacing; } if (ytime > maxy) { maxy = ytime; } }
protected override bool OnExposeEvent(EventExpose evnt) { if (data == null) { BuildData(); } hostSpots.Clear(); int ytop = padding; int markerX = 3; int lx = markerX + MarkerWidth + 1; int tx = 250; int ty = ytop; int maxx = lx; int maxy = 0; DateTime initialTime = mainValue.TimeStamp; Cairo.Context ctx = CairoHelper.Create(GdkWindow); using (Gdk.GC gc = new Gdk.GC(GdkWindow)) { gc.RgbFgColor = Style.White; GdkWindow.DrawRectangle(gc, true, 0, 0, Allocation.Width, Allocation.Height); // Draw full time marker ctx.NewPath(); ctx.Rectangle(markerX, ytop + baseTime + 0.5, MarkerWidth / 2, ((mainValue.Duration.TotalMilliseconds * scale) / 1000)); HslColor hsl = Style.Foreground(Gtk.StateType.Normal); hsl.L = 0.8; ctx.SetSourceColor(hsl); ctx.Fill(); // Draw values foreach (CounterValueInfo val in data) { DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, 0, val); } if (ty > maxy) { maxy = ty; } int totalms = (int)mainValue.Duration.TotalMilliseconds; int marks = (totalms / 1000) + 1; ctx.LineWidth = 1; gc.RgbFgColor = Style.Foreground(Gtk.StateType.Normal); for (int n = 0; n <= marks; n++) { ctx.NewPath(); int y = ytop + (int)(n * scale) + baseTime; ctx.MoveTo(markerX, y + 0.5); ctx.LineTo(markerX + MarkerWidth, y + 0.5); ctx.SetSourceColor(Style.Foreground(Gtk.StateType.Normal).ToCairoColor()); ctx.Stroke(); y += 2; layout.SetText(n + "s"); GdkWindow.DrawLayout(gc, markerX + 1, y + 2, layout); int tw, th; layout.GetPixelSize(out tw, out th); y += th; if (y > maxy) { maxy = y; } } } ((IDisposable)ctx).Dispose(); maxy += padding; maxx += padding; if (lastHeight != maxy || lastWidth != maxx) { lastWidth = maxx; lastHeight = maxy; SetSizeRequest(maxx, maxy); } return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); using (Cairo.Context CairoContext = Gdk.CairoHelper.Create(this.GdkWindow)) { //Drawing code here. //Graph Background CairoContext.LineWidth = 1; CairoContext.SetSourceRGB(0.2, 0.2, 0.2); CairoContext.Rectangle(this.graphRect); CairoContext.StrokePreserve(); CairoContext.SetSourceRGB(1, 1, 1); CairoContext.Fill(); if (this.data.Length <= 0) { return(true); } double Min = double.MaxValue; double Max = double.MinValue; foreach (float FloatItem in this.data) { if (FloatItem > Max) { Max = FloatItem; } if (FloatItem < Min) { Min = FloatItem; } } //XScale int XStep = 100 - ((int)(Min - Max) / 100); XStep = Math.Max(XStep, 1); for (int X = 0; X < this.scaleRectX.Width; X += XStep) { CairoContext.MoveTo(this.scaleRectX.X + X, this.scaleRectX.Y); CairoContext.LineTo(this.scaleRectX.X + X, this.scaleRectX.Y + this.scaleRectX.Height); } //YScale int YStep = 100 - (this.data.Length / 100); YStep = Math.Max(YStep, 1); for (int Y = 0; Y < this.scaleRectY.Height; Y += YStep) { CairoContext.MoveTo(this.scaleRectY.X, this.scaleRectY.Y + Y); CairoContext.LineTo(this.scaleRectY.X + this.scaleRectY.Width, this.scaleRectY.Y + Y); } //Graph Line CairoContext.LineWidth = 2; Cairo.Point LastValue = new Cairo.Point(0, 0); CairoContext.SetSourceRGB(0.5, 0.5, 0.5); for (int i = 0; i < this.data.Length; i++) { double X = this.graphRect.X + Scale(i, 0, (double)this.data.Length, 4d, (double)this.graphRect.Width - 8d); double Y = this.graphRect.Y + Scale(this.data[i], Min, Max, (double)this.graphRect.Height - 8d, 4d); if (LastValue.X != 0 && LastValue.Y != 0) { CairoContext.MoveTo(X, Y); CairoContext.LineTo(LastValue.X, LastValue.Y); } LastValue.X = (int)X; LastValue.Y = (int)Y; } CairoContext.Stroke(); } return(true); }
/// <summary> /// Draws the Axis and other componets of the chart /// </summary> /// <param name="height">Height of drawing area.</param> /// <param name="width">Width of drawing area.</param> /// <param name="canvas">The cairo context.</param> void DrawAxis(int height, int width, Cairo.Context canvas) { Char[] VALUE = this.ValueLabel.ToCharArray(); //Draws the Legend of the chart DrawLegendAndTitle(height, width, canvas); canvas.SetSourceRGB(0, 0, 0); //Set the Axis labels canvas.MoveTo(XStart, Padding + 15); canvas.ShowText(Encoding.UTF8.GetBytes(VALUE)); canvas.Stroke(); //Create the Axis with the markers canvas.LineWidth = 4; canvas.MoveTo(XStart, YStart); canvas.LineTo(XStart, YEnd); canvas.LineTo(XEnd, YEnd); canvas.Stroke(); // .... creates de Y markers double totalHeigth = (YEnd - YStart); double intervalHeight = totalHeigth / ValueResolution; for (double i = 0; i <= ValueResolution; i++) { canvas.LineWidth = 0.5; canvas.SetSourceRGB(0, 0, 0); string value = (((MinValue * PixelsPerUnit) + ((((MaxValue * PixelsPerUnit) - (MinValue * PixelsPerUnit)) / ValueResolution) * (ValueResolution - i))) / PixelsPerUnit).ToString(); canvas.MoveTo(XStart - ((value.Length + 1) * widthByChar), YStart + i * intervalHeight); canvas.ShowText(Encoding.UTF8.GetBytes(value)); canvas.MoveTo(XStart - lenghtLineValue, YStart + i * intervalHeight); canvas.LineTo((!ShowGridLines) ? XStart : XEnd, YStart + i * intervalHeight); canvas.Stroke(); } // .... creates de X markers //If dont exist Custom Data Set, Default set wil be Draw. Boolean drawSetDefault = (GetSetCount() == 0); double totalWidth = (XEnd - XStart); if (drawSetDefault) { int numBars = data["Default"].Count; int actualBar = 0; double maxWidthPerBar = (totalWidth - PaddingSets * 2) / (double)(numBars); foreach (BarData bd in data["Default"]) { canvas.LineWidth = 0.5; canvas.SetSourceRGB(0, 0, 0); string value = bd.Name; canvas.MoveTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar / 2) - ((value.Length * PixelsPerUnit) / 2), YEnd + 15); canvas.ShowText(Encoding.UTF8.GetBytes(value)); canvas.MoveTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar), YEnd + lenghtLineValue); canvas.LineTo(XStart + PaddingSets + (actualBar * maxWidthPerBar) + (maxWidthPerBar), YEnd); canvas.Stroke(); actualBar++; } return; } int Sets = GetSetCount(); double maxWidthPerSet = (totalWidth / (double)Sets); int actualSet = 0; foreach (String key in GetSetIds()) { if (key.Equals("Default")) { continue; } int numBars = data[key].Count; double XSetStart = XStart + maxWidthPerSet * actualSet; double XSetEnd = XSetStart + maxWidthPerSet; canvas.LineWidth = 0.5; canvas.SetSourceRGB(0, 0, 0); string value = key; canvas.MoveTo(XSetStart + maxWidthPerSet / 2, YEnd + 15); canvas.ShowText(Encoding.UTF8.GetBytes(value)); canvas.MoveTo(XSetEnd, YEnd + lenghtLineValue); canvas.LineTo(XSetEnd, YEnd); canvas.Stroke(); actualSet++; } }
protected override bool OnExposeEvent(EventExpose evnt) { base.OnExposeEvent(evnt); Cairo.Context e = CairoHelper.Create(evnt.Window); // DateTime dateTime = this.datetime; float fRadHr = (dateTime.Hour % 12 + dateTime.Minute / 60F) * 30 * PI / 180; float fRadMin = (dateTime.Minute) * 6 * PI / 180; float fRadSec = (dateTime.Second) * 6 * PI / 180; Cairo.PointD center = new Cairo.PointD(fCenterX, fCenterY); DrawLine(this.fHourTickness, this.fHourLength, hrColor, fRadHr, e); DrawLine(this.fMinTickness, this.fMinLength, minColor, fRadMin, e); DrawLine(this.fSecTickness, this.fSecLength, secColor, fRadSec, e); for (int i = 0; i < 60; i++) { if (this.bDraw5MinuteTicks == true && i % 5 == 0) // Draw 5 minute ticks { e.LineWidth = fTicksThickness; e.Color = ticksColor; Cairo.PointD p1 = new Cairo.PointD( fCenterX + (double)(this.fRadius / 1.50F * System.Math.Sin(i * 6 * PI / 180)), fCenterY - (double)(this.fRadius / 1.50F * System.Math.Cos(i * 6 * PI / 180))); Cairo.PointD p2 = new Cairo.PointD( fCenterX + (double)(this.fRadius / 1.65F * System.Math.Sin(i * 6 * PI / 180)), fCenterY - (double)(this.fRadius / 1.65F * System.Math.Cos(i * 6 * PI / 180))); e.MoveTo(p1); e.LineTo(p2); e.ClosePath(); e.Stroke(); } else if (this.bDraw1MinuteTicks == true) // draw 1 minute ticks { e.LineWidth = fTicksThickness; e.Color = ticksColor; Cairo.PointD p1 = new Cairo.PointD ( fCenterX + (double)(this.fRadius / 1.50F * System.Math.Sin(i * 6 * PI / 180)), fCenterY - (double)(this.fRadius / 1.50F * System.Math.Cos(i * 6 * PI / 180)) ); Cairo.PointD p2 = new Cairo.PointD ( fCenterX + (double)(this.fRadius / 1.55F * System.Math.Sin(i * 6 * PI / 180)), fCenterY - (double)(this.fRadius / 1.55F * System.Math.Cos(i * 6 * PI / 180)) ); e.MoveTo(p1); e.LineTo(p2); e.ClosePath(); e.Stroke(); } } DrawCenterFilledCircle(center, (fRadius / 2) + 17, e); DrawCenterFilledCircle(center, 8, e); ((IDisposable)e.Target).Dispose(); ((IDisposable)e).Dispose(); // return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.Color = new Cairo.Color(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int w = 0, w2 = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.Color = new Cairo.Color(1, 1, 1); cr.Fill(); } layout.SetText(ann.Author); layout.GetPixelSize(out w, out h); e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); layout.SetText(TruncRevision(ann.Revision)); layout.GetPixelSize(out w2, out h); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - w2 - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); int middle = w + (Allocation.Width - margin * 2 - leftSpacer - w - w2) / 2; layout.SetText(dateTime); layout.GetPixelSize(out w, out h); e.Window.DrawLayout(Style.BlackGC, leftSpacer + margin + middle - w / 2, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart); if (!string.IsNullOrEmpty(msg)) { msg = FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.Color = color; } else { cr.Color = ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.Color = new Cairo.Color(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) { if (Debugger.DebuggingService.IsDebugging) { return; } int markerStart = Segment.Offset; int markerEnd = Segment.EndOffset; if (markerEnd < startOffset || markerStart > endOffset) { return; } bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut; if (drawOverlay && editor.IsSomethingSelected) { var selectionRange = editor.SelectionRange; if (selectionRange.Contains(markerStart) && selectionRange.Contains(markerEnd)) { return; } if (selectionRange.Contains(markerEnd)) { markerEnd = selectionRange.Offset; } if (selectionRange.Contains(markerStart)) { markerStart = selectionRange.EndOffset; } if (markerEnd <= markerStart) { return; } } double drawFrom; double drawTo; if (markerStart < startOffset && endOffset < markerEnd) { drawFrom = startXPos; drawTo = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; int /*lineNr,*/ x_pos; x_pos = layout.IndexToPos(start - startOffset).X; drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale); x_pos = layout.IndexToPos(end - startOffset).X; drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } drawFrom = System.Math.Max(drawFrom, editor.TextViewMargin.XOffset); drawTo = System.Math.Max(drawTo, editor.TextViewMargin.XOffset); if (drawFrom >= drawTo) { return; } double height = editor.LineHeight / 5; cr.SetSourceColor(GetColor(editor, Result)); if (drawOverlay) { cr.Rectangle(drawFrom, y, drawTo - drawFrom, editor.LineHeight); var color = editor.ColorStyle.PlainText.Background; color.A = 0.6; cr.SetSourceColor(color); cr.Fill(); } else if (result.InspectionMark == IssueMarker.WavedLine) { Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height); } else if (result.InspectionMark == IssueMarker.DottedLine) { cr.Save(); cr.LineWidth = 1; cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5); cr.RelLineTo(System.Math.Min(drawTo - drawFrom, 4 * 3), 0); cr.SetDash(new double[] { 2, 2 }, 0); cr.Stroke(); cr.Restore(); } else { cr.MoveTo(drawFrom, y + editor.LineHeight - 1); cr.LineTo(drawTo, y + editor.LineHeight - 1); cr.Stroke(); } }
public static void DrawRoundRectangle(Cairo.Context cr, bool topLeftRound, bool topRightRound, bool bottomLeftRound, bool bottomRightRound, double x, double y, double r, double w, double h) { // UA****BQ // H C // * * // G D // TF****ES cr.NewPath(); if (topLeftRound) { cr.MoveTo(x + r, y); // Move to A } else { cr.MoveTo(x, y); // Move to U } if (topRightRound) { cr.LineTo(x + w - r, y); // Straight line to B cr.CurveTo(x + w, y, x + w, y, x + w, y + r); // Curve to C, Control points are both at Q } else { cr.LineTo(x + w, y); // Straight line to Q } if (bottomRightRound) { cr.LineTo(x + w, y + h - r); // Move to D cr.CurveTo(x + w, y + h, x + w, y + h, x + w - r, y + h); // Curve to E } else { cr.LineTo(x + w, y + h); // Move to S } if (bottomLeftRound) { cr.LineTo(x + r, y + h); // Line to F cr.CurveTo(x, y + h, x, y + h, x, y + h - r); // Curve to G } else { cr.LineTo(x, y + h); // Line to T } if (topLeftRound) { cr.LineTo(x, y + r); // Line to H cr.CurveTo(x, y, x, y, x + r, y); // Curve to A } else { cr.LineTo(x, y); // Line to U } cr.ClosePath(); }
public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics layout, int startOffset, int endOffset) { if (DebuggingService.IsDebugging) { return; } int markerStart = Segment.Offset; int markerEnd = Segment.EndOffset; if (markerEnd < startOffset || markerStart > endOffset) { return; } double drawFrom; double drawTo; double y = layout.LineYRenderStartPosition; double startXPos = layout.TextRenderStartPosition; double endXPos = layout.TextRenderEndPosition; if (markerStart < startOffset && endOffset < markerEnd) { drawTo = endXPos; var line = editor.GetLineByOffset(startOffset); int offset = line.GetIndentation(editor.Document).Length; drawFrom = startXPos + (layout.Layout.IndexToPos(offset).X / Pango.Scale.PangoScale); } else { int start; if (startOffset < markerStart) { start = markerStart; } else { var line = editor.GetLineByOffset(startOffset); int offset = line.GetIndentation(editor.Document).Length; start = startOffset + offset; } int end = endOffset < markerEnd ? endOffset : markerEnd; int x_pos; x_pos = layout.Layout.IndexToPos(start - startOffset).X; drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale); x_pos = layout.Layout.IndexToPos(end - startOffset).X; drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } drawFrom = Math.Max(drawFrom, editor.TextViewMargin.XOffset); drawTo = Math.Max(drawTo, editor.TextViewMargin.XOffset); if (drawFrom >= drawTo) { return; } double height = editor.LineHeight / 5; cr.SetSourceColor(color); if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine) { Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height); } else if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine) { cr.Save(); cr.LineWidth = 1; cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5); cr.RelLineTo(Math.Min(drawTo - drawFrom, 4 * 3), 0); cr.SetDash(new double[] { 2, 2 }, 0); cr.Stroke(); cr.Restore(); } else { cr.MoveTo(drawFrom, y + editor.LineHeight - 1); cr.LineTo(drawTo, y + editor.LineHeight - 1); cr.Stroke(); } }
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 lineSegment.Markers) { var marginMarker = marker as MarginMarker; if (marginMarker != null && marginMarker.CanDrawBackground(this)) { backgroundIsDrawn = marginMarker.DrawBackground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } #pragma warning disable 618 var iconMarker = marker as IIconBarMarker; if (iconMarker == null || !iconMarker.CanDrawBackground) { continue; } iconMarker.DrawBackground(editor, ctx, lineSegment, line, x, y, (int)Width, editor.LineHeight); backgroundIsDrawn = true; break; #pragma warning restore 618 } } if (!backgroundIsDrawn) { ctx.Rectangle(x, y, Width, lineHeight); ctx.SetSourceColor(backgroundColor); ctx.Fill(); ctx.MoveTo(x + Width - 0.5, y); ctx.LineTo(x + Width - 0.5, y + lineHeight); ctx.SetSourceColor(separatorColor); ctx.Stroke(); } if (lineSegment != null && line <= editor.Document.LineCount) { foreach (var marker in lineSegment.Markers) { var marginMarker = marker as MarginMarker; if (marginMarker != null && marginMarker.CanDrawForeground(this)) { marginMarker.DrawForeground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight)); } #pragma warning disable 618 if (marker is IIconBarMarker) { ((IIconBarMarker)marker).DrawIcon(editor, ctx, lineSegment, line, x, y, (int)Width, editor.LineHeight); } #pragma warning restore 618 } if (DrawEvent != null) { DrawEvent(this, new BookmarkMarginDrawEventArgs(editor, ctx, lineSegment, line, x, y)); } } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Cairo.Context cr = Gdk.CairoHelper.Create(e.Window); Gdk.Rectangle area = e.Area; if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage)) { Pango.Layout messageLayout = new Pango.Layout(this.PangoContext); messageLayout.Alignment = Pango.Alignment.Center; messageLayout.Width = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale); if (!string.IsNullOrEmpty(CustomMessage)) { messageLayout.SetText(CustomMessage); } else { messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document.")); } cr.MoveTo(Allocation.Width * 1 / 6, 12); cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); Pango.CairoHelper.ShowLayout(cr, messageLayout); messageLayout.Dispose(); ((IDisposable)cr).Dispose(); return(true); } var backColor = Style.Base(StateType.Normal).ToCairoColor(); cr.SetSourceColor(backColor); cr.Rectangle(area.X, area.Y, area.Width, area.Height); cr.Fill(); int xpos = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0); int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0); int ypos = -vadjustment; Category lastCategory = null; int lastCategoryYpos = 0; Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) { const int foldSegmentHeight = 8; ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) { pat.AddColorStop(0, CategoryBackgroundGradientStartColor); pat.AddColorStop(1, CategoryBackgroundGradientEndColor); cr.SetSource(pat); cr.Fill(); } if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand) { cr.MoveTo(xpos, ypos + 0.5); cr.LineTo(itemDimension.Width, ypos + 0.5); } cr.MoveTo(0, ypos + itemDimension.Height - 0.5); cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5); cr.SetSourceColor(CategoryBorderColor); cr.LineWidth = 1; cr.Stroke(); headerLayout.SetText(category.Text); int width, height; cr.SetSourceColor(CategoryLabelColor); layout.GetPixelSize(out width, out height); cr.MoveTo(xpos + CategoryLeftPadding, ypos + (itemDimension.Height - height) / 2); Pango.CairoHelper.ShowLayout(cr, headerLayout); var img = category.IsExpanded ? discloseUp : discloseDown; Gdk.CairoHelper.SetSourcePixbuf(cr, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + (itemDimension.Height - img.Height) / 2); cr.Paint(); lastCategory = category; lastCategoryYpos = ypos + itemDimension.Height; }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) { if (item == SelectedItem) { cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.Fill(); } if (listMode || !curCategory.CanIconizeItems) { Gdk.CairoHelper.SetSourcePixbuf(cr, item.Icon, xpos + ItemLeftPadding, ypos + (itemDimension.Height - item.Icon.Height) / 2); cr.Paint(); layout.SetText(item.Text); int width, height; layout.GetPixelSize(out width, out height); cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor()); cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (itemDimension.Height - height) / 2); Pango.CairoHelper.ShowLayout(cr, layout); } else { Gdk.CairoHelper.SetSourcePixbuf(cr, item.Icon, xpos + (itemDimension.Width - item.Icon.Width) / 2, ypos + (itemDimension.Height - item.Icon.Height) / 2); cr.Paint(); } if (item == mouseOverItem) { cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor()); cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1); cr.Stroke(); } }); ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (lastCategory != null && lastCategory.AnimatingExpand) { // Closing line when animating the last group of the toolbox cr.MoveTo(area.X, ypos + 0.5); cr.RelLineTo(area.Width, 0); cr.SetSourceColor(CategoryBorderColor); cr.Stroke(); } ((IDisposable)cr).Dispose(); return(true); }
/// <summary> /// Draws the Axis and other componets of the chart /// </summary> /// <param name="height">Height of drawing area.</param> /// <param name="width">Width of drawing area.</param> /// <param name="canvas">The cairo context.</param> void DrawAxis(int height, int width, Cairo.Context canvas) { Char[] Y = this.YLabel.ToCharArray(); Char[] X = this.XLabel.ToCharArray(); //Draws the Legend of the chart DrawLegendAndTitle(height, width, canvas); canvas.SetSourceRGB(0, 0, 0); //Set the Axis labels canvas.MoveTo(XStart, Padding + 15); canvas.ShowText(Encoding.UTF8.GetBytes(Y)); canvas.Stroke(); //canvas.MoveTo(width - (Padding + (X.Length * widthByChar)), height - Padding); canvas.MoveTo(width - (Padding + (X.Length * widthByChar)), YEnd + 30); canvas.ShowText(Encoding.UTF8.GetBytes(X)); canvas.Stroke(); //Create the Axis X and Y with the markers canvas.LineWidth = 4; canvas.MoveTo(XStart, YStart); canvas.LineTo(XStart, YEnd); canvas.LineTo(XEnd, YEnd); canvas.Stroke(); // .... creates de Y markers double totalHeigth = (YEnd - YStart); double intervalHeight = totalHeigth / YResolution; for (double i = 0; i <= YResolution; i++) { canvas.LineWidth = 0.5; canvas.SetSourceRGB(0, 0, 0); string value = (((MinYValue * PixelsPerUnit) + ((((MaxYValue * PixelsPerUnit) - (MinYValue * PixelsPerUnit)) / YResolution) * (YResolution - i))) / PixelsPerUnit).ToString(); canvas.MoveTo(XStart - ((value.Length + 1) * widthByChar), YStart + i * intervalHeight); canvas.ShowText(Encoding.UTF8.GetBytes(value)); canvas.MoveTo(XStart - lenghtLineValue, YStart + i * intervalHeight); canvas.LineTo((!ShowGridLines) ? XStart : XEnd, YStart + i * intervalHeight); canvas.Stroke(); } // .... creates de X markers double totalWidth = (XEnd - XStart); double intervalWidth = totalWidth / XResolution; for (double i = 0; i <= XResolution; i++) { canvas.LineWidth = 0.5; canvas.SetSourceRGB(0, 0, 0); string value = (((MinXValue * PixelsPerUnit) + ((((MaxXValue * PixelsPerUnit) - (MinXValue * PixelsPerUnit)) / XResolution) * i)) / PixelsPerUnit).ToString(); canvas.MoveTo(XStart + i * intervalWidth - ((value.Length * PixelsPerUnit) / 2), YEnd + 15); canvas.ShowText(Encoding.UTF8.GetBytes(value)); canvas.MoveTo(XStart + i * intervalWidth, YEnd + lenghtLineValue); canvas.LineTo(XStart + i * intervalWidth, (!ShowGridLines) ? YEnd : YStart); canvas.Stroke(); } canvas.SetSourceRGB(0, 0, 0); }
public bool DrawBackground(TextEditor editor, Cairo.Context g, TextViewMargin.LayoutWrapper layout2, int selectionStart, int selectionEnd, int startOffset, int endOffset, double y, double startXPos, double endXPos, ref bool drawBg) { if (!IsVisible || DebuggingService.IsDebugging) { return(true); } EnsureLayoutCreated(editor); double x = editor.TextViewMargin.XOffset; int right = editor.Allocation.Width; bool isCaretInLine = startOffset <= editor.Caret.Offset && editor.Caret.Offset <= endOffset; var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout2.PangoWidth / Pango.Scale.PangoScale; int errorCounterWidth = GetErrorCountBounds(layout2).Item1; // int eh = GetErrorCountBounds ().Item2; double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains(lineSegment.Offset + lineSegment.EditableLength) : false; int active = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1; int highlighted = active == 0 && isCaretInLine ? 1 : 0; int selected = 0; double topSize = Math.Floor(editor.LineHeight / 2); double bottomSize = editor.LineHeight / 2 + editor.LineHeight % 2; if (!fitsInSameLine) { if (isEolSelected) { x -= (int)editor.HAdjustment.Value; editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, editor.TextViewMargin.TextStartPosition, editor.LineHeight), editor.ColorStyle.Default.CairoBackgroundColor, true); editor.TextViewMargin.DrawRectangleWithRuler(g, x + editor.TextViewMargin.TextStartPosition, new Cairo.Rectangle(x + editor.TextViewMargin.TextStartPosition, y + editor.LineHeight, editor.Allocation.Width + (int)editor.HAdjustment.Value, editor.LineHeight), editor.ColorStyle.Selection.CairoBackgroundColor, true); x += (int)editor.HAdjustment.Value; } else { editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y + editor.LineHeight, x2, editor.LineHeight), editor.ColorStyle.Default.CairoBackgroundColor, true); } } DrawRectangle(g, x, y, right, topSize); g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected]; g.Fill(); DrawRectangle(g, x, y + topSize, right, bottomSize); g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]; g.Fill(); g.MoveTo(new Cairo.PointD(x, y + 0.5)); g.LineTo(new Cairo.PointD(x + right, y + 0.5)); g.Color = colorMatrix [active, TOP, LINE, highlighted, selected]; g.Stroke(); g.MoveTo(new Cairo.PointD(x, y + editor.LineHeight - 0.5)); g.LineTo(new Cairo.PointD((fitsInSameLine ? x + right : x2 + 1), y + editor.LineHeight - 0.5)); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke(); if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); g.MoveTo(new Cairo.PointD(divider + 0.5, y)); g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight)); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke(); } // draw background if (layout2.StartSet || selectionStart == endOffset) { double startX; double endX; if (selectionStart != endOffset) { var start = layout2.Layout.IndexToPos((int)layout2.SelectionStartIndex); startX = (int)(start.X / Pango.Scale.PangoScale); var end = layout2.Layout.IndexToPos((int)layout2.SelectionEndIndex); endX = (int)(end.X / Pango.Scale.PangoScale); } else { startX = x2; endX = startX; } if (editor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) { endX = startX + 2; } startX += startXPos; endX += startXPos; startX = Math.Max(editor.TextViewMargin.XOffset, startX); // clip region to textviewmargin start if (isEolSelected) { endX = editor.Allocation.Width + (int)editor.HAdjustment.Value; } if (startX < endX) { DrawRectangle(g, startX, y, endX - startX, topSize); g.Color = colorMatrix [active, TOP, LIGHT, highlighted, 1]; g.Fill(); DrawRectangle(g, startX, y + topSize, endX - startX, bottomSize); g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1]; g.Fill(); g.MoveTo(new Cairo.PointD(startX, y + 0.5)); g.LineTo(new Cairo.PointD(endX, y + 0.5)); g.Color = colorMatrix [active, TOP, LINE, highlighted, 1]; g.Stroke(); if (startX < x2) { g.MoveTo(new Cairo.PointD(startX, y + editor.LineHeight - 0.5)); g.LineTo(new Cairo.PointD(System.Math.Min(endX, x2 + 1), y + editor.LineHeight - 0.5)); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1]; g.Stroke(); if (x2 + 1 < endX) { g.MoveTo(new Cairo.PointD(x2 + 1, y + editor.LineHeight - 0.5)); g.LineTo(new Cairo.PointD(endX, y + editor.LineHeight - 0.5)); g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, 1]; g.Stroke(); } } if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); g.MoveTo(new Cairo.PointD(divider + 0.5, y)); g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight)); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, 1]; g.Stroke(); } } } if (!fitsInSameLine) { y += editor.LineHeight; } double y2 = y + 0.5; double y2Bottom = y2 + editor.LineHeight - 1; selected = isEolSelected && (CollapseExtendedErrors) ? 1 : 0; if (x2 < lineTextPx) { x2 = lineTextPx; } // draw message text background if (CollapseExtendedErrors) { if (!fitsInSameLine) { // draw box below line g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2 - 1)); g.ClosePath(); g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]; g.Fill(); g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke(); } else { // draw 'arrow marker' in the same line if (errors.Count > 1) { g.MoveTo(new Cairo.PointD(x2 + 0.5, y2)); double mid = y2 + topSize; g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid)); g.LineTo(new Cairo.PointD(right, mid)); g.LineTo(new Cairo.PointD(right, y2)); g.ClosePath(); g.Color = colorMatrix [active, TOP, DARK, highlighted, selected]; g.Fill(); g.MoveTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, mid)); g.LineTo(new Cairo.PointD(right, mid)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.ClosePath(); g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; g.Fill(); } // draw border g.MoveTo(new Cairo.PointD(x2 + 0.5, y2)); g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2)); g.ClosePath(); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke(); } } else { if (!fitsInSameLine) { // draw box below line g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2 - 1)); g.ClosePath(); } else { // draw filled arrow box if (!(errors.Count == 1 && !CollapseExtendedErrors)) { g.MoveTo(new Cairo.PointD(x2 + 0.5, y2)); g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2Bottom)); g.LineTo(new Cairo.PointD(right, y2)); g.ClosePath(); } } g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]; g.Fill(); // draw light bottom line g.MoveTo(new Cairo.PointD(right, y2Bottom)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); g.Stroke(); // stroke left line if (fitsInSameLine) { g.MoveTo(new Cairo.PointD(x2 + 0.5, y2)); g.LineTo(new Cairo.PointD(x2 - editor.LineHeight / 2 + 0.5, y2 + editor.LineHeight / 2)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom)); } else { g.MoveTo(new Cairo.PointD(x2 + 0.5, y2 - 1)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2Bottom + 1)); } g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.Stroke(); // stroke top line if (fitsInSameLine) { g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.MoveTo(new Cairo.PointD(right, y2)); g.LineTo(new Cairo.PointD(x2 + 0.5, y2)); g.Stroke(); } } if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); if (divider >= x2) { g.MoveTo(new Cairo.PointD(divider + 0.5, y2)); g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom)); g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; g.Stroke(); } } for (int i = 0; i < layouts.Count; i++) { if (!IsCurrentErrorTextFitting(layout2) && !CollapseExtendedErrors) { break; } var layout = layouts [i]; x2 = right - layout.Width - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0); if (i == 0) { x2 -= errorCounterWidth; if (x2 < lineTextPx) { // if (CollapseExtendedErrors) { x2 = lineTextPx; // } } } // x2 = System.Math.Max (x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); if (i > 0) { editor.TextViewMargin.DrawRectangleWithRuler(g, x, new Cairo.Rectangle(x, y, right, editor.LineHeight), isEolSelected ? editor.ColorStyle.Selection.CairoBackgroundColor : editor.ColorStyle.Default.CairoBackgroundColor, true); g.MoveTo(new Cairo.PointD(x2 + 0.5, y)); g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight)); g.LineTo(new Cairo.PointD(right, y + editor.LineHeight)); g.LineTo(new Cairo.PointD(right, y)); g.ClosePath(); if (CollapseExtendedErrors) { using (var pat = new Cairo.LinearGradient(x2, y, x2, y + editor.LineHeight)) { pat.AddColorStop(0, colorMatrix [active, TOP, LIGHT, highlighted, selected]); pat.AddColorStop(1, colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]); g.Pattern = pat; } } else { g.Color = colorMatrix [active, TOP, LIGHT, highlighted, selected]; } g.Fill(); if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); if (divider >= x2) { g.MoveTo(new Cairo.PointD(divider + 0.5, y)); g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight)); g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; g.Stroke(); } } } g.Color = (HslColor)(selected == 0 ? gc : cache.gcSelected); g.Save(); g.Translate(x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2); g.ShowLayout(layout.Layout); g.Restore(); y += editor.LineHeight; if (!UseVirtualLines) { break; } } return(true); }
protected void DrawQuickTasks(Cairo.Context cr, IEnumerator <Usage> allUsages, IEnumerator <QuickTask> allTasks, ref bool nextStep, ref DiagnosticSeverity severity, List <HashSet <int> > lineCache) { if (allUsages.MoveNext()) { var usage = allUsages.Current; int y = (int)GetYPosition(TextEditor.OffsetToLineNumber(usage.Offset)); if (lineCache[0].Contains(y)) { return; } lineCache[0].Add(y); var usageColor = TextEditor.ColorStyle.PlainText.Foreground; usageColor.A = 0.4; HslColor color; if ((usage.UsageType & MonoDevelop.Ide.FindInFiles.ReferenceUsageType.Declariton) != 0) { color = TextEditor.ColorStyle.ChangingUsagesRectangle.Color; } else if ((usage.UsageType & MonoDevelop.Ide.FindInFiles.ReferenceUsageType.Write) != 0) { color = TextEditor.ColorStyle.ChangingUsagesRectangle.Color; } else if ((usage.UsageType & MonoDevelop.Ide.FindInFiles.ReferenceUsageType.Read) != 0) { color = TextEditor.ColorStyle.UsagesRectangle.Color; } else { color = usageColor; } color.L = 0.5; cr.SetSourceColor(color); cr.MoveTo(0, y - 3); cr.LineTo(5, y); cr.LineTo(0, y + 3); cr.LineTo(0, y - 3); cr.ClosePath(); cr.Fill(); } else if (allTasks.MoveNext()) { var task = allTasks.Current; int y = (int)GetYPosition(TextEditor.OffsetToLineNumber(task.Location)); if (!lineCache[1].Contains(y)) { lineCache[1].Add(y); cr.SetSourceColor(GetBarColor(task.Severity)); cr.Rectangle(1, y - 1, Allocation.Width - 1, 2); cr.Fill(); } if (task.Severity == DiagnosticSeverity.Error) { severity = DiagnosticSeverity.Error; } else if (task.Severity == DiagnosticSeverity.Warning && severity != DiagnosticSeverity.Error) { severity = DiagnosticSeverity.Warning; } } else { nextStep = true; } }
public void Draw(TextEditor editor, Cairo.Context g, int lineNr, Cairo.Rectangle lineArea) { EnsureLayoutCreated(editor); int lineNumber = editor.Document.OffsetToLineNumber(lineSegment.Offset); int errorNumber = lineNr - lineNumber; if (!IsCurrentErrorTextFitting()) { errorNumber--; } double x = editor.TextViewMargin.XOffset; double y = lineArea.Y; double right = editor.Allocation.Width; int errorCounterWidth = GetErrorCountBounds().Item1; // int eh = GetErrorCountBounds ().Item2; double x2 = System.Math.Max(right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); if (errors.Count == 1) { x2 = editor.TextViewMargin.XOffset; } // bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset + lineSegment.EditableLength) : false; int active = editor.Document.GetTextAt(lineSegment) == initialText ? 0 : 1; bool isCaretInLine = lineSegment.Offset <= editor.Caret.Offset && editor.Caret.Offset <= lineSegment.EndOffset; int highlighted = active == 0 && isCaretInLine ? 1 : 0; int selected = 0; var layout = layouts [errorNumber]; x2 = right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0); x2 -= errorCounterWidth; x2 = System.Math.Max(x2, fitsInSameLine ? editor.TextViewMargin.XOffset + editor.LineHeight / 2 : editor.TextViewMargin.XOffset); g.MoveTo(new Cairo.PointD(x2 + 0.5, y)); g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight)); g.LineTo(new Cairo.PointD(right, y + editor.LineHeight)); g.LineTo(new Cairo.PointD(right, y)); g.ClosePath(); g.Color = colorMatrix [active, BOTTOM, LIGHT, highlighted, selected]; g.Fill(); g.Color = colorMatrix [active, BOTTOM, LINE, highlighted, selected]; g.MoveTo(new Cairo.PointD(x2 + 0.5, y)); g.LineTo(new Cairo.PointD(x2 + 0.5, y + editor.LineHeight)); if (errorNumber == errors.Count - 1) { g.LineTo(new Cairo.PointD(lineArea.X + lineArea.Width, y + editor.LineHeight)); } g.Stroke(); if (editor.Options.ShowRuler) { double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX); if (divider >= x2) { g.MoveTo(new Cairo.PointD(divider + 0.5, y)); g.LineTo(new Cairo.PointD(divider + 0.5, y + editor.LineHeight)); g.Color = colorMatrix [active, BOTTOM, DARK, highlighted, selected]; g.Stroke(); } } g.Save(); g.Translate(x2 + (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) + border, y + (editor.LineHeight - layout.Height) / 2 + layout.Height % 2); g.Color = selected == 0 ? gc : cache.gcSelected; g.ShowLayout(layout.Layout); g.Restore(); // if (ShowIconsInBubble) // win.DrawPixbuf (editor.Style.BaseGC (Gtk.StateType.Normal), errors[errorNumber].IsError ? errorPixbuf : warningPixbuf, 0, 0, x2, y + (editor.LineHeight - errorPixbuf.Height) / 2, errorPixbuf.Width, errorPixbuf.Height, Gdk.RgbDither.None, 0, 0); }
protected override bool OnExposeEvent(EventExpose evnt) { bool hideButton = widget.MainEditor.Document.ReadOnly; using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.Clip(); int delta = widget.MainEditor.Allocation.Y - Allocation.Y; if (Diff != null) { foreach (Hunk hunk in Diff) { double z1 = delta + fromEditor.LineToY(hunk.RemoveStart) - fromEditor.VAdjustment.Value; double z2 = delta + fromEditor.LineToY(hunk.RemoveStart + hunk.Removed) - fromEditor.VAdjustment.Value; if (z1 == z2) { z2 = z1 + 1; } double y1 = delta + toEditor.LineToY(hunk.InsertStart) - toEditor.VAdjustment.Value; double y2 = delta + toEditor.LineToY(hunk.InsertStart + hunk.Inserted) - toEditor.VAdjustment.Value; if (y1 == y2) { y2 = y1 + 1; } if (!useLeft) { var tmp = z1; z1 = y1; y1 = tmp; tmp = z2; z2 = y2; y2 = tmp; } int x1 = 0; int x2 = Allocation.Width; if (!hideButton) { if (useLeft && hunk.Removed > 0 || !useLeft && hunk.Removed == 0) { x1 += 16; } else { x2 -= 16; } } if (z1 == z2) { z2 = z1 + 1; } cr.MoveTo(x1, z1); cr.CurveTo(x1 + (x2 - x1) / 4, z1, x1 + (x2 - x1) * 3 / 4, y1, x2, y1); cr.LineTo(x2, y2); cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2, x1 + (x2 - x1) / 4, z2, x1, z2); cr.ClosePath(); cr.SetSourceColor(GetColor(hunk, this.useLeft, false, 1.0)); cr.Fill(); cr.SetSourceColor(GetColor(hunk, this.useLeft, true, 1.0)); cr.MoveTo(x1, z1); cr.CurveTo(x1 + (x2 - x1) / 4, z1, x1 + (x2 - x1) * 3 / 4, y1, x2, y1); cr.Stroke(); cr.MoveTo(x2, y2); cr.CurveTo(x1 + (x2 - x1) * 3 / 4, y2, x1 + (x2 - x1) / 4, z2, x1, z2); cr.Stroke(); if (!hideButton) { bool isButtonSelected = hunk == selectedHunk; double x, y, w, h; bool drawArrow = useLeft ? GetButtonPosition(hunk, y1, y2, z1, z2, out x, out y, out w, out h) : GetButtonPosition(hunk, z1, z2, y1, y2, out x, out y, out w, out h); cr.Rectangle(x, y, w, h); if (isButtonSelected) { int mx, my; GetPointer(out mx, out my); // mx -= (int)x; // my -= (int)y; using (var gradient = new Cairo.RadialGradient(mx, my, h, mx, my, 2)) { var color = (MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal); color.L *= 1.05; gradient.AddColorStop(0, color); color.L *= 1.07; gradient.AddColorStop(1, color); cr.SetSource(gradient); } } else { cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Mid(StateType.Normal)); } cr.FillPreserve(); cr.SetSourceColor((MonoDevelop.Components.HslColor)Style.Dark(StateType.Normal)); cr.Stroke(); cr.LineWidth = 1; cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.BaseForegroundColor.ToCairoColor()); if (drawArrow) { DrawArrow(cr, x + w / 1.5, y + h / 2); DrawArrow(cr, x + w / 2.5, y + h / 2); } else { DrawCross(cr, x + w / 2, y + (h) / 2); } cr.Stroke(); } } } } // var result = base.OnExposeEvent (evnt); // // Gdk.GC gc = Style.DarkGC (State); // evnt.Window.DrawLine (gc, Allocation.X, Allocation.Top, Allocation.X, Allocation.Bottom); // evnt.Window.DrawLine (gc, Allocation.Right, Allocation.Top, Allocation.Right, Allocation.Bottom); // // evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Y, Allocation.Right, Allocation.Y); // evnt.Window.DrawLine (gc, Allocation.Left, Allocation.Bottom, Allocation.Right, Allocation.Bottom); return(true); }
public static void Line(this Cairo.Context cr, double x1, double y1, double x2, double y2) { cr.MoveTo(x1, y1); cr.LineTo(x2, y2); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { //base.OnPaint(pe); Cairo.Context dc = Gdk.CairoHelper.Create(args.Window); // Draw white background //Graphics dc = pe.Graphics; dc.IdentityMatrix(); dc.SetSourceRGB(1.0, 1.0, 1.0); dc.Rectangle(0, 0, Allocation.Width, Allocation.Height); dc.Fill(); // Draw the raster Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix(); //t.Freeze(); dc.Save(); dc.LineWidth = 0.01; // todo: always 1 pixel dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke? { dc.Transform(t); TheRasterModel.DrawRaster( (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); }, (r1, r2) => { dc.DrawEllipse(0, 0, 2 * r1, 2 * r2); }); } dc.Restore(); // draw unavailable note if (TheDisplayModel.IsUnavailable) { dc.SetSourceRGB(0, 0, 0); dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); //StringFormat f = new StringFormat(); //f.Alignment = StringAlignment.Center; //f.LineAlignment = StringAlignment.Center; //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f); dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo dc.ShowText("<Unavailable>"); } // draw the pdf image if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null) { Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2); //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p); dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y); //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height); dc.Paint(); } // draw the overlay if (ShowOverlay) { dc.SetSourceRGB(0, 0, 0); // draw shapes from parsetree foreach (var osv in OSViews) { osv.Draw(dc); } // draw (visible) auxiliary shapes foreach (var ps in PreviewShapes.Where(o => o.Visible)) { ps.Draw(dc); } } // draw adorner(s) foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible)) { dc.SetSourceRGB(0.5, 0.5, 0.5); dc.LineWidth = 5; System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height); ShowAt.Inflate(6, 6); dc.Rectangle(ShowAt.ToCairoRectangle()); //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF()); dc.Stroke(); } // draw the object marker if (MarkObject_ShowMarker && MarkObject_Marked != null) { System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height); ShowAt.Inflate(15, 15); //using (Pen p = new Pen(Brushes.Red, 6)) { dc.SetSourceRGB(1, 0, 0); dc.LineWidth = 6; dc.DrawEllipse(ShowAt);//p, } } ((IDisposable)dc.Target).Dispose(); ((IDisposable)dc).Dispose(); return(true); }
public static void SharpLineY(this Cairo.Context cr, double x1, double y1, double x2, double y2) { cr.MoveTo(x1, y1 + 0.5); cr.LineTo(x2, y2 + 0.5); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (!painting || offset.IsNotSet ()) return; int x = (int)point.X; int y = (int)point.Y; if (last_point.IsNotSet ()) { last_point = new Point (x, y); return; } using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.ToolLayer.Surface)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = Cairo.FillRule.EvenOdd; g.Clip (); g.Antialias = Cairo.Antialias.Subpixel; g.MoveTo (last_point.X, last_point.Y); g.LineTo (x, y); g.SetSource (PintaCore.Workspace.ActiveDocument.CurrentLayer.Surface, offset.X, offset.Y); g.LineWidth = BrushWidth; g.LineCap = Cairo.LineCap.Round; g.Stroke (); } var dirty_rect = GetRectangleFromPoints (last_point, new Point (x, y)); last_point = new Point (x, y); surface_modified = true; PintaCore.Workspace.Invalidate (dirty_rect); }
public override void DrawEditor(IBitmapView view) { if (view.Image == null || view.Image.Width == 0 || view.Image.Height == 0) { return; } Gdk.Drawable target = ((FloatPixmapViewWidget)view).GdkWindow; Gdk.Rectangle image_position = ((FloatPixmapViewWidget)view).CurrentImagePosition; CrotateStageOperationParameters pm = ((CrotateStageOperationParameters)Parameters); Gdk.GC gc = new Gdk.GC(target); // Draw center square dot Point C = new Point(pm.Center.X, pm.Center.Y); int scr_c_x = image_position.X + (int)(image_position.Width * C.X); int scr_c_y = image_position.Y + (int)(image_position.Height * C.Y); // Calculating new picture's real dimensions int trueWidth = image_position.Width, trueHeight = image_position.Height; double w1, h1; w1 = pm.CropWidth * image_position.Width; h1 = pm.CropHeight * image_position.Height; double asp_rat; if (pm.AspectRatioCustom) { asp_rat = pm.AspectRatio; } else { asp_rat = pm.PresetAspectRatioValues[pm.AspectRatioPreset]; } switch (pm.Mode) { case CatEye.Core.CrotateStageOperation.Mode.Disproportional: trueWidth = (int)w1; trueHeight = (int)h1; break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalWidthFixed: trueWidth = (int)w1; trueHeight = (int)(w1 / asp_rat); break; case CatEye.Core.CrotateStageOperation.Mode.ProportionalHeightFixed: trueWidth = (int)(h1 * asp_rat); trueHeight = (int)h1; break; } // Calculating new corners positions and "round" dot position double ang = pm.Angle / 180 * Math.PI; CatEye.Core.Point lt_corner = new CatEye.Core.Point( -trueWidth / 2, -trueHeight / 2); lt_corner_rot = CatEye.Core.Point.Rotate(lt_corner, ang, new Point(0, 0)); Gdk.Point scr_lt = new Gdk.Point( (int)(scr_c_x + lt_corner_rot.X), (int)(scr_c_y + lt_corner_rot.Y)); CatEye.Core.Point rt_corner = new CatEye.Core.Point( +trueWidth / 2, -trueHeight / 2); rt_corner_rot = CatEye.Core.Point.Rotate(rt_corner, ang, new Point(0, 0)); Gdk.Point scr_rt = new Gdk.Point( (int)(scr_c_x + rt_corner_rot.X), (int)(scr_c_y + rt_corner_rot.Y)); CatEye.Core.Point rb_corner = new CatEye.Core.Point( +trueWidth / 2, +trueHeight / 2); rb_corner_rot = CatEye.Core.Point.Rotate(rb_corner, ang, new Point(0, 0)); Gdk.Point scr_rb = new Gdk.Point( (int)(scr_c_x + rb_corner_rot.X), (int)(scr_c_y + rb_corner_rot.Y)); CatEye.Core.Point lb_corner = new CatEye.Core.Point( -trueWidth / 2, +trueHeight / 2); lb_corner_rot = CatEye.Core.Point.Rotate(lb_corner, ang, new Point(0, 0)); Gdk.Point scr_lb = new Gdk.Point( (int)(scr_c_x + lb_corner_rot.X), (int)(scr_c_y + lb_corner_rot.Y)); Gdk.Point scr_rnd = new Gdk.Point( (int)(scr_c_x + (rt_corner_rot.X + rb_corner_rot.X) / 2), (int)(scr_c_y + (rt_corner_rot.Y + rb_corner_rot.Y) / 2)); // Drawing frame using (Cairo.Context cc = Gdk.CairoHelper.Create(target)) { cc.LineCap = Cairo.LineCap.Round; cc.LineJoin = Cairo.LineJoin.Round; cc.Color = new Cairo.Color(0, 0, 0, 0.5); cc.LineWidth = 3; cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); cc.Color = new Cairo.Color(1, 1, 1, 1); cc.LineWidth = 1; cc.SetDash(new double[] { 3, 3 }, 0); cc.MoveTo(scr_lt.X, scr_lt.Y); cc.LineTo(scr_lb.X, scr_lb.Y); cc.LineTo(scr_rb.X, scr_rb.Y); cc.LineTo(scr_rt.X, scr_rt.Y); cc.LineTo(scr_lt.X, scr_lt.Y); cc.ClosePath(); cc.Stroke(); } // Drawing center "triangle" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.triangle_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_c_x - buf.Width / 2), (int)(scr_c_y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing side "round" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.round_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rnd.X - buf.Width / 2), (int)(scr_rnd.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } // Drawing corner "square" dot. using (Gdk.Pixbuf buf = Gdk.Pixbuf.LoadFromResource("CatEye.UI.Gtk.Widgets.res.square_dot.png")) { target.DrawPixbuf(gc, buf, 0, 0, (int)(scr_rb.X - buf.Width / 2), (int)(scr_rb.Y - buf.Height / 2), buf.Width, buf.Height, Gdk.RgbDither.None, 0, 0); } }