示例#1
0
        void DoViewport()
        {
            var szX = (int)ImGui.GetWindowContentRegionWidth();
            var szY = (int)ImGui.GetWindowHeight();

            if (rtX != szX || rtY != szY)
            {
                rtX = szX;
                rtY = szY;
                if (renderTarget != null)
                {
                    ImGuiHelper.DeregisterTexture(renderTarget.Texture);
                    renderTarget.Dispose();
                }
                renderTarget      = new RenderTarget2D(rtX, rtY);
                renderTargetImage = ImGuiHelper.RegisterTexture(renderTarget.Texture);
            }

            mainWindow.RenderState.RenderTarget = renderTarget;
            mainWindow.Viewport.Push(0, 0, rtX, rtY);
            mainWindow.RenderState.ClearColor = Color4.Black;
            mainWindow.RenderState.ClearAll();
            //Do drawing
            if (widget != null)
            {
                context.GlobalTime     = TimeSpan.FromSeconds(mainWindow.TotalTime);
                context.ViewportWidth  = rtX;
                context.ViewportHeight = rtY;
                context.RenderWidget();
            }
            //
            mainWindow.Viewport.Pop();
            mainWindow.RenderState.RenderTarget = null;
            //We don't use ImageButton because we need to be specific about sizing
            var cPos = ImGui.GetCursorPos();

            ImGui.Image((IntPtr)renderTargetImage, new Vector2(rtX, rtY), new Vector2(0, 1), new Vector2(1, 0));
            ImGui.SetCursorPos(cPos);
            var wPos = ImGui.GetWindowPos();
            var mX   = (int)(mainWindow.Mouse.X - cPos.X - wPos.X);
            var mY   = (int)(mainWindow.Mouse.Y - cPos.Y - wPos.Y);

            ImGui.InvisibleButton("##renderThing", new Vector2(rtX, rtY));
            if (ImGui.IsItemHovered())
            {
                context.Update(null, TimeSpan.FromSeconds(mainWindow.TotalTime), mX, mY, false);
                if (ImGui.IsItemClicked(0))
                {
                    context.OnMouseClick();
                }
                var isDown = ImGui.IsMouseDown(0);
                if (lastDown && !isDown)
                {
                    context.OnMouseUp();
                }
                if (isDown && !lastDown)
                {
                    context.OnMouseDown();
                }
                context.MouseLeftDown = isDown;
                lastDown = isDown;
            }
            else
            {
                context.Update(null, TimeSpan.FromSeconds(mainWindow.TotalTime), 0, 0, false);
                context.MouseLeftDown = false;
                if (lastDown)
                {
                    lastDown = false;
                    context.OnMouseUp();
                }
            }
        }
示例#2
0
        void Player(double delta)
        {
            bool childopened = true;

            ImGui.Begin("playwindow", ref childopened,
                        ImGuiWindowFlags.NoTitleBar |
                        ImGuiWindowFlags.NoSavedSettings |
                        ImGuiWindowFlags.NoBringToFrontOnFocus |
                        ImGuiWindowFlags.NoMove |
                        ImGuiWindowFlags.NoResize);
            var szX = Math.Max((int)ImGui.GetWindowContentRegionWidth(), 32);
            var szY = Math.Max((int)ImGui.GetWindowHeight() - (int)(20 * ImGuiHelper.Scale), 32);

            if (rtX != szX || rtY != szY)
            {
                rtX = szX;
                rtY = szY;
                if (renderTarget != null)
                {
                    ImGuiHelper.DeregisterTexture(renderTarget.Texture);
                    renderTarget.Dispose();
                }
                renderTarget      = new RenderTarget2D(rtX, rtY);
                renderTargetImage = ImGuiHelper.RegisterTexture(renderTarget.Texture);
            }
            RenderContext.RenderTarget = renderTarget;
            RenderContext.PushViewport(0, 0, rtX, rtY);
            RenderContext.ClearColor = Color4.Black;
            RenderContext.ClearAll();
            //Do drawing
            _playContext.GlobalTime     = TotalTime;
            _playContext.ViewportWidth  = rtX;
            _playContext.ViewportHeight = rtY;
            _playContext.RenderWidget(delta);
            //
            RenderContext.PopViewport();
            RenderContext.RenderTarget = null;
            //We don't use ImageButton because we need to be specific about sizing
            var cPos = ImGui.GetCursorPos();

            ImGui.Image((IntPtr)renderTargetImage, new Vector2(rtX, rtY), new Vector2(0, 1), new Vector2(1, 0));
            ImGui.SetCursorPos(cPos);
            var wPos = ImGui.GetWindowPos();
            var mX   = (int)(Mouse.X - cPos.X - wPos.X);
            var mY   = (int)(Mouse.Y - cPos.Y - wPos.Y);

            ImGui.InvisibleButton("##renderThing", new Vector2(rtX, rtY));
            if (ImGui.IsItemHovered())
            {
                if (ImGui.GetIO().MouseWheel != 0)
                {
                    _playContext.OnMouseWheel(ImGui.GetIO().MouseWheel);
                }
                _playContext.Update(null, TotalTime, mX, mY, false);
                mouseWanted = _playContext.MouseWanted(mX, mY);
                if (ImGui.IsItemClicked(0))
                {
                    _playContext.OnMouseClick();
                }
                var isDown = ImGui.IsMouseDown(0);
                if (lastDown && !isDown)
                {
                    _playContext.OnMouseUp();
                }
                if (isDown && !lastDown)
                {
                    _playContext.OnMouseDown();
                }
                _playContext.MouseLeftDown = isDown;
                lastDown = isDown;
            }
            else
            {
                mouseWanted = false;
                _playContext.Update(null, TotalTime, 0, 0, false);
                _playContext.MouseLeftDown = false;
                if (lastDown)
                {
                    lastDown = false;
                    _playContext.OnMouseUp();
                }
            }
            ImGui.End();
        }