renderer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* renderer.h - renderer
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_MAIN_RENDERER_H_39419D23_FC77_52F5_BAE0_212BEBF4F7AD
  18. #define STUDIO_MAIN_RENDERER_H_39419D23_FC77_52F5_BAE0_212BEBF4F7AD
  19. #include <thread>
  20. #include <mutex>
  21. #include <queue>
  22. #include <QObject>
  23. #include <generic/context_listener.h>
  24. namespace rainynite::core::renderers {
  25. class SvgRenderer;
  26. }
  27. namespace rainynite::studio {
  28. class Canvas;
  29. class Renderer : public QObject, public ContextListener {
  30. Q_OBJECT
  31. public:
  32. Renderer(Canvas* canvas_);
  33. virtual ~Renderer();
  34. void setup_renderer();
  35. void render_period(core::TimePeriod const& period);
  36. void set_fname(string fname_);
  37. void set_context(shared_ptr<EditorContext> context_) override;
  38. void set_output_scale(double factor);
  39. public Q_SLOTS:
  40. /// Render active period
  41. void render();
  42. /// Render current frame
  43. void render_frame();
  44. void stop_render();
  45. /// Redraw canvas using render result
  46. void redraw();
  47. void toggle_extra_style(bool checked);
  48. void toggle_auto_redraw(bool checked);
  49. Q_SIGNALS:
  50. void redraw_signal();
  51. private:
  52. void set_mainarea_image(string const& fname);
  53. void quit();
  54. private:
  55. Canvas* canvas;
  56. string fname;
  57. bool extra_style = true;
  58. bool auto_redraw = true;
  59. double output_scale = 1.0;
  60. std::thread render_thread;
  61. shared_ptr<core::renderers::SvgRenderer> renderer;
  62. std::queue<core::Context> renderer_queue;
  63. std::mutex renderer_mutex;
  64. bool renderer_quit = false;
  65. bool renderer_restart = false;
  66. };
  67. } // namespace rainynite::studio
  68. #endif