Mercurial > projects > ldc
annotate demos/qd.d @ 78:2332006e1fa4 trunk
[svn r82] Fixed: Fall-through switch cases were broken.
author | lindquist |
---|---|
date | Wed, 31 Oct 2007 20:50:21 +0100 |
parents | b706170e24a9 |
children | f869c636a113 |
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 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
|
4 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
|
5 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
|
6 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
|
7 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
|
8 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
|
9 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
|
10 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
|
11 } |
835320b88ad6
[svn 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 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
|
13 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
|
14 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
|
15 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
|
16 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
|
17 pset(10, 10); |
73 | 18 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
|
19 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
22 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
|
23 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
|
24 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
|
25 } |
835320b88ad6
[svn 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 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
|
27 //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
|
28 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
|
29 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
|
30 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
|
31 } |
835320b88ad6
[svn 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 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 } |
835320b88ad6
[svn 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 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
|
48 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
|
49 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
|
50 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
|
51 SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags); |
73 | 52 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
|
53 int SDL_Flip(SDL_Surface *); |
73 | 54 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h); |
55 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); | |
56 alias SDL_UpperBlit SDL_BlitSurface; | |
57 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha); | |
58 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key); | |
59 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
|
60 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
|
61 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
|
62 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
|
63 const uint SDL_FULLSCREEN=0x80000000; |
73 | 64 const uint SDL_SRCALPHA=0x00010000; |
65 const uint SDL_SRCCOLORKEY=0x00001000; | |
66 void SDL_Delay(uint ms); | |
67 uint SDL_GetTicks(); | |
68 | |
69 enum SDLKey { | |
70 Unknown = 0, First = 0, | |
71 Escape = 27, | |
72 LCtrl = 306, | |
73 } | |
74 enum SDLMod { | |
75 KMOD_NONE = 0x0000, | |
76 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002, | |
77 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0, | |
78 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300, | |
79 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800, | |
80 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, | |
81 KMOD_RESERVED = 0x8000 | |
82 }; | |
83 | |
84 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; } | |
85 enum SDL_EventType : ubyte { | |
86 NoEvent=0, Active, KeyDown, KeyUp, | |
87 MouseMotion, MouseButtonDown, MouseButtonUp, | |
88 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp, | |
89 Quit, SysWMEvent | |
90 } | |
91 union SDL_Event { | |
92 SDL_EventType type; | |
93 struct Active { SDL_EventType type, gain, state; }; Active active; | |
94 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key; | |
95 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion; | |
96 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button; | |
97 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis; | |
98 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball; | |
99 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat; | |
100 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton; | |
101 struct Resize { SDL_EventType type; int w, h; }; Resize resize; | |
102 struct Expose { SDL_EventType type; }; Expose expose; | |
103 struct Quit { SDL_EventType type; }; Quit quit; | |
104 struct User { SDL_EventType type; int code; void *data1, data2; }; User user; | |
105 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm; | |
106 } | |
107 | |
108 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
|
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 |
835320b88ad6
[svn 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 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
|
112 |
73 | 113 void putpixel32(int x, int y, ubyte[4] col) { |
114 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
115 *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
|
116 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
117 |
73 | 118 void putpixel32(int x, int y, ubyte[3] col) { |
119 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
120 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0); | |
121 } | |
122 | |
123 void getpixel32(int x, int y, ubyte[4] *col) { | |
124 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
125 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
|
126 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
127 |
835320b88ad6
[svn 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 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
|
129 ubyte[3] values; |
73 | 130 ubyte r() { return values[0]; } |
131 ubyte g() { return values[1]; } | |
132 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
|
133 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
|
134 rgb res; |
73 | 135 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
|
136 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
|
137 } |
835320b88ad6
[svn 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 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
|
139 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
|
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 |
73 | 143 void putpixel(int x, int y, ubyte[4] col) { |
144 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return; | |
145 putpixel32(x, y, col); | |
146 } | |
147 | |
148 void hline(int x, int y, int w, rgb r) { | |
149 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0)); | |
150 } | |
151 void hline(int x, int y, int w, uint c) { | |
152 if ( (y<0) || (y!<display.h) ) return; | |
153 if (x<0) { w+=x; x=0; } | |
154 if (w<0) return; | |
155 if ( (x+w) !<display.w) w=display.w-x-1; | |
156 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
157 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
|
158 } |
835320b88ad6
[svn 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 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
|
161 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
|
162 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
|
163 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
|
164 const rgb Blue={[0, 0, 255]}; |
73 | 165 const rgb Yellow={[255, 255, 0]}; |
166 const rgb Cyan={[0, 255, 255]}; | |
167 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
|
168 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
|
169 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
|
170 |
835320b88ad6
[svn 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 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
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 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 |
73 | 199 bool doFlip=true; |
200 void flip() { SDL_Flip(display); } | |
201 void flip(bool target) { doFlip=target; } | |
202 scope class groupDraws { | |
203 bool wasOn; | |
204 this() { wasOn=doFlip; flip=false; } | |
205 ~this() { if (wasOn) { flip=true; flip; } } | |
206 } | |
207 | |
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
|
208 void execParams(T...)(T params) { |
73 | 209 const int bcol=select!(back_rgb, T); |
210 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
|
211 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
|
212 static if (col != -1) color=params[col]; |
73 | 213 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
|
214 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
|
215 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
|
216 } |
835320b88ad6
[svn 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 |
73 | 218 void tintfill(int x1, int y1, int x2, int y2, rgb color) { |
219 SDL_LockSurface(display); | |
220 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } | |
221 ubyte[4] c; | |
222 for (int x=x1; x<x2; ++x) { | |
223 for (int y=y1; y<y2; ++y) { | |
224 getpixel32(x, y, &c); | |
225 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8; | |
226 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8; | |
227 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8; | |
228 putpixel32(x, y, c); | |
229 } | |
230 } | |
231 } | |
232 | |
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
|
233 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
|
234 SDL_LockSurface(display); |
73 | 235 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
|
236 execParams(params); |
73 | 237 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
|
238 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
241 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
|
242 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
|
243 ubyte[4] c; |
73 | 244 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
|
245 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
|
246 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 void swap(T)(ref T a, ref T b) { T c=a; a=b; b=c; } |
73 | 249 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
|
250 |
835320b88ad6
[svn 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 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 } 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
|
258 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
|
259 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
|
260 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
|
261 } |
835320b88ad6
[svn 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 auto error = 0f; |
73 | 263 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
|
264 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) { |
73 | 265 static if (steep) putpixel(var2, var1, col); |
266 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
|
267 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
|
268 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
|
269 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 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
|
273 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
|
274 |
835320b88ad6
[svn 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 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
|
276 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
|
277 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
|
278 SDL_LockSurface(display); |
73 | 279 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
280 auto yend=max(y0, y1); | |
281 for (int y=min(y0, y1); y<=yend; ++y) { | |
282 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
|
283 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 } |
835320b88ad6
[svn 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 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
|
292 SDL_LockSurface(display); |
73 | 293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 } 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
|
303 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
|
304 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
|
305 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
78
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
309 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f32") { |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
310 float sqrt(float val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
311 } |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
312 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f64") { |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
313 double sqrt(double val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
314 real sqrt(real val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
315 } |
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
|
316 |
835320b88ad6
[svn 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 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 while (stopx"~(first?">=":"<=")~"stopy) { |
73 | 329 putpixel(cx+x, cy+y, col); |
330 putpixel(cx+x, cy-y, col); | |
331 putpixel(cx-x, cy+y, col); | |
332 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
|
333 "~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
|
334 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
|
335 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
|
336 "~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
|
337 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
|
338 --"~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
|
339 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
|
340 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
|
341 "~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
|
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 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
344 "; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
345 } |
835320b88ad6
[svn 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 |
73 | 347 import std.stdio; |
348 void circle(T...)(T t) { | |
349 static assert(T.length!<3, "Circle: Needs x, y and radius"); | |
350 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
|
351 SDL_LockSurface(display); |
73 | 352 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
353 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
|
354 auto yradius=xradius; |
73 | 355 if (xradius!>0) return; |
356 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
|
357 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
|
358 auto ratio=xradius*1f/yradius; |
73 | 359 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
|
360 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
|
361 ushort j=cast(ushort)(sqrt(cast(real)(yradius*yradius-i*i))*ratio); |
73 | 362 hline(cx-j, cy+i, 2*j, back_sdl); |
363 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
|
364 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 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
|
367 auto y2square=2*yradius*yradius; |
73 | 368 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
|
369 { 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
|
370 { 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
|
371 } |
835320b88ad6
[svn 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 |
73 | 373 float distance(float x1, float y1, float x2, float y2) { |
374 auto x=x1-x2, y=y1-y2; | |
375 return sqrt(x*x+y*y); | |
376 } | |
377 | |
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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
388 SDL_LockSurface(display); |
73 | 389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 } |
835320b88ad6
[svn 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 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
|
397 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
|
398 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
|
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 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 //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
|
413 for (int i=e+1; i<w; ++i) { |
73 | 414 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
|
415 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
|
416 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
|
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 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
420 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
421 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
422 |
73 | 423 struct screen { |
424 static { | |
425 void opCall(size_t w, size_t h) { | |
426 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); | |
427 } | |
428 int width() { return display.w; } | |
429 int height() { return display.h; } | |
430 } | |
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
|
431 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
432 |
73 | 433 |
434 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); } | |
435 | |
436 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) { | |
437 SDL_Event evt; | |
438 while (SDL_PollEvent(&evt)) { | |
439 switch (evt.type) { | |
440 case SDL_EventType.MouseMotion: | |
441 with (evt.motion) if (mouse) mouse(x, y, 0, false); | |
442 break; | |
443 case SDL_EventType.MouseButtonDown: | |
444 with (evt.button) if (mouse) mouse(x, y, button, true); | |
445 break; | |
446 case SDL_EventType.MouseButtonUp: | |
447 with (evt.button) if (mouse) mouse(x, y, button, false); | |
448 break; | |
449 case SDL_EventType.KeyDown: | |
450 if (key) key(evt.key.keysym.sym, true); | |
451 case SDL_EventType.KeyUp: | |
452 if (key) key(evt.key.keysym.sym, false); | |
453 break; | |
454 case SDL_EventType.Quit: | |
455 throw new Error("Quit"); | |
456 break; | |
457 default: break; | |
458 } | |
459 } | |
460 } | |
461 | |
462 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) { | |
463 events((int a, bool b) { | |
464 if (b) key(a); | |
465 }, mouse); | |
466 } | |
467 | |
468 void events(void delegate(int) key, void delegate(int, int) mouse) { | |
469 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
470 } | |
471 | |
472 void events(void delegate(int, bool) key, void delegate(int, int) mouse) { | |
473 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
474 } |