2009-10-05 Chris Toshok <toshok@ximian.com>
[moon.git] / tools / mopen / CompositeHelper.cs
blobd5ebc1a2c4c6c0efe215ad101e4e7c7658078813
1 //
2 // CompositeHelper.cs
3 //
4 // Simple helper methods for doing rgba drawing
5 //
6 // Author: Larry Ewing <lewing@novell.com>
7 //
8 //
9 using System;
10 using System.Runtime.InteropServices;
11 using Cairo;
12 using Gtk;
13 using Gdk;
15 static class CompositeHelper {
16 [DllImport("libgdk-win32-2.0-0.dll")]
17 static extern IntPtr gdk_cairo_create (IntPtr raw);
19 [DllImport("libgdk-win32-2.0-0.dll")]
20 static extern IntPtr gdk_screen_get_rgba_colormap (IntPtr screen);
22 [DllImport("libgdk-win32-2.0-0.dll")]
23 static extern void gdk_cairo_region (IntPtr ctx, IntPtr region);
25 public static Cairo.Context Create (Gdk.Drawable drawable)
27 Cairo.Context ctx = new Cairo.Context (gdk_cairo_create (drawable.Handle));
28 if (ctx == null)
29 throw new Exception ("Couldn't create Cairo Graphics!");
31 return ctx;
34 public static void Region (Cairo.Context ctx, Gdk.Region region)
36 gdk_cairo_region (ctx.Handle, region.Handle);
39 public static Colormap GetRgbaColormap (Screen screen)
41 try {
42 IntPtr raw_ret = gdk_screen_get_rgba_colormap (screen.Handle);
43 Gdk.Colormap ret = GLib.Object.GetObject(raw_ret) as Gdk.Colormap;
44 return ret;
45 } catch {
46 Gdk.Visual visual = Gdk.Visual.GetBestWithDepth (32);
47 if (visual != null) {
48 Gdk.Colormap cmap = new Gdk.Colormap (visual, false);
49 System.Console.WriteLine ("fallback");
50 return cmap;
53 return null;
56 public static bool SetRgbaColormap (Widget w)
58 Gdk.Colormap cmap = GetRgbaColormap (w.Screen);
60 if (cmap != null) {
61 w.Colormap = cmap;
62 return true;
65 return false;