diff --git a/src/gui/components/config/GraphComponent.h b/src/gui/components/config/GraphComponent.h index 3743de7..cb46fda 100644 --- a/src/gui/components/config/GraphComponent.h +++ b/src/gui/components/config/GraphComponent.h @@ -468,7 +468,7 @@ void GraphComponent::mouseDown(const juce::MouseEvent& event) if (pointEditState == PointEditingState::None || pointEditState == PointEditingState::OverPoint) { - // create new + // create new if cursor is not pointing at a point if (pointIndex == -1) { const auto newPoint = transformPointToGraph(event.getPosition()); diff --git a/src/gui/components/config/TorqueMapComponent.cpp b/src/gui/components/config/TorqueMapComponent.cpp index dcfd3dd..f328e5d 100644 --- a/src/gui/components/config/TorqueMapComponent.cpp +++ b/src/gui/components/config/TorqueMapComponent.cpp @@ -32,6 +32,8 @@ TorqueMapComponent::TorqueMapComponent(juce::ValueTree torqueMapTree) // TODO: this should really use a juce::ChangeListener instead of listening // to the value tree directly torqueMap.state.addListener(this); + + generalTooltip = std::make_shared(this, 0); } //============================================================================== @@ -241,6 +243,8 @@ void TorqueMapComponent::mouseUp(const juce::MouseEvent& event) */ void TorqueMapComponent::mouseDrag(const juce::MouseEvent& event) { + int pointNo = getPointNearMouseEvent(event); + if (mouseEventInDeadzone(event) || movingDeadzone) { if (movingDeadzone) @@ -259,6 +263,10 @@ void TorqueMapComponent::mouseDrag(const juce::MouseEvent& event) showDeadzoneTooltip(); } + else if (pointNo != -1) + { + showPointTooltip(pointNo); + } else if (!shouldPreventPointEdit(event)) { GraphComponent::mouseDrag(event); @@ -273,14 +281,20 @@ void TorqueMapComponent::mouseDrag(const juce::MouseEvent& event) */ void TorqueMapComponent::mouseMove(const juce::MouseEvent& event) { + int pointNo = getPointNearMouseEvent(event); + if (mouseEventInDeadzone(event)) { setMouseCursor(juce::MouseCursor::LeftRightResizeCursor); showDeadzoneTooltip(); } - else if (!shouldPreventPointEdit(event)) + else if (pointNo != -1) + { + showPointTooltip(pointNo); + } + else { - hideDeadzoneTooltip(); + hideTooltip(); GraphComponent::mouseMove(event); } } @@ -318,10 +332,8 @@ bool TorqueMapComponent::shouldPreventPointEdit( */ void TorqueMapComponent::showDeadzoneTooltip() { - if (deadzoneTooltip == nullptr) - { - deadzoneTooltip = std::make_unique(this, 0); - } + // Make a shared pointer pointing to generalTooltip + auto deadzoneTooltip{generalTooltip}; auto deadzoneX = transformPointForPaint({getDeadzonePosition(), 0}).getX(); @@ -339,11 +351,34 @@ void TorqueMapComponent::showDeadzoneTooltip() } /** - * @brief Hide the deadzone tooltip + * @brief Shows the hovered point tooltip + */ +void TorqueMapComponent::showPointTooltip(int pointNo) +{ + // Make a shared pointer pointing to generalTooltip + auto pointTooltip{generalTooltip}; + + // Get point and cursor position in the graph + auto pointInGraph = getPoint(pointNo); + auto cursorLocation = juce::Desktop::getMousePosition(); + + // String denoting coordinates of points in the form of (x, y) + juce::String tipText + = juce::String::toDecimalStringWithSignificantFigures(pointInGraph.x, 2) + + "," + + juce::String::toDecimalStringWithSignificantFigures(pointInGraph.y, + 3); + + pointTooltip->displayTip(cursorLocation, tipText); + pointTooltip->setVisible(true); +} + +/** + * @brief Hide the general tooltip */ -void TorqueMapComponent::hideDeadzoneTooltip() +void TorqueMapComponent::hideTooltip() { - deadzoneTooltip.reset(); + generalTooltip->setVisible(false); } } // namespace gui \ No newline at end of file diff --git a/src/gui/components/config/TorqueMapComponent.h b/src/gui/components/config/TorqueMapComponent.h index ed4b5ce..860c085 100644 --- a/src/gui/components/config/TorqueMapComponent.h +++ b/src/gui/components/config/TorqueMapComponent.h @@ -62,10 +62,11 @@ class TorqueMapComponent : public GraphComponent, bool mouseEventInDeadzone(const juce::MouseEvent& event) const; bool shouldPreventPointEdit(const juce::MouseEvent& event) const; void showDeadzoneTooltip(); - void hideDeadzoneTooltip(); + void showPointTooltip(int pointNo); + void hideTooltip(); bool movingDeadzone = false; - std::unique_ptr deadzoneTooltip; + std::shared_ptr generalTooltip; //========================================================================== TorqueMap torqueMap;