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.

68 lines
2.0KB

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