public static GlFwForm CreateGlfwForm(int w, int h, string title) { GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(w, h, title, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window GlFwForm f = new GlFwForm(); f.InitGlFwForm(glWindowPtr, w, h); f.Text = title; //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); ////------------------- existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); return(f); }
internal static void InvokeCursorPos(GlFwForm f, double x, double y) { //TODO: implement detail methods f._latestMouseX = x; f._latestMouseY = y; f.OnMouseMove(x, y); }
internal static void InitGlFwForm(GlFwForm f) { //create pointer GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(f.Width, f.Height, f.Text, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window f.InitGlFwForm(glWindowPtr, f.Width, f.Height); //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); ////------------------- existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); }
internal static void InitGlFwForm(GlFwForm f, int initW, int initH, string title = "") { GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(initW, initH, title, new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window Glfw.MakeContextCurrent(glWindowPtr); //*** f.SetupNativePtr(glWindowPtr, f.Width, f.Height); //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); //------------------- s_existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); //------------------- GLFWPlatforms.CreateGLESContext(f); }
internal static void RegisterGlfwForm(GlFwForm form) { form.IsRegistered = true; s_forms.Add(form); if (s_mainMsgWin == null) { s_mainMsgWin = form; } }
internal static void SetCursorEnterState(GlFwForm f, bool enter) { if (enter) { f.OnCursorEnter(); } else { f.OnCursorLeave(); } }
internal static void SetFocusState(GlFwForm f, bool focus) { if (focus) { f.OnFocus(); } else { f.OnLostFocus(); } }
public static void UpdateWindowsFrame() { int j = exitingFormList.Count; for (int i = 0; i < j; ++i) { /* Render here */ /* Swap front and back buffers */ GlFwForm form = exitingFormList[i]; form.DrawFrame(); Glfw.SwapBuffers(form.GlfwWindowPtr); } }
internal static void InvokeKey(GlFwForm f, Key key, int scanCode, KeyActionKind keyAction, KeyModifiers mods) { switch (keyAction) { default: throw new NotFiniteNumberException(); case KeyActionKind.Press: f.OnKeyDown(key, scanCode, mods); break; case KeyActionKind.Repeat: f.OnKeyRepeat(key, scanCode, mods); break; case KeyActionKind.Release: f.OnKeyUp(key, scanCode, mods); break; } }
internal static void InvokeMouseButton(GlFwForm f, MouseButton btn, KeyActionKind action) { //TODO: implement detail methods switch (action) { default: throw new NotSupportedException(); case KeyActionKind.Press: f.OnMouseDown(btn, f._latestMouseX, f._latestMouseY); break; case KeyActionKind.Release: f.OnMouseUp(btn, f._latestMouseX, f._latestMouseY); break; case KeyActionKind.Repeat: break; } }
static bool GetGlfwForm(GlfwWindowPtr wnd, out GlFwForm found) { if (wnd.inner_ptr == s_latestGlWindowPtr) { found = s_latestForm; return(true); } else { if (s_existingForms.TryGetValue(wnd, out found)) { s_latestGlWindowPtr = wnd.inner_ptr; s_latestForm = found; return(true); } //reset s_latestGlWindowPtr = IntPtr.Zero; s_latestForm = null; return(false); } }
static bool GetGlfwForm(GlfwWindowPtr wnd, out GlFwForm found) { if (wnd.inner_ptr == latestGlWindowPtr) { found = latestForm; return true; } else { if (existingForms.TryGetValue(wnd, out found)) { latestGlWindowPtr = wnd.inner_ptr; latestForm = found; return true; } //reset latestGlWindowPtr = IntPtr.Zero; latestForm = null; return false; } }
internal static void InvokeKeyPress(GlFwForm f, char c) { //TODO: implement detail methods f.OnKeyPress(c); }
internal static void InvokeOnClosing(GlFwForm f, ref bool cancel) { f.OnClosing(ref cancel); }
internal static void InvokeOnRefresh(GlFwForm f) { //TODO: implement detail methods }
internal static void InvokeOnSizeChanged(GlFwForm f, int w, int h) { //on pos changed //TODO: implement detail methods f.OnSizeChanged(EventArgs.Empty); }
public static GlFwForm CreateGlfwForm(int w, int h, string title) { GlfwWindowPtr glWindowPtr = Glfw.CreateWindow(w, h, title, new GlfwMonitorPtr(),//default monitor new GlfwWindowPtr()); //default top window GlFwForm f = new GlFwForm(glWindowPtr, w, h); f.Text = title; //------------------- //setup events for glfw window Glfw.SetWindowCloseCallback(glWindowPtr, s_windowCloseCb); Glfw.SetWindowFocusCallback(glWindowPtr, s_windowFocusCb); Glfw.SetWindowIconifyCallback(glWindowPtr, s_windowIconifyCb); Glfw.SetWindowPosCallback(glWindowPtr, s_windowPosCb); Glfw.SetWindowRefreshCallback(glWindowPtr, s_windowRefreshCb); Glfw.SetWindowSizeCallback(glWindowPtr, s_windowSizeCb); Glfw.SetCursorPosCallback(glWindowPtr, s_windowCursorPosCb); Glfw.SetCursorEnterCallback(glWindowPtr, s_windowCursorEnterCb); Glfw.SetMouseButtonCallback(glWindowPtr, s_windowMouseButtonCb); Glfw.SetScrollCallback(glWindowPtr, s_scrollCb); Glfw.SetKeyCallback(glWindowPtr, s_windowKeyCb); Glfw.SetCharCallback(glWindowPtr, s_windowCharCb); ////------------------- existingForms.Add(glWindowPtr, f); exitingFormList.Add(f); return f; }
static GlfwApp() { s_windowCloseCb = (GlfwWindowPtr wnd) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { //user can cancel window close here here bool userCancel = false; found.InvokeOnClosing(ref userCancel); if (userCancel) { return; } //-------------------------------------- latestForm = null; latestGlWindowPtr = IntPtr.Zero; //user let this window close *** Glfw.SetWindowShouldClose(wnd, true); Glfw.DestroyWindow(wnd); //destroy this existingForms.Remove(wnd); exitingFormList.Remove(found); //-------------------------------------- } }; s_windowFocusCb = (GlfwWindowPtr wnd, bool focus) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.SetFocusState(focus); } }; s_windowIconifyCb = (GlfwWindowPtr wnd, bool iconify) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.SetIconifyState(iconify); } }; s_windowPosCb = (GlfwWindowPtr wnd, int x, int y) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeOnMove(x, y); } }; s_windowRefreshCb = (GlfwWindowPtr wnd) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeOnRefresh(); } }; s_windowSizeCb = (GlfwWindowPtr wnd, int width, int height) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeOnSizeChanged(width, height); } }; s_windowCursorPosCb = (GlfwWindowPtr wnd, double x, double y) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeCursorPos(x, y); } }; s_windowCursorEnterCb = (GlfwWindowPtr wnd, bool enter) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.SetCursorEnterState(enter); } }; s_windowMouseButtonCb = (GlfwWindowPtr wnd, MouseButton btn, KeyAction keyAction) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeMouseButton(btn, keyAction); } }; s_scrollCb = (GlfwWindowPtr wnd, double xoffset, double yoffset) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeOnScroll(xoffset, yoffset); } }; s_windowKeyCb = (GlfwWindowPtr wnd, Key key, int scanCode, KeyAction action, KeyModifiers mods) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeKey(key, scanCode, action, mods); } }; s_windowCharCb = (GlfwWindowPtr wnd, char ch) => { GlFwForm found; if (GetGlfwForm(wnd, out found)) { found.InvokeKeyPress(ch); } }; }
internal static void InvokeOnScroll(GlFwForm f, double xoffset, double yoffset) { //TODO: implement detail methods }
internal static void SetIconifyState(GlFwForm f, bool iconify) { f.OnIconify(iconify); }
internal static void InvokeOnMove(GlFwForm f, int x, int y) { //window moved //on pos changed //TODO: implement detail methods }
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); } }; }
public GlfwWindowWrapper(GlFwForm form) { _form = form; }