1
0

r_clear.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. #include <windows.h>
  25. #include <stdlib.h>
  26. #include <vfw.h>
  27. #include <commctrl.h>
  28. #include "resource.h"
  29. #include "r_defs.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #define MOD_NAME "Render / Clear screen"
  33. #define C_THISCLASS C_ClearClass
  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_CLEAR_SCREEN,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 enabled;
  45. int onlyfirst;
  46. int color;
  47. int fcounter;
  48. int blend, blendavg;
  49. };
  50. static C_THISCLASS *g_ConfigThis; // global configuration dialog pointer
  51. static HINSTANCE g_hDllInstance; // global DLL instance pointer (not needed in this example, but could be useful)
  52. C_THISCLASS::~C_THISCLASS()
  53. {
  54. }
  55. // configuration read/write
  56. C_THISCLASS::C_THISCLASS() // set up default configuration
  57. {
  58. color = 0;
  59. onlyfirst = 0;
  60. fcounter=0;
  61. blend = 0;
  62. blendavg = 0;
  63. enabled=1;
  64. }
  65. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  66. void C_THISCLASS::load_config(unsigned char *data, int len) // read configuration of max length "len" from data.
  67. {
  68. int pos=0;
  69. if (len-pos >= 4) { enabled=GET_INT(); pos+=4; }
  70. if (len-pos >= 4) { color=GET_INT(); pos+=4; }
  71. if (len-pos >= 4) { blend=GET_INT(); pos+=4; }
  72. if (len-pos >= 4) { blendavg=GET_INT(); pos+=4; }
  73. if (len-pos >= 4) { onlyfirst=GET_INT(); pos+=4; }
  74. }
  75. #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
  76. int C_THISCLASS::save_config(unsigned char *data) // write configuration to data, return length. config data should not exceed 64k.
  77. {
  78. int pos=0;
  79. PUT_INT(enabled); pos+=4;
  80. PUT_INT(color); pos+=4;
  81. PUT_INT(blend); pos+=4;
  82. PUT_INT(blendavg); pos+=4;
  83. PUT_INT(onlyfirst); pos+=4;
  84. return pos;
  85. }
  86. // render function
  87. // render should return 0 if it only used framebuffer, or 1 if the new output data is in fbout. this is
  88. // used when you want to do something that you'd otherwise need to make a copy of the framebuffer.
  89. // w and h are the width and height of the screen, in pixels.
  90. // isBeat is 1 if a beat has been detected.
  91. // visdata is in the format of [spectrum:0,wave:1][channel][band].
  92. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  93. {
  94. int i=w*h;
  95. int *p=framebuffer;
  96. if (!enabled) return 0;
  97. if (onlyfirst && fcounter) return 0;
  98. if (isBeat&0x80000000) return 0;
  99. fcounter++;
  100. if (blend==2) while (i--) BLEND_LINE(p++,color);
  101. else if (blend) while (i--) *p++=BLEND(*p,color);
  102. else if (blendavg) while (i--) *p++=BLEND_AVG(*p,color);
  103. else while (i--) *p++=color;
  104. return 0;
  105. }
  106. // configuration dialog stuff
  107. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  108. {
  109. switch (uMsg)
  110. {
  111. case WM_INITDIALOG:
  112. if (g_ConfigThis->enabled) CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
  113. if (g_ConfigThis->onlyfirst) CheckDlgButton(hwndDlg,IDC_CLEARFIRSTFRAME,BST_CHECKED);
  114. if (g_ConfigThis->blend==1) CheckDlgButton(hwndDlg,IDC_ADDITIVE,BST_CHECKED);
  115. else if (g_ConfigThis->blend==2) CheckDlgButton(hwndDlg,IDC_DEFRENDBLEND,BST_CHECKED);
  116. else if (g_ConfigThis->blendavg) CheckDlgButton(hwndDlg,IDC_5050,BST_CHECKED);
  117. if (!g_ConfigThis->blend && !g_ConfigThis->blendavg)
  118. CheckDlgButton(hwndDlg,IDC_REPLACE,BST_CHECKED);
  119. return 1;
  120. case WM_DRAWITEM:
  121. {
  122. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  123. if (di->CtlID == IDC_DEFCOL) // paint nifty color button
  124. {
  125. int w=di->rcItem.right-di->rcItem.left;
  126. int _color=g_ConfigThis->color;
  127. _color = ((_color>>16)&0xff)|(_color&0xff00)|((_color<<16)&0xff0000);
  128. HPEN hPen,hOldPen;
  129. HBRUSH hBrush,hOldBrush;
  130. LOGBRUSH lb={(COLORREF)BS_SOLID,(COLORREF)_color,(COLORREF)0};
  131. hPen = (HPEN)CreatePen(PS_SOLID,0,_color);
  132. hBrush = CreateBrushIndirect(&lb);
  133. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  134. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  135. Rectangle(di->hDC,di->rcItem.left,di->rcItem.top,di->rcItem.right,di->rcItem.bottom);
  136. SelectObject(di->hDC,hOldPen);
  137. SelectObject(di->hDC,hOldBrush);
  138. DeleteObject(hBrush);
  139. DeleteObject(hPen);
  140. }
  141. }
  142. return 0;
  143. case WM_COMMAND:
  144. if ((LOWORD(wParam) == IDC_CHECK1) ||
  145. (LOWORD(wParam) == IDC_ADDITIVE) ||
  146. (LOWORD(wParam) == IDC_REPLACE) ||
  147. (LOWORD(wParam) == IDC_5050) ||
  148. (LOWORD(wParam) == IDC_DEFRENDBLEND))
  149. {
  150. g_ConfigThis->enabled=IsDlgButtonChecked(hwndDlg,IDC_CHECK1)?1:0;
  151. g_ConfigThis->blend=IsDlgButtonChecked(hwndDlg,IDC_ADDITIVE)?1:0;
  152. if (!g_ConfigThis->blend)
  153. g_ConfigThis->blend=IsDlgButtonChecked(hwndDlg,IDC_DEFRENDBLEND)?2:0;
  154. g_ConfigThis->blendavg=IsDlgButtonChecked(hwndDlg,IDC_5050)?1:0;
  155. }
  156. if (LOWORD(wParam) == IDC_CLEARFIRSTFRAME)
  157. {
  158. g_ConfigThis->onlyfirst=IsDlgButtonChecked(hwndDlg,IDC_CLEARFIRSTFRAME)?1:0;
  159. if (g_ConfigThis->onlyfirst) g_ConfigThis->fcounter=0;
  160. }
  161. if (LOWORD(wParam) == IDC_DEFCOL) // handle clicks to nifty color button
  162. {
  163. int *a=&(g_ConfigThis->color);
  164. static COLORREF custcolors[16];
  165. CHOOSECOLOR cs;
  166. cs.lStructSize = sizeof(cs);
  167. cs.hwndOwner = hwndDlg;
  168. cs.hInstance = 0;
  169. cs.rgbResult=((*a>>16)&0xff)|(*a&0xff00)|((*a<<16)&0xff0000);
  170. cs.lpCustColors = custcolors;
  171. cs.Flags = CC_RGBINIT|CC_FULLOPEN;
  172. if (ChooseColor(&cs))
  173. {
  174. *a = ((cs.rgbResult>>16)&0xff)|(cs.rgbResult&0xff00)|((cs.rgbResult<<16)&0xff0000);
  175. g_ConfigThis->color = *a;
  176. }
  177. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  178. }
  179. }
  180. return 0;
  181. }
  182. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent) // return NULL if no config dialog possible
  183. {
  184. g_ConfigThis = this;
  185. return WASABI_API_CREATEDIALOG(IDD_CFG_CLEAR,hwndParent,g_DlgProc);
  186. }
  187. // export stuff
  188. C_RBASE *R_Clear(char *desc) // creates a new effect object if desc is NULL, otherwise fills in desc with description
  189. {
  190. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  191. return (C_RBASE *) new C_THISCLASS();
  192. }
  193. #else
  194. C_RBASE *R_Clear(char *desc) { return NULL; }
  195. #endif