annotate demos/qd.d @ 323:0d52412d5b1a trunk

[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments. Changed the way moduleinfo is registered to use the same approach as DMD, this eliminates the need for correct linking order and should make the way for using a natively compiled runtime library. This should speed up linking tremendously and should now be possible. Fixed the llvm.used array to only be emitted if really necessary.
author lindquist
date Wed, 09 Jul 2008 23:43:51 +0200
parents f869c636a113
children 22a56b65872b
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
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
3 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
4 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
5 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
6 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
7 }
835320b88ad6 [svn 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 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
9 //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
10 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
11 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
12 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
13 }
835320b88ad6 [svn 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 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
15 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
16 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
17 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
18 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
19 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
20 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
21 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
22 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
23 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
24 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
25 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
26 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
27 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
28 }
835320b88ad6 [svn 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 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
30 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
31 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
32 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
33 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
34 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
35 int SDL_Flip(SDL_Surface *);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
36 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
37 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
38 alias SDL_UpperBlit SDL_BlitSurface;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
39 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
40 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
41 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
42 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
43 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
44 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
45 const uint SDL_FULLSCREEN=0x80000000;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
46 const uint SDL_SRCALPHA=0x00010000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
47 const uint SDL_SRCCOLORKEY=0x00001000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
48 void SDL_Delay(uint ms);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
49 uint SDL_GetTicks();
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
50
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
51 enum SDLKey {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
52 Unknown = 0, First = 0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
53 Escape = 27,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
54 LCtrl = 306,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
55 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
56 enum SDLMod {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
57 KMOD_NONE = 0x0000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
58 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
59 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
60 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
61 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
62 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
63 KMOD_RESERVED = 0x8000
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
64 };
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
65
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
66 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
67 enum SDL_EventType : ubyte {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
68 NoEvent=0, Active, KeyDown, KeyUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
69 MouseMotion, MouseButtonDown, MouseButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
70 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
71 Quit, SysWMEvent
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
72 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
73 union SDL_Event {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
74 SDL_EventType type;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
75 struct Active { SDL_EventType type, gain, state; }; Active active;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
76 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
77 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
78 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
79 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
80 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
81 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
82 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
83 struct Resize { SDL_EventType type; int w, h; }; Resize resize;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
84 struct Expose { SDL_EventType type; }; Expose expose;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
85 struct Quit { SDL_EventType type; }; Quit quit;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
86 struct User { SDL_EventType type; int code; void *data1, data2; }; User user;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
87 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
88 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
89
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
90 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
91 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
92
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
93 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
94
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
95 void putpixel32(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
96 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
97 *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
98 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
99
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
100 void putpixel32(int x, int y, ubyte[3] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
101 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
102 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
103 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
104
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
105 void getpixel32(int x, int y, ubyte[4] *col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
106 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
107 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
108 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
109
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
110 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
111 ubyte[3] values;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
112 ubyte r() { return values[0]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
113 ubyte g() { return values[1]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
114 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
115 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
116 rgb res;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
117 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
118 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
119 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
120 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
121 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
122 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
123 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
124
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
125 void putpixel(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
126 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
127 putpixel32(x, y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
128 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
129
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
130 void hline(int x, int y, int w, rgb r) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
131 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
132 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
133 void hline(int x, int y, int w, uint c) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
134 if ( (y<0) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
135 if (x<0) { w+=x; x=0; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
136 if (w<0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
137 if ( (x+w) !<display.w) w=display.w-x-1;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
138 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
139 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
140 }
835320b88ad6 [svn 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
835320b88ad6 [svn 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 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
143 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
144 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
145 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
146 const rgb Blue={[0, 0, 255]};
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
147 const rgb Yellow={[255, 255, 0]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
148 const rgb Cyan={[0, 255, 255]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
149 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
150 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
151 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
152
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
153 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
154 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
155 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
156 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
157 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
158 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
159 }
835320b88ad6 [svn 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 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 }
835320b88ad6 [svn 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 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
174 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
175 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
176 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
177 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
178 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
179 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
180
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
181 bool doFlip=true;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
182 void flip() { SDL_Flip(display); }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
183 void flip(bool target) { doFlip=target; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
184 scope class groupDraws {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
185 bool wasOn;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
186 this() { wasOn=doFlip; flip=false; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
187 ~this() { if (wasOn) { flip=true; flip; } }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
188 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
189
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
190 void execParams(T...)(T params) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
191 const int bcol=select!(back_rgb, T);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
192 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
193 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
194 static if (col != -1) color=params[col];
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
195 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
196 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
197 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
198 }
835320b88ad6 [svn 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
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
200 void tintfill(int x1, int y1, int x2, int y2, rgb color) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
201 SDL_LockSurface(display);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
202 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
203 ubyte[4] c;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
204 for (int x=x1; x<x2; ++x) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
205 for (int y=y1; y<y2; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
206 getpixel32(x, y, &c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
207 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
208 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
209 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
210 putpixel32(x, y, c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
211 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
212 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
213 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
214
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
215 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
216 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
217 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
218 execParams(params);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
219 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
220 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
221
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
222 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
223 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
224 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
225 ubyte[4] c;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
226 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
227 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
228 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
229
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
230 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
231 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
232
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
233 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
234 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
235 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
236 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
237 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
238 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
239 } 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
240 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
241 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
242 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
243 }
835320b88ad6 [svn 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 auto error = 0f;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
245 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
246 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
247 static if (steep) putpixel(var2, var1, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
248 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
249 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
250 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
251 }
835320b88ad6 [svn 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
835320b88ad6 [svn 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 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
255 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
256
835320b88ad6 [svn 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 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
258 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
259 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
260 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
261 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
262 auto yend=max(y0, y1);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
263 for (int y=min(y0, y1); y<=yend; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
264 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
265 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
267 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
268 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
269 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
270 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
271 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
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 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
274 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 } 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
285 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
286 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
287 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
291 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f32") {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
292 float sqrt(float val);
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
293 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
294 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f64") {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
295 double sqrt(double val);
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
296 real sqrt(real val);
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 73
diff changeset
297 }
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
298
835320b88ad6 [svn 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 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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 while (stopx"~(first?">=":"<=")~"stopy) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
311 putpixel(cx+x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
312 putpixel(cx+x, cy-y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
313 putpixel(cx-x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
314 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
315 "~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
316 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
317 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
318 "~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
319 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
320 --"~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
321 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
322 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
323 "~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
324 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
326 ";
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
327 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
328
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
329 import std.stdio;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
330 void circle(T...)(T t) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
331 static assert(T.length!<3, "Circle: Needs x, y and radius");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
332 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
333 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
334 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
335 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
336 auto yradius=xradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
337 if (xradius!>0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
338 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
339 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
340 auto ratio=xradius*1f/yradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
341 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
342 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
343 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
344 hline(cx-j, cy+i, 2*j, back_sdl);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
345 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
346 }
835320b88ad6 [svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff changeset
347 }
835320b88ad6 [svn 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 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
349 auto y2square=2*yradius*yradius;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
350 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
351 { 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
352 { 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
353 }
835320b88ad6 [svn 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
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
355 float distance(float x1, float y1, float x2, float y2) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
356 auto x=x1-x2, y=y1-y2;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
357 return sqrt(x*x+y*y);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
358 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
359
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
360 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
361 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
362 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
363 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
364 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
365 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
366 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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 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
370 SDL_LockSurface(display);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
371 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
372 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
373 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
374 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
375 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
376 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
377 }
835320b88ad6 [svn 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 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
379 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
380 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
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 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 //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
395 for (int i=e+1; i<w; ++i) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
396 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
397 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
398 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
399 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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 }
835320b88ad6 [svn 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
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
405 struct screen {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
406 static {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
407 void opCall(size_t w, size_t h) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
408 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
409 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
410 int width() { return display.w; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
411 int height() { return display.h; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
412 }
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
413 }
835320b88ad6 [svn 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
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
415
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
416 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
417
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
418 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
419 SDL_Event evt;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
420 while (SDL_PollEvent(&evt)) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
421 switch (evt.type) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
422 case SDL_EventType.MouseMotion:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
423 with (evt.motion) if (mouse) mouse(x, y, 0, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
424 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
425 case SDL_EventType.MouseButtonDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
426 with (evt.button) if (mouse) mouse(x, y, button, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
427 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
428 case SDL_EventType.MouseButtonUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
429 with (evt.button) if (mouse) mouse(x, y, button, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
430 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
431 case SDL_EventType.KeyDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
432 if (key) key(evt.key.keysym.sym, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
433 case SDL_EventType.KeyUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
434 if (key) key(evt.key.keysym.sym, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
435 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
436 case SDL_EventType.Quit:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
437 throw new Error("Quit");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
438 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
439 default: break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
440 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
441 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
442 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
443
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
444 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
445 events((int a, bool b) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
446 if (b) key(a);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
447 }, mouse);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
448 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
449
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
450 void events(void delegate(int) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
451 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
452 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
453
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
454 void events(void delegate(int, bool) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
455 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
456 }