|
|
|
GDI+ 直接画 或者d2d 或者skia 都行。。。GDI+圆角有锯齿 根据这个开 锯齿就没了 阴影自己根据窗体边缘画 void Form::RenderContent() { if (!m_hWnd || !m_mainBitmap) return; int totalWidth = m_mainBitmap->GetWidth(); int totalHeight = m_mainBitmap->GetHeight(); Gdiplus::Graphics graphics(m_mainBitmap.get()); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); graphics.SetInterpolationMode(Gdiplus::InterpolationModeBicubic); Gdiplus::GraphicsPath updatePath; if (m_forceFullRedraw || m_isStaticBackgroundDirty) { if (m_isStaticBackgroundDirty || !m_staticBackgroundCache) { m_staticBackgroundCache = std::make_unique<Gdiplus::Bitmap>(totalWidth, totalHeight, PixelFormat32bppARGB); Gdiplus::Graphics bgGraphics(m_staticBackgroundCache.get()); bgGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); bgGraphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf); ///*graphics.SetPageUnit(Gdiplus::UnitPixel);*/ bgGraphics.SetInterpolationMode(Gdiplus::InterpolationModeBicubic); bgGraphics.Clear(Gdiplus::Color(0, 0, 0, 0)); if (m_isShadowDirty || !m_shadowCache) { m_shadowCache = std::make_unique<Gdiplus::Bitmap>(totalWidth, totalHeight, PixelFormat32bppARGB); Gdiplus::Graphics shadowGraphics(m_shadowCache.get()); shadowGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); shadowGraphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf); shadowGraphics.SetInterpolationMode(Gdiplus::InterpolationModeBicubic); shadowGraphics.Clear(Gdiplus::Color(0, 0, 0, 0)); for (int i = 0; i < m_shadowLayers; ++i) { Gdiplus::REAL currentSpreadFactor = static_cast<Gdiplus::REAL>(i) / std::max<Gdiplus::REAL>(1, static_cast<Gdiplus::REAL>(m_shadowLayers) - 1); Gdiplus::REAL actualSpread = m_shadowSpread * currentSpreadFactor; double normalizedPos = static_cast<double>(i) / std::max<double>(1, m_shadowLayers - 1); int currentAlpha = static_cast<int>(m_shadowMaxAlpha * (1.0 - normalizedPos)); currentAlpha = std::max<int>(0, std::min<int>(255, currentAlpha)); Gdiplus::RectF shadowRect(m_shadowSpread - actualSpread, m_shadowSpread - actualSpread, m_clientWindowWidth + 2 * actualSpread, m_clientWindowHeight + 2 * actualSpread); Gdiplus::GraphicsPath layerPath; CreateRoundedRectPath(layerPath, shadowRect, m_cornerRadius + actualSpread); Gdiplus::SolidBrush shadowBrush(Gdiplus::Color(currentAlpha, 0, 0, 0)); shadowGraphics.FillPath(&shadowBrush, &layerPath); } m_isShadowDirty = false; } bgGraphics.DrawImage(m_shadowCache.get(), 0, 0); Gdiplus::RectF bodyRect = GetClientArea(); Gdiplus::GraphicsPath formBodyPath; CreateRoundedRectPath(formBodyPath, bodyRect, m_cornerRadius); Gdiplus::SolidBrush bodyBrush(From_background); bgGraphics.FillPath(&bodyBrush, &formBodyPath); m_isStaticBackgroundDirty = false; } graphics.Clear(Gdiplus::Color(0, 0, 0, 0)); graphics.DrawImage(m_staticBackgroundCache.get(), 0, 0); for (const auto& element : m_elements) { if (element->IsVisible()) { element->Draw(graphics); } } updatePath.AddRectangle(Gdiplus::RectF(0, 0, static_cast<Gdiplus::REAL>(totalWidth), static_cast<Gdiplus::REAL>(totalHeight))); } |
|