on dd024c8 help sign in
unity8/Components/OpenEffect.qml
130 lines 4.0 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 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 }
36 /*!
37 \qmlproperty real positionPx
38 The y coordinate of where to perform the split.
40 \qmlproperty real topGapPx
41 Gap's top edge.
43 \qmlproperty real bottomGapPx
44 Gap's bottom edge.
46 \qmlproperty real topOverflow
47 How much of the sourceItem should be sourced above its bounds.
49 \qmlproperty real bottomOverflow
50 How much of the sourceItem should be sourced below its bounds.
51 */
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
61 property real __roundedPositionPx: Math.round(positionPx)
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
71 clip: true
73 anchors {
74 top: parent.top
75 left: parent.left
76 right: parent.right
77 topMargin: -topOverflow - positionPx + topGapPx
78 }
79 height: topOverflow + positionPx
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;
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 }
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
105 clip: true
107 anchors {
108 left: parent.left
109 right: parent.right
110 }
111 y: topOverflow + bottomGapPx
112 height: sourceItem.height - positionPx + bottomOverflow
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;
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 }