Skip to content

Commit

Permalink
Add throttle label, lookandfeel, detection leds
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoloGranieri committed May 17, 2018
1 parent 95180cd commit ae34918
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 93 deletions.
3 changes: 2 additions & 1 deletion Builds/VisualStudio2017/ReachCpp_App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<ClCompile Include="..\..\Source\LeapListener.cpp"/>
<ClCompile Include="..\..\Source\MainComponent.cpp"/>
<ClCompile Include="..\..\Source\Main.cpp"/>
<ClCompile Include="..\..\Source\ReachLookAndFeel.cpp"/>
<ClCompile Include="C:\JUCE\modules\juce_core\containers\juce_AbstractFifo.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -1393,7 +1394,7 @@
<ItemGroup>
<ClInclude Include="..\..\Source\LeapListener.h"/>
<ClInclude Include="..\..\Source\MainComponent.h"/>
<ClInclude Include="..\..\Source\Identifiers.h"/>
<ClInclude Include="..\..\Source\ReachLookAndFeel.h"/>
<ClInclude Include="C:\JUCE\modules\juce_core\containers\juce_AbstractFifo.h"/>
<ClInclude Include="C:\JUCE\modules\juce_core\containers\juce_Array.h"/>
<ClInclude Include="C:\JUCE\modules\juce_core\containers\juce_ArrayAllocationBase.h"/>
Expand Down
5 changes: 4 additions & 1 deletion Builds/VisualStudio2017/ReachCpp_App.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<ClCompile Include="..\..\Source\Main.cpp">
<Filter>ReachCpp\Source</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\ReachLookAndFeel.cpp">
<Filter>ReachCpp\Source</Filter>
</ClCompile>
<ClCompile Include="C:\JUCE\modules\juce_core\containers\juce_AbstractFifo.cpp">
<Filter>JUCE Modules\juce_core\containers</Filter>
</ClCompile>
Expand Down Expand Up @@ -1569,7 +1572,7 @@
<ClInclude Include="..\..\Source\MainComponent.h">
<Filter>ReachCpp\Source</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\Identifiers.h">
<ClInclude Include="..\..\Source\ReachLookAndFeel.h">
<Filter>ReachCpp\Source</Filter>
</ClInclude>
<ClInclude Include="C:\JUCE\modules\juce_core\containers\juce_AbstractFifo.h">
Expand Down
5 changes: 4 additions & 1 deletion ReachCpp.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
file="Source/MainComponent.cpp"/>
<FILE id="GGE5g8" name="MainComponent.h" compile="0" resource="0" file="Source/MainComponent.h"/>
<FILE id="NHEBTx" name="Main.cpp" compile="1" resource="0" file="Source/Main.cpp"/>
<FILE id="ksinBY" name="Identifiers.h" compile="0" resource="0" file="Source/Identifiers.h"/>
<FILE id="WpyIkB" name="ReachLookAndFeel.cpp" compile="1" resource="0"
file="Source/ReachLookAndFeel.cpp"/>
<FILE id="Thbeho" name="ReachLookAndFeel.h" compile="0" resource="0"
file="Source/ReachLookAndFeel.h"/>
</GROUP>
</MAINGROUP>
<EXPORTFORMATS>
Expand Down
61 changes: 0 additions & 61 deletions Source/Identifiers.h

This file was deleted.

1 change: 0 additions & 1 deletion Source/LeapListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "../JuceLibraryCode/JuceHeader.h"
#include "LeapListener.h"
#include "Identifiers.h"

using namespace Leap;

Expand Down
21 changes: 7 additions & 14 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"
#include "ReachLookAndFeel.h"

//==============================================================================
class ReachApplication : public JUCEApplication
Expand All @@ -26,28 +27,26 @@ class ReachApplication : public JUCEApplication
//==============================================================================
void initialise (const String& commandLine) override
{
LookAndFeel::setDefaultLookAndFeel(&LAF);

mainWindow = new MainWindow ("Reach");
}

