// /// Retrieves information about this font when selected in the specified dc. // void TFont::GetTextMetrics(TEXTMETRIC& tm, TDC& dc) const { dc.SelectObject(*this); dc.GetTextMetrics(tm); dc.RestoreFont(); }
void TGaugeGadget::Paint(TDC& dc, bool erase, TRect &rect) { // Select the approprate font dc.SelectObject(Window->GetFont()); TGauge::Paint(dc, erase, rect); dc.RestoreFont(); }
// /// Returns the extent of a given string using this particular font in a /// particular DC. // TSize TFont::GetTextExtent(TDC& dc, const tstring& text) const { dc.SelectObject(*this); TSize size = dc.GetTextExtent(text, static_cast<int>(text.length())); // TODO: Widen parameter type to avoid this narrowing cast. dc.RestoreFont(); return size; }
// /// 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(); }
// /// 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(); }
void npredictMDIChild::Paint ( TDC& dc , BOOL , TRect& ) { int i, j, n, b, row, col, rstart, rstop, cstart, cstop, prevcol ; int xlab_height, xlab_width, ylab_height, ylab_width, wide ; int xlab_lw, xlab_rw, tick_height, font_height, r0, r1, c0 ; double xscale, yscale, xtickscale, ytickscale, *sig, val ; double x, xfac ; char msg[256] ; TRect rect ; SIZE size ; TColor bkgnd, *lines ; TBrush *brush ; TPen *pen, *second_pen ; TFont *font ; n = istop - istart + 1 ; sig = signal->sig ; dc.SetMapMode ( MM_TEXT ) ; dc.SetROP2 ( R2_COPYPEN ) ; dc.SetBkMode ( OPAQUE ) ; bkgnd = dc.GetNearestColor ( TColor ( background_color ) ) ; dc.SetBkColor ( bkgnd ) ; GetClientRect ( rect ) ; b = rect.bottom ; // We use origin at bottom, so b-y adapts to Windows /* Paint the background */ brush = new TBrush ( bkgnd ) ; dc.SelectObject ( *brush ) ; pen = new TPen ( bkgnd ) ; dc.SelectObject ( *pen ) ; dc.Rectangle ( rect ) ; dc.RestoreBrush () ; delete brush ; dc.RestorePen () ; delete pen ; /* Setup main drawing pen and secondary pen for hash lines */ lines = new TColor ( 0 , 0 , 0 ) ; pen = new TPen ( *lines , 1 , PS_SOLID ) ; second_pen = new TPen ( *lines , 1 , PS_DASH ) ; /* Compute the maximum height and width of the axis tick labels. This lets us position the graph optimally. */ xlab_height = xlab_width = ylab_height = ylab_width = xlab_lw = xlab_rw = 0 ; font_height = rect.bottom / 20 ; if (rect.right / 24 < font_height) font_height = rect.right / 24 ; if (font_height < 8) font_height = 0 ; if (font_height) { font = new TFont ( "Helvetica" , font_height ) ; dc.SelectObject ( *font ) ; for (i=0 ; i<xnticks ; i++) { sprintf ( msg , "%*.*lf", xndigits, xnfrac, xmin + i * xdif ) ; GetTextExtentPoint ( dc , msg , strlen(msg) , &size ) ; if (! i) xlab_lw = size.cx ; // Width of leftmost x label if (i == xnticks-1) xlab_rw = size.cx ; // And rightmost x label if (size.cx > xlab_width) xlab_width = size.cx ; if (size.cy > xlab_height) xlab_height = size.cy ; } for (i=0 ; i<ynticks ; i++) { sprintf ( msg , "%*.*lf", yndigits, ynfrac, ymin + i * ydif ) ; GetTextExtentPoint ( dc , msg , strlen(msg) , &size ) ; if (size.cx > ylab_width) ylab_width = size.cx ; if (size.cy > ylab_height) ylab_height = size.cy ; } tick_height = xlab_height / 2 ; } else { tick_height = rect.bottom / 64 + 2 ; font = NULL ; } /* Last check on label display. Are X-axis labels to wide? */ if ((xlab_width * xnticks) > (3 * rect.right / 4)) { font_height = 0 ; xlab_height = xlab_width = ylab_height = ylab_width = 0 ; xlab_lw = xlab_rw = 0 ; tick_height = rect.bottom / 64 + 2 ; if (font != NULL) { dc.RestoreFont () ; delete font ; font = NULL ; } } /* Compute the graph extent based on these label metrics */ rstart = tick_height + xlab_height + 1 ; // Ticks, X tick labels rstop = rect.bottom - ylab_height/2 - 2 ; // Top half of topmost label if (xlab_lw / 2 > ylab_width) // If left half of X label biggest cstart = xlab_lw / 2 + 1 ; // Use it for offset else cstart = ylab_width + 2 ; // Otherwise Y labels determine it cstop = rect.right - xlab_rw / 2 - 2 ; // Leave room for rightmost label /* Compute scales for data and ticks */ xscale = (double) (cstop - cstart) / (xmax - xmin) ; xfac = (rightx - leftx) / (n-1) ; yscale = (double) (rstop - rstart) / (ymax - ymin) ; xtickscale = (double) (cstop-cstart) / (double) (xnticks-1) ; ytickscale = (double) (rstop-rstart) / (double) (ynticks-1) ; /* Outline the graph, draw ticks, and write their labels */ dc.SelectObject ( *pen ) ; dc.MoveTo ( cstart , b-rstart ) ; dc.LineTo ( cstop , b-rstart ) ; dc.LineTo ( cstop , b-rstop ) ; dc.LineTo ( cstart , b-rstop ) ; dc.LineTo ( cstart , b-rstart ) ; dc.RestorePen () ; for (i=0 ; i<ynticks ; i++) { /* Y ticks */ row = rstart + i * ytickscale + 0.5 ; if (i && (i < ynticks-1)) { // Horizontal interior lines dc.SelectObject ( *second_pen ) ; dc.MoveTo ( cstart , b-row ) ; dc.LineTo ( cstop , b-row ) ; dc.RestorePen () ; } if (font_height) { sprintf ( msg , "%*.*lf", yndigits, ynfrac, ymin + i * ydif ) ; rect.bottom = b - (row - ylab_height / 2) ; rect.top = rect.bottom - ylab_height - 1 ; rect.right = cstart - 1 ; rect.left = rect.right - ylab_width - 1 ; dc.SelectObject ( *pen ) ; dc.DrawText ( msg , -1 , rect , DT_SINGLELINE | DT_BOTTOM | DT_RIGHT ); dc.RestorePen () ; } } dc.SelectObject ( *pen ) ; prevcol = 0 ; for (i=0 ; i<xnticks ; i++) { /* X ticks */ col = cstart + i * xtickscale + 0.5 ; dc.MoveTo ( col , b-rstart ) ; dc.LineTo ( col , b-(rstart - tick_height) ) ; if (i) { /* Make an additional, unlabeled tick between main ones */ dc.MoveTo ( (col + prevcol) / 2 , b-rstart ) ; dc.LineTo ( (col + prevcol) / 2 , b-(rstart - tick_height/2) ) ; } prevcol = col ; if (font_height) { sprintf ( msg , "%*.*lf", xndigits, xnfrac, xmin + i * xdif ) ; while (*msg == ' ') // Remove leading blanks strcpy ( msg , msg+1 ) ; rect.top = b - (rstart - tick_height) ; rect.bottom = rect.top + xlab_height - 1 ; rect.right = col + xlab_width / 2 ; rect.left = rect.right - xlab_width - 1 ; dc.DrawText ( msg , -1 , rect , DT_SINGLELINE | DT_BOTTOM | DT_CENTER); } } dc.RestorePen () ; if (font_height) { dc.RestoreFont () ; delete font ; } /* Draw the graph */ if ((signal->type == DataSignal) || (signal->type == SpectrumSignal) || (signal->type == SpectrumDevSignal)) { if ((command_id == ID_PRED_DISPLAY_CONFIDENCE) && // Draw confidence first (signal->known_n <= istop)) { // If visible delete second_pen ; // No longer needed for hash lines, so use for second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines dc.SelectObject ( *second_pen ) ; i = signal->known_n - 1 ; if (i >= istart) r0 = rstart + (int) ((sig[i] - ymin) * yscale) ; else { i = istart ; j = i - signal->known_n ; if (signal->mult_conf) val = sig[i] * signal->intervals[2*j] ; else val = sig[i] + signal->intervals[2*j] ; r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ; } if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = (i - istart) * xfac + leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.MoveTo ( c0 , r0 ) ; for (i=i+1 ; i<signal->known_n+signal->npred ; i++) { if (i > istop) break ; j = i - signal->known_n ; if (signal->mult_conf) val = sig[i] * signal->intervals[2*j] ; else val = sig[i] + signal->intervals[2*j] ; r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ; if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = (i - istart) * xfac + leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.LineTo ( c0 , r0 ) ; } i = signal->known_n - 1 ; if (i >= istart) r0 = rstart + (int) ((sig[i] - ymin) * yscale) ; else { i = istart ; j = i - signal->known_n ; if (signal->mult_conf) val = sig[i] * signal->intervals[2*j] ; else val = sig[i] + signal->intervals[2*j] ; r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ; } if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = (i - istart) * xfac + leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.MoveTo ( c0 , r0 ) ; for (i=signal->known_n ; i<signal->known_n+signal->npred ; i++) { if (i > istop) break ; j = i - signal->known_n ; if (signal->mult_conf) val = sig[i] * signal->intervals[2*j+1] ; else val = sig[i] + signal->intervals[2*j+1] ; r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ; if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = (i - istart) * xfac + leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.LineTo ( c0 , r0 ) ; } dc.RestorePen () ; } if (signal->type == SpectrumDevSignal) { delete second_pen ; // No longer needed for hash lines, so use for second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines dc.SelectObject ( *second_pen ) ; row = rstart + (int) ((corrlim - ymin) * yscale + 0.5) ; // Confidence if ((row >= rstart) && (row <= rstop)) { dc.MoveTo ( cstart , b-row ) ; dc.LineTo ( cstop , b-row ) ; } row = rstart + (int) ((-corrlim - ymin) * yscale + 0.5) ; // Confidence if ((row >= rstart) && (row <= rstop)) { dc.MoveTo ( cstart , b-row ) ; dc.LineTo ( cstop , b-row ) ; } dc.RestorePen () ; } dc.SelectObject ( *pen ) ; r0 = rstart + (int) ((sig[istart] - ymin) * yscale) ; if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.MoveTo ( c0 , r0 ) ; for (i=istart+1 ; i<=istop ; i++) { r0 = rstart + (int) ((sig[i] - ymin) * yscale + 0.5) ; if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; x = (i - istart) * xfac + leftx ; c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ; dc.LineTo ( c0 , r0 ) ; } dc.RestorePen () ; } // If DataSignal or SpectrumSignal else if (signal->type == CorrelationSignal) { delete second_pen ; // No longer needed for hash lines, so use for second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines dc.SelectObject ( *second_pen ) ; row = rstart + (int) ((corrlim - ymin) * yscale + 0.5) ; // Confidence if ((row >= rstart) && (row <= rstop)) { dc.MoveTo ( cstart , b-row ) ; dc.LineTo ( cstop , b-row ) ; } row = rstart + (int) ((-corrlim - ymin) * yscale + 0.5) ; // Confidence if ((row >= rstart) && (row <= rstop)) { dc.MoveTo ( cstart , b-row ) ; dc.LineTo ( cstop , b-row ) ; } dc.RestorePen () ; wide = (cstop - cstart) / n ; r0 = rstart + (int) ((0.0 - ymin) * yscale + 0.5) ; for (i=0 ; i<ynticks ; i++) { // Search all horizontal ticks row = rstart + i * ytickscale + 0.5 ; // Because rounding error if (abs ( r0 - row ) <= 1) { // Might make 0 off by one r0 = row ; // Which looks ugly break ; } } if (r0 < rstart) r0 = rstart ; if (r0 > rstop) r0 = rstop ; r0 = b - r0 ; dc.SelectObject ( *pen ) ; for (i=0 ; i<n ; i++) { c0 = cstart + (int) (xscale * (i+1) + 0.5) ; r1 = rstart + (int) ((sig[i] - ymin) * yscale + 0.5) ; if (r1 < rstart) r1 = rstart ; if (r1 > rstop) r1 = rstop ; r1 = b - r1 ; dc.MoveTo ( c0 , r0 ) ; dc.LineTo ( c0 , r1 ) ; if (wide && (c0 > cstart)) { dc.MoveTo ( c0-1 , r0 ) ; dc.LineTo ( c0-1 , r1 ) ; } if (wide && (c0 < cstop)) { dc.MoveTo ( c0+1 , r0 ) ; dc.LineTo ( c0+1 , r1 ) ; } if ((wide > 9) && (c0 > cstart+1)) { dc.MoveTo ( c0-2 , r0 ) ; dc.LineTo ( c0-2 , r1 ) ; } if ((wide > 9) && (c0 < cstop-1)) { dc.MoveTo ( c0+2 , r0 ) ; dc.LineTo ( c0+2 , r1 ) ; } } dc.RestorePen () ; } delete pen ; delete second_pen ; delete lines ; }