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.

97 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_DROPSHADOWER_JUCEHEADER__
  19. #define __JUCE_DROPSHADOWER_JUCEHEADER__
  20. #include "../components/juce_Component.h"
  21. //==============================================================================
  22. /**
  23. Adds a drop-shadow to a component.
  24. This object creates and manages a set of components which sit around a
  25. component, creating a gaussian shadow around it. The components will track
  26. the position of the component and if it's brought to the front they'll also
  27. follow this.
  28. For desktop windows you don't need to use this class directly - just
  29. set the Component::windowHasDropShadow flag when calling
  30. Component::addToDesktop(), and the system will create one of these if it's
  31. needed (which it obviously isn't on the Mac, for example).
  32. */
  33. class JUCE_API DropShadower : public ComponentListener
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates a DropShadower.
  38. @param alpha the opacity of the shadows, from 0 to 1.0
  39. @param xOffset the horizontal displacement of the shadow, in pixels
  40. @param yOffset the vertical displacement of the shadow, in pixels
  41. @param blurRadius the radius of the blur to use for creating the shadow
  42. */
  43. DropShadower (float alpha = 0.5f,
  44. int xOffset = 1,
  45. int yOffset = 5,
  46. float blurRadius = 10.0f);
  47. /** Destructor. */
  48. virtual ~DropShadower();
  49. /** Attaches the DropShadower to the component you want to shadow. */
  50. void setOwner (Component* componentToFollow);
  51. //==============================================================================
  52. /** @internal */
  53. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  54. /** @internal */
  55. void componentBroughtToFront (Component& component);
  56. /** @internal */
  57. void componentParentHierarchyChanged (Component& component);
  58. /** @internal */
  59. void componentVisibilityChanged (Component& component);
  60. private:
  61. //==============================================================================
  62. Component* owner;
  63. OwnedArray<Component> shadowWindows;
  64. Image shadowImageSections[12];
  65. const int xOffset, yOffset;
  66. const float alpha, blurRadius;
  67. bool reentrant;
  68. void updateShadows();
  69. void setShadowImage (const Image& src, int num, int w, int h, int sx, int sy);
  70. void bringShadowWindowsToFront();
  71. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DropShadower);
  72. };
  73. #endif // __JUCE_DROPSHADOWER_JUCEHEADER__