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.

42 lines
1.1KB

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