From 9f5230de8e5cf844a989f686c23b2a87989794f4 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Mon, 26 Nov 2012 17:08:11 +0100 Subject: [PATCH] Win32 fixes. Now opens up a window and displays the statusbar --- ogl_editor/src/Editor.c | 3 +- ogl_editor/src/windows/Dialogs.c | 38 +++++ ogl_editor/src/windows/RocketWindow.c | 266 ++++++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+), 2 deletions(-) create mode 100644 ogl_editor/src/windows/Dialogs.c create mode 100644 ogl_editor/src/windows/RocketWindow.c diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index 9ebf739..c154ddd 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -156,7 +156,6 @@ void Editor_create() int id; Emgui_create("foo"); id = Emgui_loadFontBitmap(g_minecraftiaFont, g_minecraftiaFontSize, EMGUI_LOCATION_MEMORY, 32, 128, g_minecraftiaFontLayout); - memset(&s_editorData, 0, sizeof(s_editorData)); RemoteConnection_createListner(); @@ -335,7 +334,7 @@ static bool internalUpdate() refresh = TrackView_render(&s_editorData.trackViewInfo, &s_editorData.trackData); Emgui_end(); - return refresh; + return !!refresh; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ogl_editor/src/windows/Dialogs.c b/ogl_editor/src/windows/Dialogs.c new file mode 100644 index 0000000..73cba95 --- /dev/null +++ b/ogl_editor/src/windows/Dialogs.c @@ -0,0 +1,38 @@ +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int Dialog_open(char* path, int pathSize) +{ + OPENFILENAME ofn; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = path; + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = pathSize; + ofn.lpstrFilter = "All\0*.*\0Rocket\0*.Rocket\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + return GetOpenFileName(&ofn); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int Dialog_save(char* path, int pathSize) +{ + (void)path; + (void)pathSize; + return 0; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Dialog_showColorPicker(unsigned int* color) +{ + (void)color; +} \ No newline at end of file diff --git a/ogl_editor/src/windows/RocketWindow.c b/ogl_editor/src/windows/RocketWindow.c new file mode 100644 index 0000000..f978b27 --- /dev/null +++ b/ogl_editor/src/windows/RocketWindow.c @@ -0,0 +1,266 @@ +#include +#include +#include +#include "../Editor.h" +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static HWND s_window; +static HINSTANCE s_instance; +static HDC s_dc; +static HGLRC s_context; +static bool s_active; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void closeWindow() +{ + if (s_context) + { + wglMakeCurrent(0, 0); + wglDeleteContext(s_context); + s_context = 0; + } + + if (s_window) + { + ReleaseDC(s_window, s_dc); + DestroyWindow(s_window); + } + + UnregisterClass("GLRocket", s_instance); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void swapBuffers() +{ + SwapBuffers(s_dc); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +bool createWindow(const char* title, int width, int height) +{ + GLuint format; + WNDCLASS wc; + DWORD exStyle; + DWORD style; + RECT rect; + + static PIXELFORMATDESCRIPTOR pfd = + { + sizeof(PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, + 32, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 0, + 0, 0, 0, 0, + 16, + 0, + 0, + PFD_MAIN_PLANE, + 0, + 0, 0, 0 + }; + + rect.left = 0; + rect.right = width; + rect.top = 0; + rect.bottom= height; + + s_instance = GetModuleHandle(0); + memset(&wc, 0, sizeof(wc)); + + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC)WndProc; + wc.hInstance = s_instance; + wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.lpszClassName = "RocketEditor"; + + if (!RegisterClass(&wc)) + { + MessageBox(0, "Failed To Register Window Class", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return FALSE; + } + + exStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + style = WS_OVERLAPPEDWINDOW; + + AdjustWindowRectEx(&rect, style, FALSE, exStyle); + + // Create The Window + if (!(s_window = CreateWindowEx(exStyle, "RocketEditor", title, style | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, s_instance, NULL))) + { + closeWindow(); // Reset The Display + return FALSE; // Return FALSE + } + + if (!(s_dc = GetDC(s_window))) + { + closeWindow(); + return FALSE; + } + + if (!(format = ChoosePixelFormat(s_dc, &pfd))) + { + closeWindow(); + return FALSE; + } + + if (!SetPixelFormat(s_dc, format,&pfd)) + { + closeWindow(); + return FALSE; + } + + if (!(s_context = wglCreateContext(s_dc))) + { + closeWindow(); + return FALSE; + } + + if (!wglMakeCurrent(s_dc, s_context)) + { + closeWindow(); + return FALSE; + } + + ShowWindow(s_window, SW_SHOW); + SetForegroundWindow(s_window); + SetFocus(s_window); + + EMGFXBackend_create(); + EMGFXBackend_updateViewPort(width, height); + + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_ACTIVATE: + { + if (!HIWORD(wParam)) + s_active = true; + else + s_active = true; + + return 0; + } + + case WM_LBUTTONDOWN: + { + Emgui_setMouseLmb(1); + Editor_update(); + break; + } + + case WM_LBUTTONUP: + { + Emgui_setMouseLmb(0); + Editor_update(); + break; + } + + case WM_MOUSEMOVE: + { + const short pos_x = GET_X_LPARAM(lParam); + const short pos_y = GET_Y_LPARAM(lParam); + Emgui_setMousePos(pos_x, pos_y); + break; + } + + case WM_SYSCOMMAND: + { + switch (wParam) + { + // prevent screensaver and power saving + case SC_SCREENSAVE: + case SC_MONITORPOWER: + return 0; + } + break; + } + + case WM_CLOSE: + { + PostQuitMessage(0); + return 0; + } + + case WM_SIZE: + { + EMGFXBackend_updateViewPort(LOWORD(lParam), HIWORD(lParam)); + Editor_setWindowSize(LOWORD(lParam), HIWORD(lParam)); + return 0; + } + } + + return DefWindowProc(window, message, wParam, lParam); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void CALLBACK timedCallback(HWND hwnd, UINT id, UINT_PTR ptr, DWORD meh) +{ + Editor_timedUpdate(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmndLine, int show) +{ + MSG msg; + bool done = false; + + memset(&msg, 0, sizeof(MSG)); + + if (!createWindow("RocketEditor", 800, 600)) + return 0; + + EMGFXBackend_create(); + Editor_create(); + Editor_update(); + + // Update timed function every 16 ms + + SetTimer(s_window, 1, 16, timedCallback); + + while (!done) + { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) + { + done = true; + } + else + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + + closeWindow(); + return msg.wParam; +}