annotate demos/qd.d @ 73:b706170e24a9 trunk

[svn r77] Fixed foreach on slice. Fixed some nested function problems when accessing outer function parameters. Major changes to handling of structs. Initial support for unions. Probably more...
author lindquist
date Wed, 31 Oct 2007 03:11:32 +0100
parents 835320b88ad6
children 2332006e1fa4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
1 module qd;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
2
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
3 /*
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
4 import std.c.time: sleep;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
5 void main() {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
6 screen(640, 480);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
7 pset(10, 10);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
8 line(0, 0, 100, 100, Box, Back(Red~Black));
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
9 for (int i=0; i<=100; i+=10) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
10 line(i, 0, 100-i, 100);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
11 line(0, i, 100, 100-i);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
12 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
13 circle(100, 100, 50, 15, White~Black, Fill=White~Black);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
14 paint(200, 200, Red, Back=White);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
15 circle(100, 100, 50, 15, White);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
16 paint(200, 200, Black);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
17 pset(10, 11); pset(10, 11, Black);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
18 pset(10, 10);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
19 sleep(5);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
20 }
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
21 */
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
22
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
23 extern(C) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
24 struct SDL_Rect {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
25 short x, y;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
26 ushort w, h;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
27 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
28 struct SDL_PixelFormat {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
29 //SDL_Palette *palette;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
30 void *palette;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
31 ubyte BitsPerPixel, BytesPerPixel, Rloss, Gloss, Bloss, Aloss, Rshift, Gshift, Bshift, Ashift;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
32 uint Rmask, Gmask, Bmask, Amask, colorkey; ubyte alpha;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
33 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
34 struct SDL_Surface {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
35 uint flags;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
36 SDL_PixelFormat *format;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
37 int w, h;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
38 ushort pitch;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
39 void *pixels;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
40 int offset;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
41 void *hwdata;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
42 SDL_Rect clip_rect;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
43 uint unused;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
44 uint locked;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
45 void *map;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
46 uint format_version;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
47 int refcount;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
48 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
49 uint SDL_MapRGBA(SDL_PixelFormat *format, ubyte r, ubyte g, ubyte b, ubyte a);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
50 void SDL_GetRGBA(uint pixel, SDL_PixelFormat *fmt, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
51 int SDL_LockSurface(SDL_Surface *);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
52 void SDL_UnlockSurface(SDL_Surface *);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
53 SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
54 SDL_Surface *SDL_CreateRGBSurface(uint flags, int width, int height, int depth, uint Rmask=0, uint Gmask=0, uint Bmask=0, uint Amask=0);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
55 int SDL_Flip(SDL_Surface *);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
56 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
57 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
58 alias SDL_UpperBlit SDL_BlitSurface;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
59 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
60 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
61 int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, uint color);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
62 const uint SDL_SWSURFACE=0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
63 const uint SDL_HWSURFACE=1;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
64 const uint SDL_DOUBLEBUF=0x40000000;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
65 const uint SDL_FULLSCREEN=0x80000000;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
66 const uint SDL_SRCALPHA=0x00010000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
67 const uint SDL_SRCCOLORKEY=0x00001000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
68 void SDL_Delay(uint ms);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
69 uint SDL_GetTicks();
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
70
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
71 enum SDLKey {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
72 Unknown = 0, First = 0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
73 Escape = 27,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
74 LCtrl = 306,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
75 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
76 enum SDLMod {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
77 KMOD_NONE = 0x0000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
78 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
79 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
80 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
81 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
82 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
83 KMOD_RESERVED = 0x8000
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
84 };
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
85
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
86 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
87 enum SDL_EventType : ubyte {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
88 NoEvent=0, Active, KeyDown, KeyUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
89 MouseMotion, MouseButtonDown, MouseButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
90 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
91 Quit, SysWMEvent
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
92 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
93 union SDL_Event {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
94 SDL_EventType type;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
95 struct Active { SDL_EventType type, gain, state; }; Active active;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
96 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
97 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
98 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
99 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
100 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
101 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
102 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
103 struct Resize { SDL_EventType type; int w, h; }; Resize resize;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
104 struct Expose { SDL_EventType type; }; Expose expose;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
105 struct Quit { SDL_EventType type; }; Quit quit;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
106 struct User { SDL_EventType type; int code; void *data1, data2; }; User user;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
107 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
108 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
109
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
110 int SDL_PollEvent(SDL_Event *event);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
111 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
112
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
113 SDL_Surface *display;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
114
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
115 void putpixel32(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
116 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
117 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], col[3]);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
118 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
119
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
120 void putpixel32(int x, int y, ubyte[3] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
121 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
122 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
123 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
124
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
125 void getpixel32(int x, int y, ubyte[4] *col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
126 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
127 SDL_GetRGBA(*bufp, display.format, &(*col)[0], &(*col)[1], &(*col)[2], &(*col)[3]);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
128 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
129
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
130 struct rgb {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
131 ubyte[3] values;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
132 ubyte r() { return values[0]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
133 ubyte g() { return values[1]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
134 ubyte b() { return values[2]; }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
135 rgb opCat(rgb other) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
136 rgb res;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
137 foreach (id, ref v; res.values) v=cast(ubyte)((values[id]+other.values[id])/2);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
138 return res;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
139 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
140 bool opEquals(rgb r) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
141 return values == r.values;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
142 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
143 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
144
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
145 void putpixel(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
146 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
147 putpixel32(x, y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
148 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
149
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
150 void hline(int x, int y, int w, rgb r) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
151 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0));
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
152 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
153 void hline(int x, int y, int w, uint c) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
154 if ( (y<0) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
155 if (x<0) { w+=x; x=0; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
156 if (w<0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
157 if ( (x+w) !<display.w) w=display.w-x-1;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
158 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
159 foreach (ref value; cur[0..w+1]) value=c;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
160 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
161
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
162 const rgb White={[255, 255, 255]};
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
163 const rgb Black={[0, 0, 0]};
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
164 const rgb Red={[255, 0, 0]};
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
165 const rgb Green={[0, 255, 0]};
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
166 const rgb Blue={[0, 0, 255]};
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
167 const rgb Yellow={[255, 255, 0]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
168 const rgb Cyan={[0, 255, 255]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
169 const rgb Purple={[255, 0, 255]};
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
170 rgb color=White;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
171 rgb back=Black;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
172
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
173 template failfind(U, T...) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
174 static if (T.length)
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
175 static if (is(T[0] == U)) static assert(false, "Duplicate "~U.stringof~" found!");
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
176 else const bool failfind=failfind!(U, T[1..$]);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
177 else
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
178 const bool failfind=true;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
179 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
180
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
181 template select(U, T...) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
182 static if(T.length)
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
183 static if (is(U == T[0])) { static if (failfind!(U, T[1..$])) { }; const int select = 0; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
184 else
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
185 static if (select!(U, T[1..$]) != -1)
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
186 const int select = 1 + select!(U, T[1..$]);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
187 else
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
188 const int select = -1;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
189 else
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
190 const int select = -1;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
191 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
192
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
193 typedef rgb back_rgb;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
194 back_rgb Back(rgb r) { return cast(back_rgb) r; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
195 back_rgb Back() { return cast(back_rgb) back; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
196 typedef rgb box_rgb;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
197 box_rgb Box(rgb r) { return cast(box_rgb) r; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
198 box_rgb Box() { return cast(box_rgb) color; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
199 alias Back Fill;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
200
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
201 bool doFlip=true;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
202 void flip() { SDL_Flip(display); }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
203 void flip(bool target) { doFlip=target; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
204 scope class groupDraws {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
205 bool wasOn;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
206 this() { wasOn=doFlip; flip=false; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
207 ~this() { if (wasOn) { flip=true; flip; } }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
208 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
209
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
210 void execParams(T...)(T params) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
211 const int bcol=select!(back_rgb, T);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
212 static if (bcol != -1) back=cast(rgb) params[bcol];
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
213 const int col=select!(rgb, T);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
214 static if (col != -1) color=params[col];
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
215 else static if (bcol != -1) color=back;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
216 const int boxcol=select!(box_rgb, T);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
217 static if (boxcol != -1) color=cast(rgb) params[boxcol];
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
218 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
219
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
220 void tintfill(int x1, int y1, int x2, int y2, rgb color) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
221 SDL_LockSurface(display);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
222 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
223 ubyte[4] c;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
224 for (int x=x1; x<x2; ++x) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
225 for (int y=y1; y<y2; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
226 getpixel32(x, y, &c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
227 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
228 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
229 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
230 putpixel32(x, y, c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
231 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
232 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
233 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
234
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
235 void pset(T...)(int x, int y, T params) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
236 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
237 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
238 execParams(params);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
239 putpixel32(x, y, color.values);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
240 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
241
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
242 rgb pget(int x, int y) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
243 SDL_LockSurface(display);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
244 scope(exit) SDL_UnlockSurface(display);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
245 ubyte[4] c;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
246 getpixel32(x, y, &c);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
247 rgb res; res.values[]=c[0..3]; return res;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
248 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
249
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
250 void swap(T)(ref T a, ref T b) { T c=a; a=b; b=c; }
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
251 T abs(T)(T a) { return (a<0) ? -a : a; }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
252
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
253 void bresenham(bool countUp=true, bool steep=false)(int x0, int y0, int x1, int y1) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
254 auto deltax = x1 - x0, deltay = y1 - y0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
255 static if (steep) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
256 auto Δerror = cast(float)deltax / cast(float)deltay;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
257 auto var2 = x0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
258 const string name="y";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
259 } else {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
260 auto Δerror = cast(float)deltay / cast(float)deltax;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
261 auto var2 = y0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
262 const string name="x";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
263 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
264 auto error = 0f;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
265 ubyte[4] col; col[0..3]=color.values;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
266 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
267 static if (steep) putpixel(var2, var1, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
268 else putpixel(var1, var2, col);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
269 error += Δerror;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
270 if (abs(error) >= 1f) { static if (countUp) { var2++; error -= 1f; } else { var2--; error += 1f; }}
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
271 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
272 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
273
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
274 T max(T)(T a, T b) { return a>b?a:b; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
275 T min(T)(T a, T b) { return a<b?a:b; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
276
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
277 void line(T...)(int x0, int y0, int x1, int y1, T p) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
278 execParams(p);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
279 static if (select!(back_rgb, T)!=-1) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
280 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
281 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
282 auto yend=max(y0, y1);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
283 for (int y=min(y0, y1); y<=yend; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
284 hline(min(x0, x1), y, max(x0, x1)-min(x0, x1), back);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
285 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
286 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
287 static if (select!(box_rgb, T)!=-1) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
288 line(x0, y0, x1, y0);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
289 line(x1, y0, x1, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
290 line(x1, y1, x0, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
291 line(x0, y1, x0, y0);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
292 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
293 static if (select!(box_rgb, T)+select!(back_rgb, T)==-2) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
294 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
295 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
296 bool steep = abs(y1 - y0) > abs(x1 - x0);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
297 void turn() { swap(x0, x1); swap(y0, y1); }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
298 if (steep) { if (y1 < y0) turn; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
299 else { if (x1 < x0) turn; }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
300 bool stepUp=steep ? (x0 < x1) : (y0 < y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
301 if (steep) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
302 if (stepUp) bresenham!(true, true)(x0, y0, x1, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
303 else bresenham!(false, true)(x0, y0, x1, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
304 } else {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
305 if (stepUp) bresenham!(true, false)(x0, y0, x1, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
306 else bresenham!(false, false)(x0, y0, x1, y1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
307 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
308 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
309 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
310
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
311 import llvm.intrinsic;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
312 alias llvm_sqrt sqrt;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
313
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
314 template circle_bresenham_pass(bool first) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
315 const string xy=(first?"x":"y");
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
316 const string yx=(first?"y":"x");
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
317 const string str="
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
318 auto x="~(first?"xradius":"0")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
319 auto y="~(first?"0":"yradius")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
320 auto xchange=yradius*yradius*"~(first?"(1-2*xradius)":"1")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
321 auto ychange=xradius*xradius*"~(first?"1":"(1-2*yradius)")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
322 auto error=0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
323 auto stopx="~(first?"y2square*xradius":"0")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
324 auto stopy="~(first?"0":"x2square*yradius")~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
325 while (stopx"~(first?">=":"<=")~"stopy) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
326 putpixel(cx+x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
327 putpixel(cx+x, cy-y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
328 putpixel(cx-x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
329 putpixel(cx-x, cy-y, col);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
330 "~yx~"++;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
331 stop"~yx~"+="~xy~"2square;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
332 error+="~yx~"change;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
333 "~yx~"change+="~xy~"2square;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
334 if ((2*error+"~xy~"change)>0) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
335 --"~xy~";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
336 stop"~xy~"-="~yx~"2square;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
337 error+="~xy~"change;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
338 "~xy~"change+="~yx~"2square;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
339 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
340 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
341 ";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
342 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
343
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
344 import std.stdio;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
345 void circle(T...)(T t) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
346 static assert(T.length!<3, "Circle: Needs x, y and radius");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
347 int cx=t[0], cy=t[1], xradius=t[2];
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
348 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
349 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
350 execParams(t[3..$]);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
351 auto yradius=xradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
352 if (xradius!>0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
353 static if (T.length>3 && is(T[3]: int)) yradius=t[3];
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
354 static if (select!(back_rgb, T) != -1) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
355 auto ratio=xradius*1f/yradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
356 auto back_sdl=SDL_MapRGBA(display.format, back.values[0], back.values[1], back.values[2], 0);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
357 for (int i=0; i<=yradius; ++i) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
358 ushort j=cast(ushort)(sqrt(cast(real)(yradius*yradius-i*i))*ratio);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
359 hline(cx-j, cy+i, 2*j, back_sdl);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
360 hline(cx-j, cy-i, 2*j, back_sdl);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
361 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
362 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
363 auto x2square=2*xradius*xradius;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
364 auto y2square=2*yradius*yradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
365 ubyte[4] col; col[0..3]=color.values;
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
366 { mixin(circle_bresenham_pass!(true).str); }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
367 { mixin(circle_bresenham_pass!(false).str); }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
368 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
369
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
370 float distance(float x1, float y1, float x2, float y2) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
371 auto x=x1-x2, y=y1-y2;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
372 return sqrt(x*x+y*y);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
373 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
374
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
375 struct floodfill_node {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
376 int x, y;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
377 static floodfill_node opCall(int x, int y) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
378 floodfill_node res;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
379 res.x=x; res.y=y;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
380 return res;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
381 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
382 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
383
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
384 void paint(T...)(int x, int y, T t) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
385 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
386 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
387 execParams(t);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
388 bool border=true;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
389 if (select!(back_rgb, T) == -1) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
390 back=pget(x, y);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
391 border=false;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
392 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
393 bool check(rgb r) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
394 if (border) return (r != back) && (r != color);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
395 else return r == back;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
396 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
397 if (back == color) throw new Exception("Having identical backgrounds and foregrounds will severely mess up floodfill.");
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
398 alias floodfill_node node;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
399 node[] queue;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
400 queue ~= node(x, y);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
401 size_t count=0;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
402 while (count<queue.length) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
403 scope(exit) count++;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
404 with (queue[count]) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
405 if (check(pget(x, y))) {
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
406 int w=x, e=x;
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
407 if (w<display.w) do w++; while ((w<display.w) && check(pget(w, y)));
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
408 if (e>=0) do e--; while (e>=0 && check(pget(e, y)));
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
409 //SDL_Flip(display);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
410 for (int i=e+1; i<w; ++i) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
411 putpixel32(i, y, color.values);
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
412 if (y && check(pget(i, y-1)) && ((i==w-1)||!check(pget(i+1, y-1)))) queue ~= node(i, y-1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
413 if ((y < display.h-1) && check(pget(i, y+1)) && ((i==w-1)||!check(pget(i+1, y+1)))) queue ~= node(i, y+1);
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
414 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
415 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
416 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
417 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
418 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
419
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
420 struct screen {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
421 static {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
422 void opCall(size_t w, size_t h) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
423 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
424 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
425 int width() { return display.w; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
426 int height() { return display.h; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
427 }
41
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
428 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
429
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
430
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
431 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
432
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
433 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
434 SDL_Event evt;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
435 while (SDL_PollEvent(&evt)) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
436 switch (evt.type) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
437 case SDL_EventType.MouseMotion:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
438 with (evt.motion) if (mouse) mouse(x, y, 0, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
439 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
440 case SDL_EventType.MouseButtonDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
441 with (evt.button) if (mouse) mouse(x, y, button, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
442 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
443 case SDL_EventType.MouseButtonUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
444 with (evt.button) if (mouse) mouse(x, y, button, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
445 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
446 case SDL_EventType.KeyDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
447 if (key) key(evt.key.keysym.sym, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
448 case SDL_EventType.KeyUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
449 if (key) key(evt.key.keysym.sym, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
450 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
451 case SDL_EventType.Quit:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
452 throw new Error("Quit");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
453 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
454 default: break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
455 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
456 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
457 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
458
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
459 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
460 events((int a, bool b) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
461 if (b) key(a);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
462 }, mouse);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
463 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
464
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
465 void events(void delegate(int) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
466 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); });
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
467 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
468
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
469 void events(void delegate(int, bool) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
470 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); });
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
471 }