2
* Copyright 2016 Canonical Ltd.
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.
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.
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/>.
16
* Authored by Florian Boucault <florian.boucault@canonical.com>
20
import Ubuntu.Components 1.3
25
implicitWidth: texture.width
26
implicitHeight: texture.height
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();
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
44
property var progressTexture: progressTexture
45
property int progressTextureSize: progressTexture.size
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;
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;
65
// TODO: not the most efficient; could be replaced with an image provider
69
property int size: 128
71
layer.sourceRect: Qt.rect(0, 0, size, 1)
72
layer.textureSize: Qt.size(size, 1)
73
layer.wrapMode: ShaderEffectSource.ClampToEdge
77
model: segmentRenderer.segmentsCount
82
color: Qt.rgba(progress, progress, progress, 1.0)
83
property real progress
84
property NumberAnimation animation: NumberAnimation {
89
duration: UbuntuAnimation.SleepyDuration
90
easing: UbuntuAnimation.StandardEasing