コード例 #1
0
        private static void _SetupEffect(ImGuiXNAState self, Effect _effect)
        {
            ImGuiIO io = ImGui.IO;

#if FNA
            const float translate = 0f;
#else
            const float translate = 0.5f;
#endif

            if (_effect is BasicEffect)
            {
                BasicEffect effect = (BasicEffect)_effect;
                effect.World              = Matrix.Identity;
                effect.View               = Matrix.Identity;
                effect.Projection         = Matrix.CreateOrthographicOffCenter(translate, io.DisplaySize.x + translate, io.DisplaySize.y + translate, translate, -1f, 1f);
                effect.TextureEnabled     = true;
                effect.VertexColorEnabled = true;
                return;
            }

            if (_effect is AlphaTestEffect)
            {
                AlphaTestEffect effect = (AlphaTestEffect)_effect;
                effect.World              = Matrix.Identity;
                effect.View               = Matrix.Identity;
                effect.Projection         = Matrix.CreateOrthographicOffCenter(translate, io.DisplaySize.x + translate, io.DisplaySize.y + translate, translate, -1f, 1f);
                effect.VertexColorEnabled = true;
                return;
            }

            throw new Exception("Default ImGuiXNAState.SetupEffect can't deal with " + _effect.GetType().FullName + ", please provide your own delegate.");
        }
コード例 #2
0
        public static void NewFrame(ImVec2 size, ImVec2 scale, ImVec2 mousePosition, uint mouseMask, ref float mouseWheel, bool[] mousePressed, ref double g_Time)
        {
            ImGuiIO io = ImGui.GetIO();

            io.DisplaySize             = size;
            io.DisplayFramebufferScale = scale;

            double currentTime = SDL.SDL_GetTicks() / 1000D;

            io.DeltaTime = g_Time > 0D ? (float)(currentTime - g_Time) : (1f / 60f);
            g_Time       = currentTime;

            io.MousePosition = mousePosition;

            io.MouseDown[0] = mousePressed[0] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_LEFT)) != 0;
            io.MouseDown[1] = mousePressed[1] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_RIGHT)) != 0;
            io.MouseDown[2] = mousePressed[2] || (mouseMask & SDL.SDL_BUTTON(SDL.SDL_BUTTON_MIDDLE)) != 0;
            mousePressed[0] = mousePressed[1] = mousePressed[2] = false;

            io.MouseWheel = mouseWheel;
            mouseWheel    = 0f;

            SDL.SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);

            ImGui.NewFrame();
        }
コード例 #3
0
ファイル: ImGuiSDL2CSWindow.cs プロジェクト: GreyKit/ImGuiCS
        protected virtual void Create()
        {
            ImGuiIO io = ImGui.GetIO();

            // Build texture atlas
            ImFontTextureData texData = io.FontAtlas.GetTexDataAsAlpha8();

            int lastTexture;

            GL.GetIntegerv(GL.Enum.GL_TEXTURE_BINDING_2D, out lastTexture);

            // Create OpenGL texture
            GL.GenTextures(1, out g_FontTexture);
            GL.BindTexture(GL.Enum.GL_TEXTURE_2D, g_FontTexture);
            GL.TexParameteri(GL.Enum.GL_TEXTURE_2D, GL.Enum.GL_TEXTURE_MIN_FILTER, (int)GL.Enum.GL_LINEAR);
            GL.TexParameteri(GL.Enum.GL_TEXTURE_2D, GL.Enum.GL_TEXTURE_MAG_FILTER, (int)GL.Enum.GL_LINEAR);
            GL.PixelStorei(GL.Enum.GL_UNPACK_ROW_LENGTH, 0);
            GL.TexImage2D(
                GL.Enum.GL_TEXTURE_2D,
                0,
                (int)GL.Enum.GL_ALPHA,
                texData.Width,
                texData.Height,
                0,
                GL.Enum.GL_ALPHA,
                GL.Enum.GL_UNSIGNED_BYTE,
                texData.Pixels
                );

            // Store the texture identifier in the ImFontAtlas substructure.
            io.FontAtlas.SetTexID(g_FontTexture);
            io.FontAtlas.ClearTexData(); // Clears CPU side texture data.
            GL.BindTexture(GL.Enum.GL_TEXTURE_2D, lastTexture);
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: rje/ImGuiSharp
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            SetupBasicShader();

            // Application init
            io = ImGui.Instance.GetIO();
            io.DisplaySize.x = GraphicsDevice.Viewport.Width;
            io.DisplaySize.y = GraphicsDevice.Viewport.Height;
            io.IniFilename   = "imgui.ini";

            SetupFontTextures();
            SetupBuffers();

            //not sure if we really need pointclamp since we add a 1px padding around each glyph
            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            GraphicsDevice.BlendState       = BlendState.NonPremultiplied;
            GraphicsDevice.RasterizerState  = new RasterizerState()
            {
                CullMode = CullMode.None, ScissorTestEnable = true
            };

            SetupKeyMappings();

            base.Initialize();
        }
