MandelWidget.h 2.1 KB

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