The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9KB

  1. /*
  2. ==============================================================================
  3. ToggleLightGridComponent.h
  4. Created: 11 Feb 2015 9:57:34am
  5. Author: Felix Faire
  6. ==============================================================================
  7. */
  8. #pragma once
  9. #include "ToggleLightComponent.h"
  10. /**
  11. This is the parent class that holds multiple ToggleLightComponents in a grid.
  12. */
  13. class ToggleLightGridComponent : public Component
  14. {
  15. public:
  16. ToggleLightGridComponent (String name = "grid")
  17. : Component (name)
  18. {
  19. // Adds the child light components and makes them visible
  20. // within this component.
  21. // (they currently rely on having a default constructor
  22. // so they dont have to be individually initialised)
  23. for (int i = 0; i < numX * numY; ++i)
  24. addAndMakeVisible (toggleLights[i]);
  25. }
  26. void resized() override
  27. {
  28. // This creates a grid of rectangles to use as the bounds
  29. // for all of our lights. The grid is defined with the
  30. // width and height of this component.
  31. int stepX = getWidth() / numX;
  32. int stepY = getHeight() / numY;
  33. for (int x = 0; x < numX; ++x)
  34. {
  35. for (int y = 0; y < numY; ++y)
  36. {
  37. // creates the rectangle (x, y, width, height)
  38. Rectangle<int> elementBounds (x * stepX, y * stepY, stepX, stepY);
  39. // set the size and position of the Toggle light to this rectangle.
  40. toggleLights[x + numX * y].setBounds (elementBounds);
  41. }
  42. }
  43. }
  44. private:
  45. // member variables for the Component
  46. static const int numX = 20;
  47. static const int numY = 20;
  48. ToggleLightComponent toggleLights [numX * numY];
  49. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleLightGridComponent)
  50. };