// /// Invalidate the working portion of this gadget--in this case just the /// InnerRect /// /// Calls TGadget::GetInnerRect to compute the area of the text for the gadget and /// then TGadget::InvalidateRect to invalidate the rectangle in the parent window. void TTextGadget::Invalidate() { TRect innerRect; GetInnerRect(innerRect); bool transparent = GetGadgetWindow()->GetFlatStyle() & TGadgetWindow::FlatXPTheme; InvalidateRect(innerRect, transparent); // Erase (redraw background) if transparent. }
void TMultiFontTextGadget :: Paint ( TDC & dc ) { TRect InnerRect ; register int left, x, y ; dc. SetMapperFlags ( 0 ) ; TAutoTextGadget :: Paint ( dc ) ; // Récupérer les coordonnées initiales GetInnerRect ( InnerRect ) ; left = InnerRect. left ; x = left ; // Parcourir la liste for ( TTextEntry * te = TextEntries ; te ; te = te -> Next ) { TSize Extent ; COLORREF OldText, OldBk, NewText, NewBk ; int OldBkMode ; dc. SelectObject ( * te -> Font ) ; Extent = dc. GetTextExtent ( te -> Text, te -> TextLength ) ; y = InnerRect. top + ( ( InnerRect. Height ( ) - Extent. cy ) / 2 ) ; NewBk = te -> BackgroundColor ; if ( NewBk == 0xFFFFFFFFL ) NewBk = GetSysColor ( COLOR_BTNFACE ) ; NewText = te -> ForegroundColor ; if ( NewText == 0xFFFFFFFFL ) NewText = GetSysColor ( COLOR_BTNTEXT ) ; OldText = dc. SetTextColor ( NewText ) ; OldBk = dc. SetBkColor ( NewBk ) ; OldBkMode = dc. SetBkMode ( OPAQUE ) ; dc. ExtTextOut ( x, y, ETO_OPAQUE, & TRect ( x, InnerRect. top, x + Extent. cx, InnerRect. bottom ), te -> Text, te -> TextLength ) ; dc. SetBkMode ( OldBkMode ) ; dc. SetBkColor ( OldBk ) ; dc. SetTextColor ( OldText ) ; dc. RestoreFont ( ) ; x += Extent. cx ; } }
void CObject::DrawInnerRect(QPainter* painter) { const QRect& r =GetInnerRect(); int rheight=r.height(); int rtop=r.top(); int bottom = iSize.y()-r.height()-r.top(); int right = r.left()+r.width(); int top = iSize.y()-r.top(); //painter->setPen(QPen(QColor(0,0,0))); QPointF position = GetPosition(); QPointF size = GetSize(); painter->fillRect(QRect(position.toPoint(),QSize(size.x(),size.y())),Qt::black); }
// /// 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(); }
// /// Calls TGadget::PaintBorder to perform the actual painting of the border of the /// control. Get Inner rectangle of control, layout Text and Bitmap and call /// PaintText() and PaintFace(). // void TButtonTextGadget::Paint(TDC& dc) { PRECONDITION(Window); PaintBorder(dc); TRect faceRect, textRect, btnRect; GetInnerRect(faceRect); Layout(faceRect, textRect, btnRect); if(Style&sText) PaintText(dc, textRect, Text); if(Style&sBitmap) PaintFace(dc, btnRect); }
// /// If (Style & sBitmap) calls TButtonGadget::SetBounds; otherwise calls /// TGadget::SetBounds to set the boundary of the rectangle, and it (Style & /// sBitmap) calculates new BitmapOrigin. // void TButtonTextGadget::SetBounds(const TRect& rect) { PRECONDITION(Window); if(Style&sBitmap) TButtonGadget::SetBounds(rect); else TGadget::SetBounds(rect); if(Style&sBitmap && Style&sText){ TRect faceRect, textRect, btnRect; GetInnerRect(faceRect); Layout(faceRect, textRect, btnRect); TSize bitmapSize = GetCelArray() ? GetCelArray()->CelSize() : GetGadgetWindow()->GetCelArray().CelSize(); TPoint pt; pt.x = btnRect.left + (btnRect.Width() - bitmapSize.cx) / 2; pt.y = btnRect.top + (btnRect.Height() - bitmapSize.cy) / 2; SetBitmapOrigin(pt); } }
// /// Tiles the gadgets in the direction requested (horizontal or vertical). Derived /// classes can adjust the spacing between gadgets. /// /// Horizontal direction results in a row-major layout, /// and vertical direction results in column-major layout // TRect TToolBox::TileGadgets() { TSize cellSize; ComputeCellSize(cellSize); int numRows, numColumns; ComputeNumRowsColumns(numRows, numColumns); TRect innerRect; GetInnerRect(innerRect); TRect invalidRect; invalidRect.SetEmpty(); if (Direction == Horizontal) { // Row Major // int y = innerRect.top; TGadget* g = Gadgets; for (int r = 0; r < numRows; r++) { int x = innerRect.left; for (int c = 0; c < numColumns && g; c++) { TRect bounds(TPoint(x, y), cellSize); TRect originalBounds(g->GetBounds()); if (bounds != g->GetBounds()) { g->SetBounds(bounds); if (invalidRect.IsNull()) invalidRect = bounds; else invalidRect |= bounds; if (originalBounds.TopLeft() != TPoint(0, 0)) invalidRect |= originalBounds; } x += cellSize.cx; g = g->NextGadget(); } y += cellSize.cy; } } else { // Column Major // int x = innerRect.left; TGadget* g = Gadgets; for (int c = 0; c < numColumns; c++) { int y = innerRect.top; for (int r = 0; r < numRows && g; r++) { TRect bounds(TPoint(x, y), cellSize); TRect originalBounds(g->GetBounds()); if (bounds != originalBounds) { g->SetBounds(bounds); if (invalidRect.IsNull()) invalidRect = bounds; else invalidRect |= bounds; if (originalBounds.TopLeft() != TPoint(0, 0)) invalidRect |= originalBounds; } y += cellSize.cy; g = g->NextGadget(); } x += cellSize.cx; } } return invalidRect; }