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.

78 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_BOX2DRENDERER_H_INCLUDED
  18. #define JUCE_BOX2DRENDERER_H_INCLUDED
  19. //==============================================================================
  20. /** A simple implementation of the b2Draw class, used to draw a Box2D world.
  21. To use it, simply create an instance of this class in your paint() method,
  22. and call its render() method.
  23. */
  24. class Box2DRenderer : public b2Draw
  25. {
  26. public:
  27. Box2DRenderer() noexcept;
  28. /** Renders the world.
  29. @param g the context to render into
  30. @param world the world to render
  31. @param box2DWorldLeft the left coordinate of the area of the world to be drawn
  32. @param box2DWorldTop the top coordinate of the area of the world to be drawn
  33. @param box2DWorldRight the right coordinate of the area of the world to be drawn
  34. @param box2DWorldBottom the bottom coordinate of the area of the world to be drawn
  35. @param targetArea the area within the target context onto which the source
  36. world rectangle should be mapped
  37. */
  38. void render (Graphics& g,
  39. b2World& world,
  40. float box2DWorldLeft, float box2DWorldTop,
  41. float box2DWorldRight, float box2DWorldBottom,
  42. const Rectangle<float>& targetArea);
  43. // b2Draw methods:
  44. void DrawPolygon (const b2Vec2*, int32, const b2Color&) override;
  45. void DrawSolidPolygon (const b2Vec2*, int32, const b2Color&) override;
  46. void DrawCircle (const b2Vec2& center, float32 radius, const b2Color&) override;
  47. void DrawSolidCircle (const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color&) override;
  48. void DrawSegment (const b2Vec2& p1, const b2Vec2& p2, const b2Color&) override;
  49. void DrawTransform (const b2Transform& xf) override;
  50. /** Converts a b2Color to a juce Colour. */
  51. virtual Colour getColour (const b2Color&) const;
  52. /** Returns the thickness to use for drawing outlines. */
  53. virtual float getLineThickness() const;
  54. protected:
  55. Graphics* graphics;
  56. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Box2DRenderer)
  57. };
  58. #endif // JUCE_BOX2DRENDERER_H_INCLUDED