コード例 #5
0
        public static bool HandleEvent(SDL.SDL_Event e, ref float mouseWheel, bool[] mousePressed)
        {
            ImGuiIO io = ImGui.GetIO();

            switch (e.type)
            {
            case SDL.SDL_EventType.SDL_MOUSEWHEEL:
                if (e.wheel.y > 0)
                {
                    mouseWheel = 1;
                }
                if (e.wheel.y < 0)
                {
                    mouseWheel = -1;
                }
                return(true);

            case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                if (mousePressed == null)
                {
                    return(true);
                }
                if (e.button.button == SDL.SDL_BUTTON_LEFT && mousePressed.Length > 0)
                {
                    mousePressed[0] = true;
                }
                if (e.button.button == SDL.SDL_BUTTON_RIGHT && mousePressed.Length > 1)
                {
                    mousePressed[1] = true;
                }
                if (e.button.button == SDL.SDL_BUTTON_MIDDLE && mousePressed.Length > 2)
                {
                    mousePressed[2] = true;
                }
                return(true);

            case SDL.SDL_EventType.SDL_TEXTINPUT:
                unsafe
                {
                    // THIS IS THE ONLY UNSAFE THING LEFT!
                    ImGui.AddInputCharactersUTF8(e.text.text);
                }
                return(true);

            case SDL.SDL_EventType.SDL_KEYDOWN:
            case SDL.SDL_EventType.SDL_KEYUP:
                int key = (int)e.key.keysym.sym & ~SDL.SDLK_SCANCODE_MASK;
                io.KeysDown[key] = e.type == SDL.SDL_EventType.SDL_KEYDOWN;
                SDL.SDL_Keymod keyModState = SDL.SDL_GetModState();
                io.ShiftPressed = (keyModState & SDL.SDL_Keymod.KMOD_SHIFT) != 0;
                io.CtrlPressed  = (keyModState & SDL.SDL_Keymod.KMOD_CTRL) != 0;
                io.AltPressed   = (keyModState & SDL.SDL_Keymod.KMOD_ALT) != 0;
                io.SuperPressed = (keyModState & SDL.SDL_Keymod.KMOD_GUI) != 0;
                return(true);
            }

            return(true);
        }
コード例 #6
0
        public void BuildTextureAtlas()
        {
            ImGuiIO io = ImGui.IO;
            // ImFontTextureData texData = io.FontAtlas.GetTexDataAsAlpha8();
            // Alpha8 has got some blending issues.
            ImFontTextureData texData = io.FontAtlas.GetTexDataAsRGBA32();

            Texture2D tex = new Texture2D(Game.GraphicsDevice, texData.Width, texData.Height, false, SurfaceFormat.Color);

            int[] data = new int[texData.Width * texData.Height];
            Marshal.Copy(texData.Pixels, data, 0, data.Length);
            tex.SetData(data);

            FontTexture = Register(tex);

            io.FontAtlas.SetTexID(FontTexture);
            io.FontAtlas.ClearTexData(); // Clears CPU side texture data.
        }
