1
0

r_oscstar.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 11/21/99
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include <math.h>
  28. #include "r_defs.h"
  29. #include "resource.h"
  30. #include "../Agave/Language/api_language.h"
  31. #define C_THISCLASS C_OscStarClass
  32. #define MOD_NAME "Render / Oscilliscope Star"
  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_OSCILLOSCOPE_STAR,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. int effect;
  44. int num_colors;
  45. int colors[16];
  46. int size, rot;
  47. int color_pos;
  48. double m_r;
  49. };
  50. #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
  51. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  52. void C_THISCLASS::load_config(unsigned char *data, int len)
  53. {
  54. int pos=0;
  55. int x=0;
  56. if (len-pos >= 4) { effect=GET_INT(); pos+=4; }
  57. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  58. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  59. else num_colors=1;
  60. if (len-pos >= 4) { size=GET_INT(); pos+=4; }
  61. if (len-pos >= 4) { rot=GET_INT(); pos+=4; }
  62. }
  63. int C_THISCLASS::save_config(unsigned char *data)
  64. {
  65. int pos=0,x=0;
  66. PUT_INT(effect); pos+=4;
  67. PUT_INT(num_colors); pos+=4;
  68. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  69. PUT_INT(size); pos+=4;
  70. PUT_INT(rot); pos+=4;
  71. return pos;
  72. }
  73. C_THISCLASS::C_THISCLASS()
  74. {
  75. effect=0|(2<<2)|(2<<4);
  76. num_colors=1;
  77. memset(colors,0,sizeof(colors));
  78. colors[0]=RGB(255,255,255);
  79. color_pos=0;
  80. m_r=0.0;
  81. size=8; // of 16
  82. rot=3; // of 16
  83. }
  84. C_THISCLASS::~C_THISCLASS()
  85. {
  86. }
  87. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  88. {
  89. int x;
  90. int current_color;
  91. unsigned char *fa_data;
  92. char center_channel[576];
  93. int which_ch=(effect>>2)&3;
  94. int y_pos=(effect>>4);
  95. if (isBeat&0x80000000) return 0;
  96. if (!num_colors) return 0;
  97. color_pos++;
  98. if (color_pos >= num_colors * 64) color_pos=0;
  99. {
  100. int p=color_pos/64;
  101. int r=color_pos&63;
  102. int c1,c2;
  103. int r1,r2,r3;
  104. c1=colors[p];
  105. if (p+1 < num_colors)
  106. c2=colors[p+1];
  107. else c2=colors[0];
  108. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  109. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  110. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  111. current_color=r1|(r2<<8)|(r3<<16);
  112. }
  113. if (which_ch>=2)
  114. {
  115. for (x = 0; x < 576; x ++) center_channel[x]=visdata[1][0][x]/2+visdata[1][1][x]/2;
  116. }
  117. if (which_ch < 2) fa_data=(unsigned char *)&visdata[1][which_ch][0];
  118. else fa_data=(unsigned char *)center_channel;
  119. {
  120. double s=size/32.0;
  121. #ifdef LASER
  122. double c_x;
  123. double is=s;
  124. if (y_pos == 2) c_x = 0;
  125. else if (y_pos == 0) c_x=-0.5;
  126. else c_x=0.5;
  127. #else
  128. int c_x;
  129. int is=min((int)(h*s),(int)(w*s));
  130. if (y_pos == 2) c_x = w/2;
  131. else if (y_pos == 0) c_x=(w/4);
  132. else c_x=w/2+w/4;
  133. #endif
  134. {
  135. int q,ii=0;
  136. for (q = 0; q < 5; q ++)
  137. {
  138. double s,c;
  139. s=sin(m_r+q*(3.14159*2.0/5.0));
  140. c=cos(m_r+q*(3.14159*2.0/5.0));
  141. double p=0.0;
  142. #ifdef LASER
  143. double lx=c_x;
  144. double ly=0.0;
  145. int t=6;
  146. #else
  147. if (y_pos == 2) c_x = w/2;
  148. else if (y_pos == 0) c_x=(w/4);
  149. int lx=c_x;
  150. int ly=h/2;
  151. int t=64;
  152. #endif
  153. double dp=is/(double)t;
  154. double dfactor=1.0/1024.0f;
  155. double hw=is;
  156. while (t--)
  157. {
  158. double ale=(((fa_data[ii]^128)-128)*dfactor*hw);
  159. #ifdef LASER
  160. double x,y;
  161. ii+=8;
  162. x=c_x+(c*p)-(s*ale);
  163. y=(s*p)+(c*ale);
  164. if ((x > -1.0 && x < 1.0 && y > -1.0 && y < 1.0) ||
  165. (lx > -1.0 && lx < 1.0 && ly > -.10 && ly < 1.0))
  166. {
  167. LineType l;
  168. l.color=current_color;
  169. l.mode=0;
  170. l.x1=(float)x;
  171. l.x2=(float)lx;
  172. l.y1=(float)y;
  173. l.y2=(float)ly;
  174. g_laser_linelist->AddLine(&l);
  175. }
  176. #else
  177. int x,y;
  178. ii++;
  179. x=c_x+(int)(c*p)-(int)(s*ale);
  180. y=h/2+(int)(s*p)+(int)(c*ale);
  181. if ((x >= 0 && x < w && y >= 0 && y < h) ||
  182. (lx >= 0 && lx < w && ly >= 0 && ly < h))
  183. {
  184. line(framebuffer,x,y,lx,ly,w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  185. }
  186. #endif
  187. lx=x;
  188. ly=y;
  189. p+=dp;
  190. dfactor -= ((1.0/1024.0f)-(1.0/128.0f))/64.0f;
  191. }
  192. }
  193. m_r+=0.01 * (double)rot;
  194. if (m_r >= 3.14159*2)
  195. m_r -= 3.14159*2;
  196. }
  197. }
  198. return 0;
  199. }
  200. C_RBASE *R_OscStars(char *desc)
  201. {
  202. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  203. return (C_RBASE *) new C_THISCLASS();
  204. }
  205. static C_THISCLASS *g_this;
  206. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  207. {
  208. int *a=NULL;
  209. switch (uMsg)
  210. {
  211. case WM_DRAWITEM:
  212. {
  213. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  214. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  215. {
  216. int x;
  217. int w=di->rcItem.right-di->rcItem.left;
  218. int l=0,nl;
  219. for (x = 0; x < g_this->num_colors; x ++)
  220. {
  221. int color=g_this->colors[x];
  222. nl = (w*(x+1))/g_this->num_colors;
  223. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  224. HPEN hPen,hOldPen;
  225. HBRUSH hBrush,hOldBrush;
  226. LOGBRUSH lb={(COLORREF)BS_SOLID,(COLORREF)color,(COLORREF)0};
  227. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  228. hBrush = CreateBrushIndirect(&lb);
  229. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  230. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  231. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  232. SelectObject(di->hDC,hOldPen);
  233. SelectObject(di->hDC,hOldBrush);
  234. DeleteObject(hBrush);
  235. DeleteObject(hPen);
  236. l=nl;
  237. }
  238. }
  239. }
  240. return 0;
  241. case WM_HSCROLL:
  242. {
  243. HWND swnd = (HWND) lParam;
  244. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  245. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  246. {
  247. g_this->size=t;
  248. }
  249. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER2))
  250. {
  251. g_this->rot=t-16;
  252. }
  253. }
  254. return 0;
  255. case WM_INITDIALOG:
  256. switch ((g_this->effect>>2)&3)
  257. {
  258. case 0: CheckDlgButton(hwndDlg,IDC_LEFTCH,BST_CHECKED); break;
  259. case 1: CheckDlgButton(hwndDlg,IDC_RIGHTCH,BST_CHECKED); break;
  260. case 2: CheckDlgButton(hwndDlg,IDC_MIDCH,BST_CHECKED); break;
  261. }
  262. switch ((g_this->effect>>4)&3)
  263. {
  264. case 0: CheckDlgButton(hwndDlg,IDC_TOP,BST_CHECKED); break;
  265. case 1: CheckDlgButton(hwndDlg,IDC_BOTTOM,BST_CHECKED); break;
  266. case 2: CheckDlgButton(hwndDlg,IDC_CENTER,BST_CHECKED); break;
  267. }
  268. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  269. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  270. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,32);
  271. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->size);
  272. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMIN,0,0);
  273. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMAX,0,32);
  274. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,g_this->rot+16);
  275. return 1;
  276. case WM_COMMAND:
  277. switch (LOWORD(wParam))
  278. {
  279. case IDC_LEFTCH: g_this->effect&=~12; break;
  280. case IDC_RIGHTCH: g_this->effect&=~12; g_this->effect|=4; break;
  281. case IDC_MIDCH: g_this->effect&=~12; g_this->effect|=8; break;
  282. case IDC_TOP: g_this->effect&=~48; break;
  283. case IDC_BOTTOM: g_this->effect&=~48; g_this->effect|=16; break;
  284. case IDC_CENTER: g_this->effect&=~48; g_this->effect|=32; break;
  285. case IDC_NUMCOL:
  286. {
  287. int p;
  288. BOOL tr=FALSE;
  289. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  290. if (tr)
  291. {
  292. if (p > 16) p = 16;
  293. g_this->num_colors=p;
  294. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  295. }
  296. }
  297. break;
  298. case IDC_DEFCOL:
  299. {
  300. int wc=-1,w,h;
  301. POINT p;
  302. RECT r;
  303. GetCursorPos(&p);
  304. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  305. p.x -= r.left;
  306. p.y -= r.top;
  307. w=r.right-r.left;
  308. h=r.bottom-r.top;
  309. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  310. {
  311. wc = (p.x*g_this->num_colors)/w;
  312. }
  313. if (wc>=0)
  314. {
  315. GR_SelectColor(hwndDlg,g_this->colors+wc);
  316. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  317. }
  318. }
  319. }
  320. }
  321. return 0;
  322. }
  323. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  324. {
  325. g_this = this;
  326. return WASABI_API_CREATEDIALOG(IDD_CFG_OSCSTAR,hwndParent,g_DlgProc);
  327. }