simple display (from: GUI library for D)

bearophile bearophileHUGS at lycos.com
Fri Apr 8 13:48:46 PDT 2011


Adam D. Ruppe:

> I, with input from others, have started writing a little module
> for simple uses of a display. You can write to a bitmap, display it
> to a window, and handle events all in an easy way. The basics are
> cross platform, but you can use native function calls too.

I'd like something like this in Phobos, or if this is not possible, a cabal-install-like command away. I sometimes use Python PyGame or Processing.


> import simpledisplay;
> 
> 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();
> }

Instead of:
image.putPixel(a, b, Color(a, b, ((a + b) % 16) * 16));
I suggest something simpler like:
image[a, b] = std.typecons.tuple(a, b, ((a + b) % 16) * 16);

Instead of:
image.display();
I suggest something like this, to swap the two image buffers:
image.flip();

Plus maybe some image.event(); reader with callbacks...

Bye,
bearophile


More information about the Digitalmars-d mailing list