📄 fontcurvectl.cpp
字号:
// CFontCurveCtrl::OnResetState - Reset control to default state
void CFontCurveCtrl::OnResetState()
{
COleControl::OnResetState();
}
/////////////////////////////////////////////////////////////////////////////
// CFontCurveCtrl message handlers
/////////////////////////////////////////////////////////////////////////////
bool CFontCurveCtrl::DrawGrid(CDC * pDC, CRect &rc)
{
ASSERT(pDC != NULL);
CPen linePen(PS_SOLID, m_nGridLineWidth, m_colorGridLine);
CPen * pPen = pDC ->SelectObject(&linePen);
CPoint pt(rc.left, rc.top);
int nWidth = rc.Width();
int nHeight = rc.Height();
int nGridWidth = (nWidth-m_nGridLineWidth*(m_nGridWidthNum+1))/m_nGridWidthNum;
int nGridHeight = (nHeight-m_nGridLineWidth*(m_nGridHeightNum+1))/m_nGridHeightNum;
//画垂直线
for(int i = (pt.x + nGridWidth); i < (pt.x+nWidth); i = i + nGridWidth+m_nGridLineWidth)
{
pDC ->MoveTo(i, pt.y);
pDC ->LineTo(i, pt.y + m_nGridHeightNum*(nGridHeight+m_nGridLineWidth));
}
//画水平线
for(int j = (pt.y+nGridHeight); j < (pt.y+nHeight); j = j+nGridHeight+m_nGridLineWidth)
{
pDC ->MoveTo(pt.x, j);
pDC ->LineTo(pt.x + m_nGridWidthNum*(nGridWidth+m_nGridLineWidth), j);
}
pDC ->SelectObject(pPen);
return true;
}
/*
注意:
根据提供的数据缓冲来组建Grid信息显示队列,然后根据Grid信息显示队列进行绘图
显示顺序:
水平显示:比如 8*8的点阵
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
.......................
57 58 59 60 61 62 63 64
垂直显示:比如 8*8的点阵
1 9 . 57
2 10 . 58
3 11 . 59
4 12 . 60
5 13 . 61
6 14 . 62
7 15 . 63
8 16 . 64
*/
bool CFontCurveCtrl::FillGrid(CDC * pDC, CRect &rc, COLORREF color, int nDrawType)
{
ASSERT(pDC != NULL);
bool bIsEmpty = true;
for(int i = 0; i <= GRID_SHOW_BUF_LEN; i++)
{
if(m_byShowBuf[i] != 0x00)
bIsEmpty = false;
}
if(bIsEmpty)
return true;
int x = 0, y = 0;
bool bDraw = false;
CURVE_SHOW_INFO * pNewInfo = NULL;
int nOneGridWidth = (rc.Width() - (m_nGridWidthNum+1)*m_nGridLineWidth)/m_nGridWidthNum;
int nOneGridHeight = (rc.Height() - (m_nGridHeightNum+1)*m_nGridLineWidth)/m_nGridHeightNum;
int nWidth8Count = m_nGridShowWidth/8;
for(y = 0; y < m_nGridShowHeight; y++)
{
for(x = 0; x < m_nGridShowWidth; x++)
{
bDraw = (m_byShowBuf[nWidth8Count*y + x/8]>>(7-x%8)%8) & 0x01;
if(bDraw)
{
pNewInfo = new CURVE_SHOW_INFO;
if(m_nGridShowType == GRID_SHOW_POS_HORI) //水平扫描
{
pNewInfo ->gridRect.left = rc.left+(x+1)*m_nGridLineWidth+x*nOneGridWidth;
pNewInfo ->gridRect.top = rc.top+(y+1)*m_nGridLineWidth+y*nOneGridHeight;
pNewInfo ->gridRect.right = rc.left+(x+1)*m_nGridLineWidth+(x+1)*nOneGridWidth;;
pNewInfo ->gridRect.bottom = rc.top+(y+1)*m_nGridLineWidth+(y+1)*nOneGridHeight;;
pNewInfo ->gridX = x+1;
pNewInfo ->gridY = y+1;
}
else if(m_nGridShowType == GRID_SHOW_POS_VER) //垂直扫描
{
pNewInfo ->gridRect.left = rc.left+(y+1)*m_nGridLineWidth+y*nOneGridHeight;
pNewInfo ->gridRect.top = rc.top+(x+1)*m_nGridLineWidth+x*nOneGridWidth;
pNewInfo ->gridRect.right = rc.left+(y+1)*m_nGridLineWidth+(y+1)*nOneGridHeight;
pNewInfo ->gridRect.bottom = rc.top+(x+1)*m_nGridLineWidth+(x+1)*nOneGridWidth;
pNewInfo ->gridX = y+1;
pNewInfo ->gridY = x+1;
}
m_gridList.AddTail(pNewInfo);
}
}
}
CBrush backBrush(color);
CBrush *pBrush = pDC ->SelectObject(&backBrush);
POSITION pos = m_gridList.GetHeadPosition();
while(pos)
{
CURVE_SHOW_INFO *pInfo = m_gridList.GetNext(pos);
if(nDrawType == GRID_DRAW_RECT)
pDC ->FillRect(pInfo ->gridRect, &backBrush);
else if(nDrawType == GRID_DRAW_CIR)
pDC ->FillRect(pInfo ->gridRect, &backBrush);
}
pDC ->SelectObject(pBrush);
//释放所有队列资源
FreeAllResource();
return true;
}
bool CFontCurveCtrl::FreeAllResource()
{
POSITION pos = m_gridList.GetHeadPosition();
while(pos)
{
CURVE_SHOW_INFO * pInfo = m_gridList.GetNext(pos);
delete pInfo;
}
m_gridList.RemoveAll();
return true;
}
bool CFontCurveCtrl::ShowData(BYTE * pInData, int nWidth, int nHeight, int nShowType)
{
if(pInData == NULL)
return false;
if((nWidth == 0) || (nHeight == 0))
return false;
memset(m_byShowBuf, 0x00, GRID_SHOW_BUF_LEN*sizeof(BYTE));
memcpy(m_byShowBuf, pInData, nWidth*nHeight*sizeof(BYTE));
m_nGridShowType = nShowType;
m_nGridShowWidth = nWidth;
m_nGridShowHeight = nHeight;
InvalidateControl();
SetModifiedFlag();
return true;
}
bool CFontCurveCtrl::JudgeGridNum()
{
if(m_nGridWidthNum <= GRID_LENGTH_8)
m_nGridWidthNum = GRID_LENGTH_8;
else if(m_nGridWidthNum <= GRID_LENGTH_16)
m_nGridWidthNum = GRID_LENGTH_16;
else if(m_nGridWidthNum <= GRID_LENGTH_24)
m_nGridWidthNum = GRID_LENGTH_24;
else if(m_nGridWidthNum <= GRID_LENGTH_32)
m_nGridWidthNum = GRID_LENGTH_32;
if(m_nGridHeightNum <= GRID_LENGTH_8)
m_nGridHeightNum = GRID_LENGTH_8;
else if(m_nGridHeightNum <= GRID_LENGTH_16)
m_nGridHeightNum = GRID_LENGTH_16;
else if(m_nGridHeightNum <= GRID_LENGTH_24)
m_nGridHeightNum = GRID_LENGTH_24;
else if(m_nGridHeightNum <= GRID_LENGTH_32)
m_nGridHeightNum = GRID_LENGTH_32;
if(m_nGridWidthNum > m_nGridHeightNum)
m_nGridWidthNum = m_nGridHeightNum;
else
m_nGridHeightNum = m_nGridWidthNum;
return true;
}
void CFontCurveCtrl::SetBackColor(OLE_COLOR backColor)
{
m_colorBackGround = TranslateColor(backColor);
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridLineColor(OLE_COLOR gridlineColor)
{
m_colorGridLine = TranslateColor(gridlineColor);
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridColor(OLE_COLOR gridColor)
{
m_colorGrid = TranslateColor(gridColor);
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridHoriNum(short horiNum)
{
m_nGridWidthNum = horiNum;
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridVerNum(short verNum)
{
m_nGridHeightNum = verNum;
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridShowType(short showType)
{
m_nGridShowType = showType;
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::SetGridDrawType(short drawType)
{
m_nGridDrawType = drawType;
InvalidateControl();
SetModifiedFlag();
}
void CFontCurveCtrl::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
if((lpncsp ->rgrc[0].bottom - lpncsp ->rgrc[0].top) > (lpncsp ->rgrc[0].right - lpncsp ->rgrc[0].left))
lpncsp ->rgrc[0].right = lpncsp ->rgrc[0].left+(lpncsp ->rgrc[0].bottom - lpncsp ->rgrc[0].top);
else
lpncsp ->rgrc[0].bottom = lpncsp ->rgrc[0].top + (lpncsp ->rgrc[0].right - lpncsp ->rgrc[0].left);
COleControl::OnNcCalcSize(bCalcValidRects, lpncsp);
}
void CFontCurveCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);
}
BOOL CFontCurveCtrl::ShowGridData(BSTR FAR* pInData, short nWidth, short nHeight, short nShowType)
{
return ShowData((BYTE *)pInData, nWidth, nHeight, nShowType);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -