Skip to content

Instantly share code, notes, and snippets.

@galloscript
Last active May 17, 2020 04:22
Show Gist options
  • Save galloscript/1ca2c21ab2b8425bb6aa36c5e0cb4bae to your computer and use it in GitHub Desktop.
Save galloscript/1ca2c21ab2b8425bb6aa36c5e0cb4bae to your computer and use it in GitHub Desktop.
Frameless GLFW/ImGui window in MacOSX
//Get the native window
NSWindow* cocoaWindow = glfwGetCocoaWindow(glfwWindowPtr);
NSUInteger lWindowStyle = NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskMiniaturizable |
NSWindowStyleMaskResizable |
NSWindowStyleMaskUnifiedTitleAndToolbar |
NSWindowStyleMaskFullSizeContentView;
//Set the style mask
[cocoaWindow setStyleMask:lWindowStyle];
cocoaWindow.titlebarAppearsTransparent = YES;
cocoaWindow.movableByWindowBackground = YES; //Not really necessary
//I'm using the menu bar for dragging
//... after creating your menus inside ImGui::BeginMenuBar()
//Window dragging from ImGui
ImRect menuBarRect = ImRect(0, 0, WINDOW_WIDTH, MENU_BAR_HEIGHT);
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
ImGui::InvisibleButton("##windowdragging", menuBarRect.Max);
if(ImGui::IsItemActive() && ImGui::IsMouseDragging(0, 0.0f))
{
MPMainWindow::instance->addWindowDeltaPos(mouseDelta.x, mouseDelta.y);
//GLFW window dragging
int newPosX, newPosY;
glfwGetWindowPos(glfwWindowPtr, &newPosX, &newPosY);
glfwSetWindowPos(glfwWindowPtr, newPosX + mouseDelta.x, newPosY + mouseDelta.y);
//Update mouse previous position
ImGui::GetIO().MousePosPrev.x = ImGui::GetIO().MousePos.x - mouseDelta.x;
ImGui::GetIO().MousePosPrev.y = ImGui::GetIO().MousePos.y - mouseDelta.y;
}
//... ImGui::EndMenuBar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment