annotate mde/types/Colour.d @ 90:b525ff28774b

Widgets generated dynamically from a list can now be standard widgets selected from data files. Started on allowing alignment to be shared between instances of a layout widget in a dynamic list (to allow column alignment of list's rows).
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 01 Oct 2008 23:37:51 +0100
parents 66d555da083e
children 4d5d53e4f881
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 57
diff changeset
16 /** Contains a basic colour type. */
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 57
diff changeset
17 module mde.types.Colour;
57
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 /// Represent a colour using clamped floats
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 struct Colour {
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 /// Returns GL_ONE if total value is nearer white than black, else GL_ZERO.
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 57
diff changeset
22 uint nearestGLConst () {
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 57
diff changeset
23 return r+g+b >= 1.5f ? 1u : 0u;
57
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 }
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 57
diff changeset
26 float r,g,b; /// values
57
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 static {
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 /// Predefined colours
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 const Colour WHITE = { r:1f, g:1f, b:1f };
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 const Colour BLACK = { r:0f, g:0f, b:0f }; /// ditto
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 /// Construct from floats (doesn't clamp, but GL does when values are passed)
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 Colour opCall (float r, float g, float b) {
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 Colour c;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 c.r = r;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 c.g = g;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 c.b = b;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 return c;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 }
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 /// Construct from ubytes
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 Colour opCall (ubyte r, ubyte g, ubyte b) {
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 Colour c;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 c.r = cast(float) r / 255f;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 c.g = cast(float) g / 255f;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 c.b = cast(float) b / 255f;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 return c;
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 }
90
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
49 /// Construct from 0xRRGGBB
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
50 Colour opCall (int col) {
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
51 Colour c;
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
52 c.r = cast(float) (col >> 16u) / 255f;
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
53 c.g = cast(float) (col >> 8u) / 255f;
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
54 c.b = cast(float) col / 255f;
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
55 return c;
b525ff28774b Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 63
diff changeset
56 }
57
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 }
9e1f05fbbcef Coloured and alpha-blended text is now supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 }