コード例 #7
0
        public static void Init()
        {
            if (_Initialized)
            {
                return;
            }
            _Initialized = true;

            ImGuiIO io = ImGui.GetIO();

            _Keys.Add(io.KeyMap[ImGuiKey.Tab]        = (int)Keys.Tab);
            _Keys.Add(io.KeyMap[ImGuiKey.LeftArrow]  = (int)Keys.Left);
            _Keys.Add(io.KeyMap[ImGuiKey.RightArrow] = (int)Keys.Right);
            _Keys.Add(io.KeyMap[ImGuiKey.UpArrow]    = (int)Keys.Up);
            _Keys.Add(io.KeyMap[ImGuiKey.DownArrow]  = (int)Keys.Down);
            _Keys.Add(io.KeyMap[ImGuiKey.PageUp]     = (int)Keys.PageUp);
            _Keys.Add(io.KeyMap[ImGuiKey.PageDown]   = (int)Keys.PageDown);
            _Keys.Add(io.KeyMap[ImGuiKey.Home]       = (int)Keys.Home);
            _Keys.Add(io.KeyMap[ImGuiKey.End]        = (int)Keys.End);
            _Keys.Add(io.KeyMap[ImGuiKey.Delete]     = (int)Keys.Delete);
            _Keys.Add(io.KeyMap[ImGuiKey.Backspace]  = (int)Keys.Back);
            _Keys.Add(io.KeyMap[ImGuiKey.Enter]      = (int)Keys.Enter);
            _Keys.Add(io.KeyMap[ImGuiKey.Escape]     = (int)Keys.Escape);
            _Keys.Add(io.KeyMap[ImGuiKey.A]          = (int)Keys.A);
            _Keys.Add(io.KeyMap[ImGuiKey.C]          = (int)Keys.C);
            _Keys.Add(io.KeyMap[ImGuiKey.V]          = (int)Keys.V);
            _Keys.Add(io.KeyMap[ImGuiKey.X]          = (int)Keys.X);
            _Keys.Add(io.KeyMap[ImGuiKey.Y]          = (int)Keys.Y);
            _Keys.Add(io.KeyMap[ImGuiKey.Z]          = (int)Keys.Z);

#if FNA
            TextInputEXT.TextInput += OnTextInput;
            io.SetGetClipboardTextFn(GetClipboardTextFn);
            io.SetSetClipboardTextFn(SetClipboardTextFn);
#endif
            // 1. Text input in XNA depends on the game's window. It thus can't be set up statically.
            // 2. ImGui already handles the Windows clipboard out of the box.

            // If no font added, add default font.
            if (io.FontAtlas.Fonts.Size == 0)
            {
                io.FontAtlas.AddDefaultFont();
            }
        }
コード例 #8
0
        private static void _SetEffectTexture(ImGuiXNAState self, Effect _effect, Texture2D texture)
        {
            ImGuiIO io = ImGui.IO;

            if (_effect is BasicEffect)
            {
                BasicEffect effect = (BasicEffect)_effect;
                effect.Texture = texture;
                return;
            }

            if (_effect is AlphaTestEffect)
            {
                AlphaTestEffect effect = (AlphaTestEffect)_effect;
                effect.Texture = texture;
                return;
            }

            throw new Exception("Default ImGuiXNAState.SetEffectTexture can't deal with " + _effect.GetType().FullName + ", please provide your own delegate.");
        }
