1 /**
2 * Contains commonly used structs
3 */
4 
5 module caLib_util.structs;
6 
7 import caLib_abstract.lattice : isLattice;
8 import caLib_abstract.renderer : isRenderer;
9 import caLib_abstract.rule : isRule;
10 import std.traits: hasIndirections;
11 
12 
13 
14 ///
15 struct Rect
16 {
17 	int x;
18 	int y;
19 	int w;
20 	int h;
21 }
22 
23 
24 
25 ///
26 auto create_Simulation(Lt, Rt, REt)(Lt* lattice, Rt* rule, REt* renderer)
27 {
28 	return Simulation!(Lt, Rt, REt)(lattice, rule, renderer);
29 }
30 
31 ///
32 struct Simulation(Lt, Rt, REt)
33 {
34 	alias LatticeType = Lt;
35 	alias RuleType = Rt;
36 	alias RendererType = REt;
37 
38 	Lt* lattice;
39 	Rt* rule;
40 	REt* renderer;
41 
42 	this(Lt* lattice, Rt* rule, REt* renderer)
43 	{
44 		this.lattice = lattice;
45 		this.rule = rule;
46 		this.renderer = renderer;
47 	}
48 }
49 
50 
51 
52 /*
53 * A struct representing a color.
54 * Note that this color struct can replace all representations
55 * of color using uint in the argb8888 format
56 */
57 struct Color
58 {
59 	uint value=0;
60 	alias value this;
61 
62 	this(ubyte r, ubyte g, ubyte b)
63 	{
64 		this(r, g, b, 255);
65 	}
66 
67 	this(ubyte r, ubyte g, ubyte b, ubyte a)
68 	{
69 		this.r = r;
70 		this.g = g;
71 		this.b = b;
72 		this.a = a;
73 	}
74 
75 	this(uint value)
76 	{
77 		this.value = value;
78 	}
79 
80 	@property ubyte r() { return (value & 0x00FF0000) >> 16; }
81 	@property void r(ubyte newR) { value = (value & 0xFF00FFFF) + (newR << 16); }
82 
83 	@property ubyte g() { return (value & 0x0000FF00) >> 8; }
84 	@property void g(ubyte newG) { value = (value & 0xFFFF00FF) + (newG << 8); }
85 
86 	@property ubyte b() { return (value & 0x000000FF) >> 0; }
87 	@property void b(ubyte newB) { value = (value & 0xFFFFFF00) + (newB << 0); }
88 
89 	@property ubyte a() { return (value & 0xFF000000) >> 24; }
90 	@property void a(ubyte newA) { value = (value & 0x00FFFFFF) + (newA << 24); }
91 }