File indexing completed on 2024-05-19 05:55:49

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Han Young <hanyoung@protonmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #pragma once
0007 
0008 #include <QOpenGLFunctions>
0009 #include <QtQuick/QQuickFramebufferObject>
0010 #include <qqmlregistration.h>
0011 
0012 class BackgroundRenderer;
0013 
0014 class WeatherBackgroundRenderer : public QQuickFramebufferObject
0015 {
0016     Q_OBJECT
0017     QML_NAMED_ELEMENT(WeatherBackground)
0018     Q_PROPERTY(bool rain READ rain WRITE setRain NOTIFY rainChanged)
0019     Q_PROPERTY(bool cloud READ cloud WRITE setCloud NOTIFY cloudChanged)
0020     Q_PROPERTY(bool sun READ sun WRITE setSun NOTIFY sunChanged)
0021     Q_PROPERTY(bool star READ star WRITE setStar NOTIFY starChanged)
0022     Q_PROPERTY(bool snow READ snow WRITE setSnow NOTIFY snowChanged)
0023     Q_PROPERTY(QColor colorTop READ colorTop WRITE setColorTop NOTIFY colorTopChanged)
0024     Q_PROPERTY(QColor colorBottom READ colorBottom WRITE setColorBottom NOTIFY colorBottomChanged)
0025     Q_PROPERTY(QColor cloudColor READ cloudColor WRITE setCloudColor NOTIFY cloudColorChanged)
0026 public:
0027     explicit WeatherBackgroundRenderer(QQuickItem *parent = nullptr);
0028     Renderer *createRenderer() const override;
0029     bool rain() const;
0030     bool cloud() const;
0031     bool sun() const;
0032     bool star() const;
0033     bool snow() const;
0034     QColor colorTop() const;
0035     QColor colorBottom() const;
0036     QColor cloudColor() const;
0037 
0038     void setRain(bool);
0039     void setCloud(bool);
0040     void setSun(bool);
0041     void setStar(bool);
0042     void setSnow(bool);
0043     void setColorTop(const QColor &);
0044     void setColorBottom(const QColor &);
0045     void setCloudColor(const QColor &);
0046 
0047 Q_SIGNALS:
0048     void rainChanged();
0049     void cloudChanged();
0050     void sunChanged();
0051     void starChanged();
0052     void snowChanged();
0053     void colorTopChanged();
0054     void colorBottomChanged();
0055     void cloudColorChanged();
0056 
0057 private Q_SLOTS:
0058     void handleTimeout();
0059 
0060 protected:
0061     friend class WeatherBackgroundContentRenderer;
0062     int minFPS = 60;
0063     int modifiedMinFPS = 60;
0064 
0065 private:
0066     QTimer *m_timer = nullptr;
0067     bool m_rain = false;
0068     bool m_cloud = false;
0069     bool m_sun = false;
0070     bool m_star = false;
0071     bool m_snow = false;
0072 
0073     QColor m_colourTop;
0074     QColor m_colourBottom;
0075     QColor m_cloudColor;
0076 };
0077 
0078 class CloudsRenderer;
0079 class RainRenderer;
0080 class SunRenderer;
0081 class StarsRendererBase;
0082 class SnowRendererBase;
0083 class WeatherBackgroundContentRenderer : public QQuickFramebufferObject::Renderer, QOpenGLFunctions
0084 {
0085 public:
0086     void render() override;
0087     void synchronize(QQuickFramebufferObject *item) override;
0088     QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override;
0089 
0090 protected:
0091     friend class WeatherBackgroundRenderer;
0092     WeatherBackgroundContentRenderer();
0093     WeatherBackgroundContentRenderer(const WeatherBackgroundContentRenderer &other) = delete;
0094     WeatherBackgroundContentRenderer(WeatherBackgroundContentRenderer &&other) = delete;
0095     WeatherBackgroundContentRenderer operator=(const WeatherBackgroundContentRenderer &other) = delete;
0096 
0097 private:
0098     CloudsRenderer *m_clouds = nullptr;
0099     RainRenderer *m_rain = nullptr;
0100     std::function<float()> dice;
0101     BackgroundRenderer *background;
0102     SunRenderer *m_sun = nullptr;
0103     StarsRendererBase *m_stars = nullptr;
0104     SnowRendererBase *m_snow = nullptr;
0105 
0106     float aspectRatio = 1;
0107     int m_minFPS = 60;
0108     bool synchronized = false;
0109 
0110     bool m_showRain = false;
0111     bool m_showCloud = false;
0112     bool m_showSun = false;
0113     bool m_showStar = false;
0114     bool m_showSnow = false;
0115     QColor m_colourTop;
0116     QColor m_colourBottom;
0117     QColor m_cloudColor;
0118     bool m_legacyMode = false;
0119 };