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); }
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.SetSource(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.SetSource(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.SetSource(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.SetSource(lg); context.Stroke(); } context.ResetClip(); }
void RenderButton(Cairo.Context context, Gdk.Point corner, double opacity, bool hovered) { Gdk.Rectangle region = new Gdk.Rectangle(corner.X, corner.Y, ButtonSize.Width, ButtonSize.Height); context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3); using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) { if (hovered) { lg.AddColorStop(0, new Cairo.Color(.15, .76, .09, opacity)); lg.AddColorStop(1, new Cairo.Color(.41, .91, .46, opacity)); } else { lg.AddColorStop(0, new Cairo.Color(.41, .91, .46, opacity)); lg.AddColorStop(1, new Cairo.Color(.15, .76, .09, opacity)); } context.SetSource(lg); context.FillPreserve(); } context.SetSourceRGBA(.29, .79, .28, opacity); context.LineWidth = 1; context.Stroke(); region.Inflate(-1, -1); context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 2); using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) { lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .74 * opacity)); lg.AddColorStop(0.1, new Cairo.Color(1, 1, 1, 0)); lg.AddColorStop(0.9, new Cairo.Color(0, 0, 0, 0)); lg.AddColorStop(1, new Cairo.Color(0, 0, 0, .34 * opacity)); context.SetSource(lg); context.Stroke(); } using (var layout = ButtonLayout(PangoContext)) { int w, h; layout.GetPixelSize(out w, out h); RenderShadowedText(context, new Gdk.Point(corner.X + ButtonSize.Width / 2 - w / 2, corner.Y + ButtonSize.Height / 2 - h / 2 - 1), opacity, layout); } }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; Theme.Widget.StyleContext.Save(); Theme.Widget.StyleContext.AddClass("entry"); Theme.Widget.StyleContext.RenderBackground(cr, 0, 0, RenderSize.Width, RenderSize.Height); var color = CairoExtensions.GdkRGBAToCairoColor(Theme.Widget.StyleContext.GetColor(Gtk.StateFlags.Active)); Theme.Widget.StyleContext.Restore(); // TODO get Dark color Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; using (var fill = new LinearGradient(0, 0, 0, RenderSize.Height)) { fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); } }
/// <summary> /// Rotates layer by the specified angle (in degrees). /// </summary> /// <param name='angle'> /// Angle (in degrees). /// </param> public void Rotate(double angle) { int w = PintaCore.Workspace.ImageSize.Width; int h = PintaCore.Workspace.ImageSize.Height; double radians = (angle / 180d) * Math.PI; double cos = Math.Cos(radians); double sin = Math.Sin(radians); var newSize = RotateDimensions(PintaCore.Workspace.ImageSize, angle); Layer dest = PintaCore.Layers.CreateLayer(string.Empty, newSize.Width, newSize.Height); using (Cairo.Context g = new Cairo.Context(dest.Surface)) { g.Matrix = new Matrix(cos, sin, -sin, cos, newSize.Width / 2.0, newSize.Height / 2.0); g.Translate(-w / 2.0, -h / 2.0); g.SetSource(Surface); g.Paint(); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose(); }
public void Render(DrawingArea area, SettingsModel settings) { var width = area.Allocation.Width; var height = area.Allocation.Height; var kaleidoscope = _factory.Get (settings.Type); var rootNode = kaleidoscope.Generate ( settings.GeometyWidth, settings.ImageUri, width, height); ImageSurface surface = new ImageSurface(Format.Argb32, width, height); using (var context = new Context (surface)) { context.Translate(width / 2, height / 2); rootNode.Render (context); } rootNode.Geometry.Dispose (); using (Context context = Gdk.CairoHelper.Create (area.GdkWindow)) { context.Rectangle(0, 0, width, height); context.SetSource(surface); context.Fill(); context.GetTarget ().Dispose (); } surface.Dispose (); }
void HandleWindowExposeEvent(object o, ExposeEventArgs args) { using (Cairo.Context cr = Gdk.CairoHelper.Create(args.Event.Window)) { cr.Operator = Operator.Source; if (currentSurface == null || currentSurface.Internal == null) { cr.Color = new Cairo.Color(1, 1, 1, 0); } else { if (background_buffer == null) { background_buffer = new DockySurface(currentSurface.Width, currentSurface.Height, cr.Target); DrawBackground(background_buffer); } background_buffer.Internal.Show(cr, 0, 0); cr.Operator = Operator.Over; cr.SetSource(currentSurface.Internal); } cr.Paint(); (cr.Target as IDisposable).Dispose(); } }
public override void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc) { cr.LineWidth = BorderWidth; border_color.A = 0.3; cr.SetSourceColor(border_color); double offset = (double)BorderWidth / 2.0; double w = Math.Max(0, alloc.Width * 0.75); double x = alloc.X + (alloc.Width - w) * 0.5 + offset; double y = alloc.Y + alloc.Height + offset; LinearGradient g = new LinearGradient(x, y, x + w, y); Color transparent = border_color; transparent.A = 0.0; g.AddColorStop(0, transparent); g.AddColorStop(0.4, border_color); g.AddColorStop(0.6, border_color); g.AddColorStop(1, transparent); cr.SetSource(g); cr.MoveTo(x, y); cr.LineTo(x + w, y); cr.Stroke(); g.Dispose(); }
public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners) { color.A *= 0.85; Cairo.Color selection_color = color; Cairo.Color selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85); selection_stroke.A = color.A; if (filled) { Cairo.Color selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.05); Cairo.Color selection_fill_dark = selection_color; selection_fill_light.A = color.A; selection_fill_dark.A = color.A; LinearGradient grad = new LinearGradient(x, y, x, y + height); grad.AddColorStop(0, selection_fill_dark); grad.AddColorStop(1, selection_fill_light); cr.SetSource(grad); cr.Rectangle(x, y, width, height); cr.Fill(); grad.Dispose(); } if (stroked && !filled) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_stroke); cr.Rectangle(x + 0.5, y + 0.5, width - 1, height - 1); cr.Stroke(); } }
protected override void OnFillRegionComputed(Point[][] polygonSet) { SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name); hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer); PintaCore.Layers.ToolLayer.Clear (); ImageSurface surface = PintaCore.Layers.ToolLayer.Surface; for (int x = 0; x < stencil.Width; x++) for (int y = 0; y < stencil.Height; y++) if (stencil.GetUnchecked (x, y)) surface.SetPixel (x, y, fill_color); using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = Antialias.Subpixel; g.SetSource (surface); g.Paint (); } PintaCore.History.PushNewItem (hist); PintaCore.Workspace.Invalidate (); }
public override void Apply(Cairo.Context cr) { if (surface != null) { cr.SetSource(surface); } }
public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners, bool flat_fill) { var selection_color = color; var selection_highlight = CairoExtensions.ColorShade(selection_color, 1.24); var selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85); selection_highlight.A = 0.5; selection_stroke.A = color.A; LinearGradient grad = null; if (filled) { if (flat_fill) { cr.SetSourceColor(selection_color); } else { var selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.12); var selection_fill_dark = selection_color; selection_fill_light.A = color.A; selection_fill_dark.A = color.A; grad = new LinearGradient(x, y, x, y + height); grad.AddColorStop(0, selection_fill_light); grad.AddColorStop(0.4, selection_fill_dark); grad.AddColorStop(1, selection_fill_light); cr.SetSource(grad); } CairoExtensions.RoundedRectangle(cr, x, y, width, height, Context.Radius, corners, true); cr.Fill(); if (grad != null) { grad.Dispose(); } } if (filled && stroked) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_highlight); CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3, Context.Radius - 1, corners, true); cr.Stroke(); } if (stroked) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_stroke); CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, Context.Radius, corners, true); cr.Stroke(); } }
public static void ShowAtEdge(this DockySurface self, DockySurface target, PointD point, DockPosition position) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; double x = point.X; double y = point.Y; switch (position) { case DockPosition.Top: x -= self.Width / 2; break; case DockPosition.Left: y -= self.Height / 2; break; case DockPosition.Right: x -= self.Width; y -= self.Height / 2; break; case DockPosition.Bottom: x -= self.Width / 2; y -= self.Height; break; } cr.SetSource(self.Internal, (int)x, (int)y); cr.Paint(); }
protected override bool OnDrawn(Cairo.Context cr) { base.OnDrawn(cr); if (Surface != null) { cr.SetSourceSurface(Surface, XOffset, YOffset); cr.Paint(); } else if (Image != null) { Bitmap orig = Image; using (Surface source = CairoHelper.LockBitmap(orig)) { cr.Scale(Scale, Scale); cr.SetSource(source, XOffset, YOffset); ((SurfacePattern)cr.Source).Filter = Filter.Nearest; cr.Scale(1.0 / Scale, 1.0 / Scale); cr.Paint(); CairoHelper.UnlockBitmap(orig); } } if (hoveringIndex != -1) { cr.NewPath(); cr.SetSourceColor(HoverColor); cr.Rectangle(new Cairo.Rectangle(XOffset + HoveringX * TileWidth * Scale + 0.5, YOffset + HoveringY * TileHeight * Scale + 0.5, ScaledTileWidth - 1, ScaledTileHeight - 1)); cr.LineWidth = 1; cr.LineJoin = LineJoin.Bevel; cr.Stroke(); } return(true); }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; cr.SetSourceColor(Theme.Colors.GetWidgetColor(GtkColorClass.Base, Gtk.StateType.Normal)); cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height); cr.Fill(); Color color = Theme.Colors.GetWidgetColor(GtkColorClass.Dark, Gtk.StateType.Active); Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; LinearGradient fill = new LinearGradient(0, 0, 0, RenderSize.Height); fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); }
public static void ShowWithOptions(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; double cos, sin; cos = Math.Cos(rotation); sin = Math.Sin(rotation); Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y); cr.Transform(m); if (zoom != 1) { cr.Scale(zoom, zoom); } cr.SetSource(self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha(opacity); cr.IdentityMatrix(); }
void RenderBackground(Cairo.Context context, Gdk.Rectangle region) { region.Inflate(-Padding, -Padding); context.RenderOuterShadow(new Gdk.Rectangle(region.X + 10, region.Y + 15, region.Width - 20, region.Height - 15), Padding, 3, .25); context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 5); using (var lg = new LinearGradient(0, region.Y, 0, region.Bottom)) { lg.AddColorStop(0, new Cairo.Color(.36, .53, .73)); lg.AddColorStop(1, new Cairo.Color(.21, .37, .54)); context.SetSource(lg); context.FillPreserve(); } context.Save(); context.Translate(IconPosition.X, IconPosition.Y); context.Scale(0.75, 0.75); Gdk.CairoHelper.SetSourcePixbuf(context, starburst, -starburst.Width / 2, -starburst.Height / 2); context.FillPreserve(); context.Restore(); context.LineWidth = 1; context.SetSourceRGB(.29, .47, .67); context.Stroke(); }
// Flatten image public void FlattenImage() { if (Layers.Count < 2) { throw new InvalidOperationException("Cannot flatten image because there is only one layer."); } Layer dest = Layers[0]; using (Cairo.Context g = new Cairo.Context(dest.Surface)) { for (int i = 1; i < Layers.Count; i++) { Layer source = Layers[i]; g.SetSource(source.Surface); g.PaintWithAlpha(source.Opacity); } } current_layer = 0; while (Layers.Count > 1) { Layer l = Layers[1]; Layers.RemoveAt(1); } PintaCore.Layers.OnLayerRemoved(); Workspace.Invalidate(); }
protected override void RenderCoverArt(Cairo.Context cr, ImageSurface image) { if (image == null) { return; } Gdk.Rectangle alloc = RenderAllocation; int asr = ArtworkSizeRequest; int reflect = (int)(image.Height * 0.2); int surface_w = image.Width; int surface_h = image.Height + reflect; int x = alloc.X + alloc.Width - asr; int y = alloc.Y; Surface scene = null; if (!surfaces.TryGetValue(image, out scene)) { scene = CreateScene(cr, image, reflect); surfaces.Add(image, scene); } cr.Rectangle(x, y, asr, alloc.Height); cr.Color = BackgroundColor; cr.Fill(); x += (asr - surface_w) / 2; y += surface_h > asr ? 0 : (asr - surface_h) / 2; cr.SetSource(scene, x, y); cr.Paint(); }
public static void ShowAsReflection(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity, double height, DockPosition position) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; switch (position) { case DockPosition.Left: point.X -= self.Width * zoom + height; break; case DockPosition.Top: point.Y -= self.Height * zoom + height; break; case DockPosition.Right: point.X += self.Width * zoom + height; break; case DockPosition.Bottom: point.Y += self.Height * zoom + height; break; } double cos, sin; cos = Math.Cos(rotation); sin = Math.Sin(rotation); Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y); cr.Transform(m); if (zoom != 1) { cr.Scale(zoom, zoom); } if (position == DockPosition.Left || position == DockPosition.Right) { cr.Scale(-1, 1); } else { cr.Scale(1, -1); } cr.SetSource(self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha(opacity * .3); cr.IdentityMatrix(); }
protected override void OnStartTransform() { base.OnStartTransform(); Document doc = PintaCore.Workspace.ActiveDocument; // If there is no selection, select the whole image. if (doc.Selection.SelectionPolygons.Count == 0) { doc.Selection.CreateRectangleSelection( new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height)); } original_selection = doc.Selection.Clone(); original_transform.InitMatrix(doc.SelectionLayer.Transform); hist = new MovePixelsHistoryItem(Icon, Name, doc); hist.TakeSnapshot(!doc.ShowSelectionLayer); if (!doc.ShowSelectionLayer) { // Copy the selection to the temp layer doc.CreateSelectionLayer(); doc.ShowSelectionLayer = true; //Use same BlendMode, Opacity and Visibility for SelectionLayer doc.SelectionLayer.BlendMode = doc.CurrentUserLayer.BlendMode; doc.SelectionLayer.Opacity = doc.CurrentUserLayer.Opacity; doc.SelectionLayer.Hidden = doc.CurrentUserLayer.Hidden; using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource(doc.CurrentUserLayer.Surface); g.Clip(); g.Paint(); } Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface; using (Cairo.Context g = new Cairo.Context(surf)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; if (is_alt_pressed) { g.Operator = Cairo.Operator.Clear; } else { g.Operator = Operator.Source; g.SetSourceColor(PintaCore.Palette.SecondaryColor); } g.Fill(); } } PintaCore.Workspace.Invalidate(); }
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) { return; } double p_x = x; double p_y = y; 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 (fill) { cr.Rectangle(x, y, width, height); cr.Color = 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(); if (!drawBorder) { if (dispose) { ((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.Color = cover_border_light_color; cr.Stroke(); } CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, radius, corners); cr.Color = cover_border_dark_color; cr.Stroke(); if (dispose) { ((IDisposable)image).Dispose(); } }
public static Gtk.Image create_big_starred_image(string pic_path) { using (Cairo.ImageSurface img_surface = new ImageSurface(pic_path)) { using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, img_surface.Width + 2, img_surface.Height + 2)) { using (Cairo.Context context = new Context(surface)) { Gdk.Pixbuf tmp_pixbuf = new Gdk.Pixbuf(pic_path); if (!tmp_pixbuf.HasAlpha) { // img_surface.Format not available... context.Rectangle(0, 0, img_surface.Width+2, img_surface.Height+2); context.Fill(); context.Stroke(); } context.SetSource(img_surface, 1, 1); context.Paint(); // evil hack because the interface to cairo is pretty bad Assembly asm = Assembly.GetCallingAssembly(); Stream s = asm.GetManifestResourceStream("big_star.png"); FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create); for (int i = 0; i < s.Length; ++i) fs.WriteByte((byte)s.ReadByte()); fs.Close(); using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) { System.IO.File.Delete(tmp_image_path); context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height); context.Paint(); surface.WriteToPng(tmp_image_path); Gtk.Image img = new Gtk.Image(tmp_image_path); System.IO.File.Delete(tmp_image_path); return img; } } } } }
public static ImageSurface Clone(this ImageSurface surf) { ImageSurface newsurf = new ImageSurface (surf.Format, surf.Width, surf.Height); using (Context g = new Context (newsurf)) { g.SetSource (surf); g.Paint (); } return newsurf; }
public override void RealRenderCairo(Cairo.Context context) { if (Camera.IsRendererOutOfScreen(this)) { return; } Vector2 screenPos = Camera.WorldToScreenPosition(gameObject.transform.position); float realRad = gameObject.transform.LocalToWorldLength(radius); double screenRad = (double)realRad * Camera.instance.zoom; context.Arc((double)screenPos.x, (double)screenPos.y, screenRad, 0, 2 * Math.PI); if (surf == null) { if (useShadow) { LinearGradient g = new LinearGradient(screenPos.x - screenRad, screenPos.y + screenRad, screenPos.x + screenRad, screenPos.y - screenRad); //g.AddColorStopRgb (0.75, new Cairo.Color (ColorR, ColorG, ColorB, ColorA)); g.AddColorStop(0, new Cairo.Color(ColorR * 0.5, ColorG * 0.5, ColorB * 0.5, ColorA * 0.5)); g.AddColorStop(1, new Cairo.Color(ColorR, ColorG, ColorB, ColorA)); context.SetSource(g); context.Fill(); g.Dispose(); } else { context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA); context.Fill(); } } else { context.SetSourceSurface(surf, (int)(screenPos.x - screenRad), (int)(screenPos.y - screenRad)); context.Fill(); context.GetSource().Dispose(); //surf.Dispose (); } /*context.SetSourceRGBA (1,1,1,1); * context.Arc ((double)screenPos.x, * (double)screenPos.y, * (double)realRad * Camera.instance.zoom, * MyMath.FixAngleRad(-Math.PI/4 - gameObject.transform.rotation), MyMath.FixAngleRad(Math.PI /4 - gameObject.transform.rotation)); * * context.Fill ();*/ }
void DrawingAreaHandleExposeEvent(object o, ExposeEventArgs args) { // Paint the ImageSurface onto the DrawingArea DrawingArea area = (DrawingArea)o; using (Cairo.Context context = Gdk.CairoHelper.Create(area.GdkWindow)) { if (s != null) { context.SetSource(s); context.Paint(); } } }
public ImageSurface GetFlattenedImage() { Cairo.ImageSurface surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height); using (Cairo.Context g = new Cairo.Context(surf)) { foreach (var layer in GetLayersToPaint()) { g.SetSource(layer.Surface); g.PaintWithAlpha(layer.Opacity); } } return(surf); }
public ImageSurface GetClippedLayer(int index) { Cairo.ImageSurface surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height); using (Cairo.Context g = new Cairo.Context(surf)) { g.AppendPath(Selection.SelectionPath); g.Clip(); g.SetSource(UserLayers[index].Surface); g.Paint(); } return(surf); }
protected override void DrawBackground (Context context, Gdk.Rectangle region) { LayoutRoundedRectangle (context, region); context.Clip (); context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF")); context.Paint (); context.Save (); context.Translate (region.X + region.Width / 2.0, region.Y + region.Height); using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) { var color = CairoExtensions.ParseColor ("E5F0FF"); rg.AddColorStop (0, color); color.A = 0; rg.AddColorStop (1, color); context.Scale (region.Width / (double)region.Height, 1.0); context.SetSource (rg); context.Paint (); } context.Restore (); LayoutRoundedRectangle (context, region, -3, -3, 2); context.SetSourceRGBA (1, 1, 1, 0.4); context.LineWidth = 1; context.StrokePreserve (); context.Clip (); int boxSize = 11; int x = region.Left + (region.Width % boxSize) / 2; for (; x < region.Right; x += boxSize) { context.MoveTo (x + 0.5, region.Top); context.LineTo (x + 0.5, region.Bottom); } int y = region.Top + (region.Height % boxSize) / 2; y += boxSize / 2; for (; y < region.Bottom; y += boxSize) { context.MoveTo (region.Left, y + 0.5); context.LineTo (region.Right, y + 0.5); } context.SetSourceRGBA (1, 1, 1, 0.2); context.Stroke (); context.ResetClip (); }
protected override bool OnDrawn(Cairo.Context cr) { if (this.isDirty) { this.Rebuild(); } bool baseDrawnResult = base.OnDrawn(cr); cr.SetFontSize(FONT_HEIGHT); cr.SelectFontFace("Mono", FontSlant.Normal, FontWeight.Normal); cr.Rectangle(0.0, 0.0, this.allocRect.Width, this.allocRect.Height); cr.SetSourceRGB(1, 1, 1); cr.Fill(); var gradient = new LinearGradient(0.0, 0.0, 0.0, this.allocRect.Height); gradient.AddColorStopRgb(0.0, new Color(0.4, 0.4, 0.4)); gradient.AddColorStopRgb(0.1, new Color(1.0, 1.0, 1.0)); gradient.AddColorStopRgb(0.2, new Color(0.6, 0.6, 0.6)); gradient.AddColorStopRgb(1.0, new Color(0.1, 0.1, 0.1)); cr.LineWidth = 1; foreach (var box in this.boxen) { this.RoundedRect(cr, box.Rect, 4.0); cr.SetSource(gradient); cr.FillPreserve(); cr.SetSourceRGB(0, 0, 0); cr.Stroke(); int x = (int)(box.Rect.X + TAGBOX_PADDING * 2 + TAGBOX_XSIZE); int y = (int)(box.Rect.Y + box.Rect.Height / 2 + cr.FontExtents.Height / 2 - cr.FontExtents.Descent / 2); cr.MoveTo(x, y); cr.TextPath(box.Tag); cr.SetSourceRGB(1.0, 1.0, 1.0); cr.Fill(); cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XOFFSET); cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, TAGBOX_XSIZE - TAGBOX_XOFFSET * 2); cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XSIZE - TAGBOX_XOFFSET); cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, -TAGBOX_XSIZE + TAGBOX_XOFFSET * 2); cr.Stroke(); } return(baseDrawnResult); }
public override void DrawFrameBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color, Cairo.Pattern pattern) { color.A = Context.FillAlpha; if (pattern != null) { cr.SetSource(pattern); } else { cr.SetSourceColor(color); } CairoExtensions.RoundedRectangle(cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, CairoCorners.All); cr.Fill(); }
public override void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color) { Color light_color = CairoExtensions.ColorShade(color, 1.6); Color dark_color = CairoExtensions.ColorShade(color, 1.3); using (var grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1)) { grad.AddColorStop(0, light_color); grad.AddColorStop(1, dark_color); cr.SetSource(grad); cr.Rectangle(alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2); cr.Fill(); } }
protected override void ClippedRender(Cairo.Context cr) { LinearGradient grad = new LinearGradient(0, 0, RenderSize.Width, RenderSize.Height); grad.AddColorStop(0, new Color(0.5, 0.5, 0.5)); grad.AddColorStop(1, new Color(0, 0, 0)); cr.SetSource(grad); cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height); cr.Fill(); grad.Dispose(); base.ClippedRender(cr); }
public void FlipVertical() { Layer dest = PintaCore.Layers.CreateLayer(); using (Cairo.Context g = new Cairo.Context(dest.Surface)) { g.Matrix = new Matrix(1, 0, 0, -1, 0, Surface.Height); g.SetSource(Surface); g.Paint(); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose(); }
protected unsafe override void OnFillRegionComputed (IBitVector2D stencil) { Document doc = PintaCore.Workspace.ActiveDocument; ImageSurface surf = doc.ToolLayer.Surface; using (var g = new Context (surf)) { g.Operator = Operator.Source; g.SetSource (doc.CurrentUserLayer.Surface); g.Paint (); } SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name); hist.TakeSnapshotOfLayer (doc.CurrentUserLayer); ColorBgra color = fill_color.ToColorBgra ().ToPremultipliedAlpha (); ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr; int width = surf.Width; surf.Flush (); // Color in any pixel that the stencil says we need to fill Parallel.For (0, stencil.Height, y => { int stencil_width = stencil.Width; for (int x = 0; x < stencil_width; ++x) { if (stencil.GetUnchecked (x, y)) { surf.SetColorBgraUnchecked (dstPtr, width, color, x, y); } } }); surf.MarkDirty (); // Transfer the temp layer to the real one, // respecting any selection area using (var g = doc.CreateClippedContext ()) { g.Operator = Operator.Source; g.SetSource (surf); g.Paint (); } doc.ToolLayer.Clear (); doc.History.PushNewItem (hist); doc.Workspace.Invalidate (); }
public override void Render(Context cr) { if (!CanResize) { return; } var selected_color = CairoExtensions.GdkRGBAToCairoColor (Window.StyleContext.GetColor (StateFlags.Selected)); var grad = new LinearGradient (0, 0, 0, Allocation.Height); selected_color.A = 0.4; grad.AddColorStop (0, selected_color); selected_color.A = 1.0; grad.AddColorStop (1, selected_color); cr.SetSource (grad); cr.LineWidth = 1.0; cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1); cr.Stroke (); selected_color.A = 0.5; cr.SetSourceColor (selected_color); double handle_size = 8; double ty = 0.5 + Allocation.Height - handle_size - 3; double tx = 0.5 + (Window.Direction == TextDirection.Ltr ? Allocation.Width - handle_size - 3 : 3); cr.Translate (tx, ty); for (double i = 0; i < 3; i++) { if (Window.Direction == TextDirection.Ltr) { cr.MoveTo (i * 3, handle_size); cr.LineTo (handle_size, i * 3); } else { cr.MoveTo (0, i * 3); cr.LineTo (handle_size - i * 3, handle_size); } } cr.Stroke (); cr.Translate (-tx, -ty); }
/// <summary> /// Exports the specified <see cref="PlotModel" /> to a png file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">Name of the output file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public static void Export(IPlotModel model, string fileName, int width, int height, Pattern background = null) { using (var bm = new ImageSurface(Format.ARGB32, width, height)) { using (var g = new Context(bm)) { if (background != null) { g.Save(); g.SetSource(background); g.Rectangle(0, 0, width, height); g.Fill(); g.Restore(); } var rc = new GraphicsRenderContext { RendersToScreen = false }; rc.SetGraphicsTarget(g); model.Update(true); model.Render(rc, width, height); bm.WriteToPng(fileName); } } }
void FillChecks (Context cr, int x, int y, int width, int height) { int CHECK_SIZE = 32; cr.Save (); Surface check; using (var target = cr.GetTarget ()) { check = target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE); } // draw the check using (Context cr2 = new Context (check)) { cr2.Operator = Operator.Source; cr2.SetSourceRGB (0.4, 0.4, 0.4); cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE); cr2.Fill (); cr2.SetSourceRGB (0.7, 0.7, 0.7); cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); } // Fill the whole surface with the check SurfacePattern check_pattern = new SurfacePattern (check); check_pattern.Extend = Extend.Repeat; cr.SetSource (check_pattern); cr.Rectangle (0, 0, width, height); cr.Fill (); check_pattern.Dispose (); check.Dispose (); cr.Restore (); }
public void Rotate180() { Layer dest = PintaCore.Layers.CreateLayer (); using (Cairo.Context g = new Cairo.Context (dest.Surface)) { g.Matrix = new Matrix (-1, 0, 0, -1, Surface.Width, Surface.Height); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose (); }
public unsafe void HueSaturation(int hueDelta, int satDelta, int lightness) { ImageSurface dest = Surface.Clone (); ColorBgra* dstPtr = (ColorBgra*)dest.DataPtr; int len = Surface.Data.Length / 4; // map the range [0,100] -> [0,100] and the range [101,200] -> [103,400] if (satDelta > 100) satDelta = ((satDelta - 100) * 3) + 100; UnaryPixelOp op; if (hueDelta == 0 && satDelta == 100 && lightness == 0) op = new UnaryPixelOps.Identity (); else op = new UnaryPixelOps.HueSaturationLightness (hueDelta, satDelta, lightness); op.Apply (dstPtr, len); using (Context g = new Context (Surface)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.SetSource (dest); g.Paint (); } (dest as IDisposable).Dispose (); }
void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } double rightPadding = (active ? TabActivePadding.Right : TabPadding.Right) - (LeanWidth / 2); rightPadding = (rightPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); double leftPadding = (active ? TabActivePadding.Left : TabPadding.Left) - (LeanWidth / 2); leftPadding = (leftPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); double bottomPadding = active ? TabActivePadding.Bottom : TabPadding.Bottom; DrawTabBackground (this, ctx, allocation, tabBounds.Width, tabBounds.X, active); ctx.LineWidth = 1; ctx.NewPath (); // Render Close Button (do this first so we can tell how much text to render) var closeButtonAlloation = new Cairo.Rectangle (tabBounds.Right - rightPadding - (tabCloseImage.Width / 2) - CloseButtonMarginRight, tabBounds.Height - bottomPadding - tabCloseImage.Height - CloseButtonMarginBottom, tabCloseImage.Width, tabCloseImage.Height); tab.CloseButtonActiveArea = closeButtonAlloation.Inflate (2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonActiveArea.Contains (tracker.MousePosition); bool tabHovered = tracker.Hovered && tab.Allocation.Contains (tracker.MousePosition); bool drawCloseButton = active || tabHovered; if (!closeButtonHovered && tab.DirtyStrength > 0.5) { ctx.DrawImage (this, tabDirtyImage, closeButtonAlloation.X, closeButtonAlloation.Y); drawCloseButton = false; } if (drawCloseButton) ctx.DrawImage (this, tabCloseImage.WithAlpha ((closeButtonHovered ? 1.0 : 0.5) * tab.Opacity), closeButtonAlloation.X, closeButtonAlloation.Y); // Render Text double tw = tabBounds.Width - (leftPadding + rightPadding); if (drawCloseButton || tab.DirtyStrength > 0.5) tw -= closeButtonAlloation.Width / 2; double tx = tabBounds.X + leftPadding; var baseline = la.GetLine (0).Layout.GetPixelBaseline (); double ty = tabBounds.Height - bottomPadding - baseline; ctx.MoveTo (tx, ty); if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(tw * Pango.Scale.PangoScale); ctx.SetSourceColor ((tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ()); Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient (tx + tw - 10, 0, tx + tw, 0)) { var color = (tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor (); color = color.MultiplyAlpha (tab.Opacity); lg.AddColorStop (0, color); color.A = 0; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout); } } la.Dispose (); }
void DrawShape(Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.SetSource (new SolidPattern (new Cairo.Color (0,0,0,0))); g.Rectangle (0, 0, width, height); g.Paint (); g.NewPath (); g.Translate (cx, cy); g.Rotate (angle); g.SetSource (new SolidPattern (new Cairo.Color (0.2, 0.2, 0.2, .6))); g.Operator = Operator.Over; g.Rectangle (0, - (border + inner), inner_x, 2 * (border + inner)); g.Arc (inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc (0, 0, radius + border, 0, 2 * Math.PI); g.Fill (); g.SetSource (new SolidPattern (new Cairo.Color (0, 0, 0, 1.0))); g.Operator = Operator.DestOut; g.Arc (inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill (); #else g.FillPreserve (); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient (inner_x - (inner * 0.3), inner * 0.3 , inner * 0.1, inner_x, 0, inner); rg.AddColorStop (0, new Cairo.Color (0.0, 0.2, .8, 0.5)); rg.AddColorStop (0.7, new Cairo.Color (0.0, 0.2, .8, 0.1)); rg.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill (); rg.Destroy (); #endif g.Operator = Operator.Over; g.Matrix = new Matrix (); g.Translate (cx, cy); if (source != null) CairoHelper.SetSourcePixbuf (g, source, -source.Width / 2, -source.Height / 2); g.Arc (0, 0, radius, 0, 2 * Math.PI); g.Fill (); if (overlay != null) { CairoHelper.SetSourcePixbuf (g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc (0, 0, radius, angle, angle + Math.PI); g.ClosePath (); g.FillPreserve (); g.SetSource (new SolidPattern (new Cairo.Color (1.0, 1.0, 1.0, 1.0))); g.Stroke (); } }
/// <summary> /// Rotates layer by the specified angle (in degrees). /// </summary> /// <param name='angle'> /// Angle (in degrees). /// </param> public void Rotate(double angle) { int w = PintaCore.Workspace.ImageSize.Width; int h = PintaCore.Workspace.ImageSize.Height; double radians = (angle / 180d) * Math.PI; double cos = Math.Cos (radians); double sin = Math.Sin (radians); var newSize = RotateDimensions (PintaCore.Workspace.ImageSize, angle); Layer dest = PintaCore.Layers.CreateLayer (string.Empty, newSize.Width, newSize.Height); using (Cairo.Context g = new Cairo.Context (dest.Surface)) { g.Matrix = new Matrix (cos, sin, -sin, cos, newSize.Width / 2.0, newSize.Height / 2.0); g.Translate (-w / 2.0, -h / 2.0); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose (); }
public void Crop(Gdk.Rectangle rect, Path path) { ImageSurface dest = new ImageSurface (Format.Argb32, rect.Width, rect.Height); using (Context g = new Context (dest)) { // Move the selected content to the upper left g.Translate (-rect.X, -rect.Y); g.Antialias = Antialias.None; // Respect the selected path g.AppendPath (path); g.FillRule = Cairo.FillRule.EvenOdd; g.Clip (); g.SetSource (Surface); g.Paint (); } (Surface as IDisposable).Dispose (); Surface = dest; }
public void draw(Context cr) { PointD p = model.position; cr.Save(); cr.Translate (p.X-image.Width/2, p.Y-image.Height/2); cr.SetSource(image); cr.Paint(); cr.Restore(); cr.MoveTo(p); cr.SetSourceRGB (0.3, 1.0, 0.3); cr.Arc (p.X, p.Y, 5, 0, 2 * Math.PI); cr.Fill (); }
protected unsafe override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; ColorBgra old_color; ColorBgra new_color; if (mouse_button == 1) { old_color = PintaCore.Palette.PrimaryColor.ToColorBgra (); new_color = PintaCore.Palette.SecondaryColor.ToColorBgra (); } else if (mouse_button == 3) { old_color = PintaCore.Palette.SecondaryColor.ToColorBgra (); new_color = PintaCore.Palette.PrimaryColor.ToColorBgra (); } else { last_point = point_empty; return; } int x = (int)point.X; int y = (int)point.Y; if (last_point.Equals (point_empty)) last_point = new Point (x, y); if (doc.Workspace.PointInCanvas (point)) surface_modified = true; ImageSurface surf = doc.CurrentLayer.Surface; ImageSurface tmp_layer = doc.ToolLayer.Surface; Gdk.Rectangle roi = GetRectangleFromPoints (last_point, new Point (x, y)); roi = PintaCore.Workspace.ClampToImageSize (roi); myTolerance = (int)(Tolerance * 256); tmp_layer.Flush (); ColorBgra* tmp_data_ptr = (ColorBgra*)tmp_layer.DataPtr; int tmp_width = tmp_layer.Width; ColorBgra* surf_data_ptr = (ColorBgra*)surf.DataPtr; int surf_width = surf.Width; // The stencil lets us know if we've already checked this // pixel, providing a nice perf boost // Maybe this should be changed to a BitVector2DSurfaceAdapter? for (int i = roi.X; i <= roi.GetRight (); i++) for (int j = roi.Y; j <= roi.GetBottom (); j++) { if (stencil[i, j]) continue; if (IsColorInTolerance (new_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j))) *tmp_layer.GetPointAddressUnchecked (tmp_data_ptr, tmp_width, i, j) = AdjustColorDifference (new_color, old_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j)); stencil[i, j] = true; } tmp_layer.MarkDirty (); using (Context g = new Context (surf)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.MoveTo (last_point.X, last_point.Y); g.LineTo (x, y); g.LineWidth = BrushWidth; g.LineJoin = LineJoin.Round; g.LineCap = LineCap.Round; g.SetSource (tmp_layer); g.Stroke (); } doc.Workspace.Invalidate (roi); last_point = new Point (x, y); }
private Surface CreateScene (Cairo.Context window_cr, ImageSurface image, int reflect) { Surface surface = window_cr.Target.CreateSimilar (window_cr.Target.Content, image.Width, image.Height + reflect); Cairo.Context cr = new Context (surface); cr.Save (); cr.SetSource (image); cr.Paint (); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * image.Height) + 1); cr.Transform (matrix); cr.SetSource (image); cr.Paint (); cr.Restore (); Color bg_transparent = BackgroundColor; bg_transparent.A = 0.65; LinearGradient mask = new LinearGradient (0, image.Height, 0, image.Height + reflect); mask.AddColorStop (0, bg_transparent); mask.AddColorStop (1, BackgroundColor); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Pattern = mask; cr.Fill (); ((IDisposable)cr).Dispose (); return surface; }
public override void SetAsSource(Context ctx, Rectangle bounds = default(Rectangle)) { float widthRatio = 1f; float heightRatio = 1f; if (Scaled){ widthRatio = (float)bounds.Width / Dimensions.Width; heightRatio = (float)bounds.Height / Dimensions.Height; } if (KeepProportions) { if (widthRatio < heightRatio) heightRatio = widthRatio; else widthRatio = heightRatio; } using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { using (Cairo.Context gr = new Context (tmp)) { gr.Translate (bounds.Left, bounds.Top); gr.Scale (widthRatio, heightRatio); gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2); hSVG.RenderCairo (gr); } ctx.SetSource (tmp); } }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { base.OnMouseMove (o, args, point); if (tracking) { UserBlendOps.NormalBlendOp normalBlendOp = new UserBlendOps.NormalBlendOp(); GradientRenderer gr = null; switch (GradientType) { case eGradientType.Linear: gr = new GradientRenderers.LinearClamped (GradientColorMode == GradientColorMode.Transparency, normalBlendOp); break; case eGradientType.LinearReflected: gr = new GradientRenderers.LinearReflected (GradientColorMode == GradientColorMode.Transparency, normalBlendOp); break; case eGradientType.Radial: gr = new GradientRenderers.Radial (GradientColorMode == GradientColorMode.Transparency, normalBlendOp); break; case eGradientType.Diamond: gr = new GradientRenderers.LinearDiamond (GradientColorMode == GradientColorMode.Transparency, normalBlendOp); break; case eGradientType.Conical: gr = new GradientRenderers.Conical (GradientColorMode == GradientColorMode.Transparency, normalBlendOp); break; } if (button == 3) {//right gr.StartColor = PintaCore.Palette.SecondaryColor.ToColorBgra (); gr.EndColor = PintaCore.Palette.PrimaryColor.ToColorBgra (); } else {//1 left gr.StartColor = PintaCore.Palette.PrimaryColor.ToColorBgra (); gr.EndColor = PintaCore.Palette.SecondaryColor.ToColorBgra (); } gr.StartPoint = startpoint; gr.EndPoint = point; gr.AlphaBlending = UseAlphaBlending; gr.BeforeRender (); Gdk.Rectangle selection_bounds = PintaCore.Layers.SelectionPath.GetBounds (); ImageSurface scratch_layer = PintaCore.Layers.ToolLayer.Surface; gr.Render (scratch_layer, new Gdk.Rectangle[] { selection_bounds }); using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) { g.AppendPath (PintaCore.Layers.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); g.SetSource (scratch_layer); g.Paint (); } selection_bounds.Inflate (5, 5); PintaCore.Workspace.Invalidate (selection_bounds); } }
static void DrawCloseButton (Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress) { if (hovered) { const double radius = 6; context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (.6, .6, .6, opacity); context.Fill (); context.SetSourceRGBA (0.95, 0.95, 0.95, opacity); context.LineWidth = 2; context.MoveTo (center.X - 3, center.Y - 3); context.LineTo (center.X + 3, center.Y + 3); context.MoveTo (center.X - 3, center.Y + 3); context.LineTo (center.X + 3, center.Y - 3); context.Stroke (); } else { double lineColor = .63 - .1 * animationProgress; const double fillColor = .74; double heightMod = Math.Max (0, 1.0 - animationProgress * 2); context.MoveTo (center.X - 3, center.Y - 3 * heightMod); context.LineTo (center.X + 3, center.Y + 3 * heightMod); context.MoveTo (center.X - 3, center.Y + 3 * heightMod); context.LineTo (center.X + 3, center.Y - 3 * heightMod); context.LineWidth = 2; context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); if (animationProgress > 0.5) { double partialProg = (animationProgress - 0.5) * 2; context.MoveTo (center.X - 3, center.Y); context.LineTo (center.X + 3, center.Y); context.LineWidth = 2 - partialProg; context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); double radius = partialProg * 3.5; // Background context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (fillColor, fillColor, fillColor, opacity); context.Fill (); // Inset shadow using (var lg = new LinearGradient (0, center.Y - 5, 0, center.Y)) { context.Arc (center.X, center.Y + 1, radius, 0, Math.PI * 2); lg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.2 * opacity)); lg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0)); context.SetSource (lg); context.Stroke (); } // Outline context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); } } }
public static ImageSurface Clone(this ImageSurface surf) { if (PintaCore.Workspace.HasOpenDocuments) PintaCore.Workspace.ActiveDocument.SignalSurfaceCloned (); ImageSurface newsurf = new ImageSurface (surf.Format, surf.Width, surf.Height); using (Context g = new Context (newsurf)) { g.SetSource (surf); g.Paint (); } return newsurf; }
protected override void OnStartTransform() { base.OnStartTransform (); Document doc = PintaCore.Workspace.ActiveDocument; original_selection = new List<List<IntPoint>> (doc.Selection.SelectionPolygons); original_transform.InitMatrix (doc.SelectionLayer.Transform); hist = new MovePixelsHistoryItem (Icon, Name, doc); hist.TakeSnapshot (!doc.ShowSelectionLayer); if (!doc.ShowSelectionLayer) { // Copy the selection to the temp layer doc.CreateSelectionLayer (); doc.ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource (doc.CurrentUserLayer.Surface); g.Clip (); g.Paint (); } Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface; using (Cairo.Context g = new Cairo.Context (surf)) { g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Operator = Cairo.Operator.Clear; g.Fill (); } } PintaCore.Workspace.Invalidate (); }
public void Rotate90CW() { int w = PintaCore.Workspace.ImageSize.X; int h = PintaCore.Workspace.ImageSize.Y; Layer dest = PintaCore.Layers.CreateLayer (string.Empty, h, w); using (Cairo.Context g = new Cairo.Context (dest.Surface)) { g.Translate (h / 2d, w / 2d); g.Rotate (Math.PI / 2); g.Translate (-w / 2d, -h / 2d); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose (); }
void DrawBackground (Context ctx, Gdk.Rectangle region) { var h = region.Height; ctx.Rectangle (0, 0, region.Width, h); using (var gr = new LinearGradient (0, 0, 0, h)) { if (isActiveNotebook) { gr.AddColorStop (0, Styles.TabBarActiveGradientStartColor); gr.AddColorStop (1, Styles.TabBarActiveGradientEndColor); } else { gr.AddColorStop (0, Styles.TabBarGradientStartColor); gr.AddColorStop (1, Styles.TabBarGradientEndColor); } ctx.SetSource (gr); ctx.Fill (); } ctx.MoveTo (region.X, 0.5); ctx.LineTo (region.Right + 1, 0.5); ctx.LineWidth = 1; ctx.SetSourceColor (Styles.TabBarGradientShadowColor); ctx.Stroke (); }
public virtual void ApplyTransform(Matrix xform, Size new_size) { var old_size = PintaCore.Workspace.ImageSize; var dest = new ImageSurface (Format.ARGB32, new_size.Width, new_size.Height); using (var g = new Context (dest)) { g.Transform (xform); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest; old.Dispose (); }
void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la) { // This logic is stupid to have here, should be in the caller! if (dragging) { tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress); tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width); } int padding = LeftRightPadding; padding = (int)(padding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0))); ctx.LineWidth = 1; LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.ClosePath (); using (var gr = new LinearGradient (tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) { if (active) { gr.AddColorStop (0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha (tab.Opacity)); } else { gr.AddColorStop (0, CairoExtensions.ParseColor ("f4f4f4").MultiplyAlpha (tab.Opacity)); gr.AddColorStop (1, CairoExtensions.ParseColor ("cecece").MultiplyAlpha (tab.Opacity)); } ctx.SetSource (gr); } ctx.Fill (); ctx.SetSourceColor (new Cairo.Color (1, 1, 1, .5).MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 1, active); ctx.Stroke (); ctx.SetSourceColor (Styles.BreadcrumbBorderColor.MultiplyAlpha (tab.Opacity)); LayoutTabBorder (ctx, allocation, tabBounds.Width, tabBounds.X, 0, active); ctx.StrokePreserve (); if (tab.GlowStrength > 0) { Gdk.Point mouse = tracker.MousePosition; using (var rg = new RadialGradient (mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) { rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength)); rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0)); ctx.SetSource (rg); ctx.Fill (); } } else { ctx.NewPath (); } // Render Close Button (do this first so we can tell how much text to render) var ch = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset; var crect = new Gdk.Rectangle (tabBounds.Right - padding - CloseButtonSize + 3, tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2, CloseButtonSize, CloseButtonSize); tab.CloseButtonAllocation = crect; tab.CloseButtonAllocation.Inflate (2, 2); bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains (tracker.MousePosition) && tab.WidthModifier >= 1.0f; bool drawCloseButton = tabBounds.Width > 60 || highlight || closeButtonHovered; if (drawCloseButton) { DrawCloseButton (ctx, new Gdk.Point (crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength); } // Render Text int w = tabBounds.Width - (padding * 2 + CloseButtonSize); if (!drawCloseButton) w += CloseButtonSize; int textStart = tabBounds.X + padding; ctx.MoveTo (textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize); if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) { // This is a work around for a linux specific problem. // A bug in the proprietary ATI driver caused TAB text not to draw. // If that bug get's fixed remove this HACK asap. la.Ellipsize = Pango.EllipsizeMode.End; la.Width = (int)(w * Pango.Scale.PangoScale); ctx.SetSourceColor (tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } else { // ellipses are for space wasting ..., we cant afford that using (var lg = new LinearGradient (textStart + w - 5, 0, textStart + w + 3, 0)) { var color = tab.Notify ? new Cairo.Color (0, 0, 1) : Styles.TabBarActiveTextColor; color = color.MultiplyAlpha (tab.Opacity); lg.AddColorStop (0, color); color.A = 0; lg.AddColorStop (1, color); ctx.SetSource (lg); Pango.CairoHelper.ShowLayoutLine (ctx, la.GetLine (0)); } } la.Dispose (); }
void PlaceSurface (Context cr, DockySurface surface, Gdk.Rectangle allocation) { int iconSize = allocation.Height - IconBuffer * 2; int x = allocation.X + Padding + ((iconSize - surface.Width) / 2); int y = allocation.Y + IconBuffer + ((iconSize - surface.Height) / 2); cr.SetSource (surface.Internal, x, y); }
ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max (256 / (double)source.Bounds.Width, 256 / (double)source.Bounds.Height); var small = new Gdk.Rectangle (0, 0, (int)Math.Ceiling (source.Bounds.Width * scale), (int)Math.Ceiling (source.Bounds.Height * scale)); var image = new ImageSurface (Format.Argb32, small.Width, small.Height); var ctx = new Context (image); ctx.Matrix = source.Fit (small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern (source.Surface); ctx.SetSource (p); ctx.Paint (); p.Dispose (); ctx.Dispose (); ImageInfo overlay = null; using (var normal = image.ToPixbuf ()) { using (var pixbufBlur = PixbufUtils.Blur (normal, 3, null)) { overlay = new ImageInfo (pixbufBlur); } } image.Dispose (); return overlay; }
public void Apply(Context ctx, Gdk.Rectangle allocation) { var p = new SurfacePattern (info.Surface); ctx.Matrix = new Matrix (); Matrix m = info.Fit (allocation); ctx.Operator = Operator.Over; ctx.Matrix = m; ctx.SetSource (p); ctx.Paint (); var overlay = new SurfacePattern (blur.Surface); ctx.Matrix = new Matrix (); ctx.Matrix = blur.Fit (allocation); ctx.Operator = Operator.Over; ctx.SetSource (overlay); // FIXME ouch this is ugly. if (mask == null) Radius = Radius; //ctx.Paint (); ctx.Mask (mask); overlay.Dispose (); p.Dispose (); }