void DrawDisabledButton(TDC& dc, const TRect& rc) { // create a monochrome memory DC // TMemoryDC ddc; TBitmap bmp(ddc, rc.Width(), rc.Height()); ddc.SelectObject(bmp); // build a mask // ddc.PatBlt(0, 0, rc.Width(), rc.Height(), WHITENESS); dc.SetBkColor(TColor::Sys3dFace); ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY); dc.SetBkColor(TColor::Sys3dHilight); ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCPAINT); // Copy the image from the toolbar into the memory DC // and draw it (grayed) back into the toolbar. // dc.FillRect(rc, TBrush(TColor::Sys3dFace)); dc.SetBkColor(RGB(0, 0, 0)); dc.SetTextColor(RGB(255, 255, 255)); TBrush brShadow(TColor::Sys3dShadow); TBrush brHilight(TColor::Sys3dHilight); dc.SelectObject(brHilight); dc.BitBlt(rc.left+1, rc.top+1, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L); dc.SelectObject(brShadow); dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L); // reset DCs // dc.RestoreBrush(); dc.RestoreBrush(); ddc.RestoreBitmap(); }
// /// Paint the text gadget by painting gadget borders, & then painting text in /// the InnerRect. Empty or 0 text blanks the gadget. // /// Calls TGadget::PaintBorder to paint the border. Calls TGadget::GetInnerRect to /// calculate the area of the text gadget's rectangle. If the text is left-aligned, /// Paint calls dc.GetTextExtent to compute the width and height of a line of the /// text. To set the background color, Paint calls dc.GetSysColor and sets the /// default background color to face shading (COLOR_BTNFACE). To set the button text /// color, Paint calls dc.SetTextColor and sets the default button text color to /// COLOR_BTNTEXT. To draw the text, Paint calls dc.ExtTextOut and passes the /// parameters ETO_CLIPPED (so the text is clipped to fit the rectangle) and /// ETO_OPAQUE (so the rectangle is filled with the current background color). // void TTextGadget::Paint(TDC& dc) { PaintBorder(dc); TRect innerRect; GetInnerRect(innerRect); if (!Font) dc.SelectObject(GetGadgetWindow()->GetFont()); else dc.SelectObject(*Font); TColor textColor = GetEnabledColor(); if(!GetEnabled()) textColor = TColor::Sys3dHilight; bool transparent = GetGadgetWindow()->GetFlatStyle() & TGadgetWindow::FlatXPTheme; if(!Text){ if (!transparent) { TColor color = dc.SetBkColor(TColor::Sys3dFace); dc.ExtTextOut(0,0, ETO_OPAQUE, &innerRect, _T(""), 0); dc.SetBkColor(color); } } else { // Create a UI Face object for this button & let it paint the button face // uint align[] = {DT_LEFT, DT_CENTER, DT_RIGHT}; uint format = DT_SINGLELINE | DT_VCENTER | align[Align]; TUIFace face(innerRect, Text, BkgndColor, format); TPoint dstPt(innerRect.TopLeft()); dc.SetBkColor(BkgndColor); TColor oldTxColor = dc.SetTextColor(textColor); if (!GetEnabled()) face.Paint(dc, dstPt, TUIFace::Disabled, false, !transparent); else face.Paint(dc, dstPt, TUIFace::Normal, false, !transparent); dc.SetTextColor(oldTxColor); } dc.RestoreFont(); }
// /// Override TWindow virtual member function to paint the control. // void TUrlLink::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/) { TPointer<TFont> tmpFnt; // Object wrapping font handle TAPointer<tchar> text; // Pointer to caption dynamic buffer // Select the font if(!LinkFont){ HFONT hFont = HFONT(::SendMessage(::GetParent(*this), WM_GETFONT, 0, 0)); if (!hFont) hFont = HFONT(GetStockObject(ANSI_VAR_FONT)); if (hFont) tmpFnt = new TFont(hFont); } if (LinkFont) { CHECK(LinkFont->IsGDIObject()); dc.SelectObject(*LinkFont); } else if (tmpFnt) { CHECK(((TFont&)tmpFnt).IsGDIObject()); dc.SelectObject((TFont&)tmpFnt); } int len = GetWindowTextLength(); text = new tchar[len+1]; GetWindowText(text, len+1); TRect textRect; GetClientRect(textRect); TColor textColor = LinkColor; if (bOverControl) textColor = HoverColor; else if (bVisited) textColor = VisitedColor; TColor oldColor = dc.SetTextColor(textColor); int oldMode = dc.SetBkMode(TRANSPARENT); dc.DrawText(&text[0], len, textRect, 0); dc.SetBkMode(oldMode); dc.SetTextColor(oldColor); // Restore font if (LinkFont || tmpFnt) dc.RestoreFont(); }
///////////////////////////////////////////////////////////////////// // TInfoControl // ------------ // void TInfoControl::Paint (TDC& dc, BOOL erase, TRect& rect) { TControl::Paint(dc, erase, rect); TRect cRect = GetClientRect(); // Select font dc.SelectObject (*StaticFont); dc.SetBkMode (TRANSPARENT); // Draw each text line if ( TextLineTab != NULL ) { for (int i = 0 ; i < NumLines ; i++) { if (TextLineTab[i] != NULL && TextLineTab[i]->Text != NULL) { int x; dc.SetTextColor ( TMapDC::GetColor16(TextLineTab[i]->Color)); dc.SetTextAlign( TextLineTab[i]->Align); switch (TextLineTab[i]->Align & (TA_CENTER |TA_LEFT |TA_RIGHT)) { case TA_LEFT: x = 0; break; case TA_CENTER: x = cRect.Width() / 2; break; case TA_RIGHT: x = cRect.Width() - 1; break; } dc.TextOut( x, FontHeight * i, TextLineTab[i]->Text); } } } dc.RestoreFont(); }
//////////////////////////////////////////////////////////// // TBitmap256Control // ----------------- // Display bitmap in DC void TBitmap256Control::DisplayBitmap (TDC& dc, TRect &rect) { // Display a cross if no bitmap if ( pDIBInfo == 0 ) { dc.SelectObject(TPen(TColor::LtGray)); dc.MoveTo (0, 0); dc.LineTo (MaxWidth, MaxHeight); dc.MoveTo (0, MaxHeight); dc.LineTo (MaxWidth, 0); dc.SetTextAlign(TA_CENTER); dc.SetTextColor(TColor::White); dc.SetBkColor(TColor::Black); char tmp[40]; if ( BitmapName[0] != '\0' && BitmapName[0] != '-' ) wsprintf (tmp, "No picture (%s)", BitmapName); else wsprintf (tmp, "No picture"); dc.TextOut (MaxWidth / 2, MaxHeight / 2 - 6, tmp); return; } assert (pBitmapPalette != NULL); // pBitmapPalette->UnrealizeObject(); dc.SelectObject (*pBitmapPalette); dc.RealizePalette(); dc.SetStretchBltMode (COLORONCOLOR); #if 1 TRect ZoomRect; ZoomRect.left = rect.left; ZoomRect.top = rect.top; ZoomRect.right = rect.right; ZoomRect.bottom = rect.bottom; // Convert the rect. size to a rect in the sprite rect.left /= ZoomFactor; rect.top /= ZoomFactor; rect.right /= ZoomFactor; rect.bottom /= ZoomFactor; TRect DIBRect; DIBRect.left = rect.left; DIBRect.top = BitmapYSize - rect.bottom; // DIBs are Y inversed DIBRect.right = DIBRect.left + rect.Width(); DIBRect.bottom = DIBRect.top + rect.Height(); dc.StretchDIBits (ZoomRect, DIBRect, pDIBits, *pDIBInfo, DIB_PAL_COLORS, SRCCOPY); #else // Create memory DC and display bitmap TMemoryDC mdc (dc); mdc.SelectObject (*pBitmapPalette); mdc.SelectObject (*pBitmap); dc.StretchBlt(0, 0, ZoomXSize, ZoomYSize, mdc, 0, 0, BitmapXSize, BitmapYSize, SRCCOPY); // Restore GDI objects mdc.RestoreBitmap(); mdc.RestorePalette(); #endif dc.RestorePalette(); }
// /// Paint Text // void TButtonTextGadget::PaintText(TDC& dc, TRect& rect, const tstring& text) { dc.SelectObject(GetFont()); TColor textColor = TColor::SysBtnText; if(!GetEnabled()) textColor = TColor::Sys3dHilight; else if((GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatHotText) && IsHaveMouse()) textColor = TColor::LtBlue; TColor oldTxColor = dc.SetTextColor(textColor); uint format = DT_SINGLELINE|DT_NOCLIP|DT_END_ELLIPSIS; switch(Align){ case aLeft: format |= DT_LEFT; break; case aRight: format |= DT_RIGHT; break; case aCenter: format |= DT_CENTER; break; } switch(LayoutStyle){ case lTextLeft: case lTextRight: format |= DT_VCENTER; break; case lTextTop: format |= DT_VCENTER;//DT_BOTTOM; break; case lTextBottom: format |= DT_VCENTER;//DT_TOP; break; } // Create a UI Face object for this button & let it paint the button face // TPoint dstPt(rect.TopLeft()); if (GetButtonState() == Down && GetEnabled() && GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatStandard) { if(IsHaveMouse()) { if(IsPressed()) { const int dx = (format & DT_CENTER) ? 2 : 1; const int dy = (format & DT_VCENTER) ? 2 : 1; rect.Offset(dx, dy); } TUIFace(rect, text, TColor::Sys3dFace,format).Paint(dc, dstPt, TUIFace::Normal, true, true); } else { TUIFace face(rect, text, TColor::Sys3dFace,format); if(GetGadgetWindow()->GadgetGetCaptured()==this) face.Paint(dc, dstPt, TUIFace::Normal, true); else face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false); } } else { TUIFace face(rect, text, TColor::Sys3dFace,format); if (!GetEnabled()) face.Paint(dc, dstPt, TUIFace::Disabled, false, false); else if (GetButtonState() == Indeterminate) face.Paint(dc, dstPt, TUIFace::Indeterm, IsPressed(), false); else if (GetButtonState() == Down) // Down and not flat face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false); else face.Paint(dc, dstPt, TUIFace::Normal, IsPressed(), false); } dc.SetTextColor(oldTxColor); dc.RestoreFont(); }