DisplayRect.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. // DisplayRect.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_CARDOCX.h"
  5. #include "PlayerDlg.h"
  6. #include "DisplayRect.h"
  7. extern UINT PORT;
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDisplayRect dialog
  15. CDisplayRect::CDisplayRect(CWnd* pParent /*=NULL*/)
  16. : CDialog(CDisplayRect::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CDisplayRect)
  19. m_nZoom = 100;
  20. //}}AFX_DATA_INIT
  21. m_pParent = pParent;
  22. m_FocusRect.nZoom = 100;
  23. m_FocusRect.nClientHeight = 288;
  24. m_FocusRect.nClientWidth = 352;
  25. m_FocusRect.CenterPoint.x = 288/2;
  26. m_FocusRect.CenterPoint.y = 352/2;
  27. m_rcRect.left = 0;
  28. m_rcRect.bottom = 288;
  29. m_rcRect.right = 352;
  30. m_rcRect.top = 0;
  31. m_bValid = FALSE;
  32. m_state = State_Set;
  33. }
  34. void CDisplayRect::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CDisplayRect)
  38. DDX_Control(pDX, IDC_SLIDER1, m_CtrlZoom);
  39. DDX_Text(pDX, IDC_EDIT_SIZE, m_nZoom);
  40. DDV_MinMaxUInt(pDX, m_nZoom, 100, 1100);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CDisplayRect, CDialog)
  44. //{{AFX_MSG_MAP(CDisplayRect)
  45. ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
  46. ON_WM_MOVE()
  47. ON_WM_PAINT()
  48. ON_WM_SIZE()
  49. ON_WM_GETMINMAXINFO()
  50. ON_WM_HSCROLL()
  51. ON_WM_MOUSEMOVE()
  52. ON_WM_LBUTTONDOWN()
  53. ON_WM_DESTROY()
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CDisplayRect message handlers
  58. void CDisplayRect::OnOK()
  59. {
  60. // TODO: Add extra validation here
  61. if(m_pParent){
  62. if (m_state == State_Set) {
  63. Enable(FALSE);
  64. m_pParent->PostMessage(WM_DISPLAY_OK, 0, 0);
  65. }
  66. else {
  67. Enable(TRUE);
  68. m_pParent->PostMessage(WM_DISPLAY_OK, 1, 0);
  69. }
  70. }
  71. else
  72. CDialog::OnOK();
  73. }
  74. void CDisplayRect::Enable(BOOL bEnable)
  75. {
  76. if (bEnable) {
  77. GetDlgItem(IDC_SLIDER1)->EnableWindow(TRUE);
  78. GetDlgItem(IDOK)->SetWindowText("播放");
  79. GetDlgItem(IDC_DISPLAY)->EnableWindow(TRUE);
  80. m_state = State_Set;
  81. }
  82. else
  83. {
  84. GetDlgItem(IDC_SLIDER1)->EnableWindow(FALSE);
  85. GetDlgItem(IDOK)->SetWindowText("设置");
  86. GetDlgItem(IDC_DISPLAY)->EnableWindow(FALSE);
  87. m_state = State_Play;
  88. }
  89. }
  90. void CDisplayRect::OnDisplay()
  91. {
  92. // TODO: Add your control notification handler code here
  93. m_FocusRect.nZoom = 100;
  94. m_nZoom = m_FocusRect.nZoom;
  95. UpdateData(FALSE);
  96. SetDisplayRegion();
  97. m_CtrlZoom.SetPos(0);
  98. }
  99. void CDisplayRect::SortCtrls()
  100. {
  101. if( !(GetStyle() & WS_SIZEBOX) )
  102. return;
  103. CRect rcClient;
  104. RECT rcControl;
  105. GetClientRect(&rcClient);
  106. int nTempWid = rcClient.Width() - 4;
  107. int nTempHei = rcClient.Height() - 85;
  108. if (nTempWid < 0 || nTempHei < 0) {
  109. return;
  110. }
  111. if (nTempWid * m_nVideoHeight
  112. > nTempHei * m_nVideoWidth) {
  113. m_FocusRect.CenterPoint.x = m_StandardCenterPoint.x * nTempHei/m_nVideoHeight;
  114. m_FocusRect.CenterPoint.y = m_StandardCenterPoint.y * nTempHei/m_nVideoHeight;
  115. TRACE("m_StandardPOint.y = %d", m_StandardCenterPoint.y);
  116. m_FocusRect.nClientWidth = m_nVideoWidth*nTempHei/m_nVideoHeight;
  117. m_FocusRect.nClientHeight = nTempHei;
  118. }else{
  119. m_FocusRect.CenterPoint.x = m_StandardCenterPoint.x * nTempWid/m_nVideoWidth;
  120. m_FocusRect.CenterPoint.y = m_StandardCenterPoint.y * nTempWid/m_nVideoWidth;
  121. m_FocusRect.nClientHeight = m_nVideoHeight * nTempWid/m_nVideoWidth;
  122. m_FocusRect.nClientWidth = nTempWid;
  123. }
  124. GetDlgItem(IDC_DISWND)->MoveWindow((rcClient.Width()-m_FocusRect.nClientWidth)/2, (rcClient.Height()-80-m_FocusRect.nClientHeight)/2, m_FocusRect.nClientWidth, m_FocusRect.nClientHeight, TRUE);
  125. DWORD x = (rcClient.Width()-m_FocusRect.nClientWidth)/2;
  126. DWORD y = rcClient.Height() - 70;
  127. GetDlgItem(IDC_STATIC_SIZE)->MoveWindow(x, y, 40, 20, TRUE);
  128. x += 40;
  129. GetDlgItem(IDC_EDIT_SIZE)->MoveWindow(x, y, 30, 15, TRUE);
  130. x += 30;
  131. GetDlgItem(IDC_STATIC_PST)->MoveWindow(x, y, 30, 20, TRUE);
  132. x += 50 + nTempWid/20;
  133. GetDlgItem(IDC_STATIC_MINUS)->MoveWindow(x, y, 16, 16, TRUE);
  134. x += 20;
  135. GetDlgItem(IDC_SLIDER1)->MoveWindow(x, y, 90, 20, TRUE );
  136. x += 90;
  137. GetDlgItem(IDC_STATIC_PLUS)->MoveWindow(x, y, 16, 16, TRUE);
  138. x = (rcClient.Width()-m_FocusRect.nClientWidth)/2+5;
  139. y += 30;
  140. GetDlgItem(IDOK)->MoveWindow(x, y, 70, 20, TRUE);
  141. x += 125+nTempWid/20;;
  142. GetDlgItem(IDC_DISPLAY)->MoveWindow(x, y, 70, 20, TRUE);
  143. rcControl.left = (rcClient.Width()-m_FocusRect.nClientWidth)/2;
  144. rcControl.right = x +200;
  145. rcControl.top = rcClient.Height() - 70;
  146. rcControl.bottom = y + 25;
  147. InvalidateRect(&rcControl);
  148. }
  149. void CDisplayRect::DisplayRect(WPARAM wParam, LPARAM lParam)
  150. {
  151. CRect * rcRect = (CRect*)lParam;
  152. UpdateData(FALSE);
  153. }
  154. void CDisplayRect::InitShow()
  155. {
  156. SortCtrls();
  157. NAME(PlayM4_SetDisplayRegion)(PORT, 1, &m_rcRect, GetDlgItem(IDC_DISWND)->m_hWnd, TRUE);
  158. NAME(PlayM4_RefreshPlayEx)(PORT, 1);
  159. }
  160. BOOL CDisplayRect::OnInitDialog()
  161. {
  162. CDialog::OnInitDialog();
  163. // TODO: Add extra initialization here
  164. m_dwScreenWidth = GetSystemMetrics(SM_CXSCREEN);
  165. m_dwScreenHeight = GetSystemMetrics(SM_CYSCREEN);
  166. m_dwOldDeviceNum = 0;
  167. m_CtrlZoom.SetRange(0, 1000);
  168. m_CtrlZoom.SetPos(m_FocusRect.nZoom - 100);
  169. m_bValid = TRUE;
  170. m_state = State_Set;
  171. return TRUE; // return TRUE unless you set the focus to a control
  172. // EXCEPTION: OCX Property Pages should return FALSE
  173. }
  174. BOOL CDisplayRect::SetDevice(UINT nSeq)
  175. {
  176. BOOL bFunctionOK = FALSE;
  177. #if (WINVER > 0x0400)
  178. DWORD nVal = NAME(PlayM4_GetDDrawDeviceTotalNums)();
  179. if(nVal >= 1)
  180. {
  181. if(NAME(PlayM4_SetDDrawDeviceEx)(PORT, 1, nSeq + 1))
  182. {
  183. bFunctionOK = TRUE;
  184. }
  185. }
  186. #endif
  187. return bFunctionOK;
  188. }
  189. BOOL CDisplayRect::SetResolution(int nHei, int nWid)
  190. {
  191. //设置图像客户区默认大小
  192. m_FocusRect.nClientWidth = 352;
  193. m_FocusRect.nClientHeight = nHei*352/nWid;
  194. m_nVideoWidth = nWid;
  195. m_nVideoHeight = nHei;
  196. m_rcRect.right = nWid;
  197. m_rcRect.bottom = nHei;
  198. m_FocusRect.CenterPoint.x = m_FocusRect.nClientWidth/2;
  199. m_FocusRect.CenterPoint.y = m_FocusRect.nClientHeight/2;
  200. m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x;
  201. m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y;
  202. m_FocusRect.nZoom = 100;
  203. m_nZoom = 100;
  204. return TRUE;
  205. }
  206. void CDisplayRect::OnMove(int x, int y)
  207. {
  208. CDialog::OnMove(x, y);
  209. // TODO: Add your message handler code here
  210. GetWindowRect(&m_rcWindow);
  211. DWORD dwNewDeviceNum;
  212. if(m_rcWindow.left < 0)
  213. return;
  214. if( (DWORD)m_rcWindow.right + (DWORD)m_rcWindow.left > 2 * m_dwScreenWidth )
  215. {
  216. if( (DWORD)m_rcWindow.top + (DWORD)m_rcWindow.bottom > 2 * m_dwScreenHeight)
  217. dwNewDeviceNum = 3;
  218. else
  219. dwNewDeviceNum = 1;
  220. }
  221. else
  222. {
  223. if( (DWORD)m_rcWindow.top + (DWORD)m_rcWindow.bottom > 2 * m_dwScreenHeight)
  224. dwNewDeviceNum = 2;
  225. else
  226. dwNewDeviceNum = 0;
  227. }
  228. if(dwNewDeviceNum != m_dwOldDeviceNum)
  229. {
  230. if(SetDevice(dwNewDeviceNum))
  231. {
  232. m_dwOldDeviceNum = dwNewDeviceNum;
  233. }
  234. }
  235. }
  236. void CDisplayRect::OnPaint()
  237. {
  238. CPaintDC dc(this); // device context for painting
  239. // TODO: Add your message handler code here
  240. UpdateWindow();
  241. NAME(PlayM4_RefreshPlayEx)(PORT, 1);
  242. DrawRectangle();
  243. // Do not call CDialog::OnPaint() for painting messages
  244. }
  245. void CDisplayRect::DrawRectangle()
  246. {
  247. if (m_state == State_Play) {
  248. return;
  249. }
  250. RECT DisRect;
  251. CBrush brush2(RGB(255,0,0));
  252. CDC* pDC = GetDlgItem(IDC_DISWND)->GetDC();
  253. GetFocusRectangle(DisRect);
  254. pDC->FrameRect(&DisRect, &brush2);
  255. }
  256. void CDisplayRect::GetFocusRectangle(RECT& DisRect)
  257. {
  258. int nWidth, nHeight;
  259. CRect VideoRect;
  260. GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
  261. nWidth = m_FocusRect.nClientWidth*100/m_FocusRect.nZoom;
  262. nHeight = m_FocusRect.nClientHeight*100/m_FocusRect.nZoom;
  263. DisRect.left = m_FocusRect.CenterPoint.x + VideoRect.left - nWidth/2;
  264. DisRect.right = DisRect.left + nWidth;
  265. DisRect.top = VideoRect.top + m_FocusRect.CenterPoint.y - nHeight/2;
  266. DisRect.bottom = DisRect.top + nHeight;
  267. if (DisRect.bottom > VideoRect.bottom) {
  268. DisRect.top -= (DisRect.bottom - VideoRect.bottom);
  269. m_FocusRect.CenterPoint.y -= (DisRect.bottom - VideoRect.bottom);
  270. DisRect.bottom = VideoRect.bottom;
  271. }
  272. if (DisRect.right > VideoRect.right) {
  273. DisRect.left -= (DisRect.right - VideoRect.right);
  274. m_FocusRect.CenterPoint.x -= (DisRect.right - VideoRect.right);
  275. DisRect.right = VideoRect.right;
  276. }
  277. if (DisRect.top < VideoRect.top) {
  278. DisRect.bottom = VideoRect.top + nHeight;
  279. DisRect.top = VideoRect.top;
  280. m_FocusRect.CenterPoint.y = VideoRect.top + nHeight/2;
  281. }
  282. if (DisRect.left < VideoRect.left) {
  283. DisRect.right = VideoRect.left + nWidth;
  284. DisRect.left = VideoRect.left;
  285. m_FocusRect.CenterPoint.x = VideoRect.left + nWidth/2;
  286. }
  287. // m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/VideoRect.Width();
  288. // m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/VideoRect.Height();
  289. }
  290. void CDisplayRect::OnSize(UINT nType, int cx, int cy)
  291. {
  292. CDialog::OnSize(nType, cx, cy);
  293. // TODO: Add your message handler code here
  294. if (GetDlgItem(IDC_DISWND)->GetSafeHwnd()) {
  295. SortCtrls();
  296. }
  297. }
  298. void CDisplayRect::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  299. {
  300. // TODO: Add your message handler code here and/or call default
  301. lpMMI->ptMinTrackSize.x = 280;
  302. lpMMI->ptMinTrackSize.y = 350;
  303. // CDialog::OnGetMinMaxInfo(lpMMI);
  304. }
  305. void CDisplayRect::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  306. {
  307. // Get the current position of scroll box.
  308. int curpos = m_CtrlZoom.GetPos();
  309. m_FocusRect.nZoom = 100 + curpos;
  310. m_nZoom = m_FocusRect.nZoom;
  311. UpdateData(FALSE);
  312. SetDisplayRegion();
  313. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  314. }
  315. void CDisplayRect::OnMouseMove(UINT nFlags, CPoint point)
  316. {
  317. // TODO: Add your message handler code here and/or call default
  318. if (m_state == State_Play) {
  319. return;
  320. }
  321. POINT VideoPoint;
  322. POINT Point1, Point2;
  323. CRect CRctFocus;
  324. CRect VideoRect;
  325. GetFocusRectangle(CRctFocus);
  326. VideoPoint.x = point.x;
  327. VideoPoint.y = point.y;
  328. ClientToScreen(&VideoPoint);
  329. if (MK_LBUTTON == nFlags) {
  330. if (PtInFocusRect(VideoPoint)) {
  331. VideoPoint.x -= m_FocusPoint.x;
  332. VideoPoint.y -= m_FocusPoint.y;
  333. m_FocusPoint = point;
  334. ClientToScreen(&m_FocusPoint);
  335. m_FocusRect.CenterPoint.x += VideoPoint.x;
  336. m_FocusRect.CenterPoint.y += VideoPoint.y;
  337. CRctFocus += VideoPoint;
  338. GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
  339. Point1 = CRctFocus.TopLeft();
  340. Point2 = VideoRect.TopLeft();
  341. if (Point1.x - Point2.x < 0) {
  342. m_FocusRect.CenterPoint.x += Point2.x - Point1.x;
  343. }
  344. if (Point1.y - Point2.y < 0) {
  345. m_FocusRect.CenterPoint.y += Point2.y - Point1.y;
  346. }
  347. Point1 = CRctFocus.BottomRight();
  348. Point2 = VideoRect.BottomRight();
  349. if (Point1.x - Point2.x > 0) {
  350. m_FocusRect.CenterPoint.x -= (Point1.x - Point2.x);
  351. }
  352. if (Point1.y - Point2.y > 0) {
  353. m_FocusRect.CenterPoint.y -= (Point1.y - Point2.y);
  354. }
  355. m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
  356. m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
  357. SetDisplayRegion();
  358. }
  359. }
  360. CDialog::OnMouseMove(nFlags, point);
  361. }
  362. BOOL CDisplayRect::PtInFocusRect(POINT Point)
  363. {
  364. RECT FocusRect;
  365. GetFocusRectangle(FocusRect);
  366. GetDlgItem(IDC_DISWND)->ClientToScreen(&FocusRect);
  367. return PtInRect(&FocusRect, Point);
  368. }
  369. BOOL CDisplayRect::PtInVideoRect(POINT Point)
  370. {
  371. RECT VideoRct;
  372. GetDlgItem(IDC_DISWND)->GetWindowRect(&VideoRct);
  373. return PtInRect(&VideoRct, Point);
  374. }
  375. void CDisplayRect::OnLButtonDown(UINT nFlags, CPoint point)
  376. {
  377. // TODO: Add your message handler code here and/or call default
  378. if (m_state == State_Play) {
  379. return;
  380. }
  381. CRect FocusRect, VideoRect;
  382. POINT ClientPoint;
  383. ClientPoint.x = point.x;
  384. ClientPoint.y = point.y;
  385. ClientToScreen(&ClientPoint);
  386. if (PtInFocusRect(ClientPoint)) {
  387. m_FocusPoint = ClientPoint;
  388. }
  389. else
  390. {
  391. if (PtInVideoRect(ClientPoint)) {
  392. GetDlgItem(IDC_DISWND)->ScreenToClient(&ClientPoint);
  393. m_FocusRect.CenterPoint.x = ClientPoint.x;
  394. m_FocusRect.CenterPoint.y = ClientPoint.y;
  395. GetFocusRectangle(FocusRect);
  396. GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
  397. if (ClientPoint.x + (FocusRect.Width())/2 >= VideoRect.right) {
  398. m_FocusRect.CenterPoint.x = VideoRect.Width() - (FocusRect.Width())/2;
  399. }
  400. if (ClientPoint.y + (FocusRect.Height())/2 >= VideoRect.bottom) {
  401. m_FocusRect.CenterPoint.y = VideoRect.Height() - (FocusRect.Height())/2;
  402. }
  403. if (ClientPoint.x < (FocusRect.Width())/2) {
  404. m_FocusRect.CenterPoint.x = (FocusRect.Width())/2;
  405. }
  406. if (ClientPoint.y < (FocusRect.Height())/2) {
  407. m_FocusRect.CenterPoint.y = (FocusRect.Height())/2;
  408. }
  409. m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
  410. m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
  411. }
  412. SetDisplayRegion();
  413. }
  414. CDialog::OnLButtonDown(nFlags, point);
  415. }
  416. void CDisplayRect::SetDisplayRegion()
  417. {
  418. UpdateWindow();
  419. NAME(PlayM4_RefreshPlayEx)(PORT, 1);
  420. DrawRectangle();
  421. RECT RectFocus, RectDisplay;
  422. POINT CenterPoint;
  423. GetFocusRectangle(RectFocus);
  424. CenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
  425. CenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
  426. RectDisplay.left = CenterPoint.x - (RectFocus.right - RectFocus.left)/2 * m_nVideoWidth/m_FocusRect.nClientWidth;
  427. RectDisplay.right = RectDisplay.left
  428. + (RectFocus.right - RectFocus.left) * m_nVideoWidth/m_FocusRect.nClientWidth;
  429. RectDisplay.top = CenterPoint.y - (RectFocus.bottom - RectFocus.top)/2 * m_nVideoHeight/m_FocusRect.nClientHeight;
  430. RectDisplay.bottom = RectDisplay.top
  431. + (RectFocus.bottom - RectFocus.top) * m_nVideoHeight/m_FocusRect.nClientHeight;
  432. ((CPlayerDlg*)m_pParent)->SetDisplayRegion(RectDisplay);
  433. }
  434. void CDisplayRect::OnDestroy()
  435. {
  436. CDialog::OnDestroy();
  437. // TODO: Add your message handler code here
  438. NAME(PlayM4_SetDisplayRegion)(PORT, 1, &m_rcRect, NULL, FALSE);
  439. m_bValid = FALSE;
  440. }