Пример #1
0
        public static Cairo.Context CreateDrawable(Gdk.Drawable drawable)
        {
            IntPtr x_drawable = IntPtr.Zero;
            int    x_off = 0, y_off = 0;

            int x, y, w, h, d;

            ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);

            bool is_gdk_window = drawable is Gdk.Window;

            if (is_gdk_window)
            {
                ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable,
                                                            out x_off, out y_off);
            }

            Cairo.Surface surface;

            PlatformID os = Environment.OSVersion.Platform;

            if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
                os == PlatformID.Win32S || os == PlatformID.WinCE)
            {
                Gdk.GC gcc   = new Gdk.GC(drawable);
                IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0);
                surface = new Win32Surface(windc);

                gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0);
            }
            else
            {
                x_drawable = drawable.Handle;
                IntPtr visual = gdk_drawable_get_visual(x_drawable);

                IntPtr Xdisplay  = gdk_x11_drawable_get_xdisplay(x_drawable);
                IntPtr Xvisual   = gdk_x11_visual_get_xvisual(visual);
                IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable);

                surface = new Cairo.XlibSurface(Xdisplay,
                                                Xdrawable,
                                                Xvisual,
                                                w, h);
            }

            Cairo.Context g = new Cairo.Context(surface);

            // this can be safely removed now, just keep it for a bit more
            //Cairo.Context g = new Cairo.Context (
            //                    gdk_cairo_create (x_drawable ));

            if (is_gdk_window)
            {
                g.Translate(-(double)x_off, -(double)y_off);
            }
            return(g);
        }
Пример #2
0
 public static Surface CreateSurface(Gdk.Drawable d)
 {
     int width, height;
     d.GetSize (out width, out height);
     XlibSurface surface = new XlibSurface (GdkUtils.GetXDisplay (d.Display),
                            (IntPtr)GdkUtils.GetXid (d),
                            GdkUtils.GetXVisual (d.Visual),
                            width, height);
     return surface;
 }
Пример #3
0
        public static Cairo.Context CreateContext(Gdk.Drawable drawable)
        {
            IntPtr x_drawable = IntPtr.Zero;
            int x_off = 0, y_off = 0;

            int x, y, w, h, d;
            ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);

            bool is_gdk_window = drawable is Gdk.Window;
            if (is_gdk_window)
                ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable,
                                         out x_off, out y_off);

            Cairo.Surface surface;

            PlatformID os = Environment.OSVersion.Platform;
            if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
                os == PlatformID.Win32S || os == PlatformID.WinCE)
            {

                Gdk.GC gcc = new Gdk.GC(drawable);
                IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0);
                surface = new Win32Surface(windc);

                gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0);
            }
            else
            {
                x_drawable = drawable.Handle;
                IntPtr visual = gdk_drawable_get_visual(x_drawable);

                IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable);
                IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual);
                IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable);

                surface = new Cairo.XlibSurface(Xdisplay,
                                   Xdrawable,
                                   Xvisual,
                                   w, h);
            }

            Cairo.Context g = new Cairo.Context(surface);

            // this can be safely removed now, just keep it for a bit more
            //Cairo.Context g = new Cairo.Context (
            //                    gdk_cairo_create (x_drawable ));

            if (is_gdk_window)
                g.Translate(-(double)x_off, -(double)y_off);
            return g;
        }
Пример #4
0
		public static void SetSourceDrawable (Context ctx, Gdk.Drawable d, double x, double y)
		{
			try {
				gdk_cairo_set_source_pixmap (ctx.Handle, d.Handle, x, y);
			} catch (EntryPointNotFoundException) {
				int width, height;
				d.GetSize (out width, out height);
				XlibSurface surface = new XlibSurface (GdkUtils.GetXDisplay (d.Display), 
								       (IntPtr)GdkUtils.GetXid (d),
								       GdkUtils.GetXVisual (d.Visual),
								       width, height);
				
				SurfacePattern p = new SurfacePattern (surface);
				Matrix m = new Matrix ();
				m.Translate (-x, -y);
				p.Matrix = m;
				ctx.Source = p;
			}
		}		
Пример #5
0
	static void Main (string [] args)
	{
		Window win = new Window (500, 500);
		
		win.Show ();
		
		Cairo.XlibSurface s = new Cairo.XlibSurface (win.Display,
			       win.XWindow,
			       X11.XDefaultVisual (win.Display, win.Screen),
			       (int)win.Width, (int)win.Height);

		
		Cairo.Context g = new Cairo.Context (s);
		
		draw (g, 500, 500);
		
		IntPtr xev = new IntPtr ();
		
		while (true) {			
			X11.XNextEvent (win.Display, xev);
		}		
	}
Пример #6
0
		public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered)
		{
			int x, y, w, h, d;
			Cairo.Surface surface;
			bool needs_xlate;
			
			((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);
			
			PlatformID os = Environment.OSVersion.Platform;

			needs_xlate = drawable is Gdk.Window && double_buffered;
			
			if (needs_xlate)
				((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y);

			if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
			    os == PlatformID.Win32S || os == PlatformID.WinCE) {

				Gdk.GC gcc = new Gdk.GC (drawable);
				IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0);
				surface = new Win32Surface (windc);
				
				if (double_buffered)
					gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0);
			} else {
				IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle);
				IntPtr visual = gdk_drawable_get_visual (drawable.Handle);
				IntPtr xvisual = gdk_x11_visual_get_xvisual (visual);
				IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle);
				surface = new XlibSurface (display, xdrawable, xvisual, w, h);
			}

			Cairo.Context ctx = new Cairo.Context (surface);

			if (needs_xlate)
				ctx.Translate (-(double) x, -(double) y);
			return ctx;
		}
Пример #7
0
    static void Main(string [] args)
    {
        Window win = new Window(500, 500);

        win.Show();

        Cairo.XlibSurface s = new Cairo.XlibSurface(win.Display,
                                                    win.XWindow,
                                                    X11.XDefaultVisual(win.Display, win.Screen),
                                                    (int)win.Width, (int)win.Height);


        Cairo.Context g = new Cairo.Context(s);

        draw(g, 500, 500);

        IntPtr xev = new IntPtr();

        while (true)
        {
            X11.XNextEvent(win.Display, xev);
        }
    }