Przeglądaj źródła

remove old interfaces

Nicolas Winkler 4 lat temu
rodzic
commit
b07c4eb553

+ 0 - 407
include/MandelWidget.h

@@ -1,407 +0,0 @@
-#pragma once
-#if 0
-
-#include <QGLWidget>
-#include <QOpenGLWidget>
-#include <QThreadPool>
-#include <QMouseEvent>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-#include <QOpenGLFunctions_2_0>
-#include <QOpenGLShaderProgram>
-#include <QMutex>
-#include <QPainter>
-//#include <qopengl.h>
-//#include <qopenglfunctions.h>
-//#include <qopenglcontext.h>
-#include <Mandel.h>
-
-#include "Bitmap.h"
-#include "Gradient.h"
-
-#include <atomic>
-#include <tuple>
-#include <deque>
-#include <chrono>
-#include <unordered_map>
-#include <unordered_set>
-
-
-using GridIndex = mnd::Integer;
-Q_DECLARE_METATYPE(GridIndex)
-Q_DECLARE_METATYPE(mnd::Real)
-
-
-class MandelView;
-class MandelWidget;
-
-class Texture
-{
-protected:
-    GLuint id;
-    QOpenGLFunctions& gl;
-    inline Texture(QOpenGLFunctions& gl) : gl{ gl } {}
-public:
-    Texture(QOpenGLFunctions& gl, const Bitmap<float>& pict, GLint param = GL_LINEAR);
-    ~Texture(void);
-
-    Texture(const Texture& other) = delete;
-    Texture& operator=(const Texture& other) = delete;
-
-    Texture(Texture&& other);
-    Texture& operator=(Texture&& other) = delete;
-
-private:
-    void bind(void) const;
-public:
-    inline GLuint getId(void) const { return id; }
-
-    void drawRect(QOpenGLShaderProgram* program,
-                  float x, float y, float width, float height,
-                  float tx = 0.0f, float ty = 0.0f,
-                  float tw = 1.0f, float th = 1.0f);
-};
-
-
-///
-/// \brief The FloatTexture class
-///
-/*class FloatTexture
-{
-    GLuint id;
-    QOpenGLFunctions& gl;
-public:
-    FloatTexture(QOpenGLFunctions& gl, const Bitmap<float>& pict, GLint param = GL_LINEAR);
-    ~Texture(void);
-
-    Texture(const Texture& other) = delete;
-    Texture& operator=(const Texture& other) = delete;
-
-    Texture(Texture&& other);
-    Texture& operator=(Texture&& other) = delete;
-
-private:
-    void bind(void) const;
-public:
-    inline GLuint getId(void) const { return id; }
-
-    void drawRect(QOpenGLShaderProgram* program,
-                  float x, float y, float width, float height,
-                  float tx = 0.0f, float ty = 0.0f,
-                  float tw = 1.0f, float th = 1.0f);
-};*/
-
-
-class CellImage
-{
-public:
-    CellImage(void) = default;
-    CellImage(CellImage&& b) = default;
-    CellImage(const CellImage& b) = delete;
-    virtual ~CellImage(void);
-
-    virtual void drawRect(QOpenGLShaderProgram* program,
-                          float x, float y, float width, float height) = 0;
-    virtual std::shared_ptr<CellImage> clip(short i, short j) = 0;
-    virtual int getRecalcPriority(void) const = 0;
-};
-
-
-class TextureClip : public CellImage
-{
-    std::shared_ptr<Texture> texture;
-    float tx, ty, tw, th;
-public:
-    inline TextureClip(std::shared_ptr<Texture> tex,
-                       float tx, float ty, float tw, float th) :
-        texture{ std::move(tex) },
-        tx{ tx }, ty{ ty }, tw{ tw }, th{ th }
-    {}
-
-    inline TextureClip(std::shared_ptr<Texture> tex) :
-        TextureClip{ tex, 0.0f, 0.0f, 1.0f, 1.0f }
-    {}
-
-    TextureClip(TextureClip&&) = default;
-    TextureClip(const TextureClip&) = delete;
-
-    virtual ~TextureClip(void);
-
-    void drawRect(QOpenGLShaderProgram* program,
-                  float x, float y, float width, float height) override;
-
-    TextureClip clip(float x, float y, float w, float h);
-    std::shared_ptr<CellImage> clip(short i, short j) override;
-    int getRecalcPriority(void) const override;
-};
-
-
-class QuadImage : public CellImage
-{
-    std::shared_ptr<CellImage> cells[2][2];
-public:
-    inline QuadImage(std::shared_ptr<CellImage> i00,
-                     std::shared_ptr<CellImage> i01,
-                     std::shared_ptr<CellImage> i10,
-                     std::shared_ptr<CellImage> i11) :
-        cells{ { std::move(i00), std::move(i01) }, { std::move(i10), std::move(i11) } }
-    {}
-
-    QuadImage(QuadImage&&) = default;
-    QuadImage(const QuadImage&) = delete;
-
-    virtual ~QuadImage(void);
-
-    void drawRect(QOpenGLShaderProgram* program,
-                  float x, float y, float width, float height) override;
-    std::shared_ptr<CellImage> clip(short i, short j) override;
-    int getRecalcPriority(void) const override;
-};
-
-
-struct PairHash {
-    template <typename T1, typename T2>
-    std::size_t operator () (const std::pair<T1, T2>& p) const {
-        auto h1 = std::hash<T1>{}(p.first);
-        auto h2 = std::hash<T2>{}(p.second);
-        //boost::hash_combine(h1, p.second);
-        return (h1 ^ 234579245) * 23452354 + h2;
-    }
-};
-
-struct TripleHash {
-    template <typename T1, typename T2, typename T3>
-    std::size_t operator () (const std::tuple<T1, T2, T3>& p) const {
-        auto h1 = std::hash<T1>{}(std::get<0>(p));
-        auto h2 = std::hash<T2>{}(std::get<1>(p));
-        auto h3 = std::hash<T3>{}(std::get<2>(p));
-        return (((h1 ^ 234579245) * 23452357 + h2) ^ 2345244345) * 23421 + h3;
-    }
-};
-
-
-struct GridElement
-{
-    bool enoughResolution;
-    std::shared_ptr<CellImage> img;
-    inline GridElement(bool enoughResolution, std::shared_ptr<CellImage> img) :
-        enoughResolution{ enoughResolution },
-        img{ std::move(img) }
-    {}
-};
-
-
-class TexGrid
-{
-public:
-    MandelView& owner;
-    int level;
-    mnd::Real dpp;
-    std::unordered_map<std::pair<GridIndex, GridIndex>, std::unique_ptr<GridElement>, PairHash> cells;
-public:
-    //inline TexGrid(MandelV& owner) : level{ 1.0 }, owner{ owner } {}
-    TexGrid(MandelView& owner, int level);
-
-    std::pair<GridIndex, GridIndex> getCellIndices(mnd::Real x, mnd::Real y);
-    std::pair<mnd::Real, mnd::Real> getPositions(GridIndex i, GridIndex j);
-    GridElement* getCell(GridIndex i, GridIndex j);
-    void setCell(GridIndex i, GridIndex j, std::unique_ptr<GridElement> tex);
-
-    inline size_t countAllocatedCells(void) const { return cells.size(); }
-    void clearCells(void);
-    void clearUncleanCells(void);
-};
-
-
-class Job : public QObject, public QRunnable
-{
-    Q_OBJECT
-public:
-    mnd::MandelGenerator* generator;
-    const Gradient& gradient;
-    MandelWidget& owner;
-    TexGrid* grid;
-    int level;
-    GridIndex i, j;
-    long calcState = 0;
-
-    inline Job(mnd::MandelGenerator* generator,
-               const Gradient& gradient,
-               MandelWidget& owner,
-               TexGrid* grid,
-               int level, GridIndex i, GridIndex j,
-               long calcState) :
-        generator{ generator },
-        gradient{ gradient },
-        owner{ owner },
-        grid{ grid },
-        level{ level },
-        i{ i }, j{ j },
-        calcState{ calcState }
-    {}
-
-    void run() override;
-signals:
-    void done(int level, GridIndex i, GridIndex j, long calcState, Bitmap<float>* bmp);
-};
-
-
-class Calcer : public QObject
-{
-    Q_OBJECT
-    /// tuple contains level, i, j of the job
-    std::unordered_map<std::tuple<int, GridIndex, GridIndex>, Job*, TripleHash> jobs;
-    QMutex jobsMutex;
-    mnd::MandelGenerator* generator;
-    std::unique_ptr<QThreadPool> threadPool;
-    MandelWidget& owner;
-    const Gradient& gradient;
-    int currentLevel;
-
-    volatile unsigned int calcState = 0;
-public:
-    Calcer(mnd::MandelGenerator* generator, MandelWidget& owner);
-    void clearAll(void);
-    void setGenerator(mnd::MandelGenerator* generator) { this->generator = generator; changeState(); }
-
-    inline void changeState(void) { calcState++; }
-
-public slots:
-    void calc(TexGrid& grid, int level, GridIndex i, GridIndex j, int priority);
-    void setCurrentLevel(int level);
-    void notFinished(int level, GridIndex i, GridIndex j);
-    void redirect(int level, GridIndex i, GridIndex j, long calcState, Bitmap<float>* bmp);
-signals:
-    void done(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp);
-};
-
-
-class MandelView : public QObject
-{
-    Q_OBJECT
-public:
-    std::unique_ptr<Texture> empty;
-
-    // a grid should not be deleted once constructed.
-    // to free up memory one can call TexGrid::clearCells()
-    std::unordered_map<int, TexGrid> levels;
-    mnd::MandelGenerator* generator;
-    Calcer calcer;
-    MandelWidget& owner;
-    int width;
-    int height;
-public:
-    static const int chunkSize;
-    MandelView(mnd::MandelGenerator* generator, MandelWidget& owner);
-    int getLevel(mnd::Real dpp);
-    mnd::Real getDpp(int level);
-
-    TexGrid& getGrid(int level);
-
-    void setGenerator(mnd::MandelGenerator* generator);
-
-    void clearCells(void);
-
-    void garbageCollect(int level, GridIndex i, GridIndex j);
-    GridElement* searchAbove(int level, GridIndex i, GridIndex j, int recursionLevel);
-    GridElement* searchUnder(int level, GridIndex i, GridIndex j, int recursionLevel);
-    void paint(const mnd::MandelViewport& mvp);
-public slots:
-    void cellReady(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp);
-signals:
-    void redrawRequested(void);
-};
-
-
-class MandelWidget : public QOpenGLWidget
-{
-    Q_OBJECT
-
-    friend class MandelView;
-private:
-    mnd::MandelContext& mndContext;
-    mnd::MandelGenerator* generator;
-    mnd::MandelInfo mandelInfo;
-
-    bool initialized = false;
-
-    Gradient gradient;
-
-    volatile bool selectingPoint = false;
-    float pointX;
-    float pointY;
-
-    volatile bool rubberbanding = false;
-    QRectF rubberband;
-    volatile bool dragging = false;
-    int dragX, dragY;
-
-    bool displayInfo = false;
-
-    mnd::MandelViewport currentViewport;
-    mnd::MandelViewport targetViewport;
-    std::chrono::time_point<std::chrono::high_resolution_clock> lastAnimUpdate;
-
-    std::unique_ptr<MandelView> mandelView;
-
-    QOpenGLShaderProgram* program;
-    GLuint gradientTexture;
-public:
-    MandelWidget(mnd::MandelContext& ctxt, mnd::MandelGenerator* generator, QWidget* parent = nullptr);
-    ~MandelWidget(void) override;
-
-    inline const Gradient& getGradient(void) const { return gradient; }
-    void setGradient(Gradient g);
-
-    inline bool getSmoothColoring(void) const { return mandelInfo.smooth; }
-    void setSmoothColoring(bool sc);
-
-    inline bool doesDisplayInfo(void) const { return displayInfo; }
-    void setDisplayInfo(bool di);
-
-    inline int getMaxIterations(void) const { return mandelInfo.maxIter; }
-    void setMaxIterations(int maxIter);
-
-    inline const mnd::MandelInfo& getMandelInfo(void) const { return mandelInfo; }
-    inline mnd::MandelInfo& getMandelInfo(void) { return mandelInfo; }
-
-    void setJuliaPos(const mnd::Real& x, const mnd::Real& y);
-    const mnd::Real& getJuliaX(void) { return mandelInfo.juliaX; }
-    const mnd::Real& getJuliaY(void) { return mandelInfo.juliaY; }
-
-    inline mnd::MandelGenerator* getGenerator(void) const { return generator; }
-    void setGenerator(mnd::MandelGenerator* generator);
-    void clearAll(void);
-
-    void initializeGL(void) override;
-    void resizeGL(int w, int h) override;
-    void paintGL() override;
-
-private:
-    void updateAnimations(void);
-
-    void drawRubberband(QPainter& p);
-    void drawInfo(QPainter& p);
-    void drawPoint(QPainter& p);
-public:
-
-    void zoom(float scale, float x = 0.5f, float y = 0.5f);
-    void setViewport(const mnd::MandelViewport& viewport);
-    void selectPoint(void);
-    void stopSelectingPoint(void);
-
-    void requestRecalc(void);
-
-    void resizeEvent(QResizeEvent* re) override;
-    void mousePressEvent(QMouseEvent* me) override;
-    void mouseMoveEvent(QMouseEvent* me) override;
-    void mouseReleaseEvent(QMouseEvent* me) override;
-    void wheelEvent(QWheelEvent * we) override;
-
-    inline const mnd::MandelViewport& getViewport(void) const { return targetViewport; }
-signals:
-    void needsUpdate(const mnd::MandelInfo vp);
-    void pointSelected(mnd::Real x, mnd::Real y);
-};
-
-#endif

