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