MandelWidget.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Texture
  15. {
  16. GLuint id;
  17. public:
  18. Texture(const Bitmap<RGBColor>& pict);
  19. ~Texture(void);
  20. void bind(void) const;
  21. void drawRect(float x, float y, float width, float height);
  22. };
  23. class MandelView : public QObject
  24. {
  25. Q_OBJECT
  26. private:
  27. std::future<void> calc;
  28. std::atomic<mnd::MandelViewport> toCalc;
  29. std::atomic_bool hasToCalc;
  30. mnd::Generator& generator;
  31. public:
  32. inline MandelView(mnd::Generator& generator) :
  33. generator{ generator }
  34. {
  35. }
  36. public slots:
  37. void adaptViewport(const mnd::MandelViewport& vp);
  38. signals:
  39. void updated(const Bitmap<RGBColor>* bitmap);
  40. };
  41. class MandelWidget : public QGLWidget
  42. {
  43. Q_OBJECT
  44. private:
  45. //QScrollArea qsa;
  46. //QLabel ql;
  47. mnd::MandelContext& mndContext;
  48. bool initialized = false;
  49. bool rubberbandDragging = false;
  50. QRectF rubberband;
  51. std::unique_ptr<Texture> tex;
  52. mnd::MandelViewport viewport;
  53. MandelView mv;
  54. public:
  55. MandelWidget(mnd::MandelContext& ctxt, QWidget* parent = nullptr);
  56. ~MandelWidget(void) override;
  57. /*inline MandelWidget(const MandelWidget& other) :
  58. mndContext{ other.mndContext },
  59. mv{ other.mndContext }
  60. {
  61. }*/
  62. void initializeGL(void) override;
  63. void resizeGL(int w, int h) override;
  64. void paintGL() override;
  65. void drawRubberband(void);
  66. //void redraw();
  67. void resizeEvent(QResizeEvent* re) override;
  68. void mousePressEvent(QMouseEvent* me) override;
  69. void mouseMoveEvent(QMouseEvent* me) override;
  70. void mouseReleaseEvent(QMouseEvent* me) override;
  71. inline const mnd::MandelViewport& getViewport(void) const { return viewport; }
  72. signals:
  73. void needsUpdate(const mnd::MandelViewport& vp);
  74. public slots:
  75. void viewUpdated(const Bitmap<RGBColor>* bitmap);
  76. };