+ 0 - 51
include/exportdialogs.h

@@ -1,51 +0,0 @@
-#ifndef EXPORTDIALOGS_H
-#define EXPORTDIALOGS_H
-
-#include "Mandel.h"
-
-#include <QtWidgets/QDialog>
-
-#include "ui_exportimagedialog.h"
-#include "ui_exportvideodialog.h"
-
-#include "MandelVideoGenerator.h"
-
-class Almond;
-
-class ExportImageDialog : public QDialog
-{
-    Q_OBJECT
-private:
-    Ui::ExportImageDialog eid;
-public:
-    ExportImageDialog(QWidget* parent);
-
-    void setMaxIterations(int mi);
-    int getMaxIterations(void) const;
-    int getWidth(void) const;
-    int getHeight(void) const;
-    QString getPath(void) const;
-private slots:
-    void on_pushButton_clicked();
-    void on_buttonBox_accepted();
-};
-
-
-class ExportVideoDialog : public QDialog
-{
-    Q_OBJECT
-private:
-    Ui::ExportVideoDialog evd;
-
-    ExportVideoInfo evi;
-    Almond* almond;
-public:
-    ExportVideoDialog(Almond* parent, const ExportVideoInfo& evi);
-
-    const ExportVideoInfo& getExportVideoInfo(void) const;
-private slots:
-    void on_buttonBox_accepted();
-    void on_pushButton_clicked();
-};
-
-#endif // EXPORTDIALOGS_H

+ 0 - 29
include/gradientchoosedialog.h

@@ -1,29 +0,0 @@
-#ifndef GRADIENTCHOOSEDIALOG_H
-#define GRADIENTCHOOSEDIALOG_H
-
-#include <QDialog>
-#include "ui_gradientchooser.h"
-#include "Gradient.h"
-
-#include <memory>
-#include <map>
-
-class GradientChooseDialog : public QDialog
-{
-    Q_OBJECT
-private:
-    Ui::GradientChooser gcd;
-    std::unique_ptr<Gradient> chosenGradient = nullptr;
-public:
-    GradientChooseDialog();
-private slots:
-    void on_buttonBox_accepted();
-    void on_buttonBox_clicked(QAbstractButton *button);
-
-    void on_presets_currentIndexChanged(const QString &arg1);
-
-public:
-    inline std::unique_ptr<Gradient> getGradient(void) { return std::move(chosenGradient); }
-};
-
-#endif // GRADIENTCHOOSEDIALOG_H

+ 0 - 1176
src/MandelWidget.cpp

