summaryrefslogtreecommitdiffstats
path: root/src/base/Colour.h
blob: 294dde81aa0135b94d8ee600c1e02b19ce1c3ffe (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
/*
    Rosegarden
    A sequencer and musical notation editor.

    This program is Copyright 2000-2008
        Guillaume Laurent   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <bownie@bownie.com>

    This file is Copyright 2003
        Mark Hymers         <markh@linuxfromscratch.org>

    The moral right of the authors to claim authorship of this work
    has been asserted.

    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.  See the file
    COPYING included with this distribution for more information.
*/

#ifndef _BASE_COLOUR_H_
#define _BASE_COLOUR_H_

#include <string>

namespace Rosegarden 
{

/**
 * Colour is our internal colour storage mechanism; it's extremely basic
 * but does what it needs to
 */

class Colour
{
public:
    /**
     * Create a Colour with values initialised to r=0, g=0, b=0
     * i.e. Black. 
     */
    Colour();

    /**
     * Create a Colour with the specified red, green, blue values.
     * If out of specification (i.e. < 0 || > 255 the value will be set to 0.
     */
    Colour(unsigned int red, unsigned int green, unsigned int blue);
    Colour(const Colour& input);

    ~Colour();
    Colour& operator= (const Colour& input);

    /**
     * Set the colour as appropriate; as with the constructor invalid values
     * will be set to 0.
     */
    void setColour(unsigned int red, unsigned int green, unsigned int blue);

    /**
     * Sets the three pointers to the values stored in the colour.
     */ 
    void getColour(unsigned int &red, unsigned int &green, unsigned int &blue) const;

    /**
     * Returns the current Red value of the colour as an integer.
     */
    unsigned int getRed() const;

    /**
     * Returns the current Blue value of the colour as an integer.
     */
    unsigned int getBlue() const;

    /**
     * Returns the current Green value of the colour as an integer.
     */
    unsigned int getGreen() const;

    /**
     * Sets the Red value of the current colour.  If the value isn't
     * between 0 and 255 inclusive, it will set to 0
     */
    void setRed(unsigned int input);

    /**
     * Sets the Blue value of the current colour.  If the value isn't
     * between 0 and 255 inclusive, it will set to 0
     */
    void setBlue(unsigned int input);

    /**
     * Sets the Green value of the current colour.  If the value isn't
     * between 0 and 255 inclusive, it will set to 0
     */
    void setGreen(unsigned int input);

    /**
     * This uses a simple calculation to give us a contrasting colour.
     * Useful for working out a visible text colour given
     * any background colour
     */
    Colour getContrastingColour() const;

    std::string toXmlString() const;

    std::string dataToXmlString() const;

private:
    unsigned int m_r, m_g, m_b;
};

    /**
     * This works out a colour which is directly in between the two inputs.
     * Useful for working out what overlapping Segments should be coloured as
     */
    Colour getCombinationColour(const Colour &input1, const Colour &input2);

}

#endif