1
0

r_rotstar.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 "r_defs.h"
  27. #include <math.h>
  28. #include "resource.h"
  29. #include "../Agave/Language/api_language.h"
  30. #ifndef LASER
  31. #define C_THISCLASS C_RotStarClass
  32. #define MOD_NAME "Render / Rotating Stars"
  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_ROTATING_STARS,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 num_colors;
  44. int colors[16];
  45. int color_pos;
  46. double r1;
  47. };
  48. #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
  49. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  50. void C_THISCLASS::load_config(unsigned char *data, int len)
  51. {
  52. int pos=0;
  53. int x=0;
  54. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  55. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  56. else num_colors=0;
  57. }
  58. int C_THISCLASS::save_config(unsigned char *data)
  59. {
  60. int pos=0,x=0;
  61. PUT_INT(num_colors); pos+=4;
  62. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  63. return pos;
  64. }
  65. C_THISCLASS::C_THISCLASS()
  66. {
  67. r1=0.0;
  68. num_colors=1;
  69. memset(colors,0,sizeof(colors));
  70. colors[0]=RGB(255,255,255);
  71. color_pos=0;
  72. }
  73. C_THISCLASS::~C_THISCLASS()
  74. {
  75. }
  76. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  77. {
  78. int x,y,c;
  79. int current_color;
  80. if (isBeat&0x80000000) return 0;
  81. if (!num_colors) return 0;
  82. color_pos++;
  83. if (color_pos >= num_colors * 64) color_pos=0;
  84. {
  85. int p=color_pos/64;
  86. int r=color_pos&63;
  87. int c1,c2;
  88. int r1,r2,r3;
  89. c1=colors[p];
  90. if (p+1 < num_colors)
  91. c2=colors[p+1];
  92. else c2=colors[0];
  93. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  94. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  95. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  96. current_color=r1|(r2<<8)|(r3<<16);
  97. }
  98. x=(int) (cos(r1)*w/4.0);
  99. y=(int) (sin(r1)*h/4.0);
  100. for (c = 0; c < 2; c ++)
  101. {
  102. double r2=-r1;
  103. int s=0;
  104. int t;
  105. int a,b;
  106. int nx, ny;
  107. int lx,ly,l;
  108. a=x;
  109. b=y;
  110. for (l = 3; l < 14; l ++)
  111. if (visdata[0][c][l] > s &&
  112. visdata[0][c][l] > visdata[0][c][l+1]+4 &&
  113. visdata[0][c][l] > visdata[0][c][l-1]+4)
  114. s=visdata[0][c][l];
  115. if (c==1) { a=-a; b=-b; }
  116. double vw,vh;
  117. vw=w/8.0*(s+9)/88.0;
  118. vh=h/8.0*(s+9)/88.0;
  119. nx=(int) (cos(r2)*vw);
  120. ny=(int) (sin(r2)*vh);
  121. lx = w/2+a+nx;
  122. ly = h/2+b+ny;
  123. r2+=3.14159*4.0/5.0;
  124. for (t = 0; t < 5; t ++)
  125. {
  126. int nx, ny;
  127. nx=(int) (cos(r2)*vw+w/2+a);
  128. ny=(int) (sin(r2)*vh+h/2+b);
  129. r2+=3.14159*4.0/5.0;
  130. line(framebuffer,lx,ly,nx,ny,w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  131. lx=nx;
  132. ly=ny;
  133. }
  134. }
  135. r1+=0.1;
  136. return 0;
  137. }
  138. C_RBASE *R_RotStar(char *desc)
  139. {
  140. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  141. return (C_RBASE *) new C_THISCLASS();
  142. }
  143. static C_THISCLASS *g_this;
  144. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  145. {
  146. int *a=NULL;
  147. switch (uMsg)
  148. {
  149. case WM_DRAWITEM:
  150. {
  151. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  152. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  153. {
  154. int x;
  155. int w=di->rcItem.right-di->rcItem.left;
  156. int l=0,nl;
  157. for (x = 0; x < g_this->num_colors; x ++)
  158. {
  159. int color=g_this->colors[x];
  160. nl = (w*(x+1))/g_this->num_colors;
  161. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  162. HPEN hPen,hOldPen;
  163. HBRUSH hBrush,hOldBrush;
  164. LOGBRUSH lb={(COLORREF)BS_SOLID,(COLORREF)color,(COLORREF)0};
  165. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  166. hBrush = CreateBrushIndirect(&lb);
  167. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  168. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  169. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  170. SelectObject(di->hDC,hOldPen);
  171. SelectObject(di->hDC,hOldBrush);
  172. DeleteObject(hBrush);
  173. DeleteObject(hPen);
  174. l=nl;
  175. }
  176. }
  177. }
  178. return 0;
  179. case WM_INITDIALOG:
  180. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  181. return 1;
  182. case WM_COMMAND:
  183. switch (LOWORD(wParam))
  184. {
  185. case IDC_NUMCOL:
  186. {
  187. int p;
  188. BOOL tr=FALSE;
  189. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  190. if (tr)
  191. {
  192. if (p > 16) p = 16;
  193. g_this->num_colors=p;
  194. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  195. }
  196. }
  197. break;
  198. case IDC_DEFCOL:
  199. {
  200. int wc=-1,w,h;
  201. POINT p;
  202. RECT r;
  203. GetCursorPos(&p);
  204. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  205. p.x -= r.left;
  206. p.y -= r.top;
  207. w=r.right-r.left;
  208. h=r.bottom-r.top;
  209. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  210. {
  211. wc = (p.x*g_this->num_colors)/w;
  212. }
  213. if (wc>=0)
  214. {
  215. GR_SelectColor(hwndDlg,g_this->colors+wc);
  216. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  217. }
  218. }
  219. }
  220. }
  221. return 0;
  222. }
  223. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  224. {
  225. g_this = this;
  226. return WASABI_API_CREATEDIALOG(IDD_CFG_ROTSTAR,hwndParent,g_DlgProc);
  227. }
  228. #else
  229. C_RBASE *R_RotStar(char *desc)
  230. { return NULL; }
  231. #endif