//----------------------------------------------------------------------------- // Purpose: Draw the current image //----------------------------------------------------------------------------- void AnimatingImagePanel::PaintBackground() { if ( m_Frames.IsValidIndex( m_iCurrentImage ) && m_Frames[m_iCurrentImage] != NULL ) { IImage *pImage = m_Frames[m_iCurrentImage]; surface()->DrawSetColor( 255, 255, 255, 255 ); pImage->SetPos(0, 0); if ( m_bScaleImage ) { // Image size is stored in the bitmap, so temporarily set its size // to our panel size and then restore after we draw it. int imageWide, imageTall; pImage->GetSize( imageWide, imageTall ); int wide, tall; GetSize( wide, tall ); pImage->SetSize( wide, tall ); pImage->SetColor( Color( 255,255,255,255 ) ); pImage->Paint(); pImage->SetSize( imageWide, imageTall ); } else { pImage->Paint(); } } }
//----------------------------------------------------------------------------- // Purpose: Paint the image on screen. Images are not panels, // You must call the Paint method explicitly for them. // and set thier position in the frame every time you draw them. //----------------------------------------------------------------------------- void ImageDemo::Paint() { m_pImage->SetPos(100, 100); m_pImage->Paint(); }
//----------------------------------------------------------------------------- // Purpose: overridden main drawing function for the panel //----------------------------------------------------------------------------- void Label::Paint() { int tx0, ty0, tx1, ty1; ComputeAlignment(tx0, ty0, tx1, ty1); // calculate who our associate is if we haven't already if (_associateName) { SetAssociatedControl(FindSiblingByName(_associateName)); delete [] _associateName; _associateName = NULL; } int labelWide, labelTall; GetSize(labelWide, labelTall); int x = tx0, y = _textInset[1] + ty0; int imageYPos = 0; // a place to save the y offset for when we draw the disable version of the image // draw the set of images for (int i = 0; i < _imageDar.Count(); i++) { TImageInfo &imageInfo = _imageDar[i]; IImage *image = imageInfo.image; if (!image) continue; // skip over null images // add the offset to x x += imageInfo.offset; // if this is the text image then add its inset to the left or from the right if (i == _textImageIndex) { switch ( _contentAlignment ) { // left case Label::a_northwest: case Label::a_west: case Label::a_southwest: { x += _textInset[0]; break; } // right case Label::a_northeast: case Label::a_east: case Label::a_southeast: { x -= _textInset[0]; break; } } } // see if the image is in a fixed position if (imageInfo.xpos >= 0) { x = imageInfo.xpos; } // draw imageYPos = y; image->SetPos(x, y); // fix up y for center-aligned text if (_contentAlignment == Label::a_west || _contentAlignment == Label::a_center || _contentAlignment == Label::a_east) { int iw, it; image->GetSize(iw, it); if (it < (ty1 - ty0)) { imageYPos = ((ty1 - ty0) - it) / 2 + y; image->SetPos(x, ((ty1 - ty0) - it) / 2 + y); } } // don't resize the image unless its too big if (imageInfo.width >= 0) { int w, t; image->GetSize(w, t); if (w > imageInfo.width) { image->SetSize(imageInfo.width, t); } } // if it's the basic text image then draw specially if (image == _textImage) { if (IsEnabled()) { if (_associate.Get() && ipanel()->HasParent(input()->GetFocus(), _associate->GetVPanel())) { _textImage->SetColor(_associateColor); } else { _textImage->SetColor(GetFgColor()); } _textImage->Paint(); } else { // draw disabled version, with embossed look // offset image _textImage->SetPos(x + 1, imageYPos + 1); _textImage->SetColor(_disabledFgColor1); _textImage->Paint(); surface()->DrawFlushText(); // overlayed image _textImage->SetPos(x, imageYPos); _textImage->SetColor(_disabledFgColor2); _textImage->Paint(); } } else { image->Paint(); } // add the image size to x int wide, tall; image->GetSize(wide, tall); x += wide; } }