Update licenseheader text in source files for qtdeclarative Qt module
[profile/ivi/qtdeclarative.git] / src / declarative / scenegraph / util / qsgsimpletexturenode.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include "qsgsimpletexturenode.h"
44
45 QT_BEGIN_NAMESPACE
46
47 static void qsgsimpletexturenode_update(QSGGeometry *g,
48                                         QSGTexture *texture,
49                                         const QRectF &rect)
50 {
51     if (!texture)
52         return;
53
54     QSize ts = texture->textureSize();
55     QRectF sourceRect(0, 0, ts.width(), ts.height());
56     QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
57 }
58
59 /*!
60   \class QSGSimpleTextureNode
61   \brief The QSGSimpleTextureNode provided for convenience to easily draw
62   textured content using the QML scene graph.
63
64   \warning The simple texture node class must have texture before being
65   added to the scene graph to be rendered.
66 */
67
68 /*!
69     Constructs a new simple texture node
70  */
71 QSGSimpleTextureNode::QSGSimpleTextureNode()
72     : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
73 {
74     setGeometry(&m_geometry);
75     setMaterial(&m_material);
76     setOpaqueMaterial(&m_opaque_material);
77 }
78
79 /*!
80     Sets the filtering to be used for this texture node to \a filtering.
81
82     For smooth scaling, use QSGTexture::Linear; for normal scaling, use
83     QSGTexture::Nearest.
84  */
85 void QSGSimpleTextureNode::setFiltering(QSGTexture::Filtering filtering)
86 {
87     if (m_material.filtering() == filtering)
88         return;
89
90     m_material.setFiltering(filtering);
91     m_opaque_material.setFiltering(filtering);
92     markDirty(DirtyMaterial);
93 }
94
95
96 /*!
97     Returns the filtering currently set on this texture node
98  */
99 QSGTexture::Filtering QSGSimpleTextureNode::filtering() const
100 {
101     return m_material.filtering();
102 }
103
104
105 /*!
106     Sets the target rect of this texture node to \a r
107  */
108 void QSGSimpleTextureNode::setRect(const QRectF &r)
109 {
110     if (m_rect == r)
111         return;
112     m_rect = r;
113     qsgsimpletexturenode_update(&m_geometry, texture(), m_rect);
114     markDirty(DirtyGeometry);
115 }
116
117
118 /*!
119     Returns the target rect of this texture node.
120  */
121 QRectF QSGSimpleTextureNode::rect() const
122 {
123     return m_rect;
124 }
125
126 /*!
127     Sets the texture of this texture node to \a texture.
128
129     \warning A texture node must have a texture before being added
130     to the scenegraph to be rendered.
131  */
132 void QSGSimpleTextureNode::setTexture(QSGTexture *texture)
133 {
134     if (m_material.texture() == texture)
135         return;
136     m_material.setTexture(texture);
137     m_opaque_material.setTexture(texture);
138     qsgsimpletexturenode_update(&m_geometry, texture, m_rect);
139     markDirty(DirtyMaterial);
140 }
141
142
143
144 /*!
145     Returns the texture for this texture node
146  */
147 QSGTexture *QSGSimpleTextureNode::texture() const
148 {
149     return m_material.texture();
150 }
151
152 QT_END_NAMESPACE