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. /** Pixel dimensions of the allocated framebuffer */
  15. math::Vec fbSize;
  16. /** Bounding box in world coordinates of where the framebuffer should be painted
  17. Always has integer coordinates so that blitting framebuffers is pixel-perfect.
  18. */
  19. math::Rect fbBox;
  20. /** Local scale relative to the world scale */
  21. math::Vec fbScale;
  22. /** Subpixel offset of fbBox in world coordinates */
  23. math::Vec fbOffset;
  24. FramebufferWidget();
  25. ~FramebufferWidget();
  26. void draw(const DrawContext &ctx) override;
  27. virtual void drawFramebuffer();
  28. int getImageHandle();
  29. void onZoom(const event::Zoom &e) override {
  30. dirty = true;
  31. Widget::onZoom(e);
  32. }
  33. };
  34. } // namespace widget
  35. } // namespace rack