internal static ImGuiUnityContext CreateUnityContext() { return(new ImGuiUnityContext { state = ImGui.CreateContext(), textures = new TextureManager(), }); }
/// <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; }
/// <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); ImGui.GetIO().Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
public ImGuiRenderer(Game game) { var context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); _game = game ?? throw new ArgumentNullException(nameof(game)); _graphicsDevice = game.GraphicsDevice; _loadedTextures = new Dictionary <IntPtr, Texture2D>(); _rasterizerState = new RasterizerState() { CullMode = CullMode.None, DepthBias = 0, FillMode = FillMode.Solid, MultiSampleAntiAlias = false, ScissorTestEnable = true, SlopeScaleDepthBias = 0 }; SetupInput(); }
public static void Init(Window window, Vector2f displaySize, bool loadDefaultFont = true) { ImGui.CreateContext(); var io = ImGui.GetIO(); // tell ImGui which features we support io.BackendFlags |= ImGuiBackendFlags.HasGamepad; io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors; io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos; // init keyboard mapping io.KeyMap[(int)ImGuiKey.Tab] = (int)Keyboard.Key.Tab; io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Keyboard.Key.Left; io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keyboard.Key.Right; io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Keyboard.Key.Up; io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Keyboard.Key.Down; io.KeyMap[(int)ImGuiKey.PageUp] = (int)Keyboard.Key.PageUp; io.KeyMap[(int)ImGuiKey.PageDown] = (int)Keyboard.Key.PageDown; io.KeyMap[(int)ImGuiKey.Home] = (int)Keyboard.Key.Home; io.KeyMap[(int)ImGuiKey.End] = (int)Keyboard.Key.End; io.KeyMap[(int)ImGuiKey.Insert] = (int)Keyboard.Key.Insert; io.KeyMap[(int)ImGuiKey.Delete] = (int)Keyboard.Key.Delete; io.KeyMap[(int)ImGuiKey.Backspace] = (int)Keyboard.Key.Backspace; io.KeyMap[(int)ImGuiKey.Space] = (int)Keyboard.Key.Space; io.KeyMap[(int)ImGuiKey.Enter] = (int)Keyboard.Key.Enter; io.KeyMap[(int)ImGuiKey.Escape] = (int)Keyboard.Key.Escape; io.KeyMap[(int)ImGuiKey.A] = (int)Keyboard.Key.A; io.KeyMap[(int)ImGuiKey.C] = (int)Keyboard.Key.C; io.KeyMap[(int)ImGuiKey.V] = (int)Keyboard.Key.V; io.KeyMap[(int)ImGuiKey.X] = (int)Keyboard.Key.X; io.KeyMap[(int)ImGuiKey.Y] = (int)Keyboard.Key.Y; io.KeyMap[(int)ImGuiKey.Z] = (int)Keyboard.Key.Z; JoystickId = GetConnectedJoystickId(); for (var i = 0u; i < (uint)ImGuiNavInput.COUNT; ++i) { _joystickMapping[i] = _nullJoystickButton; } InitDefaultJoystickMapping(); // init rendering io.DisplaySize = new Vector2(displaySize.X, displaySize.Y); LoadMouseCursor(ImGuiMouseCursor.Arrow, Cursor.CursorType.Arrow); LoadMouseCursor(ImGuiMouseCursor.TextInput, Cursor.CursorType.Text); LoadMouseCursor(ImGuiMouseCursor.ResizeAll, Cursor.CursorType.SizeAll); LoadMouseCursor(ImGuiMouseCursor.ResizeNS, Cursor.CursorType.SizeVertical); LoadMouseCursor(ImGuiMouseCursor.ResizeEW, Cursor.CursorType.SizeHorinzontal); LoadMouseCursor(ImGuiMouseCursor.ResizeNESW, Cursor.CursorType.SizeBottomLeftTopRight); LoadMouseCursor(ImGuiMouseCursor.ResizeNWSE, Cursor.CursorType.SizeTopLeftBottomRight); LoadMouseCursor(ImGuiMouseCursor.Hand, Cursor.CursorType.Hand); if (loadDefaultFont) { // this will load default font automatically // No need to call AddDefaultFont UpdateFontTexture(); } _windowHasFocus = window.HasFocus(); window.MouseMoved += OnMouseMoved; window.MouseButtonPressed += OnMouseButtonPressed; window.MouseButtonReleased += OnMouseButtonReleased; window.TouchBegan += OnTouchBegan; window.TouchEnded += OnTouchEnded; window.MouseWheelScrolled += OnMouseWheelScrolled; window.KeyPressed += OnKeyPressed; window.KeyReleased += OnKeyReleased; window.TextEntered += OnTextEntered; window.JoystickConnected += OnJoystickConnected; window.JoystickDisconnected += OnJoystickDisconnected; window.GainedFocus += OnGainedFocus; window.LostFocus += OnLostFocus; }
/// <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; }