Ejemplo n.º 1
0
static void UpdatePropertiesLayout(PropertiesLayout *layoutData, HDC hdc, RectI *rect)
{
    ScopedFont fontLeftTxt(CreateSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE));
    ScopedFont fontRightTxt(CreateSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE));
    HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt);

    /* calculate text dimensions for the left side */
    SelectObject(hdc, fontLeftTxt);
    int leftMaxDx = 0;
    for (size_t i = 0; i < layoutData->Count(); i++) {
        PropertyEl *el = layoutData->At(i);
        RECT rc = { 0 };
        DrawText(hdc, el->leftTxt, -1, &rc, DT_NOPREFIX | DT_CALCRECT);
        el->leftPos.dx = rc.right - rc.left;
        // el->leftPos.dy is set below to be equal to el->rightPos.dy

        if (el->leftPos.dx > leftMaxDx)
            leftMaxDx = el->leftPos.dx;
    }

    /* calculate text dimensions for the right side */
    SelectObject(hdc, fontRightTxt);
    int rightMaxDx = 0;
    int lineCount = 0;
    int textDy = 0;
    for (size_t i = 0; i < layoutData->Count(); i++) {
        PropertyEl *el = layoutData->At(i);
        RECT rc = { 0 };
        DrawText(hdc, el->rightTxt, -1, &rc, DT_NOPREFIX | DT_CALCRECT);
        el->rightPos.dx = rc.right - rc.left;
        el->leftPos.dy = el->rightPos.dy = rc.bottom - rc.top;
        textDy += el->rightPos.dy;

        if (el->rightPos.dx > rightMaxDx)
            rightMaxDx = el->rightPos.dx;
        lineCount++;
    }

    assert(lineCount > 0 && textDy > 0);
    int totalDx = leftMaxDx + PROPERTIES_LEFT_RIGHT_SPACE_DX + rightMaxDx;

    int totalDy = 4;
    totalDy += textDy + (lineCount - 1) * PROPERTIES_TXT_DY_PADDING;
    totalDy += 4;

    int offset = PROPERTIES_RECT_PADDING;
    if (rect)
        *rect = RectI(0, 0, totalDx + 2 * offset, totalDy + offset);

    int currY = 0;
    for (size_t i = 0; i < layoutData->Count(); i++) {
        PropertyEl *el = layoutData->At(i);
        el->leftPos = RectI(offset, offset + currY, leftMaxDx, el->leftPos.dy);
        el->rightPos.x = offset + leftMaxDx + PROPERTIES_LEFT_RIGHT_SPACE_DX;
        el->rightPos.y = offset + currY;
        currY += el->rightPos.dy + PROPERTIES_TXT_DY_PADDING;
    }

    SelectObject(hdc, origFont);
}
Ejemplo n.º 2
0
BOOL CMainWnd::DrawCtrlBoard(HDC hDC)
{
	LOGBRUSH lb;//画刷描述符
	HBRUSH hBrush, hOldBrush;//画刷句柄
	HFONT hFont, hOldFont;//字体句柄
	int FontW, FontH;//名字体宽、高

	SetBkMode(hDC, TRANSPARENT);//设置背景混合模式为透明

	//填充背景色为银灰色
	lb.lbStyle = BS_SOLID;
	lb.lbColor = RGB(230, 230, 230);
	lb.lbHatch = NULL;
	hBrush = CreateBrushIndirect(&lb);
	hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
	//FillRect填充矩形不包括右、下边界,故需要扩展矩形区域
	RECT tRect = rtInfoPart;
	tRect.right++;
	tRect.bottom++;
	FillRect(hDC, &tRect, hBrush);
	SelectObject(hDC, hOldBrush);
	DeleteObject(hBrush);

	//绘制静态框
	DrawStatic(hDC, &rtSBlc, "Black(先手)", RGB(230, 230, 230), RGB(150, 150, 150), edge);//绘制黑方静态框
	DrawStatic(hDC, &rtSWht, "White(后手)", RGB(230, 230, 230), RGB(150, 150, 150), edge);//绘制白方静态框

	//绘制引擎名
	FontW = (int)((rtBlcName.right - rtBlcName.left + 1) / strlen(strBlcName));
	FontH = (rtBlcName.bottom - rtBlcName.top + 1);
	hFont = CreateSimpleFont(FontW, FontH);
	hOldFont = (HFONT)SelectObject(hDC, hFont);
	DrawText(hDC, strBlcName, strlen(strBlcName), &rtBlcName, DT_CENTER);//绘制黑方引擎的名字
	SelectObject(hDC, hOldFont);
	DeleteObject(hFont);

	FontW = (int)((rtWhtName.right - rtWhtName.left + 1) / strlen(strWhtName));
	FontH = (rtWhtName.bottom - rtWhtName.top + 1);
	hFont = CreateSimpleFont(FontW, FontH);
	hOldFont = (HFONT)SelectObject(hDC, hFont);
	DrawText(hDC, strWhtName, strlen(strWhtName), &rtWhtName, DT_CENTER);//绘制白方引擎的名字
	SelectObject(hDC, hOldFont);
	DeleteObject(hFont);

	//绘制计时
	FontW = (int)((rtBlcTime.right - rtBlcTime.left + 1) / strlen(strBlcTime));
	FontH = (rtBlcTime.bottom - rtBlcTime.top + 1);
	hFont = CreateSimpleFont(FontW, FontH);
	hOldFont = (HFONT)SelectObject(hDC, hFont);
	DrawText(hDC, strBlcTime, strlen(strBlcTime), &rtBlcTime, DT_CENTER);//绘制黑方引擎所需时间
	DrawText(hDC, strWhtTime, strlen(strWhtTime), &rtWhtTime, DT_CENTER);//绘制白方引擎所需时间
	SelectObject(hDC, hOldFont);
	DeleteObject(hFont);

	return true;
}
Ejemplo n.º 3
0
void ViewFilesDialog::OnFviewFont(void)
{
    // Choose a font, then apply the choice to all of the text in the box.

    LOGFONT logFont;
    CFont font;

    /*
     * Create a LOGFONT structure with the desired default characteristics,
     * then use that to initialize the font dialog.
     */
    CreateSimpleFont(&font, this, fTypeFace, fPointSize);
    font.GetLogFont(&logFont);

    CFontDialog fontDlg(&logFont);
    fontDlg.m_cf.Flags &= ~(CF_EFFECTS);

    if (fontDlg.DoModal() == IDOK) {
        //fontDlg.GetCurrentFont(&logFont);
        fTypeFace = fontDlg.GetFaceName();
        fPointSize = fontDlg.GetSize() / 10;
        LOGI("Now using %d-point '%ls'", fPointSize, (LPCWSTR) fTypeFace);

        NewFontSelected(false);
    }

}
Ejemplo n.º 4
0
/**
 * SetBoard - 设置棋盘参数
 * @rtBoard:	棋盘在窗口客户区的位置
 */
