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.

73 lines
2.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /** A simple implementation of the b2Draw class, used to draw a Box2D world.
  17. To use it, simply create an instance of this class in your paint() method,
  18. and call its render() method.
  19. @tags{Box2D}
  20. */
  21. class Box2DRenderer : public b2Draw
  22. {
  23. public:
  24. Box2DRenderer() noexcept;
  25. /** Renders the world.
  26. @param g the context to render into
  27. @param world the world to render
  28. @param box2DWorldLeft the left coordinate of the area of the world to be drawn
  29. @param box2DWorldTop the top coordinate of the area of the world to be drawn
  30. @param box2DWorldRight the right coordinate of the area of the world to be drawn
  31. @param box2DWorldBottom the bottom coordinate of the area of the world to be drawn
  32. @param targetArea the area within the target context onto which the source
  33. world rectangle should be mapped
  34. */
  35. void render (Graphics& g,
  36. b2World& world,
  37. float box2DWorldLeft, float box2DWorldTop,
  38. float box2DWorldRight, float box2DWorldBottom,
  39. const Rectangle<float>& targetArea);
  40. // b2Draw methods:
  41. void DrawPolygon (const b2Vec2*, int32, const b2Color&) override;
  42. void DrawSolidPolygon (const b2Vec2*, int32, const b2Color&) override;
  43. void DrawCircle (const b2Vec2& center, float32 radius, const b2Color&) override;
  44. void DrawSolidCircle (const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color&) override;
  45. void DrawSegment (const b2Vec2& p1, const b2Vec2& p2, const b2Color&) override;
  46. void DrawTransform (const b2Transform& xf) override;
  47. /** Converts a b2Color to a juce Colour. */
  48. virtual Colour getColour (const b2Color&) const;
  49. /** Returns the thickness to use for drawing outlines. */
  50. virtual float getLineThickness() const;
  51. protected:
  52. Graphics* graphics;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Box2DRenderer)
  54. };
  55. } // namespace juce