@@ -1,1176 +0,0 @@
-#if 0
-
-#include "MandelWidget.h"
-#include <cmath>
-#include <sstream>
-
-#include <QStyle>
-#include <QStyleOption>
-#include <QOpenGLShader>
-#include <QOpenGLFunctions_3_0>
-
-using namespace mnd;
-
-#include <QPainter>
-#include <QTimer>
-
-#include <cstdio>
-
-
-Texture::Texture(QOpenGLFunctions& gl, const Bitmap<float>& bitmap, GLint param) :
-    gl{ gl }
-{
-    gl.glGenTextures(1, &id);
-    gl.glActiveTexture(GL_TEXTURE0);
-    gl.glBindTexture(GL_TEXTURE_2D, id);
-
-    Bitmap<float> copy = bitmap.map<float>([](float x) { return x / 200; });
-    Bitmap<RGBColor> rgbs = bitmap.map<RGBColor>([](float x) { return RGBColor{ 100, uint8_t(::sin(x * 0.01) * 127 + 127), 20 }; });
-
-    //int lineLength = (bitmap.width * 3 + 3) & ~3;
-
-    /*std::unique_ptr<unsigned char[]> pixels = std::make_unique<unsigned char[]>(lineLength * bitmap.height);
-    for (int i = 0; i < bitmap.width; i++) {
-        for (int j = 0; j < bitmap.height; j++) {
-            int index = i * 3 + j * lineLength;
-            RGBColor c = bitmap.get(i, j);
-            pixels[index] = c.r;
-            pixels[index + 1] = c.g;
-            pixels[index + 2] = c.b;
-        }
-    }*/
-    gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, int(bitmap.width), int(bitmap.height), 0, GL_RGB, GL_UNSIGNED_BYTE, rgbs.pixels.get());
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
-    gl.glBindTexture(GL_TEXTURE_2D, 0);
-}
-
-
-Texture::~Texture(void)
-{
-    if (id != 0)
-        gl.glDeleteTextures(1, &id);
-}
-
-
-Texture::Texture(Texture&& other) :
-    id{ other.id },
-    gl{ other.gl }
-{
-    other.id = 0;
-}
-
-
-void Texture::bind(void) const
-{
-    gl.glActiveTexture(GL_TEXTURE0);
-    gl.glBindTexture(GL_TEXTURE_2D, id);
-}
-
-
-static GLuint gradId;
-void Texture::drawRect(QOpenGLShaderProgram* program,
-                       float x, float y, float width, float height,
-                       float tx, float ty, float tw, float th)
-{
-#if 1
-    GLfloat const vertices[] = {
-        x, y,  0.0f,
-        x, y + height, 0.0f,
-        x + width, y + height, 0.0f,
-        x + width, y, 0.0f,
-    };
-
-    GLfloat const texCoords[] = {
-        tx,      ty,
-        tx,      ty + th,
-        tx + tw, ty + th,
-        tx + tw, ty,
-    };
-
-    QColor color(255, 255, 255);
-
-    int vertexLoc = program->attributeLocation("vertex");
-    int texCoordsLoc = program->attributeLocation("texCoord");
-    int colorLocation = program->uniformLocation("color");
-    int texLoc = program->uniformLocation("tex");
-    int gradLoc = program->uniformLocation("gradient");
-    program->setAttributeArray(vertexLoc, vertices, 3);
-    program->setAttributeArray(texCoordsLoc, texCoords, 2);
-    program->enableAttributeArray(vertexLoc);
-    program->enableAttributeArray(texCoordsLoc);
-    program->setUniformValue(colorLocation, color);
-
-
-    auto& gl3 = *QOpenGLContext::currentContext()->functions();
-    gl3.glEnable(GL_TEXTURE_2D);
-
-    gl3.glUniform1i(texLoc, GL_TEXTURE0);
-    gl3.glUniform1i(gradLoc, GL_TEXTURE2);
-
-    gl3.glActiveTexture(GL_TEXTURE0);
-    gl3.glBindTexture(GL_TEXTURE_2D, id);
-
-    gl3.glActiveTexture(GL_TEXTURE2);
-    gl3.glBindTexture(GL_TEXTURE_2D, gradId);
-    gl3.glActiveTexture(GL_TEXTURE0);
-
-    gl3.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-    program->disableAttributeArray(vertexLoc);
-    program->disableAttributeArray(texCoordsLoc);
-    gl3.glActiveTexture(GL_TEXTURE0);
-#else
-    gl.glColor3ub(255, 255, 255);
-    gl.glEnable(GL_TEXTURE_2D);
-    bind();
-    gl.glBegin(GL_TRIANGLE_STRIP);
-    gl.glTexCoord2f(0, 0);
-    gl.glVertex2f(x, y);
-    gl.glTexCoord2f(1, 0);
-    gl.glVertex2f(x + width, y);
-    gl.glTexCoord2f(0, 1);
-    gl.glVertex2f(x, y + height);
-    gl.glTexCoord2f(1, 1);
-    gl.glVertex2f(x + width, y + height);
-    gl.glEnd();
-    gl.glDisable(GL_TEXTURE_2D);
-#endif
-}
-
-
-CellImage::~CellImage(void)
-{
-}
-
-
-
-TextureClip::~TextureClip(void)
-{
-}
-
-
-void TextureClip::drawRect(QOpenGLShaderProgram* program,
-        float x, float y, float width, float height)
-{
-    /*
-    auto& gl = texture->gl;
-    gl.glColor3ub(255, 255, 255);
-    gl.glEnable(GL_TEXTURE_2D);
-    gl.glBindTexture(GL_TEXTURE_2D, texture->getId());
-    gl.glBegin(GL_TRIANGLE_STRIP);
-    gl.glTexCoord2f(tx, ty);
-    gl.glVertex2f(x, y);
-    gl.glTexCoord2f(tx + tw, ty);
-    gl.glVertex2f(x + width, y);
-    gl.glTexCoord2f(tx, ty + th);
-    gl.glVertex2f(x, y + height);
-    gl.glTexCoord2f(tx + tw, ty + th);
-    gl.glVertex2f(x + width, y + height);
-    gl.glEnd();
-    gl.glDisable(GL_TEXTURE_2D);*/
-    texture->drawRect(program, x, y, width, height,
-                      tx, ty, tw, th);
-}
-
-
-TextureClip TextureClip::clip(float x, float y, float w, float h)
-{
-    float tx = this->tx + x * this->tw;
-    float ty = this->ty + y * this->th;
-    float tw = this->tw * w;
-    float th = this->th * h;
-    return TextureClip{ this->texture, tx, ty, tw, th };
-}
-
-
-std::shared_ptr<CellImage> TextureClip::clip(short i, short j)
-{
-    return std::make_shared<TextureClip>(clip(i * 0.5f, j * 0.5f, 0.5f, 0.5f));
-}
-
-
-int TextureClip::getRecalcPriority() const
-{
-    return int(1.0f / tw);
-}
-
-
-QuadImage::~QuadImage(void)
-{
-}
-
-
-void QuadImage::drawRect(QOpenGLShaderProgram* program,
-        float x, float y, float width, float height)
-{
-    for (int i = 0; i < 2; i++) {
-        for (int j = 0; j < 2; j++) {
-            this->cells[i][j]->drawRect(program,
-                                        x + i * 0.5f * width,
-                                        y + j * 0.5f * height,
-                                        width * 0.5f,
-                                        height * 0.5f);
-        }
-    }
-}
-
-
-std::shared_ptr<CellImage> QuadImage::clip(short i, short j)
-{
-    return cells[i][j];
-}
-
-
-int QuadImage::getRecalcPriority() const
-{
-    return 1;
-}
-
-TexGrid::TexGrid(MandelView& owner, int level) :
-    owner{ owner },
-    level{ level },
-    dpp{ owner.getDpp(level) }
-{
-}
-
-
-std::pair<GridIndex, GridIndex> TexGrid::getCellIndices(mnd::Real x, mnd::Real y)
-{
-    return { GridIndex(mnd::floor(x / dpp / MandelView::chunkSize)), GridIndex(mnd::floor(y / dpp / MandelView::chunkSize)) };
-}
-
-
-std::pair<mnd::Real, mnd::Real> TexGrid::getPositions(GridIndex x, GridIndex y)
-{
-    return { mnd::Real(x) * dpp * MandelView::chunkSize, mnd::Real(y) * dpp * MandelView::chunkSize };
-}
-
-
-GridElement* TexGrid::getCell(GridIndex i, GridIndex j)
-{
-    auto cIt = cells.find({i, j});
-    if (cIt != cells.end()) {
-        return cIt->second.get();
-    }
-    else {
-        return nullptr;
-    }
-}
-
-
-void TexGrid::setCell(GridIndex i, GridIndex j, std::unique_ptr<GridElement> tex)
-{
-    cells[{i, j}] = std::move(tex);
-}
-
-
-void TexGrid::clearCells(void)
-{
-    cells.clear();
-}
-
-
-void TexGrid::clearUncleanCells(void)
-{
-    for (auto it = cells.begin(); it != cells.end();) {
-        if (it->second->img->getRecalcPriority() > 1)
-            cells.erase(it++);
-        else ++it;
-    }
-}
-
-
-void Job::run(void)
-{
-    auto [absX, absY] = grid->getPositions(i, j);
-    mnd::Real gw = grid->dpp * MandelView::chunkSize;
-
-    Bitmap<float>* f = new Bitmap<float>(MandelView::chunkSize, MandelView::chunkSize);
-    mnd::MandelInfo mi = owner.getMandelInfo();
-    mi.view.x = absX;
-    mi.view.y = absY;
-    mi.view.width = mi.view.height = gw;
-    mi.bWidth = mi.bHeight = MandelView::chunkSize;
-    try {
-        generator->generate(mi, f->pixels.get());
-        /*auto* rgb = new Bitmap<RGBColor>(f.map<RGBColor>([&mi, this] (float i) {
-            return i >= mi.maxIter ? RGBColor{ 0, 0, 0 } : gradient.get(i);
-        }));*/
-        emit done(level, i, j, calcState, f);
-    }
-    catch(std::exception& ex) {
-        printf("wat: %s?!\n", ex.what()); fflush(stdout);
-        exit(1);
-    }
-    catch(...) {
-        printf("wat?!\n"); fflush(stdout);
-        exit(1);
-    }
-}
-
-
-Calcer::Calcer(mnd::MandelGenerator* generator, MandelWidget& owner) :
-    jobsMutex{ QMutex::Recursive },
-    generator{ generator },
-    threadPool{ std::make_unique<QThreadPool>() },
-    owner{ owner },
-    gradient{ owner.getGradient() }
-{
-    threadPool->setMaxThreadCount(1);
-}
-
-
-void Calcer::clearAll(void)
-{
-    this->threadPool->clear();
-}
-
-
-void Calcer::calc(TexGrid& grid, int level, GridIndex i, GridIndex j, int priority)
-{
-    jobsMutex.lock();
-    if (jobs.find({ level, i, j }) == jobs.end()) {
-        Job* job = new Job(generator, gradient, owner, &grid, level, i, j, calcState);
-        connect(job, &Job::done, this, &Calcer::redirect);
-        connect(job, &QObject::destroyed, this, [this, level, i, j] () { this->notFinished(level, i, j); });
-        jobs.emplace(std::tuple{level, i, j}, job);
-        threadPool->start(job, priority);
-    }
-    jobsMutex.unlock();
-}
-
-
-void Calcer::setCurrentLevel(int level)
-{
-    if (this->currentLevel != level) {
-        this->currentLevel = level;
-        std::vector<QRunnable*> toCancel;
-        jobsMutex.lock();
-        for (auto&[tup, job] : jobs) {
-            auto& [level, i, j] = tup;
-            if(level != currentLevel) {
-                toCancel.push_back(job);
-            }
-        }
-        jobsMutex.unlock();
-        for (auto* job : toCancel) {
-            if (threadPool->tryTake(job)) {
-                delete job;
-            }
-        }
-    }
-}
-
-
-void Calcer::notFinished(int level, GridIndex i, GridIndex j)
-{
-    jobsMutex.lock();
-    jobs.erase({ level, i, j });
-    jobsMutex.unlock();
-}
-
-
-void Calcer::redirect(int level, GridIndex i, GridIndex j, long calcState, Bitmap<float>* bmp)
-{
-    jobsMutex.lock();
-    jobs.erase({ level, i, j });
-    jobsMutex.unlock();
-    if (this->calcState == calcState) {
-        emit done(level, i, j, bmp);
-    }
-    else {
-        delete bmp;
-    }
-}
-
-
-const int MandelView::chunkSize = 256;
-
-MandelView::MandelView(mnd::MandelGenerator* generator, MandelWidget& owner) :
-    generator{ generator },
-    calcer{ generator, owner },
-    owner{ owner },
-    width{ 0 },
-    height{ 0 }
-{
-    /*Bitmap<RGBColor> emp(8, 8);
-    for(auto i = 0; i < emp.width; i++) {
-        for(auto j = 0; j < emp.height; j++) {
-            if((i + j) & 0x1) { // if i+j is odd
-                emp.get(i, j) = RGBColor{ 255, 255, 255 };
-            }
-            else {
-                emp.get(i, j) = RGBColor{ 120, 120, 120 };
-            }
-        }
-    }*/
-    Bitmap<float> emp(1, 1);
-    emp.get(0, 0) = 0.0f;
-    auto& gl = *QOpenGLContext::currentContext()->functions();
-    empty = std::make_unique<Texture>(gl, emp, GL_NEAREST);
-    connect(&calcer, &Calcer::done, this, &MandelView::cellReady);
-}
-
-
-int MandelView::getLevel(mnd::Real dpp)
-{
-    return int(mnd::log2(dpp / chunkSize));
-}
-
-
-mnd::Real MandelView::getDpp(int level)
-{
-    return mnd::pow(mnd::Real(2), mnd::Real(level)) * chunkSize;
-}
-
-
-TexGrid& MandelView::getGrid(int level)
-{
-    auto it = levels.find(level);
-    if (it != levels.end()) {
-        return it->second;
-    }
-    else {
-        levels.insert(std::pair<int, TexGrid>{ level, TexGrid{ *this, level } });
-        return levels.at(level);
-    }
-}
-
-
-void MandelView::setGenerator(mnd::MandelGenerator* generator)
-{
-    if (this->generator != generator) {
-        this->generator = generator;
-        calcer.setGenerator(generator);
-        clearCells();
-        emit redrawRequested();
-    }
-}
-
-
-void MandelView::clearCells(void)
-{
-    for(auto& [level, grid] : this->levels) {
-        grid.clearCells();
-    }
-}
-
-
-void MandelView::garbageCollect(int level, GridIndex /*i*/, GridIndex /*j*/)
-{
-    for(auto& [l, grid] : levels) {
-        int dist = ::abs(l - level);
-
-        if (dist == 1) {
-            grid.clearUncleanCells();
-        }
-
-        if (dist > 20) {
-            grid.clearCells();
-        }
-        else if (dist > 10) {
-            if (grid.countAllocatedCells() > 50)
-                grid.clearCells();
-        }
-        else if (dist > 3) {
-            if (grid.countAllocatedCells() > 150)
-                grid.clearCells();
-        }
-        else if (dist > 0) {
-            if (grid.countAllocatedCells() > 350)
-                grid.clearCells();
-        }
-        else {
-            if (grid.countAllocatedCells() > 2500)
-                grid.clearCells();
-        }
-    }
-}
-
-
-GridElement* MandelView::searchAbove(int level, GridIndex i, GridIndex j, int recursionLevel)
-{
-    auto& grid = getGrid(level);
-    auto& gridAbove = getGrid(level + 1);
-
-    GridIndex ai = (i < 0 ? (i - 1) : i) / 2;
-    GridIndex aj = (j < 0 ? (j - 1) : j) / 2;
-
-    GridElement* above = gridAbove.getCell(ai, aj);
-
-    if (above == nullptr && recursionLevel > 0) {
-        auto abFound = searchAbove(level + 1, ai, aj, recursionLevel - 1);
-        if (abFound)
-            above = abFound;
-    }
-
-    if (above != nullptr) {
-        auto newElement = std::make_unique<GridElement>(
-            false, above->img->clip(short(i & 1), short(j & 1))
-        );
-        GridElement* ret = newElement.get();
-        grid.setCell(i, j, std::move(newElement));
-        return ret;
-    }
-    else {
-        return nullptr;
-    }
-}
-
-
-GridElement* MandelView::searchUnder(int level, GridIndex i, GridIndex j, int recursionLevel)
-{
-    if (recursionLevel == 0)
-        return nullptr;
-
-    auto& grid = getGrid(level);
-    auto& gridUnder = getGrid(level - 1);
-
-    GridIndex ai = i * 2;
-    GridIndex aj = j * 2;
-
-    GridElement* u00 = gridUnder.getCell(ai, aj);
-    GridElement* u01 = gridUnder.getCell(ai, aj + 1);
-    GridElement* u10 = gridUnder.getCell(ai + 1, aj);
-    GridElement* u11 = gridUnder.getCell(ai + 1, aj + 1);
-
-    /*if (   u00 == nullptr
-        || u01 == nullptr
-        || u10 == nullptr
-        || u11 == nullptr) {
-        auto abFound = searchUnder(level + 1, ai, aj, recursionLevel - 1);
-        if (abFound)
-            above = abFound;
-    }*/
-
-    if (   u00 != nullptr
-        && u01 != nullptr
-        && u10 != nullptr
-        && u11 != nullptr) {
-        auto newElement = std::make_unique<GridElement>(
-            false, std::make_shared<QuadImage>(u00->img, u01->img, u10->img, u11->img)
-        );
-        GridElement* ret = newElement.get();
-        grid.setCell(i, j, std::move(newElement));
-        return ret;
-    }
-    else {
-        return nullptr;
-    }
-}
-
-
-void MandelView::paint(const mnd::MandelViewport& mvp)
-{    
-    mnd::Real dpp = mvp.width / width;
-    int level = getLevel(dpp) - 1;
-    auto& grid = getGrid(level);
-    mnd::Real gw = getDpp(level) * chunkSize;
-    auto [left, top] = grid.getCellIndices(mvp.x, mvp.y);
-    auto [right, bottom] = grid.getCellIndices(mvp.right(), mvp.bottom());
-
-    garbageCollect(level, (left + right) / 2, (top + bottom) / 2);
-    emit calcer.setCurrentLevel(level);
-
-    mnd::Real w = width * gw / mvp.width;
-
-    auto [realXLeft, realYTop] = grid.getPositions(left, top);
-    realXLeft = ((realXLeft - mvp.x) * mnd::Real(width)) / mvp.width;
-    realYTop = ((realYTop - mvp.y) * mnd::Real(height)) / mvp.height;
-    for(GridIndex i = left; i <= right; i++) {
-        for(GridIndex j = top; j <= bottom; j++) {
-            mnd::Real x = w * int(i - left) + realXLeft;
-            mnd::Real y = w * int(j - top) + realYTop;
-
-            GridElement* t = grid.getCell(i, j);
-
-            if (t == nullptr) {
-                auto under = searchUnder(level, i, j, 1);
-                if (under) {
-                    t = under;
-                }
-                else {
-                    auto above = searchAbove(level, i, j, 3);
-                    if (above) {
-                        t = above;
-                    }
-                }
-            }
-
-            if (t != nullptr) {
-
-                auto& gl3 = *QOpenGLContext::currentContext()->functions();
-                gl3.glActiveTexture(GL_TEXTURE2);
-                gl3.glBindTexture(GL_TEXTURE_2D, owner.gradientTexture);
-                t->img->drawRect(this->owner.program,float(x), float(y), float(w), float(w));
-                /*glBegin(GL_LINE_LOOP);
-                glVertex2f(float(x), float(y));
-                glVertex2f(float(x) + float(w), float(y));
-                glVertex2f(float(x) + float(w), float(y) + float(w));
-                glVertex2f(float(x), float(y) + float(w));
-                glEnd();*/
-
-                if (!t->enoughResolution) {
-                    calcer.calc(grid, level, i, j, t->img->getRecalcPriority());
-                }
-            }
-            else {
-                calcer.calc(grid, level, i, j, 1000);
-                this->empty->drawRect(this->owner.program,
-                            float(x), float(y), float(w), float(w));
-            }
-        }
-    }
-}
-
-
-void MandelView::cellReady(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp)
-{
-    auto& gl = *QOpenGLContext::currentContext()->functions();
-    this->getGrid(level).setCell(i, j,
-        std::make_unique<GridElement>(true, std::make_shared<TextureClip>(std::make_shared<Texture>(gl, *bmp))));
-    delete bmp;
-    emit redrawRequested();
-}
-
-
-MandelWidget::MandelWidget(mnd::MandelContext& ctxt, mnd::MandelGenerator* generator, QWidget* parent) :
-    QOpenGLWidget{ parent },
-    mndContext{ ctxt },
-    generator{ generator },
-    gradient{ Gradient::defaultGradient() }
-{
-    //this->setContentsMargins(0, 0, 0, 0);
-    this->setSizePolicy(QSizePolicy::Expanding,
-        QSizePolicy::Expanding);
-    qRegisterMetaType<GridIndex>("GridIndex");
-    this->format().setSwapInterval(1);
-}
-
-
-MandelWidget::~MandelWidget()
-{
-}
-
-
-void MandelWidget::setGradient(Gradient g)
-{
-    /*this->gradient = std::move(g);
-    if (mandelView) {
-        mandelView->clearCells();
-        mandelView->calcer.changeState();
-    }
-    emit update();*/
-
-    auto& gl = *this->context()->functions();
-    this->gradient = std::move(g);
-    int width = 1024;
-
-    std::vector<unsigned char> pixels(size_t(width * 3));
-    for (int i = 0; i < width; i++) {
-        float pos = i * this->gradient.getMax() / width;
-        RGBColor c = gradient.get(pos);
-        pixels.push_back(c.r);
-        pixels.push_back(c.g);
-        pixels.push_back(c.b);
-    }
-
-    unsigned char pix[] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
-
-    GLuint id;
-    gl.glEnable(GL_TEXTURE_2D);
-    gl.glActiveTexture(GL_TEXTURE2);
-    gl.glGenTextures(1, &id);
-    gl.glBindTexture(GL_TEXTURE_2D, id);
-
-    gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 3, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<char*> (pix));
-    gl.glUniform1i(this->program->uniformLocation("gradient"), GL_TEXTURE2);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-    gl.glBindTexture(GL_TEXTURE_2D, 0);
-
-
-    gradientTexture = id;
-    gradId = id;
-    update();
-}
-
-
-void MandelWidget::setSmoothColoring(bool sc)
-{
-    if (sc != mandelInfo.smooth) {
-        mandelInfo.smooth = sc;
-        if (mandelView) {
-            mandelView->clearCells();
-            emit update();
-        }
-    }
-}
-
-
-void MandelWidget::setDisplayInfo(bool di)
-{
-    if (di != this->displayInfo) {
-        this->displayInfo = di;
-        emit update();
-    }
-}
-
-
-void MandelWidget::setMaxIterations(int maxIter)
-{
-    if (mandelInfo.maxIter != maxIter) {
-        mandelInfo.maxIter = maxIter;
-        if (mandelView) {
-            mandelView->clearCells();
-            mandelView->calcer.clearAll();
-            mandelView->calcer.changeState();
-        }
-        emit update();
-    }
-}
-
-
-void MandelWidget::setJuliaPos(const mnd::Real& x, const mnd::Real& y)
-{
-    mandelInfo.juliaX = x;
-    mandelInfo.juliaY = y;
-    if (mandelView)
-        mandelView->calcer.changeState();
-    emit update();
-}
-
-
-void MandelWidget::setGenerator(mnd::MandelGenerator* generator)
-{
-    if (this->generator != generator) {
-        this->generator = generator;
-        if (mandelView)
-            mandelView->setGenerator(generator);
-    }
-}
-
-
-void MandelWidget::clearAll(void)
-{
-    mandelView->clearCells();
-    mandelView->calcer.clearAll();
-}
-
-
-void MandelWidget::initializeGL(void)
-{
-    auto& gl = *this->context()->functions();
-    gl.glClearColor(0, 0, 0, 0);
-
-    gl.glDisable(GL_DEPTH_TEST);
-
-    // looks not even better
-    gl.glEnable(GL_FRAMEBUFFER_SRGB);
-
-    //glShadeModel(GL_SMOOTH);
-
-
-    program = new QOpenGLShaderProgram{ this->context() };
-    bool vert = program->addShaderFromSourceCode(QOpenGLShader::Vertex,
-    "attribute highp vec4 vertex;\n"
-    "attribute highp vec2 texCoord;\n"
-    "uniform highp mat4 matrix;\n"
-    "varying highp vec2 texc;\n"
-    "void main(void)\n"
-    "{\n"
-    "   gl_Position = matrix * vertex;\n"
-    "   texc = texCoord;\n"
-    "}");
-    bool frag = program->addShaderFromSourceCode(QOpenGLShader::Fragment,
-    "uniform sampler2D gradient;\n"
-    "uniform sampler2D tex;\n"
-    "uniform mediump vec4 color;\n"
-    "varying highp vec2 texc;\n"
-    "void main(void)\n"
-    "{\n"
-    "   float v = texture2D(tex, texc).r;\n"
-    "   gl_FragColor = texture2D(gradient, texc);\n"
-//    "   gl_FragColor = gl_FragColor * texture2D(tex, texc);\n"
-//    "   float v = texture2D(tex, texc).r;\n"
-//    "   gl_FragColor = vec4(v, 1.0 - v, v*v, 1);\n"
-//    "   gl_FragColor.g = 0.3;\n"
-    "}");
-    //program.link();
-    bool bound = program->bind();
-
-    //gl3.glBindSampler(0, id);
-
-    mandelView = nullptr;
-    setGradient(gradient);
-    requestRecalc();
-}
-
-void MandelWidget::resizeGL(int w, int h)
-{
-    auto& gl = *this->context()->functions();
-    double aspect = double(w) / h;
-
-    currentViewport.height = currentViewport.width / aspect;
-    targetViewport = currentViewport;
-    float pixelRatio = this->devicePixelRatioF();
-    gl.glViewport(0, 0, w * pixelRatio, h * pixelRatio);
-
-    if (mandelView.get() != nullptr) {
-        mandelView->width = w;
-        mandelView->height = h;
-        //printf("resize: %d, %d\n", w, h);
-    }
-}
-
-void MandelWidget::paintGL(void)
-{
-    //auto& gl = *QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
-    if (mandelView == nullptr) {
-        mandelView = std::make_unique<MandelView>(generator, *this);
-        QObject::connect(mandelView.get(), &MandelView::redrawRequested, this, static_cast<void(QOpenGLWidget::*)(void)>(&QOpenGLWidget::update));
-    }
-    //if (program)
-        //program->bind();
-
-    /*
-    int width = this->width();
-    int height = this->height();
-    float pixelRatio = this->devicePixelRatioF();
-    mandelView->width = width * pixelRatio;
-    mandelView->height = height * pixelRatio;
-    //glViewport(0, 0, width, height);
-
-    gl.glMatrixMode(GL_PROJECTION);
-    gl.glLoadIdentity();
-#ifdef QT_OPENGL_ES_1
-    gl.glOrthof(0, width * pixelRatio, height * pixelRatio, 0, -1.0, 1.0);
-#else
-    gl.glOrtho(0, double(width) * pixelRatio, double(height) * pixelRatio, 0, -1.0, 1.0);
-#endif
-    gl.glMatrixMode(GL_MODELVIEW);
-    gl.glLoadIdentity();
-
-    gl.glClear(GL_COLOR_BUFFER_BIT);
-
-
-    QPainter painter{ this };
-
-    mandelView->paint(this->currentViewport, painter);
-
-    if (rubberbanding)
-    drawRubberband();
-    if (displayInfo)
-    drawInfo();
-    if (selectingPoint)
-    drawPoint();*/
-    //QPainter painter{ this };
-
-
-    updateAnimations();
-
-    mandelView->paint(this->currentViewport);
-
-    static GLfloat const triangleVertices[] = {
-        0.0,  20,  0.0f,
-        49, 50, 0.0f,
-        -60,  70, 0.0f
-    };
-
-    QColor color(0, 255, 0);
-
-    QMatrix4x4 pmvMatrix;
-    pmvMatrix.ortho(rect());
-
-    int vertexLocation = program->attributeLocation("vertex");
-    int matrixLocation = program->uniformLocation("matrix");
-    int colorLocation = program->uniformLocation("color");
-    program->enableAttributeArray(vertexLocation);
-    program->setAttributeArray(vertexLocation, triangleVertices, 3);
-    program->setUniformValue(matrixLocation, pmvMatrix);
-    program->setUniformValue(colorLocation, color);
-    
-    auto& gl3 = *QOpenGLContext::currentContext()->functions();
-    gl3.glDrawArrays(GL_TRIANGLES, 0, 3);
-
-    program->disableAttributeArray(vertexLocation);
-
-    /*QPainter painter{ this };
-    painter.beginNativePainting();
-    painter.endNativePainting();*/
-    /*if (rubberbanding)
-        drawRubberband(painter);
-    if (displayInfo)
-        drawInfo(painter);
-    if (selectingPoint)
-        drawPoint(painter);*/
-}
-
-
-void MandelWidget::updateAnimations(void)
-{
-    if (mnd::abs(currentViewport.width / targetViewport.width - 1.0) < 1e-3
-            && mnd::abs(currentViewport.height / targetViewport.height - 1.0) < 1e-3) {
-        // animation finished
-        currentViewport = targetViewport;
-    }
-    else {
-        auto now = std::chrono::high_resolution_clock::now();
-        auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastAnimUpdate).count();
-        const mnd::Real factor = mnd::Real(::pow(0.97, millis));
-        const mnd::Real one(1.0);
-
-        currentViewport.x = currentViewport.x * factor + targetViewport.x * (one - factor);
-        currentViewport.y = currentViewport.y * factor + targetViewport.y * (one - factor);
-        currentViewport.width = currentViewport.width * factor + targetViewport.width * (one - factor);
-        currentViewport.height = currentViewport.height * factor + targetViewport.height * (one - factor);
-
-        lastAnimUpdate = now;
-        emit update();
-    }
-
-}
-
-
-void MandelWidget::drawRubberband(QPainter& rubberbandPainter)
-{
-    rubberbandPainter.fillRect(rubberband, QColor{ 125, 140, 225, 120 });
-
-    QPen pen{ QColor{ 100, 115, 200 } };
-    pen.setWidth(2);
-    rubberbandPainter.setPen(pen);
-
-    rubberbandPainter.drawRect(rubberband);
-    //QStyleOption so;
-    //style()->drawControl(QStyle::CE_RubberBand, &so, &rubberbandPainter, this);
-}
-
-
-void MandelWidget::drawInfo(QPainter& infoPainter)
-{
-    const float DIST_FROM_BORDER = 15;
-    float maxWidth = this->width() - 2 * DIST_FROM_BORDER;
-    mnd::Real distPerPixel = currentViewport.width / this->width();
-    float log10 = (mnd::convert<float>(mnd::log(distPerPixel)) + ::logf(maxWidth)) / ::logf(10);
-    mnd::Real displayDist = mnd::pow(mnd::Real(10), ::floor(log10));
-    float pixels = mnd::convert<float>(displayDist / distPerPixel);
-    int factor = 1;
-    for (int i = 9; i > 1; i--) {
-        if (pixels * i < maxWidth) {
-            factor *= i;
-            pixels *= i;
-            displayDist *= i;
-            break;
-        }
-    }
-
-    std::stringstream dis;
-    if (::abs(log10) < 3) {
-        dis << mnd::convert<float>(displayDist);
-    }
-    else {
-        dis << factor << "e" << int(::floor(log10));
-    }
-
-    if (maxWidth > 400) {
-        dis << "; per pixel: " << distPerPixel;
-    }
-
-    float lineY = this->height() - DIST_FROM_BORDER;
-    float lineXEnd = DIST_FROM_BORDER + pixels;
-
-    infoPainter.setPen(Qt::white);
-    infoPainter.setFont(QFont("Arial", 12));
-    infoPainter.drawLine(QPointF{ DIST_FROM_BORDER, lineY }, QPointF{ lineXEnd, lineY });
-    infoPainter.drawLine(QPointF{ DIST_FROM_BORDER, lineY }, QPointF{ DIST_FROM_BORDER, lineY - 5 });
-    infoPainter.drawLine(QPointF{ lineXEnd, lineY }, QPointF{ lineXEnd, lineY - 5 });
-    infoPainter.drawText(int(DIST_FROM_BORDER), int(lineY - 20), int(lineXEnd - DIST_FROM_BORDER), 20,
-                         Qt::AlignCenter, QString::fromStdString(dis.str()));
-}
-
-
-void MandelWidget::drawPoint(QPainter& pointPainter)
-{
-    pointPainter.setPen(QColor{ 255, 255, 255 });
-    pointPainter.drawLine(0, pointY, width(), pointY);
-    pointPainter.drawLine(pointX, 0, pointX, height());
-
-
-    /*glColor3ub(255, 255, 255);
-    glBegin(GL_LINES);
-    glVertex2f(0, pointY);
-    glVertex2f(width(), pointY);
-
-    glVertex2f(pointX, 0);
-    glVertex2f(pointX, height());
-    glEnd();*/
-}
-
-
-void MandelWidget::zoom(float scale, float x, float y)
-{
-    targetViewport.zoom(scale, x, y);
-    lastAnimUpdate = std::chrono::high_resolution_clock::now();
-    //currentViewport.zoom(scale, x, y);
-    requestRecalc();
-}
-
-
-void MandelWidget::setViewport(const mnd::MandelViewport& viewport)
-{
-    targetViewport = viewport;
-    targetViewport.adjustAspectRatio(this->width(), this->height());
-    currentViewport = targetViewport;
-    //lastAnimUpdate = std::chrono::high_resolution_clock::now();
-    //currentViewport.zoom(scale, x, y);
-    requestRecalc();
-}
-
-
-void MandelWidget::selectPoint(void)
-{
-    this->selectingPoint = true;
-    this->setMouseTracking(true);
-}
-
-
-void MandelWidget::stopSelectingPoint(void)
-{
-    this->selectingPoint = false;
-    this->setMouseTracking(false);
-}
-
-
-void MandelWidget::requestRecalc()
-{
-    emit update();
-}
-
-
-void MandelWidget::resizeEvent(QResizeEvent* re)
-{
-    QOpenGLWidget::resizeEvent(re);
-    double aspect = double(geometry().width()) / geometry().height();
-
-    currentViewport.height = currentViewport.width / aspect;
-    targetViewport = currentViewport;
-
-    if (mandelView.get() != nullptr) {
-        mandelView->width = this->width();
-        mandelView->height = this->height();
-    }
-    requestRecalc();
-}
-
-
-void MandelWidget::mousePressEvent(QMouseEvent* me)
-{
-    QOpenGLWidget::mousePressEvent(me);
-    if (me->button() == Qt::RightButton) {
-        rubberbanding = true;
-        rubberband.setCoords(me->x(), me->y(), me->x(), me->y());
-        update();
-        me->accept();
-    }
-    else if (me->button() == Qt::LeftButton) {
-        dragging = true;
-        dragX = me->x();
-        dragY = me->y();
-        me->accept();
-    }
-}
-
-
-void MandelWidget::mouseMoveEvent(QMouseEvent* me)
-{
-    QOpenGLWidget::mouseMoveEvent(me);
-
-    if (rubberbanding) {
-        QRectF& rect = rubberband;
-        double aspect = double(geometry().width()) / geometry().height();
-        rect.setBottomRight(QPoint(me->x(), me->y()));
-        if (rect.width() > rect.height() * aspect)
-            rect.setHeight(rect.width() / aspect);
-        else
-            rect.setWidth(rect.height() * aspect);
-
-        update();
-    }
-    else if (selectingPoint) {
-        pointX = me->x();
-        pointY = me->y();
-        update();
-    }
-    else if (dragging) {
-        double deltaX = me->x() - dragX;
-        double deltaY = me->y() - dragY;
-
-        this->currentViewport.x -= deltaX * currentViewport.width / this->width();
-        this->currentViewport.y -= deltaY * currentViewport.height / this->height();
-        targetViewport = currentViewport;
-        dragX = me->x(); dragY = me->y();
-
-        update();
-    }
-    me->accept();
-}
-
-
-void MandelWidget::mouseReleaseEvent(QMouseEvent* me)
-{
-    QOpenGLWidget::mouseReleaseEvent(me);
-    if (rubberbanding) {
-        QRect rect = rubberband.toRect();
-        if(rect.width() != 0 && rect.height() != 0) {
-            QRect full = this->geometry();
-
-            targetViewport.x += mnd::Real(rect.left()) * targetViewport.width / full.width();
-            targetViewport.y += mnd::Real(rect.top()) * targetViewport.height / full.height();
-            targetViewport.width *= mnd::Real(rect.width()) / full.width();
-            targetViewport.height *= mnd::Real(rect.height()) / full.height();
-            targetViewport.normalize();
-            currentViewport = targetViewport;
-        }
-        requestRecalc();
-        rubberbanding = false;
-    }
-    else if (selectingPoint) {
-        selectingPoint = false;
-        this->setMouseTracking(false);
-        mnd::Real x = currentViewport.x + currentViewport.width * mnd::convert<mnd::Real>(float(me->x()) / width());
-        mnd::Real y = currentViewport.y + currentViewport.height * mnd::convert<mnd::Real>(float(me->y()) / height());
-        emit pointSelected(x, y);
-        update();
-    }
-    dragging = false;
-
-    //requestRecalc();
-}
-
-void MandelWidget::wheelEvent(QWheelEvent* we)
-{
-    QOpenGLWidget::wheelEvent(we);
-    float x = float(we->x()) / this->width();
-    float y = float(we->y()) / this->height();
-    float scale = ::powf(0.9975f, we->angleDelta().y());
-    zoom(scale, x, y);
-    if (!we->pixelDelta().isNull())
-        this->currentViewport = this->targetViewport;
-    we->accept();
-}
-
-
-/*void MandelWidget::viewUpdated(Bitmap<RGBColor>* bitmap)
-{
-    if (bitmap != nullptr) {
-        delete bitmap;
-        emit repaint();
-    }
-}*/
-
-#endif

