public static void Update(Vector2i mousePos, Vector2f displaySize, Time dt) { var io = ImGui.GetIO(); io.DisplaySize = new Vector2(displaySize.X, displaySize.Y); io.DeltaTime = dt.AsSeconds(); if (_windowHasFocus) { if (io.WantSetMousePos) { var newMousePos = new Vector2i((int)io.MousePos.X, (int)io.MousePos.Y); Mouse.SetPosition(newMousePos); } else { io.MousePos = new Vector2(mousePos.X, mousePos.Y); } for (var i = 0; i < 3; i++) { io.MouseDown[i] = _touchDown[i] || Touch.IsDown((uint)i) || _mousePressed[i] || Mouse.IsButtonPressed((Mouse.Button)i); _mousePressed[i] = false; _touchDown[i] = false; } } // Update Ctrl, Shift, Alt, Super state io.KeyCtrl = io.KeysDown[(int)Keyboard.Key.LControl] || io.KeysDown[(int)Keyboard.Key.RControl]; io.KeyAlt = io.KeysDown[(int)Keyboard.Key.LAlt] || io.KeysDown[(int)Keyboard.Key.RAlt]; io.KeyShift = io.KeysDown[(int)Keyboard.Key.LShift] || io.KeysDown[(int)Keyboard.Key.RShift]; io.KeySuper = io.KeysDown[(int)Keyboard.Key.LSystem] || io.KeysDown[(int)Keyboard.Key.RSystem]; Debug.Assert(io.Fonts.Fonts.Size > 0); // You forgot to create and set up font // atlas (see createFontTexture) //gamepad navigation Joystick.Update(); // joystick detection issue fix in SFML.NET if ((io.ConfigFlags & ImGuiConfigFlags.NavEnableGamepad) != 0 && JoystickId != _nullJoystickId) { UpdateJoystickActionState(io, ImGuiNavInput.Activate); UpdateJoystickActionState(io, ImGuiNavInput.Cancel); UpdateJoystickActionState(io, ImGuiNavInput.Input); UpdateJoystickActionState(io, ImGuiNavInput.Menu); UpdateJoystickActionState(io, ImGuiNavInput.FocusPrev); UpdateJoystickActionState(io, ImGuiNavInput.FocusNext); UpdateJoystickActionState(io, ImGuiNavInput.TweakSlow); UpdateJoystickActionState(io, ImGuiNavInput.TweakFast); UpdateJoystickDPadState(io); UpdateJoystickLStickState(io); } ImGui.NewFrame(); }
/// <summary> /// Sets up ImGui for a new frame, should be called at frame start /// </summary> public virtual void BeforeLayout(GameTime gameTime) { ImGui.GetIO().DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; UpdateInput(); ImGui.NewFrame(); }
public void BeginFrame(float elapsedTime = 1.0f / 60.0f) { IO io = ImGui.GetIO(); io.DisplaySize = new System.Numerics.Vector2(Window.Width, Window.Height); io.DeltaTime = elapsedTime; UpdateImGuiInput(io); ImGui.NewFrame(); }
/// <summary> /// Updates ImGui input and IO configuration state. /// </summary> public void Update(float deltaSeconds, InputSnapshot snapshot) { if (_frameBegun) { ImGui.Render(); } SetPerFrameImGuiData(deltaSeconds); UpdateImGuiInput(snapshot); _frameBegun = true; ImGui.NewFrame(); }
unsafe void Render() { io.DisplaySize = new System.Numerics.Vector2(window.Width, window.Height); io.DisplayFramebufferScale = new System.Numerics.Vector2(window.Width / setting.Width); io.DeltaTime = setting.DesiredFrameRate; control.Update(); ImGui.NewFrame(); DrawUI(); ImGui.Render(); RenderImDrawData(ImGui.GetDrawData()); }
/// <summary> /// Constructs a new ImGuiRenderer. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height) { _gd = gd; _windowWidth = width; _windowHeight = height; ImGui.GetIO().Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetOpenTKKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
/// <summary> /// Updates ImGui input and IO configuration state. /// </summary> public void Update(float deltaSeconds, InputSnapshot snapshot) { if (_frameBegun) { ImGui.Render(); ImGui.UpdatePlatformWindows(); } SetPerFrameImGuiData(deltaSeconds); UpdateImGuiInput(snapshot); UpdateMonitors(); _frameBegun = true; ImGui.NewFrame(); ImGui.Text($"Main viewport Position: {ImGui.GetPlatformIO().MainViewport.Pos}"); ImGui.Text($"Main viewport Size: {ImGui.GetPlatformIO().MainViewport.Size}"); ImGui.Text($"MoouseHoveredViewport: {ImGui.GetIO().MouseHoveredViewport}"); }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height) { _gd = gd; _windowWidth = width; _windowHeight = height; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); var io = ImGui.GetIO(); ImVector ranges; unsafe { var rangesBuilder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); rangesBuilder.AddRanges(io.Fonts.GetGlyphRangesJapanese()); rangesBuilder.AddRanges(io.Fonts.GetGlyphRangesChineseFull()); ushort[] extraCharsRange = { 0x25A0, 0x25FF, // geometric shapes, 0x2000, 0x206F, // general punctuation 0xFF00, 0xFFEF, // halfwidth and fullwidth forms 0x2600, 0x26FF, // misc symbols 0x2190, 0x21FF, // arrows 0 }; fixed(ushort *extraCharsRangePtr = extraCharsRange) { rangesBuilder.AddRanges((IntPtr)extraCharsRangePtr); rangesBuilder.BuildRanges(out ranges); } } ImFontPtr font = io.Fonts.AddFontFromFileTTF("../../../NotoSansCJKjp-Medium.otf", 24.0f, null, ranges.Data); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
private unsafe void RenderFrame() { IO io = ImGui.GetIO(); io.DisplaySize = new System.Numerics.Vector2(_nativeWindow.Width, _nativeWindow.Height); io.DisplayFramebufferScale = new System.Numerics.Vector2(_scaleFactor); io.DeltaTime = (1f / 60f); UpdateImGuiInput(io); ImGui.NewFrame(); SubmitImGuiStuff(); ImGui.Render(); DrawData *data = ImGui.GetDrawData(); RenderImDrawData(data); }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height) { _gd = gd; _windowWidth = width; _windowHeight = height; _imgui = new ImGui(); IntPtr context = _imgui.CreateContext(); _imgui.SetCurrentContext(context); var fonts = _imgui.GetIO().Fonts; _imgui.GetIO().Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); _imgui.NewFrame(); _frameBegun = true; }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, Sdl2Window window, OutputDescription outputDescription, int width, int height) { _gd = gd; _window = window; _windowWidth = width; _windowHeight = height; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); ImGuiIOPtr io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO(); ImGuiViewportPtr mainViewport = platformIO.MainViewport; _mainViewportWindow = new VeldridImGuiWindow(gd, mainViewport, _window); mainViewport.PlatformHandle = window.Handle; _createWindow = CreateWindow; _destroyWindow = DestroyWindow; _getWindowPos = GetWindowPos; _showWindow = ShowWindow; _setWindowPos = SetWindowPos; _setWindowSize = SetWindowSize; _getWindowSize = GetWindowSize; _setWindowFocus = SetWindowFocus; _getWindowFocus = GetWindowFocus; _getWindowMinimized = GetWindowMinimized; _setWindowTitle = SetWindowTitle; platformIO.Platform_CreateWindow = Marshal.GetFunctionPointerForDelegate(_createWindow); platformIO.Platform_DestroyWindow = Marshal.GetFunctionPointerForDelegate(_destroyWindow); platformIO.Platform_ShowWindow = Marshal.GetFunctionPointerForDelegate(_showWindow); platformIO.Platform_SetWindowPos = Marshal.GetFunctionPointerForDelegate(_setWindowPos); platformIO.Platform_SetWindowSize = Marshal.GetFunctionPointerForDelegate(_setWindowSize); platformIO.Platform_SetWindowFocus = Marshal.GetFunctionPointerForDelegate(_setWindowFocus); platformIO.Platform_GetWindowFocus = Marshal.GetFunctionPointerForDelegate(_getWindowFocus); platformIO.Platform_GetWindowMinimized = Marshal.GetFunctionPointerForDelegate(_getWindowMinimized); platformIO.Platform_SetWindowTitle = Marshal.GetFunctionPointerForDelegate(_setWindowTitle); platformIO.Platform_GetWindowPos = Marshal.GetFunctionPointerForDelegate(_getWindowPos); platformIO.Platform_GetWindowSize = Marshal.GetFunctionPointerForDelegate(_getWindowSize); unsafe { io.NativePtr->BackendPlatformName = (byte *)new FixedAsciiString("Veldrid.SDL2 Backend").DataPtr; } io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors; io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos; io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports; io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; io.Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); UpdateMonitors(); ImGui.NewFrame(); _frameBegun = true; }