Last active
May 17, 2020 04:22
-
-
Save galloscript/1ca2c21ab2b8425bb6aa36c5e0cb4bae to your computer and use it in GitHub Desktop.
Frameless GLFW/ImGui window in MacOSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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