C

Qt Quick Ultralite traveo_t2g_effects Example

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

#include <qul/painteditemdelegate.h>
#include <qul/image.h>

#include <platforminterface/drawingdevice.h>
#include <platforminterface/rect.h>
#include <platforminterface/rgba32.h>

#ifdef QUL_TVIIC_PLATFORM
#include <ut_class_surface.h>
#endif

class GaussianBlurDelegate : public Qul::PaintedItemDelegate
{
public:
    Qul::Property<double> blur;
    Qul::Property<Qul::SharedImage> source;

    void blurChanged();

    Qul::PlatformInterface::Rect boundingRect(Qul::PlatformInterface::Size size) const override;

    void paint(Qul::PlatformInterface::DrawingDevice *device,
               const Qul::PlatformInterface::Rect &clip,
               const Qul::PlatformInterface::Transform &transform,
               Qul::PlatformInterface::Size size,
               float opacity) const override;

private:
    float blurValue() const
    {
        if (blur.value() < 0)
            return 0;
        // Blur values above 2.5 cause graphical glitches on TRAVEO™ T2G
        if (blur.value() > 2.5)
            return 2.5;
        return blur.value();
    }

    mutable bool m_initialized = false;
    mutable bool m_blurDirty = true;
#ifdef QUL_TVIIC_PLATFORM
    mutable CSurface<1> m_source;
    mutable CSurface<1> m_blurred[3];
    mutable int m_index = 0;
#endif
};