public override void Draw(RenderState rstate) { Mpv.mpv_event *ev = Mpv.mpv_wait_event(mpvhandle, 0); while (ev->event_id != Mpv.mpv_event_id.MPV_EVENT_NONE) { if (ev->event_id == Mpv.mpv_event_id.MPV_EVENT_END_FILE) { Playing = false; } ev = Mpv.mpv_wait_event(mpvhandle, 0); } if (disposed) { return; } game.UnbindAll(); RenderTarget2D.ClearBinding(); game.TrashGLState(); if (firstDraw) { firstDraw = false; framebuffer.BindFramebuffer(); rstate.ClearColor = Color4.Black; rstate.ClearAll(); RenderTarget2D.ClearBinding(); } if (doDraw) { rstate.Cull = false; rstate.Apply(); Mpv.mpv_opengl_cb_draw(mpvgl, (int)framebuffer.FBO, game.Width, game.Height); doDraw = false; rstate.Cull = true; } }
public void Begin(int fixWidth = -1, int fixHeight = -1) { var renderWidth = Math.Max(120, (int)ImGui.GetWindowWidth() - MarginW); var renderHeight = Math.Max(120, (int)ImGui.GetWindowHeight() - MarginH); if (fixWidth > 0) { renderWidth = fixWidth; } if (fixHeight > 0) { renderHeight = fixHeight; } //Generate render target if (rh != renderHeight || rw != renderWidth) { if (RenderTarget != null) { ImGuiHelper.DeregisterTexture(RenderTarget); RenderTarget.Dispose(); } RenderTarget = new RenderTarget2D(renderWidth, renderHeight); rid = ImGuiHelper.RegisterTexture(RenderTarget); rw = renderWidth; rh = renderHeight; } cc = rstate.ClearColor; RenderTarget.BindFramebuffer(); vps.Push(0, 0, rw, rh); rstate.Cull = true; rstate.DepthEnabled = true; rstate.ClearColor = Background; rstate.ClearAll(); }
void DrawGL(int renderWidth, int renderHeight) { //Set state renderTarget.BindFramebuffer(); rstate.Cull = true; var cc = rstate.ClearColor; rstate.DepthEnabled = true; rstate.ClearColor = Color4.CornflowerBlue * new Color4(0.3f, 0.3f, 0.3f, 1f); rstate.ClearAll(); vps.Push(0, 0, renderWidth, renderHeight); var cam = new LookAtCamera(); cam.Update(renderWidth, renderHeight, new Vector3(zoom, 0, 0), Vector3.Zero); buffer.StartFrame(rstate); polyline.SetCamera(cam); billboards.Begin(cam, buffer); debug.StartFrame(cam, rstate); instance.Draw(polyline, billboards, debug, transform, sparam); polyline.FrameEnd(); billboards.End(); buffer.DrawOpaque(rstate); rstate.DepthWrite = false; buffer.DrawTransparent(rstate); rstate.DepthWrite = true; debug.Render(); //Restore state rstate.Cull = false; rstate.BlendMode = BlendMode.Normal; rstate.DepthEnabled = false; rstate.ClearColor = cc; RenderTarget2D.ClearBinding(); vps.Pop(); }
void DrawGL(int renderWidth, int renderHeight) { //Set state renderTarget.BindFramebuffer(); rstate.Cull = true; var cc = rstate.ClearColor; rstate.DepthEnabled = true; rstate.ClearColor = background; rstate.ClearAll(); vps.Push(0, 0, renderWidth, renderHeight); //Draw Model var cam = new LookAtCamera(); cam.Update(renderWidth, renderHeight, new Vector3(zoom, 0, 0), Vector3.Zero); drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero); if (viewMode != M_NONE) { buffer.StartFrame(rstate); if (drawable is CmpFile) { DrawCmp(cam, false); } else { DrawSimple(cam, false); } buffer.DrawOpaque(rstate); rstate.DepthWrite = false; buffer.DrawTransparent(rstate); rstate.DepthWrite = true; } if (doWireframe) { buffer.StartFrame(rstate); GL.PolygonOffset(1, 1); rstate.Wireframe = true; if (drawable is CmpFile) { DrawCmp(cam, true); } else { DrawSimple(cam, false); } GL.PolygonOffset(0, 0); buffer.DrawOpaque(rstate); rstate.Wireframe = false; } //Draw hardpoints DrawHardpoints(cam); //Restore state rstate.Cull = false; rstate.BlendMode = BlendMode.Normal; rstate.DepthEnabled = false; rstate.ClearColor = cc; RenderTarget2D.ClearBinding(); vps.Pop(); }
public void Begin(int fixWidth = -1, int fixHeight = -1) { ImGuiHelper.AnimatingElement(); var renderWidth = Math.Max(120, (int)ImGui.GetWindowWidth() - MarginW); var renderHeight = Math.Max(120, (int)ImGui.GetWindowHeight() - MarginH); if (fixWidth > 0) { renderWidth = fixWidth; } if (fixHeight > 0) { renderHeight = fixHeight; } //Generate render target if (rh != renderHeight || rw != renderWidth) { if (RenderTarget != null) { ImGuiHelper.DeregisterTexture(RenderTarget); RenderTarget.Dispose(); } RenderTarget = new RenderTarget2D(renderWidth, renderHeight); rid = ImGuiHelper.RegisterTexture(RenderTarget); rw = renderWidth; rh = renderHeight; } if (mw.Config.MSAA != 0 && ((mrw != rw) || (mrh != rh) || (msamples != mw.Config.MSAA))) { if (msaa != null) { msaa.Dispose(); } msaa = new MultisampleTarget(rw, rh, mw.Config.MSAA); } else if (msaa != null) { msaa.Dispose(); mrw = mrh = -1; msamples = 0; msaa = null; } cc = rstate.ClearColor; if (mw.Config.MSAA != 0) { msaa.Bind(); } else { RenderTarget.BindFramebuffer(); } vps.Push(0, 0, rw, rh); rstate.Cull = true; rstate.DepthEnabled = true; rstate.ClearColor = Background; rstate.ClearAll(); }
int RenderGradientInternal(ViewportManager vps, Color4 top, Color4 bottom) { var target = new RenderTarget2D(128, 128); var r2d = game.GetService <Renderer2D>(); target.BindFramebuffer(); vps.Push(0, 0, 128, 128); r2d.Start(128, 128); r2d.DrawVerticalGradient(new Rectangle(0, 0, 128, 128), top, bottom); r2d.Finish(); vps.Pop(); RenderTarget2D.ClearBinding(); toFree.Add(target); return(RegisterTexture(target)); }
public void Draw(float width) { icard.SetRectangle(new Rectangle(0, 0, (int)width, int.MaxValue)); if (icard.Height != renderHeight || (int)width != renderWidth) { renderWidth = (int)width; renderHeight = (int)icard.Height; if (renderTarget != null) { ImGuiHelper.DeregisterTexture(renderTarget); renderTarget.Dispose(); } renderTarget = new RenderTarget2D(renderWidth, renderHeight); rid = ImGuiHelper.RegisterTexture(renderTarget); } renderTarget.BindFramebuffer(); window.Viewport.Push(0, 0, renderWidth, renderHeight); var cc = window.RenderState.ClearColor; window.RenderState.ClearColor = Color4.Transparent; window.RenderState.ClearAll(); window.RenderState.ClearColor = cc; window.Renderer2D.Start(renderWidth, renderHeight); icard.Draw(window.Renderer2D); window.Renderer2D.Finish(); RenderTarget2D.ClearBinding(); window.Viewport.Pop(); //ImGui. Base off ImageButton so we can get input for selection later var style = ImGui.GetStyle(); var btn = style.Colors[(int)ImGuiCol.Button]; ImGui.PushStyleColor(ImGuiCol.ButtonHovered, btn); ImGui.PushStyleColor(ImGuiCol.ButtonActive, btn); ImGui.ImageButton((IntPtr)rid, new Vector2(renderWidth, icard.Height), new Vector2(0, 1), new Vector2(1, 0), 0, Vector4.Zero, Vector4.One); ImGui.PopStyleColor(); ImGui.PopStyleColor(); //Somehow keep track of selection? (idk if InfocardDisplay should do this) }
public void Draw(float width) { icard.Recalculate(width); if (icard.Height != renderHeight || (int)width != renderWidth) { renderWidth = (int)width; renderHeight = (int)icard.Height; if (renderTarget != null) { ImGuiHelper.DeregisterTexture(renderTarget); renderTarget.Dispose(); } renderTarget = new RenderTarget2D(renderWidth, renderHeight); rid = ImGuiHelper.RegisterTexture(renderTarget); } renderTarget.BindFramebuffer(); window.Viewport.Push(0, 0, renderWidth, renderHeight); var cc = window.RenderState.ClearColor; window.RenderState.ClearColor = Color4.Transparent; window.RenderState.ClearAll(); window.RenderState.ClearColor = cc; window.Renderer2D.Start(renderWidth, renderHeight); window.RichText.RenderText(icard, 0, 0); window.Renderer2D.Finish(); RenderTarget2D.ClearBinding(); window.Viewport.Pop(); var cPos = (Vector2)ImGui.GetCursorPos(); var wPos = (Vector2)ImGui.GetWindowPos(); var scrPos = -ImGui.GetScrollY(); var mOffset = cPos + wPos + new Vector2(0, scrPos); var drawList = ImGui.GetWindowDrawList(); drawList.AddImage((IntPtr)rid, new Vector2((int)mOffset.X, (int)mOffset.Y), new Vector2((int)(mOffset.X + renderWidth), (int)(mOffset.Y + icard.Height)), new Vector2(0, 1), new Vector2(1, 0)); ImGui.InvisibleButton("##infocardbutton", new System.Numerics.Vector2(renderWidth, icard.Height)); }
void DrawGL(int renderWidth, int renderHeight) { //Set state renderTarget.BindFramebuffer(); rstate.Cull = true; var cc = rstate.ClearColor; rstate.DepthEnabled = true; rstate.ClearColor = Color4.CornflowerBlue * new Color4(0.3f, 0.3f, 0.3f, 1f); rstate.ClearAll(); vps.Push(0, 0, renderWidth, renderHeight); //Draw Model var cam = new ChaseCamera(new Viewport(0, 0, renderWidth, renderHeight)); cam.ChasePosition = Vector3.Zero; cam.ChaseOrientation = Matrix4.CreateRotationX(MathHelper.Pi); cam.DesiredPositionOffset = new Vector3(zoom, 0, 0); //cam.OffsetDirection = Vector3.UnitX; cam.Reset(); cam.Update(TimeSpan.FromSeconds(500)); buffer.StartFrame(rstate); polyline.SetCamera(cam); billboards.Begin(cam, buffer); debug.StartFrame(cam, rstate); instance.Draw(polyline, billboards, debug, transform, sparam); polyline.FrameEnd(); billboards.End(); buffer.DrawOpaque(rstate); rstate.DepthWrite = false; buffer.DrawTransparent(rstate); rstate.DepthWrite = true; debug.Render(); //Restore state rstate.Cull = false; rstate.BlendMode = BlendMode.Normal; rstate.DepthEnabled = false; rstate.ClearColor = cc; RenderTarget2D.ClearBinding(); vps.Pop(); }
void DrawGL(int renderWidth, int renderHeight) { //Set state renderTarget.BindFramebuffer(); rstate.Cull = true; var cc = rstate.ClearColor; rstate.DepthEnabled = true; rstate.ClearColor = Color4.CornflowerBlue; rstate.ClearAll(); vps.Push(0, 0, renderWidth, renderHeight); //Draw Model var cam = new ChaseCamera(new Viewport(0, 0, renderWidth, renderHeight)); cam.ChasePosition = Vector3.Zero; cam.ChaseOrientation = Matrix4.CreateRotationX(MathHelper.Pi); cam.DesiredPositionOffset = new Vector3(drawable.GetRadius() * 2, 0, 0); cam.OffsetDirection = Vector3.UnitX; cam.Reset(); cam.Update(TimeSpan.FromSeconds(500)); buffer.StartFrame(); drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero); drawable.Update(cam, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)); drawable.DrawBuffer(buffer, Matrix4.Identity, Lighting.Empty); buffer.DrawOpaque(rstate); rstate.DepthWrite = false; buffer.DrawTransparent(rstate); rstate.DepthWrite = true; //Restore state rstate.Cull = false; rstate.BlendMode = BlendMode.Normal; rstate.DepthEnabled = false; rstate.ClearColor = cc; RenderTarget2D.ClearBinding(); vps.Pop(); }
void DrawGL(int renderWidth, int renderHeight) { //Set state renderTarget.BindFramebuffer(); rstate.Cull = true; var cc = rstate.ClearColor; rstate.DepthEnabled = true; rstate.ClearColor = Color4.CornflowerBlue * new Color4(0.3f, 0.3f, 0.3f, 1f); rstate.ClearAll(); vps.Push(0, 0, renderWidth, renderHeight); //Draw Model var cam = new ChaseCamera(new Viewport(0, 0, renderWidth, renderHeight)); cam.ChasePosition = Vector3.Zero; cam.ChaseOrientation = Matrix4.CreateRotationX(MathHelper.Pi); cam.DesiredPositionOffset = new Vector3(drawable.GetRadius() * 2, 0, 0); //cam.OffsetDirection = Vector3.UnitX; cam.Reset(); cam.Update(TimeSpan.FromSeconds(500)); cam.UpdateFrameNumber(rand.Next()); //Stop bad matrix caching drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero); if (viewMode != M_NONE) { buffer.StartFrame(rstate); if (drawable is CmpFile) { DrawCmp(cam, false); } else { DrawSimple(cam, false); } buffer.DrawOpaque(rstate); rstate.DepthWrite = false; buffer.DrawTransparent(rstate); rstate.DepthWrite = true; } if (doWireframe) { buffer.StartFrame(rstate); GL.PolygonOffset(1, 1); rstate.Wireframe = true; if (drawable is CmpFile) { DrawCmp(cam, true); } else { DrawSimple(cam, false); } GL.PolygonOffset(0, 0); buffer.DrawOpaque(rstate); rstate.Wireframe = false; } //Draw hardpoints DrawHardpoints(cam); //Restore state rstate.Cull = false; rstate.BlendMode = BlendMode.Normal; rstate.DepthEnabled = false; rstate.ClearColor = cc; RenderTarget2D.ClearBinding(); vps.Pop(); }
protected override void Draw(double elapsed) { //Don't process all the imgui stuff when it isn't needed if (!guiHelper.DoRender(elapsed)) { if (lastFrame != null) { lastFrame.BlitToScreen(); } WaitForEvent(); //Yield like a regular GUI program return; } TimeStep = elapsed; Viewport.Replace(0, 0, Width, Height); RenderState.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f); RenderState.ClearAll(); guiHelper.NewFrame(elapsed); ImGui.PushFont(ImGuiHelper.Noto); ImGui.BeginMainMenuBar(); if (ImGui.BeginMenu("File")) { if (Theme.IconMenuItem("New", "new", Color4.White, true)) { var t = new UtfTab(this, new EditableUtf(), "Untitled"); ActiveTab = t; AddTab(t); } if (Theme.IconMenuItem("Open", "open", Color4.White, true)) { var f = FileDialog.Open(UtfFilters); OpenFile(f); } if (ActiveTab == null) { Theme.IconMenuItem("Save", "save", Color4.LightGray, false); Theme.IconMenuItem("Save As", "saveas", Color4.LightGray, false); } else { if (Theme.IconMenuItem(string.Format("Save '{0}'", ActiveTab.DocumentName), "saveas", Color4.White, true)) { Save(); } if (Theme.IconMenuItem("Save As", "saveas", Color4.White, true)) { SaveAs(); } } if (Theme.IconMenuItem("Quit", "quit", Color4.White, true)) { Exit(); } ImGui.EndMenu(); } bool openLoading = false; if (ImGui.BeginMenu("View")) { Theme.IconMenuToggle("Log", "log", Color4.White, ref showLog, true); ImGui.EndMenu(); } if (ImGui.BeginMenu("Tools")) { if (Theme.IconMenuItem("Options", "options", Color4.White, true)) { showOptions = true; } if (Theme.IconMenuItem("Resources", "resources", Color4.White, true)) { AddTab(new ResourcesTab(this, Resources, MissingResources, ReferencedMaterials, ReferencedTextures)); } if (Theme.IconMenuItem("Import Collada", "import", Color4.White, true)) { string input; if ((input = FileDialog.Open(ColladaFilters)) != null) { openLoading = true; finishLoading = false; new Thread(() => { List <ColladaObject> dae = null; try { dae = ColladaSupport.Parse(input); EnsureUIThread(() => FinishColladaLoad(dae, System.IO.Path.GetFileName(input))); } catch (Exception ex) { EnsureUIThread(() => ColladaError(ex)); } }).Start(); } } if (Theme.IconMenuItem("Infocard Browser", "browse", Color4.White, true)) { string input; if ((input = FileDialog.Open(FreelancerIniFilter)) != null) { AddTab(new InfocardBrowserTab(input, this)); } } ImGui.EndMenu(); } if (ImGui.BeginMenu("Help")) { if (Theme.IconMenuItem("Topics", "help", Color4.White, true)) { Shell.OpenCommand("https://wiki.librelancer.net/lanceredit:lanceredit"); } if (Theme.IconMenuItem("About", "about", Color4.White, true)) { openAbout = true; } ImGui.EndMenu(); } if (openAbout) { ImGui.OpenPopup("About"); openAbout = false; } if (openError) { ImGui.OpenPopup("Error"); openError = false; } if (openLoading) { ImGui.OpenPopup("Processing"); } bool pOpen = true; if (ImGui.BeginPopupModal("Error", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.Text("Error:"); errorText.InputTextMultiline("##etext", new Vector2(430, 200), ImGuiInputTextFlags.ReadOnly); if (ImGui.Button("OK")) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } pOpen = true; if (ImGui.BeginPopupModal("About", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.SameLine(ImGui.GetWindowWidth() / 2 - 64); Theme.Icon("reactor_128", Color4.White); CenterText(Version); CenterText("Callum McGing 2018-2019"); ImGui.Separator(); CenterText("Icons from Icons8: https://icons8.com/"); CenterText("Icons from komorra: https://opengameart.org/content/kmr-editor-icon-set"); ImGui.Separator(); var btnW = ImGui.CalcTextSize("OK").X + ImGui.GetStyle().FramePadding.X * 2; ImGui.Dummy(Vector2.One); ImGui.SameLine(ImGui.GetWindowWidth() / 2 - (btnW / 2)); if (ImGui.Button("OK")) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } pOpen = true; if (ImGui.BeginPopupModal("Processing", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize)) { ImGuiExt.Spinner("##spinner", 10, 2, ImGuiNative.igGetColorU32(ImGuiCol.ButtonHovered, 1)); ImGui.SameLine(); ImGui.Text("Processing"); if (finishLoading) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } //Confirmation if (doConfirm) { ImGui.OpenPopup("Confirm?##mainwindow"); doConfirm = false; } pOpen = true; if (ImGui.BeginPopupModal("Confirm?##mainwindow", ref pOpen, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.Text(confirmText); if (ImGui.Button("Yes")) { confirmAction(); ImGui.CloseCurrentPopup(); } ImGui.SameLine(); if (ImGui.Button("No")) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } var menu_height = ImGui.GetWindowSize().Y; ImGui.EndMainMenuBar(); var size = (Vector2)ImGui.GetIO().DisplaySize; size.Y -= menu_height; //Window MissingResources.Clear(); ReferencedMaterials.Clear(); ReferencedTextures.Clear(); foreach (var tab in tabs) { ((EditorTab)tab).DetectResources(MissingResources, ReferencedMaterials, ReferencedTextures); } ImGui.SetNextWindowSize(new Vector2(size.X, size.Y - 25), ImGuiCond.Always); ImGui.SetNextWindowPos(new Vector2(0, menu_height), ImGuiCond.Always, Vector2.Zero); bool childopened = true; ImGui.Begin("tabwindow", ref childopened, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize); TabHandler.TabLabels(tabs, ref selected); var totalH = ImGui.GetWindowHeight(); if (showLog) { ImGuiExt.SplitterV(2f, ref h1, ref h2, 8, 8, -1); h1 = totalH - h2 - 24f; if (tabs.Count > 0) { h1 -= 20f; } ImGui.BeginChild("###tabcontent" + (selected != null ? selected.RenderTitle : ""), new Vector2(-1, h1), false, ImGuiWindowFlags.None); } else { ImGui.BeginChild("###tabcontent" + (selected != null ? selected.RenderTitle : "")); } if (selected != null) { selected.Draw(); ((EditorTab)selected).SetActiveTab(this); } else { ActiveTab = null; } ImGui.EndChild(); if (showLog) { ImGui.BeginChild("###log", new Vector2(-1, h2), false, ImGuiWindowFlags.None); ImGui.Text("Log"); ImGui.SameLine(ImGui.GetWindowWidth() - 20); if (Theme.IconButton("closelog", "x", Color4.White)) { showLog = false; } logBuffer.InputTextMultiline("##logtext", new Vector2(-1, h2 - 24), ImGuiInputTextFlags.ReadOnly); ImGui.EndChild(); } ImGui.End(); //Status bar ImGui.SetNextWindowSize(new Vector2(size.X, 25f), ImGuiCond.Always); ImGui.SetNextWindowPos(new Vector2(0, size.Y - 6f), ImGuiCond.Always, Vector2.Zero); bool sbopened = true; ImGui.Begin("statusbar", ref sbopened, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize); if (updateTime > 9) { updateTime = 0; frequency = RenderFrequency; } else { updateTime++; } string activename = ActiveTab == null ? "None" : ActiveTab.DocumentName; string utfpath = ActiveTab == null ? "None" : ActiveTab.GetUtfPath(); ImGui.Text(string.Format("FPS: {0} | {1} Materials | {2} Textures | Active: {3} - {4}", (int)Math.Round(frequency), Resources.MaterialDictionary.Count, Resources.TextureDictionary.Count, activename, utfpath)); ImGui.End(); if (errorTimer > 0) { ImGuiExt.ToastText("An error has occurred\nCheck the log for details", new Color4(21, 21, 22, 128), Color4.Red); } if (showOptions) { ImGui.Begin("Options", ref showOptions, ImGuiWindowFlags.AlwaysAutoResize); var pastC = cFilter; ImGui.Combo("Texture Filter", ref cFilter, filters, filters.Length); if (cFilter != pastC) { SetTexFilter(); Config.TextureFilter = cFilter; } ImGui.Combo("Antialiasing", ref cMsaa, msaaStrings, Math.Min(msaaLevels.Length, msaaStrings.Length)); Config.MSAA = msaaLevels[cMsaa]; int cm = (int)Config.CameraMode; ImGui.Combo("Camera Mode", ref cm, cameraModes, cameraModes.Length); Config.CameraMode = (CameraModes)cm; ImGui.Checkbox("View Buttons", ref Config.ViewButtons); ImGui.Checkbox("Pause When Unfocused", ref Config.PauseWhenUnfocused); guiHelper.PauseWhenUnfocused = Config.PauseWhenUnfocused; ImGui.End(); } ImGui.PopFont(); if (lastFrame == null || lastFrame.Width != Width || lastFrame.Height != Height) { if (lastFrame != null) { lastFrame.Dispose(); } lastFrame = new RenderTarget2D(Width, Height); } lastFrame.BindFramebuffer(); guiHelper.Render(RenderState); RenderTarget2D.ClearBinding(); lastFrame.BlitToScreen(); foreach (var tab in toAdd) { tabs.Add(tab); selected = tab; } toAdd.Clear(); }
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); renderTarget.Dispose(); } renderTarget = new RenderTarget2D(rtX, rtY); renderTargetImage = ImGuiHelper.RegisterTexture(renderTarget); } renderTarget.BindFramebuffer(); mainWindow.Viewport.Push(0, 0, rtX, rtY); mainWindow.RenderState.ClearColor = Color4.Black; mainWindow.RenderState.ClearAll(); //Do drawing if (widget != null) { mainWindow.Context.GlobalTime = TimeSpan.FromSeconds(mainWindow.TotalTime); mainWindow.Context.ViewportWidth = rtX; mainWindow.Context.ViewportHeight = rtY; mainWindow.Context.RenderWidget(); } // mainWindow.Viewport.Pop(); RenderTarget2D.ClearBinding(); //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()) { mainWindow.Context.Update(null, TimeSpan.FromSeconds(mainWindow.TotalTime), mX, mY, false); if (ImGui.IsItemClicked(0)) { mainWindow.Context.OnMouseClick(); } var isDown = ImGui.IsMouseDown(0); if (lastDown && !isDown) { mainWindow.Context.OnMouseUp(); } if (isDown && !lastDown) { mainWindow.Context.OnMouseDown(); } lastDown = isDown; } else { mainWindow.Context.Update(null, TimeSpan.FromSeconds(mainWindow.TotalTime), 0, 0, false); if (lastDown) { lastDown = false; mainWindow.Context.OnMouseUp(); } } }