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.

45 lines
1.3KB

  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().
  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. bool bypass = false;
  13. float oversample = 1.0;
  14. NVGLUframebuffer* fb = NULL;
  15. /** Scale relative to the world */
  16. math::Vec scale;
  17. /** Offset in world coordinates */
  18. math::Vec offset;
  19. /** Pixel dimensions of the allocated framebuffer */
  20. math::Vec fbSize;
  21. /** Bounding box in world coordinates of where the framebuffer should be painted.
  22. Always has integer coordinates so that blitting framebuffers is pixel-perfect.
  23. */
  24. math::Rect fbBox;
  25. /** Framebuffer's scale relative to the world */
  26. math::Vec fbScale;
  27. /** Framebuffer's subpixel offset relative to fbBox in world coordinates */
  28. math::Vec fbOffset;
  29. FramebufferWidget();
  30. ~FramebufferWidget();
  31. void step() override;
  32. void draw(const DrawArgs& args) override;
  33. virtual void drawFramebuffer();
  34. int getImageHandle();
  35. };
  36. } // namespace widget
  37. } // namespace rack