static void Main() { // The using statement ensures that potentially heavy objects // are disposed immediately. using (ImageSurface draw = new ImageSurface(Format.Argb32, 70, 150)) { using (Context gr = new Context(draw)) { gr.Antialias = Antialias.Subpixel; // sets the anti-aliasing method gr.LineWidth = 9; // sets the line width gr.SetSourceColor(new Color(0, 0, 0, 1)); // red, green, blue, alpha gr.MoveTo(10, 10); // sets the Context's start point. gr.LineTo(40, 60); // draws a "virtual" line from 5,5 to 20,30 gr.Stroke(); //stroke the line to the image surface gr.Antialias = Antialias.Gray; gr.LineWidth = 8; gr.SetSourceColor(new Color(1, 0, 0, 1)); gr.LineCap = LineCap.Round; gr.MoveTo(10, 50); gr.LineTo(40, 100); gr.Stroke(); gr.Antialias = Antialias.None; //fastest method but low quality gr.LineWidth = 7; gr.MoveTo(10, 90); gr.LineTo(40, 140); gr.Stroke(); draw.WriteToPng("antialias.png"); //save the image as a png image. } } }
protected override bool OnExposeEvent(EventExpose evnt) { using (Cairo.Context ctx = CairoHelper.Create(evnt.Window)) { int dx = (int)((double)Allocation.Width * dividerPosition); ctx.LineWidth = 1; ctx.Rectangle(0, 0, dx, Allocation.Height); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.Rectangle(dx, 0, Allocation.Width - dx, Allocation.Height); ctx.SetSourceRGB(1, 1, 1); ctx.Fill(); if (PropertyContentRightPadding > 0) { ctx.Rectangle(Allocation.Width - PropertyContentRightPadding, 0, PropertyContentRightPadding, Allocation.Height); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.MoveTo(Allocation.Width - PropertyContentRightPadding + 0.5, 0); ctx.RelLineTo(0, Allocation.Height); ctx.SetSourceColor(DividerColor); ctx.Stroke(); } ctx.MoveTo(dx + 0.5, 0); ctx.RelLineTo(0, Allocation.Height); ctx.SetSourceColor(DividerColor); ctx.Stroke(); int y = 0; Draw(ctx, rows, dx, PropertyLeftPadding, ref y); } return(base.OnExposeEvent(evnt)); }
public override void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc) { double top_offset = 2.0; double right_offset = 2.0; double margin = 0.5; double line_width = 0.7; var stroke_color = CairoExtensions.ColorShade( Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected), 0.8); stroke_color.A = 0.1; cr.SetSourceColor(stroke_color); CairoExtensions.RoundedRectangle(cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (margin + line_width) * 2.0 - right_offset, alloc.Height - (margin + line_width) * 2.0 - top_offset, Context.Radius / 2.0, CairoCorners.None); cr.Fill(); stroke_color.A = 1.0; cr.LineWidth = line_width; cr.SetSourceColor(stroke_color); CairoExtensions.RoundedRectangle(cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (line_width + margin) * 2.0 - right_offset, alloc.Height - (line_width + margin) * 2.0 - right_offset, Context.Radius / 2.0, CairoCorners.All); cr.Stroke(); }
public void Draw(Cairo.Context g, double scale, bool fillSelection) { g.Save(); g.Translate(0.5, 0.5); g.Scale(scale, scale); g.AppendPath(SelectionPath); if (fillSelection) { g.SetSourceColor(new Cairo.Color(0.7, 0.8, 0.9, 0.2)); g.FillRule = Cairo.FillRule.EvenOdd; g.FillPreserve(); } g.LineWidth = 1 / scale; // Draw a white line first so it shows up on dark backgrounds g.SetSourceColor(new Cairo.Color(1, 1, 1)); g.StrokePreserve(); // Draw a black dashed line over the white line g.SetDash(new double[] { 2 / scale, 4 / scale }, 0); g.SetSourceColor(new Cairo.Color(0, 0, 0)); g.Stroke(); g.Restore(); }
public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners, bool flat_fill) { var selection_color = color; var selection_highlight = CairoExtensions.ColorShade(selection_color, 1.24); var selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85); selection_highlight.A = 0.5; selection_stroke.A = color.A; LinearGradient grad = null; if (filled) { if (flat_fill) { cr.SetSourceColor(selection_color); } else { var selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.12); var selection_fill_dark = selection_color; selection_fill_light.A = color.A; selection_fill_dark.A = color.A; grad = new LinearGradient(x, y, x, y + height); grad.AddColorStop(0, selection_fill_light); grad.AddColorStop(0.4, selection_fill_dark); grad.AddColorStop(1, selection_fill_light); cr.SetSource(grad); } CairoExtensions.RoundedRectangle(cr, x, y, width, height, Context.Radius, corners, true); cr.Fill(); if (grad != null) { grad.Dispose(); } } if (filled && stroked) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_highlight); CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3, Context.Radius - 1, corners, true); cr.Stroke(); } if (stroked) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_stroke); CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, Context.Radius, corners, true); cr.Stroke(); } }
protected void DrawHoverAndSelection(Cairo.Context cr) { cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Hoverable && hoveringIndex != -1) { Cairo.Rectangle rect = GetTileRectSansPadding(HoveringX, HoveringY, scale: false, offset: false); cr.NewPath(); cr.SetSourceColor(HoverColor); cr.Rectangle(new Cairo.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1)); cr.LineWidth = 1; cr.LineJoin = LineJoin.Bevel; cr.Stroke(); } if (Selectable) { var rect = GetTileRectSansPadding(SelectedX, SelectedY, scale: false, offset: false); if (IsInBounds((int)rect.X, (int)rect.Y, scale: false, offset: false)) { cr.NewPath(); cr.SetSourceColor(SelectionColor); cr.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1); cr.LineWidth = 1; cr.Stroke(); } } cr.Restore(); }
void DrawFoldSegment(Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected) { var drawArea = new Cairo.Rectangle(System.Math.Floor(x + (Margin.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); } }
/// <summary>Paint on the graphics context</summary> /// <param name="context">The graphics context to draw on</param> public override void Paint(Cairo.Context context) { if (Selected) { context.SetSourceColor(OxyColors.Blue); } else { context.SetSourceColor(ForegroundColour); } // Draw circle context.LineWidth = 3; context.NewPath(); context.Arc(Location.X, Location.Y, Width / 2, 0, 2 * Math.PI); context.StrokePreserve(); context.SetSourceColor(Colour); context.Fill(); // Write text context.LineWidth = 1; context.SetSourceColor(OxyColors.Black); context.SetFontSize(13); DrawCentredText(context, Name, Location); }
/*override (Gdk.EventButton evnt) * { * var res = base.OnButtonPressEvent(evnt); * if ((evnt.Button & (uint)Gdk.ModifierType.Button1Mask) != 0) * { * if ((evnt.Button & (uint)Gdk.ModifierType.ShiftMask) != 0) * { * // if is left click + shift * EnableMode = EnableMode.ActiveWithLimit; * } * else * { * // if is left click * EnableMode = EnableMode.Active; * } * }else if ((evnt.Button & (uint)Gdk.ModifierType.Button3Mask) != 0) * { * //right clicked * EnableMode = EnableMode.Disabled; * } * * QueueDraw(); * * return res; * }*/ void SetBgColor(EnableMode enableMode, Gdk.EventExpose evnt) { //this.ModifyBg(StateType.Normal, Colors[(int)EnableMode]); Cairo.Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.Rectangle(0, 0, Allocation.Width, Allocation.Height); Color c = new Color(0, 0, 0); cr.SetSourceColor(c); cr.Stroke(); cr.Rectangle(1, 1, Allocation.Width - 1, Allocation.Height - 1); if (enableMode == EnableMode.Active) { c = Colors[1]; } else if (enableMode == EnableMode.ActiveWithLimit) { c = Colors[2]; } else if (enableMode == EnableMode.Disabled) { c = Colors[0]; } cr.SetSourceColor(c); cr.Fill(); cr.Target.Dispose(); cr.Dispose(); // set tooltip HasTooltip = true; TooltipText = enableMode.ToString(); }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; cr.SetSourceColor(Theme.Colors.GetWidgetColor(GtkColorClass.Base, Gtk.StateType.Normal)); cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height); cr.Fill(); Color color = Theme.Colors.GetWidgetColor(GtkColorClass.Dark, Gtk.StateType.Active); Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; LinearGradient fill = new LinearGradient(0, 0, 0, RenderSize.Height); fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); }
public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath(); double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo(x, rectangle.Y + 0.5 + 2); cr.RelLineTo(0, rectangle.Height - 1 - 4); cr.ClosePath(); cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor()); cr.LineWidth = 1; cr.Stroke(); return; } if (Active || HoverPosition.X >= 0) { if (Active) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { gr.AddColorStop(0, Tabstrip.ActiveGradientStart); gr.AddColorStop(1, Tabstrip.ActiveGradientEnd); cr.SetSource(gr); } cr.Fill(); cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1); cr.SetSourceRGBA(1, 1, 1, 0.05); cr.LineWidth = 1; cr.Stroke(); } else if (HoverPosition.X >= 0) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { var c1 = Tabstrip.ActiveGradientStart; var c2 = Tabstrip.ActiveGradientEnd; c1.A = 0.2; c2.A = 0.2; gr.AddColorStop(0, c1); gr.AddColorStop(1, c2); cr.SetSource(gr); } cr.Fill(); } } if (Active) { cr.SetSourceRGB(1, 1, 1); } else { cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor()); } cr.MoveTo(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2); Pango.CairoHelper.ShowLayout(cr, layout); }
public override void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc) { var corners = CairoCorners.All; double top_extend = 0; double bottom_extend = 0; double left_extend = 0; double right_extend = 0; if (Context.ToplevelBorderCollapse) { if (Widget.Allocation.Top <= Widget.Toplevel.Allocation.Top) { corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight); top_extend = cr.LineWidth; } if (Widget.Allocation.Bottom >= Widget.Toplevel.Allocation.Bottom) { corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight); bottom_extend = cr.LineWidth; } if (Widget.Allocation.Left <= Widget.Toplevel.Allocation.Left) { corners &= ~(CairoCorners.BottomLeft | CairoCorners.TopLeft); left_extend = cr.LineWidth; } if (Widget.Allocation.Right >= Widget.Toplevel.Allocation.Right) { corners &= ~(CairoCorners.BottomRight | CairoCorners.TopRight); right_extend = cr.LineWidth; } } // FIXME Windows; shading the color by .8 makes it blend into the bg if (Widget.HasFocus && !Hyena.PlatformDetection.IsWindows) { cr.LineWidth = BorderWidth * 1.5; cr.SetSourceColor(CairoExtensions.ColorShade(border_color, 0.8)); } else { cr.LineWidth = BorderWidth; cr.SetSourceColor(border_color); } double offset = (double)cr.LineWidth / 2.0; CairoExtensions.RoundedRectangle(cr, alloc.X + offset - left_extend, alloc.Y + offset - top_extend, alloc.Width - cr.LineWidth + left_extend + right_extend, alloc.Height - cr.LineWidth - top_extend + bottom_extend, Context.Radius, corners); cr.Stroke(); }
protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context g) { Theme.BorderColor = marker.TooltipColor.Color; g.Rectangle(0, 0, Allocation.Width, Allocation.Height); g.SetSourceColor(marker.TooltipColor.Color); g.Fill(); using (var drawingLayout = new Pango.Layout(this.PangoContext)) { drawingLayout.FontDescription = cache.tooltipFontDescription; double y = verticalTextBorder; var showBulletedList = marker.Errors.Count > 1; foreach (var msg in marker.Errors) { var icon = msg.IsError ? cache.errorPixbuf : cache.warningPixbuf; if (!showBulletedList) { drawingLayout.Width = maxTextWidth; } drawingLayout.SetText(GetFirstLine(msg)); int w; int h; drawingLayout.GetPixelSize(out w, out h); if (showBulletedList) { g.Save(); g.Translate( textBorder, y + verticalTextSpace / 2 + 1 + Math.Max(0, (h - icon.Height) / 2) ); Gdk.CairoHelper.SetSourcePixbuf(g, icon, 0, 0); g.Paint(); g.Restore(); } g.Save(); g.Translate(showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2 + 1); g.SetSourceColor(ShadowColor); g.ShowLayout(drawingLayout); g.Translate(0, -1); g.SetSourceColor(marker.TagColor.SecondColor); g.ShowLayout(drawingLayout); g.Restore(); y += h + verticalTextSpace; } } }
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(System.Math.Max(0, start - startOffset)).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); x_pos = layout.IndexToPos(System.Math.Max(0, 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; if (selected) { cr.SetSourceColor(editor.ColorStyle.SelectedText.Foreground); } else { cr.SetSourceColor(ColorName == null ? Color : editor.ColorStyle.GetChunkStyle(ColorName).Foreground); } if (Wave) { Pango.CairoHelper.ShowErrorUnderline(cr, @from, y + editor.LineHeight - height, to - @from, height); } else { cr.LineWidth = 1; cr.MoveTo(@from, y + editor.LineHeight - 1.5); cr.LineTo(to, y + editor.LineHeight - 1.5); cr.Stroke(); } }
/// <summary>Paint on the graphics context</summary> /// <param name="context">The graphics context to draw on</param> public override void Paint(Cairo.Context context) { CalcBezPoints(); if (BezPoints.Count != 0) { // Create point for upper-left corner of drawing. context.NewPath(); if (Selected) { context.SetSourceColor(OxyColors.Blue); } else { context.SetSourceColor(Colour); } // Draw text if necessary if (Name != null) { DGNode.DrawCentredText(context, Name, Location); } context.MoveTo(BezPoints[0]); PointD controlPoint = new PointD(Location.X, Location.Y); context.CurveTo(controlPoint, controlPoint, BezPoints[BezPoints.Count - 1]); context.Stroke(); // find closest point in the bezPoints to the intersection point that is outside the target // work backwards through BezPoints array and use the first one that is outside the target for (int i = BezPoints.Count - 1; i >= 0; i--) { PointD arrowHead; if (!TargetNode.HitTest(BezPoints[i])) { arrowHead = BezPoints[i]; i--; //keep moving along the line until distance = target radius double targetRadius = TargetNode.Width / 2; while (i >= 0) { double dist = GetDistance(BezPoints[i], arrowHead); if (dist >= 20) { DrawArrow(context, BezPoints[i], arrowHead); break; } i--; } break; } } } }
public void DrawLine(Coordinate a, Coordinate b) { var pt1 = ToCairoPoint(a); var pt2 = ToCairoPoint(b); context.LineWidth = 1.0; context.SetSourceColor(currentLineColor); context.MoveTo(pt1); context.LineTo(pt2); context.Stroke(); }
protected virtual void DrawBorder(Cairo.Context context, Gdk.Rectangle region) { LayoutRoundedRectangle(context, region, -1, -1); context.LineWidth = 1; context.SetSourceColor(Styles.StatusBarInnerColor); context.Stroke(); LayoutRoundedRectangle(context, region); context.LineWidth = 1; context.SetSourceColor(Styles.StatusBarBorderColor); context.StrokePreserve(); }
protected override bool OnDrawn(Context cr) { cr.Rectangle(0, 0, AllocatedWidth, AllocatedHeight); cr.SetSourceColor(BackgroundColor); cr.Fill(); cr.SelectFontFace(FontFamily, FontStyle, Cairo.FontWeight.Normal); cr.SetFontSize(FontSize); cr.SetSourceColor(Color); var te = cr.TextExtents(Text); var charsPerLine = AllocatedWidth / te.Height; var lineCount = Text.Length * charsPerLine; var totalHeight = te.Height * lineCount + PaddingBottom + PaddingTop; if (totalHeight < AllocatedHeight) { // SetSizeRequest(); } if (te.Width > AllocatedWidth) { } cr.MoveTo(PaddingLeft, PaddingTop + FontSize); cr.ShowText(Text); // var g = new Glyph(); // Pango.CairoHelper.ShowGlyphString(); Console.WriteLine(cr.TextExtents(Text).Width); Console.WriteLine(cr.TextExtents(Text).Height); var fontWidth = cr.GetScaledFont().FontExtents.MaxXAdvance; var fontHeight = cr.GetScaledFont().FontExtents.Height; // 7.201171875 // 13.5 // cr.ShowGlyphs(); // cr.ShowGlyphs(); // for (var i = 0; i < lineCount; i++) // { // cr.ShowText(Text.Substring( // i * charsPerLine, // (i + 1) * charsPerLine)); // } return(true); }
void DrawProgressBar(Cairo.Context context, double progress, Gdk.Rectangle bounding, StatusArea.RenderArg arg) { LayoutRoundedRectangle(context, new Gdk.Rectangle(bounding.X, bounding.Y, (int)(bounding.Width * progress), bounding.Height), 0, 0, 1); context.Clip(); LayoutRoundedRectangle(context, bounding, 0, 0, 1); context.SetSourceColor(Styles.WithAlpha(Styles.StatusBarProgressBackgroundColor, Styles.StatusBarProgressBackgroundColor.A * arg.ProgressBarAlpha)); context.FillPreserve(); context.ResetClip(); context.SetSourceColor(Styles.WithAlpha(Styles.StatusBarProgressOutlineColor, Styles.StatusBarProgressOutlineColor.A * arg.ProgressBarAlpha)); context.LineWidth = 1; context.Stroke(); }
void DrawMediaBox(Context cr, PdfPage page) { cr.MoveTo(margin + page.MediaBox.X1, margin + page.MediaBox.Y2); DrawHelper.DrawBox(cr, margin + page.MediaBox.X1, margin + page.MediaBox.Y2, pageWidth, pageHeight); cr.SetSourceColor(whiteColor); cr.FillPreserve(); cr.SetSourceColor(blackColor); cr.Stroke(); /*cr.SetSourceColor(shadowColor); * cr.MoveTo(margin + page.MediaBox.X1 + 2, margin + page.MediaBox.Y1 + 2); * DrawHelper.DrawBox(cr, margin + page.MediaBox.X1 + 2, margin + page.MediaBox.Y1 + 2, pageWidth, pageHeight); * cr.Stroke (); * cr.SetSourceColor(blackColor);*/ }
private void DrawEdge(Cairo.Context cx, NodeVisualization _from, NodeVisualization _to) { int beginX = _from.X + _from.Width / 2; int beginY = _from.Y + _from.Height / 2; int endX = _to.X + _to.Width / 2; int endY = _to.Y + _to.Height / 2; cx.Antialias = Antialias.Gray; cx.LineWidth = 3; if (!_from.successors.ContainsKey(_to) || _from.successors[_to] == false) { cx.SetSourceColor(new Color(0, 0, 0, 1)); } else { cx.SetSourceColor(new Color(0, 0.8, 0, 1)); } cx.LineCap = LineCap.Round; cx.MoveTo(beginX, beginY); cx.LineTo(endX, endY); cx.Stroke(); int tipX = ((2 * endX) + beginX) / 3; int tipY = ((2 * endY) + beginY) / 3; int arrowLength = 10; //can be adjusted int dx = endX - beginX; int dy = endY - beginY; double theta = Math.Atan2(dy, dx); double rad = 35 * Math.PI / 180; //35 angle double x = tipX - arrowLength * Math.Cos(theta + rad); double y = tipY - arrowLength * Math.Sin(theta + rad); double phi2 = -35 * Math.PI / 180; //-35 angle double x2 = tipX - arrowLength * Math.Cos(theta + phi2); double y2 = tipY - arrowLength * Math.Sin(theta + phi2); cx.MoveTo(tipX, tipY); cx.LineTo(x, y); cx.Stroke(); cx.MoveTo(tipX, tipY); cx.LineTo(x2, y2); cx.Stroke(); }
public CellRendererSurface(int width, int height) { // TODO: Respect cell padding (Xpad and Ypad). SetFixedSize(width, height); transparent = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height); Cairo.Color gray = new Cairo.Color(.75, .75, .75); // Create checkerboard background int grid_width = 4; using (Cairo.Context g = new Cairo.Context(transparent)) { g.SetSourceColor(new Cairo.Color(1, 1, 1)); g.Paint(); for (int y = 0; y < height; y += grid_width) { for (int x = 0; x < width; x += grid_width) { if ((x / grid_width % 2) + (y / grid_width % 2) == 1) { g.FillRectangle(new Cairo.Rectangle(x, y, grid_width, grid_width), gray); } } } } }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); Win32Surface = new Win32Surface(this.CreateGraphics().GetHdc()); FontContext = new Context(Win32Surface); //CRITICAL: Format of Win32Surface and ImageSurface must be identical! ImageSurface = new ImageSurface(Format.Rgb24, ClientSize.Width, ClientSize.Height); BackContext = new Context(ImageSurface); //Clear Surface2 BackContext.SetSourceColor(new Color(1,1,1)); BackContext.Operator = Operator.Source; BackContext.Paint(); BackContext.Operator = Operator.Over; var textFormat = DWriteCairo.CreateTextFormat( "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 32f); Debug.Assert(Math.Abs(textFormat.FontSize - 32f) < 0.0001); const string s = "Hello World"; textLayout = DWriteCairo.CreateTextLayout(s, textFormat, 300, 40); }
private void Image_Loaded(object sender, RoutedEventArgs e) { Image image = (Image)sender; using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height)) { using (Context context = new Context(surface)) { PointD p = new PointD(10.0, 10.0); PointD p2 = new PointD(100.0, 10.0); PointD p3 = new PointD(100.0, 100.0); PointD p4 = new PointD(10.0, 100.0); context.MoveTo(p); context.LineTo(p2); context.LineTo(p3); context.LineTo(p4); context.LineTo(p); context.ClosePath(); context.Fill(); context.MoveTo(140.0, 110.0); context.SetFontSize(32.0); context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0)); context.ShowText("Hello Cairo!"); surface.Flush(); RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width); image.Source = source; } } }
protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress) { cr.SetSourceColor (new Color (0, 0, 0, progress)); if (next != null) { double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height); cr.Save (); cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (0, 0, width, height); cr.Scale (scale, scale); CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height)); cr.PaintWithAlpha (progress); cr.Restore (); } }
public override void Apply (CanvasItem item, Context cr) { int steps = ShadowSize; double opacity_step = ShadowOpacity / ShadowSize; Color color = new Color (0, 0, 0); double width = Math.Round (item.Allocation.Width); double height = Math.Round (item.Allocation.Height); if (Fill != null) { cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2); Fill.Apply (cr); cr.Fill (); } cr.LineWidth = 1.0; for (int i = 0; i < steps; i++) { CairoExtensions.RoundedRectangle (cr, i + 0.5, i + 0.5, (width - 2 * i) - 1, (height - 2 * i) - 1, steps - i); color.A = opacity_step * (i + 1); cr.SetSourceColor (color); cr.Stroke (); } }
public override void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc) { cr.LineWidth = BorderWidth; border_color.A = 0.3; cr.SetSourceColor(border_color); double offset = (double)BorderWidth / 2.0; double w = Math.Max(0, alloc.Width * 0.75); double x = alloc.X + (alloc.Width - w) * 0.5 + offset; double y = alloc.Y + alloc.Height + offset; LinearGradient g = new LinearGradient(x, y, x + w, y); Color transparent = border_color; transparent.A = 0.0; g.AddColorStop(0, transparent); g.AddColorStop(0.4, border_color); g.AddColorStop(0.6, border_color); g.AddColorStop(1, transparent); cr.SetSource(g); cr.MoveTo(x, y); cr.LineTo(x + w, y); cr.Stroke(); g.Dispose(); }
public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners) { color.A *= 0.85; Cairo.Color selection_color = color; Cairo.Color selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85); selection_stroke.A = color.A; if (filled) { Cairo.Color selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.05); Cairo.Color selection_fill_dark = selection_color; selection_fill_light.A = color.A; selection_fill_dark.A = color.A; LinearGradient grad = new LinearGradient(x, y, x, y + height); grad.AddColorStop(0, selection_fill_dark); grad.AddColorStop(1, selection_fill_light); cr.SetSource(grad); cr.Rectangle(x, y, width, height); cr.Fill(); grad.Dispose(); } if (stroked && !filled) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_stroke); cr.Rectangle(x + 0.5, y + 0.5, width - 1, height - 1); cr.Stroke(); } }
protected override bool OnDrawn(Cairo.Context cr) { base.OnDrawn(cr); if (Surface != null) { cr.SetSourceSurface(Surface, XOffset, YOffset); cr.Paint(); } else if (Image != null) { Bitmap orig = Image; using (Surface source = CairoHelper.LockBitmap(orig)) { cr.Scale(Scale, Scale); cr.SetSource(source, XOffset, YOffset); ((SurfacePattern)cr.Source).Filter = Filter.Nearest; cr.Scale(1.0 / Scale, 1.0 / Scale); cr.Paint(); CairoHelper.UnlockBitmap(orig); } } if (hoveringIndex != -1) { cr.NewPath(); cr.SetSourceColor(HoverColor); cr.Rectangle(new Cairo.Rectangle(XOffset + HoveringX * TileWidth * Scale + 0.5, YOffset + HoveringY * TileHeight * Scale + 0.5, ScaledTileWidth - 1, ScaledTileHeight - 1)); cr.LineWidth = 1; cr.LineJoin = LineJoin.Bevel; cr.Stroke(); } return(true); }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; Theme.Widget.StyleContext.Save(); Theme.Widget.StyleContext.AddClass("entry"); Theme.Widget.StyleContext.RenderBackground(cr, 0, 0, RenderSize.Width, RenderSize.Height); var color = CairoExtensions.GdkRGBAToCairoColor(Theme.Widget.StyleContext.GetColor(Gtk.StateFlags.Active)); Theme.Widget.StyleContext.Restore(); // TODO get Dark color Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; using (var fill = new LinearGradient(0, 0, 0, RenderSize.Height)) { fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); } }
public void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc) { /*Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal); * Cairo.Color light_color = CairoExtensions.ColorShade (gtk_background_color, 1.1); * Cairo.Color dark_color = CairoExtensions.ColorShade (gtk_background_color, 0.95); * * CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight; * * LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom); * grad.AddColorStop (0, light_color); * grad.AddColorStop (0.75, dark_color); * grad.AddColorStop (0, light_color); * * cr.Pattern = grad; * CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, corners); * cr.Fill (); * * cr.Color = border_color; * cr.Rectangle (alloc.X, alloc.Bottom, alloc.Width, BorderWidth); * cr.Fill (); * grad.Destroy ();*/ Cairo.Color gtk_background_color = CairoExtensions.GdkRGBAToCairoColor(widget.StyleContext.GetBackgroundColor(StateFlags.Normal)); Cairo.Color dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.80); cr.SetSourceColor(dark_color); cr.MoveTo(alloc.X, alloc.Bottom + 0.5); cr.LineTo(alloc.Right, alloc.Bottom + 0.5); cr.LineWidth = 1.0; cr.Stroke(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (System.Drawing.Graphics graphics = e.Graphics) { using (Win32Surface surface = new Win32Surface(graphics.GetHdc())) { using (Context context = new Context(surface)) { context.LineWidth = 2.0; context.SetSourceColor(this.bugColor); context.MoveTo(7.0, 64.0); context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0); context.MoveTo(25.0, 80.0); context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0); context.MoveTo(10.0, 41.0); context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0); context.LineWidth = 1.0; context.MoveTo(1.0, 26.0); context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0); context.LineTo(12.0, 14.0); context.Stroke(); context.MoveTo(30.0, 74.0); context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0); context.LineTo(10.0, 45.0); context.LineTo(10.0, 40.0); context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0); context.Stroke(); } } } }
public override void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color, CairoCorners corners) { cr.LineWidth = 1.25; cr.SetSourceColor(color); CairoExtensions.RoundedRectangle(cr, x + cr.LineWidth / 2.0, y + cr.LineWidth / 2.0, width - cr.LineWidth, height - cr.LineWidth, Context.Radius, corners, true); cr.Stroke(); }
public Document NewDocument(Gdk.Size imageSize, Color backgroundColor) { Document doc = CreateAndActivateDocument(null, imageSize); doc.Workspace.CanvasSize = imageSize; // Start with an empty white layer Layer background = doc.AddNewLayer(Catalog.GetString("Background")); if (backgroundColor.A != 0) { using (Cairo.Context g = new Cairo.Context(background.Surface)) { g.SetSourceColor(backgroundColor); g.Paint(); } } doc.Workspace.History.PushNewItem(new BaseHistoryItem(Stock.New, Catalog.GetString("New Image"))); doc.Workspace.History.SetClean(); // This ensures these are called after the window is done being created and sized. // Without it, we sometimes try to zoom when the window has a size of (0, 0). Gtk.Application.Invoke(delegate { PintaCore.Actions.View.ActualSize.Activate(); }); return(doc); }
private void DrawTriangle(Cairo.Context context) { double height = sideLength * Math.Sqrt(3) / 2; double x1 = offsetX; double y1 = height + offsetY; double x2 = 0.5 * sideLength + offsetX; double y2 = 0 + offsetY; double x3 = sideLength + offsetX; double y3 = height + offsetY; context.NewPath(); context.SetSourceColor(Utility.Colour.ToOxy(owner.MainWidget.StyleContext.GetColor(StateFlags.Normal).ToColour().ToGdk())); context.MoveTo(x1, y1); context.LineTo(x2, y2); context.StrokePreserve(); context.LineTo(x3, y3); context.StrokePreserve(); context.LineTo(x1, y1); context.StrokePreserve(); }
void Paint(Context cr, double w, double h) { layout = Pango.CairoHelper.CreateLayout(cr); cr.LineWidth = 0.5d; cr.SetSourceColor(blackColor); for (int idx = 0; idx < inputDocument.PageCount; idx++) { var page = inputDocument.Pages [idx]; var res = page.Resources; lineHeight = 10d; pageHeight = page.MediaBox.Height; pageWidth = page.MediaBox.Width; cursor = new Tuple <double, double>(0d, pageHeight + margin); DrawMediaBox(cr, page); CObject content = ContentReader.ReadContent(page); DrawContent(cr, content); } }
protected override void ClippedRender (Context cr) { if (!color_set || ChangeOnRender) { color = CairoExtensions.RgbToColor ((uint)rand.Next (0, 0xffffff)); color_set = true; } CairoExtensions.RoundedRectangle (cr, 0, 0, RenderSize.Width, RenderSize.Height, 5); cr.SetSourceColor (color); cr.Fill (); }
protected override void DrawBackground (Context context, Gdk.Rectangle region) { LayoutRoundedRectangle (context, region); context.Clip (); context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF")); context.Paint (); context.Save (); context.Translate (region.X + region.Width / 2.0, region.Y + region.Height); using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) { var color = CairoExtensions.ParseColor ("E5F0FF"); rg.AddColorStop (0, color); color.A = 0; rg.AddColorStop (1, color); context.Scale (region.Width / (double)region.Height, 1.0); context.SetSource (rg); context.Paint (); } context.Restore (); LayoutRoundedRectangle (context, region, -3, -3, 2); context.SetSourceRGBA (1, 1, 1, 0.4); context.LineWidth = 1; context.StrokePreserve (); context.Clip (); int boxSize = 11; int x = region.Left + (region.Width % boxSize) / 2; for (; x < region.Right; x += boxSize) { context.MoveTo (x + 0.5, region.Top); context.LineTo (x + 0.5, region.Bottom); } int y = region.Top + (region.Height % boxSize) / 2; y += boxSize / 2; for (; y < region.Bottom; y += boxSize) { context.MoveTo (region.Left, y + 0.5); context.LineTo (region.Right, y + 0.5); } context.SetSourceRGBA (1, 1, 1, 0.2); context.Stroke (); context.ResetClip (); }
public override void Render(Context cr) { if (!CanResize) { return; } var selected_color = CairoExtensions.GdkRGBAToCairoColor (Window.StyleContext.GetColor (StateFlags.Selected)); var grad = new LinearGradient (0, 0, 0, Allocation.Height); selected_color.A = 0.4; grad.AddColorStop (0, selected_color); selected_color.A = 1.0; grad.AddColorStop (1, selected_color); cr.SetSource (grad); cr.LineWidth = 1.0; cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1); cr.Stroke (); selected_color.A = 0.5; cr.SetSourceColor (selected_color); double handle_size = 8; double ty = 0.5 + Allocation.Height - handle_size - 3; double tx = 0.5 + (Window.Direction == TextDirection.Ltr ? Allocation.Width - handle_size - 3 : 3); cr.Translate (tx, ty); for (double i = 0; i < 3; i++) { if (Window.Direction == TextDirection.Ltr) { cr.MoveTo (i * 3, handle_size); cr.LineTo (handle_size, i * 3); } else { cr.MoveTo (0, i * 3); cr.LineTo (handle_size - i * 3, handle_size); } } cr.Stroke (); cr.Translate (-tx, -ty); }
public CellRendererSurface (int width, int height) { // TODO: Respect cell padding (Xpad and Ypad). SetFixedSize (width, height); transparent = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height); Cairo.Color gray = new Cairo.Color (.75, .75, .75); // Create checkerboard background int grid_width = 4; using (Cairo.Context g = new Cairo.Context (transparent)) { g.SetSourceColor (new Cairo.Color (1, 1, 1)); g.Paint (); for (int y = 0; y < height; y += grid_width) for (int x = 0; x < width; x += grid_width) if ((x / grid_width % 2) + (y / grid_width % 2) == 1) g.FillRectangle (new Cairo.Rectangle (x, y, grid_width, grid_width), gray); } }
protected override void RenderTrackInfo(Context cr, TrackInfo track, bool renderTrack, bool renderArtistAlbum) { if (track == null) { return; } double offset = ArtworkSizeRequest + ArtworkSpacing, y = 0; double x = offset; double width = Allocation.Width - offset; int fl_width, fl_height, sl_width, sl_height; int pango_width = (int)(width * Pango.Scale.PangoScale); if (first_line_layout == null) { first_line_layout = CairoExtensions.CreateLayout (this, cr); first_line_layout.Ellipsize = Pango.EllipsizeMode.End; } if (second_line_layout == null) { second_line_layout = CairoExtensions.CreateLayout (this, cr); second_line_layout.Ellipsize = Pango.EllipsizeMode.End; } // Set up the text layouts first_line_layout.Width = pango_width; second_line_layout.Width = pango_width; // Compute the layout coordinates first_line_layout.SetMarkup (GetFirstLineText (track)); first_line_layout.GetPixelSize (out fl_width, out fl_height); second_line_layout.SetMarkup (GetSecondLineText (track)); second_line_layout.GetPixelSize (out sl_width, out sl_height); if (fl_height + sl_height > Allocation.Height) { SetSizeRequest (-1, fl_height + sl_height); } y = (Allocation.Height - (fl_height + sl_height)) / 2; // Render the layouts cr.Antialias = Cairo.Antialias.Default; if (renderTrack) { cr.MoveTo (x, y); cr.SetSourceColor (TextColor); Pango.CairoHelper.ShowLayout (cr, first_line_layout); } if (!renderArtistAlbum) { return; } cr.MoveTo (x, y + fl_height); Pango.CairoHelper.ShowLayout (cr, second_line_layout); }
void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } int padding = LeftRightPadding; padding = (int)(padding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); ctx.LineWidth = 1; LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.ClosePath (); using (var gr = new LinearGradient (tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) { if (active) { gr.AddColorStop (0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha (tab.Opacity)); } else { gr.AddColorStop (0, CairoExtensions.ParseColor ("f4f4f4").MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, CairoExtensions.ParseColor ("cecece").MultiplyAlpha (tab.Opacity)); } ctx.SetSource (gr); } ctx.Fill (); ctx.SetSourceColor (new Cairo.Color (1, 1, 1, .5).MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 1, active); ctx.Stroke (); ctx.SetSourceColor (Styles.BreadcrumbBorderColor.MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.StrokePreserve (); if (tab.GlowStrength > 0) { Gdk.Point mouse = tracker.MousePosition; using (var rg = new RadialGradient (mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) { rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength)); rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0)); ctx.SetSource (rg); ctx.Fill (); } } else { ctx.NewPath (); } // Render Close Button (do this first so we can tell how much text to render) var ch = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset; var crect = new Gdk.Rectangle (tabBounds.Right - padding - CloseButtonSize + 3, tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2, CloseButtonSize, CloseButtonSize); tab.CloseButtonAllocation = crect; tab.CloseButtonAllocation.Inflate (2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains (tracker.MousePosition) && tab.WidthModifier >= 1.0f; bool drawCloseButton = tabBounds.Width > 60 || highlight || closeButtonHovered; if (drawCloseButton) { DrawCloseButton (ctx, new Gdk.Point (crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength); } // Render Text int w = tabBounds.Width - (padding * 2 + CloseButtonSize); if (!drawCloseButton) w += CloseButtonSize; int textStart = tabBounds.X + padding; ctx.MoveTo (textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize); if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(w * Pango.Scale.PangoScale); ctx.SetSourceColor (tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient (textStart + w - 5, 0, textStart + w + 3, 0)) { var color = tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor; color = color.MultiplyAlpha (tab.Opacity); lg.AddColorStop (0, color); color.A = 0; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } } la.Dispose (); }
void Draw (Context ctx) { int tabArea = tabEndX - tabStartX; int x = GetRenderOffset (); const int y = 0; int n = 0; Action<Context> drawActive = c => { }; var drawCommands = new List<Action<Context>> (); for (; n < notebook.Tabs.Count; n++) { if (x + TabWidth < tabStartX) { x += TabWidth; continue; } if (x > tabEndX) break; int closingWidth; var cmd = DrawClosingTab (n, new Gdk.Rectangle (x, y, 0, Allocation.Height), out closingWidth); drawCommands.Add (cmd); x += closingWidth; var tab = (DockNotebookTab)notebook.Tabs [n]; bool active = tab == notebook.CurrentTab; int width = Math.Min (TabWidth, Math.Max (50, tabEndX - x - 1)); if (tab == notebook.Tabs.Last ()) width += LastTabWidthAdjustment; width = (int)(width * tab.WidthModifier); if (active) { int tmp = x; drawActive = c => DrawTab (c, tab, Allocation, new Gdk.Rectangle (tmp, y, width, Allocation.Height), true, true, draggingTab, CreateTabLayout (tab)); tab.Allocation = new Gdk.Rectangle (tmp, Allocation.Y, width, Allocation.Height); } else { int tmp = x; bool highlighted = tab == highlightedTab; if (tab.SaveStrength > 0.0f) { tmp = (int)(tab.SavedAllocation.X + (tmp - tab.SavedAllocation.X) * (1.0f - tab.SaveStrength)); } drawCommands.Add (c => DrawTab (c, tab, Allocation, new Gdk.Rectangle (tmp, y, width, Allocation.Height), highlighted, false, false, CreateTabLayout (tab))); tab.Allocation = new Gdk.Rectangle (tmp, Allocation.Y, width, Allocation.Height); } x += width; } var allocation = Allocation; int tabWidth; drawCommands.Add (DrawClosingTab (n, new Gdk.Rectangle (x, y, 0, allocation.Height), out tabWidth)); drawCommands.Reverse (); DrawBackground (ctx, allocation); // Draw breadcrumb bar header if (notebook.Tabs.Count > 0) { ctx.Rectangle (0, allocation.Height - BottomBarPadding, allocation.Width, BottomBarPadding); ctx.SetSourceColor (Styles.BreadcrumbBackgroundColor); ctx.Fill (); } ctx.Rectangle (tabStartX - LeanWidth / 2, allocation.Y, tabArea + LeanWidth, allocation.Height); ctx.Clip (); foreach (var cmd in drawCommands) cmd (ctx); ctx.ResetClip (); // Redraw the dragging tab here to be sure its on top. We drew it before to get the sizing correct, this should be fixed. drawActive (ctx); }
void DrawBackground (Context ctx, Gdk.Rectangle region) { var h = region.Height; ctx.Rectangle (0, 0, region.Width, h); using (var gr = new LinearGradient (0, 0, 0, h)) { if (isActiveNotebook) { gr.AddColorStop (0, Styles.TabBarActiveGradientStartColor); gr.AddColorStop (1, Styles.TabBarActiveGradientEndColor); } else { gr.AddColorStop (0, Styles.TabBarGradientStartColor); gr.AddColorStop (1, Styles.TabBarGradientEndColor); } ctx.SetSource (gr); ctx.Fill (); } ctx.MoveTo (region.X, 0.5); ctx.LineTo (region.Right + 1, 0.5); ctx.LineWidth = 1; ctx.SetSourceColor (Styles.TabBarGradientShadowColor); ctx.Stroke (); }
void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } double rightPadding = (active ? TabActivePadding.Right : TabPadding.Right) - (LeanWidth / 2); rightPadding = (rightPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); double leftPadding = (active ? TabActivePadding.Left : TabPadding.Left) - (LeanWidth / 2); leftPadding = (leftPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); double bottomPadding = active ? TabActivePadding.Bottom : TabPadding.Bottom; DrawTabBackground (this, ctx, allocation, tabBounds.Width, tabBounds.X, active); ctx.LineWidth = 1; ctx.NewPath (); // Render Close Button (do this first so we can tell how much text to render) var closeButtonAlloation = new Cairo.Rectangle (tabBounds.Right - rightPadding - (tabCloseImage.Width / 2) - CloseButtonMarginRight, tabBounds.Height - bottomPadding - tabCloseImage.Height - CloseButtonMarginBottom, tabCloseImage.Width, tabCloseImage.Height); tab.CloseButtonActiveArea = closeButtonAlloation.Inflate (2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonActiveArea.Contains (tracker.MousePosition); bool tabHovered = tracker.Hovered && tab.Allocation.Contains (tracker.MousePosition); bool drawCloseButton = active || tabHovered; if (!closeButtonHovered && tab.DirtyStrength > 0.5) { ctx.DrawImage (this, tabDirtyImage, closeButtonAlloation.X, closeButtonAlloation.Y); drawCloseButton = false; } if (drawCloseButton) ctx.DrawImage (this, tabCloseImage.WithAlpha ((closeButtonHovered ? 1.0 : 0.5) * tab.Opacity), closeButtonAlloation.X, closeButtonAlloation.Y); // Render Text double tw = tabBounds.Width - (leftPadding + rightPadding); if (drawCloseButton || tab.DirtyStrength > 0.5) tw -= closeButtonAlloation.Width / 2; double tx = tabBounds.X + leftPadding; var baseline = la.GetLine (0).Layout.GetPixelBaseline (); double ty = tabBounds.Height - bottomPadding - baseline; ctx.MoveTo (tx, ty); if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(tw * Pango.Scale.PangoScale); ctx.SetSourceColor ((tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ()); Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient (tx + tw - 10, 0, tx + tw, 0)) { var color = (tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor (); color = color.MultiplyAlpha (tab.Opacity); lg.AddColorStop (0, color); color.A = 0; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout); } } la.Dispose (); }
public override void DrawArrow (Context cr, Gdk.Rectangle alloc, double rotation) { rotation -= Math.PI / 2.0; double x1 = alloc.X; double x2 = alloc.Right; double x3 = alloc.X + alloc.Width / 2.0; double y1 = alloc.Y; double y2 = alloc.Bottom; double cx = x3; double cy = alloc.Y + alloc.Height / 2.0; if (rotation != 0) { // Rotate about the center of the arrow cr.Translate (cx, cy); cr.Rotate (rotation); cr.Translate (-cx, -cy); } cr.LineWidth = 1.0; bool hz = (rotation % (Math.PI / 2.0)) == 0; double dx = hz ? 0 : 0.5; double dy = hz ? 0.5 : 0.5; cr.Translate (dx, dy); cr.MoveTo (x1, y1); cr.LineTo (x2, y1); cr.LineTo (x3, y2); cr.LineTo (x1, y1); cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)); cr.FillPreserve (); cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal)); cr.Stroke (); cr.Translate (-dx, -dy); if (rotation != 0) { cr.Translate (cx, cy); cr.Rotate (-rotation); cr.Translate (-cx, -cy); } }
/// <summary> /// Gets the final pixel color for the given point, taking layers, opacity, and blend modes into account. /// </summary> public ColorBgra GetComputedPixel (int x, int y) { using (var dst = new ImageSurface (Format.Argb32, 1, 1)) { using (var g = new Context (dst)) { foreach (var layer in GetLayersToPaint ()) { var color = layer.Surface.GetColorBgraUnchecked (x, y).ToStraightAlpha ().ToCairoColor (); g.SetBlendMode (layer.BlendMode); g.SetSourceColor (color); g.Rectangle (dst.GetBounds ().ToCairoRectangle ()); g.PaintWithAlpha (layer.Opacity); } } return dst.GetColorBgraUnchecked (0, 0); } }
public Document NewDocument(Gdk.Size imageSize, Color backgroundColor) { Document doc = CreateAndActivateDocument (null, imageSize); doc.Workspace.CanvasSize = imageSize; // Start with an empty white layer Layer background = doc.AddNewLayer (Catalog.GetString ("Background")); if (backgroundColor.A != 0) { using (Cairo.Context g = new Cairo.Context (background.Surface)) { g.SetSourceColor (backgroundColor); g.Paint (); } } doc.Workspace.History.PushNewItem (new BaseHistoryItem (Stock.New, Catalog.GetString ("New Image"))); doc.IsDirty = false; PintaCore.Actions.View.ZoomToWindow.Activate (); return doc; }
public override void DrawArrow(Context cr, Gdk.Rectangle alloc, SortType type) { cr.LineWidth = 1; cr.Translate (0.5, 0.5); double x1 = alloc.X; double x3 = alloc.X + alloc.Width / 2.0; double x2 = x3 + (x3 - x1); double y1 = alloc.Y; double y2 = alloc.Bottom; if (type == SortType.Ascending) { cr.MoveTo (x1, y1); cr.LineTo (x2, y1); cr.LineTo (x3, y2); cr.LineTo (x1, y1); } else { cr.MoveTo (x3, y1); cr.LineTo (x2, y2); cr.LineTo (x1, y2); cr.LineTo (x3, y1); } cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)); cr.FillPreserve (); cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal)); cr.Stroke (); cr.Translate (-0.5, -0.5); }
protected override void onDraw(Context gr) { base.onDraw (gr); gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; rText = new Rectangle(new Size( measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); rText.Width -= 2 * Margin; rText.Height -= 2 * Margin; widthRatio = 1f; heightRatio = 1f; Rectangle cb = ClientRectangle; rText.X = cb.X; rText.Y = cb.Y; if (horizontalStretch) { widthRatio = (float)cb.Width / (float)rText.Width; if (!verticalStretch) heightRatio = widthRatio; } if (verticalStretch) { heightRatio = (float)cb.Height / (float)rText.Height; if (!horizontalStretch) widthRatio = heightRatio; } rText.Width = (int)(widthRatio * (float)rText.Width); rText.Height = (int)(heightRatio * (float)rText.Height); switch (TextAlignment) { case Alignment.TopLeft: //ok rText.X = cb.X; rText.Y = cb.Y; break; case Alignment.Top: //ok rText.Y = cb.Y; rText.X = cb.X + cb.Width / 2 - rText.Width / 2; break; case Alignment.TopRight: //ok rText.Y = cb.Y; rText.X = cb.Right - rText.Width; break; case Alignment.Left://ok rText.X = cb.X; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Right://ok rText.X = cb.X + cb.Width - rText.Width; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Bottom://ok rText.X = cb.Width / 2 - rText.Width / 2; rText.Y = cb.Height - rText.Height; break; case Alignment.BottomLeft://ok rText.X = cb.X; rText.Y = cb.Bottom - rText.Height; break; case Alignment.BottomRight://ok rText.Y = cb.Bottom - rText.Height; rText.X = cb.Right - rText.Width; break; case Alignment.Center://ok rText.X = cb.X + cb.Width / 2 - rText.Width / 2; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; } gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0); fe = gr.FontExtents; #region draw text cursor if (HasFocus && Selectable) { if (mouseLocalPos >= 0) { computeTextCursor(gr); if (SelectionInProgress) { if (SelBegin < 0){ SelBegin = new Point(CurrentColumn, CurrentLine); SelStartCursorPos = textCursorPos; SelRelease = -1; }else{ SelRelease = new Point(CurrentColumn, CurrentLine); if (SelRelease == SelBegin) SelRelease = -1; else SelEndCursorPos = textCursorPos; } } }else computeTextCursorPosition(gr); Foreground.SetAsSource (gr); gr.LineWidth = 1.0; gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height); gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height); gr.Stroke(); } #endregion //****** debug selection ************* // if (SelRelease >= 0) { // gr.Color = Color.Green; // Rectangle R = new Rectangle ( // rText.X + (int)SelEndCursorPos - 2, // rText.Y + (int)(SelRelease.Y * fe.Height), // 4, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); // } // if (SelBegin >= 0) { // gr.Color = Color.UnmellowYellow; // Rectangle R = new Rectangle ( // rText.X + (int)SelStartCursorPos - 2, // rText.Y + (int)(SelBegin.Y * fe.Height), // 4, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); // } //******************* for (int i = 0; i < lines.Count; i++) { string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize)); int lineLength = (int)gr.TextExtents (l).XAdvance; Rectangle lineRect = new Rectangle ( rText.X, rText.Y + (int)Math.Ceiling(i * fe.Height), lineLength, (int)Math.Ceiling(fe.Height)); // if (TextAlignment == Alignment.Center || // TextAlignment == Alignment.Top || // TextAlignment == Alignment.Bottom) // lineRect.X += (rText.Width - lineLength) / 2; // else if (TextAlignment == Alignment.Right || // TextAlignment == Alignment.TopRight || // TextAlignment == Alignment.BottomRight) // lineRect.X += (rText.Width - lineLength); if (Selectable) { if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { gr.SetSourceColor (selBackground); Rectangle selRect = lineRect; int cpStart = (int)SelStartCursorPos, cpEnd = (int)SelEndCursorPos; if (SelBegin.Y > SelRelease.Y) { cpStart = cpEnd; cpEnd = (int)SelStartCursorPos; } if (i == selectionStart.Y) { selRect.Width -= cpStart; selRect.Left += cpStart; } if (i == selectionEnd.Y) selRect.Width -= (lineLength - cpEnd); gr.Rectangle (selRect); gr.Fill (); } } if (string.IsNullOrWhiteSpace (l)) continue; Foreground.SetAsSource (gr); gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i); gr.ShowText (l); gr.Fill (); } }
public override void DrawBackground (Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset) { int markerStart = usage.Offset; int markerEnd = usage.EndOffset; if (markerEnd < startOffset || markerStart > endOffset) return; double @from; double to; var startXPos = metrics.TextRenderStartPosition; var endXPos = metrics.TextRenderEndPosition; var y = metrics.LineYRenderStartPosition; if (markerStart < startOffset && endOffset < markerEnd) { @from = startXPos; to = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; uint curIndex = 0, byteIndex = 0; TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex); int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex); x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X; to = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } @from = Math.Max (@from, editor.TextViewMargin.XOffset); to = Math.Max (to, editor.TextViewMargin.XOffset); if (@from < to) { Mono.TextEditor.Highlighting.AmbientColor colorStyle; if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write || (usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton) { colorStyle = editor.ColorStyle.ChangingUsagesRectangle; } else { colorStyle = editor.ColorStyle.UsagesRectangle; } using (var lg = new LinearGradient (@from + 1, y + 1, to , y + editor.LineHeight)) { lg.AddColorStop (0, colorStyle.Color); lg.AddColorStop (1, colorStyle.SecondColor); cr.SetSource (lg); cr.RoundedRectangle (@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4); cr.FillPreserve (); } cr.SetSourceColor (colorStyle.BorderColor); cr.Stroke (); } }
private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit (); Cairo.ImageSurface old = doc.CurrentUserLayer.Surface.Clone (); using (var g = new Cairo.Context (doc.CurrentUserLayer.Surface)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSourceColor (PintaCore.Palette.PrimaryColor); g.Fill (); } doc.Workspace.Invalidate (); doc.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.FillSelection.png", Catalog.GetString ("Fill Selection"), old, doc.CurrentUserLayerIndex)); }
protected override void OnMouseUp (Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; doc.ToolLayer.Clear (); doc.ToolLayer.Hidden = true; ImageSurface surf = doc.CurrentUserLayer.Surface; using (Context g = new Context (surf)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.SetDash(DashPatternBox.GenerateDashArray(dashPattern, BrushWidth), 0.0); if (path != null) { g.AppendPath (path); (path as IDisposable).Dispose (); path = null; } g.ClosePath (); g.LineWidth = BrushWidth; g.FillRule = FillRule.EvenOdd; if (FillShape && StrokeShape) { g.SetSourceColor (fill_color); g.FillPreserve (); g.SetSourceColor (outline_color); g.Stroke (); } else if (FillShape) { g.SetSourceColor (outline_color); g.FillPreserve(); g.SetSourceColor (outline_color); g.Stroke(); } else { g.SetSourceColor (outline_color); g.Stroke (); } } if (surface_modified) PintaCore.History.PushNewItem (new SimpleHistoryItem (Icon, Name, undo_surface, doc.CurrentUserLayerIndex)); else if (undo_surface != null) (undo_surface as IDisposable).Dispose (); surface_modified = false; doc.Workspace.Invalidate (); }
public virtual void Render(Context cr, Gdk.Rectangle area, Color color, bool showEmptyStars, bool isHovering, int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity) { if (Value == MinRating && !isHovering && !showEmptyStars) { return; } cr.Save (); Cairo.Color fill_color = color; fill_color.A = fillOpacity; Cairo.Color stroke_color = fill_color; stroke_color.A = strokeOpacity; Cairo.Color hover_fill_color = fill_color; hover_fill_color.A = hoverFillOpacity; double x, y; ComputePosition (area, out x, out y); cr.LineWidth = 1.0; cr.Translate (0.5, 0.5); for (int i = MinRating + 1, s = isHovering || showEmptyStars ? MaxRating : Value; i <= s; i++, x += Size) { bool fill = i <= Value && Value > MinRating; bool hover_fill = i <= hoverValue && hoverValue > MinRating; double scale = fill || hover_fill ? Size : Size - 2; double ofs = fill || hover_fill ? 0 : 1; for (int p = 0, n = star_plot.GetLength (0); p < n; p++) { double px = x + ofs + star_plot[p, 0] * scale; double py = y + ofs + star_plot[p, 1] * scale; if (p == 0) { cr.MoveTo (px, py); } else { cr.LineTo (px, py); } } cr.ClosePath (); if (fill || hover_fill) { if (!isHovering || hoverValue >= Value) { cr.SetSourceColor (fill ? fill_color : hover_fill_color); } else { cr.SetSourceColor (hover_fill ? fill_color : hover_fill_color); } cr.Fill (); } else { cr.SetSourceColor (stroke_color); cr.Stroke (); } } cr.Restore (); }
protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask) { outline_color = PintaCore.Palette.PrimaryColor; fill_color = PintaCore.Palette.SecondaryColor; } else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask) { outline_color = PintaCore.Palette.SecondaryColor; fill_color = PintaCore.Palette.PrimaryColor; } else { last_point = point_empty; return; } int x = (int)point.X; int y = (int)point.Y; if (last_point.Equals (point_empty)) { last_point = new Point (x, y); return; } if (doc.Workspace.PointInCanvas (point)) surface_modified = true; doc.ToolLayer.Clear (); ImageSurface surf = doc.ToolLayer.Surface; using (Context g = new Context (surf)) { doc.Selection.Clip(g); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.SetDash(DashPatternBox.GenerateDashArray(dashPattern, BrushWidth), 0.0); if (path != null) { g.AppendPath (path); (path as IDisposable).Dispose (); } else { g.MoveTo (x, y); } g.LineTo (x, y); path = g.CopyPath (); g.ClosePath (); g.LineWidth = BrushWidth; g.FillRule = FillRule.EvenOdd; if (FillShape && StrokeShape) { g.SetSourceColor (fill_color); g.FillPreserve (); g.SetSourceColor (outline_color); g.Stroke (); } else if (FillShape) { g.SetSourceColor (outline_color); g.FillPreserve(); g.SetSourceColor (outline_color); g.Stroke(); } else { g.SetSourceColor (outline_color); g.Stroke (); } } doc.Workspace.Invalidate (); last_point = new Point (x, y); }
protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if (mouse_button == 1) { stroke_color = PintaCore.Palette.PrimaryColor; } else if (mouse_button == 3) { stroke_color = PintaCore.Palette.SecondaryColor; } else { last_point = point_empty; return; } // TODO: also multiply by pressure stroke_color = new Color (stroke_color.R, stroke_color.G, stroke_color.B, stroke_color.A * active_brush.StrokeAlphaMultiplier); int x = (int)point.X; int y = (int)point.Y; if (last_point.Equals (point_empty)) last_point = new Point (x, y); if (doc.Workspace.PointInCanvas (point)) surface_modified = true; var surf = doc.CurrentUserLayer.Surface; var invalidate_rect = Gdk.Rectangle.Zero; var brush_width = BrushWidth; using (var g = new Context (surf)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.LineWidth = brush_width; g.LineJoin = LineJoin.Round; g.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round; g.SetSourceColor (stroke_color); invalidate_rect = active_brush.DoMouseMove (g, stroke_color, surf, x, y, last_point.X, last_point.Y); } // If we draw partially offscreen, Cairo gives us a bogus // dirty rectangle, so redraw everything. if (doc.Workspace.IsPartiallyOffscreen (invalidate_rect)) { doc.Workspace.Invalidate (); } else { doc.Workspace.Invalidate (doc.ClampToImageSize (invalidate_rect)); } last_point = new Point (x, y); }
public override void DrawListBackground (Context cr, Gdk.Rectangle alloc, Color color) { color.A = Context.FillAlpha; cr.SetSourceColor (color); cr.Rectangle (alloc.X, alloc.Y, alloc.Width, alloc.Height); cr.Fill (); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if (mouse_button <= 0) { last_point = point_empty; return; } int x = (int)point.X; int y = (int)point.Y; if (last_point.Equals (point_empty)) last_point = new Point (x, y); if (doc.Workspace.PointInCanvas (point)) surface_modified = true; ImageSurface surf = doc.CurrentUserLayer.Surface; using (Context g = new Context (surf)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; // Adding 0.5 forces cairo into the correct square: // See https://bugs.launchpad.net/bugs/672232 g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5); g.LineTo (x + 0.5, y + 0.5); // Right-click is erase to background color, left-click is transparent if (mouse_button == 3) g.SetSourceColor (PintaCore.Palette.SecondaryColor); else g.Operator = Operator.Clear; g.LineWidth = BrushWidth; g.LineJoin = LineJoin.Round; g.LineCap = LineCap.Round; g.Stroke (); } Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y)); if (doc.Workspace.IsPartiallyOffscreen (r)) { doc.Workspace.Invalidate (); } else { doc.Workspace.Invalidate (doc.ClampToImageSize (r)); } last_point = new Point (x, y); }
private void DrawGrid (Context g) { g.SetSourceColor (new Color (0.05, 0.05, 0.05)); g.SetDash (new double[] {4, 4}, 2); g.LineWidth = 1; for (int i = 1; i < 4; i++) { g.MoveTo (i * size / 4, 0); g.LineTo (i * size / 4, size); g.MoveTo (0, i * size / 4); g.LineTo (size, i * size / 4); } g.MoveTo (0, size - 1); g.LineTo (size - 1, 0); g.Stroke (); g.SetDash (new double[] {}, 0); }
private void DrawSpline (Context g) { var infos = GetDrawingInfos (); foreach (var controlPoints in ControlPoints) { int points = controlPoints.Count; SplineInterpolator interpolator = new SplineInterpolator (); IList<int> xa = controlPoints.Keys; IList<int> ya = controlPoints.Values; PointD[] line = new PointD [size]; for (int i = 0; i < points; i++) { interpolator.Add (xa [i], ya [i]); } for (int i = 0; i < line.Length; i++) { line[i].X = (float)i; line[i].Y = (float)(Utility.Clamp(size - 1 - interpolator.Interpolate (i), 0, size - 1)); } g.LineWidth = 2; g.LineJoin = LineJoin.Round; g.MoveTo (line [0]); for (int i = 1; i < line.Length; i++) g.LineTo (line [i]); infos.MoveNext (); var info = infos.Current; g.SetSourceColor (info.Color); g.LineWidth = info.IsActive ? 2 : 1; g.Stroke (); } }