コード例 #9
0
        public void NewFrame(GameTime gameTime)
        {
            ImGuiIO io = ImGui.GetIO();

            MouseState    mouse    = Mouse.GetState();
            KeyboardState keyboard = Keyboard.GetState();

            for (int i = 0; i < _Keys.Count; i++)
            {
                io.KeysDown[_Keys[i]] = keyboard.IsKeyDown((Keys)_Keys[i]);
            }

            io.ShiftPressed = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);
            io.CtrlPressed  = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl);
            io.AltPressed   = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt);
            io.SuperPressed = keyboard.IsKeyDown(Keys.LeftWindows) || keyboard.IsKeyDown(Keys.RightWindows);

            io.DisplaySize             = new ImVec2(Game.GraphicsDevice.PresentationParameters.BackBufferWidth, Game.GraphicsDevice.PresentationParameters.BackBufferHeight);
            io.DisplayFramebufferScale = new ImVec2(1f, 1f);

            double currentTime = gameTime.TotalGameTime.TotalSeconds;

            io.DeltaTime = _Time > 0D ? (float)(currentTime - _Time) : (1f / 60f);
            _Time        = currentTime;

            io.MousePosition = new ImVec2(mouse.X, mouse.Y);

            io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed;
            io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed;
            io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed;

            int scrollDelta = mouse.ScrollWheelValue - _ScrollWheelValue;

            io.MouseWheel     = scrollDelta > 0 ? 1 : scrollDelta < 0 ? -1 : 0;
            _ScrollWheelValue = mouse.ScrollWheelValue;

            Game.IsMouseVisible = !io.MouseDrawCursor;

            ImGui.NewFrame();
        }
コード例 #10
0
        public static void Init()
        {
            if (_Initialized)
            {
                return;
            }
            _Initialized = true;

            ImGuiIO io = ImGui.GetIO();

            io.KeyMap[ImGuiKey.Tab]        = (int)SDL.SDL_Keycode.SDLK_TAB;
            io.KeyMap[ImGuiKey.LeftArrow]  = (int)SDL.SDL_Scancode.SDL_SCANCODE_LEFT;
            io.KeyMap[ImGuiKey.RightArrow] = (int)SDL.SDL_Scancode.SDL_SCANCODE_RIGHT;
            io.KeyMap[ImGuiKey.UpArrow]    = (int)SDL.SDL_Scancode.SDL_SCANCODE_UP;
            io.KeyMap[ImGuiKey.DownArrow]  = (int)SDL.SDL_Scancode.SDL_SCANCODE_DOWN;
            io.KeyMap[ImGuiKey.PageUp]     = (int)SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP;
            io.KeyMap[ImGuiKey.PageDown]   = (int)SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN;
            io.KeyMap[ImGuiKey.Home]       = (int)SDL.SDL_Scancode.SDL_SCANCODE_HOME;
            io.KeyMap[ImGuiKey.End]        = (int)SDL.SDL_Scancode.SDL_SCANCODE_END;
            io.KeyMap[ImGuiKey.Delete]     = (int)SDL.SDL_Keycode.SDLK_DELETE;
            io.KeyMap[ImGuiKey.Backspace]  = (int)SDL.SDL_Keycode.SDLK_BACKSPACE;
            io.KeyMap[ImGuiKey.Enter]      = (int)SDL.SDL_Keycode.SDLK_RETURN;
            io.KeyMap[ImGuiKey.Escape]     = (int)SDL.SDL_Keycode.SDLK_ESCAPE;
            io.KeyMap[ImGuiKey.A]          = (int)SDL.SDL_Keycode.SDLK_a;
            io.KeyMap[ImGuiKey.C]          = (int)SDL.SDL_Keycode.SDLK_c;
            io.KeyMap[ImGuiKey.V]          = (int)SDL.SDL_Keycode.SDLK_v;
            io.KeyMap[ImGuiKey.X]          = (int)SDL.SDL_Keycode.SDLK_x;
            io.KeyMap[ImGuiKey.Y]          = (int)SDL.SDL_Keycode.SDLK_y;
            io.KeyMap[ImGuiKey.Z]          = (int)SDL.SDL_Keycode.SDLK_z;

            io.SetGetClipboardTextFn((userData) => SDL.SDL_GetClipboardText());
            io.SetSetClipboardTextFn((userData, text) => SDL.SDL_SetClipboardText(text));

            // If no font added, add default font.
            if (io.FontAtlas.Fonts.Size == 0)
            {
                io.FontAtlas.AddDefaultFont();
            }
        }
