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(); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { using (Context cg = Gdk.CairoHelper.Create(args.Window)) { Win32GDI GDI_Win32 = Win32GDI.getInstance(); if (GDI_Win32.isAvailable()) { System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); IntPtr hdc = wg.GetHdc(); int i = 0; int n = 3; int w = 16; int h = 16; Rect[] rects = new Rect[n]; /* Test Case 1 */ rects[i].x1 = 0; rects[i].y1 = 0; rects[i].x2 = w; rects[i].y2 = h; i++; /* Test Case 2 */ rects[i].x1 = w * i + 3; rects[i].y1 = 0; rects[i].x2 = w * (i + 1) - 3; rects[i].y2 = h; i++; /* Test Case 3 */ rects[i].x1 = w * i; rects[i].y1 = 0 + 3; rects[i].x2 = w * (i + 1); rects[i].y2 = h - 3; i++; /* Fill Area with White */ cg.Color = new Cairo.Color(255, 255, 255); Cairo.Rectangle rect = new Cairo.Rectangle(0, 0, n * w, h); cg.Rectangle(rect); cg.Fill(); cg.Stroke(); IntPtr blackSolidBrush = GDI_Win32.CreateSolidBrush(0); IntPtr oldBrush = GDI_Win32.SelectObject(hdc, blackSolidBrush); for (i = 0; i < n; i++) { GDI_Win32.Ellipse(hdc, rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); dumpText += "unsigned char ellipse_case_" + (i + 1) + "[" + w * h + "] = \n"; dumpText += dumpPixelArea(GDI_Win32, hdc, i * w, 0, w, h) + "\n"; } } } return(true); }
/// <summary> /// Determines whether the inner rectangle is completely inside the outer one. /// </summary> /// <param name="outerRectangle">The rectangle.</param> /// <param name="innerRectangle">The inner rectangle.</param> /// <returns> /// <c>true</c> if [contains] [the specified rectangle]; otherwise, <c>false</c>. /// </returns> public static bool Contains( this Rectangle outerRectangle, Rectangle innerRectangle) { // If the inner rectangle starts outside of the outer, then return false. if (outerRectangle.X > innerRectangle.X || outerRectangle.Y > innerRectangle.Y) { return false; } // Make sure the right and bottom sides are within the outer. double innerRight = innerRectangle.X + innerRectangle.Width; double outerRight = outerRectangle.X + outerRectangle.Width; double innerBottom = innerRectangle.Y + innerRectangle.Height; double outerBottom = outerRectangle.Y + outerRectangle.Height; if (innerRight > outerRight || innerBottom > outerBottom) { return false; } // At this point, the inner rectangle is completely inside the outer. return true; }
public override void DrawContent(Cairo.Context Context, Cairo.Rectangle Area) { Context.Color = new Color(0, 0, 0); Pango.CairoHelper.UpdateLayout(Context, textLayout); Context.MoveTo(Area.X, Area.Y); Pango.CairoHelper.ShowLayout(Context, textLayout); }
void DrawButtonTabs(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.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); return; } int topPadding = 2; if (Active || HoverPosition.X >= 0) { cr.NewPath(); cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); cr.ClosePath(); if (Active) { cr.Color = (HslColor)parent.Style.Background(StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Dark(StateType.Normal); color.L *= 1.1; gradient.AddColorStop(0, color); color.L *= 1.1; gradient.AddColorStop(1, color); cr.Pattern = gradient; } if (!Active) { cr.Fill(); } else { cr.FillPreserve(); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); } } cr.Save(); cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding); cr.Color = (HslColor)parent.Style.Text(StateType.Normal); cr.ShowLayout(layout); 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); } }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); Cairo.Rectangle desiredRect = GetTotalBounds(); if (Halign == Gtk.Align.Center || Halign == Gtk.Align.Fill) { XOffset = (int)(((allocation.Width) - desiredRect.Width) / 2); } else if (Halign == Gtk.Align.Start) { XOffset = 0; } else { throw new NotImplementedException(); } if (Valign == Gtk.Align.Center || Valign == Gtk.Align.Fill) { YOffset = (int)(((allocation.Height) - desiredRect.Height) / 2); } else if (Valign == Gtk.Align.Start) { YOffset = 0; } else { throw new NotImplementedException(); } }
public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight) { context.Context.Translate(0, 0.5); int draw_x = 0; foreach (int i in AttributesForBoundObject) { Gdk.Pixbuf render_pixbuf = pixbufs[i]; Cairo.Rectangle pixbuf_area = new Cairo.Rectangle(draw_x, (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height); if (!context.Opaque) { context.Context.Save(); } Gdk.CairoHelper.SetSourcePixbuf(context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y); context.Context.Rectangle(pixbuf_area); if (!context.Opaque) { context.Context.Clip(); context.Context.PaintWithAlpha(0.5); context.Context.Restore(); } else { context.Context.Fill(); } draw_x += render_pixbuf.Width; } }
protected override bool OnExposeEvent(Gdk.EventExpose args) { using (Context cg = Gdk.CairoHelper.Create (args.Window)) { Win32GDI GDI_Win32 = Win32GDI.getInstance(); if (GDI_Win32.isAvailable()) { System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); IntPtr hdc = wg.GetHdc(); int i = 0; int n = 3; int w = 16; int h = 16; Rect[] rects = new Rect[n]; /* Test Case 1 */ rects[i].x1 = 0; rects[i].y1 = 0; rects[i].x2 = w; rects[i].y2 = h; i++; /* Test Case 2 */ rects[i].x1 = w * i + 3; rects[i].y1 = 0; rects[i].x2 = w * (i + 1) - 3; rects[i].y2 = h; i++; /* Test Case 3 */ rects[i].x1 = w * i; rects[i].y1 = 0 + 3; rects[i].x2 = w * (i + 1); rects[i].y2 = h - 3; i++; /* Fill Area with White */ cg.Color = new Cairo.Color(255,255,255); Cairo.Rectangle rect = new Cairo.Rectangle(0, 0, n * w, h); cg.Rectangle(rect); cg.Fill(); cg.Stroke(); IntPtr blackSolidBrush = GDI_Win32.CreateSolidBrush(0); IntPtr oldBrush = GDI_Win32.SelectObject(hdc, blackSolidBrush); for (i = 0; i < n; i++) { GDI_Win32.Ellipse(hdc, rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); dumpText += "unsigned char ellipse_case_" + (i + 1) + "[" + w * h + "] = \n"; dumpText += dumpPixelArea(GDI_Win32, hdc, i * w, 0, w, h) + "\n"; } } } return true; }
protected override Gdk.Rectangle OnMouseMove(int x, int y, int lastX, int lastY) { int size = Random.Next (2, (int)G.LineWidth); Rectangle r = new Rectangle (x - Random.Next (-15, 15), y - Random.Next (-15, 15), size, size); double rx = r.Width / 2; double ry = r.Height / 2; double cx = r.X + rx; double cy = r.Y + ry; double c1 = 0.552285; G.Save (); G.MoveTo (cx + rx, cy); G.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry); G.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy); G.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry); G.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy); G.ClosePath (); Rectangle dirty = G.StrokeExtents (); G.Fill (); G.Restore (); return dirty.ToGdkRectangle (); }
/// <summary> /// Used to set the adjustments on the scrollbars for the text editor /// </summary> private void SetAdjustments() { // We have to have a size and an adjustment. if (verticalAdjustment == null || Renderer == null) { return; } // If the text width is negative, then we can't format. if (TextWidth < 0) { return; } // Set the line buffer's width and then request the height for all // the lines in the buffer. Renderer.Width = TextWidth; int height = Renderer.GetLineLayoutHeight(0, Int32.MaxValue); // Set the adjustments based on those values. int lineHeight = Renderer.GetLineLayoutHeight(); verticalAdjustment.SetBounds( 0.0, height, lineHeight, (int)(Allocation.Height / 2.0), Allocation.Height); // Figure out the scroll padding. int scrollPaddingHeight = lineHeight * editorViewSettings.CaretScrollPad; scrollPaddingRegion = new Rectangle( 0, scrollPaddingHeight, Allocation.Width, Allocation.Height - scrollPaddingHeight * 2); }
public WarpSpiral(Rectangle rect) { if (rect == null) throw new ArgumentNullException("rect"); _rect = rect; }
}
// Most of these functions return an affected area // This can be ignored if you don't need it #region context public static Rectangle DrawRectangle (this Context g, Rectangle r, Color color, int lineWidth) { // Put it on a pixel line if (lineWidth == 1) r = new Rectangle (r.X - 0.5, r.Y - 0.5, r.Width, r.Height); g.Save (); g.MoveTo (r.X, r.Y); g.LineTo (r.X + r.Width, r.Y); g.LineTo (r.X + r.Width, r.Y + r.Height); g.LineTo (r.X, r.Y + r.Height); g.LineTo (r.X, r.Y); g.Color = color; g.LineWidth = lineWidth; g.LineCap = LineCap.Square; Rectangle dirty = g.StrokeExtents (); g.Stroke (); g.Restore (); return dirty; }
public ImageView(MonoReports.Model.Controls.Image image,ImageRenderer renderer, SectionView parentSection) : base(image) { this.ParentSection = parentSection; AbsoluteBound = new Rectangle (parentSection.AbsoluteDrawingStartPoint.X + image.Location.X, parentSection.AbsoluteDrawingStartPoint.Y + image.Location.Y, image.Width, image.Height); ImageRenderer = renderer; }
private void DrawLine(int x1, int y1, int x2, int y2) { Cairo.Rectangle rect = new Cairo.Rectangle(Math.Min(x1, x2) - lineWidth / 2, Math.Min(y1, y2) - lineWidth / 2, Math.Abs(x1 - x2) + lineWidth, Math.Abs(y1 - y2) + lineWidth); using (Context c = CairoHelper.Create(drawingarea.GdkWindow)) { c.Color = new Cairo.Color(foreground.Red, foreground.Green, foreground.Blue, 1); c.Rectangle(rect); c.LineWidth = lineWidth; c.LineCap = LineCap.Round; c.LineJoin = LineJoin.Round; c.StrokePreserve(); c.Fill(); } using (Context c = CairoHelper.Create(shape)) { DrawCairoLine(c, x1, y1, x2, y2, opaque); } using (Context c = CairoHelper.Create(pixmap)) { DrawCairoLine(c, x1, y1, x2, y2, foreground); } modified = true; }
public ImageView(MonoReports.Model.Controls.Image image, SectionView parentSection, PixbufRepository pixbufRepository) : base(image) { this.ParentSection = parentSection; AbsoluteBound = new Rectangle (parentSection.AbsoluteDrawingStartPoint.X + image.Location.X, parentSection.AbsoluteDrawingStartPoint.Y + image.Location.Y, image.Width, image.Height); ImageRenderer = new ImageRenderer(){ PixbufRepository = pixbufRepository, DesignMode = true}; }
public static Rectangle DrawRectangle(this Cairo.Context g, Cairo.Rectangle r, Cairo.Color color, int lineWidth) { // Put it on a pixel line if (lineWidth == 1) { r = new Rectangle(r.X - 0.5, r.Y - 0.5, r.Width, r.Height); } g.Save(); g.MoveTo(r.X, r.Y); g.LineTo(r.X + r.Width, r.Y); g.LineTo(r.X + r.Width, r.Y + r.Height); g.LineTo(r.X, r.Y + r.Height); g.LineTo(r.X, r.Y); g.Color = color; g.LineWidth = lineWidth; g.LineCap = LineCap.Square; Rectangle dirty = g.StrokeExtents(); g.Stroke(); g.Restore(); return(dirty); }
protected void DrawBackground(Cairo.Context cr) { var totalRect = GetTotalBounds(); cr.SetSourceColor(BackgroundColor); cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height); cr.Fill(); cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Surface != null) { cr.SetSource(Surface, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } else if (Image != null) { using (Surface source = new BitmapSurface(Image)) { cr.SetSource(source, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } } else { Cairo.Rectangle extents = cr.ClipExtents(); for (int i = 0; i < Width * Height; i++) { int tileX = i % Width; int tileY = i / Width; Cairo.Rectangle rect = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false); if (!CairoHelper.RectsOverlap(extents, rect)) { continue; } cr.Save(); cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY); cr.Rectangle(0, 0, TileWidth, TileHeight); cr.Clip(); TileDrawer(i, cr); cr.Restore(); } } cr.Restore(); // Undo scale, offset }
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 WarpCurl(TextExtents text, Rectangle rect) { if (text == null) throw new ArgumentNullException("text"); if (rect == null) throw new ArgumentNullException("rect"); _rect = rect; _extents = text; }
protected override Rectangle DrawShape(Rectangle r, Layer l) { Document doc = PintaCore.Workspace.ActiveDocument; doc.Selection.CreateEllipseSelection(l.Surface, r); return r; }
public SubreportView(MonoReports.Model.Controls.SubReport subreport,SubreportRenderer renderer, SectionView parentSection) : base(subreport) { this.subreport = subreport; this.ParentSection = parentSection; AbsoluteBound = new Rectangle (parentSection.AbsoluteDrawingStartPoint.X + subreport.Location.X, parentSection.AbsoluteDrawingStartPoint.Y + subreport.Location.Y, subreport.Width, subreport.Height); SubreportRenderer = renderer; }
public TextBlockView(TextBlock textBlock,SectionView parentSection) : base(textBlock) { this.ParentSection = parentSection; AbsoluteBound = new Rectangle (parentSection.AbsoluteDrawingStartPoint.X + textBlock.Location.X, parentSection.AbsoluteDrawingStartPoint.Y + textBlock.Location.Y, textBlock.Width, textBlock.Height); TextBlockRenderer = new TextBlockRenderer(){ DesignMode = true}; }
public void Render(Cairo.Context c, MonoReports.Model.Controls.Control control) { Section section = control as Section; Rectangle borderRect; c.Save (); borderRect = new Rectangle (section.Location.X * unitMulitipier , section.Location.Y * unitMulitipier , section.Width * unitMulitipier, section.Height * unitMulitipier); c.FillRectangle (borderRect, section.BackgroundColor.ToCairoColor()); c.Restore (); }
public void ResetSelectionPaths() { var rect = new Cairo.Rectangle(0, 0, ImageSize.Width, ImageSize.Height); Selection.CreateRectangleSelection(rect); PreviousSelection.CreateRectangleSelection(rect); ShowSelection = false; }
protected override Rectangle DrawShape(Rectangle r, Layer l) { Document doc = PintaCore.Workspace.ActiveDocument; doc.Selection.CreateRectangleSelection(l.Surface, r); // Add some padding for invalidation return new Rectangle (r.X, r.Y, r.Width + 2, r.Height + 2); }
public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle) { switch (parent.VisualStyle) { case TabstripVisualStyle.CurveTabs: DrawCurveTabs(cr, rectangle); break; case TabstripVisualStyle.Buttons: DrawButtonTabs(cr, rectangle); break; } }
// Methods // Check if the given "real" position (in pixels) is in bounds. This ALSO checks that the // index that it's hovering over does not exceed MaxIndex. public bool IsInBounds(int x, int y, bool scale = true, bool offset = true) { Cairo.Rectangle p = GetTotalBounds(scale: scale, offset: offset); if (!(x >= p.X && y >= p.Y && x < p.X + p.Width && y < p.Y + p.Height)) { return(false); } return(GetGridIndex(x, y) <= MaxIndex); }
void DrawCurveTabs(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { return; } cr.MoveTo(rectangle.X, rectangle.Y); double bottom = rectangle.Y + rectangle.Height - 1; cr.CurveTo( rectangle.X + SpacerWidth / 2, rectangle.Y, rectangle.X + SpacerWidth / 2, bottom, rectangle.X + SpacerWidth, bottom); cr.LineTo(rectangle.X + rectangle.Width - SpacerWidth, bottom); cr.CurveTo( rectangle.X + rectangle.Width - SpacerWidth / 2, bottom, rectangle.X + rectangle.Width - SpacerWidth / 2, rectangle.Y, rectangle.X + rectangle.Width, rectangle.Y); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.StrokePreserve(); cr.ClosePath(); if (Active) { cr.Color = (HslColor)parent.Style.Background(StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Mid(StateType.Normal); color.L *= 1.05; gradient.AddColorStop(0, color); color.L *= 1.07; gradient.AddColorStop(1, color); cr.Pattern = gradient; } else { cr.Color = (HslColor)parent.Style.Mid(StateType.Normal); } cr.Fill(); cr.Save(); cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2); cr.Color = (HslColor)parent.Style.Text(StateType.Normal); cr.ShowLayout(layout); cr.Restore(); }
public void Render(Layer layer) { double scale_factor = (1.0 / PintaCore.Workspace.ActiveWorkspace.Scale); using (Context g = new Context(layer.Surface)) { var rect = new Cairo.Rectangle(Position.X - scale_factor * 2, Position.Y - scale_factor * 2, scale_factor * 4, scale_factor * 4); g.FillStrokedRectangle(rect, FillColor, StrokeColor, 1); } }
private void RoundedRect(Cairo.Context cr, Cairo.Rectangle rect, double r) { var rightAngle = Math.PI / 2.0; cr.NewPath(); cr.Arc(rect.X + rect.Width - r, rect.Y + r, r, -rightAngle, 0); cr.Arc(rect.X + rect.Width - r, rect.Y + rect.Height - r, r, 0, rightAngle); cr.Arc(rect.X + r, rect.Y + rect.Height - r, r, rightAngle, rightAngle * 2); cr.Arc(rect.X + r, rect.Y + r, r, rightAngle * 2, rightAngle * 3); cr.ClosePath(); }
protected void RefreshHandler(Cairo.Rectangle r) { controls[0].Position = new PointD(shape_origin.X, shape_origin.Y); controls[1].Position = new PointD(shape_origin.X, shape_end.Y); controls[2].Position = new PointD(shape_end.X, shape_origin.Y); controls[3].Position = new PointD(shape_end.X, shape_end.Y); controls[4].Position = new PointD(shape_origin.X, (shape_origin.Y + shape_end.Y) / 2); controls[5].Position = new PointD((shape_origin.X + shape_end.X) / 2, shape_origin.Y); controls[6].Position = new PointD(shape_end.X, (shape_origin.Y + shape_end.Y) / 2); controls[7].Position = new PointD((shape_origin.X + shape_end.X) / 2, shape_end.Y); }
protected override Rectangle DrawShape(Rectangle r, Layer l) { Path path = PintaCore.Layers.SelectionPath; using (Context g = new Context (l.Surface)) PintaCore.Layers.SelectionPath = g.CreateEllipsePath (r); (path as IDisposable).Dispose (); return r; }
public void Render(Cairo.Context c, MonoReports.Model.Controls.Control control) { SubReport subreport = control as SubReport; Rectangle borderRect; c.Save (); borderRect = new Rectangle (subreport.Location.X, subreport.Location.Y, subreport.Width, subreport.Height); c.ClipRectangle (borderRect); borderRect = new Rectangle (subreport.Location.X, subreport.Location.Y, subreport.Width, subreport.Height); c.FillRectangle (borderRect, subreport.BackgroundColor.ToCairoColor ()); c.Restore (); }
protected override Rectangle DrawShape(Rectangle r, Layer l) { Path path = PintaCore.Layers.SelectionPath; using (Context g = new Context (l.Surface)) PintaCore.Layers.SelectionPath = g.CreateRectanglePath (r); (path as IDisposable).Dispose (); // Add some padding for invalidation return new Rectangle (r.X, r.Y, r.Width + 2, r.Height + 2); }
public static void Render (Context cr, Rectangle box, double xalign, double yalign, Color innerColor, Color outerColor) { // virtual size of the figure we will draw below on the 1:1 scale double original_width = 8; double original_height = 12; // figure out the scale dimensions of the bounding box and the glyph double box_size = Math.Min (box.Width, box.Height); double original_size = Math.Max (original_width, original_height); // create a scale for the box (ratio between virtual glyph size and the box), // then re-scale to account for the extra size that will be added via stroke. // glyph_scale is the stroke width and the actual transformation size double box_scale = box_size / original_size; double glyph_scale = Math.Floor ((box_size - box_scale) / original_size); // compute the alignment to the pixel grid for the stroke/scale double pixel_align = Math.Floor (glyph_scale + 0.5) / 2.0; // figure out the actual size in pixels of the glyph double actual_width = glyph_scale * original_width + 2 * Math.Floor (pixel_align); double actual_height = glyph_scale * original_height + 2 * Math.Floor (pixel_align); // compute the offset accounting for box, grid alignment, and figure alignment double tx = box.X + pixel_align + Math.Round ((box.Width - actual_width) * xalign); double ty = box.Y + pixel_align + Math.Round ((box.Height - actual_height) * yalign); // save the context, and transform the current/new context cr.Save (); cr.Translate (tx, ty); cr.Scale (glyph_scale, glyph_scale); // define how the strokes look cr.LineWidth = 1; cr.LineCap = LineCap.Round; cr.LineJoin = LineJoin.Round; // inner 'b' note cr.Color = innerColor; cr.MoveTo (0, 2); cr.LineTo (2, 0); cr.Arc (4, 8, 2, Math.PI, Math.PI * 3); cr.Stroke (); // outer 'cut' circle cr.Color = outerColor; cr.Arc (4, 8, 4, Math.PI * 1.5, Math.PI * 1.12); cr.Stroke (); cr.Restore (); }
protected PointD GetContentStart(PointD start, SizeD visibleSize, SizeD contentsSize) { PointD startOffset = GetContentStart(); PointD endOffset = GetContentEnd(); Cairo.Rectangle contentArea = new Cairo.Rectangle ( start.X + startOffset.X, start.Y + startOffset.Y, visibleSize.Width - startOffset.X - endOffset.X, visibleSize.Height - startOffset.Y - endOffset.Y ); HorizontalAlignment hAlign = distribution.GetColumnsUsed() > 1 ? HorizontalAlignment.Left : style.HAlign; VerticalAlignment vAlign = distribution.GetRowsUsed() > 1 ? VerticalAlignment.Top : style.VAlign; PointD ret = new PointD(0f, 0f); switch (hAlign) { case HorizontalAlignment.Right: ret.X = contentArea.X + (contentArea.Width - contentsSize.Width); break; case HorizontalAlignment.Center: ret.X = contentArea.X + (contentArea.Width - contentsSize.Width) / 2; break; default: ret.X = contentArea.X; break; } switch (vAlign) { case VerticalAlignment.Bottom: ret.Y = contentArea.Y + (contentArea.Height - contentsSize.Height); break; case VerticalAlignment.Center: ret.Y = contentArea.Y + (contentArea.Height - contentsSize.Height) / 2; break; default: ret.Y = contentArea.Y; break; } return(ret); }
protected override Rectangle DrawShape(Rectangle r, Layer l) { Document doc = PintaCore.Workspace.ActiveDocument; Path path = doc.SelectionPath; using (Context g = new Context (l.Surface)) doc.SelectionPath = g.CreateEllipsePath (r); (path as IDisposable).Dispose (); return r; }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); if (pages == null) { return(false); } int width = (int)(report.PageWidthPoints * Scale); int height = (int)(report.PageHeightPoints * Scale); Cairo.Rectangle rep_r = new Cairo.Rectangle(1, 1, width - 1, height - 1); int widgetWidth, widgetHeight; ev.Window.GetSize(out widgetWidth, out widgetHeight); using (Context g = Gdk.CairoHelper.Create(this.GdkWindow)) using (ImageSurface rep_s = new ImageSurface(Format.Argb32, width, height)) using (Context rep_g = new Context(rep_s)) using (ImageSurface shadow_s = rep_s.Clone()) using (Context shadow_g = new Context(shadow_s)) { g.Translate(((widgetWidth - width) / 2) - rep_padding, 0); shadow_g.Pattern = new SolidPattern(new Color(0.6, 0.6, 0.6)); shadow_g.Paint(); g.SetSourceSurface(shadow_s, shadow_padding, shadow_padding); g.Paint(); rep_g.Pattern = new SolidPattern(new Color(1, 1, 1)); rep_g.Paint(); rep_g.DrawRectangle(rep_r, new Color(0.1, 0.1, 0.1), 1); SetItemsHitArea(); if (selectedItem != null) { rep_g.Pattern = new SolidPattern(new Color(0.4, 0.4, 1)); rep_g.Rectangle(GetSelectedItemRectangle()); rep_g.Fill(); } using (var render = new RenderCairo(rep_g, Scale)) { render.RunPage(pages); } g.SetSourceSurface(rep_s, rep_padding, rep_padding); g.Paint(); } return(true); }
Cairo.Rectangle DeskAreaOnIcon(int width, int height, int column, int row) { double BorderPercent = 0.05; double Border = height * BorderPercent; double boxWidth, boxHeight; Cairo.Rectangle area; boxWidth = (width - 2 * Border) / DeskGrid.GetLength(0); boxHeight = (height - 2 * Border) / DeskGrid.GetLength(1); area = new Cairo.Rectangle(boxWidth * column + Border, boxHeight * row + Border, boxWidth, boxHeight); return(area); }
public Rectangle GetArea(Widget relativeTo) { Widget parent = this; Rectangle alloc = this.Allocation; while(parent != relativeTo) { parent = parent.Parent; if(parent == null) throw new InvalidOperationException(); alloc = new Rectangle(parent.Allocation.X + alloc.X, parent.Allocation.Y + alloc.Y, alloc.Width, alloc.Height); } return alloc; }
public static bool ContainsPoint(this Cairo.Rectangle r, double x, double y) { if (x < r.X || x >= r.X + r.Width) { return(false); } if (y < r.Y || y >= r.Y + r.Height) { return(false); } return(true); }
private void CheckPoint (Rectangle rect, PointD point) { if (point.X < rect.X) { point.X = rect.X; } else if (point.X > rect.X + rect.Width) { point.X = rect.X + rect.Width; } if (point.Y < rect.Y) { point.Y = rect.Y; } else if (point.Y > rect.Y + rect.Height) { point.Y = rect.Y + rect.Height; } }
public static Path CreateRectanglePath (this Context g, Rectangle r) { g.Save (); g.MoveTo (r.X, r.Y); g.LineTo (r.X + r.Width, r.Y); g.LineTo (r.X + r.Width, r.Y + r.Height); g.LineTo (r.X, r.Y + r.Height); g.LineTo (r.X, r.Y); Path path = g.CopyPath (); g.Restore (); return path; }
protected override bool OnExposed(Context cr, Rectangle area) { cr.Save(); if(!base.OnExposed(cr, area)) { cr.Color = new Color(1.0, 0.0, 0.0); cr.SetFontSize(100.0); cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold); cr.ShowText(role.ToString()); cr.Restore(); return true; } cr.Restore(); return true; }
public WarpPerspective(IEnumerable<PointD> destPoints, Rectangle srcRect) { if (destPoints == null || destPoints.Count() != 4) throw new ArgumentException("destPoints"); if (srcRect == null) throw new ArgumentNullException("srcRect"); _pntSrc[0].X = _pntSrc[2].X = srcRect.GetLeft(); _pntSrc[1].X = _pntSrc[3].X = srcRect.GetRight(); _pntSrc[0].Y = _pntSrc[1].Y = srcRect.GetTop(); _pntSrc[2].Y = _pntSrc[3].Y = srcRect.GetBottom(); PreCalc(destPoints.ToArray(), _pntSrc); }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { Context cr = Gdk.CairoHelper.Create (this.GdkWindow); Cairo.Rectangle area = new Cairo.Rectangle (evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); Cairo.Rectangle allocation = new Cairo.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); Cairo.Rectangle contentArea = new Cairo.Rectangle (allocation.X + BorderWidth, allocation.Y + BorderWidth, allocation.Width - 2 * BorderWidth, allocation.Height - 2 * BorderWidth); cr.Rectangle (area); cr.Clip (); theme.DrawTile (cr, allocation, contentArea, this); DrawContent (cr, contentArea); return base.OnExposeEvent (evnt); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Context cr = Gdk.CairoHelper.Create(this.GdkWindow); Cairo.Rectangle area = new Cairo.Rectangle(evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); Cairo.Rectangle allocation = new Cairo.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); Cairo.Rectangle contentArea = new Cairo.Rectangle(allocation.X + BorderWidth, allocation.Y + BorderWidth, allocation.Width - 2 * BorderWidth, allocation.Height - 2 * BorderWidth); cr.Rectangle(area); cr.Clip(); theme.DrawTile(cr, allocation, contentArea, this); DrawContent(cr, contentArea); return(base.OnExposeEvent(evnt)); }
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(Styles.SubTabBarSeparatorColor.ToCairoColor()); cr.LineWidth = 1; cr.Stroke(); return; } if (Active || HoverPosition.X >= 0) { if (Active) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); cr.SetSourceColor(Styles.SubTabBarActiveBackgroundColor.ToCairoColor()); cr.Fill(); } else if (HoverPosition.X >= 0) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); cr.SetSourceColor(Styles.SubTabBarHoverBackgroundColor.ToCairoColor()); cr.Fill(); } } if (Active) { cr.SetSourceColor(Styles.SubTabBarActiveTextColor.ToCairoColor()); layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11, Pango.Weight.Bold); } else { cr.SetSourceColor(Styles.SubTabBarTextColor.ToCairoColor()); layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); } layout.Width = (int)rectangle.Width; cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1); Pango.CairoHelper.ShowLayout(cr, layout); }
void DrawFoldSegment(Cairo.Context ctx, double x, double y, bool isCollapsed) { 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); var useSolidColor = isCollapsed || FoldMarkerOcapitiy >= 1; var drawColor = background; if (!useSolidColor) { drawColor.A = FoldMarkerOcapitiy; } ctx.SetSourceColor(drawColor); ctx.FillPreserve(); drawColor = foldLine; if (!useSolidColor) { drawColor.A = FoldMarkerOcapitiy; } ctx.SetSourceColor(drawColor); ctx.Stroke(); drawColor = foreground; if (!useSolidColor) { drawColor.A = FoldMarkerOcapitiy; } ctx.DrawLine(drawColor, 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 (isCollapsed) { ctx.DrawLine(drawColor, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height * 2 / 10, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10); } }
protected override bool OnDrawn(Context cr) { base.OnDrawn(cr); if (size == Gdk.Size.Empty) { return(true); } var preview_size = Gdk.Size.Empty; var widget_size = Window.GetBounds(); // Figure out the dimensions of the preview to draw if (size.Width <= max_size && size.Height <= max_size) { preview_size = size; } else if (size.Width > size.Height) { preview_size = new Gdk.Size(max_size, (int)(max_size / ((float)size.Width / (float)size.Height))); } else { preview_size = new Gdk.Size((int)(max_size / ((float)size.Height / (float)size.Width)), max_size); } var r = new Cairo.Rectangle((widget_size.Width - preview_size.Width) / 2, (widget_size.Height - preview_size.Height) / 2, preview_size.Width, preview_size.Height); if (color.A == 0) { // Fill with transparent checkerboard pattern using (var pattern = CairoExtensions.CreateTransparentBackgroundPattern(16)) cr.FillRectangle(r, pattern); } else { // Fill with selected color cr.FillRectangle(r, color); } // Draw our canvas drop shadow cr.DrawRectangle(new Cairo.Rectangle(r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2), new Cairo.Color(.5, .5, .5), 1); cr.DrawRectangle(new Cairo.Rectangle(r.X - 2, r.Y - 2, r.Width + 4, r.Height + 4), new Cairo.Color(.8, .8, .8), 1); cr.DrawRectangle(new Cairo.Rectangle(r.X - 3, r.Y - 3, r.Width + 6, r.Height + 6), new Cairo.Color(.9, .9, .9), 1); return(true); }
protected virtual void OnPreviewDrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args) { DrawingArea area = (DrawingArea)o; if (designService.Report.Pages.Count > 0) { Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); cr.Antialias = Cairo.Antialias.None; reportRenderer.Context = cr; Cairo.Rectangle r = new Cairo.Rectangle(0, 0, designService.Report.WidthWithMargins, designService.Report.HeightWithMargins); cr.FillRectangle(r, backgroundPageColor); cr.Translate(designService.Report.Margin.Left, designService.Report.Margin.Top); reportRenderer.RenderPage(designService.Report.Pages [pageNumber]); area.SetSizeRequest((int)designService.Report.HeightWithMargins, (int)designService.Report.HeightWithMargins + 5); (cr as IDisposable).Dispose(); } }
protected override Rectangle DrawShape(Rectangle rect, Layer l) { Document doc = PintaCore.Workspace.ActiveDocument; Rectangle dirty; using (Context g = new Context (l.Surface)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; dirty = g.DrawLine (shape_origin, current_point , outline_color, BrushWidth); } return dirty; }
public override void Render(CellContext context, double cellWidth, double cellHeight) { TrackInfo track = BoundTrack; if (track == null) { return; } int icon_index = GetIconIndex(track); TooltipMarkup = icon_index == -1 ? null : StatusNames[icon_index]; if (icon_index < 0 || pixbufs == null || pixbufs[icon_index] == null) { return; } context.Context.Translate(0, 0.5); Gdk.Pixbuf render_pixbuf = pixbufs[icon_index]; Cairo.Rectangle pixbuf_area = new Cairo.Rectangle((cellWidth - render_pixbuf.Width) / 2, (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height); if (!context.Opaque) { context.Context.Save(); } Gdk.CairoHelper.SetSourcePixbuf(context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y); context.Context.Rectangle(pixbuf_area); if (!context.Opaque) { context.Context.Clip(); context.Context.PaintWithAlpha(0.5); context.Context.Restore(); } else { context.Context.Fill(); } }
public static unsafe void FillStencilByColor(ImageSurface surface, IBitVector2D stencil, ColorBgra cmp, int tolerance, out Rectangle boundingBox) { int top = int.MaxValue; int bottom = int.MinValue; int left = int.MaxValue; int right = int.MinValue; stencil.Clear (false); for (int y = 0; y < surface.Height; ++y) { bool foundPixelInRow = false; ColorBgra* ptr = surface.GetRowAddressUnchecked (y); for (int x = 0; x < surface.Width; ++x) { if (CheckColor (cmp, *ptr, tolerance)) { stencil.SetUnchecked (x, y, true); if (x < left) { left = x; } if (x > right) { right = x; } foundPixelInRow = true; } ++ptr; } if (foundPixelInRow) { if (y < top) { top = y; } if (y >= bottom) { bottom = y; } } } boundingBox = new Rectangle (left, top, right + 1, bottom + 1); }
public void ReDraw(Gdk.ModifierType state) { Document doc = PintaCore.Workspace.ActiveDocument; doc.ShowSelection = true; doc.ToolLayer.Hidden = false; bool constraint = (state & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask; if (constraint) { double dx = Math.Abs(shape_end.X - shape_origin.X); double dy = Math.Abs(shape_end.Y - shape_origin.Y); if (dx <= dy) { if (shape_end.X >= shape_origin.X) { shape_end.X = shape_origin.X + dy; } else { shape_end.X = shape_origin.X - dy; } } else if (shape_end.Y >= shape_origin.Y) { shape_end.Y = shape_origin.Y + dx; } else { shape_end.Y = shape_origin.Y - dx; } } Cairo.Rectangle rect = Utility.PointsToRectangle(shape_origin, shape_end, constraint); RefreshHandler(rect); Rectangle dirty = DrawShape(rect, doc.SelectionLayer); DrawHandler(doc.ToolLayer); doc.Workspace.Invalidate(); last_dirty = dirty; }
public static Rectangle FillRectangle (this Context g, Rectangle r, Color color) { g.Save (); g.MoveTo (r.X, r.Y); g.LineTo (r.X + r.Width, r.Y); g.LineTo (r.X + r.Width, r.Y + r.Height); g.LineTo (r.X, r.Y + r.Height); g.LineTo (r.X, r.Y); g.Color = color; Rectangle dirty = g.StrokeExtents (); g.Fill (); g.Restore (); return dirty; }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); if (pages == null) return false; int width = (int)(report.PageWidthPoints * Scale); int height = (int)(report.PageHeightPoints * Scale); Cairo.Rectangle rep_r = new Cairo.Rectangle(1, 1, width - 1, height - 1); int widgetWidth, widgetHeight; ev.Window.GetSize(out widgetWidth, out widgetHeight); using (Context g = Gdk.CairoHelper.Create(this.GdkWindow)) using (ImageSurface rep_s = new ImageSurface(Format.Argb32, width, height)) using (Context rep_g = new Context(rep_s)) using (ImageSurface shadow_s = rep_s.Clone()) using (Context shadow_g = new Context(shadow_s)) { g.Translate(((widgetWidth - width) / 2) - rep_padding, 0); shadow_g.Pattern = new SolidPattern(new Color(0.6, 0.6, 0.6)); shadow_g.Paint(); g.SetSourceSurface(shadow_s, shadow_padding, shadow_padding); g.Paint(); rep_g.Pattern = new SolidPattern(new Color(1, 1, 1)); rep_g.Paint(); rep_g.DrawRectangle(rep_r, new Color(0.1, 0.1, 0.1), 1); using (var render = new RenderCairo(rep_g, Scale)) { render.RunPage(pages); } g.SetSourceSurface(rep_s, rep_padding, rep_padding); g.Paint(); } return true; }
protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { int line_width = (int)g.LineWidth; int size; // we want a minimum size of 2 for the splatter (except for when the brush width is 1), since a splatter of size 1 is very small if (line_width == 1) { size = 1; } else { size = Random.Next (2, line_width); } Rectangle r = new Rectangle (x - Random.Next (-15, 15), y - Random.Next (-15, 15), size, size); double rx = r.Width / 2; double ry = r.Height / 2; double cx = r.X + rx; double cy = r.Y + ry; double c1 = 0.552285; g.Save (); g.MoveTo (cx + rx, cy); g.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry); g.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy); g.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry); g.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy); g.ClosePath (); Rectangle dirty = g.FixedStrokeExtents (); g.Fill (); g.Restore (); return dirty.ToGdkRectangle (); }