| 228 | } |
| 229 | |
| 230 | void ImGuiMenu::startFrame() |
| 231 | { |
| 232 | MR_TIMER; |
| 233 | if ( pollEventsInPreDraw ) |
| 234 | { |
| 235 | glfwPollEvents(); |
| 236 | } |
| 237 | |
| 238 | // clear ordered keys |
| 239 | getOrderedKeys() = {}; |
| 240 | |
| 241 | if ( viewer->isGLInitialized() ) |
| 242 | { |
| 243 | ImGui_ImplOpenGL3_NewFrame(); |
| 244 | #ifdef __EMSCRIPTEN__ |
| 245 | ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; |
| 246 | #endif |
| 247 | |
| 248 | ImGui_ImplGlfw_NewFrame(); |
| 249 | |
| 250 | #ifdef __EMSCRIPTEN__ |
| 251 | ImGui::GetIO().ConfigFlags &= ~( ImGuiConfigFlags_NoMouseCursorChange ); |
| 252 | #pragma clang diagnostic push |
| 253 | #pragma clang diagnostic ignored "-Wdollar-in-identifier-extension" |
| 254 | EM_ASM( customSetCursor( $0 ), int( ImGui::GetMouseCursor() ) ); |
| 255 | #pragma clang diagnostic pop |
| 256 | #endif |
| 257 | |
| 258 | if ( viewer->hasScaledFramebuffer() ) |
| 259 | { |
| 260 | // we want ImGui to think it is common scaling in case of retina monitor |
| 261 | ImGui::GetIO().DisplaySize = ImVec2( float( viewer->framebufferSize.x ), float( viewer->framebufferSize.y ) ); |
| 262 | ImGui::GetIO().DisplayFramebufferScale = ImVec2( 1, 1 ); |
| 263 | |
| 264 | // ImGui takes mouse position from glfw each frame, but we scale mouse events, so need to update it |
| 265 | if ( context_ ) |
| 266 | { |
| 267 | ImGuiInputEvent e; |
| 268 | auto curPos = Vector2f( viewer->mouseController().getMousePos() ); |
| 269 | if ( !context_->InputEventsQueue.empty() && context_->InputEventsQueue.back().Type == ImGuiInputEventType_MousePos ) |
| 270 | { |
| 271 | context_->InputEventsQueue.back().MousePos.PosX = curPos.x; |
| 272 | context_->InputEventsQueue.back().MousePos.PosY = curPos.y; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | // needed for dear ImGui |
| 280 | // should be window size |
| 281 | ImGui::GetIO().DisplaySize = ImVec2( float( viewer->framebufferSize.x ), float( viewer->framebufferSize.y ) ); |
| 282 | } |
| 283 | auto& style = ImGui::GetStyle(); |
| 284 | if ( !needModalBgChange_ ) |
| 285 | style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4( 0.0f, 0.0f, 0.0f, 0.8f ); |
| 286 | else |
| 287 | { |
no test coverage detected