//
// Created by matin on 20/07/22.
//

#ifndef KWIN4_SHAPECORNERS_CONFIG_SHADERMANAGER_H
#define KWIN4_SHAPECORNERS_CONFIG_SHADERMANAGER_H

#include <QRectF>
#include <QVector2D>

#include <kwineffects.h>

#include <memory>

namespace KWin
{
class GLShader;
class ShaderManager;

inline QRectF operator*(const QRect &r, const qreal scale)
{
    return {r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale};
}
inline QRectF operator*(const QRectF &r, const qreal scale)
{
    return {r.x() * scale, r.y() * scale, r.width() * scale, r.height() * scale};
}
inline QVector2D toVector2D(const QSizeF &s)
{
    return {static_cast<float>(s.width()), static_cast<float>(s.height())};
}

class ShapeCornersShader
{
public:
    explicit ShapeCornersShader();

    bool IsValid() const;

    const std::unique_ptr<GLShader> &Bind(EffectWindow *window, qreal scale) const;
    void Unbind() const;
    inline std::unique_ptr<GLShader> &GetShader() { return m_shader; }

private:
    std::unique_ptr<GLShader> m_shader;
    ShaderManager *m_manager;
    int m_shader_windowSize = 0;
    int m_shader_windowExpandedSize = 0;
    int m_shader_windowTopLeft = 0;
    int m_shader_shadowArea = 0;
    int m_shader_shadowColor = 0;
    int m_shader_shadowSize = 0;
    int m_shader_radius = 0;
    int m_shader_outlineColor = 0;
    int m_shader_outlineThickness = 0;
    int m_shader_front = 0;

    float m_shadowRadius;
    float m_shadowBorder_active;
    float m_shadowBorder_inactive;
    QPointF m_shadowShift_active;
    QPointF m_shadowShift_inactive;
    float m_shadowAlphaF_active;
    float m_shadowAlphaF_inactive;
    float m_borderAlphaF;
    QColor m_borderActiveColor;
    QColor m_borderInactiveColor;
    QColor m_shadowActiveColor;
    QColor m_shadowInactiveColor;
};

}

#endif // KWIN4_SHAPECORNERS_CONFIG_SHADERMANAGER_H
