Author: lewing
Date: 2007-06-25 02:33:05 -0400 (Mon, 25 Jun 2007)
New Revision: 80668

Added:
   trunk/moon/gtk/CompositeHelper.cs
   trunk/moon/gtk/mopen.exe.config
Modified:
   trunk/moon/gtk/Makefile.am
   trunk/moon/gtk/mopen.cs
Log:
2007-06-25  Larry Ewing  <lewing@>

        * gtk/mopen.cs:  Add --transparent option that creates a
        transparent toplevel window.

        * gtk/CompositeHelper.cs: 
        * gtk/Makefile.am:
        * gtk/mopen.exe.config: add cairo and gdk helper functions.  
        All of these can go away with sufficiently new gtk# versions.



Added: trunk/moon/gtk/CompositeHelper.cs
===================================================================
--- trunk/moon/gtk/CompositeHelper.cs   2007-06-25 06:13:30 UTC (rev 80667)
+++ trunk/moon/gtk/CompositeHelper.cs   2007-06-25 06:33:05 UTC (rev 80668)
@@ -0,0 +1,67 @@
+//
+// CompositeHelper.cs
+//
+// Simple helper methods for doing rgba drawing
+//
+// Author: Larry Ewing <[EMAIL PROTECTED]>
+//
+//
+using System;
+using System.Runtime.InteropServices;
+using Cairo;
+using Gtk;
+using Gdk;
+
+static class CompositeHelper {
+               [DllImport("libgdk-win32-2.0-0.dll")]
+               static extern IntPtr gdk_cairo_create (IntPtr raw);
+
+               [DllImport("libgdk-win32-2.0-0.dll")]
+               static extern IntPtr gdk_screen_get_rgba_colormap (IntPtr 
screen);
+
+               [DllImport("libgdk-win32-2.0-0.dll")]
+               static extern void gdk_cairo_region (IntPtr ctx, IntPtr region);
+
+               public static Cairo.Context Create (Gdk.Drawable drawable)
+               {
+                       Cairo.Context ctx = new Cairo.Context (gdk_cairo_create 
(drawable.Handle));
+                       if (ctx == null) 
+                               throw new Exception ("Couldn't create Cairo 
Graphics!");
+                       
+                       return ctx;
+               }
+               
+               public static void Region (Cairo.Context ctx, Gdk.Region region)
+               {
+                       gdk_cairo_region (ctx.Handle, region.Handle);
+               }               
+
+               public static Colormap GetRgbaColormap (Screen screen)
+               {
+                       try {
+                               IntPtr raw_ret = gdk_screen_get_rgba_colormap 
(screen.Handle);
+                               Gdk.Colormap ret = 
GLib.Object.GetObject(raw_ret) as Gdk.Colormap;
+                               return ret;
+                       } catch {
+                               Gdk.Visual visual = Gdk.Visual.GetBestWithDepth 
(32);
+                               if (visual != null) {
+                                       Gdk.Colormap cmap = new Gdk.Colormap 
(visual, false);
+                                       System.Console.WriteLine ("fallback");
+                                       return cmap;
+                               }
+                       }
+                       return null;
+               }
+
+               public static bool SetRgbaColormap (Widget w)
+               {
+                       Gdk.Colormap cmap = GetRgbaColormap (w.Screen);
+
+                       if (cmap != null) {
+                               w.Colormap = cmap;
+                               return true;
+                       }
+
+                       return false;
+               }
+}

Modified: trunk/moon/gtk/Makefile.am
===================================================================
--- trunk/moon/gtk/Makefile.am  2007-06-25 06:13:30 UTC (rev 80667)
+++ trunk/moon/gtk/Makefile.am  2007-06-25 06:33:05 UTC (rev 80668)
@@ -2,7 +2,7 @@
 pkgconfigdir = $(prefix)/lib/pkgconfig
 
 bin_SCRIPTS = mopen
-gtksilver_DATA = gtksilver.dll mopen.exe
+gtksilver_DATA = gtksilver.dll mopen.exe mopen.exe.config
 pkgconfig_DATA = gtksilver.pc
 
 EXTRA_DIST= $(gtksilver_dll_CS) $(mopen_exe_CS) gtksilver.snk mopen.in
@@ -12,15 +12,16 @@
                    $(srcdir)/ManagedDownloader.cs \
                    $(srcdir)/Assembly.cs
 
-mopen_exe_CS = $(srcdir)/mopen.cs
+mopen_exe_CS = $(srcdir)/mopen.cs              \
+               $(srcdir)/CompositeHelper.cs
 
 gtksilver_SNK = $(srcdir)/gtksilver.snk
 
 gtksilver.dll: $(gtksilver_dll_CS)
-       gmcs -debug -out:gtksilver.dll -target:library $(gtksilver_dll_CS) 
-keyfile:$(gtksilver_SNK) -pkg:gtk-sharp-2.0 -pkg:silver 
+       gmcs -debug -out:gtksilver.dll -target:library $(gtksilver_dll_CS) 
-keyfile:$(gtksilver_SNK) -pkg:gtk-sharp-2.0 -pkg:silver
 
 mopen.exe: $(mopen_exe_CS) gtksilver.dll 
-       gmcs -debug -out:mopen.exe -target:exe $(mopen_exe_CS) -r:gtksilver.dll 
-pkg:gtk-sharp-2.0 -pkg:silver
+       gmcs -debug -out:mopen.exe -target:exe $(mopen_exe_CS) -r:gtksilver.dll 
-pkg:gtk-sharp-2.0 -pkg:silver -pkg:mono-cairo
 
 do_subst = sed -e 's,[EMAIL PROTECTED]@],$(gtksilverdir),g' -e 's,[EMAIL 
PROTECTED]@],$(VERSION),g' 
 