コード例 #11
0
ファイル: ImGuiSDL2CSWindow.cs プロジェクト: GreyKit/ImGuiCS
        protected override void Dispose(bool disposing)
        {
            ImGuiIO io = ImGui.GetIO();

            if (disposing)
            {
                // Dispose managed state (managed objects).
            }

            // Free unmanaged resources (unmanaged objects) and override a finalizer below.
            // Set large fields to null.
            if (g_FontTexture != 0)
            {
                // Texture gets deleted with the context.
                // GL.DeleteTexture(g_FontTexture);
                if ((int)io.FontAtlas.TexID == g_FontTexture)
                {
                    io.FontAtlas.TexID = IntPtr.Zero;
                }
                g_FontTexture = 0;
            }

            base.Dispose(disposing);
        }
コード例 #12
0
        public static void RenderDrawData(ImDrawData drawData, int displayW, int displayH)
        {
            // We are using the OpenGL fixed pipeline to make the example code simpler to read!
            // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
            int  lastTexture; GL.GetIntegerv(GL.Enum.GL_TEXTURE_BINDING_2D, out lastTexture);
            Int4 lastViewport; GL.GetIntegerv4(GL.Enum.GL_VIEWPORT, out lastViewport);
            Int4 lastScissorBox; GL.GetIntegerv4(GL.Enum.GL_SCISSOR_BOX, out lastScissorBox);

            GL.PushAttrib(GL.Enum.GL_ENABLE_BIT | GL.Enum.GL_COLOR_BUFFER_BIT | GL.Enum.GL_TRANSFORM_BIT);
            GL.Enable(GL.Enum.GL_BLEND);
            GL.BlendFunc(GL.Enum.GL_SRC_ALPHA, GL.Enum.GL_ONE_MINUS_SRC_ALPHA);
            GL.Disable(GL.Enum.GL_CULL_FACE);
            GL.Disable(GL.Enum.GL_DEPTH_TEST);
            GL.Enable(GL.Enum.GL_SCISSOR_TEST);
            GL.EnableClientState(GL.Enum.GL_VERTEX_ARRAY);
            GL.EnableClientState(GL.Enum.GL_TEXTURE_COORD_ARRAY);
            GL.EnableClientState(GL.Enum.GL_COLOR_ARRAY);
            GL.Enable(GL.Enum.GL_TEXTURE_2D);

            GL.UseProgram(0);

            // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
            ImGuiIO io = ImGui.GetIO();

            ImGui.ScaleClipRects(drawData, io.DisplayFramebufferScale);

            // Setup orthographic projection matrix
            GL.Viewport(0, 0, displayW, displayH);
            GL.MatrixMode(GL.Enum.GL_PROJECTION);
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.Ortho(
                0.0f,
                io.DisplaySize.X / io.DisplayFramebufferScale.X,
                io.DisplaySize.Y / io.DisplayFramebufferScale.Y,
                0.0f,
                -1.0f,
                1.0f
                );
            GL.MatrixMode(GL.Enum.GL_MODELVIEW);
            GL.PushMatrix();
            GL.LoadIdentity();

            // Render command lists

            for (int n = 0; n < drawData.CmdListsCount; n++)
            {
                ImDrawList            cmdList   = drawData[n];
                ImVector <ImDrawVert> vtxBuffer = cmdList.VtxBuffer;
                ImVector <ushort>     idxBuffer = cmdList.IdxBuffer;

                GL.VertexPointer(2, GL.Enum.GL_FLOAT, ImDrawVert.Size, new IntPtr((long)vtxBuffer.Data + ImDrawVert.PosOffset));
                GL.TexCoordPointer(2, GL.Enum.GL_FLOAT, ImDrawVert.Size, new IntPtr((long)vtxBuffer.Data + ImDrawVert.UVOffset));
                GL.ColorPointer(4, GL.Enum.GL_UNSIGNED_BYTE, ImDrawVert.Size, new IntPtr((long)vtxBuffer.Data + ImDrawVert.ColOffset));

                long idxBufferOffset = 0;
                for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++)
                {
                    ImDrawCmd pcmd = cmdList.CmdBuffer[cmdi];
                    if (pcmd.UserCallback != IntPtr.Zero)
                    {
                        pcmd.InvokeUserCallback(ref cmdList, ref pcmd);
                    }
                    else
                    {
                        GL.BindTexture(GL.Enum.GL_TEXTURE_2D, (int)pcmd.TextureId);
                        GL.Scissor(
                            (int)pcmd.ClipRect.X,
                            (int)(io.DisplaySize.Y - pcmd.ClipRect.W),
                            (int)(pcmd.ClipRect.Z - pcmd.ClipRect.X),
                            (int)(pcmd.ClipRect.W - pcmd.ClipRect.Y)
                            );
                        GL.DrawElements(GL.Enum.GL_TRIANGLES, (int)pcmd.ElemCount, GL.Enum.GL_UNSIGNED_SHORT, new IntPtr((long)idxBuffer.Data + idxBufferOffset));
                    }
                    idxBufferOffset += pcmd.ElemCount * 2 /*sizeof(ushort)*/;
                }
            }

            // Restore modified state
            GL.DisableClientState(GL.Enum.GL_COLOR_ARRAY);
            GL.DisableClientState(GL.Enum.GL_TEXTURE_COORD_ARRAY);
            GL.DisableClientState(GL.Enum.GL_VERTEX_ARRAY);
            GL.BindTexture(GL.Enum.GL_TEXTURE_2D, lastTexture);
            GL.MatrixMode(GL.Enum.GL_MODELVIEW);
            GL.PopMatrix();
            GL.MatrixMode(GL.Enum.GL_PROJECTION);
            GL.PopMatrix();
            GL.PopAttrib();
            GL.Viewport(lastViewport.X, lastViewport.Y, lastViewport.Z, lastViewport.W);
            GL.Scissor(lastScissorBox.X, lastScissorBox.Y, lastScissorBox.Z, lastScissorBox.W);
        }
