From 9cc9bb5bf379e7bbdc0baf692859e3bff2318975 Mon Sep 17 00:00:00 2001 From: Konrad Trubecki Date: Tue, 21 Mar 2023 18:30:51 +0000 Subject: [PATCH 1/2] added axis --- src/gui/components/config/GraphComponent.h | 86 ++++++++++++++++++++-- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/src/gui/components/config/GraphComponent.h b/src/gui/components/config/GraphComponent.h index ddc196b..610e991 100644 --- a/src/gui/components/config/GraphComponent.h +++ b/src/gui/components/config/GraphComponent.h @@ -53,6 +53,8 @@ class GraphComponent : public juce::Component, public juce::KeyListener //========================================================================== void paint(juce::Graphics& g) override; + void paintXAxis(Graphics& g); + void paintYAxis(Graphics& g); void resized() override; void mouseDown(const juce::MouseEvent& event) override; @@ -235,9 +237,11 @@ ValueType GraphComponent::getMaxY() const template void GraphComponent::paint(juce::Graphics& g) { + paintBorder(g); paintTicks(g); - + paintXAxis(g); + paintYAxis(g); if (interpolator) { paintCurve(g); @@ -246,6 +250,73 @@ void GraphComponent::paint(juce::Graphics& g) paintPoints(g); } +template +void GraphComponent::paintXAxis(Graphics& g) +{ + g.setFont(Font(15.0f)); + g.setColour(Colours::white); + + int xAxisStart = 0; + int xAxisEnd = getWidth(); + int xAxisLength = xAxisEnd - xAxisStart; + int xAxisMid = xAxisStart + (xAxisLength / 2); + int xAxisBottom = getHeight(); + int xAxisLabelY = xAxisBottom; + + g.drawLine(xAxisStart, xAxisBottom, xAxisEnd, xAxisBottom, 2.0f); + g.drawText("accelerator pressure", + xAxisLabelY - 20, + xAxisMid, + g.getCurrentFont().getStringWidth("accelerator pressure"), + 20, + Justification::centred, + true); +} + +template +void GraphComponent::paintYAxis(Graphics& g) +{ + g.setFont(Font(15.0f)); + g.setColour(Colours::white); + + int yAxisStart = 0; + int yAxisLength = getHeight(); + int xAxisLength = getWidth(); + + g.drawLine(yAxisStart, yAxisStart, yAxisStart, yAxisLength, 2.0f); + + // Draw intervals on the y-axis + for (int i = 10; i <= 100; i += 10) + { + int intervalStart = yAxisLength - (i * yAxisLength / 100); + g.drawLine(xAxisLength - 10, + intervalStart, + xAxisLength, + intervalStart, + 2.0f); + + // Draw the interval label + g.setFont(Font(15.0f)); + g.setColour(Colours::white); + g.drawText(String(i) + "%", + xAxisLength - 40, + intervalStart, + 50, + 20, + Justification::centred, + true); + + // Draw torque label vertically + g.drawText("t\nor\nq\nue", + yAxisStart, + yAxisStart, + g.getCurrentFont().getStringWidth("torque"), + yAxisLength, + Justification::centred, + true); + } +} + /** * @brief Paints the graph border * @@ -598,14 +669,17 @@ bool GraphComponent::keyPressed( { if (key.isKeyCode(juce::KeyPress::backspaceKey)) { - pointEditState = (pointEditState == PointEditingState::Delete) - ? PointEditingState::None - : PointEditingState::Delete; - + pointEditState = PointEditingState::Delete; + updateCursor(); + return true; + } + else if (key.isKeyCode(juce::KeyPress::escapeKey) + && pointEditState == PointEditingState::Delete) + { + pointEditState = PointEditingState::None; updateCursor(); return true; } - return false; } From 76d90451b3a48bfd2b441a42e8e1d482aa091cf1 Mon Sep 17 00:00:00 2001 From: George Peppard Date: Tue, 7 Nov 2023 14:37:34 +0000 Subject: [PATCH 2/2] refactor: revert change for other PR --- src/gui/components/config/GraphComponent.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/gui/components/config/GraphComponent.h b/src/gui/components/config/GraphComponent.h index 610e991..d9a690c 100644 --- a/src/gui/components/config/GraphComponent.h +++ b/src/gui/components/config/GraphComponent.h @@ -667,19 +667,14 @@ bool GraphComponent::keyPressed( const juce::KeyPress& key, juce::Component* /*originatingComponent*/) { - if (key.isKeyCode(juce::KeyPress::backspaceKey)) - { - pointEditState = PointEditingState::Delete; - updateCursor(); - return true; - } - else if (key.isKeyCode(juce::KeyPress::escapeKey) - && pointEditState == PointEditingState::Delete) - { - pointEditState = PointEditingState::None; + if (key.isKeyCode(juce::KeyPress::backspaceKey)) { + pointEditState = (pointEditState == PointEditingState::Delete) + ? PointEditingState::None + : PointEditingState::Delete; updateCursor(); return true; } + return false; }