From 429acd3da4626b20c9f28ae28e6ef6b0711eaa1f Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Mon, 18 May 2020 00:39:30 +0200
Subject: [PATCH] position as label

---
 Source/PluginEditor.cpp | 19 +++++++++++++------
 Source/PluginEditor.h   | 19 +++++++++++++++----
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp
index 220bce3..03bae6e 100644
--- a/Source/PluginEditor.cpp
+++ b/Source/PluginEditor.cpp
@@ -15,14 +15,21 @@ Test2AudioProcessorEditor::Test2AudioProcessorEditor(Test2AudioProcessor &p)
 {
   // Make sure that before the constructor has finished, you've set the
   // editor's size to whatever you need it to be.
-
-  // m_flogger = std::unique_ptr<juce::FileLogger>(juce::FileLogger::createDateStampedLogger("foo", "mylog", ".txt", "Welcome to plugin"));
+  addAndMakeVisible(positionLabel);
+  positionLabel.setText("Text input:", juce::dontSendNotification);
+  // positionLabel.attachToComponent(&inputText, true);
+  positionLabel.setColour(juce::Label::textColourId, juce::Colours::orange);
+  positionLabel.setJustificationType(juce::Justification::right);
+  startTimerHz(60);
   setResizable(true, true);
+  setResizeLimits(400, 300, 1024, 1024);
+
   setSize(400, 300);
 }
 
 Test2AudioProcessorEditor::~Test2AudioProcessorEditor()
 {
+  stopTimer();
 }
 
 //==============================================================================
@@ -33,10 +40,9 @@ void Test2AudioProcessorEditor::paint(juce::Graphics &g)
 
   g.setColour(juce::Colours::white);
   g.setFont(15.0f);
-  g.drawFittedText("Hello Per 10 !", getLocalBounds(), juce::Justification::centred, 1);
-  g.drawFittedText("Hello Per 10 !", getLocalBounds(), juce::Justification::centred, 1);
-  if (processor.m_flogger)
-    processor.m_flogger->logMessage("paint called");
+  g.drawFittedText("1) Position : " + std::to_string(processor.position), getLocalBounds(), juce::Justification::centred, 1);
+  // if (processor.m_flogger)
+  //   processor.m_flogger->logMessage("paint called");
 }
 
 void Test2AudioProcessorEditor::resized()
@@ -45,6 +51,7 @@ void Test2AudioProcessorEditor::resized()
   // subcomponents in your editor..
 
   auto bounds = getLocalBounds();
+  positionLabel.setBounds(bounds.removeFromBottom(30).withSizeKeepingCentre(50, 24));
 
   if (processor.m_flogger)
     processor.m_flogger->logMessage(bounds.toString());
diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h
index ce210d1..271c020 100644
--- a/Source/PluginEditor.h
+++ b/Source/PluginEditor.h
@@ -14,7 +14,7 @@
 //==============================================================================
 /**
 */
-class Test2AudioProcessorEditor : public juce::AudioProcessorEditor
+class Test2AudioProcessorEditor : public juce::AudioProcessorEditor, private juce::Timer
 {
 public:
   Test2AudioProcessorEditor(Test2AudioProcessor &);
@@ -28,8 +28,19 @@ private:
   // This reference is provided as a quick way for your editor to
   // access the processor object that created it.
   Test2AudioProcessor &processor;
-
-  std::unique_ptr<juce::FileLogger> m_flogger;
-
+  // is this the way
+  juce::Label positionLabel; // = juce::Label("Position", "Position : 0");
+  // or something like
+  //juce::Label positionLabel = {"Position"};
+
+  // should it be here or in the cpp file
+  // do we even need a cpp file, seems easier to do everything in the
+  // class declaration as we do not need to repeat the type name for each
+  // member function.
+  void timerCallback() override
+  {
+    positionLabel.setText("Pos : " + std::to_string(processor.position), juce::dontSendNotification);
+    repaint();
+  }
   JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Test2AudioProcessorEditor)
 };
-- 
GitLab