Permalink
Browse files

SkGui: Create WDeclarativeTexture

  • Loading branch information...
3unjee committed Apr 7, 2018
1 parent 275c108 commit a256a1813d946887570dec93105ef8c3df764cbc
@@ -14,6 +14,8 @@

## SkGui

- Create WDeclarativeTexture.

- Create WDeclarativeItemPaint.

#
@@ -18,6 +18,7 @@
#include "WDeclarativePlayer.h"
#include "WDeclarativeText.h"
#include "WDeclarativeTextSvg.h"
#include "WDeclarativeTexture.h"
#include "WAbstractView.h"
#include "WResizer.h"
#include "WView.h"
@@ -18,6 +18,7 @@
#include "WDeclarativePlayer.h"
#include "WDeclarativeText.h"
#include "WDeclarativeTextSvg.h"
#include "WDeclarativeTexture.h"
#include "WAbstractView.h"
#include "WResizer.h"
#include "WView.h"
@@ -0,0 +1 @@
#include "../../src/SkGui/src/declarative/WDeclarativeTexture.h"
@@ -0,0 +1 @@
#include "../../src/SkGui/src/declarative/WDeclarativeTexture.h"
@@ -0,0 +1 @@
#include "../../../src/SkGui/src/declarative/WDeclarativeTexture_p.h"
@@ -0,0 +1 @@
#include "../../../src/SkGui/src/declarative/WDeclarativeTexture_p.h"
@@ -115,7 +115,7 @@ class SK_GUI_EXPORT WDeclarativeBorderImage : public WDeclarativeImageBase

#ifdef QT_LATEST
protected: // WDeclarativeTexture reimplementation
virtual void applyGeometry(QSGInternalImageNode * node, const QPixmap & pixmap); /* {} */
virtual void applyGeometry(QSGInternalImageNode * node, const QPixmap & pixmap);
#endif

signals:
@@ -164,8 +164,6 @@ void WDeclarativeBordersPrivate::init()
#ifdef QT_4
q->setFlag(QGraphicsItem::ItemHasNoContents, false);
#elif defined(SK_SOFTWARE) == false
Q_Q(WDeclarativeBorders);

updateLeft = true;
updateRight = true;
updateTop = true;
@@ -110,7 +110,6 @@ class SK_GUI_EXPORT WDeclarativeImageSvg : public WDeclarativeTexture
#else
/* virtual */ void itemChange(ItemChange change, const ItemChangeData & value);

#ifdef QT_LATEST
/* virtual */ void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);

protected: // WDeclarativeTexture implementation
@@ -119,7 +118,6 @@ class SK_GUI_EXPORT WDeclarativeImageSvg : public WDeclarativeTexture
protected: // WDeclarativeTexture reimplementation
/*virtual */ void applyGeometry(QSGInternalImageNode * node, const QPixmap & pixmap);
#endif
#endif

signals:
void loaded();
@@ -126,9 +126,7 @@ class SK_GUI_EXPORT WDeclarativeTextSvg : public WDeclarativeTexture
/* virtual */ QVariant itemChange(GraphicsItemChange change, const QVariant & value);
#else
/* virtual */ void itemChange(ItemChange change, const ItemChangeData & value);
#endif

#ifdef QT_LATEST
/* virtual */ void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);

protected: // WDeclarativeTexture implementation
@@ -137,7 +135,6 @@ class SK_GUI_EXPORT WDeclarativeTextSvg : public WDeclarativeTexture
protected: // WDeclarativeTexture reimplementation
/*virtual */ void applyGeometry(QSGInternalImageNode * node, const QPixmap & pixmap);
#endif
#endif

signals:
void textWidthChanged ();
@@ -0,0 +1,245 @@
//=================================================================================================
/*
Copyright (C) 2015-2017 Sky kit authors united with omega. <http://omega.gg/about>
Author: Benjamin Arnaud. <http://bunjee.me> <bunjee@omega.gg>
This file is part of the SkGui module of Sky kit.
- GNU General Public License Usage:
This file may be used under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation and appearing in the LICENSE.md file included in the packaging
of this file. Please review the following information to ensure the GNU General Public License
requirements will be met: https://www.gnu.org/licenses/gpl.html.
*/
//=================================================================================================

#include "WDeclarativeTexture.h"

#ifndef SK_NO_DECLARATIVETEXTURE

// Sk includes
#include <WView>

// Private includes
#include <private/qquickwindow_p.h>
#include <private/qsgadaptationlayer_p.h>

//-------------------------------------------------------------------------------------------------
// Private
//-------------------------------------------------------------------------------------------------

#include "WDeclarativeTexture_p.h"

WDeclarativeTexturePrivate::WDeclarativeTexturePrivate(WDeclarativeTexture * p)
: WDeclarativeItemPrivate(p) {}

/* virtual */ WDeclarativeTexturePrivate::~WDeclarativeTexturePrivate()
{
if (texture) texture->deleteLater();
}

//-------------------------------------------------------------------------------------------------

void WDeclarativeTexturePrivate::init()
{
Q_Q(WDeclarativeTexture);

context = NULL;
texture = NULL;

updateTexture = false;
updateGeometry = false;
updateMipmap = false;

mipmap = false;

q->setFlag(QQuickItem::ItemHasContents);
}

//-------------------------------------------------------------------------------------------------
// Private functions
//-------------------------------------------------------------------------------------------------

void WDeclarativeTexturePrivate::applyMipmap(QSGInternalImageNode * node)
{
updateMipmap = false;

if (mipmap)
{
node->setMipmapFiltering(QSGTexture::Linear);
}
else node->setMipmapFiltering(QSGTexture::None);
}

//-------------------------------------------------------------------------------------------------
// Ctor / dtor
//-------------------------------------------------------------------------------------------------

