on fbf656a help sign in
unity8/Components/OpenEffect.qml
138 lines 4.2 kB history raw
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 */
17import QtQuick 2.0
19Item {
20 id: effect
21 property bool enabled: topGapPx != positionPx || bottomGapPx != positionPx
22 property alias live: effectSource.live
23 property Item sourceItem
24 property ShaderEffectSource source: ShaderEffectSource {
25 id: effectSource
26 sourceItem: effect.enabled ? effect.sourceItem : null
27 hideSource: effect.enabled
28 live: false
29 sourceRect: {
30 if (effect.enabled) {
31 Qt.rect(0, -effect.topOverflow, sourceItem.width, sourceItem.height + effect.topOverflow + effect.bottomOverflow)
32 } else {
33 Qt.rect(0, 0, 0, 0)
34 }
35 }
36 }
38 onEnabledChanged: if (!live && enabled) scheduleUpdate()
40 /*!
41 \qmlproperty real positionPx
42 The y coordinate of where to perform the split.
44 \qmlproperty real topGapPx
45 Gap's top edge.
47 \qmlproperty real bottomGapPx
48 Gap's bottom edge.
50 \qmlproperty real topOverflow
51 How much of the sourceItem should be sourced above its bounds.
53 \qmlproperty real bottomOverflow
54 How much of the sourceItem should be sourced below its bounds.
55 */
57 property real positionPx: 0
58 property real topGapPx: 0
59 property real bottomGapPx: height
60 property real topOverflow: 0.0
61 property real bottomOverflow: 0.0
62 property real topOpacity: 1.0
63 property real bottomOpacity: 1.0
65 property real __roundedPositionPx: Math.round(positionPx)
67 function scheduleUpdate() {
68 source.scheduleUpdate();
69 }
71 ShaderEffect {
72 id: top
73 visible: effect.enabled
74 opacity: topOpacity
75 property ShaderEffectSource source: effect.source
76 property real positionPx: __roundedPositionPx
77 property real factor: effect.height / height
79 clip: true
81 anchors {
82 top: parent.top
83 left: parent.left
84 right: parent.right
85 topMargin: -topOverflow - positionPx + topGapPx
86 }
87 height: topOverflow + positionPx
89 vertexShader: "
90 uniform highp mat4 qt_Matrix;
91 attribute highp vec4 qt_Vertex;
92 attribute highp vec2 qt_MultiTexCoord0;
93 varying highp vec2 qt_TexCoord0;
94 uniform highp float factor;
96 void main() {
97 highp vec4 pos = qt_Vertex;
98 pos.y *= factor;
99 gl_Position = qt_Matrix * pos;
100 qt_TexCoord0 = qt_MultiTexCoord0;
101 }
102 "
103 }
105 ShaderEffect {
106 id: bottom
107 visible: effect.enabled
108 opacity: bottomOpacity
109 property ShaderEffectSource source: effect.source
110 property real offset: effect.topOverflow + __roundedPositionPx
111 property real factor: effect.height / height
113 clip: true
115 anchors {
116 left: parent.left
117 right: parent.right
118 }
119 y: topOverflow + bottomGapPx
120 height: sourceItem.height - positionPx + bottomOverflow
122 vertexShader: "
123 uniform highp mat4 qt_Matrix;
124 attribute highp vec4 qt_Vertex;
125 attribute highp vec2 qt_MultiTexCoord0;
126 varying highp vec2 qt_TexCoord0;
127 uniform highp float factor;
128 uniform highp float offset;
130 void main() {
131 highp vec4 pos = qt_Vertex;
132 pos.y = (pos.y * factor) - offset;
133 gl_Position = qt_Matrix * pos;
134 qt_TexCoord0 = qt_MultiTexCoord0;
135 }
136 "
137 }