#include "qwaylandukuieffectv1_p.h"

namespace QtWaylandClient
{
// QWaylandUkuiEffectV1 Implementation
QWaylandUkuiEffectV1::QWaylandUkuiEffectV1(struct ::wl_registry *registry, uint32_t id, uint32_t availableVersion)
    : QtWayland::ukui_effect_v1(registry, id, qMin<uint32_t>(availableVersion, interface()->version))
{
}

QWaylandUkuiEffectV1::~QWaylandUkuiEffectV1()
{
}

QWaylandAnimationCurveV1 *QWaylandUkuiEffectV1::createAnimationCurve(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2)
{
    for (const auto &pair : m_animationCurves) {
        if (pair.first == QVector4D(x1, y1, x2, y2))
            return pair.second;
    }

    QWaylandAnimationCurveV1 *curve = new QWaylandAnimationCurveV1(ukui_effect_v1_create_animation_curve(object(), x1, y1, x2, y2));
    m_animationCurves.append(QPair<QVector4D, QWaylandAnimationCurveV1 *>(QVector4D(x1, y1, x2, y2), curve));
    return curve;
}

QWaylandFadeEffectV1 *QWaylandUkuiEffectV1::createFadeEffect(struct ::wl_surface *surface, uint32_t stage)
{
    return new QWaylandFadeEffectV1(ukui_effect_v1_create_fade_effect(object(), surface, stage));
}

QWaylandSlideEffectV1 *QWaylandUkuiEffectV1::createSlideEffect(struct ::wl_surface *surface, uint32_t stage)
{
    return new QWaylandSlideEffectV1(ukui_effect_v1_create_slide_effect(object(), surface, stage));
}

void QWaylandUkuiEffectV1::ukui_effect_v1_builtin_animation_curves(struct ::animation_curve_v1 *animation, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2)
{
    m_animationCurves.append(QPair<QVector4D, QWaylandAnimationCurveV1 *>(QVector4D(x1, y1, x2, y2), new QWaylandAnimationCurveV1(animation)));
}

void QWaylandUkuiEffectV1::ukui_effect_v1_done()
{
    m_done = true;
}

// QWaylandAnimationCurveV1 Implementation
QWaylandAnimationCurveV1::QWaylandAnimationCurveV1(::animation_curve_v1 *curve)
    : QtWayland::animation_curve_v1(curve)
{
}

QWaylandAnimationCurveV1::~QWaylandAnimationCurveV1()
{
    destroy();
}

// QWaylandFadeEffectV1 Implementation
QWaylandFadeEffectV1::QWaylandFadeEffectV1(::fade_effect_v1 *effect)
    : QtWayland::fade_effect_v1(effect)
{
}

QWaylandFadeEffectV1::~QWaylandFadeEffectV1()
{
    destroy();
}

// QWaylandSlideEffectV1 Implementation
QWaylandSlideEffectV1::QWaylandSlideEffectV1(::slide_effect_v1 *effect)
    : QtWayland::slide_effect_v1(effect)
{
}

QWaylandSlideEffectV1::~QWaylandSlideEffectV1()
{
    destroy();
}

}