1
0

r_dotgrid.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 "r_defs.h"
  28. #include <math.h>
  29. #include "resource.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #define C_THISCLASS C_DotGridClass
  33. #define MOD_NAME "Render / Dot Grid"
  34. class C_THISCLASS : public C_RBASE {
  35. protected:
  36. public:
  37. C_THISCLASS();
  38. virtual ~C_THISCLASS();
  39. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  40. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_DOT_GRID,desc,128):desc); }
  41. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  42. virtual void load_config(unsigned char *data, int len);
  43. virtual int save_config(unsigned char *data);
  44. int num_colors;
  45. int colors[16];
  46. int color_pos;
  47. int xp;
  48. int yp;
  49. int x_move;
  50. int y_move;
  51. int spacing;
  52. int blend;
  53. };
  54. #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
  55. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  56. void C_THISCLASS::load_config(unsigned char *data, int len)
  57. {
  58. int pos=0;
  59. int x=0;
  60. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  61. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  62. else num_colors=0;
  63. if (len-pos >= 4) { spacing=GET_INT(); pos+=4; }
  64. if (len-pos >= 4) { x_move=GET_INT(); pos+=4; }
  65. if (len-pos >= 4) { y_move=GET_INT(); pos+=4; }
  66. if (len-pos >= 4) { blend=GET_INT(); pos+=4; }
  67. }
  68. int C_THISCLASS::save_config(unsigned char *data)
  69. {
  70. int pos=0,x=0;
  71. PUT_INT(num_colors); pos+=4;
  72. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  73. PUT_INT(spacing); pos+=4;
  74. PUT_INT(x_move); pos+=4;
  75. PUT_INT(y_move); pos+=4;
  76. PUT_INT(blend); pos+=4;
  77. return pos;
  78. }
  79. C_THISCLASS::C_THISCLASS()
  80. {
  81. num_colors=1;
  82. memset(colors,0,sizeof(colors));
  83. colors[0]=RGB(255,255,255);
  84. color_pos=0;
  85. xp=0;
  86. yp=0;
  87. x_move=128;
  88. y_move=128;
  89. spacing=8;
  90. blend=3;
  91. }
  92. C_THISCLASS::~C_THISCLASS()
  93. {
  94. }
  95. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  96. {
  97. int x,y;
  98. int current_color;
  99. if (isBeat&0x80000000) return 0;
  100. if (!num_colors) return 0;
  101. color_pos++;
  102. if (color_pos >= num_colors * 64) color_pos=0;
  103. {
  104. int p=color_pos/64;
  105. int r=color_pos&63;
  106. int c1,c2;
  107. int r1,r2,r3;
  108. c1=colors[p];
  109. if (p+1 < num_colors)
  110. c2=colors[p+1];
  111. else c2=colors[0];
  112. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  113. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  114. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  115. current_color=r1|(r2<<8)|(r3<<16);
  116. }
  117. if (spacing<2)spacing=2;
  118. while (yp < 0) yp+=spacing*256;
  119. while (xp < 0) xp+=spacing*256;
  120. int sy=(yp>>8)%spacing;
  121. int sx=(xp>>8)%spacing;
  122. framebuffer += sy*w;
  123. for (y = sy; y < h; y += spacing)
  124. {
  125. if (blend==1)
  126. for (x = sx; x < w; x += spacing)
  127. framebuffer[x]=BLEND(framebuffer[x],current_color);
  128. else if (blend == 2)
  129. for (x = sx; x < w; x += spacing)
  130. framebuffer[x]=BLEND_AVG(framebuffer[x],current_color);
  131. else if (blend == 3)
  132. for (x = sx; x < w; x += spacing)
  133. BLEND_LINE(framebuffer+x,current_color);
  134. else
  135. for (x = sx; x < w; x += spacing)
  136. framebuffer[x]=current_color;
  137. framebuffer += w*spacing;
  138. }
  139. xp+=x_move;
  140. yp+=y_move;
  141. return 0;
  142. }
  143. C_RBASE *R_DotGrid(char *desc)
  144. {
  145. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  146. return (C_RBASE *) new C_THISCLASS();
  147. }
  148. static C_THISCLASS *g_this;
  149. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  150. {
  151. int *a=NULL;
  152. switch (uMsg)
  153. {
  154. case WM_DRAWITEM:
  155. {
  156. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  157. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  158. {
  159. int x;
  160. int w=di->rcItem.right-di->rcItem.left;
  161. int l=0,nl;
  162. for (x = 0; x < g_this->num_colors; x ++)
  163. {
  164. int color=g_this->colors[x];
  165. nl = (w*(x+1))/g_this->num_colors;
  166. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  167. HPEN hPen,hOldPen;
  168. HBRUSH hBrush,hOldBrush;
  169. LOGBRUSH lb={ (COLORREF)BS_SOLID,(COLORREF)color,(COLORREF)0};
  170. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  171. hBrush = CreateBrushIndirect(&lb);
  172. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  173. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  174. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  175. SelectObject(di->hDC,hOldPen);
  176. SelectObject(di->hDC,hOldBrush);
  177. DeleteObject(hBrush);
  178. DeleteObject(hPen);
  179. l=nl;
  180. }
  181. }
  182. }
  183. return 0;
  184. case WM_INITDIALOG:
  185. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  186. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,33);
  187. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->x_move/32+16);
  188. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMIN,0,0);
  189. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMAX,0,33);
  190. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,g_this->y_move/32+16);
  191. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  192. SetDlgItemInt(hwndDlg,IDC_EDIT1,g_this->spacing,FALSE);
  193. if (g_this->blend==1)
  194. CheckDlgButton(hwndDlg,IDC_RADIO2,BST_CHECKED);
  195. else if (g_this->blend==2)
  196. CheckDlgButton(hwndDlg,IDC_RADIO3,BST_CHECKED);
  197. else if (g_this->blend==3)
  198. CheckDlgButton(hwndDlg,IDC_RADIO4,BST_CHECKED);
  199. else
  200. CheckDlgButton(hwndDlg,IDC_RADIO1,BST_CHECKED);
  201. return 1;
  202. case WM_HSCROLL:
  203. {
  204. HWND swnd = (HWND) lParam;
  205. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  206. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  207. {
  208. g_this->x_move=(t-16)*32;
  209. }
  210. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER2))
  211. {
  212. g_this->y_move=(t-16)*32;
  213. }
  214. }
  215. return 0;
  216. case WM_COMMAND:
  217. switch (LOWORD(wParam))
  218. {
  219. case IDC_BUTTON1:
  220. g_this->x_move=0;
  221. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,16);
  222. return 0;
  223. case IDC_BUTTON3:
  224. g_this->y_move=0;
  225. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,16);
  226. return 0;
  227. case IDC_RADIO1:
  228. case IDC_RADIO2:
  229. case IDC_RADIO3:
  230. case IDC_RADIO4:
  231. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO1)) g_this->blend=0;
  232. else if (IsDlgButtonChecked(hwndDlg,IDC_RADIO2)) g_this->blend=1;
  233. else if (IsDlgButtonChecked(hwndDlg,IDC_RADIO3)) g_this->blend=2;
  234. else if (IsDlgButtonChecked(hwndDlg,IDC_RADIO4)) g_this->blend=3;
  235. break;
  236. case IDC_NUMCOL:
  237. {
  238. int p;
  239. BOOL tr=FALSE;
  240. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  241. if (tr)
  242. {
  243. if (p > 16) p = 16;
  244. g_this->num_colors=p;
  245. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  246. }
  247. }
  248. break;
  249. case IDC_EDIT1:
  250. {
  251. int p;
  252. BOOL tr=FALSE;
  253. p=GetDlgItemInt(hwndDlg,IDC_EDIT1,&tr,FALSE);
  254. if (tr)
  255. {
  256. if (p < 2) p = 2;
  257. g_this->spacing=p;
  258. }
  259. }
  260. break;
  261. case IDC_DEFCOL:
  262. {
  263. int wc=-1,w,h;
  264. POINT p;
  265. RECT r;
  266. GetCursorPos(&p);
  267. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  268. p.x -= r.left;
  269. p.y -= r.top;
  270. w=r.right-r.left;
  271. h=r.bottom-r.top;
  272. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  273. {
  274. wc = (p.x*g_this->num_colors)/w;
  275. }
  276. if (wc>=0)
  277. {
  278. GR_SelectColor(hwndDlg,g_this->colors+wc);
  279. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  280. }
  281. }
  282. }
  283. }
  284. return 0;
  285. }
  286. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  287. {
  288. g_this = this;
  289. return WASABI_API_CREATEDIALOG(IDD_CFG_DOTGRID,hwndParent,g_DlgProc);
  290. }
  291. #else
  292. C_RBASE *R_DotGrid(char *desc) { return NULL; }
  293. #endif