private void InitGlfw() { _io.KeyMap[(int)ImGuiKey.Tab] = GLFW_KEY_TAB; _io.KeyMap[(int)ImGuiKey.LeftArrow] = GLFW_KEY_LEFT; _io.KeyMap[(int)ImGuiKey.RightArrow] = GLFW_KEY_RIGHT; _io.KeyMap[(int)ImGuiKey.UpArrow] = GLFW_KEY_UP; _io.KeyMap[(int)ImGuiKey.DownArrow] = GLFW_KEY_DOWN; _io.KeyMap[(int)ImGuiKey.PageUp] = GLFW_KEY_PAGE_UP; _io.KeyMap[(int)ImGuiKey.PageDown] = GLFW_KEY_PAGE_DOWN; _io.KeyMap[(int)ImGuiKey.Home] = GLFW_KEY_HOME; _io.KeyMap[(int)ImGuiKey.End] = GLFW_KEY_END; _io.KeyMap[(int)ImGuiKey.Insert] = GLFW_KEY_INSERT; _io.KeyMap[(int)ImGuiKey.Delete] = GLFW_KEY_DELETE; _io.KeyMap[(int)ImGuiKey.Backspace] = GLFW_KEY_BACKSPACE; _io.KeyMap[(int)ImGuiKey.Space] = GLFW_KEY_SPACE; _io.KeyMap[(int)ImGuiKey.Enter] = GLFW_KEY_ENTER; _io.KeyMap[(int)ImGuiKey.Escape] = GLFW_KEY_ESCAPE; _io.KeyMap[(int)ImGuiKey.KeyPadEnter] = GLFW_KEY_KP_ENTER; _io.KeyMap[(int)ImGuiKey.A] = GLFW_KEY_A; _io.KeyMap[(int)ImGuiKey.C] = GLFW_KEY_C; _io.KeyMap[(int)ImGuiKey.V] = GLFW_KEY_V; _io.KeyMap[(int)ImGuiKey.X] = GLFW_KEY_X; _io.KeyMap[(int)ImGuiKey.Y] = GLFW_KEY_Y; _io.KeyMap[(int)ImGuiKey.Z] = GLFW_KEY_Z; _io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_setClipboardTextFn); _io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_getClipboardTextFn); _io.ClipboardUserData = _window; _mouseCursors[(int)ImGuiMouseCursor.Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); _mouseCursors[(int)ImGuiMouseCursor.NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); _userCallbackMousebutton = MouseButtonCallback; _userCallbackScroll = ScrollCallback; _userCallbackKey = KeyCallback; _userCallbackChar = CharCallback; glfwSetMouseButtonCallback(_window, _userCallbackMousebutton); glfwSetScrollCallback(_window, _userCallbackScroll); glfwSetKeyCallback(_window, _userCallbackKey); glfwSetCharCallback(_window, _userCallbackChar); }
public static void SetScrollCallback(IntPtr window, GLFWscrollfun scroll_callback) => _glfwSetScrollCallback(window, scroll_callback);
public static extern GLFWscrollfun setScrollCallback(IntPtr window, GLFWscrollfun cbfun);
public static GLFWscrollfun setScrollCallback(GLFWwindow window, GLFWscrollfun cbfun) { return(Glfwint.setScrollCallback(window.handle, cbfun)); }
internal OpenGLContext(string name) { if (GLFW.GlfwInit() == 0) { Console.Error.WriteLine("GLFW failed to initialize!"); Environment.Exit(1); } Window = GLFW.GlfwCreateWindow(1920, 1080, name, null, null); if (Window == null) { Console.Error.WriteLine("GLFW failed to open window!"); GLFW.GlfwTerminate(); Environment.Exit(1); } Input = new InputSource(); GLFW.GlfwMakeContextCurrent(Window); StrongReferences = new List <Delegate>(); { GLFWkeyfun cb = KeyCallback; StrongReferences.Add(cb); GLFW.GlfwSetKeyCallback(Window, cb); } { GLFWcharfun cb = CharCallback; StrongReferences.Add(cb); GLFW.GlfwSetCharCallback(Window, cb); } { GLFWerrorfun cb = ErrorCallback; StrongReferences.Add(cb); GLFW.GlfwSetErrorCallback(cb); } { GLFWscrollfun cb = ScrollCallback; StrongReferences.Add(cb); GLFW.GlfwSetScrollCallback(Window, cb); } { GLFWcharmodsfun cb = CharModsCallback; StrongReferences.Add(cb); GLFW.GlfwSetCharModsCallback(Window, cb); } { GLFWcursorposfun cb = CursorPosCallback; StrongReferences.Add(cb); GLFW.GlfwSetCursorPosCallback(Window, cb); } { GLFWwindowposfun cb = WindowPosCallback; StrongReferences.Add(cb); GLFW.GlfwSetWindowPosCallback(Window, cb); } { GLFWwindowsizefun cb = WindowSizeCallback; StrongReferences.Add(cb); GLFW.GlfwSetWindowSizeCallback(Window, cb); } { GLFWcursorenterfun cb = CursorEnterCallback; StrongReferences.Add(cb); GLFW.GlfwSetCursorEnterCallback(Window, cb); } { GLFWmousebuttonfun cb = MouseButtonCallback; StrongReferences.Add(cb); GLFW.GlfwSetMouseButtonCallback(Window, cb); } { GLFWwindowfocusfun cb = WindowFocusCallback; StrongReferences.Add(cb); GLFW.GlfwSetWindowFocusCallback(Window, cb); } { GLFWwindowiconifyfun cb = WindowIconifyCallback; StrongReferences.Add(cb); GLFW.GlfwSetWindowIconifyCallback(Window, cb); } { GLFWframebuffersizefun cb = FrameBufferSizeCallback; StrongReferences.Add(cb); GLFW.GlfwSetFramebufferSizeCallback(Window, cb); } }
public GlfwWindow(WindowSettings settings) : base(settings) { var glfwMonitor = settings.Monitor as GlfwMonitor ?? throw new NotSupportedException(); this.keyRepeatEnabled = false; var enc = Encoding.GetEncoding("utf-32", new EncoderReplacementFallback("□"), new DecoderReplacementFallback("□")); this.utf32Decoder = enc.GetDecoder(); glfwDefaultWindowHints(); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); switch (settings.Style) { case WindowStyle.Windowed: glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); break; case WindowStyle.FullScreen: case WindowStyle.Borderless: glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); break; } checked { var mode = settings.DisplayMode; int bitspercolour = (int)mode.BitsPerPixel / 4; glfwWindowHint(GLFW_RED_BITS, bitspercolour); glfwWindowHint(GLFW_GREEN_BITS, bitspercolour); glfwWindowHint(GLFW_BLUE_BITS, bitspercolour); glfwWindowHint(GLFW_ALPHA_BITS, bitspercolour); glfwWindowHint(GLFW_REFRESH_RATE, (int)mode.RefreshRate); var titleutf8 = Encoding.UTF8.GetBytes(settings.Title); unsafe { fixed(byte *titleptr = titleutf8) { this.window = glfwCreateWindow((int)mode.Width, (int)mode.Height, titleptr, settings.Style == WindowStyle.FullScreen ? glfwMonitor.Handle : IntPtr.Zero, IntPtr.Zero); } } } if (this.window == IntPtr.Zero) { var errorPtr = IntPtr.Zero; glfwGetError(errorPtr); var errorDesc = new CString(errorPtr); throw new ApplicationException(errorDesc); } this.windowResizeDelegate = this.HandleResizeEvent; this.windowFocusDelegate = this.HandleFocusEvent; this.cursorEnterDelegate = this.HandleMouseEnterOrLeaveEvent; this.cursorMoveDelegate = this.HandleMouseMoveEvent; this.mouseButtonDelegate = this.HandleMouseButtonEvent; this.scrollDelegate = this.HandleScrollEvent; this.keyDelegate = this.HandleKeyEvent; this.textDelegate = this.HandleTextEvent; this.SetupCallbacks(); this.Activate(); glfwSwapInterval(settings.VSync ? 1 : 0); glfwSetInputMode(this.window, GLFW_CURSOR, settings.ShowCursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); }
/*! @brief Sets the scroll callback. * * This function sets the scroll callback of the specified window, which is * called when a scrolling device is used, such as a mouse wheel or scrolling * area of a touchpad. * * The scroll callback receives all scrolling input, like that from a mouse * wheel or a touchpad scrolling area. * * @param[in] window The window whose callback to set. * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently * set callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @par Thread Safety * This function may only be called from the main thread. * * @sa @ref scrolling * * @since Added in GLFW 3.0. Replaces `glfwSetMouseWheelCallback`. * * @ingroup input */ internal static extern GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);