コード例 #13
0
        public void RenderDrawData(ImDrawData drawData)
        {
            GraphicsDevice device = Game.GraphicsDevice;

            // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
            Viewport  lastViewport   = device.Viewport;
            Rectangle lastScissorBox = device.ScissorRectangle;

            device.BlendFactor       = Color.White;
            device.BlendState        = BlendState.NonPremultiplied;
            device.RasterizerState   = RasterizerState;
            device.DepthStencilState = DepthStencilState.DepthRead;

            // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
            ImGuiIO io = ImGui.GetIO();

            ImGui.ScaleClipRects(drawData, io.DisplayFramebufferScale);

            // Setup projection
            device.Viewport = new Viewport(0, 0, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight);

            if (Effect == null)
            {
                Effect = new BasicEffect(device);
            }
            Effect effect = Effect;

            SetupEffect(this, effect);

            // Render command lists
            for (int n = 0; n < drawData.CmdListsCount; n++)
            {
                ImDrawList cmdList = drawData[n];

                ImVector <ImDrawVertXNA> vtxBuffer;
                unsafe
                {
                    vtxBuffer = new ImVector <ImDrawVertXNA>(cmdList.VtxBuffer.Native);
                }
                ImDrawVertXNA[] vtxArray = new ImDrawVertXNA[vtxBuffer.Size];
                for (int i = 0; i < vtxBuffer.Size; i++)
                {
                    vtxArray[i] = vtxBuffer[i];
                }

                ImVector <short> idxBuffer;
                unsafe
                {
                    idxBuffer = new ImVector <short>(cmdList.IdxBuffer.Native);
                }

                /*
                 * short[] idxArray = new short[idxBuffer.Size];
                 * for (int i = 0; i < idxBuffer.Size; i++)
                 *  idxArray[i] = idxBuffer[i];
                 */

                uint offset = 0;
                for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++)
                {
                    ImDrawCmd pcmd = cmdList.CmdBuffer[cmdi];
                    if (pcmd.UserCallback != IntPtr.Zero)
                    {
                        pcmd.InvokeUserCallback(ref cmdList, ref pcmd);
                    }
                    else
                    {
                        // Instead of uploading the complete idxBuffer again and again, just upload what's required.
                        short[] idxArray = new short[pcmd.ElemCount];
                        for (int i = 0; i < pcmd.ElemCount; i++)
                        {
                            idxArray[i] = idxBuffer[(int)offset + i];
                        }
                        SetEffectTexture(this, effect, GetTexture((int)pcmd.TextureId));
                        device.ScissorRectangle = new Rectangle(
                            (int)pcmd.ClipRect.X,
                            (int)pcmd.ClipRect.Y,
                            (int)(pcmd.ClipRect.Z - pcmd.ClipRect.X),
                            (int)(pcmd.ClipRect.W - pcmd.ClipRect.Y)
                            );
                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawUserIndexedPrimitives(
                                PrimitiveType.TriangleList,
                                vtxArray, 0, vtxBuffer.Size,
                                idxArray, 0, (int)pcmd.ElemCount / 3,
                                ImDrawVertXNA._VertexDeclaration
                                );
                        }
                    }
                    offset += pcmd.ElemCount;
                }
            }

            // Restore modified state
            device.Viewport         = lastViewport;
            device.ScissorRectangle = lastScissorBox;
        }
