~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-yakkety-1895

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Settings/Fingerprint/SegmentRenderer.qml

  • Committer: Bileto Bot
  • Date: 2016-06-20 14:01:03 UTC
  • mfrom: (103.6.69 fingerprint)
  • Revision ID: ci-train-bot@canonical.com-20160620140103-q57lulbze89e6yyd
jonas-drange
* Add components for Fingerprint management.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by  Florian Boucault <florian.boucault@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import Ubuntu.Components 1.3
 
21
 
 
22
ShaderEffect {
 
23
    id: segmentRenderer
 
24
 
 
25
    implicitWidth: texture.width
 
26
    implicitHeight: texture.height
 
27
 
 
28
    function animate(segments) {
 
29
        for (var i in segments) {
 
30
            var progressPixel = progressTexture.children[segments[i]];
 
31
            if (progressPixel.progress == 0.0) {
 
32
                progressPixel.animation.start();
 
33
            }
 
34
        }
 
35
    }
 
36
 
 
37
    property string source
 
38
    property int segmentsCount
 
39
    property color backgroundColor: theme.palette.normal.base
 
40
    property color fillColor: theme.palette.normal.activity
 
41
    property Image texture: Image {
 
42
        source: segmentRenderer.source
 
43
    }
 
44
    property var progressTexture: progressTexture
 
45
    property int progressTextureSize: progressTexture.size
 
46
 
 
47
    fragmentShader: "
 
48
        varying mediump vec2 qt_TexCoord0;
 
49
        uniform lowp float qt_Opacity;
 
50
        uniform lowp vec4 backgroundColor;
 
51
        uniform lowp vec4 fillColor;
 
52
        uniform lowp sampler2D texture;
 
53
        uniform lowp sampler2D progressTexture;
 
54
        uniform lowp int progressTextureSize;
 
55
 
 
56
        void main() {
 
57
            lowp vec4 p = texture2D(texture, qt_TexCoord0);
 
58
            lowp float segment = p.r * 255.0;
 
59
            lowp vec4 segmentProgress = step(0.9, segment) * texture2D(progressTexture, vec2((segment - 1.0 + 0.5) / float(progressTextureSize), 0.5));
 
60
            lowp vec4 color = mix(fillColor, backgroundColor, step(segmentProgress.r, p.g));
 
61
            gl_FragColor = vec4(color.rgb, 1.0) * p.b * qt_Opacity;
 
62
        }
 
63
    "
 
64
 
 
65
    // TODO: not the most efficient; could be replaced with an image provider
 
66
    Row {
 
67
        id: progressTexture
 
68
 
 
69
        property int size: 128
 
70
        layer.enabled: true
 
71
        layer.sourceRect: Qt.rect(0, 0, size, 1)
 
72
        layer.textureSize: Qt.size(size, 1)
 
73
        layer.wrapMode: ShaderEffectSource.ClampToEdge
 
74
        visible: false
 
75
 
 
76
        Repeater {
 
77
            model: segmentRenderer.segmentsCount
 
78
            Rectangle {
 
79
                id: progressPixel
 
80
                width: 1
 
81
                height: 1
 
82
                color: Qt.rgba(progress, progress, progress, 1.0)
 
83
                property real progress
 
84
                property NumberAnimation animation: NumberAnimation {
 
85
                    target: progressPixel
 
86
                    property: "progress"
 
87
                    from: 0.0
 
88
                    to: 1.0
 
89
                    duration: UbuntuAnimation.SleepyDuration
 
90
                    easing: UbuntuAnimation.StandardEasing
 
91
                }
 
92
            }
 
93
        }
 
94
    }
 
95
}