📄 imageboardview.cpp
字号:
{
case MM_HIENGLISH:
pMenu->CheckMenuRadioItem(IDM_PIXEL, IDM_MM, IDM_INCH, MF_BYCOMMAND);
break;
case MM_HIMETRIC:
pMenu->CheckMenuRadioItem(IDM_PIXEL, IDM_MM, IDM_MM, MF_BYCOMMAND);
break;
case MM_TEXT:
default:
pMenu->CheckMenuRadioItem(IDM_PIXEL, IDM_MM, IDM_PIXEL, MF_BYCOMMAND);
break;
}
}
void CImageBoardView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
if (bActivate)
{
OnRealizePal((WPARAM)m_hWnd,0); // realize the new palette
SetLengthUnit(m_nLengthUnit);
SetStatusBarBitCount(m_pDib->GetBitCount());
ShowPenColor();
ShowFillColor();
ShowPenWidth();
ShowPenStyle();
ShowColorGrid();
}
CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CImageBoardView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
CImageBoardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_pDib = pDoc->m_pDib;
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetStatusBarImageSize(sizeTotal);
SetStatusBarBitCount(m_pDib->GetBitCount());
ShowColorGrid();
// re paint the entire client area
Invalidate();
}
void CImageBoardView::OnUpdateSelect(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_SELECT == m_nDrawType);
}
void CImageBoardView::OnUpdateCurve(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_CURVE == m_nDrawType);
}
void CImageBoardView::OnUpdateLine(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_LINE == m_nDrawType);
}
void CImageBoardView::OnUpdateFreeline(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_FREELINE == m_nDrawType);
}
void CImageBoardView::OnUpdateRectH(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_RECT_H == m_nDrawType);
}
void CImageBoardView::OnUpdateRectF(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_RECT_F == m_nDrawType);
}
void CImageBoardView::OnUpdateEllipseH(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_ELLIP_H == m_nDrawType);
}
void CImageBoardView::OnUpdateEllipseF(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_ELLIP_F == m_nDrawType);
}
void CImageBoardView::OnUpdateFill(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_FILL == m_nDrawType);
}
void CImageBoardView::OnUpdateText(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_TEXT == m_nDrawType);
}
void CImageBoardView::OnUpdateRoundrectF(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_ROUNDRECT_F == m_nDrawType);
}
void CImageBoardView::OnUpdateRoundrectH(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_ROUNDRECT_H == m_nDrawType);
}
void CImageBoardView::OnUpdateEraser(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_ERASER == m_nDrawType);
}
void CImageBoardView::OnUpdatePicker(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_PICKER == m_nDrawType);
}
void CImageBoardView::OnSelect()
{
SetDrawType(DT_SELECT);
}
void CImageBoardView::OnEraser()
{
SetDrawType(DT_ERASER);
}
void CImageBoardView::OnPicker()
{
SetDrawType(DT_PICKER);
}
void CImageBoardView::OnCurve()
{
SetDrawType(DT_CURVE);
}
void CImageBoardView::OnLine()
{
SetDrawType(DT_LINE);
}
void CImageBoardView::OnFreeline()
{
SetDrawType(DT_FREELINE);
}
void CImageBoardView::OnRectH()
{
SetDrawType(DT_RECT_H);
}
void CImageBoardView::OnRectF()
{
SetDrawType(DT_RECT_F);
}
void CImageBoardView::OnRoundrectF()
{
SetDrawType(DT_ROUNDRECT_F);
}
void CImageBoardView::OnRoundrectH()
{
SetDrawType(DT_ROUNDRECT_H);
}
void CImageBoardView::OnEllipseH()
{
SetDrawType(DT_ELLIP_H);
}
void CImageBoardView::OnEllipseF()
{
SetDrawType(DT_ELLIP_F);
}
void CImageBoardView::OnText()
{
SetDrawType(DT_TEXT);
}
void CImageBoardView::OnFill()
{
SetDrawType(DT_FILL);
}
void CImageBoardView::OnPencolor()
{
CColorDialog dlgColor(m_crPenColor);
if (dlgColor.DoModal() == IDOK)
{
m_crPenColor = dlgColor.GetColor();
ShowPenColor();
}
}
void CImageBoardView::OnSolid()
{
SetPenStyle(PS_SOLID);
ShowPenStyle();
}
void CImageBoardView::OnDash()
{
SetPenStyle(PS_DASH);
ShowPenStyle();
}
void CImageBoardView::OnDot()
{
SetPenStyle(PS_DOT);
ShowPenStyle();
}
void CImageBoardView::OnFillcolor()
{
CColorDialog dlgColor(m_crFillColor);
if (dlgColor.DoModal() == IDOK)
{
m_crFillColor = dlgColor.GetColor();
ShowFillColor();
}
}
void CImageBoardView::OnUpdateDash(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(PS_DASH == m_nPenStyle);
}
void CImageBoardView::OnUpdateDot(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(PS_DOT == m_nPenStyle);
}
void CImageBoardView::OnUpdateSolid(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(PS_SOLID == m_nPenStyle);
}
void CImageBoardView::OnPw1()
{
SetPenWidth(1);
ShowPenWidth();
}
void CImageBoardView::OnPw2()
{
SetPenWidth(2);
ShowPenWidth();
}
void CImageBoardView::OnPw3()
{
SetPenWidth(3);
ShowPenWidth();
}
void CImageBoardView::OnPw4()
{
SetPenWidth(4);
ShowPenWidth();
}
void CImageBoardView::OnPw5()
{
SetPenWidth(5);
ShowPenWidth();
}
void CImageBoardView::OnPw6()
{
SetPenWidth(6);
ShowPenWidth();
}
void CImageBoardView::OnPw7()
{
SetPenWidth(7);
ShowPenWidth();
}
void CImageBoardView::OnPw8()
{
SetPenWidth(8);
ShowPenWidth();
}
void CImageBoardView::OnUpdatePw1(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(1 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw2(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(2 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw3(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(3 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw4(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(4 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw5(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(5 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw6(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(6 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw7(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(7 == m_nPenWidth);
}
void CImageBoardView::OnUpdatePw8(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(8 == m_nPenWidth);
}
void CImageBoardView::OnPwOther()
{
CPenWidth dlg(this);
dlg.m_nPenWidth = m_nPenWidth;
if (dlg.DoModal() == IDOK)
SetPenWidth(dlg.m_nPenWidth);
}
void CImageBoardView::OnUpdatePwOther(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(8 < m_nPenWidth);
}
void CImageBoardView::ShowPenColor()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowPenColor(m_crPenColor);
}
void CImageBoardView::ShowFillColor()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowFillColor(m_crFillColor);
}
void CImageBoardView::ShowPenWidth()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowPenWidth(m_nPenWidth);
}
void CImageBoardView::ShowPenStyle()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowPenStyle(m_nPenStyle);
}
void CImageBoardView::ShowColorGrid()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
pAppFrame->m_wndPaintParamBar.ShowColorGrid((HPALETTE)m_pDib->m_pPalette->GetSafeHandle());
}
void CImageBoardView::OnPenColorGrid(UINT nID)
{
HPALETTE hPalette = (HPALETTE)m_pDib->m_pPalette->GetSafeHandle();
if (hPalette != NULL)
{
PALETTEENTRY pe;
GetPaletteEntries(hPalette, nID-IDC_COLORTABLE_BASE, 1, &pe);
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_FILL_COLOR)
{
m_crFillColor = RGB(pe.peRed, pe.peGreen, pe.peBlue);
ShowFillColor();
}
else if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_PEN_COLOR)
{
m_crPenColor = RGB(pe.peRed, pe.peGreen, pe.peBlue);
ShowPenColor();
}
}
}
void CImageBoardView::OnFillcolor1()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_FILL_COLOR)
OnFillcolor();
else
pAppFrame->m_wndPaintParamBar.SetSelectColorMode(PP_FILL_COLOR);
}
void CImageBoardView::OnPencolor1()
{
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_PEN_COLOR)
OnPencolor();
else
pAppFrame->m_wndPaintParamBar.SetSelectColorMode(PP_PEN_COLOR);
}
void CImageBoardView::OnFont()
{
LOGFONT lf;
m_pFont->GetLogFont(&lf);
CFontDialog dlg(&lf, CF_SCREENFONTS);
if (dlg.DoModal() == IDOK)
{
dlg.GetCurrentFont(&lf);
m_pFont->DeleteObject();
m_pFont->CreateFontIndirect(&lf);
if (::IsWindow(m_EditText.m_hWnd))
{
CString s;
m_EditText.GetWindowText(s);
CClientDC dc(this);
CFont *pOldFont = dc.SelectObject(m_pFont);
// needed rectangle
CRect rect(0,0,1,1);
dc.DrawText(s, &rect, DT_CALCRECT);
dc.SelectObject(pOldFont);
CRect rc;
m_EditText.GetWindowRect(&rc);
ScreenToClient(&rc);
if (rc.Height() < rect.Height())
rc.bottom = rc.top + rect.Height();
if (rc.Width() < rect.Width())
rc.right = rc.left + rect.Width();
ClientToDib(rc);
if (rc.bottom > m_pDib->GetHeight())
rc.bottom = m_pDib->GetHeight();
if (rc.right > m_pDib->GetWidth())
rc.right = m_pDib->GetWidth();
DibToClient(rc);
// new edit
m_EditText.SetWindowPos(NULL,0,0,rc.Width(),rc.Height(),SWP_NOMOVE|SWP_NOZORDER);
m_EditText.SetFont(m_pFont);
m_EditText.Invalidate();
// new frame
m_EditText.GetWindowRect(&rc);
ScreenToClient(&rc);
rc.InflateRect(3,3);
InvalidateRect(&rc);
}
}
}
void CImageBoardView::OnLeft()
{
m_nTextAlign = DT_LEFT;
if (::IsWindow(m_EditText.m_hWnd))
{
CRect rc;
m_EditText.GetWindowRect(&rc);
ScreenToClient(&rc);
CString s;
m_EditText.GetWindowText(s);
m_EditText.DestroyWindow();
m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_LEFT|ES_MULTILINE,
rc,
this,
IDC_EDIT);
m_EditText.SetWindowText(s);
}
}
void CImageBoardView::OnCenter()
{
m_nTextAlign = DT_CENTER;
if (::IsWindow(m_EditText.m_hWnd))
{
CRect rc;
m_EditText.GetWindowRect(&rc);
ScreenToClient(&rc);
CString s;
m_EditText.GetWindowText(s);
m_EditText.DestroyWindow();
m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_CENTER|ES_MULTILINE,
rc,
this,
IDC_EDIT);
m_EditText.SetWindowText(s);
}
}
void CImageBoardView::OnRight()
{
m_nTextAlign = DT_RIGHT;
if (::IsWindow(m_EditText.m_hWnd))
{
CRect rc;
m_EditText.GetWindowRect(&rc);
ScreenToClient(&rc);
CString s;
m_EditText.GetWindowText(s);
m_EditText.DestroyWindow();
m_EditText.Create(WS_VISIBLE|WS_CHILD|ES_RIGHT|ES_MULTILINE,
rc,
this,
IDC_EDIT);
m_EditText.SetWindowText(s);
}
}
void CImageBoardView::OnUpdateCenter(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_CENTER == m_nTextAlign);
}
void CImageBoardView::OnUpdateLeft(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_LEFT == m_nTextAlign);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -