void _gfx_platform_window_set_size( GFX_PlatformWindow handle, unsigned int width, unsigned int height) { GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it && (it->flags & GFX_WIN32_RESIZABLE)) { RECT rect; rect.left = 0; rect.right = width; rect.top = 0; rect.bottom = height; /* Make sure the client area is the specified size */ AdjustWindowRectEx( &rect, GetWindowLong(handle, GWL_STYLE), FALSE, GetWindowLong(handle, GWL_EXSTYLE)); SetWindowPos( handle, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER); } }
GFX_PlatformMonitor _gfx_platform_window_get_monitor( GFX_PlatformWindow handle) { GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it) return it->monitor; return NULL; }
void _gfx_platform_window_hide( GFX_PlatformWindow handle) { GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it) it->flags |= GFX_WIN32_HIDDEN; ShowWindow(handle, SW_HIDE); }
void _gfx_platform_window_show( GFX_PlatformWindow handle) { GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it) it->flags &= ~GFX_WIN32_HIDDEN; ShowWindow(handle, SW_SHOW); }
void _gfx_platform_context_clear( GFX_PlatformWindow handle) { /* Get the window and destroy its context */ GFX_Win32_Window* window = _gfx_win32_get_window_from_handle(handle); if(window) { wglDeleteContext(window->context); window->context = NULL; } }
void _gfx_platform_window_free( GFX_PlatformWindow handle) { /* Make sure to undo fullscreen */ GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it->flags & GFX_WIN32_FULLSCREEN) _gfx_win32_leave_fullscreen(it->monitor); /* Destroy the context and window */ _gfx_platform_context_clear(handle); DestroyWindow(handle); /* Remove from vector */ gfx_vector_erase(&_gfx_win32.windows, it); }
void _gfx_platform_window_set_position( GFX_PlatformWindow handle, int x, int y) { /* Check if fullscreen */ GFX_Win32_Window* it = _gfx_win32_get_window_from_handle(handle); if(it && !(it->flags & GFX_WIN32_FULLSCREEN)) { /* Get window's monitor position */ int xM = 0; int yM = 0; if(it->monitor) { xM = it->monitor->x; yM = it->monitor->y; } RECT rect; rect.left = x + xM; rect.right = rect.left; rect.top = y + yM; rect.bottom = rect.top; /* Make sure the client area is the specified size */ AdjustWindowRectEx( &rect, GetWindowLong(handle, GWL_STYLE), FALSE, GetWindowLong(handle, GWL_EXSTYLE)); SetWindowPos( handle, NULL, rect.left, rect.top, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER); } }
int _gfx_platform_context_set_swap_interval( GFX_PlatformWindow handle, int num) { /* First get window */ GFX_Win32_Window* window = _gfx_win32_get_window_from_handle(handle); if(!window || !_gfx_win32.extensions.SwapIntervalEXT) return 0; /* Correct if adaptive vsync is not supported */ if(!_gfx_win32.extensions.EXT_swap_control_tear && num < 0) num = -num; /* Make current to set its interval */ _gfx_platform_context_make_current(handle, window->context); _gfx_win32.extensions.SwapIntervalEXT(num); return num; }
GFX_PlatformContext _gfx_platform_context_init( GFX_PlatformWindow handle, int major, int minor, GFX_PlatformContext share, int debug) { /* Get the window */ GFX_Win32_Window* window = _gfx_win32_get_window_from_handle(handle); if(!window) return NULL; /* Create context */ window->context = _gfx_win32_create_context( major, minor, handle, share, debug ); return window->context; }
static LRESULT CALLBACK _gfx_win32_window_proc( HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) { /* Get window */ GFX_PlatformWindow window = (GFX_PlatformWindow)handle; switch(msg) { /* Close button */ case WM_CLOSE : { _gfx_event_window_close(window); return 0; } /* Move */ case WM_MOVE : { int xS = 0; int yS = 0; GFX_Win32_Monitor* monitor = _gfx_platform_window_get_monitor(window); if(monitor) { xS = monitor->x; yS = monitor->y; } int x = (int)(short)LOWORD(lParam); int y = (int)(short)HIWORD(lParam); _gfx_event_window_move(window, x - xS, y - yS); return 0; } /* Resize */ case WM_SIZE : { _gfx_event_window_resize( window, LOWORD(lParam), HIWORD(lParam) ); return 0; } /* Focus */ case WM_SETFOCUS : { /* Enter fullscreen */ GFX_Win32_Window* internal = _gfx_win32_get_window_from_handle(handle); if(!internal) return 0; if( (internal->flags & GFX_WIN32_FULLSCREEN) && !(internal->flags & GFX_WIN32_HIDDEN)) { _gfx_win32_enter_fullscreen( internal->monitor, internal->mode ); } _gfx_event_window_focus(window); return 0; } /* Blur */ case WM_KILLFOCUS : { /* Leave fullscreen */ GFX_Win32_Window* internal = _gfx_win32_get_window_from_handle(handle); if(!internal) return 0; if(internal->flags & GFX_WIN32_FULLSCREEN) { _gfx_win32_leave_fullscreen(internal->monitor); if(!(internal->flags & GFX_WIN32_HIDDEN)) ShowWindow(handle, SW_MINIMIZE); } _gfx_event_window_blur(window); return 0; } /* Key press */ case WM_KEYDOWN : case WM_SYSKEYDOWN : { GFXKey key; if(wParam > GFX_WIN32_MAX_KEYCODE) key = GFX_KEY_UNKNOWN; else key = _gfx_win32_get_extended_key( _gfx_win32.keys[wParam], lParam); _gfx_event_key_press(window, key, _gfx_win32_get_key_state()); return 0; } /* Key release */ case WM_KEYUP : case WM_SYSKEYUP : { GFXKey key; if(wParam > GFX_WIN32_MAX_KEYCODE) key = GFX_KEY_UNKNOWN; else key = _gfx_win32_get_extended_key( _gfx_win32.keys[wParam], lParam); _gfx_event_key_release(window, key, _gfx_win32_get_key_state()); return 0; } /* Mouse move */ case WM_MOUSEMOVE : { int x = GET_X_LPARAM(lParam); int y = GET_Y_LPARAM(lParam); GFXKeyState state = _gfx_win32_get_key_state(); /* Check mouse enter event */ GFX_Win32_Window* internal = _gfx_win32_get_window_from_handle(handle); if(!internal) return 0; if(!(internal->flags & GFX_WIN32_MOUSEINSIDE)) { internal->flags |= GFX_WIN32_MOUSEINSIDE; _gfx_win32_track_mouse(handle); _gfx_event_mouse_enter(window, x, y, state); } else _gfx_event_mouse_move(window, x, y, state); return 0; } /* Mouse leave */ case WM_MOUSELEAVE : { GFX_Win32_Window* internal = _gfx_win32_get_window_from_handle(handle); if(!internal) return 0; internal->flags &= ~GFX_WIN32_MOUSEINSIDE; /* Untrack */ TRACKMOUSEEVENT track; ZeroMemory(&track, sizeof(TRACKMOUSEEVENT)); track.cbSize = sizeof(TRACKMOUSEEVENT); track.dwFlags = TME_CANCEL | TME_LEAVE; track.hwndTrack = handle; TrackMouseEvent(&track); /* Get mouse position */ POINT pnt; ZeroMemory(&pnt, sizeof(POINT)); GetCursorPos(&pnt); ScreenToClient(handle, &pnt); _gfx_event_mouse_leave( window, pnt.x, pnt.y, _gfx_win32_get_key_state() ); return 0; } /* Left mouse button */ case WM_LBUTTONDOWN : { _gfx_event_mouse_press(window, GFX_MOUSE_KEY_LEFT, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } case WM_LBUTTONUP : { _gfx_event_mouse_release(window, GFX_MOUSE_KEY_LEFT, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } /* Right mouse button */ case WM_RBUTTONDOWN : { _gfx_event_mouse_press(window, GFX_MOUSE_KEY_RIGHT, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } case WM_RBUTTONUP : { _gfx_event_mouse_release(window, GFX_MOUSE_KEY_RIGHT, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } /* Middle mouse button */ case WM_MBUTTONDOWN : { _gfx_event_mouse_press(window, GFX_MOUSE_KEY_MIDDLE, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } case WM_MBUTTONUP : { _gfx_event_mouse_release(window, GFX_MOUSE_KEY_MIDDLE, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } /* Vertical mouse wheel */ case WM_MOUSEWHEEL : { _gfx_event_mouse_wheel(window, 0, GET_WHEEL_DELTA_WPARAM(wParam), GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } /* Horizontal mouse wheel */ case WM_MOUSEHWHEEL : { _gfx_event_mouse_wheel(window, GET_WHEEL_DELTA_WPARAM(wParam), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), _gfx_win32_get_key_state() ); return 0; } } return DefWindowProc(handle, msg, wParam, lParam); }