コード例 #14
0
ファイル: Game1.cs プロジェクト: rje/ImGuiSharp
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();
            //int w = 1920, h = 1080;
            int w = GraphicsDevice.Viewport.Width, h = GraphicsDevice.Viewport.Height;
            int display_w = GraphicsDevice.Viewport.Width, display_h = GraphicsDevice.Viewport.Height;
            //int display_w = GraphicsDevice.PresentationParameters.BackBufferWidth, display_h = GraphicsDevice.PresentationParameters.BackBufferHeight;

            var keyboard = Keyboard.GetState();
            var mouse    = Mouse.GetState();

            io             = ImGui.Instance.GetIO();
            io.DisplaySize = new ImVec2(w, h);
            //io.DisplayFramebufferScale = new ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
            //// 1) get low-level inputs (e.g. on Win32, GetKeyboardState(), or poll your events, etc.)
            //// TODO: fill all fields of IO structure and call NewFrame
            io.DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (IsActive)
            {
                io.MousePos        = new ImVec2(mouse.X, mouse.Y);
                io.MouseDrawCursor = true;
            }
            else
            {
                io.MousePos        = new ImVec2(-1, -1);
                io.MouseDrawCursor = false;
            }

            io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed;
            io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed;
            io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed;
            io.MouseWheel   = mouse.ScrollWheelValue > scrollWheel ? 1 : mouse.ScrollWheelValue < scrollWheel ? -1 : 0;
            scrollWheel     = mouse.ScrollWheelValue;

            io.KeyCtrl  = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl);
            io.KeyAlt   = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt);
            io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);

            var capslock = ((((ushort)GetKeyState(0x14)) & 0xffff) != 0);

            var keys = keyboard.GetPressedKeys();

            for (var i = 0; i < io.KeysDown.Length; i++)
            {
                io.KeysDown[i] = false;
            }


            foreach (var key in keys)
            {
                var ch = ConvertKeyboardInput(key, io.KeyAlt, io.KeyShift, io.KeyCtrl, capslock);
                if (!io.KeyAlt && !io.KeyCtrl && (int)key < 0x80 && ch != 0)
                {
                    io.KeysDown[ch] = true;
                    io.AddInputCharacter(ch);
                }
                else
                {
                    io.KeysDown[(int)key + 0xff] = true;
                }
            }

            ImGui.Instance.NewFrame();

            bool crap = true;

            ImGui.Instance.ShowTestWindow(ref crap);

            base.Update(gameTime);
        }