// UstwnBm.cpp: implementation of the UserTwainBitmap class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "Userbtmp.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif LEAD_START_CLASS_MAP(LUserBitmapWindow,LBitmapBase) LEAD_END_CLASS_MAP(LUserBitmapWindow,LBitmapBase) LEAD_IMPLEMENTOBJECT(LUserBitmapWindow); //BEGIN: External Functions (Defined in Demo.cpp)// L_VOID NormalizeRect(RECT* pRect); L_VOID ChangeToImage(LUserBitmapWindow* pbitmap, RECT* pRect); L_VOID ChangeToZoom(LUserBitmapWindow* pbitmap, RECT* pRect); //END: External Functions (Defined in Demo.cpp)// L_TCHAR TEXT_BACKGRND[] = TEXT("BG"); L_TCHAR TEXT_ONECOLOR[] = TEXT("1C"); L_TCHAR TEXT_1BIT_BW[] = TEXT("T1BW"); L_TCHAR TEXT_2BIT_BW[] = TEXT("T2BW"); L_TCHAR TEXT_1BIT_COLOR[] = TEXT("T1C"); L_TCHAR TEXT_2BIT_COLOR[] = TEXT("T2C"); L_TCHAR TEXT_2BIT_GRAYSCALE[] = TEXT("G2"); L_TCHAR TEXT_8BIT_GRAYSCALE[] = TEXT("G8"); L_TCHAR TEXT_PICTURE[] = TEXT("P"); #define SIZE_TEXT_BACKGRND (sizeof(TEXT_BACKGRND) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_ONECOLOR (sizeof(TEXT_ONECOLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_BW (sizeof(TEXT_2BIT_BW) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_1BIT_BW (sizeof(TEXT_1BIT_BW) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_1BIT_COLOR (sizeof(TEXT_1BIT_COLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_COLOR (sizeof(TEXT_2BIT_COLOR) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_2BIT_GRAYSCALE (sizeof(TEXT_2BIT_GRAYSCALE) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_8BIT_GRAYSCALE (sizeof(TEXT_8BIT_GRAYSCALE) / sizeof(L_TCHAR)) - 1 #define SIZE_TEXT_PICTURE (sizeof(TEXT_PICTURE) / sizeof(L_TCHAR)) - 1 #define SCROLL_RATIO 50 #define RCWIDTH(lpRect) (((LPRECT) lpRect)->right - ((LPRECT) lpRect)->left) #define RCHEIGHT(lpRect) (((LPRECT) lpRect)->bottom - ((LPRECT) lpRect)->top) ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// LUserBitmapWindow::LUserBitmapWindow() { m_pView = NULL; } LUserBitmapWindow::~LUserBitmapWindow() { } L_VOID LUserBitmapWindow::OnZoom(L_UINT uZoomPercent) { } L_VOID LUserBitmapWindow::DrawSelectedLines(HDC hdc, RECT* pRect) { L_INT x1, y1, x2, y2; if (!hdc) return; // Draw the selection rectangles x1 = (pRect->right + pRect->left) / 2 - 3 ; y1 = pRect->top - 3 ; x2 = (pRect->right + pRect->left) / 2 + 3 ; y2 = pRect->top + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = (pRect->right + pRect->left) / 2 - 3 ; y1 = pRect->bottom - 3 ; x2 = (pRect->right + pRect->left) / 2 + 3 ; y2 = pRect->bottom + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->left - 3 ; y1 = (pRect->top + pRect->bottom) / 2 - 3 ; x2 = pRect->left + 3 ; y2 = (pRect->top + pRect->bottom) / 2 + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->right - 3 ; y1 = (pRect->top + pRect->bottom) / 2 - 3 ; x2 = pRect->right + 3 ; y2 = (pRect->top + pRect->bottom) / 2 + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->left - 3 ; y1 = pRect->top - 3 ; x2 = pRect->left + 3 ; y2 = pRect->top + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->right - 3 ; y1 = pRect->top - 3 ; x2 = pRect->right + 3 ; y2 = pRect->top + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->left - 3 ; y1 = pRect->bottom - 3 ; x2 = pRect->left + 3 ; y2 = pRect->bottom + 3 ; Rectangle(hdc, x1, y1, x2, y2); x1 = pRect->right - 3 ; y1 = pRect->bottom - 3 ; x2 = pRect->right + 3 ; y2 = pRect->bottom + 3 ; Rectangle(hdc, x1, y1, x2, y2); } L_VOID LUserBitmapWindow::OnDraw(HDC hdc,RECT& Rect) { HBRUSH hBrush, oldBrush; HPEN hSegmentPen, hOldPen; L_INT nSegment; RECT rc, rcDest; if (!m_pView) return; if (m_pView->m_Segment.m_pSegmentData == NULL) return; hBrush = GetStockBrush(NULL_BRUSH); hSegmentPen = CreatePen(PS_SOLID, 1,RGB(255,0,0)); m_pView->m_LBitmapWnd.GetRects(NULL,NULL,&rcDest,NULL); oldBrush = SelectBrush(hdc, hBrush); hOldPen = SelectPen(hdc, hSegmentPen); for(nSegment = 0; nSegment < m_pView->m_Segment.m_nSegmentsCount ; nSegment++) { ::CopyRect(&rc, &m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.rcBitmapSeg); ChangeToZoom(&m_pView->m_LBitmapWnd, &rc); OffsetRect(&rc,rcDest.left,rcDest.top); Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); if ( !(m_pView->m_Segment.m_pSegmentData[nSegment].m_bSelected) && m_pView->m_bShowSegmentType) { if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_BACKGROUND) int ret = TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_BACKGRND, SIZE_TEXT_BACKGRND); if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_ONECOLOR) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_ONECOLOR, SIZE_TEXT_ONECOLOR); if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_TEXT_2BITBW) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_BW, SIZE_TEXT_2BIT_BW); if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_TEXT_1BIT_BW) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_1BIT_BW, SIZE_TEXT_1BIT_BW); else if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_TEXT_1BIT_COLOR) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_1BIT_COLOR, SIZE_TEXT_1BIT_COLOR); else if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_TEXT_2BIT_COLOR) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_COLOR, SIZE_TEXT_2BIT_COLOR); else if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_GRAYSCALE_2BIT) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_2BIT_GRAYSCALE, SIZE_TEXT_2BIT_GRAYSCALE); else if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_GRAYSCALE_8BIT) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_8BIT_GRAYSCALE, SIZE_TEXT_2BIT_GRAYSCALE); else if (m_pView->m_Segment.m_pSegmentData[nSegment].m_Data.uType == SEGTYPE_PICTURE) TextOut(hdc, rc.left + 5, rc.top + 5, TEXT_PICTURE, SIZE_TEXT_PICTURE); } } SelectObject(hdc, oldBrush); SelectObject(hdc, hOldPen); for (int i = 0; i < m_pView->m_Segment.m_nSegmentsCount ; i++) { if ( FALSE == m_pView->m_Segment.m_pSegmentData[i].m_bSelected) continue; ::CopyRect(&rc, &m_pView->m_Segment.m_pSegmentData[i].m_Data.rcBitmapSeg); ChangeToZoom( &m_pView->m_LBitmapWnd, &rc); OffsetRect(&rc,rcDest.left,rcDest.top); DrawSelectedLines( hdc, &rc); } DeleteObject(hBrush); DeleteObject(hSegmentPen); }