void CImageGUISkin::drawHorizontalProgressBar( IGUIElement* element, const core::rect<s32>& rectangle, const core::rect<s32>* clip, f32 filledRatio, video::SColor fillColor ) { if ( !Config.ProgressBar.Texture || !Config.ProgressBarFilled.Texture ) { return; } // Draw empty progress bar drawElementStyle( Config.ProgressBar, rectangle, clip ); // Draw filled progress bar on top if ( filledRatio < 0.0f ) filledRatio = 0.0f; else if ( filledRatio > 1.0f ) filledRatio = 1.0f; if ( filledRatio > 0.0f ) { s32 filledPixels = (s32)( filledRatio * rectangle.getSize().Width ); s32 height = rectangle.getSize().Height; core::rect<s32> clipRect = clip? *clip:rectangle; if ( filledPixels < height ) { if ( clipRect.LowerRightCorner.X > rectangle.UpperLeftCorner.X + filledPixels ) clipRect.LowerRightCorner.X = rectangle.UpperLeftCorner.X + filledPixels; filledPixels = height; } core::rect<s32> filledRect = core::rect<s32>( rectangle.UpperLeftCorner.X, rectangle.UpperLeftCorner.Y, rectangle.UpperLeftCorner.X + filledPixels, rectangle.LowerRightCorner.Y ); drawElementStyle( Config.ProgressBarFilled, filledRect, &clipRect, &fillColor ); } }
void CImageGUISkin::drawElementStyle( const SImageGUIElementStyle& elem, const core::rect<s32>& rect, const core::rect<s32>* clip, video::SColor* pcolor ) { core::rect<s32> srcRect; core::rect<s32> dstRect; core::dimension2d< u32 > tsize = elem.Texture->getSize(); video::ITexture* texture = elem.Texture; video::SColor color = elem.Color; if ( pcolor ) color = *pcolor; video::SColor faceColor = getColor(EGDC_3D_FACE); color.setRed( (u8)(color.getRed() * faceColor.getRed() / 255) ); color.setGreen( (u8)(color.getGreen() * faceColor.getGreen() / 255) ); color.setBlue( (u8)(color.getBlue() * faceColor.getBlue() / 255) ); color.setAlpha( (u8)(color.getAlpha() * faceColor.getAlpha() / 255 ) ); video::SColor colors [4] = { color, color, color, color }; core::dimension2di dstSize = rect.getSize(); // Scale the border if there is insufficient room SImageGUIElementStyle::SBorder dst = elem.DstBorder; f32 scale = 1.0f; if ( dstSize.Width < dst.Left + dst.Right ) { scale = dstSize.Width / (f32)( dst.Left + dst.Right ); } if ( dstSize.Height < dst.Top + dst.Bottom ) { f32 x = dstSize.Height / (f32)( dst.Top + dst.Bottom ); if ( x < scale ) { scale = x; } } if ( scale < 1.0f ) { dst.Left = (s32)( dst.Left * scale ); dst.Right = (s32)( dst.Right * scale ); dst.Top = (s32)( dst.Top * scale ); dst.Bottom = (s32)( dst.Bottom * scale ); } const SImageGUIElementStyle::SBorder& src = elem.SrcBorder; // Draw the top left corner srcRect = core::rect<s32>( 0, 0, src.Left, src.Top ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y, rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the top right corner srcRect = core::rect<s32>( tsize.Width-src.Right, 0, tsize.Width, src.Top ); dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X, rect.UpperLeftCorner.Y+dst.Top ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the top border srcRect = core::rect<s32>( src.Left, 0, tsize.Width-src.Right, src.Top ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the left border srcRect = core::rect<s32>( 0, src.Top, src.Left, tsize.Height-src.Bottom ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y+dst.Top, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the right border srcRect = core::rect<s32>( tsize.Width-src.Right, src.Top, tsize.Width, tsize.Height-src.Bottom ); dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X, rect.LowerRightCorner.Y-dst.Bottom ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the middle section srcRect = core::rect<s32>( src.Left, src.Top, tsize.Width-src.Right, tsize.Height-src.Bottom ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the bottom left corner srcRect = core::rect<s32>( 0, tsize.Height-src.Bottom, src.Left, tsize.Height ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.LowerRightCorner.Y-dst.Bottom, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the bottom right corner srcRect = core::rect<s32>( tsize.Width-src.Right, tsize.Height-src.Bottom, tsize.Width, tsize.Height ); dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X, rect.LowerRightCorner.Y ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); // Draw the bottom border srcRect = core::rect<s32>( src.Left, tsize.Height-src.Bottom, tsize.Width-src.Right, tsize.Height ); dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y ); if ( !clip || clipRects( dstRect, srcRect, *clip ) ) VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true ); }