wndmenu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #ifndef _WNDMENU_H_
  2. #define _WNDMENU_H_
  3. //need to define WNDMENU_CAPTION to the caption
  4. // you can define these to remove menu functionality
  5. //WNDMENU_NOABOUT // no about header
  6. //WNDMENU_NOVOLUME // no volume submenu
  7. //WNDMENU_NOINFO // no info submenu
  8. //WNDMENU_NOZOOM // no zoom 50/100/200/400
  9. //WNDMENU_NOZOOMFS // no zoom fullscreen
  10. //WNDMENU_NOOPTIONS // no options submenu
  11. //WNDMENU_NOPOSITIONSAVE // disables saving of position
  12. //WNDMENU_NOSUBTITLES // no subtitles submenu
  13. #ifndef ABS
  14. #define ABS(x) ((x)<0?-(x):(x))
  15. #endif
  16. static void _ReadConfigItemInt(char *name, int *value)
  17. {
  18. HKEY hKey;
  19. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Nullsoft\\NSVPlay",0,KEY_READ,&hKey) == ERROR_SUCCESS)
  20. {
  21. DWORD t,l=4;
  22. int a;
  23. if (RegQueryValueEx(hKey,name,NULL,&t,(unsigned char *)&a,&l ) == ERROR_SUCCESS && t == REG_DWORD)
  24. *value=a;
  25. RegCloseKey(hKey);
  26. }
  27. }
  28. static void _WriteConfigItemInt(char *name, int value)
  29. {
  30. HKEY hKey;
  31. if (RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Nullsoft\\NSVPlay",&hKey) == ERROR_SUCCESS)
  32. {
  33. RegSetValueEx(hKey,name,0,REG_DWORD,(unsigned char*)&value,4);
  34. RegCloseKey(hKey);
  35. }
  36. }
  37. static void _InsertString(HMENU hMenu, int pos, char *string, int id, int checked=0, int disabled=0)
  38. {
  39. MENUITEMINFO inf={sizeof(inf),MIIM_ID|MIIM_STATE|MIIM_TYPE,MFT_STRING,
  40. (checked?MFS_CHECKED:0) | (disabled?MFS_DISABLED:MFS_ENABLED), id,
  41. };
  42. inf.dwTypeData = string;
  43. InsertMenuItem(hMenu,pos,TRUE,&inf);
  44. }
  45. static void _InsertSep(HMENU hMenu, int pos)
  46. {
  47. MENUITEMINFO inf={sizeof(inf),MIIM_TYPE,MFT_SEPARATOR };
  48. InsertMenuItem(hMenu,pos,TRUE,&inf);
  49. }
  50. static HMENU _InsertSub(HMENU hMenu, int pos, char *string)
  51. {
  52. MENUITEMINFO inf={sizeof(inf),MIIM_TYPE|MIIM_SUBMENU,MFT_STRING };
  53. inf.dwTypeData = string;
  54. inf.hSubMenu=CreatePopupMenu();
  55. InsertMenuItem(hMenu,pos,TRUE,&inf);
  56. return inf.hSubMenu;
  57. }
  58. #define MENUITEM_ABOUT 1
  59. #define MENUITEM_INFOBASE 10
  60. #define MENUITEM_VOLUMEBASE 100
  61. #define MENUITEM_VSYNC 120
  62. #define MENUITEM_ASPECTADJ 121
  63. #define MENUITEM_VOVERLAYS 122
  64. #define MENUITEM_VDDRAW 123
  65. #define MENUITEM_SOFTVOLMIX 124
  66. #define MENUITEM_ENABLESUBTITLES 125
  67. #define MENUITEM_SUBSIZEBASE 126 // 5 sizes
  68. #define MENUITEM_ZOOM50 112
  69. #define MENUITEM_ZOOM100 113
  70. #define MENUITEM_ZOOM200 114
  71. #define MENUITEM_ZOOM400 115
  72. #define MENUITEM_ZOOMFS 116
  73. #define MENUITEM_CLOSE 200
  74. #define MENUITEM_SUBSLANGBASE 300
  75. extern int g_audio_use_mixer;
  76. LRESULT my_wndcallback(void *token, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  77. {
  78. if (token)
  79. {
  80. parms *parm=(parms*)token;
  81. #ifndef WNDMENU_NOPOSITIONSAVE
  82. if (uMsg == WM_MOVE)
  83. {
  84. if (!parm->vidOut->is_fullscreen())
  85. {
  86. RECT r;
  87. GetWindowRect(hwnd,&r);
  88. _WriteConfigItemInt("xpos",r.left);
  89. _WriteConfigItemInt("ypos",r.top);
  90. }
  91. }
  92. #endif
  93. if(uMsg==WM_SETCURSOR && parm->vidOut->is_fullscreen()) {
  94. SetCursor(NULL);
  95. return TRUE;
  96. }
  97. if (uMsg == WM_RBUTTONUP && !parm->vidOut->is_fullscreen())
  98. {
  99. int pos=0;
  100. HMENU hMenu=CreatePopupMenu();
  101. #ifndef WNDMENU_NOABOUT
  102. _InsertString(hMenu,pos++,WNDMENU_CAPTION,MENUITEM_ABOUT);
  103. _InsertSep(hMenu,pos++);
  104. #endif
  105. #ifndef WNDMENU_NOINFO
  106. if (parm->decode)
  107. {
  108. char buf[1024];
  109. int subpos=0;
  110. int tmpid=MENUITEM_INFOBASE;
  111. HMENU sub=_InsertSub(hMenu,pos++,"Info");
  112. { // title
  113. char *v=parm->decode->getTitle();
  114. if (v && *v)
  115. {
  116. char *tmp=(char*)malloc(strlen(v)+32);
  117. wsprintf(tmp,"Title: %s",v);
  118. char *p=tmp;
  119. while (*p)
  120. {
  121. if (*p == '_') *p=' ';
  122. p++;
  123. }
  124. _InsertString(sub,subpos++,tmp,tmpid++);
  125. free(tmp);
  126. }
  127. }
  128. { // length
  129. int lenms=parm->decode->getlen();
  130. if (lenms != ~0)
  131. {
  132. wsprintf(buf,"Length: %d:%02d",lenms/60000,(lenms/1000)%60);
  133. _InsertString(sub,subpos++,buf,tmpid++);
  134. }
  135. }
  136. { // codecs
  137. int a=(parm->decode->getBitrate()+500)/1000;
  138. unsigned int a2=parm->decode->getFileSize();
  139. if (a)
  140. {
  141. wsprintf(buf,"Bitrate: %dkbps",a);
  142. if (a2 && a2 != ~0)
  143. wsprintf(buf+strlen(buf)," (Total %u bytes)",a2);
  144. _InsertString(sub,subpos++,buf,tmpid++);
  145. }
  146. else if (a2 && a2 != ~0)
  147. {
  148. wsprintf(buf,"Size: %u bytes",a2);
  149. _InsertString(sub,subpos++,buf,tmpid++);
  150. }
  151. lstrcpy(buf,"Video: ");
  152. char *p=buf+strlen(buf);
  153. parm->decode->getVideoDesc(p);
  154. if (*p) _InsertString(sub,subpos++,buf,tmpid++);
  155. lstrcpy(buf,"Audio: ");
  156. p=buf+strlen(buf);
  157. parm->decode->getAudioDesc(p);
  158. if (*p) _InsertString(sub,subpos++,buf,tmpid++);
  159. }
  160. {
  161. const char *p=parm->decode->getServerHeader("Server");
  162. if (p && *p)
  163. {
  164. lstrcpy(buf,"Server: ");
  165. lstrcpyn(buf+strlen(buf),p,sizeof(buf)-strlen(buf)-2);
  166. _InsertString(sub,subpos++,buf,tmpid++);
  167. }
  168. }
  169. }
  170. #endif //WNDMENU_NOINFO
  171. #ifndef WNDMENU_NOVOLUME
  172. if (parm->decode)
  173. {
  174. HMENU sub=_InsertSub(hMenu,pos++,"Volume");
  175. int cv=(parm->decode->getvolume()*100)/255;
  176. int x;
  177. for (x=0;x<=10;x++)
  178. {
  179. char buf[64];
  180. int a=100-x*10;
  181. wsprintf(buf,"%d%%",a);
  182. _InsertString(sub,x,buf,MENUITEM_VOLUMEBASE+x,cv >= a-5 && cv < a+5);
  183. }
  184. }
  185. #endif//WNDMENU_NOVOLUME
  186. #ifndef WNDMENU_NOOPTIONS
  187. if (parm->vidOut)
  188. {
  189. HMENU sub=_InsertSub(hMenu,pos++,"Options");
  190. int subpos=0;
  191. _InsertString(sub,subpos++,"Synchronize video to refresh",MENUITEM_VSYNC,!!parm->vidOut->vid_vsync);
  192. _InsertString(sub,subpos++,"Maintain video aspect ratio",MENUITEM_ASPECTADJ,!!parm->vidOut->vid_aspectadj);
  193. _InsertString(sub,subpos++,"Allow video overlay",MENUITEM_VOVERLAYS,!!parm->vidOut->vid_overlays);
  194. //_InsertString(sub,subpos++,"Allow DirectDraw acceleration",MENUITEM_VDDRAW,!!parm->vidOut->vid_ddraw);
  195. _InsertString(sub,subpos++,"Use software volume mixing",MENUITEM_SOFTVOLMIX,!g_audio_use_mixer);
  196. }
  197. #endif//WNDMENU_NOOPTIONS
  198. #if !defined(WNDMENU_NOZOOM) || !defined(WNDMENU_NOZOOMFS)
  199. if (parm->decode && parm->vidOut)
  200. {
  201. HMENU sub=_InsertSub(hMenu,pos++,"Zoom");
  202. int subpos=0;
  203. #ifndef WNDMENU_NOZOOM
  204. int ow,oh;
  205. int w=parm->decode->getWidth();
  206. int h=parm->decode->getHeight();
  207. parm->vidOut->getOutputSize(&ow,&oh);
  208. _InsertString(sub,subpos++,"50%",MENUITEM_ZOOM50,ABS(w/2-ow)<4);
  209. _InsertString(sub,subpos++,"100%",MENUITEM_ZOOM100,ABS(w-ow)<4);
  210. _InsertString(sub,subpos++,"200%",MENUITEM_ZOOM200,ABS(w*2-ow)<4);
  211. _InsertString(sub,subpos++,"400%",MENUITEM_ZOOM400,ABS(w/4-ow)<4);
  212. #ifndef WNDMENU_NOZOOMFS
  213. _InsertSep(sub,subpos++);
  214. #endif
  215. #endif
  216. #ifndef WNDMENU_NOZOOMFS
  217. _InsertString(sub,subpos++,"Fullscreen",MENUITEM_ZOOMFS,!!parm->vidOut->is_fullscreen());
  218. #endif//WNDMENU_NOZOOMFS
  219. }
  220. #endif//WNDMENU_NOZOOM||WNDMENU_NOZOOMFS
  221. #ifndef WNDMENU_NOSUBTITLES
  222. if(parm->decode)
  223. {
  224. HMENU sub=_InsertSub(hMenu,pos++,"Subtitles");
  225. int subpos=0;
  226. _InsertString(sub,subpos++,"Enabled",MENUITEM_ENABLESUBTITLES,parm->decode->subsEnabled());
  227. _InsertSep(sub,subpos++);
  228. HMENU sizesub=_InsertSub(sub,subpos++,"Font size");
  229. int sizesubpos=0;
  230. int fontsize=parm->decode->getSubsFontSize();
  231. _InsertString(sizesub,sizesubpos++,"Largest",MENUITEM_SUBSIZEBASE,fontsize==20);
  232. _InsertString(sizesub,sizesubpos++,"Larger",MENUITEM_SUBSIZEBASE+1,fontsize==10);
  233. _InsertString(sizesub,sizesubpos++,"Medium",MENUITEM_SUBSIZEBASE+2,fontsize==0);
  234. _InsertString(sizesub,sizesubpos++,"Smaller",MENUITEM_SUBSIZEBASE+3,fontsize==-4);
  235. _InsertString(sizesub,sizesubpos++,"Smallest",MENUITEM_SUBSIZEBASE+4,fontsize==-8);
  236. HMENU langsub=_InsertSub(sub,subpos++,"Language");
  237. int langsubpos=0;
  238. for(int i=0;;i++) {
  239. const char *lang=parm->decode->getSubLanguage(i);
  240. if(!lang) break;
  241. _InsertString(langsub,langsubpos++,(char *)lang,MENUITEM_SUBSLANGBASE+i,i==parm->decode->getCurSubLanguage());
  242. }
  243. }
  244. #endif//WNDMENU_NOSUBTITLES
  245. #ifndef WNDMENU_NOCLOSE
  246. _InsertSep(hMenu,pos++);
  247. _InsertString(hMenu,pos++,"E&xit\tAlt+F4",MENUITEM_CLOSE);
  248. #endif//WNDMENU_NOCLOSE
  249. POINT p;
  250. GetCursorPos(&p);
  251. int x=TrackPopupMenu(hMenu,TPM_RETURNCMD|TPM_RIGHTBUTTON|TPM_LEFTBUTTON|TPM_NONOTIFY,p.x,p.y,0,hwnd,NULL);
  252. DestroyMenu(hMenu);
  253. switch (x)
  254. {
  255. #ifndef WNDMENU_NOABOUT
  256. case MENUITEM_ABOUT:
  257. #ifdef _ABOUT_H_ // dont display the about box if do_about isn't there anyway
  258. do_about(hwnd);
  259. #endif
  260. break;
  261. #endif//WNDMENU_NOABOUT
  262. #ifndef WNDMENU_NOOPTIONS
  263. case MENUITEM_VOVERLAYS:
  264. _WriteConfigItemInt("overlays",parm->vidOut->vid_overlays=!parm->vidOut->vid_overlays);
  265. PostMessage(hwnd,WM_USER+0x1,0,0); //renegotiate surface
  266. break;
  267. case MENUITEM_VDDRAW:
  268. _WriteConfigItemInt("ddraw",parm->vidOut->vid_ddraw=!parm->vidOut->vid_ddraw);
  269. PostMessage(hwnd,WM_USER+0x1,0,0); //renegotiate surface
  270. break;
  271. case MENUITEM_ASPECTADJ:
  272. _WriteConfigItemInt("aspectadj",parm->vidOut->vid_aspectadj=!parm->vidOut->vid_aspectadj);
  273. PostMessage(hwnd,WM_TIMER,1,0);
  274. break;
  275. case MENUITEM_VSYNC:
  276. _WriteConfigItemInt("vsync",parm->vidOut->vid_vsync=!parm->vidOut->vid_vsync);
  277. break;
  278. case MENUITEM_SOFTVOLMIX:
  279. _WriteConfigItemInt("use_mixer",g_audio_use_mixer=!g_audio_use_mixer);
  280. parm->decode->setvolume(parm->decode->getvolume());
  281. break;
  282. #endif//WNDMENU_NOOPTIONS
  283. #ifndef WNDMENU_NOZOOM
  284. case MENUITEM_ZOOM50:
  285. case MENUITEM_ZOOM100:
  286. case MENUITEM_ZOOM200:
  287. case MENUITEM_ZOOM400:
  288. if (parm->vidOut->is_fullscreen()) parm->vidOut->remove_fullscreen();
  289. {
  290. int w=parm->decode->getWidth();
  291. int h=parm->decode->getHeight();
  292. if (x == MENUITEM_ZOOM50) { w/=2; h/=2; }
  293. else if (x == MENUITEM_ZOOM200) { w*=2; h*=2; }
  294. else if (x == MENUITEM_ZOOM400) { w*=4; h*=4; }
  295. parm->vidOut->setOutputSize(w,h);
  296. }
  297. break;
  298. #endif//WNDMENU_NOZOOM
  299. #ifndef WNDMENU_NOZOOMFS
  300. case MENUITEM_ZOOMFS:
  301. if (parm->vidOut->is_fullscreen()) parm->vidOut->remove_fullscreen();
  302. else parm->vidOut->fullscreen();
  303. break;
  304. #endif//WNDMENU_NOZOOMFS
  305. #ifndef WNDMENU_NOCLOSE
  306. case MENUITEM_CLOSE:
  307. SendMessage(hwnd,WM_CLOSE,0,0);
  308. break;
  309. #endif//WNDMENU_NOCLOSE
  310. #ifndef WNDMENU_NOSUBTITLES
  311. case MENUITEM_ENABLESUBTITLES:
  312. if(parm->decode) parm->decode->enableSubs(!parm->decode->subsEnabled());
  313. _WriteConfigItemInt("subtitles",parm->decode->subsEnabled());
  314. break;
  315. case MENUITEM_SUBSIZEBASE:
  316. case MENUITEM_SUBSIZEBASE+1:
  317. case MENUITEM_SUBSIZEBASE+2:
  318. case MENUITEM_SUBSIZEBASE+3:
  319. case MENUITEM_SUBSIZEBASE+4:
  320. if(parm->decode) {
  321. int sizes[]={20,10,0,-4,-8};
  322. int s=x-MENUITEM_SUBSIZEBASE;
  323. parm->decode->setSubsFontSize(sizes[s]);
  324. _WriteConfigItemInt("subtitles_size",parm->decode->getSubsFontSize());
  325. }
  326. break;
  327. #endif//WNDMENU_NOSUBTITLES
  328. default:
  329. #ifndef WNDMENU_NOVOLUME
  330. if (x >= MENUITEM_VOLUMEBASE && x <= MENUITEM_VOLUMEBASE+10)
  331. {
  332. int v=10-(x-MENUITEM_VOLUMEBASE);
  333. parm->decode->setvolume((v*255)/10);
  334. _WriteConfigItemInt("volume",parm->decode->getvolume());
  335. }
  336. #endif
  337. break;
  338. #ifndef WNDMENU_NOCLOSE
  339. case WM_CLOSE:
  340. DestroyWindow(hwnd);
  341. return 0;
  342. #endif
  343. }
  344. #ifndef WNDMENU_NOSUBTITLES
  345. if(x>=MENUITEM_SUBSLANGBASE && x<=MENUITEM_SUBSLANGBASE+64) {
  346. parm->decode->setSubLanguage(x-MENUITEM_SUBSLANGBASE);
  347. }
  348. #endif
  349. }
  350. }
  351. return DefWindowProc(hwnd,uMsg,wParam,lParam);
  352. }
  353. #endif//_WNDMENU_H_