Skip to content

Commit

Permalink
Port CreateMissingImage() to GTK3.
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Jul 16, 2020
1 parent 80e3a77 commit a974032
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions Pinta.Core/Extensions/CairoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ public static bool ContainsPoint (this Cairo.Rectangle r, Cairo.PointD point)

public unsafe static Gdk.Pixbuf ToPixbuf (this Cairo.ImageSurface surfSource)
{
// TODO-GTK3 use Gdk.Pixbuf.GetFromSurface once available (https://github.com/GtkSharp/GtkSharp/issues/174)
using (Cairo.ImageSurface surf = surfSource.Clone ()) {
surf.Flush ();

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/CoreEffectsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace Pinta.Effects
{
// TODO-GTK3
// TODO-GTK3 (addins)
#if false
[Mono.Addins.Extension]
class CoreEffectsExtension : IExtension
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Utilities/EffectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class EffectHelper
/// The localizer for the effect add-in. This is used to fetch translations for the
/// strings in the dialog.
/// </param>
// TODO-GTK3
// TODO-GTK3 (addins)
#if false
public static bool LaunchSimpleEffectDialog (BaseEffect effect, AddinLocalizer localizer)
{
Expand Down
43 changes: 23 additions & 20 deletions Pinta.Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,29 @@ public static Stream GetResourceIconStream (string name)
// https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/gtk-gui/generated.cs
private static Pixbuf CreateMissingImage (int size)
{
// TODO-GTK3 implement this. This will probably need to use Cairo:
// https://developer.gnome.org/gtk3/stable/ch26s02.html#id-1.6.3.4.5
#if false
var pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, size, size);
var gc = new Gdk.GC (pmap);

gc.RgbFgColor = new Gdk.Color (255, 255, 255);
pmap.DrawRectangle (gc, true, 0, 0, size, size);
gc.RgbFgColor = new Gdk.Color (0, 0, 0);
pmap.DrawRectangle (gc, false, 0, 0, (size - 1), (size - 1));

gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
gc.RgbFgColor = new Gdk.Color (255, 0, 0);
pmap.DrawLine (gc, (size / 4), (size / 4), ((size - 1) - (size / 4)), ((size - 1) - (size / 4)));
pmap.DrawLine (gc, ((size - 1) - (size / 4)), (size / 4), (size / 4), ((size - 1) - (size / 4)));

return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, size, size);
#else
throw new NotImplementedException();
#endif
using (var surf = new Cairo.ImageSurface(Cairo.Format.Argb32, size, size))
using (var g = new Cairo.Context(surf))
{
g.SetSourceColor(new Cairo.Color(1, 1, 1));
g.Rectangle(0, 0, size, size);
g.Fill();

g.SetSourceColor(new Cairo.Color(0, 0, 0));
g.Rectangle(0, 0, size - 1, size - 1);
g.Fill();

g.LineWidth = 3;
g.LineCap = Cairo.LineCap.Round;
g.LineJoin = Cairo.LineJoin.Round;
g.SetSourceColor(new Cairo.Color(1, 0, 0));
g.MoveTo(size / 4, size / 4);
g.LineTo((size - 1) - (size / 4), (size - 1) - (size / 4));
g.MoveTo((size - 1) - (size / 4), size / 4);
g.LineTo(size / 4, (size - 1) - (size / 4));

// TODO-GTK3 use Gdk.Pixbuf.GetFromSurface once available (https://github.com/GtkSharp/GtkSharp/issues/174)
return new Gdk.Pixbuf(surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
}
}

private static Gtk.IconSize GetIconSize(int size)
Expand Down

0 comments on commit a974032

Please sign in to comment.