示例#1
0
    static void HandleExposeEvent(object sender, ExposeEventArgs expose_args)
    {
        Widget w = (Widget)sender;

        using (Cairo.Context ctx = CompositeHelper.Create(w.GdkWindow)){
            double opacity = 0;
            ctx.Operator = Cairo.Operator.Source;
            if (moon_host.Content is Moon.Windows.Desktop.Window)
            {
                opacity = ((Moon.Windows.Desktop.Window)moon_host.Content).WindowOpacity;
            }
            ctx.Color = new Cairo.Color(1.0, 1.0, 1.0, opacity);
            CompositeHelper.Region(ctx, expose_args.Event.Region);
            ctx.Fill();
        }
    }
示例#2
0
    static int LoadXap(string file, List <string> args)
    {
        string [] test = { "" };

        if (sync)
        {
            test [0] = "--sync";
        }

        Application.Init("mopen", ref test);
        MoonlightRuntime.Init();
        window = new Gtk.Window(file);
        window.SetDefaultSize(400, 400);

        if (transparent)
        {
            CompositeHelper.SetRgbaColormap(window);
            window.AppPaintable = true;
            window.ExposeEvent += HandleExposeEvent;
        }

        if (desklet)
        {
            ConfigureDeskletWindow(window);
        }

        window.DeleteEvent += delegate {
            Application.Quit();
        };

        moon_host = new MoonlightHost();

        try {
            moon_host.LoadXap(file);
        } catch (Exception e) {
            Console.Error.WriteLine("mopen: Could not load xaml: {0}", e.Message);
            return(1);
        }

        System.Windows.Application app = moon_host.Application;
        FrameworkElement           top = (FrameworkElement)app.RootVisual;

        if (top is Moon.Windows.Desktop.Window)
        {
            var moonwindow = ((Moon.Windows.Desktop.Window)top);
            /* special window handling mode */
            moonwindow.IsActive = window.IsActive;

            Wnck.Screen.Default.ActiveWindowChanged += delegate {
                moonwindow.IsActive = window.IsActive;
            };

            moonwindow.PositionChanged += delegate {
                window.Move((int)moonwindow.Position.X, (int)moonwindow.Position.Y);
            };

            moonwindow.SizeChanged += delegate {
                window.Resize((int)moonwindow.Size.Width, (int)moonwindow.Size.Height);
            };

            moonwindow.WindowOpacityChanged += delegate {
                moon_host.QueueDraw();
            };

            if (!transparent)
            {
                CompositeHelper.SetRgbaColormap(window);
                window.AppPaintable = true;
                window.ExposeEvent += HandleExposeEvent;

                moon_host.AppPaintable = true;
                moon_host.Transparent  = true;
            }
        }

        if (parse_only)
        {
            return(0);
        }

        if (width == -1)
        {
            width = (int)top.Width;
        }
        if (height == -1)
        {
            height = (int)top.Height;
        }

        if (width > 0 && height > 0)
        {
            moon_host.SetSizeRequest(width, height);
            window.Resize(width, height);
        }

        if (transparent)
        {
            moon_host.AppPaintable = true;
            moon_host.Transparent  = true;
        }

        if (desklet)
        {
            top.MouseLeftButtonDown += new MouseButtonEventHandler(HandleMouseLeftButtonDown);
            top.MouseLeftButtonUp   += new MouseButtonEventHandler(HandleMouseLeftButtonUp);
            top.MouseMove           += new MouseEventHandler(HandleMouseMove);
        }

        window.Add(moon_host);

        window.ShowAll();

        if (story_names != null)
        {
            storyboards = new List <Storyboard> ();

            foreach (string story in story_names)
            {
                object     o  = top.FindName(story);
                Storyboard sb = o as Storyboard;

                if (sb == null)
                {
                    Console.Error.WriteLine("mopen: there is no Storyboard object named {0} in the XAML file", story);
                    return(1);
                }
                sb.Completed += delegate {
                    window.Title = String.Format("Storyboard {0} completed", current_storyboard - 1);
                };

                storyboards.Add(sb);
            }
            ;

            top.MouseLeftButtonUp += delegate {
                if (current_storyboard == storyboards.Count)
                {
                    current_storyboard = 0;
                }
                if (current_storyboard == storyboards.Count)
                {
                    return;
                }

                window.Title = String.Format("Storyboard {0} running", current_storyboard);
                storyboards [current_storyboard++].Begin();
            };
        }

        if (timeout > 0)
        {
            GLib.Timeout.Add((uint)(timeout * 1000), new TimeoutHandler(Quit));
        }

        Application.Run();
        return(0);
    }