summaryrefslogtreecommitdiffstats
path: root/kcoloredit/color.cpp
blob: eb06444b6b7c269b5e85f9f0675e35cebad5b972 (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
/***************************************************************************
                          color.cpp  -  description
                             -------------------
    begin                : Sun Jul 9 2000
    copyright            : (C) 2000 by Artur Rataj
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "color.h"

Color::Color(){
	setComponents(0, 0, 0);
	setName("");
}
Color::Color(const int red, const int green, const int blue, const TQString& name) {
	setComponents(red, green, blue);
	setName(name);
}
Color::~Color(){
}

void Color::setComponent(const int index, const int value) {
	m_components[index] = value;
}

void Color::setComponents(const int red, const int green, const int blue) {
	setComponent(RED_INDEX, red);
	setComponent(GREEN_INDEX, green);
	setComponent(BLUE_INDEX, blue);
}

void Color::setName(const TQString& name) {
	m_name = name;
}

int Color::component(const int index) const {
	return m_components[index];
}

const int* Color::components() const{
	return m_components;
}

const TQString& Color::name() const {
	return m_name;
}

bool Color::equals(const Color& color) {
	return component(RED_INDEX) == color.component(RED_INDEX) &&
		component(GREEN_INDEX) == color.component(GREEN_INDEX) &&
		component(BLUE_INDEX) == color.component(BLUE_INDEX);
}

void Color::modifyComponent(const int index, const int value, const double amount) {
	int comp = component(index);
	comp += (int)(value*amount + 0.5);
	if(comp > RGB_MAX_COMPONENT_VALUE)
		comp = RGB_MAX_COMPONENT_VALUE;
	else if(comp < 0)
		comp = 0;
	setComponent(index, comp);
}

void Color::modifyComponents(const int red, const int green, const int blue, const double amount) {
	modifyComponent(RED_INDEX, red, amount);
	modifyComponent(GREEN_INDEX, green, amount);
	modifyComponent(BLUE_INDEX, blue, amount);
}