protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if (!IsDrawable) { return(false); } Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window); try { DrawFrame(cr, evnt.Area); if (child != null) { PropagateExpose(child, evnt); } return(false); } finally { CairoExtensions.DisposeContext(cr); } }
public ClosableExpander() { header = new ExpanderHeader(this); PackStart(header, false, false, 0); contentBox = new VBox(); contentBox.ExposeEvent += delegate(object o, ExposeEventArgs args) { using (var cr = CairoHelper.Create(args.Event.Window)) { CairoCorners corners = CairoCorners.BottomLeft | CairoCorners.BottomRight; int r = 10; CairoExtensions.RoundedRectangle(cr, contentBox.Allocation.X + 0.5, contentBox.Allocation.Y + 0.5, contentBox.Allocation.Width - 1, contentBox.Allocation.Height - 1, r, corners, true); cr.LineWidth = 1; cr.Color = (Mono.TextEditor.HslColor)Style.Dark(StateType.Normal); cr.Stroke(); } }; expanded = true; PackStart(contentBox, true, true, 0); ShowAll(); }
protected override bool OnDamageEvent(Gdk.EventExpose evnt) { if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped) { return(true); } Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window); context.Context = cr; for (int i = 0; i < evnt.Region.NumRectangles; i++) { var damage = evnt.Region.GetRectangle(i); cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height); cr.Clip(); cr.Translate(Allocation.X, Allocation.Y); canvas_child.Render(context); cr.Translate(-Allocation.X, -Allocation.Y); if (Debug) { cr.LineWidth = 1.0; cr.SetSourceColor(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); }
private void Reset() { store.Clear(); if (active_layer_surface != null) { (active_layer_surface as IDisposable).Dispose(); active_layer_surface = null; } if (!PintaCore.Workspace.HasOpenDocuments) { return; } var doc = PintaCore.Workspace.ActiveDocument; foreach (var layer in doc.Layers.UserLayers.Reverse()) { var surf = layer.Surface; // If this is the currently selected layer, we may need to draw the // selection layer over it, like when dragging a selection. if (layer == doc.Layers.CurrentUserLayer && doc.Layers.ShowSelectionLayer) { active_layer_surface = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, thumbnail_width, thumbnail_height); canvas_renderer.Initialize(doc.ImageSize, new Gdk.Size(thumbnail_width, thumbnail_height)); var layers = new List <Layer> { layer, doc.Layers.SelectionLayer }; canvas_renderer.Render(layers, active_layer_surface, Gdk.Point.Zero); surf = active_layer_surface; } store.AppendValues(surf, layer.Name, !layer.Hidden, layer); } SelectLayerInTreeView(doc.Layers.Count() - doc.Layers.CurrentUserLayerIndex - 1); }
internal override MainToolbar CreateMainToolbar(Gtk.Window window) { NSWindow w = GtkQuartz.GetWindow(window); w.IsOpaque = false; var resource = "maintoolbarbg.png"; NSImage img = LoadImage(resource); var c = NSColor.FromPatternImage(img); w.BackgroundColor = c; w.StyleMask |= NSWindowStyle.TexturedBackground; var result = new MainToolbar() { Background = CairoExtensions.LoadImage(typeof(MacPlatformService).Assembly, resource), TitleBarHeight = GetTitleBarHeight() }; return(result); }
public override void Render(CellContext context, double cellWidth, double cellHeight) { Gdk.Rectangle area = new Gdk.Rectangle(0, 0, (int)cellWidth, (int)cellHeight); // FIXME: Compute font height and set to renderer.Size renderer.Value = Value; bool is_hovering = hover_bound == BoundObjectParent && hover_bound != null; context.StyleContext.Save(); context.StyleContext.State |= context.State; Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(context.StyleContext.GetColor(context.StyleContext.State)); renderer.Render(context.Context, area, color, is_hovering, is_hovering, hover_value, 0.8, 0.45, 0.35); context.StyleContext.Restore(); // FIXME: Something is hosed in the view when computing cell dimensions // The cell width request is always smaller than the actual cell, so // this value is preserved once we compute it from rendering so the // input stuff can do its necessary calculations actual_area_hack = area; }
protected override void OnStyleSet(Style previous) { base.OnStyleSet(previous); text_color = CairoExtensions.GdkColorToCairoColor(Style.Foreground(StateType.Normal)); background_color = CairoExtensions.GdkColorToCairoColor(Style.Background(StateType.Normal)); text_light_color = Hyena.Gui.Theming.GtkTheme.GetCairoTextMidColor(this); if (missing_audio_image != null) { ((IDisposable)missing_audio_image).Dispose(); missing_audio_image = null; } if (missing_video_image != null) { ((IDisposable)missing_video_image).Dispose(); missing_video_image = null; } OnThemeChanged(); }
public override void Render(Cairo.Context cr, Gdk.Rectangle area, Cairo.Color color, bool showEmptyStars, bool isHovering, int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity) { if (Value == MinRating && !isHovering && !showEmptyStars) { return; } ComputePosition(area, out var x, out var y); cr.Translate(0.5, 0.5); using (var pixbuf = RenderPixbuf(showEmptyStars, isHovering, hoverValue, fillOpacity, hoverFillOpacity, strokeOpacity)) { using (var surface = CairoExtensions.CreateSurfaceForPixbuf(cr, pixbuf)) { cr.Rectangle(x, y, pixbuf.Width, pixbuf.Height); cr.SetSource(surface, x, y); cr.Fill(); } } }
public override void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc) { Color gtk_background_color = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Normal); Color light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1); Color dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.95); CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight; using (LinearGradient grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Bottom)) { grad.AddColorStop(0, light_color); grad.AddColorStop(0.75, dark_color); grad.AddColorStop(0, light_color); cr.SetSource(grad); CairoExtensions.RoundedRectangle(cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, corners); cr.Fill(); } cr.SetSourceColor(border_color); cr.Rectangle(alloc.X, alloc.Bottom, alloc.Width, BorderWidth); cr.Fill(); }
private void PaintCell(Cairo.Context cr, object item, int column_index, int row_index, Rectangle area, bool opaque, bool bold, StateFlags state, bool dragging) { ColumnCell cell = column_cache[column_index].Column.GetCell(0); cell.Bind(item); cell.Manager = manager; ColumnCellDataProvider(cell, item); ITextCell text_cell = cell as ITextCell; if (text_cell != null) { text_cell.FontWeight = bold ? Pango.Weight.Bold : Pango.Weight.Normal; } if (dragging) { StyleContext.Save(); StyleContext.AddClass("entry"); Cairo.Color fill_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Normal)); StyleContext.Restore(); fill_color.A = 0.5; cr.Color = fill_color; cr.Rectangle(area.X, area.Y, area.Width, area.Height); cr.Fill(); } cr.Save(); cr.Translate(area.X, area.Y); cell_context.Area = area; cell_context.Opaque = opaque; cell_context.State = dragging ? StateFlags.Normal : state; cell.Render(cell_context, area.Width, area.Height); cr.Restore(); AccessibleCellRedrawn(column_index, row_index); }
public override void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc) { double top_offset = 2.0; double right_offset = 2.0; double margin = 0.5; double line_width = 0.7; Cairo.Color stroke_color = CairoExtensions.ColorShade(Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected), 0.8); stroke_color.A = 0.1; cr.SetSourceColor(stroke_color); CairoExtensions.RoundedRectangle(cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (margin + line_width) * 2.0 - right_offset, alloc.Height - (margin + line_width) * 2.0 - top_offset, Context.Radius / 2.0, CairoCorners.None); cr.Fill(); stroke_color.A = 1.0; cr.LineWidth = line_width; cr.SetSourceColor(stroke_color); CairoExtensions.RoundedRectangle(cr, alloc.X + margin + line_width + right_offset, alloc.Y + margin + line_width + top_offset, alloc.Width - (line_width + margin) * 2.0 - right_offset, alloc.Height - (line_width + margin) * 2.0 - right_offset, Context.Radius / 2.0, CairoCorners.All); cr.Stroke(); }
protected override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle roi) { var r = roi.ToCairoRectangle(); using (var temp = CairoExtensions.CreateImageSurface(Format.Argb32, roi.Width, roi.Height)) { RenderClouds(temp, roi, Data.Scale, (byte)(Data.Seed ^ instanceSeed), Data.Power / 100.0, PintaCore.Palette.PrimaryColor.ToColorBgra(), PintaCore.Palette.SecondaryColor.ToColorBgra()); temp.MarkDirty(); // Have to lock because effect renderer is multithreaded lock (render_lock) { using (var g = new Context(dst)) { // - Clear any previous render from the destination // - Copy the source to the destination // - Blend the clouds over the source g.Clear(r); g.BlendSurface(src, r); g.BlendSurface(temp, r.Location(), (BlendMode)CloudsData.BlendOps[Data.BlendMode]); } } } }
protected virtual void DrawHoverBackground(Cairo.Context ctx) { if (BorderPadding <= 0) { ctx.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); ctx.SetSourceColor(CairoExtensions.ParseColor(HoverBackgroundColor)); ctx.Fill(); ctx.MoveTo(Allocation.X, Allocation.Y + 0.5); ctx.RelLineTo(Allocation.Width, 0); ctx.MoveTo(Allocation.X, Allocation.Y + Allocation.Height - 0.5); ctx.RelLineTo(Allocation.Width, 0); if (DrawRightBorder) { ctx.MoveTo(Allocation.Right + 0.5, Allocation.Y + 0.5); ctx.LineTo(Allocation.Right + 0.5, Allocation.Bottom - 0.5); } if (DrawLeftBorder) { ctx.MoveTo(Allocation.Left + 0.5, Allocation.Y + 0.5); ctx.LineTo(Allocation.Left + 0.5, Allocation.Bottom - 0.5); } ctx.LineWidth = 1; ctx.SetSourceColor(CairoExtensions.ParseColor(HoverBorderColor)); ctx.Stroke(); } else { Gdk.Rectangle region = Allocation; region.Inflate(-BorderPadding, -BorderPadding); ctx.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3); ctx.SetSourceColor(CairoExtensions.ParseColor(HoverBackgroundColor)); ctx.FillPreserve(); ctx.LineWidth = 1; ctx.SetSourceColor(CairoExtensions.ParseColor(HoverBorderColor)); ctx.Stroke(); } }
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.SetSourceColor(CairoExtensions.WithAlpha(FontColor(), opacity)); Pango.CairoHelper.ShowLayout(context, pl); IsEllipsized = pl.IsEllipsized; pl.Dispose(); context.Restore(); }
public override void Render(CellContext context, double cellWidth, double cellHeight) { if (BoundObject == null) { return; } if (!(BoundObject is TrackInfo)) { throw new InvalidCastException("ColumnCellAlbum can only bind to AlbumInfo objects"); } TrackInfo track = (TrackInfo)BoundObject; context.Layout.Width = (int)((cellWidth - 8) * Pango.Scale.PangoScale); context.Layout.Ellipsize = Pango.EllipsizeMode.End; context.Layout.FontDescription.Weight = font_weight; context.Layout.SetMarkup(String.Format("<b>{0}</b>\n<small><i>{1}</i></small>", GLib.Markup.EscapeText(track.DisplayTrackTitle), GLib.Markup.EscapeText(track.DisplayArtistName))); int text_width; int text_height; context.Layout.GetPixelSize(out text_width, out text_height); context.Context.MoveTo(4, ((int)cellHeight - text_height) / 2); context.Widget.StyleContext.Save(); context.Widget.StyleContext.AddClass("entry"); Gdk.RGBA rgba = context.Widget.StyleContext.GetColor(context.Selected ? StateFlags.Selected : StateFlags.Normal); Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(rgba); context.Widget.StyleContext.Restore(); color.A = (!context.Opaque) ? 0.3 : 1.0; context.Context.SetSourceColor(color); Pango.CairoHelper.ShowLayout(context.Context, context.Layout); }
private void RenderBackground(Cairo.Context cr, Gdk.Rectangle background_area, bool selected, StateFlags state) { if (view == null) { return; } if (selected) { // Just leave the standard GTK selection and focus return; } if (!TreeIter.Zero.Equals(iter) && iter.Equals(view.HighlightedIter)) { // Item is highlighted but not selected view.Theme.DrawHighlightFrame(cr, background_area.X + 1, background_area.Y + 1, background_area.Width - 2, background_area.Height - 2); } else if (view.NotifyStage.ActorCount > 0) { if (!TreeIter.Zero.Equals(iter) && view.NotifyStage.Contains(iter)) { // Render the current step of the notification animation Actor <TreeIter> actor = view.NotifyStage[iter]; Cairo.Color normal_color = CairoExtensions.GdkRGBAToCairoColor(view.StyleContext.GetBackgroundColor(StateFlags.Normal)); Cairo.Color selected_color = CairoExtensions.GdkRGBAToCairoColor(view.StyleContext.GetBackgroundColor(StateFlags.Selected)); Cairo.Color notify_bg_color = CairoExtensions.AlphaBlend(normal_color, selected_color, 0.5); notify_bg_color.A = Math.Sin(actor.Percent * Math.PI); cr.SetSourceColor(notify_bg_color); CairoExtensions.RoundedRectangle(cr, background_area.X, background_area.Y, background_area.Width, background_area.Height, view.Theme.Context.Radius); cr.Fill(); } } }
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); }
public override void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc) { Cairo.Color gtk_background_color = CairoExtensions.GdkRGBAToCairoColor(Widget.StyleContext.GetBackgroundColor(StateFlags.Normal)); Cairo.Color light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1); Cairo.Color dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.95); CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight; LinearGradient grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Bottom); grad.AddColorStop(0, light_color); grad.AddColorStop(0.75, dark_color); grad.AddColorStop(0, light_color); cr.Pattern = grad; CairoExtensions.RoundedRectangle(cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, corners); cr.Fill(); cr.Color = border_color; cr.Rectangle(alloc.X, alloc.Bottom, alloc.Width, BorderWidth); cr.Fill(); grad.Destroy(); }
protected override bool OnExposeEvent(EventExpose evnt) { var ret = base.OnExposeEvent(evnt); if (image.Pixbuf != null) { return(ret); } using (var cr = CairoHelper.Create(evnt.Window)) { cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.Clip(); var imgAlloc = image.Allocation; cr.Translate(imgAlloc.X, imgAlloc.Y); using (var layout = new Pango.Layout(PangoContext)) { layout.SetText(GettextCatalog.GetString("No image")); layout.Width = (int)((imgAlloc.Width - 20) * Pango.Scale.PangoScale); layout.Wrap = Pango.WrapMode.WordChar; layout.Alignment = Pango.Alignment.Center; int pw, ph; layout.GetPixelSize(out pw, out ph); cr.MoveTo((imgAlloc.Width - layout.Width / Pango.Scale.PangoScale) / 2, (imgAlloc.Height - ph) / 2); cr.Color = new Cairo.Color(0.5, 0.5, 0.5); cr.ShowLayout(layout); } CairoExtensions.RoundedRectangle(cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5); cr.LineWidth = 3; cr.Color = new Cairo.Color(0.8, 0.8, 0.8); cr.SetDash(new double[] { 12, 2 }, 0); cr.Stroke(); } return(ret); }
private void UpdateRectangle(Document document, PointD point) { if (!is_drawing) { return; } var r = CairoExtensions.PointsToRectangle(shape_origin, point); document.Layers.ToolLayer.Clear(); document.Layers.ToolLayer.Hidden = false; using (var g = new Context(document.Layers.ToolLayer.Surface)) { g.Antialias = Antialias.Subpixel; var dirty = g.FillStrokedRectangle(r, new Color(0, 0.4, 0.8, 0.1), new Color(0, 0, 0.9), 1); dirty = dirty.Clamp(); document.Workspace.Invalidate(last_dirty.ToGdkRectangle()); document.Workspace.Invalidate(dirty.ToGdkRectangle()); last_dirty = dirty; } }
public override void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x) { Cairo.Color gtk_background_color = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Normal); Cairo.Color dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.8); Cairo.Color light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1); int y_1 = alloc.Top + 4; int y_2 = alloc.Bottom - 3; cr.LineWidth = 1; cr.Antialias = Antialias.None; cr.SetSourceColor(dark_color); cr.MoveTo(x, y_1); cr.LineTo(x, y_2); cr.Stroke(); cr.SetSourceColor(light_color); cr.MoveTo(x + 1, y_1); cr.LineTo(x + 1, y_2); cr.Stroke(); cr.Antialias = Cairo.Antialias.Default; }
public override void DrawPie(double fraction) { // Calculate the pie path fraction = Theme.Clamp(0.0, 1.0, fraction); double a1 = 3.0 * Math.PI / 2.0; double a2 = a1 + 2.0 * Math.PI * fraction; if (fraction == 0.0) { return; } Context.Cairo.MoveTo(Context.X, Context.Y); Context.Cairo.Arc(Context.X, Context.Y, Context.Radius, a1, a2); Context.Cairo.LineTo(Context.X, Context.Y); // Fill the pie Color color_a = CairoExtensions.GdkRGBAToCairoColor( Widget.StyleContext.GetBackgroundColor(StateFlags.Selected)); Color color_b = CairoExtensions.ColorShade(color_a, 1.4); RadialGradient fill = new RadialGradient(Context.X, Context.Y, 0, Context.X, Context.Y, 2.0 * Context.Radius); fill.AddColorStop(0, color_a); fill.AddColorStop(1, color_b); Context.Cairo.Pattern = fill; Context.Cairo.FillPreserve(); fill.Destroy(); // Stroke the pie Context.Cairo.Color = CairoExtensions.ColorShade(color_a, 0.8); Context.Cairo.LineWidth = Context.LineWidth; Context.Cairo.Stroke(); }
public void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x) { Cairo.Color gtk_background_color = CairoExtensions.GdkRGBAToCairoColor(widget.StyleContext.GetBackgroundColor(StateFlags.Normal)); Cairo.Color dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.80); Cairo.Color light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1); int y_1 = alloc.Top + 4; int y_2 = alloc.Bottom - 3; cr.LineWidth = 1; cr.Antialias = Cairo.Antialias.None; cr.SetSourceColor(dark_color); cr.MoveTo(x, y_1); cr.LineTo(x, y_2); cr.Stroke(); cr.SetSourceColor(light_color); cr.MoveTo(x + 1, y_1); cr.LineTo(x + 1, y_2); cr.Stroke(); cr.Antialias = Cairo.Antialias.Default; }
public override void Render(CellContext context, double cellWidth, double cellHeight) { if (BoundObject == null) { return; } if (!(BoundObject is AlbumInfo)) { throw new InvalidCastException("ColumnCellAlbum can only bind to AlbumInfo objects"); } AlbumInfo album = (AlbumInfo)BoundObject; bool is_default = false; ImageSurface image = artwork_manager == null ? null : artwork_manager.LookupScaleSurface(album.ArtworkId, image_size, true); if (image == null) { image = default_cover_image; is_default = true; } // int image_render_size = is_default ? image.Height : (int)cellHeight - 8; int image_render_size = image_size; int x = image_spacing; int y = ((int)cellHeight - image_render_size) / 2; ArtworkRenderer.RenderThumbnail(context.Context, image, false, x, y, image_render_size, image_render_size, !is_default, context.Theme.Context.Radius); int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0; context.Widget.StyleContext.Save(); context.Widget.StyleContext.AddClass("entry"); Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor(context.Widget.StyleContext.GetColor(StateFlags.Selected)); context.Widget.StyleContext.Restore(); text_color.A = 0.75; Pango.Layout layout = context.Layout; layout.Width = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale); layout.Ellipsize = Pango.EllipsizeMode.End; layout.FontDescription.Weight = Pango.Weight.Bold; // Compute the layout sizes for both lines for centering on the cell int old_size = layout.FontDescription.Size; layout.SetText(album.DisplayTitle); layout.GetPixelSize(out fl_width, out fl_height); if (!String.IsNullOrEmpty(album.ArtistName)) { layout.FontDescription.Weight = Pango.Weight.Normal; layout.FontDescription.Size = (int)(old_size * Pango.Scale.Small); layout.FontDescription.Style = Pango.Style.Italic; layout.SetText(album.ArtistName); layout.GetPixelSize(out sl_width, out sl_height); } // Calculate the layout positioning x = ((int)cellHeight - x) + 10; y = (int)((cellHeight - (fl_height + sl_height)) / 2); // Render the second line first since we have that state already if (!String.IsNullOrEmpty(album.ArtistName)) { context.Context.MoveTo(x, y + fl_height); context.Context.SetSourceColor(text_color); Pango.CairoHelper.ShowLayout(context.Context, layout); } // Render the first line, resetting the state layout.SetText(album.DisplayTitle); layout.FontDescription.Weight = Pango.Weight.Bold; layout.FontDescription.Size = old_size; layout.FontDescription.Style = Pango.Style.Normal; layout.SetText(album.DisplayTitle); context.Context.MoveTo(x, y); text_color.A = 1; context.Context.SetSourceColor(text_color); Pango.CairoHelper.ShowLayout(context.Context, layout); }
protected override bool OnDrawn(Cairo.Context context) { base.OnDrawn(context); var scale = document.Workspace.Scale; var x = (int)document.Workspace.Offset.X; var y = (int)document.Workspace.Offset.Y; // Translate our expose area for the whole drawingarea to just our canvas var canvas_bounds = new Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height); Rectangle expose_rect; if (Gdk.CairoHelper.GetClipRectangle(context, out expose_rect)) { canvas_bounds.Intersect(expose_rect); } if (canvas_bounds.IsEmpty) { return(true); } canvas_bounds.X -= x; canvas_bounds.Y -= y; // Resize our offscreen surface to a surface the size of our drawing area if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height) { canvas?.Dispose(); canvas = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height); } cr.Initialize(document.ImageSize, document.Workspace.CanvasSize); var g = context; // Draw our canvas drop shadow g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, document.Workspace.CanvasSize.Width + 2, document.Workspace.CanvasSize.Height + 2), new Cairo.Color(.5, .5, .5), 1); g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, document.Workspace.CanvasSize.Width + 4, document.Workspace.CanvasSize.Height + 4), new Cairo.Color(.8, .8, .8), 1); g.DrawRectangle(new Cairo.Rectangle(x - 3, y - 3, document.Workspace.CanvasSize.Width + 6, document.Workspace.CanvasSize.Height + 6), new Cairo.Color(.9, .9, .9), 1); // Set up our clip rectangle g.Rectangle(new Cairo.Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height)); g.Clip(); g.Translate(x, y); // Render all the layers to a surface var layers = document.Layers.GetLayersToPaint(); if (layers.Count == 0) { canvas.Clear(); } cr.Render(layers, canvas, canvas_bounds.Location); // Paint the surface to our canvas g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale)); g.Paint(); // Selection outline if (document.Selection.Visible) { var tool_name = PintaCore.Tools.CurrentTool?.GetType().Name ?? string.Empty; var fillSelection = tool_name.Contains("Select") && !tool_name.Contains("Selected"); document.Selection.Draw(g, scale, fillSelection); } return(true); }
public static void RenderThumbnail(Cairo.Context cr, ImageSurface image, bool dispose, double x, double y, double width, double height, bool drawBorder, double radius, bool fill, Color fillColor, CairoCorners corners) { if (image == null || image.Handle == IntPtr.Zero) { image = null; } double p_x = x; double p_y = y; if (image != null) { p_x += image.Width < width ? (width - image.Width) / 2 : 0; p_y += image.Height < height ? (height - image.Height) / 2 : 0; } cr.Antialias = Cairo.Antialias.Default; if (image != null) { if (fill) { CairoExtensions.RoundedRectangle(cr, x, y, width, height, radius, corners); cr.SetSourceColor(fillColor); cr.Fill(); } CairoExtensions.RoundedRectangle(cr, p_x, p_y, image.Width, image.Height, radius, corners); cr.SetSource(image, p_x, p_y); cr.Fill(); } else { CairoExtensions.RoundedRectangle(cr, x, y, width, height, radius, corners); if (fill) { using (var grad = new LinearGradient(x, y, x, y + height)) { grad.AddColorStop(0, fillColor); grad.AddColorStop(1, CairoExtensions.ColorShade(fillColor, 1.3)); cr.SetSource(grad); cr.Fill(); } } Banshee.CairoGlyphs.BansheeLineLogo.Render(cr, new Rectangle(x + 15, y + 15, width - 30, height - 30), CairoExtensions.RgbaToColor(0x00000044), CairoExtensions.RgbaToColor(0x00000055)); } if (!drawBorder) { if (dispose && image != null) { ((IDisposable)image).Dispose(); } return; } cr.LineWidth = 1.0; if (radius < 1) { cr.Antialias = Antialias.None; CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3, radius, corners); cr.SetSourceColor(cover_border_light_color); cr.Stroke(); } CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, radius, corners); cr.SetSourceColor(cover_border_dark_color); cr.Stroke(); if (dispose && image != null) { ((IDisposable)image).Dispose(); } }
static CellRendererSurface() { transparent_pattern = CairoExtensions.CreateTransparentBackgroundPattern(8); }
public void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height) { Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(Widget.StyleContext.GetBackgroundColor(StateFlags.Selected)); DrawRowCursor(cr, x, y, width, height, color); }
private void RenderBackground(Cairo.Context cr) { // Box background CairoExtensions.RoundedRectangle(cr, 0, 0, Allocation.Width, Allocation.Height, 3); cr.SetSourceColor(CairoExtensions.RgbToColor(0xf9f9f9)); cr.Fill(); // Box border cr.LineWidth = 1.0; CairoExtensions.RoundedRectangle(cr, 0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1, 3); cr.SetSourceColor(CairoExtensions.RgbToColor(0x8f8f8f)); cr.Stroke(); // Box header background CairoExtensions.RoundedRectangle(cr, 3, 3, Allocation.Width - 6, header.Allocation.Height + 3, 2, CairoCorners.TopLeft | CairoCorners.TopRight); cr.SetSourceColor(CairoExtensions.RgbToColor(0xd7d9d6)); cr.Fill(); // Highlight children foreach (var item in highlight_widgets) { var widget = item.Key; var flags = item.Value; if (!widget.Visible || !widget.IsMapped) { continue; } if ((flags & HighlightFlags.Background) != 0) { cr.Rectangle(3, widget.Allocation.Y - Allocation.Y - Spacing + 2, Allocation.Width - 6, widget.Allocation.Height + Spacing + 2); cr.SetSourceColor(CairoExtensions.RgbToColor(0xf6f6f6)); cr.Fill(); } cr.LineWidth = 1; cr.SetSourceColor(CairoExtensions.RgbToColor(0x8f8f8f)); if ((flags & HighlightFlags.TopLine) != 0) { double y = widget.Allocation.Y - Allocation.Y + 0.5; cr.MoveTo(0.5, y); cr.LineTo(Allocation.Width - 1, y); cr.Stroke(); } if ((flags & HighlightFlags.BottomLine) != 0) { cr.MoveTo(0.5, widget.Allocation.Y - Allocation.Y + widget.Allocation.Height + 0.5); cr.LineTo(Allocation.Width - 1, widget.Allocation.Y - Allocation.Y + widget.Allocation.Height + 0.5); cr.Stroke(); } } }
void DrawTab(Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp(tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } int padding = LeftRightPadding; padding = (int)(padding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0))); ctx.LineWidth = 1; LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.ClosePath(); using (var gr = new LinearGradient(tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) { if (active) { gr.AddColorStop(0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha(tab.Opacity)); gr.AddColorStop(1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha(tab.Opacity)); } else { gr.AddColorStop(0, CairoExtensions.ParseColor("f4f4f4").MultiplyAlpha(tab.Opacity)); gr.AddColorStop(1, CairoExtensions.ParseColor("cecece").MultiplyAlpha(tab.Opacity)); } ctx.SetSource(gr); } ctx.Fill(); ctx.SetSourceColor(new Cairo.Color(1, 1, 1, .5).MultiplyAlpha(tab.Opacity)); LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 1, active); ctx.Stroke(); ctx.SetSourceColor(Styles.BreadcrumbBorderColor.MultiplyAlpha(tab.Opacity)); LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.StrokePreserve(); if (tab.GlowStrength > 0) { Gdk.Point mouse = tracker.MousePosition; using (var rg = new RadialGradient(mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) { rg.AddColorStop(0, new Cairo.Color(1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength)); rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0)); ctx.SetSource(rg); ctx.Fill(); } } else { ctx.NewPath(); } // Render Close Button (do this first so we can tell how much text to render) var ch = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset; var crect = new Gdk.Rectangle(tabBounds.Right - padding - CloseButtonSize + 3, tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2, CloseButtonSize, CloseButtonSize); tab.CloseButtonAllocation = crect; tab.CloseButtonAllocation.Inflate(2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains(tracker.MousePosition) && tab.WidthModifier >= 1.0f; bool drawCloseButton = tabBounds.Width > 60 || highlight || closeButtonHovered; if (drawCloseButton) { DrawCloseButton(ctx, new Gdk.Point(crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength); } // Render Text int w = tabBounds.Width - (padding * 2 + CloseButtonSize); if (!drawCloseButton) { w += CloseButtonSize; } int textStart = tabBounds.X + padding; ctx.MoveTo(textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize); if (!Platform.IsMac && !Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(w * Pango.Scale.PangoScale); ctx.SetSourceColor(tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor); Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0)); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient(textStart + w - 5, 0, textStart + w + 3, 0)) { var color = tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor; color = color.MultiplyAlpha(tab.Opacity); lg.AddColorStop(0, color); color.A = 0; lg.AddColorStop(1, color); ctx.SetSource(lg); Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0)); } } la.Dispose(); }