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.

79 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "ToggleLightComponent.h"
  21. /**
  22. This is the parent class that holds multiple ToggleLightComponents in a grid.
  23. */
  24. class ToggleLightGridComponent : public Component
  25. {
  26. public:
  27. ToggleLightGridComponent (String name = "grid")
  28. : Component (name)
  29. {
  30. // Adds the child light components and makes them visible
  31. // within this component.
  32. // (they currently rely on having a default constructor
  33. // so they dont have to be individually initialised)
  34. for (int i = 0; i < numX * numY; ++i)
  35. addAndMakeVisible (toggleLights[i]);
  36. }
  37. void resized() override
  38. {
  39. // This creates a grid of rectangles to use as the bounds
  40. // for all of our lights. The grid is defined with the
  41. // width and height of this component.
  42. int stepX = getWidth() / numX;
  43. int stepY = getHeight() / numY;
  44. for (int x = 0; x < numX; ++x)
  45. {
  46. for (int y = 0; y < numY; ++y)
  47. {
  48. // creates the rectangle (x, y, width, height)
  49. Rectangle<int> elementBounds (x * stepX, y * stepY, stepX, stepY);
  50. // set the size and position of the Toggle light to this rectangle.
  51. toggleLights[x + numX * y].setBounds (elementBounds);
  52. }
  53. }
  54. }
  55. private:
  56. // member variables for the Component
  57. static const int numX = 20;
  58. static const int numY = 20;
  59. ToggleLightComponent toggleLights [numX * numY];
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleLightGridComponent)
  61. };