MandelWidget.h 1.7 KB

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