VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
ParallaxTransformItem.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PARALLAXTRANSFORMITEM_H
18 #define PARALLAXTRANSFORMITEM_H
19 
20 #include <QQuickItem>
21 
22 class Actor;
23 
39  Q_OBJECT
40 
49  Q_PROPERTY(float zDepth READ getZDepth WRITE setZDepth NOTIFY zDepthChanged)
50 
51 public:
55  constexpr static const float REFERENCE_DEPTH = 1.0f;
56 
62  virtual ~ParallaxTransformItem();
63 
67  float getZDepth() const { return mZDepth; }
72  void setZDepth(float value);
73 
74 signals:
78  void zDepthChanged();
79 
80 protected:
84  virtual void componentComplete() override;
85 
86 private:
87  void updateItemOffset();
88  void updateProjectionRatio();
89 
90  Actor* mActor = nullptr;
91  float mZDepth = REFERENCE_DEPTH;
92  float mZProjectionRatioX = 0.0f;
93  float mZProjectionRatioY = 0.0f;
94 };
95 Q_DECLARE_METATYPE(ParallaxTransformItem*)
96 
97 #endif // PARALLAXTRANSFORMITEM_H
void setZDepth(float value)
Sets zDepth.
static constexpr const float REFERENCE_DEPTH
The zDepth which appears to be foreground, and no parallax is apparent.
Definition: ParallaxTransformItem.h:55
float getZDepth() const
Returns zDepth.
Definition: ParallaxTransformItem.h:67
QQuickItem which applies a translation to children, giving the illusion of parallax scrolling...
Definition: ParallaxTransformItem.h:38
virtual void componentComplete() override
Override of QQuickItem::componentComplete() to perform additional initialization. ...
ParallaxTransformItem(QQuickItem *parent=0)
Construct a ParallaxTransformItem.
void zDepthChanged()
Emitted when zDepth changes.
Representation of an entity within the Game scene.
Definition: Actor.h:40
QObject * parent() const
float zDepth
The distance into the background (or foreground) that this QQuickItem appears for the purpose of comp...
Definition: ParallaxTransformItem.h:49