+ 0 - 233
src/exportdialogs.cpp

@@ -1,233 +0,0 @@
-#include "exportdialogs.h"
-
-#include <QIntValidator>
-#include <QFileDialog>
-#include <QMessageBox>
-
-#include "Mandel.h"
-#include "Almond.h"
-#include "VideoStream.h"
-
-//static bool exportVideo(const ExportVideoInfo& evi);
-
-ExportImageDialog::ExportImageDialog(QWidget* parent) :
-    QDialog{ parent }
-{
-    eid.setupUi(this);
-    this->adjustSize();
-    eid.maxIterations->setValidator(new QIntValidator(1, 1000000000, this));
-    eid.imgWidth->setValidator(new QIntValidator(1, 10000000, this));
-    eid.imgHeight->setValidator(new QIntValidator(1, 10000000, this));
-}
-
-
-void ExportImageDialog::setMaxIterations(int mi)
-{
-    eid.maxIterations->setText(QString::number(mi));
-}
-
-
-int ExportImageDialog::getMaxIterations(void) const
-{
-    return std::stoi(eid.maxIterations->text().toStdString());
-}
-
-
-int ExportImageDialog::getWidth(void) const
-{
-    return std::stoi(eid.imgWidth->text().toStdString());
-}
-
-
-int ExportImageDialog::getHeight(void) const
-{
-    return std::stoi(eid.imgHeight->text().toStdString());
-}
-
-
-QString ExportImageDialog::getPath(void) const
-{
-    return eid.savePath->text();
-}
-
-void ExportImageDialog::on_pushButton_clicked()
-{
-    std::string formatString = "";
-    if (alm::supportsImageFormat(alm::ImageFormat::PNG)) {
-        formatString += "PNG image (*.png);;";
-    }
-    if (alm::supportsImageFormat(alm::ImageFormat::JPEG)) {
-        formatString += "JPEG image (*.jpg *.jpeg);;";
-    }
-    if (alm::supportsImageFormat(alm::ImageFormat::BMP)) {
-        formatString += "BMP image (*.bmp *.dib);;";
-    }
-    if (!formatString.empty()) {
-        formatString.erase(formatString.end() - 2, formatString.end());
-    }
-
-    QString saveAs = QFileDialog::getSaveFileName(this,
-            tr("Save exported image"), "",
-            tr(formatString.c_str()));
-    if(!saveAs.isEmpty() && !saveAs.isNull())
-        eid.savePath->setText(saveAs);
-    this->repaint();
-}
-
-void ExportImageDialog::on_buttonBox_accepted()
-{
-    if (eid.savePath->text() == "") {
-        QMessageBox msgBox;
-        msgBox.setText("Please specify a path.");
-        msgBox.show();
-        msgBox.exec();
-        reject();
-    }
-}
-
-
-ExportVideoDialog::ExportVideoDialog(Almond *parent, const ExportVideoInfo& evi) :
-    QDialog{ parent },
-    almond{ parent },
-    evi{ evi }
-{
-    evd.setupUi(this);
-    this->adjustSize();
-    evd.maxIterations->setValidator(new QIntValidator(1, 1000000000, this));
-    evd.vidWidth->setValidator(new QIntValidator(1, 10000000, this));
-    evd.vidHeight->setValidator(new QIntValidator(1, 10000000, this));
-    evd.bitrate->setValidator(new QIntValidator(1, 10000000, this));
-    evd.fps->setValidator(new QIntValidator(1, 8000, this));
-    evd.zoomSpeed->setValidator(new QDoubleValidator(0.0, 100.0, -1, this));
-
-#ifdef WITH_BOOST
-    evd.startX->setText(QString::fromStdString(evi.start.x.str()));
-    evd.startY->setText(QString::fromStdString(evi.start.y.str()));
-    evd.startW->setText(QString::fromStdString(evi.start.width.str()));
-    evd.startH->setText(QString::fromStdString(evi.start.height.str()));
-
-    evd.endX->setText(QString::fromStdString(evi.end.x.str()));
-    evd.endY->setText(QString::fromStdString(evi.end.y.str()));
-    evd.endW->setText(QString::fromStdString(evi.end.width.str()));
-    evd.endH->setText(QString::fromStdString(evi.end.height.str()));
-#else
-    evd.startX->setText(QString::number(evi.start.x));
-    evd.startY->setText(QString::number(evi.start.y));
-    evd.startW->setText(QString::number(evi.start.width));
-    evd.startH->setText(QString::number(evi.start.height));
-
-    evd.endX->setText(QString::number(evi.end.x));
-    evd.endY->setText(QString::number(evi.end.y));
-    evd.endW->setText(QString::number(evi.end.width));
-    evd.endH->setText(QString::number(evi.end.height));
-#endif // WITH_BOOST
-
-    auto presets = {
-        "ultrafast",
-        "superfast",
-        "veryfast",
-        "faster",
-        "fast",
-        "medium",
-        "slow",
-        "slower",
-        "veryslow",
-    };
-    for (auto& preset : presets) {
-        evd.encodingPresetBox->addItem(preset);
-    }
-}
-
-
-const ExportVideoInfo& ExportVideoDialog::getExportVideoInfo(void) const
-{
-    return evi;
-}
-
-void ExportVideoDialog::on_buttonBox_accepted()
-{
-    /*
-    if (evd.savePath->text() == "") {
-        QMessageBox* msgBox = new QMessageBox;
-        msgBox->setText("Please specify a path.");
-        msgBox->exec();
-        emit reject();
-    }
-
-    evi.path = evd.savePath->text().toStdString();
-
-    evi.mi = almond->mw->getMandelInfo();
-    evi.mi.bWidth = evd.vidWidth->text().toInt();
-    evi.mi.bHeight = evd.vidHeight->text().toInt();
-    evi.mi.maxIter = evd.maxIterations->text().toInt();
-
-    evi.bitrate = evd.bitrate->text().toInt();
-    evi.preset = evd.encodingPresetBox->currentText().toStdString();
-    evi.fps = evd.fps->text().toInt();
-    evi.zoomSpeed = QLocale::system().toDouble(evd.zoomSpeed->text());
-    /*evi.start = mnd::MandelViewport {
-        evd.startX->text().toDouble(),
-        evd.startY->text().toDouble(),
-        evd.startW->text().toDouble(),
-        evd.startH->text().toDouble(),
-    };
-    evi.end = mnd::MandelViewport {
-        evd.endX->text().toDouble(),
-        evd.endY->text().toDouble(),
-        evd.endW->text().toDouble(),
-        evd.endH->text().toDouble(),
-    };*/
-    /*
-    evi.start.adjustAspectRatio(evi.mi.bWidth, evi.mi.bHeight);
-    evi.end.adjustAspectRatio(evi.mi.bWidth, evi.mi.bHeight);
-    evi.gradient = almond->mw->getGradient();
-    */
-    //}
-}
-
-
-void ExportVideoDialog::on_pushButton_clicked()
-{
-    QString saveAs = QFileDialog::getSaveFileName(this,
-            tr("Save exported image"), "",
-            tr("AVI video (*.avi);;MP4 video (*.mp4);;All Files (*)"));
-    evd.savePath->setText(saveAs);
-    this->repaint();
-}
-
-/*
-bool exportVideo(const ExportVideoInfo& evi)
-{
-    auto lerp = [] (double a, double b, double v) {
-        return a * (1 - v) + b * v;
-    };
-
-    mnd::MandelContext ctxt = mnd::initializeContext();
-    mnd::Generator& gen = *ctxt.getDevices()[0].getGeneratorFloat();
-    mnd::MandelInfo mi;
-    mi.bWidth = evi.width;
-    mi.bHeight = evi.height;
-    mi.maxIter = evi.maxIterations;
-
-    VideoStream vs(evi.width, evi.height, evi.path, evi.bitrate, evi.preset.c_str());
-
-    double x = evi.end.x + evi.end.width / 2;
-    double y = evi.end.y + evi.end.height / 2;
-    double w = evi.start.width;
-    double h = evi.start.height;
-
-    while(w > evi.end.width || h > evi.end.height) {
-        mi.view = mnd::MandelViewport{ x - w/2, y - h/2, w, h };
-
-        Bitmap<float> raw{ evi.width, evi.height };
-        gen.generate(mi, raw.pixels.get());
-        vs.addFrame(raw.map<RGBColor>([] (float x) { return
-            RGBColor{ uint8_t(::sin(x / 100) * 127 + 127), uint8_t(::sin(x / 213) * 127 + 127), uint8_t(::cos(x / 173) * 127 + 127) };
-        }));
-
-        w *= 0.975;
-        h *= 0.975;
-    }
-    return true;
-}
-*/

