Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using SDL2;
  5. using ImGuiNET;
  6. using ImGuiSDL2CS;
  7.  
  8. namespace YourGameNamespace {
  9. public class YourGameWindow : ImGuiSDL2CSWindow {
  10.  
  11. private TextInputBuffer[] _TextInputBuffers;
  12.  
  13. public YourGameWindow()
  14. : base("Your Game Window Title") {
  15.  
  16. //////// OPTIONAL ////////
  17. // This affects the "underlying" SDL2Window and can be used for a quick game loop sketch.
  18. // Don't set those and only ImGui gets rendered / handled.
  19. // They're delegate fields so that one can override those from outside.
  20. OnEvent = MyEventHandler;
  21. OnLoop = MyGameLoop;
  22.  
  23. }
  24.  
  25. // Create any possibly unmanaged resources (textures, buffers) here.
  26. protected override void Create() {
  27. base.Create();
  28.  
  29. _TextInputBuffers = TextInputBuffer.CreateBuffers(2);
  30. }
  31.  
  32. // Dispose any possibly unmanaged resources (textures, buffers) here.
  33. protected override void Dispose(bool disposing) {
  34. TextInputBuffer.DisposeBuffers(_TextInputBuffers);
  35.  
  36. base.Dispose(disposing);
  37. }
  38.  
  39. // This runs between ImGuiSDL2CSHelper.NewFrame and ImGuiSDL2CSHelper.Render.
  40. public unsafe override void ImGuiLayout() {
  41. ImGui.BeginWindow("Window 1");
  42. ImGui.LabelText("Label", "Text");
  43. ImGui.InputText("Some text input", _TextInputBuffers[0].Buffer, _TextInputBuffers[0].Length, InputTextFlags.Default, ImGuiSDL2CSHelper.OnTextEdited);
  44. ImGui.EndWindow();
  45.  
  46. ImGui.BeginWindow("Window 2");
  47. ImGui.LabelText("Label", "Text");
  48. ImGui.InputText("Some other text input", _TextInputBuffers[1].Buffer, _TextInputBuffers[1].Length, InputTextFlags.Default, ImGuiSDL2CSHelper.OnTextEdited);
  49. ImGui.EndWindow();
  50. }
  51.  
  52. //////// OPTIONAL ////////
  53.  
  54. // Processs any SDL2 events manually if required.
  55. // Return false to not allow the default event handler to process it.
  56. public bool MyEventHandler(SDL2Window _self, SDL.SDL_Event e) {
  57. // We're replacing OnEvent and thus call ImGuiSDL2CSHelper.OnEvent manually.
  58. if (!ImGuiSDL2CSHelper.OnEvent(e, ref g_MouseWheel, g_MousePressed))
  59. return false;
  60.  
  61. // Any custom event handling can happen here.
  62.  
  63. return true;
  64. }
  65.  
  66. // Any custom game loop should end up here.
  67. // Setting the window.IsActive = false stops the loop.
  68. public void MyGameLoop(SDL2Window _self) {
  69. // This is the default implementation.
  70.  
  71. // Using MiniTK (not OpenTK) to provide access to OpenGL methods.
  72. // Alternatively, use SDL_GL_GetProcAddress on your own.
  73. OpenTK.Graphics.OpenGL.GL.ClearColor(0.1f, 0.125f, 0.15f, 1f);
  74. OpenTK.Graphics.OpenGL.GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit);
  75.  
  76. // This calls ImGuiSDL2CSHelper.NewFrame, the overridden ImGuiLayout, ImGuiSDL2CSHelper.Render and renders it.
  77. // ImGuiSDL2CSHelper.NewFrame properly sets up ImGuiIO and ImGuiSDL2CSHelper.Render renders the draw data.
  78. ImGuiRender();
  79.  
  80. // Finally, swap.
  81. Swap();
  82. }
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement