void CPopupWnd::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default if ( nIDEvent == 1 ) { KillTimer( nIDEvent ); CWnd::OnTimer(nIDEvent); DestroyWindow(); } else { CWnd::OnTimer(nIDEvent); BOOL bDestroy = TRUE; if ( m_hTargetWnd && ::IsWindow( m_hTargetWnd) ) { CRect rect; ::GetWindowRect( m_hTargetWnd, &rect ); if ( rect.EqualRect( m_rectTarget ) ) { bDestroy = FALSE; } } if ( bDestroy ) { KillTimer( nIDEvent ); DestroyWindow(); } } }
tkExtentsRelation GeometryHelper::RelateExtents(CRect& r1, CRect& r2) { if(r1.right < r2.left || r1.bottom < r2.top || r2.right < r1.left || r2.bottom < r1.top) return erNone; else if (r1.EqualRect(r2)) return erEqual; else if (r1.left <= r2.left && r1.right >= r2.right && r1.top <= r2.top && r1.bottom >= r2.bottom) return erInclude; // 1 include 2 else if (r1.left >= r2.left && r1.right <= r2.right && r1.top >= r2.top && r1.bottom <= r2.bottom) return erIsIncluded; // 2 include 1 else return erIntersection; }
BOOL CRectTracker::TrackHandle(int nHandle, CWnd* pWnd, CPoint point, CWnd* pWndClipTo) { ASSERT(nHandle >= 0); ASSERT(nHandle <= 8); // handle 8 is inside the rect // don't handle if capture already set if (::GetCapture() != NULL) return FALSE; ASSERT(!m_bFinalErase); // save original width & height in pixels int nWidth = m_rect.Width(); int nHeight = m_rect.Height(); // set capture to the window which received this message pWnd->SetCapture(); ASSERT(pWnd == CWnd::GetCapture()); pWnd->UpdateWindow(); if (pWndClipTo != NULL) pWndClipTo->UpdateWindow(); CRect rectSave = m_rect; // find out what x/y coords we are supposed to modify int *px, *py; int xDiff, yDiff; GetModifyPointers(nHandle, &px, &py, &xDiff, &yDiff); xDiff = point.x - xDiff; yDiff = point.y - yDiff; // get DC for drawing CDC* pDrawDC; if (pWndClipTo != NULL) { // clip to arbitrary window by using adjusted Window DC pDrawDC = pWndClipTo->GetDCEx(NULL, DCX_CACHE); } else { // otherwise, just use normal DC pDrawDC = pWnd->GetDC(); } ASSERT_VALID(pDrawDC); CRect rectOld; BOOL bMoved = FALSE; AfxLockTempMaps(); // protect maps while looping // get messages until capture lost or cancelled/accepted for (;;) { MSG msg; VERIFY(::GetMessage(&msg, NULL, 0, 0)); if (CWnd::GetCapture() != pWnd) break; switch (msg.message) { // handle movement/accept messages case WM_LBUTTONUP: case WM_MOUSEMOVE: rectOld = m_rect; // handle resize cases (and part of move) if (px != NULL) *px = (int)(short)LOWORD(msg.lParam) - xDiff; if (py != NULL) *py = (int)(short)HIWORD(msg.lParam) - yDiff; // handle move case if (nHandle == hitMiddle) { m_rect.right = m_rect.left + nWidth; m_rect.bottom = m_rect.top + nHeight; } // allow caller to adjust the rectangle if necessary AdjustRect(nHandle, &m_rect); // only redraw and callback if the rect actually changed! m_bFinalErase = (msg.message == WM_LBUTTONUP); if (!rectOld.EqualRect(&m_rect) || m_bFinalErase) { if (bMoved) { m_bErase = TRUE; DrawTrackerRect(&rectOld, pWndClipTo, pDrawDC, pWnd); } OnChangedRect(rectOld); if (msg.message != WM_LBUTTONUP) bMoved = TRUE; } if (m_bFinalErase) goto ExitLoop; if (!rectOld.EqualRect(&m_rect)) { m_bErase = FALSE; DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd); } break; // handle cancel messages case WM_KEYDOWN: if (msg.wParam != VK_ESCAPE) break; case WM_RBUTTONDOWN: if (bMoved) { m_bErase = m_bFinalErase = TRUE; DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd); } m_rect = rectSave; goto ExitLoop; // just dispatch rest of the messages default: DispatchMessage(&msg); break; } } ExitLoop: if (pWndClipTo != NULL) pWndClipTo->ReleaseDC(pDrawDC); else pWnd->ReleaseDC(pDrawDC); ReleaseCapture(); AfxUnlockTempMaps(FALSE); // restore rect in case bMoved is still FALSE if (!bMoved) m_rect = rectSave; m_bFinalErase = FALSE; m_bErase = FALSE; // return TRUE only if rect has changed return !rectSave.EqualRect(&m_rect); }
CRect rect1(35, 150, 10, 25); CRect rect2(35, 150, 10, 25); CRect rect3(98, 999, 6, 3); ASSERT(rect1.EqualRect(rect2)); ASSERT(!rect1.EqualRect(rect3)); // works just fine against RECTs, as well RECT test; test.left = 35; test.top = 150; test.right = 10; test.bottom = 25; ASSERT(rect1.EqualRect(&test));
// 操作中クリップの描画を行う BOOL TimelineEditorView::DrawOperatingClip(const CDC& dcDC, const int& iHeight) { // TODO: 元のクリップの色を変える 元々各タイミングで実施するよう変更 m_pOperatingClipData->DrawOperatingOldRect(iHeight); CRect* rcOperatingRect = m_pOperatingClipData->GetOperatingRect(); if (m_pTimelineDataOperator->IsSingleInTrim() || m_pTimelineDataOperator->IsSingleOutTrim()) { m_pOperatingClipData->DrawSingleTrimRect(iHeight, m_pTimelineDataOperator->IsSingleInTrim()); #ifdef _DEBUG //TODO: デバッグ CString strText; double dPointX, dPointY; int iPoint; int iDuration; if (m_pTimelineDataOperator->IsSingleInTrim()) { iPoint = m_pOperatingClipData->GetTimelineInPoint() + m_pTimelineDataOperator->GetOperatingClipFrameCount(); } else { iPoint = m_pOperatingClipData->GetTimelineInPoint(); } HFONT hfDrawFont; CreateDrawFont(13, 0, DEFAULT_FONTFACE, hfDrawFont); strText.Format(_T("TrimingClipInPoint %d"), iPoint); ChangeScreenPointToOpenGLPoint(700, 15, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("TrimingClipLeftPoint %d"), rcOperatingRect->left); ChangeScreenPointToOpenGLPoint(700, 30, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); if (m_pTimelineDataOperator->IsSingleInTrim()) { iPoint = m_pOperatingClipData->GetTimelineOutPoint(); iDuration = m_pOperatingClipData->GetDuration() - m_pTimelineDataOperator->GetOperatingClipFrameCount(); } else { iPoint = m_pOperatingClipData->GetTimelineOutPoint() + m_pTimelineDataOperator->GetOperatingClipFrameCount(); iDuration = m_pOperatingClipData->GetDuration() + m_pTimelineDataOperator->GetOperatingClipFrameCount(); } strText.Format(_T("TrimingClipOutPoint %d"), iPoint); ChangeScreenPointToOpenGLPoint(700, 45, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("TrimingClipRightPoint %d"), rcOperatingRect->right); ChangeScreenPointToOpenGLPoint(700, 60, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("TrimingClipDuration %d"), iDuration); ChangeScreenPointToOpenGLPoint(700, 75, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); DeleteObject(hfDrawFont); #endif } else { // ドロップ位置用 m_pOperatingClipData->DrawMovingRect(iHeight); #ifdef _DEBUG //TODO: デバッグ CString strText; double dPointX, dPointY; HFONT hfDrawFont; CreateDrawFont(13, 0, DEFAULT_FONTFACE, hfDrawFont); strText.Format(_T("MovingClipInPoint %d"), m_pOperatingClipData->GetTimelineInPoint() + m_pTimelineDataOperator->GetOperatingClipFrameCount()); ChangeScreenPointToOpenGLPoint(700, 15, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("MovingClipLeftPoint %d"), rcOperatingRect->left); ChangeScreenPointToOpenGLPoint(700, 30, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("MovingClipRightPoint %d"), rcOperatingRect->right); ChangeScreenPointToOpenGLPoint(700, 45, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); #endif // マウス位置追随用 CRect rcMousePointRect = m_pTimelineDataOperator->GetMousePointRect(); if (!(rcMousePointRect.EqualRect(rcOperatingRect))) { m_pOperatingClipData->SetOverlappingVert(static_cast<float>(rcMousePointRect.left), static_cast<float>(iHeight - rcMousePointRect.top), static_cast<float>(rcMousePointRect.right), static_cast<float>(iHeight - rcMousePointRect.bottom)); m_pOperatingClipData->DrawOverlappingRect(iHeight); #ifdef _DEBUG strText.Format(_T("MouseMoveClipLeftPoint %d"), rcMousePointRect.left); ChangeScreenPointToOpenGLPoint(700, 60, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); strText.Format(_T("MouseMoveClipRightPoint %d"), rcMousePointRect.right); ChangeScreenPointToOpenGLPoint(700, 75, iHeight, dPointX, dPointY); DrawTextOnGL(static_cast<PCTSTR>(strText), dcDC.GetSafeHdc(), hfDrawFont, BLACKCOLOR_BRUSH_FLOAT, static_cast<float>(dPointX), static_cast<float>(dPointY), TIMELINE_DEFAULTZ, 1.0f); DeleteObject(hfDrawFont); #endif } } return TRUE; }