1
0

r_bspin.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. // alphachannel safe (sets alpha to 0 on rendered portions) 11/21/99
  25. #include <windows.h>
  26. #include <math.h>
  27. #include "r_defs.h"
  28. #include "resource.h"
  29. #include "../Agave/Language/api_language.h"
  30. #ifndef LASER
  31. #define C_THISCLASS C_BSpinClass
  32. #define MOD_NAME "Render / Bass Spin"
  33. class C_THISCLASS : public C_RBASE {
  34. protected:
  35. public:
  36. C_THISCLASS();
  37. virtual ~C_THISCLASS();
  38. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  39. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_BASS_SPIN,desc,128):desc); }
  40. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  41. virtual void load_config(unsigned char *data, int len);
  42. virtual int save_config(unsigned char *data);
  43. void my_triangle(int *fb, int points[6], int width, int height, int color);
  44. int enabled;
  45. int colors[2];
  46. int mode;
  47. int last_a;
  48. int lx[2][2],ly[2][2];
  49. double r_v[2];
  50. double v[2];
  51. double dir[2];
  52. };
  53. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
  54. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  55. void C_THISCLASS::load_config(unsigned char *data, int len)
  56. {
  57. int pos=0;
  58. if (len-pos >= 4) { enabled=GET_INT(); pos+=4; }
  59. if (len-pos >= 4) { colors[0]=GET_INT(); pos+=4; }
  60. if (len-pos >= 4) { colors[1]=GET_INT(); pos+=4; }
  61. if (len-pos >= 4) { mode=GET_INT(); pos+=4; }
  62. }
  63. int C_THISCLASS::save_config(unsigned char *data)
  64. {
  65. int pos=0;
  66. PUT_INT(enabled); pos+=4;
  67. PUT_INT(colors[0]); pos+=4;
  68. PUT_INT(colors[1]); pos+=4;
  69. PUT_INT(mode); pos+=4;
  70. return pos;
  71. }
  72. C_THISCLASS::C_THISCLASS()
  73. {
  74. last_a=0;
  75. enabled=3;
  76. colors[0]=RGB(255,255,255);
  77. colors[1]=RGB(255,255,255);
  78. memset(lx,0,sizeof(lx));
  79. memset(ly,0,sizeof(ly));
  80. memset(v,0,sizeof(v));
  81. r_v[0]=3.14159;
  82. r_v[1]=0.0;
  83. dir[0]=-1.0;
  84. dir[1]=1.0;
  85. mode=1;
  86. }
  87. C_THISCLASS::~C_THISCLASS()
  88. {
  89. }
  90. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  91. {
  92. int y,x;
  93. if (isBeat&0x80000000) return 0;
  94. for (y = 0; y < 2; y ++)
  95. {
  96. if (!(enabled&(1<<y))) continue;
  97. unsigned char *fa_data=(unsigned char *)visdata[0][y];
  98. int xp,yp;
  99. int ss=min(h/2,(w*3)/8);
  100. double s=(double)ss;
  101. int c_x = (!y?w/2-ss/2:w/2+ss/2);
  102. int a=0,d=0;
  103. int nc=1;
  104. int oc6 = colors[y];
  105. for (x = 0; x < 44; x ++)
  106. {
  107. d+=fa_data[x];
  108. }
  109. a=(d*512)/(last_a+30*256);
  110. last_a=d;
  111. if (a > 255) a =255;
  112. v[y] = 0.7*(max(a-104,12)/96.0) + 0.3*v[y];
  113. r_v[y] += 3.14159/6.0 * v[y] * dir[y];
  114. s *= a*1.0/256.0f;
  115. yp=(int)(sin(r_v[y])*s);
  116. xp=(int)(cos(r_v[y])*s);
  117. if (mode==0)
  118. {
  119. if (lx[0][y] || ly[0][y]) line(framebuffer,lx[0][y],ly[0][y],xp+c_x,yp+h/2,w,h,oc6,(g_line_blend_mode&0xff0000)>>16);
  120. lx[0][y]=xp+c_x;
  121. ly[0][y]=yp+h/2;
  122. line(framebuffer,c_x,h/2,c_x+xp,h/2+yp,w,h,oc6,(g_line_blend_mode&0xff0000)>>16);
  123. if (lx[1][y] || ly[1][y]) line(framebuffer,lx[1][y],ly[1][y],c_x-xp,h/2-yp,w,h,oc6,(g_line_blend_mode&0xff0000)>>16);
  124. lx[1][y]=c_x-xp;
  125. ly[1][y]=h/2-yp;
  126. line(framebuffer,c_x,h/2,c_x-xp,h/2-yp,w,h,oc6,(g_line_blend_mode&0xff0000)>>16);
  127. }
  128. else if (mode==1)
  129. {
  130. if (lx[0][y] || ly[0][y])
  131. {
  132. int points[6] = { c_x,h/2, lx[0][y], ly[0][y], xp+c_x,yp+h/2 };
  133. my_triangle(framebuffer,points,w,h,oc6);
  134. }
  135. lx[0][y]=xp+c_x;
  136. ly[0][y]=yp+h/2;
  137. if (lx[1][y] || ly[1][y])
  138. {
  139. int points[6] = { c_x,h/2, lx[1][y], ly[1][y], c_x-xp,h/2-yp };
  140. my_triangle(framebuffer,points,w,h,oc6);
  141. }
  142. lx[1][y]=c_x-xp;
  143. ly[1][y]=h/2-yp;
  144. }
  145. }
  146. return 0;
  147. }
  148. C_RBASE *R_BSpin(char *desc)
  149. {
  150. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  151. return (C_RBASE *) new C_THISCLASS();
  152. }
  153. static C_THISCLASS *g_this;
  154. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  155. {
  156. int *a=NULL;
  157. switch (uMsg)
  158. {
  159. case WM_DRAWITEM:
  160. {
  161. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  162. switch (di->CtlID)
  163. {
  164. case IDC_LC:
  165. GR_DrawColoredButton(di,g_this->colors[0]);
  166. break;
  167. case IDC_RC:
  168. GR_DrawColoredButton(di,g_this->colors[1]);
  169. break;
  170. }
  171. }
  172. return 0;
  173. case WM_INITDIALOG:
  174. if (g_this->enabled&1) CheckDlgButton(hwndDlg,IDC_LEFT,BST_CHECKED);
  175. if (g_this->enabled&2) CheckDlgButton(hwndDlg,IDC_RIGHT,BST_CHECKED);
  176. if (g_this->mode==0) CheckDlgButton(hwndDlg,IDC_LINES,BST_CHECKED);
  177. if (g_this->mode==1) CheckDlgButton(hwndDlg,IDC_TRI,BST_CHECKED);
  178. return 1;
  179. case WM_COMMAND:
  180. switch (LOWORD(wParam))
  181. {
  182. case IDC_LINES:
  183. g_this->mode=IsDlgButtonChecked(hwndDlg,IDC_LINES)?0:1;
  184. return 0;
  185. case IDC_TRI:
  186. g_this->mode=IsDlgButtonChecked(hwndDlg,IDC_TRI)?1:0;
  187. return 0;
  188. case IDC_LEFT:
  189. g_this->enabled&=~1;
  190. g_this->enabled|=IsDlgButtonChecked(hwndDlg,IDC_LEFT)?1:0;
  191. return 0;
  192. case IDC_RIGHT:
  193. g_this->enabled&=~2;
  194. g_this->enabled|=IsDlgButtonChecked(hwndDlg,IDC_RIGHT)?2:0;
  195. return 0;
  196. case IDC_LC:
  197. if (!a) a=&g_this->colors[0];
  198. case IDC_RC:
  199. if (!a) a=&g_this->colors[1];
  200. GR_SelectColor(hwndDlg,a);
  201. InvalidateRect(GetDlgItem(hwndDlg,LOWORD(wParam)),NULL,FALSE);
  202. return 0;
  203. }
  204. }
  205. return 0;
  206. }
  207. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  208. {
  209. g_this = this;
  210. return WASABI_API_CREATEDIALOG(IDD_CFG_BSPIN,hwndParent,g_DlgProc);
  211. }
  212. #define F16(x) ((x)<<16)
  213. void C_THISCLASS::my_triangle(int *fb, int points[6], int width, int height, int color)
  214. {
  215. int ymax;
  216. int p;
  217. int y;
  218. int dx1,dx2;
  219. int x1,x2;
  220. for (y = 0; y < 2; y ++)
  221. {
  222. if (points[1] > points[3])
  223. {
  224. p=points[2]; points[2]=points[0]; points[0]=p;
  225. p=points[3]; points[3]=points[1]; points[1]=p;
  226. }
  227. if (points[3] > points[5])
  228. {
  229. p=points[4]; points[4]=points[2]; points[2]=p;
  230. p=points[5]; points[5]=points[3]; points[3]=p;
  231. }
  232. }
  233. x1=x2=F16(points[0]);
  234. if (points[1] < points[3])
  235. {
  236. dx1 = F16(points[2]-points[0])/(points[3]-points[1]);
  237. } else dx1=0;
  238. if (points[1] < points[5])
  239. dx2 = F16(points[4]-points[0])/(points[5]-points[1]);
  240. else dx2=0;
  241. fb += points[1]*width;
  242. ymax = min(points[5],height);
  243. for (y = points[1]; y < ymax; y ++)
  244. {
  245. if (y == points[3])
  246. {
  247. if (y == points[5]) return;
  248. x1=F16(points[2]);
  249. dx1=F16(points[4]-points[2])/(points[5]-points[3]);
  250. }
  251. if (y >= 0) {
  252. int x,xl;
  253. x=(min(x1,x2)-32768)>>16;
  254. xl=((max(x1,x2)+32768)>>16)-x;
  255. if (xl < 0) xl=-xl;
  256. if (!xl) xl++;
  257. {
  258. int *t=fb+x;
  259. if (x < 0) { t-=x; xl-=x; }
  260. if (x+xl >= width) xl=width-x;
  261. if (xl>0) while (xl--) BLEND_LINE(t++,color);
  262. }
  263. }
  264. fb += width;
  265. x1+=dx1;
  266. x2+=dx2;
  267. }
  268. }
  269. #else
  270. C_RBASE *R_BSpin(char *desc) { return NULL; }
  271. #endif