📄 imageboardview.cpp
字号:
}
void CImageBoardView::OnUpdateRight(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(DT_RIGHT == m_nTextAlign);
}
void CImageBoardView::OnEditCopy()
{
CopyToClipboard();
}
void CImageBoardView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnEditCut()
{
Cut();
}
void CImageBoardView::OnUpdateEditCut(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnEditPaste()
{
Paste();
}
void CImageBoardView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
pCmdUI->Enable(::IsClipboardFormatAvailable(CF_DIB) ||
::IsClipboardFormatAvailable(CF_BITMAP) ||
::IsClipboardFormatAvailable(CF_PALETTE));
}
void CImageBoardView::OnSelectpaste()
{
CSelectPasteDlg spDlg(this);
if (spDlg.DoModal() == IDOK)
{
SelectPaste(spDlg.m_nCF);
}
}
void CImageBoardView::OnUpdateSelectpaste(CCmdUI* pCmdUI)
{
pCmdUI->Enable(::IsClipboardFormatAvailable(CF_DIB) ||
::IsClipboardFormatAvailable(CF_BITMAP) ||
::IsClipboardFormatAvailable(CF_PALETTE));
}
void CImageBoardView::OnCrop()
{
Crop();
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateCrop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty() && ! m_rcClip.IsRectEmpty());
}
void CImageBoardView::OnRotateAngle()
{
// TODO: Add your command handler code here
CRotateAngle rotateDlg;
if (rotateDlg.DoModal() == IDOK)
{
Rotate(rotateDlg.m_fAngle);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateRotateAngle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnRotate()
{
Rotate(90);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateRotate(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnRotate180()
{
Rotate(180);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateRotate180(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnRotate270()
{
Rotate(270);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateRotate270(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnHmirror()
{
Flip(MD_HORZ);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateHmirror(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnVmirror()
{
Flip(MD_VERT);
CImageBoardDoc* pDoc = GetDocument();
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
void CImageBoardView::OnUpdateVmirror(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnScale()
{
CImageBoardDoc* pDoc = GetDocument();
CScale scaleDlg(m_pDib->GetWidth(), m_pDib->GetHeight(), this);
if (scaleDlg.DoModal() == IDOK)
{
ChangeImageSize(scaleDlg.m_nWidth, scaleDlg.m_nHeight);
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateScale(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnCanvassize()
{
CImageBoardDoc* pDoc = GetDocument();
CCanvasSize canvasDlg((int)m_pDib->GetWidth(), (int)m_pDib->GetHeight(), this);
if (canvasDlg.DoModal() == IDOK)
{
ChangeCanvasSize(canvasDlg.m_nWidth, canvasDlg.m_nHeight, canvasDlg.m_nPosition);
CSize sizeTotal(m_pDib->GetWidth(), m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
pDoc->SetModifiedFlag(TRUE);
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateCanvassize(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnAdjustcolor()
{
CImageBoardDoc* pDoc = GetDocument();
CAdjustColorDlg colorDlg(this);
if (colorDlg.DoModal() == IDOK)
{
m_pDib->AdjustColor(colorDlg.m_nColorModel,
colorDlg.m_nValue1,
colorDlg.m_nValue2,
colorDlg.m_nValue3);
pDoc->SetModifiedFlag(TRUE);
OnRealizePal((WPARAM)m_hWnd,0); // realize the new palette
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateAdjustcolor(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnBc()
{
CImageBoardDoc* pDoc = GetDocument();
CBCDlg bcDlg(this);
if (bcDlg.DoModal() == IDOK)
{
m_pDib->AdjustBrightness(bcDlg.m_nValue1);
m_pDib->AdjustContrast(bcDlg.m_nValue2);
pDoc->SetModifiedFlag(TRUE);
OnRealizePal((WPARAM)m_hWnd,0); // realize the new palette
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateBc(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnColorbits()
{
CImageBoardDoc* pDoc = GetDocument();
CColorBitsDlg colorBitsDlg((int)m_pDib->GetBitCount(), this);
if (colorBitsDlg.DoModal() == IDOK)
{
m_pDib->ColorQuantize(colorBitsDlg.m_nColorBits);
pDoc->SetModifiedFlag(TRUE);
OnRealizePal((WPARAM)m_hWnd,0); // realize the new palette
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateColorbits(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnGray()
{
CImageBoardDoc* pDoc = GetDocument();
CGrayDlg grayDlg(this);
if (grayDlg.DoModal() == IDOK)
{
m_pDib->ChangeToGrayscale(grayDlg.m_nMethod,
grayDlg.m_fWeightR,
grayDlg.m_fWeightG,
grayDlg.m_fWeightB);
pDoc->SetModifiedFlag(TRUE);
OnRealizePal((WPARAM)m_hWnd,0); // realize the new palette
pDoc->UpdateAllViews(NULL);
}
}
void CImageBoardView::OnUpdateGray(CCmdUI* pCmdUI)
{
pCmdUI->Enable(! m_pDib->IsEmpty());
}
void CImageBoardView::OnDestroy()
{
CScrollView::OnDestroy();
DeleteFloatWnd();
delete m_pFont;
}
void CImageBoardView::CreateFloatWnd(HDIB hDib, CPoint ptTopLeft)
{
MergeFloatDib();
// get DIB width and height
LPBYTE lpDIB = (LPBYTE)GlobalLock(hDib);
if (! lpDIB)
{
GlobalUnlock(hDib);
return;
}
int nWidth = (int)DIBWidth(lpDIB);
int nHeight = (int)DIBHeight(lpDIB);
GlobalUnlock(hDib);
// create float window
CRect rc(ptTopLeft.x, ptTopLeft.y, ptTopLeft.x+nWidth, ptTopLeft.y+nHeight);
m_pFloatWnd = new CFloatDibWnd(hDib, rc, this);
}
void CImageBoardView::DeleteFloatWnd()
{
if (m_pFloatWnd)
{
delete m_pFloatWnd;
m_pFloatWnd = NULL;
}
}
void CImageBoardView::ClientToDib(CPoint& point)
{
point.x += GetScrollPos(SB_HORZ);
point.y += GetScrollPos(SB_VERT);
}
void CImageBoardView::ClientToDib(CRect& rect)
{
rect.left += GetScrollPos(SB_HORZ);
rect.top += GetScrollPos(SB_VERT);
rect.right += GetScrollPos(SB_HORZ);
rect.bottom += GetScrollPos(SB_VERT);
}
void CImageBoardView::DibToClient(CPoint& point)
{
point.x -= GetScrollPos(SB_HORZ);
point.y -= GetScrollPos(SB_VERT);
}
void CImageBoardView::DibToClient(CRect& rect)
{
rect.left -= GetScrollPos(SB_HORZ);
rect.top -= GetScrollPos(SB_VERT);
rect.right -= GetScrollPos(SB_HORZ);
rect.bottom -= GetScrollPos(SB_VERT);
}
BOOL CImageBoardView::AdjustPointinDib(CPoint& point)
{
int nWidth = m_pDib->GetWidth();
int nHeight = m_pDib->GetHeight();
BOOL bOut = FALSE;
ClientToDib(point);
if (point.x < 0)
{
point.x = 0;
bOut = TRUE;
}
else if (point.x >= nWidth)
{
point.x = nWidth;
bOut = TRUE;
}
if (point.y < 0)
{
point.y = 0;
bOut = TRUE;
}
else if (point.y >= nHeight)
{
point.y = nHeight;
bOut = TRUE;
}
DibToClient(point);
return bOut;
}
void CImageBoardView::DoDrawRubber(CDC *pDC, CRect rc)
{
if (rc.IsRectEmpty())
return;
// draw
switch(m_nDrawType)
{
case DT_SELECT:
case DT_TEXT:
pDC->Rectangle(&rc);
break;
case DT_LINE:
{
// use client coordinates
CPoint ptStart(m_ptStart);
DibToClient(ptStart);
if (ptStart == rc.TopLeft() ||
ptStart == rc.BottomRight())
{
pDC->MoveTo(rc.TopLeft());
pDC->LineTo(rc.BottomRight());
}
else
{
pDC->MoveTo(rc.right, rc.top);
pDC->LineTo(rc.left, rc.bottom);
}
}
break;
case DT_CURVE:
{
if (m_nDrawCurveStep == 0)
{
// use client coordinates
CPoint ptStart(m_ptStart);
DibToClient(ptStart);
if (ptStart == rc.TopLeft() ||
ptStart == rc.BottomRight())
{
pDC->MoveTo(rc.TopLeft());
pDC->LineTo(rc.BottomRight());
}
else
{
pDC->MoveTo(rc.right, rc.top);
pDC->LineTo(rc.left, rc.bottom);
}
}
}
break;
case DT_RECT_H:
case DT_RECT_F:
pDC->Rectangle(&rc);
break;
case DT_ROUNDRECT_H:
case DT_ROUNDRECT_F:
pDC->RoundRect(&rc, CPoint((int)(rc.Width()/3), (int)(rc.Height()/3)));
break;
case DT_ELLIP_H:
case DT_ELLIP_F:
pDC->Ellipse(&rc);
break;
}
}
void CImageBoardView::StartDrawRubber(CPoint point)
{
// save current mouse position
ClientToDib(point);
m_ptStart = point;
// empty current rectangle
m_rcClip.SetRectEmpty();
m_rcRubber.SetRectEmpty();
// capture mouse
SetCapture();
}
void CImageBoardView::DrawRubber(CPoint point)
{
// get DC and set its ROP
CClientDC dc(this);
// define used pen
int nPenStyle;
int nPenWidth;
COLORREF color;
int nOldRop = dc.SetROP2(R2_NOTXORPEN);
if (m_nDrawType == DT_SELECT || m_nDrawType == DT_TEXT)
{
nPenStyle = PS_DOT;
nPenWidth = 1;
color = RGB(0,0,0);
}
else
{
nPenStyle = m_nPenStyle;
nPenWidth = m_nPenWidth;
color = m_crPenColor;
}
CPen pen(nPenStyle, nPenWidth, color);
CPen* pOldPen = dc.SelectObject(&pen);
// if there is rectangle drawn, clear it
DoDrawRubber(&dc, m_rcRubber);
// Adjust cooridnates for select
if (m_nDrawType == DT_SELECT)
{
// get current scroll pos
int nScrollX = GetScrollPos(SB_HORZ);
int nScrollY = GetScrollPos(SB_VERT);
// calculate new scroll pos, and set it
CRect rcClient;
GetClientRect(&rcClient);
int nMinX, nMaxX, nMinY, nMaxY;
GetScrollRange(SB_HORZ, &nMinX, &nMaxX);
GetScrollRange(SB_VERT, &nMinY, &nMaxY);
BOOL bNeedRedraw = FALSE;
if ((rcClient.Width() < m_pDib->GetWidth()) &&
(point.x < 0 || point.x > rcClient.right))
{
nScrollX += point.x;
nScrollX = BOUND(nScrollX, nMinX, nMaxX);
SetScrollPos(SB_HORZ, nScrollX);
bNeedRedraw = TRUE;
}
if ((rcClient.Height() < m_pDib->GetHeight()) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -