public void Dispose()
            {
                View = null;

                m_DataWatcher?.Dispose();
                m_DataWatcher = null;
            }
Beispiel #2
0
        public InputManager(Noesis.View rootView)
        {
            m_RootView = rootView;

            // Let Monogame emulate touch when just using the mouse.
            // NOTE: Has some issues related to mouse capture, even in Monogame 3.6
            TouchPanel.EnableMouseTouchPoint = true;
        }
        public void Dispose()
        {
            View = null;

            m_ContentReloader?.Dispose();
            m_ContentReloader = null;

            m_Game.Window.TextInput         -= HandleWindowTextInput;
            m_Game.Window.ClientSizeChanged -= HandleWindowClientSizeChange;

            // TODO: How do we dispose just this Noesis UI view?
            Noesis.GUI.Shutdown();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            try
            {
                // Initialization
                GLUTWrapper.Init(800, 600, "NoesisGUI Integration Sample");

                Noesis.GUI.Init();
                Noesis.GUI.SetResourceProvider("Data");

                // Global theme
                {
                    var theme = (Noesis.ResourceDictionary)Noesis.GUI.LoadXaml("NoesisStyle.xaml");
                    Noesis.GUI.SetTheme(theme);
                }

                // Data loading
                {
                    var content = (Noesis.Grid)Noesis.GUI.LoadXaml("TextBox.xaml");
                    _view     = Noesis.GUI.CreateView(content);
                    _renderer = _view.Renderer;
                    _renderer.InitGL(new Noesis.VGOptions());
                }

                // Attach to Application events
                GLUTWrapper.Close      += OnClose;
                GLUTWrapper.Tick       += OnTick;
                GLUTWrapper.PreRender  += OnPreRender;
                GLUTWrapper.PostRender += OnPostRender;
                GLUTWrapper.Resize     += OnResize;
                GLUTWrapper.MouseMove  += OnMouseMove;
                GLUTWrapper.MouseDown  += OnMouseDown;
                GLUTWrapper.MouseUp    += OnMouseUp;
                GLUTWrapper.KeyDown    += OnKeyDown;
                GLUTWrapper.KeyUp      += OnKeyUp;
                _eventsAttached         = true;

                // Main Loop
                GLUTWrapper.Run();
            }
            catch (Exception e)
            {
                LogError(e.Message);

                OnClose();
            }
        }
Beispiel #5
0
        static void OnClose()
        {
            // Detach from Application events
            if (_eventsAttached)
            {
                _eventsAttached         = false;
                GLUTWrapper.Close      -= OnClose;
                GLUTWrapper.Tick       -= OnTick;
                GLUTWrapper.PreRender  -= OnPreRender;
                GLUTWrapper.PostRender -= OnPostRender;
                GLUTWrapper.Resize     -= OnResize;
                GLUTWrapper.MouseMove  -= OnMouseMove;
                GLUTWrapper.MouseDown  -= OnMouseDown;
                GLUTWrapper.MouseUp    -= OnMouseUp;
                GLUTWrapper.KeyDown    -= OnKeyDown;
                GLUTWrapper.KeyUp      -= OnKeyUp;
            }

            if (_renderer != null)
            {
                _renderer.Shutdown();
            }

            _view = null;

            try
            {
                Noesis.GUI.Shutdown();
            }
            catch (Exception e)
            {
                LogError(e.Message);
            }

            GLUTWrapper.Shutdown();
        }
Beispiel #6
0
        protected override void OnLoad(System.EventArgs e)
        {
            Noesis.GUI.Init();
            //EmbeddedXaml[] xamls = new EmbeddedXaml[]
            //{
            //        new EmbeddedXaml { filename = "Reflections.xaml", resource = "Reflections" }
            //};
            //Noesis.GUI.SetXamlProvider(new LocalXamlProvider("."));



            // Data loading
            Noesis.GUI.SetXamlProvider(new NoesisApp.LocalXamlProvider("."));
            //Noesis.Grid xaml = (Noesis.Grid)Noesis.GUI.LoadXaml("UI\\UItest0.xaml");
            xaml = new Noesis.Grid();
            Noesis.GUI.LoadComponent(xaml, "UI\\UItest03.xaml");
            //MyGrid xaml = new MyGrid();

            Noesis.StackPanel sp = (Noesis.StackPanel)xaml.FindName("BottomMenu");
            sp.DataContext = new ViewModel();



            Noesis.Button button = (Noesis.Button)xaml.FindName("button");

            button.Click += (object sender, Noesis.RoutedEventArgs args) =>
            {
                System.Console.WriteLine("Button was clicked");
            };


            // create view
            nView = Noesis.GUI.CreateView(xaml);

            nView.SetSize(this.Width, this.Height);
            // get OpenGL rendering device
            Noesis.RenderDevice device = new Noesis.RenderDeviceGL();

            // init renderer as OpenGL
            renderer = nView.Renderer;
            renderer.Init(device);


            nView.Update(0.001); // Ensures view is updated before first render call (avoids crash)


            CursorVisible = true;



            mousePos            = new Vector2(this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).X, this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).Y);
            Input.mousePosition = mousePos;
            //GL.Disable()
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);


            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);


            spritedrawer  = new SpriteDrawer(view);
            cursorTexture = SpriteDrawer.LoadTexture("PNG\\crosshair010.png", true, false);



            texture = SpriteDrawer.LoadTexture("PNG\\playerShip1_red.png", true, false);

            player  = new PlayerShip(0, 0, 0, texture, SpriteDrawer.LoadTexture("PNG\\Lasers\\laserBlue01.png", true, false), view);
            enemyAI = new AI(spaceObjects, player);
            Ship enemy1 = new Ship(200, 200, 0, SpriteDrawer.LoadTexture("PNG\\ufoBlue.png", true, false));

            player.setTarget(enemy1);


            enemyAI.takeControl(enemy1);
            spaceObjects.Add(enemy1);


            Closed += OnClosed;
        }
