void TabDisplay::PaintButton(Canvas &canvas, unsigned CaptionStyle, const TCHAR *caption, const PixelRect &rc, const Bitmap *bmp, const bool isDown, bool inverse) { PixelRect rcTextFinal = rc; const UPixelScalar buttonheight = rc.bottom - rc.top; const PixelSize text_size = canvas.CalcTextSize(caption); const int textwidth = text_size.cx; const int textheight = text_size.cy; UPixelScalar textheightoffset = 0; if (textwidth > (rc.right - rc.left)) // assume 2 lines textheightoffset = std::max(0, (int)(buttonheight - textheight * 2) / 2); else textheightoffset = std::max(0, (int)(buttonheight - textheight) / 2); rcTextFinal.top += textheightoffset; canvas.DrawFilledRectangle(rc, canvas.GetBackgroundColor()); if (bmp != NULL) { const PixelSize bitmap_size = bmp->GetSize(); const int offsetx = (rc.right - rc.left - bitmap_size.cx / 2) / 2; const int offsety = (rc.bottom - rc.top - bitmap_size.cy) / 2; if (inverse) // black background canvas.CopyNotOr(rc.left + offsetx, rc.top + offsety, bitmap_size.cx / 2, bitmap_size.cy, *bmp, bitmap_size.cx / 2, 0); else canvas.CopyAnd(rc.left + offsetx, rc.top + offsety, bitmap_size.cx / 2, bitmap_size.cy, *bmp, bitmap_size.cx / 2, 0); } else { #ifndef USE_GDI if (IsDithered()) CaptionStyle |= DT_UNDERLINE; #endif canvas.DrawFormattedText(&rcTextFinal, caption, CaptionStyle); } }
void TabDisplay::PaintButton(Canvas &canvas, unsigned CaptionStyle, const TCHAR *caption, const PixelRect &rc, const Bitmap *bmp, const bool isDown, bool inverse) { PixelRect rcTextFinal = rc; const UPixelScalar buttonheight = rc.bottom - rc.top; const PixelSize text_size = canvas.CalcTextSize(caption); const int textwidth = text_size.cx; const int textheight = text_size.cy; UPixelScalar textheightoffset = 0; if (textwidth > (rc.right - rc.left)) // assume 2 lines textheightoffset = std::max(0, (int)(buttonheight - textheight * 2) / 2); else textheightoffset = std::max(0, (int)(buttonheight - textheight) / 2); rcTextFinal.top += textheightoffset; canvas.DrawFilledRectangle(rc, canvas.GetBackgroundColor()); if (bmp != nullptr) { const PixelSize bitmap_size = bmp->GetSize(); const int offsetx = (rc.right - rc.left - bitmap_size.cx / 2) / 2; const int offsety = (rc.bottom - rc.top - bitmap_size.cy) / 2; #ifdef ENABLE_OPENGL if (inverse) { OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); /* invert the texture color */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); /* copy the texture alpha */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); } else /* simple copy */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const GLEnable scope(GL_TEXTURE_2D); const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLTexture &texture = *bmp->GetNative(); texture.Bind(); texture.Draw(rc.left + offsetx, rc.top + offsety); #else if (inverse) // black background canvas.CopyNotOr(rc.left + offsetx, rc.top + offsety, bitmap_size.cx / 2, bitmap_size.cy, *bmp, bitmap_size.cx / 2, 0); else canvas.CopyAnd(rc.left + offsetx, rc.top + offsety, bitmap_size.cx / 2, bitmap_size.cy, *bmp, bitmap_size.cx / 2, 0); #endif } else { #ifndef USE_GDI if (IsDithered()) CaptionStyle |= DT_UNDERLINE; #endif canvas.DrawFormattedText(&rcTextFinal, caption, CaptionStyle); } }