Modified: trunk/moon/gtk/mopen.cs
===================================================================
--- trunk/moon/gtk/mopen.cs     2007-06-25 06:13:30 UTC (rev 80667)
+++ trunk/moon/gtk/mopen.cs     2007-06-25 06:33:05 UTC (rev 80668)
@@ -41,6 +41,7 @@
 
 using System;
 using Gtk;
+using Cairo;
 using Gtk.Moonlight;
 using System.Windows;
 using System.Windows.Media;
@@ -53,21 +54,42 @@
        static bool fixedwindow = false;
        static int width = -1;
        static int height = -1;
-       
+       static bool transparent = false;        
+
        static void Help ()
        {
                Console.WriteLine ("Usage is: mopen [args] 
[file.xaml|dirname]\n\n" +
                                   "Arguments are:\n" +
                                   "   --fixed         Disable window 
resizing\n"  +
                                   "   --geometry WxH  Overrides the geometry 
to be W x H pixels\n" +
-                                  "   --host NAME     Specifies that this file 
should be loaded in host NAME\n" 
+                                  "   --host NAME     Specifies that this file 
should be loaded in host NAME\n" +
+                                  "   --transparent   Transparent toplevel\n"
                                   );
        }
 
+       [GLib.ConnectBefore]
+       static void HandleExposeEvent (object sender, ExposeEventArgs 
expose_args)
+       {
+                Widget w = (Widget)sender;
+           
+                Cairo.Context ctx = CompositeHelper.Create (w.GdkWindow);
+                ctx.Operator = Cairo.Operator.Source;
+                ctx.Color = new Cairo.Color (1.0, 1.0, 1.0, 0.0);
+                CompositeHelper.Region (ctx, expose_args.Event.Region);
+                ctx.Fill ();
+       }
+
        static int LoadXaml (string file, ArrayList args)
        {
                Application.Init ();
                Window w = new Window (file);
+
+               if (transparent) {
+                       CompositeHelper.SetRgbaColormap (w);
+                       w.AppPaintable = true;
+                       w.ExposeEvent += HandleExposeEvent;
+               }       
+
                w.DeleteEvent += delegate {
                        Application.Quit ();
                };
@@ -174,6 +196,10 @@
                        case "-fixed": case "--fixed":
                                fixedwindow = true;
                                break;
+                       
+                       case "--transparent": case "-t":
+                               transparent = true;
+                               break;
 
                        case "--geometry": case "-g":
                                if (i+1 == args.Length){

Added: trunk/moon/gtk/mopen.exe.config
===================================================================
--- trunk/moon/gtk/mopen.exe.config     2007-06-25 06:13:30 UTC (rev 80667)
+++ trunk/moon/gtk/mopen.exe.config     2007-06-25 06:33:05 UTC (rev 80668)
@@ -0,0 +1,3 @@
+<configuration>
+  <dllmap dll="libgdk-win32-2.0-0.dll" target="/usr/lib/libgdk-x11-2.0.so.0"/>
+</configuration>
\ No newline at end of file

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to