static void draw (Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI); gr.Clip (); gr.NewPath (); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale (1.0/w, 1.0/h); image.Show (gr, 0, 0); image.Destroy(); gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
protected override void onDraw(Cairo.Context gr) { Rectangle rBack = new Rectangle (Slot.Size); //rBack.Inflate (-Margin); // if (BorderWidth > 0) // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill (); if (BorderWidth > 0) { Foreground.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); } gr.Save (); if (ClipToClientRect) { //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); gr.Clip (); } if (child != null) child.Paint (ref gr); gr.Restore (); }
static void draw (Cairo.Context gr, int width, int height) { gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
void Draw (Cairo.Context ctx) { int tabArea = tabEndX - tabStartX; int x = GetRenderOffset (); int y = 0; int n = 0; Action<Cairo.Context> drawActive = c => {}; List<Action<Cairo.Context>> 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; } Gdk.Rectangle 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 RenderLineNumberIcon (Widget widget, Cairo.Context cr, Gdk.Rectangle cell_area, int markupHeight, int yOffset) { if (Frame == null) return; cr.Save (); #if CENTER_ROUNDED_RECTANGLE cr.Translate (cell_area.X + Padding, (cell_area.Y + (cell_area.Height - RoundedRectangleHeight) / 2.0)); #else cr.Translate (cell_area.X + Padding, cell_area.Y + Padding + yOffset); #endif cr.Antialias = Cairo.Antialias.Subpixel; cr.RoundedRectangle (0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Clip (); if (IsUserCode) cr.SetSourceRGBA (0.90, 0.60, 0.87, 1.0); // 230, 152, 223 else cr.SetSourceRGBA (0.77, 0.77, 0.77, 1.0); // 197, 197, 197 cr.RoundedRectangle (0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.Fill (); cr.SetSourceRGBA (0.0, 0.0, 0.0, 0.11); cr.RoundedRectangle (0.0, 0.0, RoundedRectangleWidth, RoundedRectangleHeight, RoundedRectangleRadius); cr.LineWidth = 2; cr.Stroke (); var lineNumber = !string.IsNullOrEmpty (Frame.File) ? Frame.Line : -1; using (var layout = PangoUtil.CreateLayout (widget, lineNumber != -1 ? lineNumber.ToString () : "???")) { layout.Alignment = Pango.Alignment.Left; layout.FontDescription = LineNumberFont; int width, height; layout.GetPixelSize (out width, out height); double y_offset = (RoundedRectangleHeight - height) / 2.0; double x_offset = (RoundedRectangleWidth - width) / 2.0; // render the text shadow cr.Save (); cr.SetSourceRGBA (0.0, 0.0, 0.0, 0.34); cr.Translate (x_offset, y_offset + 1); cr.ShowLayout (layout); cr.Restore (); cr.SetSourceRGBA (1.0, 1.0, 1.0, 1.0); cr.Translate (x_offset, y_offset); cr.ShowLayout (layout); } cr.Restore (); }
void ClipBackground (Cairo.Context context, Gdk.Rectangle region) { int rounding = (region.Height - 2) / 2; context.RoundedRectangle (region.X, region.Y + 2, region.Width, region.Height - 4, rounding); context.Clip (); }
protected override void OnRender (Cairo.Context context) { using (var layout = GetLayout ()) { int w, h; layout.GetPixelSize (out w, out h); int textX = 10; int textY = ((int)Height - h) / 2; if (CaretHighlightOffset != -1) { Pango.Rectangle rightStrongRect, rightRect; layout.GetCursorPos (Math.Max (CaretOffset, CaretHighlightOffset), out rightStrongRect, out rightRect); Pango.Rectangle leftStrongRect, leftRect; layout.GetCursorPos (Math.Min (CaretOffset, CaretHighlightOffset), out leftStrongRect, out leftRect); context.Rectangle (textX + Pango.Units.ToPixels (leftRect.X), textY + Pango.Units.ToPixels (leftRect.Y), Pango.Units.ToPixels (rightRect.X + rightRect.Width - leftRect.X), Pango.Units.ToPixels (leftRect.Height)); context.Color = HasFocus ? new Cairo.Color (0.8, 0.9, 1, Opacity) : new Cairo.Color (0.8, 0.8, 0.8, Opacity); context.Fill (); } context.MoveTo (textX, textY); context.Color = new Cairo.Color (0, 0, 0, Opacity); Pango.CairoHelper.ShowLayout (context, layout); if (CaretHighlightOffset == -1 && drawCaret) { Pango.Rectangle strongRect, weakRect; layout.GetCursorPos (CaretOffset, out strongRect, out weakRect); context.Rectangle (textX + Pango.Units.ToPixels (weakRect.X), textY + Pango.Units.ToPixels (weakRect.Y), 1, Pango.Units.ToPixels (weakRect.Height)); context.Color = new Cairo.Color (0, 0, 0, Opacity); context.Fill (); } } OnLayoutOutline (context); context.Clip (); base.OnRender (context); }
protected override bool OnDrawn(Cairo.Context cr) { if (!CairoHelper.ShouldDrawWindow (cr, Window)) { return base.OnDrawn (cr); } if (reflect) { CairoExtensions.PushGroup (cr); } cr.Operator = Operator.Over; cr.Translate (h_padding, 0); cr.Rectangle (0, 0, Allocation.Width - h_padding, Math.Max (2 * bar_height, bar_height + bar_label_spacing + layout_height)); cr.Clip (); Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height); cr.Save (); cr.Source = bar; cr.Paint (); cr.Restore (); if (reflect) { cr.Save (); cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * bar_height) + 1); cr.Transform (matrix); cr.Pattern = bar; LinearGradient mask = new LinearGradient (0, 0, 0, bar_height); mask.AddColorStop (0.25, new Color (0, 0, 0, 0)); mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125)); mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4)); mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7)); cr.Mask (mask); mask.Destroy (); cr.Restore (); CairoExtensions.PopGroupToSource (cr); cr.Paint (); } if (show_labels) { cr.Translate ((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2, bar_height + bar_label_spacing); RenderLabels (cr); } bar.Destroy (); return true; }
public void Render (Cairo.Context context, StatusArea.RenderArg arg) { context.CachedDraw (surface: ref backgroundSurface, region: arg.Allocation, draw: (c, o) => DrawBackground (c, new Gdk.Rectangle (0, 0, arg.Allocation.Width, arg.Allocation.Height))); if (arg.BuildAnimationOpacity > 0.001f) DrawBuildEffect (context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity); if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999) { DrawErrorAnimation (context, arg); } DrawBorder (context, arg.Allocation); if (arg.HoverProgress > 0.001f) { context.Clip (); int x1 = arg.Allocation.X + arg.MousePosition.X - 200; int x2 = x1 + 400; using (Cairo.LinearGradient gradient = new LinearGradient (x1, 0, x2, 0)) { Cairo.Color targetColor = Styles.StatusBarFill1Color; Cairo.Color transparentColor = targetColor; targetColor.A = .7; transparentColor.A = 0; targetColor.A = .7 * arg.HoverProgress; gradient.AddColorStop (0.0, transparentColor); gradient.AddColorStop (0.5, targetColor); gradient.AddColorStop (1.0, transparentColor); context.Pattern = gradient; context.Rectangle (x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height); context.Fill (); } context.ResetClip (); } else { context.NewPath (); } int progress_bar_x = arg.ChildAllocation.X; int progress_bar_width = arg.ChildAllocation.Width; if (arg.CurrentPixbuf != null) { int y = arg.Allocation.Y + (arg.Allocation.Height - arg.CurrentPixbuf.Height) / 2; Gdk.CairoHelper.SetSourcePixbuf (context, arg.CurrentPixbuf, arg.ChildAllocation.X, y); context.Paint (); progress_bar_x += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding; progress_bar_width -= arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding; } int center = arg.Allocation.Y + arg.Allocation.Height / 2; Gdk.Rectangle progressArea = new Gdk.Rectangle (progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight); if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0) { DrawProgressBar (context, arg.ProgressBarFraction, progressArea, arg); ClipProgressBar (context, progressArea); } int text_x = progress_bar_x + Styles.ProgressBarInnerPadding; int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2); double textTweenValue = arg.TextAnimationProgress; if (arg.LastText != null) { double opacity = Math.Max (0.0f, 1.0f - textTweenValue); DrawString (arg.LastText, arg.LastTextIsMarkup, context, text_x, center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg); } if (arg.CurrentText != null) { DrawString (arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x, center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min (textTweenValue, 1.0), arg.Pango, arg); } if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0) context.ResetClip (); }
protected override bool OnExposed(Cairo.Context cr, Cairo.Rectangle area) { Rectangle rectT = new Rectangle(0.0, 0.0, Allocation.Width, EdgeSize); Rectangle rectB = new Rectangle(0.0, Allocation.Height - EdgeSize, Allocation.Width, EdgeSize); Rectangle rectL = new Rectangle(0.0, 0.0, EdgeSize, Allocation.Height); Rectangle rectR = new Rectangle(Allocation.Width - EdgeSize, 0.0, EdgeSize, Allocation.Height); Rectangle areaT = Widget.Intersect(area, rectT); Rectangle areaB = Widget.Intersect(area, rectB); Rectangle areaL = Widget.Intersect(area, rectL); Rectangle areaR = Widget.Intersect(area, rectR); if(areaT.Width != 0.0 && areaT.Height != 0.0) { LinearGradient grT = new LinearGradient(0.0, 0.0, 0.0, EdgeSize); grT.AddColorStop(0.0, new Color(1.0, 1.0, 1.0, 1.0)); grT.AddColorStop(1.0, new Color(1.0, 1.0, 1.0, 0.0)); cr.Save(); cr.Pattern = grT; //cr.Rectangle(areaT); cr.NewPath(); cr.MoveTo(0.0, 0.0); cr.LineTo(Allocation.Width, 0.0); cr.LineTo(Allocation.Width - EdgeSize, EdgeSize); cr.LineTo(EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaB.Width != 0.0 && areaB.Height != 0.0) { LinearGradient grB = new LinearGradient(0.0, Allocation.Height, 0.0, Allocation.Height - EdgeSize); grB.AddColorStop(0.0, new Color(0.0, 0.0, 0.0, 1.0)); grB.AddColorStop(1.0, new Color(0.0, 0.0, 0.0, 0.0)); cr.Save(); cr.Pattern = grB; //cr.Rectangle(areaB); cr.MoveTo(0.0, Allocation.Height); cr.LineTo(Allocation.Width, Allocation.Height); cr.LineTo(Allocation.Width - EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(EdgeSize, Allocation.Height - EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaL.Width != 0.0 && areaL.Height != 0.0) { LinearGradient grL = new LinearGradient(0.0, 0.0, EdgeSize, 0.0); grL.AddColorStop(0.0, new Color(1.0, 1.0, 1.0, 1.0)); grL.AddColorStop(1.0, new Color(1.0, 1.0, 1.0, 0.0)); cr.Save(); cr.Pattern = grL; //cr.Rectangle(areaL); cr.MoveTo(0.0, 0.0); cr.LineTo(0.0, Allocation.Height); cr.LineTo(EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } if(areaR.Width != 0.0 && areaR.Height != 0.0) { LinearGradient grR = new LinearGradient(Allocation.Width, 0.0, Allocation.Width - EdgeSize, 0.0); grR.AddColorStop(0.0, new Color(0.0, 0.0, 0.0, 1.0)); grR.AddColorStop(1.0, new Color(0.0, 0.0, 0.0, 0.0)); cr.Save(); cr.Pattern = grR; //cr.Rectangle(areaR); cr.MoveTo(Allocation.Width, 0.0); cr.LineTo(Allocation.Width, Allocation.Height); cr.LineTo(Allocation.Width - EdgeSize, Allocation.Height - EdgeSize); cr.LineTo(Allocation.Width - EdgeSize, EdgeSize); cr.ClosePath(); cr.Clip(); cr.Paint(); cr.Restore(); } return true; }
// Used by the workspace drawing area expose render loop. // Takes care of the clipping. public void RenderLivePreviewLayer (Cairo.Context ctx, double opacity) { if (!IsEnabled) throw new InvalidOperationException ("Tried to render a live preview after live preview has ended."); // TODO remove seam around selection during live preview. ctx.Save (); if (selection_path != null) { // Paint area outsize of the selection path, with the pre-effect image. var imageSize = PintaCore.Workspace.ImageSize; ctx.Rectangle (0, 0, imageSize.Width, imageSize.Height); ctx.AppendPath (selection_path); ctx.Clip (); layer.Draw(ctx, layer.Surface, opacity); ctx.ResetClip (); // Paint area inside the selection path, with the post-effect image. ctx.AppendPath (selection_path); ctx.Clip (); layer.Draw(ctx, live_preview_surface, opacity); ctx.PaintWithAlpha (opacity); ctx.AppendPath (selection_path); ctx.FillRule = Cairo.FillRule.EvenOdd; ctx.Clip (); } else { layer.Draw(ctx, live_preview_surface, opacity); } ctx.Restore (); }
private static unsafe void Renderer() { int tmp_mouse_X, tmp_mouse_Y; int old_mouse_X = -1, old_mouse_Y = -1; bool update; while (true) { tmp_mouse_X = Mouse_X; tmp_mouse_Y = Mouse_Y; update = false; Cairo.Save(MainContext); Cairo.Save(VideoContext); if (tmp_mouse_X != old_mouse_X || tmp_mouse_Y != old_mouse_Y) { update = true; Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, MainContext); Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, VideoContext); Cairo.Rectangle(32, 32, tmp_mouse_Y, tmp_mouse_X, VideoContext); } old_mouse_X = tmp_mouse_X; old_mouse_Y = tmp_mouse_Y; var queue = RedrawRects; Monitor.AcquireLock(ref RedrawRectsLock); while (queue.Count > 0) { var rect = (Rect *)queue.Dequeue(); Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, MainContext); Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, VideoContext); Libc.free((uint)rect); update = true; } Monitor.ReleaseLock(ref RedrawRectsLock); if (update) { Cairo.Clip(MainContext); var list = Stacking; Monitor.AcquireLock(ref StackingLock); int count = list.Count; for (int index = 0; index < count; index++) { var win = list[index]; Cairo.Save(MainContext); Cairo.Translate(win.Y, win.X, MainContext); Cairo.SetSourceSurface(0, 0, win.Surface, MainContext); Cairo.Paint(MainContext); Cairo.Restore(MainContext); } Monitor.ReleaseLock(ref StackingLock); } if (update) { Cairo.Clip(VideoContext); Cairo.Translate(0, 0, VideoContext); Cairo.SetOperator(Operator.Source, VideoContext); Cairo.SetSourceSurface(0, 0, MainSurface, VideoContext); Cairo.Paint(VideoContext); Cairo.Translate(old_mouse_Y, old_mouse_X, VideoContext); Cairo.SetOperator(Operator.Over, VideoContext); Cairo.SetSourceSurface(0, 0, MouseSurface, VideoContext); Cairo.Paint(VideoContext); } Cairo.Restore(MainContext); Cairo.Restore(VideoContext); Task.Switch(); } }
private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r) { double height, width; // some work variables StyleInfo si = pi.SI; // adjust drawing rectangle based on padding // System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft), // r.Top + PixelsY(si.PaddingTop), // r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), // r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft), r.Y + PixelsY(si.PaddingTop), r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle ir; // int work rectangle switch (pi.Sizing) { case ImageSizingEnum.AutoSize: // // Note: GDI+ will stretch an image when you only provide // // the left/top coordinates. This seems pretty stupid since // // it results in the image being out of focus even though // // you don't want the image resized. // if (g.DpiX == im.HorizontalResolution && // g.DpiY == im.VerticalResolution) float imwidth = PixelsX(im.Width); float imheight = PixelsX(im.Height); ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), imwidth, imheight); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); //g.DrawImage(im, ir); im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper); g.DrawPixbufRect(im, ir); break; case ImageSizingEnum.Clip: // Region saveRegion = g.Clip; g.Save(); // Region clipRegion = new Region(g.Clip.GetRegionData()); // clipRegion.Intersect(r2); // g.Clip = clipRegion; g.Rectangle(r2); g.Clip(); // if (dpiX == im.HorizontalResolution && // dpiY == im.VerticalResolution) ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), im.Width, im.Height); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); // g.DrawImage(im, ir); g.DrawPixbufRect(im, ir); // g.Clip = saveRegion; g.Restore(); break; case ImageSizingEnum.FitProportional: double ratioIm = (float)im.Height / (float)im.Width; double ratioR = r2.Height / r2.Width; height = r2.Height; width = r2.Width; if (ratioIm > ratioR) { // this means the rectangle width must be corrected width = height * (1 / ratioIm); } else if (ratioIm < ratioR) { // this means the ractangle height must be corrected height = width * ratioIm; } r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height); g.DrawPixbufRect(im, r2); break; case ImageSizingEnum.Fit: default: g.DrawPixbufRect(im, r2); break; } }
private void RenderNodeGroup(NodeGroup ng, Network network, Cairo.Context gc) { gc.Save(); SizeD size = CalculateNodeGroupSize(ng, gc); ng.Dimension = size; CreateRoundedRectPath(gc, ng.Position.X, ng.Position.Y, size.Width, size.Height, 20); gc.Color = new Cairo.Color(0, 0, 0, 0.5); gc.FillPreserve(); if (selectedGroup == ng) { gc.Save(); gc.Color = orangeOverlay; gc.StrokePreserve(); gc.Restore(); } var titleTextSize = CalculateNodeGroupTitleTextSize(ng, gc); var titleSize = new SizeD(size.Width, titleTextSize.Height + (Padding * 2.0)); gc.Clip(); gc.Rectangle(ng.Position.X, ng.Position.Y, titleSize.Width, titleSize.Height); gc.Fill(); gc.ResetClip(); gc.Color = lightGray; double hostTextX = ng.Position.X + (titleSize.Width / 2.0) - (titleTextSize.Width / 2.0); double hostTextY = ng.Position.Y + (titleSize.Height / 2.0) - (titleTextSize.Height / 2.0); gc.MoveTo(hostTextX, hostTextY /* + titleTextSize.Height */); Pango.Layout layout = new Pango.Layout(this.PangoContext); layout.FontDescription = this.PangoContext.FontDescription.Copy(); layout.FontDescription.Size = Pango.Units.FromDouble(NodegroupNameFontSize); layout.SetText(ng.Name); Pango.CairoHelper.ShowLayout(gc, layout); SizeD nodesSize = CalculateNodeGroupSize(ng, gc); if (ng.Nodes.Count == 1) { double positionY = ng.Position.Y + titleSize.Height + Padding; double positionX = ng.Position.X + (ng.Dimension.Width / 2.0) - HalfAvatarDimension; RenderNode(gc, (Node)ng.Nodes[0], positionX, positionY); } else if (ng.Nodes.Count == 2) { // position them side-by-side, separated by (padding) number of pixels, centered in the // space. double positionY = ng.Position.Y + titleSize.Height + Padding; double position1X = ng.Position.X + (ng.Dimension.Width / 2.0) - (Padding / 2.0) - AvatarDimension; double position2X = position1X + Padding + AvatarDimension; RenderNode(gc, (Node)ng.Nodes[0], position1X, positionY); RenderNode(gc, (Node)ng.Nodes[1], position2X, positionY); } else { double deg = 0; double x = 0; double y = 0; var contentY = ng.Position.Y + titleSize.Height; var contentHeight = size.Height - titleSize.Height; var middle = new System.Drawing.Point(Convert.ToInt32(ng.Position.X + size.Width - (size.Width / 2.0)), Convert.ToInt32(contentY + contentHeight - (contentHeight / 2.0))); int nodeSize = Convert.ToInt32(AvatarDimension); for (int i = 0; i < ng.Nodes.Count; i++) { x = Math.Sin(deg) * ((size.Width / 2.0) - (nodeSize)) + middle.X - (nodeSize / 2.0); y = Math.Cos(deg) * ((contentHeight / 2.0) - (nodeSize)) + middle.Y - (nodeSize / 2.0); RenderNode(gc, (Node)ng.Nodes[i], x, y); deg += Math.PI / (ng.Nodes.Count / 2.0); } } gc.Restore(); }
protected override void onDraw(Cairo.Context gr) { //onDraw is overrided to prevent default drawing of background, template top container //may have a binding to root background or a fixed one. //this allow applying root background to random template's component gr.Save (); if (ClipToClientRect) { //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); } if (child != null) child.Paint (ref gr); gr.Restore (); }
protected override void OnRender (Cairo.Context context) { context.RoundedRectangle (0.5, 0.5, Width - 1, Height - 1, Rounding); if (Relief) { using (var lg = new Cairo.LinearGradient (0, 0, 0, Height)) { CreateGradient (lg, State, Opacity); context.Pattern = lg; context.FillPreserve (); } context.LineWidth = 1; context.Color = new Cairo.Color (0.8, 0.8, 0.8, Opacity); context.StrokePreserve (); } context.Clip (); base.OnRender (context); }
protected override void OnRender (Cairo.Context context) { OnLayoutOutline (context); context.Clip (); context.Color = new Cairo.Color (1, 1, 1, Opacity * entryGroup.Opacity); context.Paint (); Gdk.Rectangle region = new Gdk.Rectangle (0, 0, (int)Width, (int)Height); context.Save (); ClipBackground (context, region); base.OnRender (context); context.Restore (); DrawOutline (context, region, Opacity * entryGroup.Opacity); }
void DrawErrorAnimation (Cairo.Context context, StatusArea.RenderArg arg) { const int surfaceWidth = 2000; double opacity; int progress; if (arg.ErrorAnimationProgress < .5f) { progress = (int) (arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4); opacity = 1.0d; } else { progress = (int) (arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4); opacity = 1.0d - (arg.ErrorAnimationProgress - .5d) * 2; } LayoutRoundedRectangle (context, arg.Allocation); context.Clip (); context.CachedDraw (surface: ref errorSurface, position: new Gdk.Point (arg.Allocation.X - surfaceWidth + progress, arg.Allocation.Y), size: new Gdk.Size (surfaceWidth, arg.Allocation.Height), opacity: (float)opacity, draw: (c, o) => { // The smaller the pixel range of our gradient the less error there will be in it. using (var lg = new LinearGradient (surfaceWidth - 250, 0, surfaceWidth, 0)) { lg.AddColorStop (0.00, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.15 * o)); lg.AddColorStop (0.10, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.15 * o)); lg.AddColorStop (0.88, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.30 * o)); lg.AddColorStop (1.00, Styles.WithAlpha (Styles.StatusBarErrorColor, 0.00 * o)); c.Pattern = lg; c.Paint (); } }); context.ResetClip (); }
void DrawSerie(Cairo.Context ctx, Serie serie) { ctx.NewPath (); ctx.Rectangle (left, top, width + 1, height + 1); ctx.Clip (); ctx.NewPath (); ctx.SetSourceColor (serie.Color); ctx.LineWidth = serie.LineWidth; bool first = true; bool blockMode = serie.DisplayMode == DisplayMode.BlockLine; double lastY = 0; foreach (Data d in serie.GetData (startX, endX)) { double x, y; GetPoint (d.X, d.Y, out x, out y); if (first) { ctx.MoveTo (x, y); lastY = y; first = false; } else { if (blockMode) { if (lastY != y) ctx.LineTo (x, lastY); ctx.LineTo (x, y); } else ctx.LineTo (x, y); } lastY = y; } ctx.Stroke (); }
void ClipProgressBar (Cairo.Context context, Gdk.Rectangle bounding) { LayoutRoundedRectangle (context, bounding); context.Clip (); }
void DrawBuildEffect (Cairo.Context context, Gdk.Rectangle area, double progress, double opacity) { context.Save (); LayoutRoundedRectangle (context, area); context.Clip (); Gdk.Point center = new Gdk.Point (area.Left + 19, (area.Top + area.Bottom) / 2); context.Translate (center.X, center.Y); var circles = new [] { new { Radius = 200, Thickness = 12, Speed = 1, ArcLength = Math.PI * 1.50 }, new { Radius = 195, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.50 }, new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 }, new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 }, new { Radius = 240, Thickness = 12, Speed = 3, ArcLength = Math.PI * 1.50 }, new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 }, new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 }, new { Radius = 215, Thickness = 20, Speed = 2, ArcLength = Math.PI * 1.25 } }; double zmod = 1.0d; double zporg = progress; foreach (var arc in circles) { double zoom = 1.0d; zoom = (double) Math.Sin (zporg * Math.PI * 2 + zmod); zoom = ((zoom + 1) / 6.0d) + .05d; context.Rotate (Math.PI * 2 * progress * arc.Speed); context.MoveTo (arc.Radius * zoom, 0); context.Arc (0, 0, arc.Radius * zoom, 0, arc.ArcLength); context.LineWidth = arc.Thickness * zoom; context.Color = CairoExtensions.ParseColor ("B1DDED", 0.35 * opacity); context.Stroke (); context.Rotate (Math.PI * 2 * -progress * arc.Speed); progress = -progress; context.Rotate (Math.PI * 2 * progress * arc.Speed); context.MoveTo (arc.Radius * zoom, 0); context.Arc (0, 0, arc.Radius * zoom, 0, arc.ArcLength); context.LineWidth = arc.Thickness * zoom; context.Stroke (); context.Rotate (Math.PI * 2 * -progress * arc.Speed); progress = -progress; zmod += (float)Math.PI / circles.Length; } context.LineWidth = 1; context.ResetClip (); context.Restore (); }
public void DrawImageFromFile(Cairo.Context cr, string filename, double x, double y, double width, double height) { SvgImage image; if (width <= 0 || height <= 0) throw new ArgumentException (String.Format ("Spumux->DrawImageFromFile. DVD menu buttons width {0} and height {1} should be > 0", width, height)); try { image = new SvgImage (filename); } catch (Exception) { Logger.Error ("Spumux.DrawImageFromFile. Error loading file {0}", filename); return; } Logger.Debug ("Spumux.DrawImageFromFile. Loaded file {0}, w:{1} h:{2}", filename, image.Width, image.Height); cr.Save (); // Have to clip for RenderToCairo cr.Rectangle (x, y, width, height); cr.Clip (); cr.Translate (x, y); cr.Scale (width / image.Width, height / image.Height); image.RenderToCairo (cr.Handle); cr.Restore (); image.Dispose (); }
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)); context.Clip (); LayoutRoundedRectangle (context, bounding); context.Color = Styles.WithAlpha (Styles.StatusBarProgressBackgroundColor, Styles.StatusBarProgressBackgroundColor.A * arg.ProgressBarAlpha); context.FillPreserve (); context.ResetClip (); context.Color = Styles.WithAlpha (Styles.StatusBarProgressOutlineColor, Styles.StatusBarProgressOutlineColor.A * arg.ProgressBarAlpha); context.LineWidth = 1; context.Stroke (); }
protected override bool OnDrawn(Cairo.Context cr) { if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped) { return true; } foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles ()) { cr.Rectangle (damage.X, damage.Y, damage.Width, damage.Height); cr.Clip (); cr.Translate (Allocation.X, Allocation.Y); canvas_child.Render (cr); cr.Translate (-Allocation.X, -Allocation.Y); if (Debug) { cr.LineWidth = 1.0; cr.Color = CairoExtensions.RgbToColor ( (uint)(rand = rand ?? new Random ()).Next (0, 0xffffff)); cr.Rectangle (damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke (); } cr.ResetClip (); } CairoExtensions.DisposeContext (cr); if (fps.Update ()) { // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond); } return true; }
void DrawString (string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg) { Pango.Layout pl = new Pango.Layout (pango); if (isMarkup) pl.SetMarkup (text); else pl.SetText (text); pl.FontDescription = Styles.StatusFont; pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Styles.StatusFontPixelHeight); pl.Ellipsize = Pango.EllipsizeMode.End; pl.Width = Pango.Units.FromPixels(width); int w, h; pl.GetPixelSize (out w, out h); context.Save (); // use widget height instead of message box height as message box does not have a true height when no widgets are packed in it // also ensures animations work properly instead of getting clipped context.Rectangle (new Rectangle (x, arg.Allocation.Y, width, arg.Allocation.Height)); context.Clip (); // Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels context.MoveTo (x, y - h / 2 - (h % 2)); context.Color = Styles.WithAlpha (FontColor (), opacity); Pango.CairoHelper.ShowLayout (context, pl); pl.Dispose (); context.Restore (); }
void Draw(Cairo.Context ctx, List<TableRow> rowList, int dividerX, int x, ref int y) { if (!heightMeasured) return; Pango.Layout layout = new Pango.Layout (PangoContext); TableRow lastCategory = null; foreach (var r in rowList) { int w,h; layout.SetText (r.Label); layout.GetPixelSize (out w, out h); int indent = 0; if (r.IsCategory) { var rh = h + CategoryTopBottomPadding*2; ctx.Rectangle (0, y, Allocation.Width, rh); using (var gr = new LinearGradient (0, y, 0, rh)) { gr.AddColorStop (0, new Cairo.Color (248d/255d, 248d/255d, 248d/255d)); gr.AddColorStop (1, new Cairo.Color (240d/255d, 240d/255d, 240d/255d)); ctx.SetSource (gr); ctx.Fill (); } if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand) { ctx.MoveTo (0, y + 0.5); ctx.LineTo (Allocation.Width, y + 0.5); } ctx.MoveTo (0, y + rh - 0.5); ctx.LineTo (Allocation.Width, y + rh - 0.5); ctx.SetSourceColor (DividerColor); ctx.Stroke (); ctx.MoveTo (x, y + CategoryTopBottomPadding); ctx.SetSourceColor (CategoryLabelColor); Pango.CairoHelper.ShowLayout (ctx, layout); var img = r.Expanded ? discloseUp : discloseDown; ctx.DrawImage (this, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + Math.Round ((rh - img.Height) / 2)); y += rh; lastCategory = r; } else { var cell = GetCell (r); r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject; var state = r.Enabled ? State : Gtk.StateType.Insensitive; ctx.Save (); ctx.Rectangle (0, y, dividerX, h + PropertyTopBottomPadding*2); ctx.Clip (); ctx.MoveTo (x, y + PropertyTopBottomPadding); ctx.SetSourceColor (Style.Text (state).ToCairoColor ()); Pango.CairoHelper.ShowLayout (ctx, layout); ctx.Restore (); if (r != currentEditorRow) cell.Render (GdkWindow, ctx, r.EditorBounds, state); y += r.EditorBounds.Height; indent = PropertyIndent; } if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand)) { int py = y; ctx.Save (); if (r.AnimatingExpand) ctx.Rectangle (0, y, Allocation.Width, r.AnimationHeight); else ctx.Rectangle (0, 0, Allocation.Width, Allocation.Height); ctx.Clip (); Draw (ctx, r.ChildRows, dividerX, x + indent, ref y); ctx.Restore (); if (r.AnimatingExpand) { y = py + r.AnimationHeight; // Repaing the background because the cairo clip doesn't work for gdk primitives int dx = (int)((double)Allocation.Width * dividerPosition); ctx.Rectangle (0, y, dx, Allocation.Height - y); ctx.SetSourceColor (LabelBackgroundColor); ctx.Fill (); ctx.Rectangle (dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y); ctx.SetSourceRGB (1, 1, 1); ctx.Fill (); } } } }
protected override void onDraw(Cairo.Context gr) { gr.Save (); int spacing = (Parent as TabView).Spacing; gr.MoveTo (0.5, TabTitle.Slot.Bottom-0.5); gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom-0.5); gr.CurveTo ( TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom-0.5, TabTitle.Slot.Left - spacing / 2, 0.5, TabTitle.Slot.Left, 0.5); gr.LineTo (TabTitle.Slot.Right, 0.5); gr.CurveTo ( TabTitle.Slot.Right + spacing / 2, 0.5, TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom-0.5, TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom-0.5); gr.LineTo (Slot.Width-0.5, TabTitle.Slot.Bottom-0.5); gr.LineTo (Slot.Width-0.5, Slot.Height-0.5); gr.LineTo (0.5, Slot.Height-0.5); gr.ClosePath (); gr.LineWidth = 2; Foreground.SetAsSource (gr); gr.StrokePreserve (); gr.Clip (); base.onDraw (gr); gr.Restore (); }
protected override bool OnDrawn(Cairo.Context cr) { int bar_width = (int)((double)Allocation.Width * buffering_progress); bool render_bar = false; var border = StyleContext.GetBorder (StateFlags); if (bar_width > 0 && IsBuffering) { bar_width -= border.Left + border.Right; render_bar = true; StyleContext.Save (); StyleContext.AddClass ("trough"); StyleContext.RenderBackground (cr, 0, 0, Allocation.Width, Allocation.Height); StyleContext.RenderFrame (cr, 0, 0, Allocation.Width, Allocation.Height); StyleContext.Restore (); if (bar_width > 0) { StyleContext.Save (); StyleContext.AddClass ("progressbar"); StyleContext.RenderActivity (cr, border.Left, border.Top, bar_width, Allocation.Height - (border.Top + border.Bottom)); StyleContext.Restore (); } } int width, height; layout.GetPixelSize (out width, out height); int x = (Allocation.Width - width) / 2; int y = (Allocation.Height - height) / 2; Gdk.Rectangle rect = new Gdk.Rectangle (0, 0, Allocation.Width, Allocation.Height); if (render_bar) { // First render the text that is on the progressbar int full_bar_width = bar_width + border.Left; rect.Width = full_bar_width; cr.Save (); Gdk.CairoHelper.Rectangle (cr, rect); cr.Clip (); StyleContext.Save (); // The entry class is need so that the text get the "selected" color StyleContext.AddClass ("entry"); StyleContext.AddClass ("progressbar"); StyleContext.RenderLayout (cr, x, y, layout); StyleContext.Restore (); cr.Restore (); // Adjust the rectangle so that the rest of the text is rendered as expected rect.X += rect.Width; rect.Width = Allocation.Width - rect.Width; } cr.Save (); Gdk.CairoHelper.Rectangle (cr, rect); cr.Clip (); StyleContext.Save (); StyleContext.AddClass ("trough"); StyleContext.RenderLayout (cr, x, y, layout); StyleContext.Restore (); cr.Restore (); return true; }