/* explicit */ WDeclarativeTexture::WDeclarativeTexture(QQuickItem * parent)
: WDeclarativeItem(new WDeclarativeTexturePrivate(this), parent)
{
Q_D(WDeclarativeTexture); d->init();
}

//-------------------------------------------------------------------------------------------------
// Protected

WDeclarativeTexture::WDeclarativeTexture(WDeclarativeTexturePrivate * p, QQuickItem * parent)
: WDeclarativeItem(p, parent)
{
Q_D(WDeclarativeTexture); d->init();
}

//-------------------------------------------------------------------------------------------------
// QQuickItem reimplementation
//-------------------------------------------------------------------------------------------------

/* virtual */ QSGNode * WDeclarativeTexture::updatePaintNode(QSGNode * oldNode,
UpdatePaintNodeData *)
{
const QPixmap & pixmap = getPixmap();

if (pixmap.isNull() || width() < 1 || height() < 1)
{
if (oldNode)
{
Q_D(WDeclarativeTexture);

delete oldNode;

delete d->texture;

d->texture = NULL;
}

return NULL;
}

Q_D(WDeclarativeTexture);

QSGInternalImageNode * node;

if (oldNode)
{
node = static_cast<QSGInternalImageNode *> (oldNode);

if (d->updateTexture)
{
if (d->updateMipmap) d->applyMipmap(node);

d->updateTexture = false;
d->updateGeometry = false;

if (d->texture) delete d->texture;

d->texture = d->view->createTextureFromImage(pixmap.toImage());

node->setTexture(d->texture);

applyGeometry(node, pixmap);

node->update();
}
else if (d->updateGeometry)
{
if (d->updateMipmap) d->applyMipmap(node);

d->updateGeometry = false;

applyGeometry(node, pixmap);

node->update();
}
else if (d->updateMipmap)
{
d->applyMipmap(node);

node->update();
}
}
else
{
node = d->context->createInternalImageNode();

node->setFiltering(QSGTexture::Linear);

d->applyMipmap(node);

d->updateTexture = false;
d->updateGeometry = false;

d->texture = d->view->createTextureFromImage(pixmap.toImage());

node->setTexture(d->texture);

applyGeometry(node, pixmap);

node->update();
}

return node;
}

//-------------------------------------------------------------------------------------------------
// Protected virtual functions
//-------------------------------------------------------------------------------------------------

/* virtual */ void WDeclarativeTexture::applyGeometry(QSGInternalImageNode * node, const QPixmap &)
{
QRectF rect = boundingRect();

node->setTargetRect (rect);
node->setInnerTargetRect(rect);
}

//-------------------------------------------------------------------------------------------------
// Protected QQuickItem reimplementation
//-------------------------------------------------------------------------------------------------

/* virtual */ void WDeclarativeTexture::itemChange(ItemChange change, const ItemChangeData & value)
{
if (change == ItemSceneChange)
{
Q_D(WDeclarativeTexture);

QQuickWindow * window = value.window;

if (window)
{
QQuickWindowPrivate * p
= static_cast<QQuickWindowPrivate *> (QObjectPrivate::get(window));

d->context = p->context->sceneGraphContext();
}
else d->context = NULL;
}

WDeclarativeItem::itemChange(change, value);
}

//-------------------------------------------------------------------------------------------------
// Properties
//-------------------------------------------------------------------------------------------------

bool WDeclarativeTexture::mipmap() const
{
Q_D(const WDeclarativeTexture); return d->mipmap;
}

void WDeclarativeTexture::setMipmap(bool enabled)
{
Q_D(WDeclarativeTexture);

if (d->mipmap == enabled) return;

d->mipmap = enabled;

d->updateMipmap = true;

update();

emit mipmapChanged();
}

#endif // SK_NO_DECLARATIVETEXTURE
@@ -0,0 +1,64 @@
//=================================================================================================
/*
Copyright (C) 2015-2017 Sky kit authors united with omega. <http://omega.gg/about>
Author: Benjamin Arnaud. <http://bunjee.me> <bunjee@omega.gg>
This file is part of the SkGui module of Sky kit.
- GNU General Public License Usage:
This file may be used under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation and appearing in the LICENSE.md file included in the packaging
of this file. Please review the following information to ensure the GNU General Public License
requirements will be met: https://www.gnu.org/licenses/gpl.html.
*/
//=================================================================================================

#ifndef WDECLARATIVETEXTURE_H
#define WDECLARATIVETEXTURE_H

// Sk includes
#include <WDeclarativeItem>

#ifndef SK_NO_DECLARATIVETEXTURE

// Forward declarations
class QSGInternalImageNode;
class WDeclarativeTexturePrivate;

class SK_GUI_EXPORT WDeclarativeTexture : public WDeclarativeItem
{
Q_OBJECT

Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)

public:
explicit WDeclarativeTexture(QQuickItem * parent = NULL);
protected:
WDeclarativeTexture(WDeclarativeTexturePrivate * p, QQuickItem * parent = NULL);

public: // QQuickItem reimplementation
/* virtual */ QSGNode * updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data);

protected: // Abstract functions
virtual const QPixmap & getPixmap() = 0;

protected: // Virtual functions
virtual void applyGeometry(QSGInternalImageNode * node, const QPixmap & pixmap);

protected: // QQuickItem reimplementation
/* virtual */ void itemChange(ItemChange change, const ItemChangeData & value);

signals:
void mipmapChanged();

public: // Properties
bool mipmap() const;
void setMipmap(bool enabled);

private:
W_DECLARE_PRIVATE(WDeclarativeTexture)
};

#endif // SK_NO_DECLARATIVETEXTURE
#endif // WDECLARATIVETEXTURE_H
Oops, something went wrong.

0 comments on commit a256a18

Please sign in to comment.