private static void DestroyWindow(ImGuiViewport *viewport) { ViewportData *viewportData = (ViewportData *)viewport->PlatformUserData; if (viewportData is not null) { if (viewportData->WindowOwned) { PlatformBackend backend = GetPlatformBackend(); // Release any keys that were pressed in the window being destroyed and are still held down, // because we will not receive any release events after window is destroyed. for (int i = 0; i < backend.KeyOwnerWindows.Length; i++) { if (backend.KeyOwnerWindows[i] == viewportData->Window) { KeyCallbackManaged(viewportData->Window, (Keys)i, 0, InputAction.Release, 0); } // Later params are only used for main viewport, on which this function is never called. } GLFW.DestroyWindow(viewportData->Window); } viewportData->Window = null; ViewportData.Free(viewportData); } viewport->PlatformUserData = viewport->PlatformHandle = null; }
// ImGui_ImplGlfw_InitPlatformInterface private void InitPlatformInterface() { Io->BackendFlags |= ImGuiBackendFlags.PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) PlatformIo->Platform_CreateWindow = &CreateWindow; PlatformIo->Platform_DestroyWindow = &DestroyWindow; PlatformIo->Platform_ShowWindow = &ShowWindow; PlatformIo->Platform_SetWindowPos = &SetWindowPos; PlatformIo->Platform_GetWindowPos = &GetWindowPos; PlatformIo->Platform_SetWindowSize = &SetWindowSize; PlatformIo->Platform_GetWindowSize = &GetWindowSize; PlatformIo->Platform_SetWindowFocus = &SetWindowFocus; PlatformIo->Platform_GetWindowFocus = &GetWindowFocus; PlatformIo->Platform_GetWindowMinimized = &GetWindowMinimized; PlatformIo->Platform_SetWindowTitle = &SetWindowTitle; PlatformIo->Platform_SetWindowAlpha = &SetWindowAlpha; // Unused: UpdateWindow PlatformIo->Platform_RenderWindow = &RenderWindow; PlatformIo->Platform_SwapBuffers = &SwapBuffers; // Unused: GetWindowDpiScale // Unused: OnChangedViewport // Unused: CreateVkSurface // Register main window handle (which is owned by the main application, not by us) // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport *mainViewport = ImGui.GetMainViewport(); ViewportData * viewportData = ViewportData.Allocate(); *viewportData = new() { Window = Window, WindowOwned = false }; mainViewport->PlatformUserData = viewportData; mainViewport->PlatformHandle = Window; // Determine if SetWindowSize needs the macOS workaround // (See SetWindowSize for details.) if (OperatingSystem.IsMacOS()) { GLFW.GetVersion(out int major, out int minor, out int revision); NeedMacOsSetWindowSizeWorkaround = (major * 1000 + minor * 100 + revision * 10) < 3310; } }
private static void CreateWindow(ImGuiViewport *viewport) { PlatformBackend backend = GetPlatformBackend(); ViewportData * viewportData = ViewportData.Allocate(); viewport->PlatformUserData = viewportData; GLFW.WindowHint(WindowHintBool.Visible, false); GLFW.WindowHint(WindowHintBool.Focused, false); GLFW.WindowHint(WindowHintBool.FocusOnShow, false); GLFW.WindowHint(WindowHintBool.Decorated, !viewport->Flags.HasFlag(ImGuiViewportFlags.NoDecoration)); GLFW.WindowHint(WindowHintBool.Floating, viewport->Flags.HasFlag(ImGuiViewportFlags.TopMost)); *viewportData = new ViewportData() { Window = GLFW.CreateWindow((int)viewport->Size.X, (int)viewport->Size.Y, "No Title Yet", null, backend.Window), WindowOwned = true, }; viewport->PlatformHandle = viewportData->Window; if (OperatingSystem.IsWindows()) { viewport->PlatformHandleRaw = (void *)GLFW.GetWin32Window(viewportData->Window); } GLFW.SetWindowPos(viewportData->Window, (int)viewport->Pos.X, (int)viewport->Pos.Y); // Install GLFW callbacks for secondary viewports GlfwNative.glfwSetWindowFocusCallback(viewportData->Window, &WindowFocusCallback); GlfwNative.glfwSetCursorEnterCallback(viewportData->Window, &CursorEnterCallback); GlfwNative.glfwSetCursorPosCallback(viewportData->Window, &CursorPosCallback); GlfwNative.glfwSetMouseButtonCallback(viewportData->Window, &MouseButtonCallback); GlfwNative.glfwSetScrollCallback(viewportData->Window, &ScrollCallback); GlfwNative.glfwSetKeyCallback(viewportData->Window, &KeyCallback); GlfwNative.glfwSetCharCallback(viewportData->Window, &CharCallback); GlfwNative.glfwSetWindowCloseCallback(viewportData->Window, &WindowCloseCallback); GlfwNative.glfwSetWindowPosCallback(viewportData->Window, &WindowPosCallback); GlfwNative.glfwSetWindowSizeCallback(viewportData->Window, &WindowSizeCallback); GLFW.MakeContextCurrent(viewportData->Window); GLFW.SwapInterval(0); }
private void RefreshDataTimerTick(object sender, EventArgs e) { try { sync.EnterReadLock(); for (int i = Math.Max(lastRawDataIndex, rawData.Count - DataWindow); i < rawData.Count; i++) { ViewportData.Add(rawData[i]); } lastRawDataIndex = rawData.Count; while (ViewportData.Count > DataWindow) { ViewportData.RemoveAt(0); } } finally { sync.ExitReadLock(); } }
public void CompareWith(ObjectCollection Collection) { for (int i = 0; i < Viewports.Count; i++) { ViewportData vp1 = Viewports[i]; ViewportData vp2 = i < Collection.Viewports.Count ? Collection.Viewports[i] : null; if (vp2 == null) { Console.WriteLine($"One disposed viewport ({vp1.X}, {vp1.Y}, {vp1.Width}, {vp1.Height})"); } else { vp1.CompareWith(vp2); } } for (int i = Viewports.Count; i < Collection.Viewports.Count; i++) { ViewportData vp = Collection.Viewports[i]; Console.WriteLine($"One new viewport ({vp.X}, {vp.Y}, {vp.Width}, {vp.Height})"); } }
public SpriteData(ViewportData Viewport, Sprite Sprite) { this.X = Sprite.X; this.Y = Sprite.Y; this.OX = Sprite.OX; this.OY = Sprite.OY; this.ZoomX = Sprite.ZoomX; this.ZoomY = Sprite.ZoomY; this.Opacity = Sprite.Opacity; this.Angle = Sprite.Angle; this.MirrorX = Sprite.MirrorX; this.MirrorY = Sprite.MirrorY; this.Bitmap = new BitmapData(Sprite.Bitmap); this.SrcRect = new RectData(Sprite.SrcRect); this.Color = new ColorData(Sprite.Color); this.Tone = new ToneData(Sprite.Tone); this.Disposed = Sprite.Disposed; this.Visible = Sprite.Visible; this.Viewport = Viewport; this.Z = Sprite.Z; }
public void CompareWith(ViewportData Viewport) { string Diff = "Viewport properties changed: "; if (this.X != Viewport.X) { Diff += $"(X {this.X}->{Viewport.X}) "; } if (this.Y != Viewport.Y) { Diff += $"(Y {this.Y}->{Viewport.Y}) "; } if (this.Width != Viewport.Width) { Diff += $"(Width {this.Width}->{Viewport.Width}) "; } if (this.Height != Viewport.Height) { Diff += $"(Height {this.Height}->{Viewport.Height}) "; } if (this.OX != Viewport.OX) { Diff += $"(OX {this.OX}->{Viewport.OX}) "; } if (this.OY != Viewport.OY) { Diff += $"(OY {this.OY}->{Viewport.OY}) "; } if (this.Visible != Viewport.Visible) { Diff += $"(Visible {this.Visible}->{Viewport.Visible}) "; } if (this.Disposed != Viewport.Disposed) { Diff += $"(Disposed {this.Disposed}->{Viewport.Disposed}) "; } if (this.Z != Viewport.Z) { Diff += $"(Z {this.Z}->{Viewport.Z}) "; } Diff += this.Color.CompareWith(Viewport.Color); if (Diff != "Viewport properties changed: ") { Console.WriteLine(Diff.Substring(0, Diff.Length - 1) + ")"); } for (int i = 0; i < Sprites.Count; i++) { SpriteData s1 = Sprites[i]; SpriteData s2 = i < Viewport.Sprites.Count ? Viewport.Sprites[i] : null; if (s2 == null) { Console.WriteLine($"One disposed sprite ({s1.X}, {s1.Y}, bmp({s1.Bitmap.Width},{s1.Bitmap.Height}))"); } else { s1.CompareWith(s2); } } for (int i = Sprites.Count; i < Viewport.Sprites.Count; i++) { SpriteData s = Viewport.Sprites[i]; Console.WriteLine($"One new sprite ({s.X}, {s.Y}, bmp({s.Bitmap.Width}, {s.Bitmap.Height}))"); } }