videoui.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "Main.h"
  2. #include "video.h"
  3. #include "resource.h"
  4. #define inreg(x,y,x2,y2) \
  5. ((mouse_x <= ( x2 ) && mouse_x >= ( x ) && \
  6. mouse_y <= ( y2 ) && mouse_y >= ( y )))
  7. static int mouse_x, mouse_y, mouse_type, mouse_stats;
  8. static int which_cap=0;
  9. enum { NO_CAP,TITLE_CAP,TB_CAP, SZ_CAP,VW_CAP};
  10. static void do_titlebar();
  11. static void do_titlebuttons();
  12. static void do_size();
  13. static void do_vw();
  14. void videoui_handlemouseevent(int x, int y, int type, int stats)
  15. {
  16. mouse_x = x;
  17. mouse_y = y;
  18. mouse_type = type;
  19. mouse_stats = stats;
  20. switch (which_cap)
  21. {
  22. case VW_CAP: do_vw(); return;
  23. case TITLE_CAP: do_titlebar();return;
  24. case TB_CAP: do_titlebuttons();return;
  25. case SZ_CAP: do_size(); return;
  26. default: break;
  27. }
  28. do_vw();
  29. do_titlebuttons();
  30. do_size();
  31. do_titlebar();
  32. }
  33. static void do_titlebar()
  34. {
  35. if (which_cap == TITLE_CAP || (!which_cap && (config_easymove || mouse_y < 14)))
  36. {
  37. static int clickx, clicky;
  38. switch (mouse_type)
  39. {
  40. case 1:
  41. {
  42. which_cap=TITLE_CAP;
  43. clickx=mouse_x;
  44. clicky=mouse_y;
  45. }
  46. break;
  47. case -1:
  48. which_cap=0;
  49. break;
  50. case 0:
  51. if (which_cap == TITLE_CAP && mouse_stats & MK_LBUTTON)
  52. {
  53. POINT p = { mouse_x, mouse_y};
  54. ClientToScreen(hVideoWindow,&p);
  55. p.x-=clickx;
  56. p.y-=clicky;
  57. SendMessageW(hVideoWindow,WM_USER+0x100,1,(LPARAM)&p);
  58. }
  59. break;
  60. }
  61. }
  62. }
  63. static void do_titlebuttons()
  64. {
  65. int w=0;
  66. w=inreg(config_video_width-10,3,config_video_width-1,3+9)?1:0;
  67. if (w) // kill button
  68. {
  69. if (mouse_type == -1 && which_cap == TB_CAP)
  70. {
  71. which_cap=0;
  72. draw_vw_tbutton(0);
  73. SendMessageW(hMainWindow,WM_COMMAND,WINAMP_OPTIONS_VIDEO,0);
  74. }
  75. else if (mouse_stats & MK_LBUTTON)
  76. {
  77. which_cap=TB_CAP;
  78. draw_vw_tbutton(w?1:0);
  79. }
  80. }
  81. else if (which_cap == TB_CAP)
  82. {
  83. which_cap=0;
  84. draw_vw_tbutton(0);
  85. }
  86. }
  87. static void do_vw()
  88. {
  89. HWND videoGetHwnd();
  90. int w=0;
  91. w=inreg(9,config_video_height-29,89,config_video_height-11)?1:0;
  92. if (w)
  93. {
  94. w=(mouse_x-9)/15;
  95. if (mouse_type == -1 && which_cap == VW_CAP)
  96. {
  97. which_cap=0;
  98. draw_vw_mbuts(-1);
  99. switch (w)
  100. {
  101. case 0:
  102. videoGoFullscreen();
  103. break;
  104. case 1:
  105. if (videoGetHwnd()) SendMessageW(videoGetHwnd(),WM_COMMAND,ID_VIDEOWND_ZOOM100,0);
  106. break;
  107. case 2:
  108. if (videoGetHwnd()) SendMessageW(videoGetHwnd(),WM_COMMAND,ID_VIDEOWND_ZOOM200,0);
  109. break;
  110. case 3:
  111. SendMessageW(hMainWindow,WM_COMMAND,WINAMP_VIDEO_TVBUTTON,0);
  112. break;
  113. case 4:
  114. // menu
  115. if (videoGetHwnd()) SendMessageW(videoGetHwnd(),WM_RBUTTONUP,0,0);
  116. break;
  117. }
  118. }
  119. else if (mouse_stats & MK_LBUTTON)
  120. {
  121. which_cap=VW_CAP;
  122. draw_vw_mbuts(w);
  123. }
  124. }
  125. else if (which_cap == VW_CAP)
  126. {
  127. which_cap=0;
  128. draw_vw_mbuts(-1);
  129. }
  130. }
  131. static void do_size()
  132. {
  133. if (which_cap == SZ_CAP || (!which_cap &&
  134. mouse_x > config_video_width-20 && mouse_y > config_video_height-20 &&
  135. ((config_video_width-mouse_x + config_video_height-mouse_y) <= 30)))
  136. {
  137. static int dx,dy;
  138. if (!which_cap && mouse_type == 1)
  139. {
  140. dx=config_video_width-mouse_x;
  141. dy=config_video_height-mouse_y;
  142. which_cap=SZ_CAP;
  143. }
  144. if (which_cap == SZ_CAP)
  145. {
  146. int x,y;
  147. if (mouse_type == -1)
  148. {
  149. which_cap=0;
  150. }
  151. x=mouse_x + dx;
  152. y=mouse_y + dy;
  153. int old_x = x;
  154. int old_y = y;
  155. if (config_video_width != x || config_video_height != y) // don't bother resizing if we're at the current size already.
  156. {
  157. if (x >= GetSystemMetrics(SM_CXSCREEN)) x = GetSystemMetrics(SM_CXSCREEN)-24;
  158. if (y >= GetSystemMetrics(SM_CYSCREEN)) y = GetSystemMetrics(SM_CYSCREEN)-28;
  159. if (!config_embedwnd_freesize)
  160. {
  161. x += 24;
  162. x -= x%25;
  163. y += 28;
  164. y -= y%29;
  165. }
  166. if (x < 275) x = 275;
  167. if (y < 20+38+29+29) y = 20+38+29+29;
  168. //config_video_width = x;
  169. //config_video_height= y;
  170. if (!((old_x < config_video_width && x > config_video_width)
  171. || (old_y < config_video_height && y > config_video_height))) // don't snap out a size if we're moving the mouse inward (video might not have started snapped)
  172. {
  173. SetExteriorSize(x,y);
  174. //SetWindowPos(hVideoWindow,0,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  175. {
  176. HDC hdc=GetWindowDC(hVideoWindow);
  177. draw_vw(hdc);
  178. ReleaseDC(hVideoWindow,hdc);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }