~ubuntu-branches/ubuntu/lucid/gbrainy/lucid

« back to all changes in this revision

Viewing changes to src/Core/Main/ColorPalette.cs

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-01-12 11:21:24 UTC
  • mfrom: (13.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100112112124-o4ztomxa0xfh2ulj
Tags: 1.30-1ubuntu1
* debian/control:
  - Revert build-depends to lucid versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007 Javier M Mora <javiermm@gmail.com>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of the
 
7
 * License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this program; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
using Cairo;
 
21
using Mono.Unix;
 
22
 
 
23
namespace gbrainy.Core.Main
 
24
{
 
25
        //Utility class for color operations
 
26
        public class ColorPalette
 
27
        {
 
28
                private ArrayListIndicesRandom color_order;
 
29
 
 
30
                private double alpha;
 
31
                public double Alpha {
 
32
                        set { alpha = value; }
 
33
                        get { return alpha; }
 
34
                }
 
35
 
 
36
                public int Count {
 
37
                        get { return color_order.Count; }
 
38
                }
 
39
 
 
40
                // Are defined "First", "PrimaryColors", "PrimarySecundaryColors", and "Last" to
 
41
                // create iterators. So: 
 
42
                //   for (Colors.Id it= Colors.Id.First; it<Colors.Id.PrimaryColors; it++);
 
43
                //   for (Colors.Id it= Colors.Id.First; it<Colors.Id.PrimarySecundaryColors; it++);
 
44
                //   for (Colors.Id it= Colors.Id.First; it<Colors.Id.Last; it++);
 
45
                //
 
46
 
 
47
                public enum Id
 
48
                {
 
49
                        First=0,
 
50
                        Red=First,
 
51
                        Green,
 
52
                        Blue,
 
53
                        PrimaryColors,
 
54
                        Yellow=PrimaryColors, 
 
55
                        Magenta,
 
56
                        Orange,
 
57
                        PrimarySecundaryColors,
 
58
                        Black=PrimarySecundaryColors,
 
59
                        Last,
 
60
                        White=Last
 
61
                };
 
62
 
 
63
                private static readonly string[] ColorName= new string[] {
 
64
                        Catalog.GetString ("red"),
 
65
                        Catalog.GetString ("green"),
 
66
                        Catalog.GetString ("blue"),
 
67
                        Catalog.GetString ("yellow"),
 
68
                        Catalog.GetString ("magenta"),
 
69
                        Catalog.GetString ("orange"),
 
70
                        Catalog.GetString ("black"),
 
71
                        Catalog.GetString ("white")
 
72
                };
 
73
 
 
74
                private static Cairo.Color[] CairoColor = new Cairo.Color[] {
 
75
                        new Cairo.Color (0.81, 0.1, 0.13),
 
76
                        new Cairo.Color (0.54, 0.71, 0.24),
 
77
                        new Cairo.Color (0.17, 0.23 ,0.56),
 
78
                        new Cairo.Color (0.94, 0.93, 0.25),
 
79
                        new Cairo.Color (0.82, 0.25, 0.59),
 
80
                        new Cairo.Color (1, 0.54, 0),
 
81
                        new Cairo.Color (0, 0, 0),
 
82
                        new Cairo.Color (.9, .9, .9)
 
83
                };
 
84
 
 
85
                public ColorPalette (Id id)
 
86
                {
 
87
                        color_order = new ArrayListIndicesRandom((int)id);
 
88
                        alpha=1;
 
89
                }
 
90
 
 
91
                public ColorPalette (int size)
 
92
                {
 
93
                        color_order = new ArrayListIndicesRandom(size);
 
94
                        alpha=1;
 
95
                }
 
96
 
 
97
                public void Initialize()
 
98
                {
 
99
                        color_order.Initialize();
 
100
                }
 
101
 
 
102
                public Cairo.Color Cairo (int index) 
 
103
                {
 
104
                        return Cairo (CairoColor[(int)color_order[index]]);
 
105
                }
 
106
 
 
107
                public Cairo.Color Cairo (Id id) 
 
108
                {
 
109
                        return Cairo (CairoColor[(int)id]);
 
110
                }
 
111
 
 
112
                public Cairo.Color Cairo(Cairo.Color color)
 
113
                {
 
114
                        return new Cairo.Color(color.R, color.G, color.B, alpha);
 
115
                }
 
116
 
 
117
                public string Name(int index)
 
118
                {
 
119
                        return ColorName[(int)color_order[index]];
 
120
                }
 
121
 
 
122
                public string Name(Id id)
 
123
                {
 
124
                        return ColorName[(int)id];
 
125
                }
 
126
 
 
127
                public int Size()
 
128
                {
 
129
                        return color_order.Count;
 
130
                }
 
131
        }
 
132
}