1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-01 03:10:06 +00:00

BLOCKS: Some code cleanup and modernisation in BlocksDrawing

This commit is contained in:
ed 2017-06-13 12:48:21 +01:00
parent 3d04a23c0f
commit 319ca33637
3 changed files with 36 additions and 37 deletions

View file

@ -58,8 +58,8 @@ class LightpadComponent : public Component
public:
LightpadComponent ()
{
for (int x = 0; x < 15; ++x)
for (int y = 0; y < 15; ++y)
for (auto x = 0; x < 15; ++x)
for (auto y = 0; y < 15; ++y)
addAndMakeVisible (leds.add (new LEDComponent()));
}
@ -81,13 +81,13 @@ public:
void resized() override
{
Rectangle<int> r = getLocalBounds().reduced (10);
auto r = getLocalBounds().reduced (10);
int circleWidth = r.getWidth() / 15;
int circleHeight = r.getHeight() / 15;
auto circleWidth = r.getWidth() / 15;
auto circleHeight = r.getHeight() / 15;
for (int x = 0; x < 15; ++x)
for (int y = 0; y < 15; ++y)
for (auto x = 0; x < 15; ++x)
for (auto y = 0; y < 15; ++y)
leds.getUnchecked ((x * 15) + y)->setBounds (r.getX() + (x * circleWidth),
r.getY() + (y * circleHeight),
circleWidth, circleHeight);
@ -95,9 +95,9 @@ public:
void mouseDown (const MouseEvent& e) override
{
for (int x = 0; x < 15; ++x)
for (auto x = 0; x < 15; ++x)
{
for (int y = 0; y < 15; ++y)
for (auto y = 0; y < 15; ++y)
{
if (leds.getUnchecked ((x * 15) + y)->getBounds().contains (e.position.toInt()))
{
@ -109,13 +109,13 @@ public:
void mouseDrag (const MouseEvent& e) override
{
for (int x = 0; x < 15; ++x)
for (auto x = 0; x < 15; ++x)
{
for (int y = 0; y < 15; ++y)
for (auto y = 0; y < 15; ++y)
{
if (leds.getUnchecked ((x * 15) + y)->getBounds().contains (e.position.toInt()))
{
const Time t = e.eventTime;
const auto t = e.eventTime;
if (lastLED == Point<int> (x, y) && t.toMilliseconds() - lastMouseEventTime.toMilliseconds() < 50)
return;

View file

@ -79,10 +79,10 @@ void MainComponent::resized()
{
infoLabel.centreWithSize (getWidth(), 100);
Rectangle<int> bounds = getLocalBounds().reduced (20);
auto bounds = getLocalBounds().reduced (20);
// top buttons
Rectangle<int> topButtonArea = bounds.removeFromTop (getHeight() / 20);
auto topButtonArea = bounds.removeFromTop (getHeight() / 20);
topButtonArea.removeFromLeft (20);
clearButton.setBounds (topButtonArea.removeFromLeft (80));
@ -94,15 +94,12 @@ void MainComponent::resized()
bounds.removeFromTop (20);
// brightness controls
Rectangle<int> brightnessControlBounds;
Desktop::DisplayOrientation orientation = Desktop::getInstance().getCurrentOrientation();
auto orientation = Desktop::getInstance().getCurrentOrientation();
if (orientation == Desktop::DisplayOrientation::upright
|| orientation == Desktop::DisplayOrientation::upsideDown)
{
brightnessControlBounds = bounds.removeFromBottom (getHeight() / 10);
auto brightnessControlBounds = bounds.removeFromBottom (getHeight() / 10);
brightnessSlider.setSliderStyle (Slider::SliderStyle::LinearHorizontal);
brightnessLED.setBounds (brightnessControlBounds.removeFromLeft (getHeight() / 10));
@ -110,7 +107,7 @@ void MainComponent::resized()
}
else
{
brightnessControlBounds = bounds.removeFromRight (getWidth() / 10);
auto brightnessControlBounds = bounds.removeFromRight (getWidth() / 10);
brightnessSlider.setSliderStyle (Slider::SliderStyle::LinearVertical);
brightnessLED.setBounds (brightnessControlBounds.removeFromTop (getWidth() / 10));
@ -118,7 +115,7 @@ void MainComponent::resized()
}
// lightpad component
int sideLength = jmin (bounds.getWidth() - 40, bounds.getHeight() - 40);
auto sideLength = jmin (bounds.getWidth() - 40, bounds.getHeight() - 40);
lightpadComponent.centreWithSize (sideLength, sideLength);
}
@ -132,7 +129,7 @@ void MainComponent::topologyChanged()
detachActiveBlock();
// Get the array of currently connected Block objects from the PhysicalTopologySource
Block::Array blocks = topologySource.getCurrentTopology().blocks;
auto blocks = topologySource.getCurrentTopology().blocks;
// Iterate over the array of Block objects
for (auto b : blocks)
@ -154,8 +151,8 @@ void MainComponent::topologyChanged()
if (auto grid = activeBlock->getLEDGrid())
{
// Work out scale factors to translate X and Y touches to LED indexes
scaleX = (float) (grid->getNumColumns()) / activeBlock->getWidth();
scaleY = (float) (grid->getNumRows()) / activeBlock->getHeight();
scaleX = (float) (grid->getNumColumns() - 1) / activeBlock->getWidth();
scaleY = (float) (grid->getNumRows() - 1) / activeBlock->getHeight();
setLEDProgram (*activeBlock);
}
@ -173,8 +170,8 @@ void MainComponent::topologyChanged()
void MainComponent::touchChanged (TouchSurface&, const TouchSurface::Touch& touch)
{
// Translate X and Y touch events to LED indexes
int xLed = roundToInt (touch.x * scaleX);
int yLed = roundToInt (touch.y * scaleY);
auto xLed = roundToInt (touch.x * scaleX);
auto yLed = roundToInt (touch.y * scaleY);
if (currentMode == colourPalette)
{
@ -183,8 +180,9 @@ void MainComponent::touchChanged (TouchSurface&, const TouchSurface::Touch& touc
if (auto* colourPaletteProgram = getPaletteProgram())
{
colourPaletteProgram->setGridFills (layout.numColumns, layout.numRows, layout.gridFillArray);
brightnessLED.setColour (layout.currentColour.withBrightness (layout.currentColour == Colours::black ? 0.0f
: static_cast<float> (brightnessSlider.getValue())));
brightnessLED.setColour (layout.currentColour
.withBrightness (layout.currentColour == Colours::black ? 0.0f
: static_cast<float> (brightnessSlider.getValue())));
}
}
}
@ -230,8 +228,9 @@ void MainComponent::buttonClicked (Button* b)
void MainComponent::sliderValueChanged (Slider* s)
{
if (s == &brightnessSlider)
brightnessLED.setColour (layout.currentColour.withBrightness (layout.currentColour == Colours::black ? 0.0f
: static_cast<float> (brightnessSlider.getValue())));
brightnessLED.setColour (layout.currentColour
.withBrightness (layout.currentColour == Colours::black ? 0.0f
: static_cast<float> (brightnessSlider.getValue())));
}
void MainComponent::timerCallback()

View file

@ -49,11 +49,11 @@ struct ColourGrid
{
gridFillArray.clear();
int counter = 0;
auto counter = 0;
for (int i = 0; i < numColumns; ++i)
for (auto i = 0; i < numColumns; ++i)
{
for (int j = 0; j < numRows; ++j)
for (auto j = 0; j < numRows; ++j)
{
DrumPadGridProgram::GridFill fill;
Colour colourToUse = colourArray.getUnchecked (counter);
@ -78,12 +78,12 @@ struct ColourGrid
*/
bool setActiveColourForTouch (int x, int y)
{
bool colourHasChanged = false;
auto colourHasChanged = false;
int xindex = x / 5;
int yindex = y / 5;
auto xindex = x / 5;
auto yindex = y / 5;
Colour newColour = colourArray.getUnchecked ((yindex * 3) + xindex);
auto newColour = colourArray.getUnchecked ((yindex * 3) + xindex);
if (currentColour != newColour)
{
currentColour = newColour;