VOID CNoGo::SetBoard(RECT rtBoard)
{
	//设置棋盘参数
	this->rtBoard = rtBoard;
	side = rtBoard.right - rtBoard.left;
	d = side / 10;

	//设置刻线画笔
	if (hPen != NULL)
		DeleteObject(hPen);
	pWidth = (int)(side / 300);
	if (pWidth == 0)
		pWidth = 1;
	hPen = CreatePen(PS_SOLID, pWidth, RGB(0, 0, 0));

	//设置刻度字体
	if (hFont != NULL)
		DeleteObject(hFont);
	fWidth = (int)(d / 3);
	fHeight = (int)(d * 2 / 3);
	hFont = CreateSimpleFont(fWidth, fHeight);

	//绘制棋子元素
	DrawChess();
}
Ejemplo n.º 5
0
//填充背景
BOOL CMainWnd::FillBkAndBoard(HDC hDC)
{
	char filename[MAX_PATH] = { 0 };
	HFONT hFont, hOldFont;
	int x, y, len, fWidth, fHeight;
	COLORREF hOldColor;
	LOGBRUSH lb;//画刷描述符
	HBRUSH hBrush, hOldBrush;//画刷句柄

	SetBkMode(hDC, TRANSPARENT);//设置字体背景模式为透明

	//填充背景图片
	if (gameSet.BkPicFileName[0] != 0)
	{
		DisplayImage(hDC, gameSet.BkPicFileName, &rtBackground);
	}
	else
	{
		lb.lbStyle = BS_SOLID;
		lb.lbColor = RGB(255, 255, 255);
		lb.lbHatch = NULL;
		hBrush = CreateBrushIndirect(&lb);
		hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
		FillRect(hDC, &rtBackground, hBrush);
		SelectObject(hDC, hOldBrush);
		DeleteObject(hBrush);
	}

	len = strlen("Black");
	fWidth = (rtBlcPer.right - rtBlcPer.left + 1) / (2 * len);
	fHeight = fWidth * 2;
	hFont = CreateSimpleFont(fWidth, fHeight);
	hOldFont = (HFONT)SelectObject(hDC, hFont);
	hOldColor = SetTextColor(hDC, RGB(255, 0, 0));
	if (gameSet.BlcPerFileName[0] != 0)
	{
		DisplayImage(hDC, gameSet.BlcPerFileName, &rtBlcPer);
		x = rtBlcPer.left + (rtBlcPer.right - rtBlcPer.left - len*fWidth) / 2;
		y = rtBlcPer.bottom;
		TextOut(hDC, x, y, "Black", len);
	}
	if (gameSet.WhtPerFileName[0] != 0)
	{
		DisplayImage(hDC, gameSet.WhtPerFileName, &rtWhtPer);
		x = rtWhtPer.left + (rtWhtPer.right - rtWhtPer.left - len*fWidth) / 2;
		y = rtWhtPer.bottom;
		TextOut(hDC, x, y, "White", len);
	}

	//恢复原始样式
	SetTextColor(hDC, hOldColor);
	SelectObject(hDC, hOldFont);
	DeleteObject(hFont);
	return true;
}
Ejemplo n.º 6
0
static void DrawProperties(HWND hwnd, HDC hdc)
{
    PropertiesLayout *layoutData = FindPropertyWindowByHwnd(hwnd);

    ScopedFont fontLeftTxt(CreateSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE));
    ScopedFont fontRightTxt(CreateSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE));

    HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt); /* Just to remember the orig font */

    SetBkMode(hdc, TRANSPARENT);

    ClientRect rcClient(hwnd);
    RECT rTmp = rcClient.ToRECT();
    ScopedGdiObj<HBRUSH> brushAboutBg(CreateSolidBrush(GetAboutBgColor()));
    FillRect(hdc, &rTmp, brushAboutBg);

    SetTextColor(hdc, WIN_COL_BLACK);

    /* render text on the left*/
    SelectObject(hdc, fontLeftTxt);
    for (size_t i = 0; i < layoutData->Count(); i++) {
        PropertyEl *el = layoutData->At(i);
        const WCHAR *txt = el->leftTxt;
        rTmp = el->leftPos.ToRECT();
        DrawText(hdc, txt, -1, &rTmp, DT_RIGHT | DT_NOPREFIX);
    }

    /* render text on the right */
    SelectObject(hdc, fontRightTxt);
    for (size_t i = 0; i < layoutData->Count(); i++) {
        PropertyEl *el = layoutData->At(i);
        const WCHAR *txt = el->rightTxt;
        RectI rc = el->rightPos;
        if (rc.x + rc.dx > rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING)
            rc.dx = rcClient.x + rcClient.dx - PROPERTIES_RECT_PADDING - rc.x;
        rTmp = rc.ToRECT();
        UINT format = DT_LEFT | DT_NOPREFIX | (el->isPath ? DT_PATH_ELLIPSIS : DT_WORD_ELLIPSIS);
        DrawText(hdc, txt, -1, &rTmp, format);
    }

    SelectObject(hdc, origFont);
}
Ejemplo n.º 7
0
void Label::ReadConfig()
{
    // Background and Borders
    TCHAR backgroundImageFile[MAX_PATH];
    
    mBackgroundColor = GetRCColor(mName, "BackgroundColor", RGB(255, 255, 255));
    GetRCString(mName, "BackgroundImage", backgroundImageFile, NULL, MAX_PATH);
    mBackgroundImage = LoadLSImage(backgroundImageFile, NULL);
    mBackgroundImageBorderTop = GetRCInt(mName, "BackgroundImageBorderTop", 0);
    mBackgroundImageBorderRight = GetRCInt(mName, "BackgroundImageBorderRight", 0);
    mBackgroundImageBorderBottom = GetRCInt(mName, "BackgroundImageBorderBottom", 0);
    mBackgroundImageBorderLeft = GetRCInt(mName, "BackgroundImageBorderLeft", 0);
    mBackgroundImageTile = GetRCEnum(mName, "BackgroundImageTile", gBackgroundImageTileEnum);
    mBorderColorTop = GetRCColor(mName, "BorderColorTop", RGB(0, 0, 0));
    mBorderColorRight = GetRCColor(mName, "BorderColorRight", RGB(0, 0, 0));
    mBorderColorBottom = GetRCColor(mName, "BorderColorBottom", RGB(0, 0, 0));
    mBorderColorLeft = GetRCColor(mName, "BorderColorLeft", RGB(0, 0, 0));
    mBorderTop = GetRCInt(mName, "BorderTop", 0);
    mBorderRight = GetRCInt(mName, "BorderRight", 0);
    mBorderBottom = GetRCInt(mName, "BorderBottom", 0);
    mBorderLeft = GetRCInt(mName, "BorderLeft", 0);
    
    // Font
    TCHAR fontName[LF_FACESIZE];
    int fontHeight;
    bool fontBold;
    bool fontItalic;
    bool fontUnderline;
    
    GetRCString(mName, "Font", fontName, "Arial", LF_FACESIZE);
    fontHeight = GetRCInt(mName, "FontHeight", 15);
    fontBold = GetRCBoolDef(mName, "FontBold", FALSE);
    fontItalic = GetRCBoolDef(mName, "FontItalic", FALSE);
    fontUnderline = GetRCBoolDef(mName, "FontUnderline", FALSE);
    mFont = CreateSimpleFont(fontName, fontHeight, fontBold, fontItalic, fontUnderline);
    mFontColor = GetRCColor(mName, "FontColor", RGB(0, 0, 0));
    mFontShadow = GetRCBoolDef(mName, "FontShadow", FALSE);
    mFontShadowColor = GetRCColor(mName, "FontShadowColor", RGB(128, 128, 128));
    mFontShadowOffsetX = GetRCInt(mName, "FontShadowOffsetX", 1);
    mFontShadowOffsetY = GetRCInt(mName, "FontShadowOffsetY", 1);
    
    // Layout
    mAlign = GetRCEnum(mName, "Align", gAlignEnum);
    mImagePosition = GetRCEnum(mName, "ImagePosition", gImagePositionEnum);
    mImageTextGap = GetRCInt(mName, "ImageTextGap", 4);
    mPaddingLeft = GetRCInt(mName, "PaddingLeft", 0);
    mPaddingTop = GetRCInt(mName, "PaddingTop", 0);
    mPaddingRight = GetRCInt(mName, "PaddingRight", 0);
    mPaddingBottom = GetRCInt(mName, "PaddingBottom", 0);
    mVerticalAlign = GetRCEnum(mName, "VerticalAlign", gVerticalAlignEnum);
    
    // Content
    TCHAR imageFile[MAX_PATH];
    
    GetRCString(mName, "Image", imageFile, NULL, MAX_PATH);
    mImage = LoadLSImage(imageFile, NULL);
    GetRCString(mName, "Text", mText, NULL, MAX_TEXT);
    
    // Position and Size
    mAlwaysOnTop = GetRCBoolDef(mName, "AlwaysOnTop", FALSE);
    mVisible = !GetRCBoolDef(mName, "StartHidden", FALSE);
    mX = GetRCInt(mName, "X", 0);
    mY = GetRCInt(mName, "Y", 0);
    mWidth = GetRCInt(mName, "Width", 64);
    mHeight = GetRCInt(mName, "Height", 64);
}