1 /*
2     SuperCollider Qt IDE
3     Copyright (c) 2018 SuperCollider Team
4     https://supercollider.github.io/
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 
21 #include "color.hpp"
22 
23 namespace ScIDE { namespace color {
24 
lighten(const QColor & color,int amount)25 QColor lighten(const QColor& color, int amount) {
26     int value = color.value() + amount;
27 
28     if (value < 0) {
29         value = 0;
30     } else if (value > 255) {
31         value = 255;
32     }
33 
34     return QColor::fromHsv(color.hue(), color.saturation(), value);
35 }
36 
darken(const QColor & color,int amount)37 QColor darken(const QColor& color, int amount) { return lighten(color, -amount); }
38 
interpolate(const QColor & color_1,const QColor & color_2,float amount)39 QColor interpolate(const QColor& color_1, const QColor& color_2, float amount) {
40     return QColor(color_1.red() * (1 - amount) + color_2.red() * amount,
41                   color_1.green() * (1 - amount) + color_2.green() * amount,
42                   color_1.blue() * (1 - amount) + color_2.blue() * amount);
43 }
44 
setValue(const QColor & color,int value)45 QColor setValue(const QColor& color, int value) { return QColor::fromHsv(color.hue(), color.saturation(), value); }
46 
47 } // namespace color
48 } // namespace ScIDE
49