~unity-team/unity8/trunk

« back to all changes in this revision

Viewing changes to Components/OpenEffect.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
 
 
19
Item {
 
20
    id: effect
 
21
    property bool enabled: topGapPx != positionPx || bottomGapPx != positionPx
 
22
    property Item sourceItem
 
23
    property ShaderEffectSource source: ShaderEffectSource {
 
24
        sourceItem: effect.enabled ? effect.sourceItem : null
 
25
        hideSource: effect.enabled
 
26
        live: effect.enabled
 
27
        sourceRect: {
 
28
          if (effect.enabled) {
 
29
            Qt.rect(0, -effect.topOverflow, sourceItem.width, sourceItem.height + effect.topOverflow + effect.bottomOverflow)
 
30
          } else {
 
31
            Qt.rect(0, 0, 0, 0)
 
32
          }
 
33
        }
 
34
    }
 
35
 
 
36
    /*!
 
37
    \qmlproperty real positionPx
 
38
    The y coordinate of where to perform the split.
 
39
 
 
40
    \qmlproperty real topGapPx
 
41
    Gap's top edge.
 
42
 
 
43
    \qmlproperty real bottomGapPx
 
44
    Gap's bottom edge.
 
45
 
 
46
    \qmlproperty real topOverflow
 
47
    How much of the sourceItem should be sourced above its bounds.
 
48
 
 
49
    \qmlproperty real bottomOverflow
 
50
    How much of the sourceItem should be sourced below its bounds.
 
51
    */
 
52
 
 
53
    property real positionPx: 0
 
54
    property real topGapPx: 0
 
55
    property real bottomGapPx: height
 
56
    property real topOverflow: 0.0
 
57
    property real bottomOverflow: 0.0
 
58
    property real topOpacity: 1.0
 
59
    property real bottomOpacity: 1.0
 
60
 
 
61
    property real __roundedPositionPx: Math.round(positionPx)
 
62
 
 
63
    ShaderEffect {
 
64
        id: top
 
65
        visible: effect.enabled
 
66
        opacity: topOpacity
 
67
        property ShaderEffectSource source: effect.source
 
68
        property real positionPx: __roundedPositionPx
 
69
        property real factor: effect.height / height
 
70
 
 
71
        clip: true
 
72
 
 
73
        anchors {
 
74
            top: parent.top
 
75
            left: parent.left
 
76
            right: parent.right
 
77
            topMargin: -topOverflow - positionPx + topGapPx
 
78
        }
 
79
        height: topOverflow + positionPx
 
80
 
 
81
        vertexShader: "
 
82
            uniform highp mat4 qt_Matrix;
 
83
            attribute highp vec4 qt_Vertex;
 
84
            attribute highp vec2 qt_MultiTexCoord0;
 
85
            varying highp vec2 qt_TexCoord0;
 
86
            uniform highp float factor;
 
87
 
 
88
            void main() {
 
89
                highp vec4 pos = qt_Vertex;
 
90
                pos.y *= factor;
 
91
                gl_Position = qt_Matrix * pos;
 
92
                qt_TexCoord0 = qt_MultiTexCoord0;
 
93
            }
 
94
        "
 
95
    }
 
96
 
 
97
    ShaderEffect {
 
98
        id: bottom
 
99
        visible: effect.enabled
 
100
        opacity: bottomOpacity
 
101
        property ShaderEffectSource source: effect.source
 
102
        property real offset: effect.topOverflow + __roundedPositionPx
 
103
        property real factor: effect.height / height
 
104
 
 
105
        clip: true
 
106
 
 
107
        anchors {
 
108
            left: parent.left
 
109
            right: parent.right
 
110
        }
 
111
        y: topOverflow + bottomGapPx
 
112
        height: sourceItem.height - positionPx + bottomOverflow
 
113
 
 
114
        vertexShader: "
 
115
            uniform highp mat4 qt_Matrix;
 
116
            attribute highp vec4 qt_Vertex;
 
117
            attribute highp vec2 qt_MultiTexCoord0;
 
118
            varying highp vec2 qt_TexCoord0;
 
119
            uniform highp float factor;
 
120
            uniform highp float offset;
 
121
 
 
122
            void main() {
 
123
                highp vec4 pos = qt_Vertex;
 
124
                pos.y = (pos.y * factor) - offset;
 
125
                gl_Position = qt_Matrix * pos;
 
126
                qt_TexCoord0 = qt_MultiTexCoord0;
 
127
            }
 
128
        "
 
129
    }
 
130
}