Beispiel #1
0
        public override int StartDocument(DocumentParameter[] parameters)
        {
            if (parameters.Length > 0)
            {
                throw new Exception("Shell application does not allow any parameters.");
            }

            // We first check if render target parameters are set.
            if (rtParameters == null)
            {
                rtParameters = new RenderTargetParameters();
                rtParameters.BackBufferCount          = 2;
                rtParameters.BackBufferWidth          = 1024;
                rtParameters.BackBufferHeight         = 768;
                rtParameters.DepthStencilCommonFormat = CommonPixelFormatLayout.D24_UNORM_S8_UINT;
                rtParameters.FormatCommon             = CommonPixelFormatLayout.X8Y8Z8W8_UNORM;
                rtParameters.MultiSampleQuality       = 0;
                rtParameters.MultiSampleType          = 1;
                rtParameters.RefreshRate = 0;
                rtParameters.Windowed    = true;
            }


            // We create graphics device.
            Window         window  = null;
            GraphicsDevice device  = null;
            IWindowManager manager = null;

            try {
                // 1) We create graphics device in owned mode.
                device = graphicsService.CreateDevice(true, graphicsDebug, rtParameters, out window);

                // 2) We initialize input.
                inputService.Initialize(window);

                // 3) We create window manager.
                manager = new Default.DefaultWindowManager(device, device.SwapChain, inputService, defaultTheme);

                // 4) We replace component directory (add new stuff in shell enviorment).
                IComponentDirectory newDirectory = new ComponentDirectory(componentDirectory, "Shell");
                newDirectory.Register(new Instance(true, "ShellFinishedConfiguring"));
                newDirectory.Register(new Instance(manager));
                newDirectory.Register(new Instance(defaultTheme));

                // 5) We replace console by Shell provided console.
                newDirectory.Register(new AlwaysNewConfiguredComponent(
                                          typeof(ShellTextConsole).FullName));

                // 6) We set the component directory.



                // 7) We unregister component directory.
            } finally {
                if (manager != null && manager is IDisposable)
                {
                    (manager as IDisposable).Dispose();
                }
                if (inputService != null)
                {
                    inputService.Dispose();
                }
                if (device != null)
                {
                    device.Dispose();
                }
            }

            return(0);
        }
Beispiel #2
0
        public override int Start(string verb, string[] args)
        {
            // We initialize the service.
            if (service.DeviceExists)
            {
                throw new InvalidOperationException("Test application cannot be contructed, " +
                                                    "device already exists.");
            }

            if (renderTargetParameters == null)
            {
                // We use defaults.
                renderTargetParameters                          = new RenderTargetParameters();
                renderTargetParameters.Windowed                 = true;
                renderTargetParameters.FormatCommon             = CommonPixelFormatLayout.X8Y8Z8W8_UNORM;
                renderTargetParameters.DepthStencilCommonFormat = CommonPixelFormatLayout.D24_UNORM_S8_UINT;
                renderTargetParameters.BackBufferCount          = 1;
                renderTargetParameters.BackBufferWidth          = 800;
                renderTargetParameters.BackBufferHeight         = 600;
                renderTargetParameters.MultiSampleType          = 4;
                renderTargetParameters.MultiSampleQuality       = 3;
            }


            Window window;
            Font   font = new Font(SVGFontProvider.ImportSVG("dressel.svg"));

            using (GraphicsDevice device =
                       service.CreateDevice(true, false, renderTargetParameters, out window))
            {
                // We craete input device.
                using (input = new Input.InputService(new Input.Driver.DirectInput.DIInput()))
                {
                    /*
                     * DefaultTheme theme = new DefaultTheme(font);
                     * input.Initialize(window);
                     *
                     * bool isClosed = false;
                     * window.Closed += delegate(Window w) { isClosed = true; };
                     * IWindowManager manager = new DefaultWindowManager(device, device.SwapChain, input, theme);
                     *
                     * Container container = new Container();
                     *
                     * // We create a simple area.
                     * Area area = new Area();
                     * using (area.Enter())
                     * {
                     *  Area.AreaStyle s = new Area.AreaStyle();
                     *  area.PreferredRect = new GuiRect(RectangleMode.MinMax,
                     *      new GuiVector2(new Vector2f(0.2f, 0.2f)),
                     *      new GuiVector2(new Vector2f(0.8f, 0.8f)));
                     *  s.Background = new BackgroundStyle(new SolidFill(Colour.Red));
                     *  area.Style = Style.Create<Area.AreaStyle>(null,
                     *      new KeyValuePair<StyleState, Area.AreaStyle>(CommonStyleStates.Normal, s));
                     * }
                     *
                     * using (container.Enter())
                     * {
                     *  container.AddChild(area);
                     * }
                     *
                     *
                     * theme.AutomaticApply(container, true);
                     *
                     *
                     *
                     * RootWindow client = new RootWindow(device, manager, "Window Title", "SomeGroup",
                     *  WindowOptions.Close|WindowOptions.Maximimize|WindowOptions.Minimize, new Vector2i(100, 100), new Vector2i(300,300),
                     *  null, null, WindowState.Normal, container, 1, 0);
                     *
                     * client.GuiManager.PreRendering += delegate(GuiManager guiManager)
                     * {
                     *  guiManager.Canvas.Device.Clear(guiManager.Canvas.Target, Colour.Blue);
                     * };
                     *
                     * client.IsVisible = true;
                     *
                     * manager.PreRendering += delegate(IWindowManager y)
                     * {
                     *  device.Clear(device.SwapChain, Colour.Yellow);
                     * };
                     * manager.PostRendering += delegate(IWindowManager z)
                     * {
                     *  device.SwapChain.Present();
                     * };
                     *
                     * while (!isClosed)
                     * {
                     *  client.GuiManager.Invalidate();
                     *  client.GuiManager.Render();
                     *  (manager as IWindowManagerControl).Update();
                     *  window.DoEvents();
                     * }
                     * (manager as IWindowManagerControl).Dispose();
                     *
                     */


                    /*
                     * input.Initialize(window);
                     *
                     * // We default to font rendering 2.
                     * if (args.Length == 0)
                     * {
                     *
                     *  IGuiTheme theme = new DefaultTheme(font);
                     *  GuiTest test = new GuiTest();
                     *
                     *  using (GraphicsCanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1, 1)))
                     *  {
                     *      test.SimpleGUI(canvas, theme, input);
                     *
                     *  }
                     *
                     *
                     *  // We now run demos.
                     *
                     *  VectorTest test = new VectorTest();
                     *  test.FontRendering2(device);
                     * }
                     * /*
                     * else
                     * {
                     *
                     *  VectorTest test = new VectorTest();
                     *  foreach (string arg in args)
                     *  {
                     *      MethodInfo info = typeof(VectorTest).GetMethod(arg);
                     *      if (info != null)
                     *      {
                     *          try
                     *          {
                     *              info.Invoke(test, new object[] { device });
                     *          }
                     *          catch (Exception)
                     *          {
                     *              Console.WriteLine("Could not run or error method {0}.", arg);
                     *          }
                     *      }
                     *      else
                     *      {
                     *          Console.WriteLine("Could not run method {0}.", arg);
                     *      }
                     *  }
                     * }*/
                    //}
                }
            }
            return(0);
        }