Skip to content

Commit

Permalink
SkGui: Create WDeclarativeTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
3unjee committed Apr 7, 2018
1 parent 275c108 commit a256a18
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 8 deletions.
2 changes: 2 additions & 0 deletions dist/changes/1.3.1.md
Expand Up @@ -14,6 +14,8 @@

## SkGui

- Create WDeclarativeTexture.

- Create WDeclarativeItemPaint.

#
Expand Down
1 change: 1 addition & 0 deletions include/SkGui/SkGui
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/SkGui/SkGui.h
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/SkGui/WDeclarativeTexture
@@ -0,0 +1 @@
#include "../../src/SkGui/src/declarative/WDeclarativeTexture.h"
1 change: 1 addition & 0 deletions include/SkGui/WDeclarativeTexture.h
@@ -0,0 +1 @@
#include "../../src/SkGui/src/declarative/WDeclarativeTexture.h"
1 change: 1 addition & 0 deletions include/SkGui/private/WDeclarativeTexture_p
@@ -0,0 +1 @@
#include "../../../src/SkGui/src/declarative/WDeclarativeTexture_p.h"
1 change: 1 addition & 0 deletions include/SkGui/private/WDeclarativeTexture_p.h
@@ -0,0 +1 @@
#include "../../../src/SkGui/src/declarative/WDeclarativeTexture_p.h"
2 changes: 1 addition & 1 deletion src/SkGui/src/declarative/WDeclarativeBorderImage.h
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/SkGui/src/declarative/WDeclarativeBorders.cpp
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/SkGui/src/declarative/WDeclarativeImageSvg.h
Expand Up @@ -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
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/SkGui/src/declarative/WDeclarativeTextSvg.h
Expand Up @@ -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
Expand All @@ -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 ();
Expand Down
245 changes: 245 additions & 0 deletions src/SkGui/src/declarative/WDeclarativeTexture.cpp
@@ -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
64 changes: 64 additions & 0 deletions src/SkGui/src/declarative/WDeclarativeTexture.h
@@ -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

0 comments on commit a256a18

Please sign in to comment.