void shutdown() override
{
mainWindow = nullptr; // deletes our window
mainWindow = nullptr;
}

//==============================================================================
void systemRequestedQuit() override
{
quit(); // allows app to close
quit();
}

void anotherInstanceStarted (const String& commandLine) override
{
// When another instance of the app is launched while this one is running,
// this method is invoked, and the commandLine parameter tells you what
// the other instance's command-line arguments were.
}

// Class implements desktop window that contains instance of MainContentComponent class
class MainWindow : public DocumentWindow
{
public:
Expand All @@ -69,21 +68,15 @@ class ReachApplication : public JUCEApplication
JUCEApplication::getInstance()->systemRequestedQuit();
}

/* Note: Be careful if you override any DocumentWindow methods - the base
class uses a lot of them, so by overriding you might break its functionality.
It's best to do all your work in your content component instead, but if
you really have to override any DocumentWindow methods, make sure your
subclass also calls the superclass's method.
*/

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};

private:
ScopedPointer<MainWindow> mainWindow;

ReachLookAndFeel LAF;
};

//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (ReachApplication)
57 changes: 43 additions & 14 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,23 @@ MainContentComponent::MainContentComponent()

addAndMakeVisible(ipAddress);
addAndMakeVisible(port);
addAndMakeVisible(throttleSpeed);

ipAddress.addListener(this);
port.addListener(this);
throttleSpeed.addListener(this);

ipAddress.setFont(Font(22.0f));
ipAddress.setJustificationType(Justification::centred);
ipAddress.setColour(Label::ColourIds::backgroundColourId, Colours::white);
ipAddress.setColour(Label::ColourIds::textColourId, Colours::black);
ipAddress.setColour(Label::ColourIds::textWhenEditingColourId, Colours::black);
ipAddress.setEditable(true);
ipAddress.setText(senderIP, dontSendNotification);

port.setFont(Font(22.0f));
port.setJustificationType(Justification::centred);
port.setColour(Label::ColourIds::backgroundColourId, Colours::white);
port.setColour(Label::ColourIds::textColourId, Colours::black);
port.setColour(Label::ColourIds::textWhenEditingColourId, Colours::black);
port.setEditable(true);
port.setText((String)senderPort, dontSendNotification);

/*DBG(", timestamp: " + (String)frame.timestamp());
DBG(", hands: " + (String)frame.hands().count());
DBG(", fingers: " + (String)frame.fingers().count());
DBG(", testdata: " + (String)frame.hands().leftmost().palmPosition().x);*/
throttleSpeed.setFont(Font(22.0f));
throttleSpeed.setEditable(true);
throttleSpeed.setText((String)throttleTime, dontSendNotification);
}

MainContentComponent::~MainContentComponent()
Expand All @@ -65,30 +58,58 @@ void MainContentComponent::paint (Graphics& g)
g.setColour (Colours::white);
g.drawText (currentSizeAsString, getLocalBounds(), Justification::centred, true);

g.setColour(Colours::red);
g.drawEllipse(getWidth() / 4, (getHeight() / 3) * 2, getWidth() / 100, getWidth() / 100, 5);
g.drawEllipse((getWidth() / 4) * 3, (getHeight() / 3) * 2, getWidth() / 100, getWidth() / 100, 5);

if (leftLed)
{
g.setColour(Colours::green);
g.drawEllipse(getWidth() / 4, (getHeight() / 3) * 2, getWidth() / 100, getWidth() / 100, 5);
}
if (rightLed)
{
g.setColour(Colours::green);
g.drawEllipse((getWidth() / 4) * 3, (getHeight() / 3) * 2, getWidth() / 100, getWidth() / 100, 5);
}

}

