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 (); }
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 virtual void DrawBackground (Cairo.Context context, Gdk.Rectangle region) { LayoutRoundedRectangle (context, region); context.ClipPreserve (); using (LinearGradient lg = new LinearGradient (region.X, region.Y, region.X, region.Y + region.Height)) { lg.AddColorStop (0, Styles.StatusBarFill1Color); lg.AddColorStop (1, Styles.StatusBarFill4Color); context.Pattern = lg; context.FillPreserve (); } context.Save (); double midX = region.X + region.Width / 2.0; double midY = region.Y + region.Height; context.Translate (midX, midY); using (RadialGradient rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) { rg.AddColorStop (0, Styles.StatusBarFill1Color); rg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarFill1Color, 0)); context.Scale (region.Width / (double)region.Height, 1.0); context.Pattern = rg; context.Fill (); } context.Restore (); using (LinearGradient lg = new LinearGradient (0, region.Y, 0, region.Y + region.Height)) { lg.AddColorStop (0, Styles.StatusBarShadowColor1); lg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarShadowColor1, Styles.StatusBarShadowColor1.A * 0.2)); LayoutRoundedRectangle (context, region, 0, -1); context.LineWidth = 1; context.Pattern = lg; context.Stroke (); } using (LinearGradient lg = new LinearGradient (0, region.Y, 0, region.Y + region.Height)) { lg.AddColorStop (0, Styles.StatusBarShadowColor2); lg.AddColorStop (1, Styles.WithAlpha (Styles.StatusBarShadowColor2, Styles.StatusBarShadowColor2.A * 0.2)); LayoutRoundedRectangle (context, region, 0, -2); context.LineWidth = 1; context.Pattern = lg; context.Stroke (); } context.ResetClip (); }
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 (); }
// 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 (); }
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 (); }
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); }
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; }
/// <summary> /// Method which paints cells /// </summary> /// <param name="evnt"> /// Expose event parameters <see cref="Gdk.EventExpose"/> /// </param> /// <param name="aContext"> /// Cairo context <see cref="Cairo.Context"/> /// </param> protected virtual void PaintCells (Gdk.EventExpose evnt, Gdk.Drawable aDrawable, Cairo.Context aContext, CellRectangle aArea) { if (box.IsVisible == false) return; System.Console.WriteLine("Paint"); box.Area.Clip (aContext); // aContext.Rectangle (box.Area); // aContext.Clip(); // Cairo.Rectangle cliprect = new Cairo.Rectangle (0, 0, Allocation.Width, Allocation.Height); CellRectangle cliprect = new CellRectangle (evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); // box.Paint (evnt, aContext, cliprect, box.Area); // box.Paint (new CellExposeEventArgs (evnt, aContext, evnt.Window, cliprect, box.Area)); CellExposeEventArgs args = new CellExposeEventArgs (evnt, aContext, aDrawable, cliprect, box.Area); args.WidgetInRenderer = IsCellRenderer; args.Widget = this; args.ForceRecalculation = true; box.Arguments.Start (CellAction.Paint, args); box.Paint (args); box.Arguments.Stop(); args.Disconnect(); args = null; aContext.ResetClip(); }
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(); }
private void RenderBackground(Cairo.Context cr) { rand = rand ?? new Random (); if (circles == null) { for (int i = 0, n = rand.Next (100, 150); i < n; i++) { circles = circles ?? new Circle[n]; circles[i] = new Circle { X = rand.Next (0, Screen.Width), Y = rand.Next (0, Screen.Height), R = rand.Next (10, 70), A = rand.NextDouble () * 0.08 }; } } Gdk.Rectangle damage = new Gdk.Rectangle(); cr.RenderDamage (damage); //cr.Rectangle (damage.X, damage.Y, damage.Width, damage.Height); //cr.Clip (); cr.Translate (Allocation.X, Allocation.Y); cr.Rectangle (0, 0, Allocation.Width, Allocation.Height); if (render_gradient) { var grad = new Cairo.LinearGradient (0, 0, 0, Allocation.Height); grad.AddColorStop (0.7, CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Prelight))); grad.AddColorStop (1, CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal))); cr.SetSource (grad); cr.Fill (); grad.Dispose (); foreach (var circle in circles) { cr.SetSourceColor (new Cairo.Color (0, 0, 0, circle.A)); cr.Arc (circle.X + circle.R, circle.Y + circle.R, circle.R, 0, 2 * Math.PI); cr.Fill (); } } else { cr.SetSourceColor (new Cairo.Color (1, 1, 1)); cr.Fill (); } if (window_decorator != null) { window_decorator.Render (cr); } if (render_debug) { cr.LineWidth = 1.0; cr.SetSourceColor (CairoExtensions.RgbToColor ( (uint)rand.Next (0, 0xffffff))); cr.Rectangle (damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke (); } cr.ResetClip (); }