MandelWidget.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include <QGLWidget>
  3. #include <qopengl.h>
  4. #include <qopenglfunctions.h>
  5. #include <qopenglcontext.h>
  6. #include <qscrollarea.h>
  7. #include <qlabel.h>
  8. #include <qevent.h>
  9. #include <qrubberband.h>
  10. #include "Bitmap.h"
  11. #include <Mandel.h>
  12. #include <future>
  13. #include <atomic>
  14. class MandelWidget;
  15. class Texture
  16. {
  17. GLuint id;
  18. QOpenGLContext* context;
  19. public:
  20. Texture(const Bitmap<RGBColor>& pict);
  21. Texture(const Bitmap<RGBColor>& pict, QOpenGLContext* context);
  22. ~Texture(void);
  23. Texture(const Texture& other) = delete;
  24. Texture& operator=(const Texture& other) = delete;
  25. Texture(Texture&& other) = default;
  26. Texture& operator=(Texture&& other) = default;
  27. void bind(void) const;
  28. void drawRect(float x, float y, float width, float height);
  29. };
  30. class MandelView : public QObject
  31. {
  32. Q_OBJECT
  33. private:
  34. std::future<void> calc;
  35. std::atomic<mnd::MandelInfo> toCalc;
  36. std::atomic_bool hasToCalc;
  37. mnd::Generator* generator;
  38. MandelWidget* mWidget;
  39. QOpenGLContext* context;
  40. public:
  41. MandelView(mnd::Generator& generator, MandelWidget* mWidget);
  42. void setGenerator(mnd::Generator &value);
  43. public slots:
  44. void adaptViewport(const mnd::MandelInfo vp);
  45. signals:
  46. void updated(Texture* bitmap);
  47. };
  48. class MandelWidget : public QGLWidget
  49. {
  50. Q_OBJECT
  51. private:
  52. //QScrollArea qsa;
  53. //QLabel ql;
  54. mnd::MandelContext& mndContext;
  55. bool initialized = false;
  56. bool rubberbandDragging = false;
  57. QRectF rubberband;
  58. std::unique_ptr<Texture> tex;
  59. mnd::MandelViewport viewport;
  60. MandelView mv;
  61. public:
  62. MandelWidget(mnd::MandelContext& ctxt, QWidget* parent = nullptr);
  63. ~MandelWidget(void) override;
  64. /*inline MandelWidget(const MandelWidget& other) :
  65. mndContext{ other.mndContext },
  66. mv{ other.mndContext }
  67. {
  68. }*/
  69. void initializeGL(void) override;
  70. void resizeGL(int w, int h) override;
  71. void paintGL() override;
  72. void drawRubberband(void);
  73. //void redraw();
  74. void resizeEvent(QResizeEvent* re) override;
  75. void mousePressEvent(QMouseEvent* me) override;
  76. void mouseMoveEvent(QMouseEvent* me) override;
  77. void mouseReleaseEvent(QMouseEvent* me) override;
  78. inline const mnd::MandelViewport& getViewport(void) const { return viewport; }
  79. signals:
  80. void needsUpdate(const mnd::MandelInfo vp);
  81. public slots:
  82. void viewUpdated(Texture* bitmap);
  83. };