void MainContentComponent::resized()
{

auto area = getLocalBounds().reduced(proportionOfWidth(0.03), proportionOfHeight(0.03));
area.removeFromTop(proportionOfHeight(0.2));
auto labelarea = area.removeFromTop(proportionOfHeight(0.2));
auto labelarea = area.removeFromTop(proportionOfHeight(0.425));
auto labelarea1 = labelarea.removeFromBottom(proportionOfHeight(0.2));
auto spacearea = labelarea.removeFromBottom(proportionOfHeight(0.025));

ipAddress.setBounds(labelarea.removeFromLeft(proportionOfWidth(0.4)));
port.setBounds(labelarea.removeFromRight(proportionOfWidth(0.4)));

labelarea1.removeFromRight(proportionOfWidth(0.27));
throttleSpeed.setBounds(labelarea1.removeFromRight(proportionOfWidth(0.4)));
}

void MainContentComponent::timerCallback()
{
for (auto& hand : handList)

leftLed = false;
rightLed = false;

for (auto& hand : handList)
{
String handedness;

if (hand.isLeft())
{
leftLed = true;
handedness = "/Lefthand";
}

else
{
rightLed = true;
handedness = "/Righthand";
}

Expand All @@ -99,6 +120,8 @@ for (auto& hand : handList)
sender.send(m);

}

repaint();
}

void MainContentComponent::labelTextChanged(Label* labelThatHasChanged)
Expand All @@ -108,4 +131,10 @@ void MainContentComponent::labelTextChanged(Label* labelThatHasChanged)

if (labelThatHasChanged == &port)
senderPort = (int)labelThatHasChanged->getText().getIntValue();

if (labelThatHasChanged == &throttleSpeed)
{
throttleTime = (int)labelThatHasChanged->getText().getIntValue();
startTimer(throttleTime);
}
}
4 changes: 4 additions & 0 deletions Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MainContentComponent : public Component,
ScopedPointer<LeapListener> leapListener;
Leap::HandList handList;

bool leftLed = false;
bool rightLed = false;

//==============================================================================
OSCSender sender;

Expand All @@ -41,6 +44,7 @@ class MainContentComponent : public Component,
//==============================================================================
Label ipAddress;
Label port;
Label throttleSpeed;

//==============================================================================
String currentSizeAsString;
Expand Down
57 changes: 57 additions & 0 deletions Source/ReachLookAndFeel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
==============================================================================
ReachLookAndFeel.cpp
Created: 17 May 2018 12:44:57pm
Author: Niccolo'
==============================================================================
*/

#include "../JuceLibraryCode/JuceHeader.h"
#include "ReachLookAndFeel.h"

//==============================================================================
ReachLookAndFeel::ReachLookAndFeel()
{
setupColours();
}

ReachLookAndFeel::~ReachLookAndFeel()
{
}

void ReachLookAndFeel::setupColours()
{
setColour(Label::backgroundColourId, Colours::white);
setColour(Label::textColourId, Colours::black);
setColour(Label::textWhenEditingColourId, Colours::black);
}

void ReachLookAndFeel::drawLabel(Graphics& g, Label& label)
{
g.fillAll(label.findColour(Label::backgroundColourId));

if (!label.isBeingEdited())
{
auto alpha = label.isEnabled() ? 1.0f : 0.5f;
const Font font(getLabelFont(label));

g.setColour(label.findColour(Label::textColourId).withMultipliedAlpha(alpha));
g.setFont(font);

Rectangle<int> textArea(label.getBorderSize().subtractedFrom(label.getLocalBounds()));

g.drawFittedText(label.getText(), textArea, Justification::centred,
jmax(1, (int)(textArea.getHeight() / font.getHeight())),
label.getMinimumHorizontalScale());

g.setColour(label.findColour(Label::outlineColourId).withMultipliedAlpha(alpha));
}
else if (label.isEnabled())
{
g.setColour(label.findColour(Label::outlineColourId));
}

g.drawRect(label.getLocalBounds());
}
Loading

0 comments on commit ae34918

Please sign in to comment.