LoadXap() public method

Initializes the Surface widget from a XAP file
This uses the XAP loader to load the given XAP display it on the Surface widget.
public LoadXap ( string xapPath ) : void
xapPath string Path to the XAP file
return void
Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Application.Init ();
            //MainWindow win = new MainWindow ();
            //win.Show ();
            MoonlightRuntime.Init ();
            Window w = new Window ("mldsp");
            w.DefaultHeight = 520;
            w.DefaultWidth = 760;
            w.DeleteEvent += delegate { Application.Quit (); };

            var moon = new MoonlightHost ();
            var xappath = System.IO.Path.Combine (System.IO.Path.GetDirectoryName (new Uri (typeof (MainClass).Assembly.CodeBase).LocalPath), "mldsp.clr.xap");
            moon.LoadXap (xappath);
            if (args.Length > 0) {
                int device;
                if (int.TryParse (args [0], out device))
                    ((mldsp.App) moon.Application).OutputDeviceID = device;
                else {
                    Console.WriteLine ("WARNING: wrong device ID speficication. Specify an index.");
                    foreach (var dev in PortMidiSharp.MidiDeviceManager.AllDevices)
                        if (dev.IsOutput)
                            Console.WriteLine ("{0} {1}", dev.ID, dev.Name);
                }
            }

            var vbox = new VBox (false, 0);
            w.Add (vbox);
            var mainmenu = new MenuBar ();
            vbox.PackStart (mainmenu, false, true, 0);
            var optmi = new MenuItem ("_Options");
            mainmenu.Add (optmi);
            var devmi = new MenuItem ("Select Device");
            var optmenu = new Menu ();
            optmi.Submenu = optmenu;
            optmenu.Append (devmi);
            var devlist = new SList (IntPtr.Zero);
            var devmenu = new Menu ();
            devmi.Submenu = devmenu;
            foreach (var dev in PortMidiSharp.MidiDeviceManager.AllDevices) {
                if (dev.IsOutput) {
                    var mi = new RadioMenuItem (devlist, dev.Name);
                    mi.Data ["Device"] = dev.ID;
                    devlist = mi.Group;
                    int id = dev.ID;
                    mi.Activated += delegate {
                        ((mldsp.App) moon.Application).ResetDevice ((int) mi.Data ["Device"]);
                    };
                    devmenu.Append (mi);
                }
            }

            vbox.PackEnd (moon);

            w.ShowAll ();
            Application.Run ();
        }
Ejemplo n.º 2
0
Archivo: mopen.cs Proyecto: dfr0/moon
	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;
	}