@@ -307,30 +307,30 @@ void GetRoundRectPath(Gdiplus::GraphicsPath *pPath, Gdiplus::Rect r, int dia) {
307307LRESULT CALLBACK OptionsDialog::ButtonProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
308308 using namespace Gdiplus ;
309309 struct PaintData {
310- GdiPlusImageLoader Logo;
311310 std::wstring Text;
312311 Font Font;
313- Pen BorderPen;
314- ARGB Gradient[2 ];
315312 SolidBrush TextColor;
316- Pen LinePen;
317313 int LogoOffset;
318314 int Margin;
319315 int Height;
320316 };
321317
322- static PaintData connect { { IDB_WHITELOGO, L" PNG" }, {}, { L" Tahoma" , 10 , FontStyleBold }, 0xffd05300 , { 0xffdc4a33 , 0xffcd4127 }, 0xffffffff , 0xffc83f27 , 39 , 66 , 35 };
323- static PaintData disconnect { { IDB_ORANGELOGO, L" PNG" }, {}, { L" Tahoma" , 10 }, 0xffbfbfbf , { 0xffffffff , 0xfff1f1f1 }, 0xff333333 , 0xffe4e4e4 , 33 , 56 , 27 };
318+ static PrivateFontCollection pfc;
319+
320+ static PaintData connect { {}, { L" Roboto Medium" , 14 , FontStyleBold, UnitPixel, &pfc }, 0x8a000000 , 33 , 72 , 46 };
321+ static PaintData disconnect { {}, { L" Roboto Medium" , 14 , FontStyleBold, UnitPixel, &pfc }, 0x8a000000 , 33 , 72 , 46 };
322+
323+ static GdiPlusImageLoader BtnBackground { IDB_GOOGLEBTN, L" PNG" };
324324
325325 static PaintData *currentBtn = nullptr ;
326326 static OptionsDialog *dialog = nullptr ;
327327 static bool mouseOver = false ;
328328 static bool customFocus = false ;
329329 static bool connected = false ;
330330
331- static Rect r;
331+ static Rect r, outer ;
332332 static RectF layoutRect;
333- static SolidBrush focusBrush (0x11000000 );
333+ static SolidBrush focusBrush (0x0A000000 );
334334 static Gdiplus::GraphicsPath borderPath;
335335 static Gdiplus::StringFormat format;
336336
@@ -339,6 +339,13 @@ LRESULT CALLBACK OptionsDialog::ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam,
339339 dialog = (OptionsDialog *)dwRefData;
340340 format.SetAlignment (StringAlignmentCenter);
341341 format.SetLineAlignment (StringAlignmentCenter);
342+ if (HRSRC hResource = ::FindResource (g_hInst, MAKEINTRESOURCE (IDB_GOOGLEFONT), L" TTF" )) {
343+ if (DWORD dataSize = ::SizeofResource (g_hInst, hResource)) {
344+ if (void *pResourceData = ::LockResource (::LoadResource (g_hInst, hResource))) {
345+ pfc.AddMemoryFont (pResourceData, dataSize);
346+ }
347+ }
348+ }
342349 } break ;
343350 case WM_MOUSELEAVE: mouseOver = false ; break ;
344351 case WM_MOUSEMOVE: mouseOver = true ; break ;
@@ -362,35 +369,42 @@ LRESULT CALLBACK OptionsDialog::ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam,
362369 currentBtn = &connect;
363370 }
364371 Gdiplus::Graphics (hWnd).MeasureString (currentBtn->Text .c_str (), currentBtn->Text .size (), ¤tBtn->Font , PointF (0 , 0 ), &textRect);
365- r.Width = textRect.Width + currentBtn->Margin ;
366- r.Height = currentBtn->Height ;
372+ outer.Width = textRect.Width + currentBtn->Margin ;
373+ outer.Height = currentBtn->Height ;
374+ r.X = 3 ;
375+ r.Y = 3 ;
376+ r.Width = outer.Width - 6 ;
377+ r.Height = outer.Height - 6 ;
367378 if (connected) {
368- SetWindowPos (hWnd, NULL , rc.right - r .Width - 10 , rc.bottom - r .Height - 10 , r .Width , r .Height , SWP_NOZORDER);
379+ SetWindowPos (hWnd, NULL , rc.right - outer .Width - 10 , rc.bottom - outer .Height - 10 , outer .Width , outer .Height , SWP_NOZORDER);
369380 } else {
370- SetWindowPos (hWnd, NULL , rc.left + ((rc.right - rc.left ) - r .Width ) / 2 , rc.top + ((rc.bottom - rc.top ) - r .Height ) / 2 , r .Width , r .Height , SWP_NOZORDER);
381+ SetWindowPos (hWnd, NULL , rc.left + ((rc.right - rc.left ) - outer .Width ) / 2 , rc.top + ((rc.bottom - rc.top ) - outer .Height ) / 2 , outer .Width , outer .Height , SWP_NOZORDER);
371382 }
372383
373- GetRoundRectPath (&borderPath, r, 4 );
374- layoutRect = RectF (currentBtn-> LogoOffset , 0 , r. Width - currentBtn-> LogoOffset , r. Height );
384+ layoutRect = RectF (currentBtn-> LogoOffset , 3 , r. Width - currentBtn-> LogoOffset , r. Height );
385+ GetRoundRectPath (&borderPath, r, 6 );
375386 } break ;
376387 case WM_PAINT: {
377388 PAINTSTRUCT ps;
378389 HDC hdc = BeginPaint (hWnd, &ps);
379390 Gdiplus::Graphics g (hdc);
391+ g.Clear (0xfff0f0f0 );
392+
393+ g.DrawImage (BtnBackground, Gdiplus::RectF (0 , 0 , 54 , outer.Height ), 0 , 0 , 108 , 92 , Gdiplus::UnitPixel); // left side
394+ g.DrawImage (BtnBackground, Gdiplus::RectF (54 , 0 , outer.Width - 54 - 8 , outer.Height ), 108 , 0 , 5 , 92 , Gdiplus::UnitPixel); // middle stretch
395+ g.DrawImage (BtnBackground, Gdiplus::RectF (outer.Width - 8 , 0 , 8 , outer.Height ), 108 , 0 , 16 , 92 , Gdiplus::UnitPixel); // right side
380396
381- LinearGradientBrush linGrBrush (Point (0 , 0 ), Point (0 , r.Height ), currentBtn->Gradient [mouseOver ? 1 : 0 ], currentBtn->Gradient [mouseOver ? 0 : 1 ]);
382- g.FillPath (&linGrBrush, &borderPath);
383- if (customFocus)
397+ if (customFocus || mouseOver)
384398 g.FillPath (&focusBrush, &borderPath);
385399
386- g.DrawImage (currentBtn->Logo , 10 , 7 , currentBtn->Logo ->GetWidth (), currentBtn->Logo ->GetHeight ());
387- g.DrawLine (¤tBtn->LinePen , currentBtn->LogoOffset , 0 , currentBtn->LogoOffset , r.Height );
400+ g.SetTextRenderingHint (TextRenderingHintAntiAlias);
388401 g.DrawString (currentBtn->Text .c_str (), currentBtn->Text .size (), ¤tBtn->Font , layoutRect, &format, ¤tBtn->TextColor );
389- g.DrawPath (¤tBtn->BorderPen , &borderPath);
390402
391403 EndPaint (hWnd, &ps);
392404 return TRUE ;
393405 }
406+ case WM_ERASEBKGND:
407+ return TRUE ;
394408 case WM_SETCURSOR:
395409 SetCursor (LoadCursor (NULL , IDC_HAND));
396410 return TRUE ;
0 commit comments