File : controls/colorControl/RedSliderInputEL.js

1
2
/*
3
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
4
5
This  program is free software;
6
you can redistribute it and/or modify it under the terms of the
7
GNU General Public License as published by the Free Software Foundation;
8
either version 3 of the License, or any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
*/
19
/*
20
Changes:
21
    - v4.0.0:
22
        - created from v3.6.0
23
Doc reviewed 202208
24
 */
25
26
/* ------------------------------------------------------------------------------------------------------------------------- */
27
/**
28
Input event listener for the red slider
29
*/
30
/* ------------------------------------------------------------------------------------------------------------------------- */
31
32
class RedSliderInputEL {
33
34
    /**
35
    A reference to the ColorControl object
36
    @type {ColorControl}
37
    */
38
39
    #colorControl;
40
41
    /**
42
    A coefficient to use to transform the slider value into a color value
43
    Slider value are from 0 to RedSliderControlElement.SLIDER_MAX_VALUE, Color values are from 0 to Color.MAX_COLOR
44
    @type {Number}
45
    */
46
47
    #colorCoef;
48
49
    /**
50
    The constructor
51
    @param {ColorControl} colorControl A reference to the ColorControl object
52
    @param {Number} colorCoef A coefficient to use to transform the slider value into a color value
53
    */
54
55
    constructor ( colorControl, colorCoef ) {
56
        Object.freeze ( this );
57
        this.#colorControl = colorControl;
58
        this.#colorCoef = colorCoef;
59
    }
60
61
    /**
62
    Event listener
63
    @param {Event} inputEvent The event to handle
64
    */
65
66
    handleEvent ( inputEvent ) {
67
        inputEvent.stopPropagation ( );
68
69
        let red = inputEvent.target.valueAsNumber * this.#colorCoef;
70
71
        // With js 100 * 2.55 = 254.99999999
72
        red = red - Math.floor ( red ) < Math.ceil ( red ) - red
73
            ?
74
            Math.floor ( red )
75
            :
76
            Math.ceil ( red );
77
78
        this.#colorControl.onRedSliderInput ( red );
79
    }
80
}
81
82
export default RedSliderInputEL;
83
84
/* --- End of file --------------------------------------------------------------------------------------------------------- */
85