summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/effects/color.js
blob: 1f4bdf4a4427d8b0c95c976f2fe3c457fae431a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import GObject from 'gi://GObject';

import * as utils from '../conveniences/utils.js';

const Shell = await utils.import_in_shell_only('gi://Shell');
const Clutter = await utils.import_in_shell_only('gi://Clutter');

const SHADER_FILENAME = 'color.glsl';
const DEFAULT_PARAMS = {
    color: [0.0, 0.0, 0.0, 0.0],
    blend_mode: 0
};


export const ColorEffect = utils.IS_IN_PREFERENCES ?
    { default_params: DEFAULT_PARAMS } :
    new GObject.registerClass({
        GTypeName: "ColorEffect",
        Properties: {
            'red': GObject.ParamSpec.double(
                `red`,
                `Red`,
                `Red value in shader`,
                GObject.ParamFlags.READWRITE,
                0.0, 1.0,
                0.0,
            ),
            'green': GObject.ParamSpec.double(
                `green`,
                `Green`,
                `Green value in shader`,
                GObject.ParamFlags.READWRITE,
                0.0, 1.0,
                0.0,
            ),
            'blue': GObject.ParamSpec.double(
                `blue`,
                `Blue`,
                `Blue value in shader`,
                GObject.ParamFlags.READWRITE,
                0.0, 1.0,
                0.0,
            ),
            'blend': GObject.ParamSpec.double(
                `blend`,
                `Blend`,
                `Amount of blending between the colors`,
                GObject.ParamFlags.READWRITE,
                0.0, 1.0,
                0.0,
            ),
            'blend_mode': GObject.ParamSpec.int(
                `blend_mode`,
                `Blend mode`,
                `Blend mode`,
                GObject.ParamFlags.READWRITE,
                0, 17,
                0,
            )
        }
        // Normal (0), Multiply (1), Screen (2), Overlay (3), Darken (4), Lighten (5), Plus darker (6), Plus lighter (7), Color dodge (8),
        // Color burn (9), Hard light (10), Soft light (11), Difference (12), Exclusion (13), Hue (14), Saturation (15), Color (16),
        // Luminosity (17)
    }, class ColorEffect extends Clutter.ShaderEffect {
        constructor(params) {
            // initialize without color as a parameter
            const { color, ...parent_params } = params;
            super(parent_params);

            this._red = null;
            this._green = null;
            this._blue = null;
            this._blend = null;
            this._blend_mode = null;

            // set shader source
            this._source = utils.get_shader_source(Shell, SHADER_FILENAME, import.meta.url);
            if (this._source)
                this.set_shader_source(this._source);

            // set params; utils.setup_params doesn't work here with color
            this.color = 'color' in params ? color : this.constructor.default_params.color;
            this.blend_mode = 'blend_mode' in params ?  params.blend_mode : this.constructor.default_params.blend_mode;
        }

        static get default_params() {
            return DEFAULT_PARAMS;
        }

        get red() {
            return this._red;
        }

        set red(value) {
            if (this._red !== value) {
                this._red = value;

                this.set_uniform_value('red', parseFloat(this._red - 1e-6));
            }
        }

        get green() {
            return this._green;
        }

        set green(value) {
            if (this._green !== value) {
                this._green = value;

                this.set_uniform_value('green', parseFloat(this._green - 1e-6));
            }
        }

        get blue() {
            return this._blue;
        }

        set blue(value) {
            if (this._blue !== value) {
                this._blue = value;

                this.set_uniform_value('blue', parseFloat(this._blue - 1e-6));
            }
        }

        get blend() {
            return this._blend;
        }

        set blend(value) {
            if (this._blend !== value) {
                this._blend = value;

                this.set_uniform_value('blend', parseFloat(this._blend - 1e-6));
                this.set_enabled(this.blend > 0);
            }
        }

        get blend_mode() {
            return this._blend_mode;
        }

        set blend_mode(value) {
            if (this._blend_mode !== value) {
                this._blend_mode = value;

                this.set_uniform_value('mode', this._blend_mode);
            }
        }

        set color(rgba) {
            let [r, g, b, a] = rgba;
            this.red = r;
            this.green = g;
            this.blue = b;
            this.blend = a;
        }

        get color() {
            return [this.red, this.green, this.blue, this.blend];
        }

        /// False set function, only cares about the color. Too hard to change.
        set(params) {
            this.color = params.color;
            this.blend_mode = params.blend_mode;
        }
    });