📄 cdc.cpp
字号:
posList[nCount * 2 ] = lpPoints[0].x;
posList[nCount * 2 + 1] = lpPoints[0].y;
uglPolygon(m_uglGcId , nCount + 1 , posList);
return true;
}
bool CDC::Polygon( CPoint *lpPoints, int nCount )
{
UGL_POS posList[(nCount + 1) * 2];
int i;
for(i = 0 ; i < nCount ; i ++ )
{
//由于windml对于带有负数的多边形绘制会有问题
posList[i*2] = (lpPoints[i].x >= 0) ? lpPoints[i].x:0;
posList[i*2 + 1] = (lpPoints[i].y >= 0) ? lpPoints[i].y:0;
}
posList[nCount * 2 ] = lpPoints[0].x;
posList[nCount * 2 + 1] = lpPoints[0].y;
uglPolygon(m_uglGcId , nCount + 1 , posList);
return true;
}
//##ModelId=4050003700A3
bool CDC::Rectangle(int x1, int y1, int x2, int y2)
{
uglRectangle(m_uglGcId , x1 , y1 , x2 , y2);
return true;
}
//##ModelId=4050003700AB
bool CDC::Rectangle(RECT *lpRect)
{
return Rectangle(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom);
}
//##ModelId=4050003700B3
bool CDC::Rectangle(CRect *lpRect)
{
return Rectangle(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom);
}
//##ModelId=4050003700B5
bool CDC::Ellipse(int x1, int y1, int x2, int y2)
{
uglEllipse(m_uglGcId , x1 , y1 , x2 , y2 , 0 , 0, 0 , 0);
return true;
}
//##ModelId=4050003700BE
bool CDC::Ellipse(RECT *lpRect)
{
return Ellipse(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom);
}
//##ModelId=4050003700C0
bool CDC::Ellipse(CRect *lpRect)
{
return Ellipse(lpRect->left,lpRect->top,lpRect->right,lpRect->bottom);
}
//##ModelId=4050003700C2
bool CDC::LineTo(int x, int y)
{
UGL_STATUS status = uglLine(m_uglGcId ,m_nCurPosition.x , m_nCurPosition.y , x , y );
if(status != UGL_STATUS_OK)
return false;
m_nCurPosition.x = x;
m_nCurPosition.y = y;
return true;
}
//##ModelId=4050003700C9
bool CDC::LineTo(POINT point)
{
LineTo(point.x , point.y);
}
//##ModelId=4050003700CB
bool CDC::LineTo(CPoint point)
{
LineTo(point.x , point.y);
}
//##ModelId=4050003700CD
CPoint CDC::MoveTo(int x, int y)
{
m_nCurPosition.x = x;
m_nCurPosition.y = y;
}
//##ModelId=4050003700D3
CPoint CDC::MoveTo(POINT point)
{
m_nCurPosition.x = point.x;
m_nCurPosition.y = point.y;
}
bool CDC::Polyline( CPoint *lpPoints, int nCount )
{
//转换成POINT 类型
UGL_POS posList[nCount* 2];
int i;
for(i = 0 ; i < nCount ; i ++ )
{
posList[i*2] = lpPoints[i].x;
posList[i*2 + 1] = lpPoints[i].y;
}
return Polyline((POINT *)posList , nCount);
}
//##ModelId=4050003700D5
bool CDC::Polyline(POINT *lpPoints, int nCount)
{
//保存颜色
UGL_COLOR preColor;
uglBackgroundColorGet(m_uglGcId , &preColor);
//不填充,背景透明
uglBackgroundColorSet(m_uglGcId , UGL_COLOR_TRANSPARENT);
uglPolygon(m_uglGcId , nCount , (UGL_POS *)lpPoints);
//恢复颜色
uglBackgroundColorSet(m_uglGcId , preColor);
}
//##ModelId=4050003700DC
void CDC::FillRect(RECT *lpRect, CBrush* pBrush)
{
CBrush *preBrush = SelectObject(pBrush);
UGL_COLOR preColor;
uglForegroundColorGet(m_uglGcId , &preColor);
uglForegroundColorSet(m_uglGcId , pBrush->m_BackgroundColor);
uglRectangle(m_uglGcId , lpRect->left , lpRect->top , lpRect->right , lpRect->bottom);
uglForegroundColorSet(m_uglGcId , preColor);
SelectObject(preBrush);
}
//##ModelId=4050003700DF
void CDC::FillRect(CRect *lpRect, CBrush* pBrush)
{
RECT rect = { lpRect->left , lpRect->top , lpRect->right , lpRect->bottom};
FillRect(&rect , pBrush);
}
//##ModelId=4050003700E5
void CDC::FillRect(CRect Rect, CBrush* pBrush)
{
RECT rect = { Rect.left , Rect.top , Rect.right , Rect.bottom};
FillRect(&rect , pBrush);
}
//##ModelId=4050003700E8
bool CDC::SetPixelV(int x, int y, COLORREF crColor)
{
UGL_COLOR uglColor = CWMLHelp::GetColor(crColor);
uglPixelSet(m_uglGcId , x ,y ,uglColor);
return true;
}
//##ModelId=4050003700F1
bool CDC::SetPixelV(POINT point, COLORREF crColor)
{
UGL_COLOR uglColor = CWMLHelp::GetColor(crColor);
uglPixelSet(m_uglGcId , point.x ,point.y ,uglColor);
return true;
}
//##ModelId=4050003700F4
COLORREF CDC::SetPixel(int x, int y, COLORREF crColor)
{
UGL_COLOR uglColor = CWMLHelp::GetColor(crColor);
uglPixelSet(m_uglGcId , x ,y ,uglColor);
return crColor;
}
//##ModelId=4050003700FB
COLORREF CDC::SetPixel(POINT point, COLORREF crColor)
{
return SetPixel(point.x,point.y,crColor);
}
//##ModelId=4050003700FE
UGL_COLOR CDC::GetPixel(int x, int y)
{
UGL_COLOR color;
uglPixelGet(m_uglGcId , x , y ,&color);
return color;
}
//##ModelId=405000370105
UGL_COLOR CDC::GetPixel(POINT point)
{
return GetPixel(point.x , point.y);
}
//##ModelId=405000370107
int CDC::SetBkMode(int nBkMode)
{
m_nBkMode = nBkMode;
return m_nBkMode;
}
//##ModelId=405000370109
int CDC::GetBkMode()
{
return m_nBkMode;
}
//##ModelId=40500037010E
COLORREF CDC::SetBkColor(COLORREF crColor)
{
UGL_COLOR uglcolor = CWMLHelp::GetColor(crColor);
if(uglBackgroundColorSet(m_uglGcId , uglcolor) == UGL_STATUS_OK)
return crColor;
return UGL_NULL;
}
//##ModelId=405000370110
UGL_COLOR CDC::GetBkColor()
{
UGL_COLOR backgroundColor;
if(uglBackgroundColorGet(m_uglGcId , &backgroundColor) == UGL_STATUS_OK)
return backgroundColor;
return UGL_NULL;
}
//##ModelId=405000370111
UGL_COLOR CDC::GetTextColor()
{
UGL_COLOR foregroundColor;
if(uglForegroundColorGet(m_uglGcId , &foregroundColor) == UGL_STATUS_OK)
return foregroundColor;
return UGL_NULL;
}
//##ModelId=405000370112
COLORREF CDC::SetTextColor(COLORREF crColor)
{
UGL_COLOR uglcolor = CWMLHelp::GetColor(crColor);
if(uglForegroundColorSet(m_uglGcId , uglcolor) == UGL_STATUS_OK)
return crColor;
return UGL_NULL;
}
//##ModelId=405000370115
bool CDC::TextOut(int x, int y, LPCTSTR lpszString, int nCount)
{
int length = (strlen(lpszString) < nCount) ? strlen(lpszString) : nCount ;
//字符串的长和高
CSize size = GetTextExtent(lpszString , nCount);
if(m_nBkMode == TRANSPARENT){
UGL_COLOR backColor ;
uglBackgroundColorGet(m_uglGcId , &backColor);
uglBackgroundColorSet(m_uglGcId , UGL_COLOR_TRANSPARENT);
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId , x , y + size.cy , length ,lpszString);
uglBackgroundColorSet(m_uglGcId , backColor);
}else{
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId , x , y + size.cy , length ,lpszString);
}
return true;
}
//##ModelId=40500037011C
bool CDC::TextOut(int x, int y, const CString& str)
{
CSize size = GetTextExtent(str.C_STR() , strlen(str.C_STR()));
if(m_nBkMode == TRANSPARENT){
UGL_COLOR backColor ;
uglBackgroundColorGet(m_uglGcId , &backColor);
uglBackgroundColorSet(m_uglGcId , UGL_COLOR_TRANSPARENT);
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId,x,y + size.cy , -1 ,str.C_STR());
uglBackgroundColorSet(m_uglGcId , backColor);
}else{
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId,x,y + size.cy , -1 ,str.C_STR());
}
return true;
}
//##ModelId=405000370124
bool CDC::TextOut(int x, int y, const char *pStr)
{
if(pStr == NULL)
return false;
CSize size = GetTextExtent(pStr , strlen(pStr));
if(m_nBkMode == TRANSPARENT){
UGL_COLOR backColor ;
uglBackgroundColorGet(m_uglGcId , &backColor);
uglBackgroundColorSet(m_uglGcId , UGL_COLOR_TRANSPARENT);
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId,x,y + size.cy , -1,pStr);
uglBackgroundColorSet(m_uglGcId , backColor);
}else{
//转换输出字符的基点为左下角
uglTextDraw(m_uglGcId,x,y + size.cy , -1,pStr);
}
return true;
}
//##ModelId=405000370124
bool CDC::TextOutW(int x, int y, const char *pStr)
{
if(pStr == NULL)
return false;
CSize size = GetTextExtent(pStr , strlen(pStr));
int length = strlen(pStr);
if(m_nBkMode == TRANSPARENT){
UGL_COLOR backColor ;
uglBackgroundColorGet(m_uglGcId , &backColor);
uglBackgroundColorSet(m_uglGcId , UGL_COLOR_TRANSPARENT);
//转换输出字符的基点为左下角
uglTextDrawW(m_uglGcId,x,y + size.cy , length,(UGL_WCHAR *)pStr);
uglBackgroundColorSet(m_uglGcId , backColor);
}else{
//转换输出字符的基点为左下角
uglTextDrawW(m_uglGcId,x,y + size.cy , length,(UGL_WCHAR *)pStr);
}
return true;
}
int CDC::SelectClipRgn(CRgn* pRgn)
{
SelectObject(pRgn);
}
/*
//##ModelId=405000370130
int CDC::SelectClipRgn(CRgn* pRgn, int nMode)
{
UGL_REGION_ID curClipRegionId;
uglClipRegionGet(m_uglGcId , &curClipRegionId);
if(curClipRegionId != UGL_NULL){
CRgn curRgn(curClipRegionId);
curRgn.CombineRgn(pRgn , &curRgn , nMode);
SelectObject(&curRgn);
}else{
CRgn curRgn;
int left,top,right,bottom;
uglClipRectGet(m_uglGcId , &left ,&top ,&right , &bottom);
curRgn.CreateRectRgn(left,top,right,bottom);
curRgn.CombineRgn(pRgn , &curRgn , nMode);
SelectObject(&curRgn);
}
uglRegionDestroy(pRgn->m_uglRegionId);
pRgn->m_uglRegionId = UGL_NULL;
return 0;
}
*/
bool CDC::DeleteObject()
{
if(m_uglGcId == NULL)
return true;
if(m_pBitmap != UGL_NULL){
//没有把选择进来的位图选出去
assert(false);
}
//释放画刷,字体,和画笔
delete m_pCurBrush;
m_pCurBrush = 0;
delete m_pCurFont;
m_pCurFont = 0;
delete m_pCurPen;
m_pCurPen = 0;
//释放裁减区
UGL_REGION_ID curClipRegionId;
uglClipRegionGet(m_uglGcId , &curClipRegionId);
if(curClipRegionId != NULL){
uglRegionDestroy(curClipRegionId);
uglClipRegionSet(m_uglGcId , NULL);
}
//释放gc
uglGcDestroy(m_uglGcId);
m_uglGcId = UGL_NULL;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -