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.

44 lines
1.2KB

  1. #pragma once
  2. #include "widget/Widget.hpp"
  3. namespace rack {
  4. namespace widget {
  5. /** Caches a widget's draw() result to a framebuffer so it is called less frequently.
  6. When `dirty` is true, its children will be re-rendered on the next call to step() override.
  7. Events are not passed to the underlying scene.
  8. */
  9. struct FramebufferWidget : Widget {
  10. /** Set this to true to re-render the children to the framebuffer the next time it is drawn */
  11. bool dirty = true;
  12. float oversample;
  13. NVGLUframebuffer *fb = NULL;
  14. /** Scale relative to the world */
  15. math::Vec scale;
  16. /** Offset in world coordinates */
  17. math::Vec offset;
  18. /** Pixel dimensions of the allocated framebuffer */
  19. math::Vec fbSize;
  20. /** Bounding box in world coordinates of where the framebuffer should be painted.
  21. Always has integer coordinates so that blitting framebuffers is pixel-perfect.
  22. */
  23. math::Rect fbBox;
  24. /** Framebuffer's scale relative to the world */
  25. math::Vec fbScale;
  26. /** Framebuffer's subpixel offset relative to fbBox in world coordinates */
  27. math::Vec fbOffset;
  28. FramebufferWidget();
  29. ~FramebufferWidget();
  30. void step() override;
  31. void draw(const DrawArgs &args) override;
  32. virtual void drawFramebuffer();
  33. int getImageHandle();
  34. };
  35. } // namespace widget
  36. } // namespace rack