Beispiel #7
0
        private static void Main()
        {
            Noesis.Log.SetLogCallback((level, channel, message) =>
            {
                if (channel == "")
                {
                    // [TRACE] [DEBUG] [INFO] [WARNING] [ERROR]
                    string[] prefixes = new string[] { "T", "D", "I", "W", "E" };
                    string prefix     = (int)level < prefixes.Length ? prefixes[(int)level] : " ";
                    Console.WriteLine("[NOESIS/" + prefix + "] " + message);
                }
            });

            // Noesis initialization. This must be the first step before using any NoesisGUI functionality
            Noesis.GUI.Init("LICENSE_NAME", "LICENSE_KEY");

            // Setup theme
            NoesisApp.Application.SetThemeProviders();
            Noesis.GUI.LoadApplicationResources("Theme/NoesisTheme.DarkBlue.xaml");

            // For simplicity purposes we are not using resource providers in this sample. ParseXaml() is
            // enough if there is no extra XAML dependencies
            Noesis.Grid xaml = (Noesis.Grid)Noesis.GUI.ParseXaml(@"
                <Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                    <Grid.Background>
                        <LinearGradientBrush StartPoint=""0,0"" EndPoint=""0,1"">
                            <GradientStop Offset=""0"" Color=""#FF123F61""/>
                            <GradientStop Offset=""0.6"" Color=""#FF0E4B79""/>
                            <GradientStop Offset=""0.7"" Color=""#FF106097""/>
                        </LinearGradientBrush>
                    </Grid.Background>
                    <Viewbox>
                        <StackPanel Margin=""50"">
                            <Button Content=""Hello World!"" Margin=""0,30,0,0""/>
                            <Rectangle Height=""5"" Margin=""-10,20,-10,0"">
                                <Rectangle.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Offset=""0"" Color=""#40000000""/>
                                        <GradientStop Offset=""1"" Color=""#00000000""/>
                                    </RadialGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                        </StackPanel>
                    </Viewbox>
                </Grid>");

            // View creation to render and interact with the user interface
            // We transfer the ownership to a global pointer instead of a Ptr<> because there is no way
            // in GLUT to do shutdown and we don't want the Ptr<> to be released at global time
            Noesis.View view = Noesis.GUI.CreateView(xaml);
            view.SetFlags(Noesis.RenderFlags.PPAA | Noesis.RenderFlags.LCD);

            // Creation of the system window
            RenderForm form = new RenderForm("NoesisGUI - IntegrationSharpDX D3D11")
            {
                Width  = 1000,
                Height = 600,
                Icon   = new System.Drawing.Icon("Noesis.ico")
            };

            view.SetSize(form.ClientSize.Width, form.ClientSize.Height);

            // SwapChain description
            SwapChainDescription desc = new SwapChainDescription()
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                      new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            Device    device;
            SwapChain swapChain;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
            DeviceContext context = device.ImmediateContext;

            Factory factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
            factory.Dispose();

            // Renderer initialization with a Direct3D11 device
            view.Renderer.Init(new Noesis.RenderDeviceD3D11(context.NativePointer));

            // New RenderTargetView from the backbuffer
            Texture2D        backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            RenderTargetView renderView = new RenderTargetView(device, backBuffer);

            backBuffer.Dispose();

            // Register window events
            form.SizeChanged += (s, e) =>
            {
                context.OutputMerger.SetRenderTargets(null, (RenderTargetView)null);
                renderView.Dispose();

                swapChain.ResizeBuffers(0, 0, 0, Format.Unknown, SwapChainFlags.None);

                backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
                renderView = new RenderTargetView(device, backBuffer);
                backBuffer.Dispose();

                view.SetSize(form.ClientSize.Width, form.ClientSize.Height);
            };
            form.MouseMove += (s, e) => { view.MouseMove(e.X, e.Y); };
            form.MouseDown += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    view.MouseButtonDown(e.X, e.Y, Noesis.MouseButton.Left);
                }
            };
            form.MouseUp += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    view.MouseButtonUp(e.X, e.Y, Noesis.MouseButton.Left);
                }
            };

            // Main loop
            DateTime start = DateTime.Now;

            RenderLoop.Run(form, () =>
            {
                // Update view (layout, animations, ...)
                view.Update((DateTime.Now - start).TotalSeconds);

                // Offscreen rendering phase populates textures needed by the on-screen rendering
                view.Renderer.UpdateRenderTree();
                view.Renderer.RenderOffscreen();

                // If you are going to render here with your own engine you need to restore the GPU state
                // because noesis changes it. In this case only framebuffer and viewport need to be restored
                context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
                context.OutputMerger.SetTargets(renderView);
                context.ClearRenderTargetView(renderView, Color.Black);

                // Rendering is done in the active framebuffer
                view.Renderer.Render();

                // Present and swap buffers
                swapChain.Present(0, PresentFlags.None);
            });

            // Release all resources
            renderView.Dispose();
            context.ClearState();
            context.Flush();
            device.Dispose();
            context.Dispose();
            swapChain.Dispose();
        }