import simpledisplay; import std.stdio; struct Wrapped(T, T min, T max) { T value; alias value this; Wrapped opOpAssign(string op)(T t) { mixin("value " ~ op ~ "= t;"); checkLimits(); return this; } void checkLimits() { if(value < min) value = min; if(value > max) value = max; } this(T t) { value = t; checkLimits(); } Wrapped opAssign(T t) { value = t; checkLimits(); return this; } } void main() { auto image = new Image(255, 255); foreach(a; 0..255) foreach(b; 0..255) image.putPixel(a, b, Color(a, b, ((a + b) % 16) * 16)); //image.display(); // use this for the simple demonstration // and now a more advanced demo with event handling.... auto win = new SimpleWindow(image); Wrapped!(real, 0, 360) h = 180; Wrapped!(real, 0, 1) s = 1; Wrapped!(real, 0, 1) l = 0.5; win.eventLoop(0, // FIXME: timer pulse not implemented (dchar c) { writeln("Got a char event: ", c); if(c == 'q') h += 15; if(c == 'a') h -= 15; if(c == 'w') s += 0.05; if(c == 's') s -= 0.05; if(c == 'e') l += 0.05; if(c == 'd') l -= 0.05; foreach(a; 0..255) foreach(b; 0..255) image.putPixel(a, b, fromHsl(h, s, l)); win.image = image; }, (int key) { writeln("Got a keydown event: ", key); if(key == KEY_ESCAPE) { auto color = fromHsl(h, s, l); writefln("%02x%02x%02x", color.r, color.g, color.b); win.close(); } }); }