MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / HandleInput

Method HandleInput

src/openboardview/BoardView.cpp:1375–1654  ·  view source on GitHub ↗

* This HandleInput() function isn't actually a generic input handler * it's meant specifically for the board draw surface only. The inputs * for menus is handled within the menu generation itself. */

Source from the content-addressed store, hash-verified

1373 * for menus is handled within the menu generation itself.
1374 */
1375void BoardView::HandleInput() {
1376 if (!m_board || (!m_file)) return;
1377
1378 const ImGuiIO &io = ImGui::GetIO();
1379
1380 if (ImGui::IsWindowHovered()) {
1381 if (!ImGui::IsWindowFocused()) {
1382 // Set focus on boardview area hover to apply our key bindings instead of the currently active ImGui's keyboard navigation
1383 // Using imgui_internal's FocusWindow with UnlessBelowModal instead of SetWindowFocus
1384 // Otherwise PopupModal get closed right after opening when boardview area is hovered
1385 // https://github.com/ocornut/imgui/issues/3595
1386 // Warning: wouldn't work with regular Popup but we use only PopupModal
1387 ImGui::FocusWindow(nullptr, ImGuiFocusRequestFlags_UnlessBelowModal);
1388 }
1389
1390 if (ImGui::IsMouseDragging(0)) {
1391 if ((m_dragging_token == 0) && (io.MouseClickedPos[0].x < m_board_surface.x)) m_dragging_token = 1; // own it.
1392 if (m_dragging_token == 1) {
1393 // if ((io.MouseClickedPos[0].x < m_info_surface.x)) {
1394 ImVec2 delta = ImGui::GetMouseDragDelta();
1395 if ((abs(delta.x) > 500) || (abs(delta.y) > 500)) {
1396 delta.x = 0;
1397 delta.y = 0;
1398 } // If the delta values are crazy just drop them (happens when panning
1399 // off screen). 500 arbritary chosen
1400 ImGui::ResetMouseDragDelta();
1401 ImVec2 td = ScreenToCoord(delta.x, delta.y, 0);
1402 m_dx += td.x;
1403 m_dy += td.y;
1404 m_draggingLastFrame = true;
1405 m_needsRedraw = true;
1406 }
1407 } else if (m_dragging_token >= 0) {
1408 m_dragging_token = 0;
1409
1410 if (m_lastFileOpenWasInvalid == false) {
1411 // Conext menu
1412 if (!m_lastFileOpenWasInvalid && m_file && m_board && ImGui::IsMouseClicked(1)) {
1413 if (config.showAnnotations) {
1414 // Build context menu here, for annotations and inspection
1415 //
1416 ImVec2 spos = ImGui::GetMousePos();
1417 if (AnnotationIsHovered()) m_annotation_clicked_id = m_annotation_last_hovered;
1418
1419 m_annotationedit_retain = false;
1420 m_showContextMenu = true;
1421 m_showContextMenuPos = spos;
1422 m_needsRedraw = true;
1423 if (debug) fprintf(stderr, "context click request at (%f %f)\n", spos.x, spos.y);
1424 }
1425
1426 // Flip the board with the middle click
1427 } else if (!m_lastFileOpenWasInvalid && m_file && m_board && ImGui::IsMouseReleased(2)) {
1428 FlipBoard();
1429
1430 // Else, click to select pin
1431 } else if (!m_lastFileOpenWasInvalid && m_file && m_board && ImGui::IsMouseReleased(0) && !m_draggingLastFrame) {
1432 ImVec2 spos = ImGui::GetMousePos();

Callers

nothing calls this directly

Calls 6

containsFunction · 0.85
removeFunction · 0.85
DPIFunction · 0.85
WriteBoolMethod · 0.80
clearMethod · 0.45
isPressedMethod · 0.45

Tested by

no test coverage detected