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

Method ContextMenu

src/openboardview/BoardView.cpp:415–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

413}
414
415void BoardView::ContextMenu(void) {
416 bool dummy = true;
417 static std::string note;
418 static std::string note_new;
419 static std::string pin, partn, net;
420 double tx, ty;
421
422 ImVec2 pos = ScreenToCoord(m_showContextMenuPos.x, m_showContextMenuPos.y);
423
424 /*
425 * So we don't have dozens of near-same-spot annotation points, we truncate
426 * back to integer levels, which still gives us 1-thou precision
427 */
428 tx = trunc(pos.x);
429 ty = trunc(pos.y);
430
431 /*
432 * Originally the dialog was to follow the cursor but it proved to be an overkill
433 * to try adjust things to keep it within the bounds of the window so as to not
434 * lose the buttons.
435 *
436 * Now it's kept at a fixed point.
437 */
438 ImGui::SetNextWindowPos(ImVec2(DPIF(50), DPIF(50)));
439 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
440 if (ImGui::BeginPopupModal("Annotations", &dummy, ImGuiWindowFlags_AlwaysAutoResize)) {
441
442 if (m_showContextMenu) {
443 note.clear();
444 m_showContextMenu = false;
445 for (auto &ann : m_annotations.annotations) ann.hovered = false;
446 }
447
448 /*
449 * For the new annotation possibility, we need to detect our various
450 * attributes that we can bind to, such as pin, net, part
451 */
452 {
453 /*
454 * we're going to go through all the possible items we can annotate at this position and offer them
455 */
456
457 float min_dist = m_pinDiameter * 1.0f;
458
459 /*
460 * find the closest pin, starting at no more than
461 * 1 radius away
462 */
463 min_dist *= min_dist; // all distance squared
464 Pin *selection = nullptr;
465 for (auto &pin : m_board->Pins()) {
466 if (BoardElementIsVisible(pin->component)) {
467 float dx = pin->position.x - pos.x;
468 float dy = pin->position.y - pos.y;
469 float dist = dx * dx + dy * dy;
470 if (dist < min_dist) {
471 selection = pin.get();
472 min_dist = dist;

Callers

nothing calls this directly

Calls 8

DPIFFunction · 0.85
DPIFunction · 0.85
GenerateListMethod · 0.80
AddMethod · 0.80
RemoveMethod · 0.80
clearMethod · 0.45
isPressedMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected