123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- // DisplayRect.cpp : implementation file
- //
- #include "stdafx.h"
- #include "StoneU_HC_CARDOCX.h"
- #include "PlayerDlg.h"
- #include "DisplayRect.h"
- extern UINT PORT;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDisplayRect dialog
- CDisplayRect::CDisplayRect(CWnd* pParent /*=NULL*/)
- : CDialog(CDisplayRect::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDisplayRect)
- m_nZoom = 100;
- //}}AFX_DATA_INIT
- m_pParent = pParent;
- m_FocusRect.nZoom = 100;
- m_FocusRect.nClientHeight = 288;
- m_FocusRect.nClientWidth = 352;
- m_FocusRect.CenterPoint.x = 288/2;
- m_FocusRect.CenterPoint.y = 352/2;
- m_rcRect.left = 0;
- m_rcRect.bottom = 288;
- m_rcRect.right = 352;
- m_rcRect.top = 0;
- m_bValid = FALSE;
- m_state = State_Set;
- }
- void CDisplayRect::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDisplayRect)
- DDX_Control(pDX, IDC_SLIDER1, m_CtrlZoom);
- DDX_Text(pDX, IDC_EDIT_SIZE, m_nZoom);
- DDV_MinMaxUInt(pDX, m_nZoom, 100, 1100);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDisplayRect, CDialog)
- //{{AFX_MSG_MAP(CDisplayRect)
- ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
- ON_WM_MOVE()
- ON_WM_PAINT()
- ON_WM_SIZE()
- ON_WM_GETMINMAXINFO()
- ON_WM_HSCROLL()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
-
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDisplayRect message handlers
- void CDisplayRect::OnOK()
- {
- // TODO: Add extra validation here
- if(m_pParent){
- if (m_state == State_Set) {
- Enable(FALSE);
- m_pParent->PostMessage(WM_DISPLAY_OK, 0, 0);
- }
- else {
- Enable(TRUE);
- m_pParent->PostMessage(WM_DISPLAY_OK, 1, 0);
- }
- }
- else
- CDialog::OnOK();
-
- }
- void CDisplayRect::Enable(BOOL bEnable)
- {
- if (bEnable) {
- GetDlgItem(IDC_SLIDER1)->EnableWindow(TRUE);
- GetDlgItem(IDOK)->SetWindowText("播放");
- GetDlgItem(IDC_DISPLAY)->EnableWindow(TRUE);
- m_state = State_Set;
- }
- else
- {
- GetDlgItem(IDC_SLIDER1)->EnableWindow(FALSE);
- GetDlgItem(IDOK)->SetWindowText("设置");
- GetDlgItem(IDC_DISPLAY)->EnableWindow(FALSE);
- m_state = State_Play;
- }
- }
- void CDisplayRect::OnDisplay()
- {
- // TODO: Add your control notification handler code here
- m_FocusRect.nZoom = 100;
- m_nZoom = m_FocusRect.nZoom;
-
- UpdateData(FALSE);
- SetDisplayRegion();
- m_CtrlZoom.SetPos(0);
- }
- void CDisplayRect::SortCtrls()
- {
- if( !(GetStyle() & WS_SIZEBOX) )
- return;
-
- CRect rcClient;
- RECT rcControl;
- GetClientRect(&rcClient);
- int nTempWid = rcClient.Width() - 4;
- int nTempHei = rcClient.Height() - 85;
- if (nTempWid < 0 || nTempHei < 0) {
- return;
- }
- if (nTempWid * m_nVideoHeight
- > nTempHei * m_nVideoWidth) {
- m_FocusRect.CenterPoint.x = m_StandardCenterPoint.x * nTempHei/m_nVideoHeight;
- m_FocusRect.CenterPoint.y = m_StandardCenterPoint.y * nTempHei/m_nVideoHeight;
- TRACE("m_StandardPOint.y = %d", m_StandardCenterPoint.y);
- m_FocusRect.nClientWidth = m_nVideoWidth*nTempHei/m_nVideoHeight;
- m_FocusRect.nClientHeight = nTempHei;
- }else{
- m_FocusRect.CenterPoint.x = m_StandardCenterPoint.x * nTempWid/m_nVideoWidth;
- m_FocusRect.CenterPoint.y = m_StandardCenterPoint.y * nTempWid/m_nVideoWidth;
- m_FocusRect.nClientHeight = m_nVideoHeight * nTempWid/m_nVideoWidth;
- m_FocusRect.nClientWidth = nTempWid;
- }
- GetDlgItem(IDC_DISWND)->MoveWindow((rcClient.Width()-m_FocusRect.nClientWidth)/2, (rcClient.Height()-80-m_FocusRect.nClientHeight)/2, m_FocusRect.nClientWidth, m_FocusRect.nClientHeight, TRUE);
- DWORD x = (rcClient.Width()-m_FocusRect.nClientWidth)/2;
- DWORD y = rcClient.Height() - 70;
- GetDlgItem(IDC_STATIC_SIZE)->MoveWindow(x, y, 40, 20, TRUE);
- x += 40;
- GetDlgItem(IDC_EDIT_SIZE)->MoveWindow(x, y, 30, 15, TRUE);
- x += 30;
- GetDlgItem(IDC_STATIC_PST)->MoveWindow(x, y, 30, 20, TRUE);
- x += 50 + nTempWid/20;
- GetDlgItem(IDC_STATIC_MINUS)->MoveWindow(x, y, 16, 16, TRUE);
- x += 20;
- GetDlgItem(IDC_SLIDER1)->MoveWindow(x, y, 90, 20, TRUE );
- x += 90;
- GetDlgItem(IDC_STATIC_PLUS)->MoveWindow(x, y, 16, 16, TRUE);
- x = (rcClient.Width()-m_FocusRect.nClientWidth)/2+5;
- y += 30;
- GetDlgItem(IDOK)->MoveWindow(x, y, 70, 20, TRUE);
- x += 125+nTempWid/20;;
- GetDlgItem(IDC_DISPLAY)->MoveWindow(x, y, 70, 20, TRUE);
- rcControl.left = (rcClient.Width()-m_FocusRect.nClientWidth)/2;
- rcControl.right = x +200;
- rcControl.top = rcClient.Height() - 70;
- rcControl.bottom = y + 25;
- InvalidateRect(&rcControl);
-
- }
- void CDisplayRect::DisplayRect(WPARAM wParam, LPARAM lParam)
- {
- CRect * rcRect = (CRect*)lParam;
- UpdateData(FALSE);
- }
- void CDisplayRect::InitShow()
- {
- SortCtrls();
- NAME(PlayM4_SetDisplayRegion)(PORT, 1, &m_rcRect, GetDlgItem(IDC_DISWND)->m_hWnd, TRUE);
- NAME(PlayM4_RefreshPlayEx)(PORT, 1);
- }
- BOOL CDisplayRect::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_dwScreenWidth = GetSystemMetrics(SM_CXSCREEN);
- m_dwScreenHeight = GetSystemMetrics(SM_CYSCREEN);
-
- m_dwOldDeviceNum = 0;
- m_CtrlZoom.SetRange(0, 1000);
- m_CtrlZoom.SetPos(m_FocusRect.nZoom - 100);
- m_bValid = TRUE;
- m_state = State_Set;
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BOOL CDisplayRect::SetDevice(UINT nSeq)
- {
- BOOL bFunctionOK = FALSE;
- #if (WINVER > 0x0400)
- DWORD nVal = NAME(PlayM4_GetDDrawDeviceTotalNums)();
- if(nVal >= 1)
- {
- if(NAME(PlayM4_SetDDrawDeviceEx)(PORT, 1, nSeq + 1))
- {
- bFunctionOK = TRUE;
- }
- }
- #endif
- return bFunctionOK;
- }
- BOOL CDisplayRect::SetResolution(int nHei, int nWid)
- {
- //设置图像客户区默认大小
- m_FocusRect.nClientWidth = 352;
- m_FocusRect.nClientHeight = nHei*352/nWid;
- m_nVideoWidth = nWid;
- m_nVideoHeight = nHei;
- m_rcRect.right = nWid;
- m_rcRect.bottom = nHei;
-
- m_FocusRect.CenterPoint.x = m_FocusRect.nClientWidth/2;
- m_FocusRect.CenterPoint.y = m_FocusRect.nClientHeight/2;
- m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x;
- m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y;
- m_FocusRect.nZoom = 100;
- m_nZoom = 100;
- return TRUE;
- }
- void CDisplayRect::OnMove(int x, int y)
- {
- CDialog::OnMove(x, y);
-
- // TODO: Add your message handler code here
- GetWindowRect(&m_rcWindow);
- DWORD dwNewDeviceNum;
- if(m_rcWindow.left < 0)
- return;
-
- if( (DWORD)m_rcWindow.right + (DWORD)m_rcWindow.left > 2 * m_dwScreenWidth )
- {
- if( (DWORD)m_rcWindow.top + (DWORD)m_rcWindow.bottom > 2 * m_dwScreenHeight)
- dwNewDeviceNum = 3;
- else
- dwNewDeviceNum = 1;
- }
- else
- {
- if( (DWORD)m_rcWindow.top + (DWORD)m_rcWindow.bottom > 2 * m_dwScreenHeight)
- dwNewDeviceNum = 2;
- else
- dwNewDeviceNum = 0;
- }
-
- if(dwNewDeviceNum != m_dwOldDeviceNum)
- {
- if(SetDevice(dwNewDeviceNum))
- {
- m_dwOldDeviceNum = dwNewDeviceNum;
- }
- }
- }
- void CDisplayRect::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- UpdateWindow();
- NAME(PlayM4_RefreshPlayEx)(PORT, 1);
- DrawRectangle();
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CDisplayRect::DrawRectangle()
- {
- if (m_state == State_Play) {
- return;
- }
- RECT DisRect;
- CBrush brush2(RGB(255,0,0));
- CDC* pDC = GetDlgItem(IDC_DISWND)->GetDC();
-
- GetFocusRectangle(DisRect);
- pDC->FrameRect(&DisRect, &brush2);
- }
- void CDisplayRect::GetFocusRectangle(RECT& DisRect)
- {
- int nWidth, nHeight;
- CRect VideoRect;
- GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
- nWidth = m_FocusRect.nClientWidth*100/m_FocusRect.nZoom;
- nHeight = m_FocusRect.nClientHeight*100/m_FocusRect.nZoom;
- DisRect.left = m_FocusRect.CenterPoint.x + VideoRect.left - nWidth/2;
- DisRect.right = DisRect.left + nWidth;
- DisRect.top = VideoRect.top + m_FocusRect.CenterPoint.y - nHeight/2;
- DisRect.bottom = DisRect.top + nHeight;
- if (DisRect.bottom > VideoRect.bottom) {
- DisRect.top -= (DisRect.bottom - VideoRect.bottom);
- m_FocusRect.CenterPoint.y -= (DisRect.bottom - VideoRect.bottom);
- DisRect.bottom = VideoRect.bottom;
- }
- if (DisRect.right > VideoRect.right) {
- DisRect.left -= (DisRect.right - VideoRect.right);
- m_FocusRect.CenterPoint.x -= (DisRect.right - VideoRect.right);
- DisRect.right = VideoRect.right;
- }
- if (DisRect.top < VideoRect.top) {
- DisRect.bottom = VideoRect.top + nHeight;
- DisRect.top = VideoRect.top;
- m_FocusRect.CenterPoint.y = VideoRect.top + nHeight/2;
- }
- if (DisRect.left < VideoRect.left) {
- DisRect.right = VideoRect.left + nWidth;
- DisRect.left = VideoRect.left;
- m_FocusRect.CenterPoint.x = VideoRect.left + nWidth/2;
- }
- // m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/VideoRect.Width();
- // m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/VideoRect.Height();
- }
- void CDisplayRect::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
-
- // TODO: Add your message handler code here
- if (GetDlgItem(IDC_DISWND)->GetSafeHwnd()) {
- SortCtrls();
- }
-
- }
- void CDisplayRect::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- {
- // TODO: Add your message handler code here and/or call default
- lpMMI->ptMinTrackSize.x = 280;
- lpMMI->ptMinTrackSize.y = 350;
- // CDialog::OnGetMinMaxInfo(lpMMI);
- }
- void CDisplayRect::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // Get the current position of scroll box.
- int curpos = m_CtrlZoom.GetPos();
- m_FocusRect.nZoom = 100 + curpos;
- m_nZoom = m_FocusRect.nZoom;
-
- UpdateData(FALSE);
- SetDisplayRegion();
-
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CDisplayRect::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if (m_state == State_Play) {
- return;
- }
- POINT VideoPoint;
- POINT Point1, Point2;
- CRect CRctFocus;
- CRect VideoRect;
- GetFocusRectangle(CRctFocus);
- VideoPoint.x = point.x;
- VideoPoint.y = point.y;
- ClientToScreen(&VideoPoint);
- if (MK_LBUTTON == nFlags) {
- if (PtInFocusRect(VideoPoint)) {
- VideoPoint.x -= m_FocusPoint.x;
- VideoPoint.y -= m_FocusPoint.y;
- m_FocusPoint = point;
- ClientToScreen(&m_FocusPoint);
- m_FocusRect.CenterPoint.x += VideoPoint.x;
- m_FocusRect.CenterPoint.y += VideoPoint.y;
- CRctFocus += VideoPoint;
- GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
- Point1 = CRctFocus.TopLeft();
- Point2 = VideoRect.TopLeft();
- if (Point1.x - Point2.x < 0) {
- m_FocusRect.CenterPoint.x += Point2.x - Point1.x;
- }
- if (Point1.y - Point2.y < 0) {
- m_FocusRect.CenterPoint.y += Point2.y - Point1.y;
- }
- Point1 = CRctFocus.BottomRight();
- Point2 = VideoRect.BottomRight();
- if (Point1.x - Point2.x > 0) {
- m_FocusRect.CenterPoint.x -= (Point1.x - Point2.x);
- }
- if (Point1.y - Point2.y > 0) {
- m_FocusRect.CenterPoint.y -= (Point1.y - Point2.y);
- }
- m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
- m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
- SetDisplayRegion();
- }
- }
-
- CDialog::OnMouseMove(nFlags, point);
- }
- BOOL CDisplayRect::PtInFocusRect(POINT Point)
- {
- RECT FocusRect;
- GetFocusRectangle(FocusRect);
- GetDlgItem(IDC_DISWND)->ClientToScreen(&FocusRect);
- return PtInRect(&FocusRect, Point);
- }
- BOOL CDisplayRect::PtInVideoRect(POINT Point)
- {
- RECT VideoRct;
- GetDlgItem(IDC_DISWND)->GetWindowRect(&VideoRct);
- return PtInRect(&VideoRct, Point);
- }
- void CDisplayRect::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if (m_state == State_Play) {
- return;
- }
- CRect FocusRect, VideoRect;
- POINT ClientPoint;
- ClientPoint.x = point.x;
- ClientPoint.y = point.y;
- ClientToScreen(&ClientPoint);
- if (PtInFocusRect(ClientPoint)) {
- m_FocusPoint = ClientPoint;
- }
- else
- {
- if (PtInVideoRect(ClientPoint)) {
- GetDlgItem(IDC_DISWND)->ScreenToClient(&ClientPoint);
- m_FocusRect.CenterPoint.x = ClientPoint.x;
- m_FocusRect.CenterPoint.y = ClientPoint.y;
- GetFocusRectangle(FocusRect);
- GetDlgItem(IDC_DISWND)->GetClientRect(VideoRect);
- if (ClientPoint.x + (FocusRect.Width())/2 >= VideoRect.right) {
- m_FocusRect.CenterPoint.x = VideoRect.Width() - (FocusRect.Width())/2;
- }
- if (ClientPoint.y + (FocusRect.Height())/2 >= VideoRect.bottom) {
- m_FocusRect.CenterPoint.y = VideoRect.Height() - (FocusRect.Height())/2;
- }
- if (ClientPoint.x < (FocusRect.Width())/2) {
- m_FocusRect.CenterPoint.x = (FocusRect.Width())/2;
- }
- if (ClientPoint.y < (FocusRect.Height())/2) {
- m_FocusRect.CenterPoint.y = (FocusRect.Height())/2;
- }
- m_StandardCenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
- m_StandardCenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
-
- }
- SetDisplayRegion();
- }
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CDisplayRect::SetDisplayRegion()
- {
- UpdateWindow();
- NAME(PlayM4_RefreshPlayEx)(PORT, 1);
- DrawRectangle();
- RECT RectFocus, RectDisplay;
- POINT CenterPoint;
- GetFocusRectangle(RectFocus);
- CenterPoint.x = m_FocusRect.CenterPoint.x * m_nVideoWidth/m_FocusRect.nClientWidth;
- CenterPoint.y = m_FocusRect.CenterPoint.y * m_nVideoHeight/m_FocusRect.nClientHeight;
- RectDisplay.left = CenterPoint.x - (RectFocus.right - RectFocus.left)/2 * m_nVideoWidth/m_FocusRect.nClientWidth;
- RectDisplay.right = RectDisplay.left
- + (RectFocus.right - RectFocus.left) * m_nVideoWidth/m_FocusRect.nClientWidth;
- RectDisplay.top = CenterPoint.y - (RectFocus.bottom - RectFocus.top)/2 * m_nVideoHeight/m_FocusRect.nClientHeight;
- RectDisplay.bottom = RectDisplay.top
- + (RectFocus.bottom - RectFocus.top) * m_nVideoHeight/m_FocusRect.nClientHeight;
- ((CPlayerDlg*)m_pParent)->SetDisplayRegion(RectDisplay);
- }
- void CDisplayRect::OnDestroy()
- {
- CDialog::OnDestroy();
-
- // TODO: Add your message handler code here
- NAME(PlayM4_SetDisplayRegion)(PORT, 1, &m_rcRect, NULL, FALSE);
- m_bValid = FALSE;
- }
|