Esempio n. 1
0
        static GlfwApp()
        {
            s_windowCloseCb = (GlfwWindowPtr wnd) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    //user can cancel window close here here
                    bool userCancel = false;
                    GlFwForm.InvokeOnClosing(found, ref userCancel);
                    if (userCancel)
                    {
                        return;
                    }
                    //--------------------------------------
                    s_latestForm        = null;
                    s_latestGlWindowPtr = IntPtr.Zero;
                    //user let this window close ***
                    Glfw.SetWindowShouldClose(wnd, true);
                    Glfw.DestroyWindow(wnd); //destroy this
                    s_existingForms.Remove(wnd);
                    exitingFormList.Remove(found);
                    //--------------------------------------
                }
            };
            s_windowFocusCb = (GlfwWindowPtr wnd, bool focus) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.SetFocusState(found, focus);
                }
            };
            s_windowIconifyCb = (GlfwWindowPtr wnd, bool iconify) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.SetIconifyState(found, iconify);
                }
            };

            s_windowPosCb = (GlfwWindowPtr wnd, int x, int y) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.InvokeOnWindowMove(found, x, y);
                }
            };
            s_windowRefreshCb = (GlfwWindowPtr wnd) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.InvokeOnRefresh(found);
                }
            };

            s_windowSizeCb = (GlfwWindowPtr wnd, int width, int height) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.InvokeOnSizeChanged(found, width, height);
                }
            };
            s_windowCursorPosCb = (GlfwWindowPtr wnd, double x, double y) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    found._latestMouseX = x;
                    found._latestMouseY = y;

                    GlFwForm.InvokeCursorPos(found, x, y);
                }
            };
            s_windowCursorEnterCb = (GlfwWindowPtr wnd, bool enter) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.SetCursorEnterState(found, enter);
                }
            };
            s_windowMouseButtonCb = (GlfwWindowPtr wnd, MouseButton btn, KeyActionKind keyAction) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    int x = (int)found._latestMouseX;
                    int y = (int)found._latestMouseY;

                    GlFwForm.InvokeMouseButton(found, btn, keyAction, x, y);
                }
            };
            s_scrollCb = (GlfwWindowPtr wnd, double xoffset, double yoffset) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    int x = (int)found._latestMouseX;
                    int y = (int)found._latestMouseY;
                    GlFwForm.InvokeOnScroll(found, x, y, (int)xoffset, (int)yoffset);
                }
            };
            s_windowKeyCb = (GlfwWindowPtr wnd, Key key, int scanCode, KeyActionKind action, KeyModifiers mods) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.InvokeKey(found, key, scanCode, action, mods);
                }
            };
            s_windowCharCb = (GlfwWindowPtr wnd, char ch) =>
            {
                if (GetGlfwForm(wnd, out GlFwForm found))
                {
                    GlFwForm.InvokeKeyPress(found, ch);
                }
            };
        }