Mercurial > projects > ldc
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 |
rev | line source |
---|---|
73 | 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 | 3 /* |
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 | 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 | 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 | 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 | 56 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h); |
57 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); | |
58 alias SDL_UpperBlit SDL_BlitSurface; | |
59 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha); | |
60 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key); | |
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 | 66 const uint SDL_SRCALPHA=0x00010000; |
67 const uint SDL_SRCCOLORKEY=0x00001000; | |
68 void SDL_Delay(uint ms); | |
69 uint SDL_GetTicks(); | |
70 | |
71 enum SDLKey { | |
72 Unknown = 0, First = 0, | |
73 Escape = 27, | |
74 LCtrl = 306, | |
75 } | |
76 enum SDLMod { | |
77 KMOD_NONE = 0x0000, | |
78 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002, | |
79 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0, | |
80 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300, | |
81 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800, | |
82 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, | |
83 KMOD_RESERVED = 0x8000 | |
84 }; | |
85 | |
86 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; } | |
87 enum SDL_EventType : ubyte { | |
88 NoEvent=0, Active, KeyDown, KeyUp, | |
89 MouseMotion, MouseButtonDown, MouseButtonUp, | |
90 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp, | |
91 Quit, SysWMEvent | |
92 } | |
93 union SDL_Event { | |
94 SDL_EventType type; | |
95 struct Active { SDL_EventType type, gain, state; }; Active active; | |
96 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key; | |
97 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion; | |
98 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button; | |
99 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis; | |
100 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball; | |
101 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat; | |
102 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton; | |
103 struct Resize { SDL_EventType type; int w, h; }; Resize resize; | |
104 struct Expose { SDL_EventType type; }; Expose expose; | |
105 struct Quit { SDL_EventType type; }; Quit quit; | |
106 struct User { SDL_EventType type; int code; void *data1, data2; }; User user; | |
107 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm; | |
108 } | |
109 | |
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 | 115 void putpixel32(int x, int y, ubyte[4] col) { |
116 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
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 | 120 void putpixel32(int x, int y, ubyte[3] col) { |
121 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
122 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0); | |
123 } | |
124 | |
125 void getpixel32(int x, int y, ubyte[4] *col) { | |
126 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
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 | 132 ubyte r() { return values[0]; } |
133 ubyte g() { return values[1]; } | |
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 | 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 | 145 void putpixel(int x, int y, ubyte[4] col) { |
146 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return; | |
147 putpixel32(x, y, col); | |
148 } | |
149 | |
150 void hline(int x, int y, int w, rgb r) { | |
151 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0)); | |
152 } | |
153 void hline(int x, int y, int w, uint c) { | |
154 if ( (y<0) || (y!<display.h) ) return; | |
155 if (x<0) { w+=x; x=0; } | |
156 if (w<0) return; | |
157 if ( (x+w) !<display.w) w=display.w-x-1; | |
158 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
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 | 167 const rgb Yellow={[255, 255, 0]}; |
168 const rgb Cyan={[0, 255, 255]}; | |
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 | 201 bool doFlip=true; |
202 void flip() { SDL_Flip(display); } | |
203 void flip(bool target) { doFlip=target; } | |
204 scope class groupDraws { | |
205 bool wasOn; | |
206 this() { wasOn=doFlip; flip=false; } | |
207 ~this() { if (wasOn) { flip=true; flip; } } | |
208 } | |
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 | 211 const int bcol=select!(back_rgb, T); |
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 | 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 | 220 void tintfill(int x1, int y1, int x2, int y2, rgb color) { |
221 SDL_LockSurface(display); | |
222 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } | |
223 ubyte[4] c; | |
224 for (int x=x1; x<x2; ++x) { | |
225 for (int y=y1; y<y2; ++y) { | |
226 getpixel32(x, y, &c); | |
227 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8; | |
228 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8; | |
229 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8; | |
230 putpixel32(x, y, c); | |
231 } | |
232 } | |
233 } | |
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 | 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 | 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 | 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 | 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 | 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 | 267 static if (steep) putpixel(var2, var1, col); |
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 | 281 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
282 auto yend=max(y0, y1); | |
283 for (int y=min(y0, y1); y<=yend; ++y) { | |
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 | 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 | 326 putpixel(cx+x, cy+y, col); |
327 putpixel(cx+x, cy-y, col); | |
328 putpixel(cx-x, cy+y, col); | |
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 | 344 import std.stdio; |
345 void circle(T...)(T t) { | |
346 static assert(T.length!<3, "Circle: Needs x, y and radius"); | |
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 | 349 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
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 | 352 if (xradius!>0) return; |
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 | 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 | 359 hline(cx-j, cy+i, 2*j, back_sdl); |
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 | 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 | 370 float distance(float x1, float y1, float x2, float y2) { |
371 auto x=x1-x2, y=y1-y2; | |
372 return sqrt(x*x+y*y); | |
373 } | |
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 | 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 | 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 | 420 struct screen { |
421 static { | |
422 void opCall(size_t w, size_t h) { | |
423 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); | |
424 } | |
425 int width() { return display.w; } | |
426 int height() { return display.h; } | |
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 | 430 |
431 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); } | |
432 | |
433 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) { | |
434 SDL_Event evt; | |
435 while (SDL_PollEvent(&evt)) { | |
436 switch (evt.type) { | |
437 case SDL_EventType.MouseMotion: | |
438 with (evt.motion) if (mouse) mouse(x, y, 0, false); | |
439 break; | |
440 case SDL_EventType.MouseButtonDown: | |
441 with (evt.button) if (mouse) mouse(x, y, button, true); | |
442 break; | |
443 case SDL_EventType.MouseButtonUp: | |
444 with (evt.button) if (mouse) mouse(x, y, button, false); | |
445 break; | |
446 case SDL_EventType.KeyDown: | |
447 if (key) key(evt.key.keysym.sym, true); | |
448 case SDL_EventType.KeyUp: | |
449 if (key) key(evt.key.keysym.sym, false); | |
450 break; | |
451 case SDL_EventType.Quit: | |
452 throw new Error("Quit"); | |
453 break; | |
454 default: break; | |
455 } | |
456 } | |
457 } | |
458 | |
459 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) { | |
460 events((int a, bool b) { | |
461 if (b) key(a); | |
462 }, mouse); | |
463 } | |
464 | |
465 void events(void delegate(int) key, void delegate(int, int) mouse) { | |
466 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
467 } | |
468 | |
469 void events(void delegate(int, bool) key, void delegate(int, int) mouse) { | |
470 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
471 } |