Skip to content

Commit

Permalink
Merge branch 'master' into release-1.5
Browse files Browse the repository at this point in the history
Fix some critical bugs with Pinta on Ubuntu 14.04.
  • Loading branch information
cameronwhite committed Apr 26, 2014
2 parents 5643c50 + 11134d1 commit 99b1592
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 78 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
*.pidb
*.suo
*.userprefs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
bin
config.log
config.status
configure
install-sh
intltool-extract.in
intltool-merge.in
intltool-update.in
Makefile
Makefile.in
missing
obj
pinta
pinta.pc
intltool-extract.in
intltool-merge.in
intltool-update.in
po/.intltool-merge-cache
po/Makefile.in.in
po/POTFILES
po/stamp-it
xdg/pinta.desktop
2 changes: 1 addition & 1 deletion Pinta.Core/Actions/EditActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void HandlePintaCoreActionsEditFillSelectionActivated (object sender, Ev
g.AppendPath (doc.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;

g.Color = PintaCore.Palette.PrimaryColor;
g.SetSourceColor (PintaCore.Palette.PrimaryColor);
g.Fill ();
}

Expand Down
6 changes: 3 additions & 3 deletions Pinta.Core/Classes/DocumentSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ public void Draw (Cairo.Context g, double scale, bool fillSelection)

if (fillSelection)
{
g.Color = new Cairo.Color (0.7, 0.8, 0.9, 0.2);
g.SetSourceColor (new Cairo.Color (0.7, 0.8, 0.9, 0.2));
g.FillRule = Cairo.FillRule.EvenOdd;
g.FillPreserve ();
}

g.LineWidth = 1 / scale;

// Draw a white line first so it shows up on dark backgrounds
g.Color = new Cairo.Color (1, 1, 1);
g.SetSourceColor (new Cairo.Color (1, 1, 1));
g.StrokePreserve ();

// Draw a black dashed line over the white line
g.SetDash (new double[] { 2 / scale, 4 / scale }, 0);
g.Color = new Cairo.Color (0, 0, 0);
g.SetSourceColor (new Cairo.Color (0, 0, 0));

g.Stroke ();
g.Restore ();
Expand Down
86 changes: 59 additions & 27 deletions Pinta.Core/Extensions/CairoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using System;
using Cairo;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Pinta.Core
{
Expand All @@ -59,7 +60,7 @@ public static Rectangle DrawRectangle (this Context g, Rectangle r, Color color,
g.LineTo (r.X, r.Y + r.Height);
g.LineTo (r.X, r.Y);

g.Color = color;
g.SetSourceColor (color);
g.LineWidth = lineWidth;
g.LineCap = LineCap.Square;

Expand Down Expand Up @@ -97,7 +98,7 @@ public static Rectangle FillRectangle (this Context g, Rectangle r, Color color)
g.LineTo (r.X, r.Y + r.Height);
g.LineTo (r.X, r.Y);

g.Color = color;
g.SetSourceColor (color);

Rectangle dirty = g.FixedStrokeExtents ();

Expand All @@ -117,7 +118,7 @@ public static Rectangle FillRectangle (this Context g, Rectangle r, Pattern patt
g.LineTo (r.X, r.Y + r.Height);
g.LineTo (r.X, r.Y);

g.Pattern = pattern;
g.SetSource (pattern);

Rectangle dirty = g.FixedStrokeExtents ();
g.Fill ();
Expand All @@ -135,7 +136,7 @@ public static Rectangle DrawPolygonal (this Context g, PointD[] points, Color co
g.LineTo (point.X, point.Y);
}

g.Color = color;
g.SetSourceColor (color);

Rectangle dirty = g.FixedStrokeExtents ();
g.Stroke ();
Expand All @@ -153,7 +154,7 @@ public static Rectangle FillPolygonal (this Context g, PointD[] points, Color co
foreach (var point in points)
g.LineTo (point);

g.Color = color;
g.SetSourceColor (color);

Rectangle dirty = g.FixedStrokeExtents ();
g.Fill ();
Expand Down Expand Up @@ -182,10 +183,10 @@ public static Rectangle FillStrokedRectangle (this Context g, Rectangle r, Color
g.LineTo (x, y + r.Height);
g.LineTo (x, y);

g.Color = fill;
g.SetSourceColor (fill);
g.FillPreserve ();

g.Color = stroke;
g.SetSourceColor (stroke);
g.LineWidth = lineWidth;
g.LineCap = LineCap.Square;

Expand Down Expand Up @@ -216,7 +217,7 @@ public static Rectangle DrawEllipse (this Context g, Rectangle r, Color color, i

g.ClosePath ();

g.Color = color;
g.SetSourceColor (color);
g.LineWidth = lineWidth;

Rectangle dirty = g.FixedStrokeExtents ();
Expand Down Expand Up @@ -246,7 +247,7 @@ public static Rectangle FillEllipse (this Context g, Rectangle r, Color color)

g.ClosePath ();

g.Color = color;
g.SetSourceColor (color);

Rectangle dirty = g.FixedStrokeExtents ();

Expand Down Expand Up @@ -301,10 +302,10 @@ public static Rectangle FillStrokedEllipse (this Context g, Rectangle r, Color f

g.ClosePath ();

g.Color = fill;
g.SetSourceColor (fill);
g.FillPreserve ();

g.Color = stroke;
g.SetSourceColor (stroke);
g.LineWidth = lineWidth;

Rectangle dirty = g.FixedStrokeExtents ();
Expand Down Expand Up @@ -332,10 +333,10 @@ public static Rectangle FillStrokedRoundedRectangle (this Context g, Rectangle r
g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
g.ClosePath ();

g.Color = fill;
g.SetSourceColor (fill);
g.FillPreserve ();

g.Color = stroke;
g.SetSourceColor (stroke);
g.LineWidth = lineWidth;

Rectangle dirty = g.FixedStrokeExtents ();
Expand Down Expand Up @@ -363,7 +364,7 @@ public static Rectangle FillRoundedRectangle (this Context g, Rectangle r, doubl
g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
g.ClosePath ();

g.Color = fill;
g.SetSourceColor (fill);

Rectangle dirty = g.FixedStrokeExtents ();

Expand All @@ -377,7 +378,7 @@ public static void FillRegion (this Context g, Gdk.Region region, Color color)
{
g.Save ();

g.Color = color;
g.SetSourceColor (color);

foreach (Gdk.Rectangle r in region.GetRectangles ()) {
g.MoveTo (r.X, r.Y);
Expand All @@ -386,7 +387,7 @@ public static void FillRegion (this Context g, Gdk.Region region, Color color)
g.LineTo (r.X, r.Y + r.Height);
g.LineTo (r.X, r.Y);

g.Color = color;
g.SetSourceColor (color);

g.FixedStrokeExtents ();
g.Fill ();
Expand All @@ -403,7 +404,7 @@ public static Rectangle DrawRoundedRectangle (this Context g, Rectangle r, doubl

g.AppendPath (p);

g.Color = stroke;
g.SetSourceColor (stroke);
g.LineWidth = lineWidth;

Rectangle dirty = g.FixedStrokeExtents ();
Expand Down Expand Up @@ -463,7 +464,7 @@ public static Rectangle DrawLine (this Context g, PointD p1, PointD p2, Color co
g.MoveTo (p1.X, p1.Y);
g.LineTo (p2.X, p2.Y);

g.Color = color;
g.SetSourceColor (color);
g.LineWidth = lineWidth;
g.LineCap = LineCap.Square;

Expand All @@ -485,17 +486,42 @@ public static Rectangle DrawLine (this Context g, PointD p1, PointD p2, Color co
/// bottom-right corner of the Rectangle in the width and
/// height members. This method corrects the rectangle to
/// contain the width and height in the width and height members.
///
/// This can be removed once we port to GTK3.
/// </summary>
/// <returns>
/// The rectangle describing the area that would be
/// affected.
/// </returns>
public static Rectangle FixedStrokeExtents (this Context g)
{
Rectangle r = g.StrokeExtents();
return new Rectangle (r.X, r.Y, r.Width - r.X, r.Height - r.Y);
double x1, y1, x2, y2;
cairo_stroke_extents (g.Handle, out x1, out y1, out x2, out y2);
return new Rectangle (x1, y1, x2 - x1, y2 - y1);
}

/// <summary>
/// The Pattern property is now deprecated in favour of the SetSource (pattern) method,
/// but that method doesn't exist in older versions of Mono.Cairo. This extension method
/// provides an implementation of that functionality.
///
/// This can be removed once we port to GTK3.
/// </summary>
public static void SetSource (this Context g, Pattern source)
{
#pragma warning disable 612
cairo_set_source (g.Handle, source.Pointer);
#pragma warning restore 612
}

private const string CairoLib = "libcairo-2.dll";

[DllImport (CairoLib, CallingConvention=CallingConvention.Cdecl)]
private static extern void cairo_stroke_extents (IntPtr cr, out double x1, out double y1, out double x2, out double y2);

[DllImport (CairoLib, CallingConvention=CallingConvention.Cdecl)]
private static extern void cairo_set_source (IntPtr cr, IntPtr pattern);

private static Pango.Style CairoToPangoSlant (FontSlant slant)
{
switch (slant) {
Expand All @@ -518,7 +544,7 @@ public static Rectangle DrawText (this Context g, PointD p, string family, FontS
g.Save ();

g.MoveTo (p.X, p.Y);
g.Color = color;
g.SetSourceColor (color);
g.Antialias = antiAliasing ? Antialias.Subpixel : Antialias.None;

Pango.Layout layout = Pango.CairoHelper.CreateLayout (g);
Expand Down Expand Up @@ -560,12 +586,12 @@ public static void DrawLinearGradient (this Context g, Surface oldsurface, Gradi
if (mode == GradientColorMode.Color) {
gradient.AddColorStop (0, c1);
gradient.AddColorStop (1, c2);
g.Source = gradient;
g.SetSource (gradient);
g.Paint ();
} else if (mode == GradientColorMode.Transparency) {
gradient.AddColorStop (0, new Color (0, 0, 0, 1));
gradient.AddColorStop (1, new Color (0, 0, 0, 0));
g.Source = new SurfacePattern (oldsurface);
g.SetSource (new SurfacePattern (oldsurface));
g.Mask (gradient);
}

Expand All @@ -582,13 +608,13 @@ public static void DrawLinearReflectedGradient (this Context g, Surface oldsurfa
gradient.AddColorStop (0, c1);
gradient.AddColorStop (0.5, c2);
gradient.AddColorStop (1, c1);
g.Source = gradient;
g.SetSource (gradient);
g.Paint ();
} else if (mode == GradientColorMode.Transparency) {
gradient.AddColorStop (0, new Color (0, 0, 0, 1));
gradient.AddColorStop (0.5, new Color (0, 0, 0, 0));
gradient.AddColorStop (1, new Color (0, 0, 0, 1));
g.Source = new SurfacePattern (oldsurface);
g.SetSource (new SurfacePattern (oldsurface));
g.Mask (gradient);
}

Expand All @@ -604,17 +630,23 @@ public static void DrawRadialGradient (this Context g, Surface oldsurface, Gradi
if (mode == GradientColorMode.Color) {
gradient.AddColorStop (0, c1);
gradient.AddColorStop (1, c2);
g.Source = gradient;
g.SetSource (gradient);
g.Paint ();
} else if (mode == GradientColorMode.Transparency) {
gradient.AddColorStop (0, new Color (0, 0, 0, 1));
gradient.AddColorStop (1, new Color (0, 0, 0, 0));
g.Source = new SurfacePattern (oldsurface);
g.SetSource (new SurfacePattern (oldsurface));
g.Mask (gradient);
}

g.Restore ();
}

// The Color property is deprecated, so use this extension method until SetSourceColor is officially available everywhere.
public static void SetSourceColor (this Context g, Color c)
{
g.SetSourceRGBA (c.R, c.G, c.B, c.A);
}
#endregion

public static double Distance (this PointD s, PointD e)
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Effects/Dialogs/Effects.CurvesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private void DrawPointerCross (Context g)

private void DrawGrid (Context g)
{
g.Color = new Color (0.05, 0.05, 0.05);
g.SetSourceColor (new Color (0.05, 0.05, 0.05));
g.SetDash (new double[] {4, 4}, 2);
g.LineWidth = 1;

Expand Down Expand Up @@ -390,7 +390,7 @@ private void DrawSpline (Context g)
infos.MoveNext ();
var info = infos.Current;

g.Color = info.Color;
g.SetSourceColor (info.Color);
g.LineWidth = info.IsActive ? 2 : 1;
g.Stroke ();
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void DrawGradient (Context g)
pat.AddColorStop (1, new Cairo.Color (0, 0, 0));

g.Rectangle (rect);
g.Pattern = pat;
g.SetSource (pat);
g.Fill();
}

Expand Down
4 changes: 2 additions & 2 deletions Pinta.Gui.Widgets/Widgets/Layers/CellRendererSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CellRendererSurface (int width, int height)
int grid_width = 4;

using (Cairo.Context g = new Cairo.Context (transparent)) {
g.Color = new Cairo.Color (1, 1, 1);
g.SetSourceColor (new Cairo.Color (1, 1, 1));
g.Paint ();

for (int y = 0; y < height; y += grid_width)
Expand Down Expand Up @@ -123,7 +123,7 @@ private void RenderCell (Context g, int width, int height)
g.Restore ();

// TODO: scale this box correctly to match layer aspect ratio
g.Color = new Cairo.Color (0.5, 0.5, 0.5);
g.SetSourceColor (new Cairo.Color (0.5, 0.5, 0.5));
g.Rectangle (offset_x + 0.5, offset_y + 0.5, draw_width, draw_height);
g.LineWidth = 1;
g.Stroke ();
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Tools/Tools/EraserTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected override void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, C

// Right-click is erase to background color, left-click is transparent
if (mouse_button == 3)
g.Color = PintaCore.Palette.SecondaryColor;
g.SetSourceColor (PintaCore.Palette.SecondaryColor);
else
g.Operator = Operator.Clear;

Expand Down

0 comments on commit 99b1592

Please sign in to comment.