xref: /MusicPlayer2/MusicPlayer2/GdiPlusTool.cpp (revision 9b32c1f65086ce3ea42d441b2f3350b622a575e7)
1 #include "stdafx.h"
2 #include "GdiPlusTool.h"
3 
4 
CGdiPlusTool()5 CGdiPlusTool::CGdiPlusTool()
6 {
7 }
8 
9 
~CGdiPlusTool()10 CGdiPlusTool::~CGdiPlusTool()
11 {
12 }
13 
COLORREFToGdiplusColor(COLORREF color,BYTE alpha)14 Gdiplus::Color CGdiPlusTool::COLORREFToGdiplusColor(COLORREF color, BYTE alpha /*= 255*/)
15 {
16     return Gdiplus::Color(alpha, GetRValue(color), GetGValue(color), GetBValue(color));
17 }
18 
GdiplusColorToCOLORREF(Gdiplus::Color color)19 COLORREF CGdiPlusTool::GdiplusColorToCOLORREF(Gdiplus::Color color)
20 {
21     return RGB(color.GetR(), color.GetG(), color.GetB());
22 }
23 
ToGDIPluseFontStyle(const FontStyle & style)24 int CGdiPlusTool::ToGDIPluseFontStyle(const FontStyle& style)
25 {
26     int value = 0;
27     if (style.bold)
28         value |= Gdiplus::FontStyle::FontStyleBold;
29     if (style.italic)
30         value |= Gdiplus::FontStyle::FontStyleItalic;
31     if (style.underline)
32         value |= Gdiplus::FontStyle::FontStyleUnderline;
33     if (style.strike_out)
34         value |= Gdiplus::FontStyle::FontStyleStrikeout;
35     return value;
36 }
37 
CreateRoundRectPath(Gdiplus::GraphicsPath & path,CRect rect,int r)38 void CGdiPlusTool::CreateRoundRectPath(Gdiplus::GraphicsPath& path, CRect rect, int r)
39 {
40     int L{ rect.left }, T{ rect.top }, R{ rect.right }, B{ rect.bottom }, d{ 2 * r };
41     path.AddArc(L, T, d, d, 180, 90);         // 左上角圆弧
42     path.AddLine(L + r, T, R - r, T);         // 上边
43 
44     path.AddArc(R - d, T, d, d, 270, 90);     // 右上角圆弧
45     path.AddLine(R, T + r, R, B - r);         // 右边
46 
47     path.AddArc(R - d, B - d, d, d, 0, 90);   // 右下角圆弧
48     path.AddLine(R - r, B, L + r, B);         // 下边
49 
50     path.AddArc(L, B - d, d, d, 90, 90);
51     path.AddLine(L, T + r, L, B - r);
52 
53 }
54 
GdiplusRectToCRect(Gdiplus::Rect rect)55 CRect CGdiPlusTool::GdiplusRectToCRect(Gdiplus::Rect rect)
56 {
57     return CRect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
58 }
59 
CRectToGdiplusRect(CRect rect)60 Gdiplus::Rect CGdiPlusTool::CRectToGdiplusRect(CRect rect)
61 {
62     return Gdiplus::Rect(rect.left, rect.top, rect.Width(), rect.Height());
63 }
64