+ 0 - 41
src/gradientchoosedialog.cpp

@@ -1,41 +0,0 @@
-#include "gradientchoosedialog.h"
-
-#include <QFile>
-#include <QResource>
-
-#include <QColorDialog>
-
-GradientChooseDialog::GradientChooseDialog()
-{
-    gcd.setupUi(this);
-    QFont f("unexistent");
-    f.setStyleHint(QFont::Monospace);
-    gcd.plainTextEdit->setFont(f);
-
-    gcd.presets->addItem("default");
-    gcd.presets->addItem("clouds");
-    gcd.presets->addItem("rainbow");
-    gcd.presets->addItem("grayscale");
-    gcd.presets->addItem("peach");
-    gcd.presets->addItem("blue gold");
-}
-
-
-void GradientChooseDialog::on_buttonBox_accepted()
-{
-    //chosenGradient = std::make_unique<Gradient>(Gradient::readXml(gcd.plainTextEdit->toPlainText()));
-}
-
-
-void GradientChooseDialog::on_buttonBox_clicked(QAbstractButton*)
-{
-}
-
-
-void GradientChooseDialog::on_presets_currentIndexChanged(const QString& index)
-{
-    QFile res(":/gradients/" + index);
-    res.open(QIODevice::ReadOnly);
-    QString str = QString::fromUtf8(res.readAll());
-    emit gcd.plainTextEdit->setPlainText(str);
-}