Advertisement
keybode

source engine DrawCircle & DrawRoundedRect

Jan 27th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. void DrawCircle(int x0, int y0, int radius, Engine::Color color)
  2. {
  3.     int x = radius;
  4.     int y = 0;
  5.     int xChange = 1 - (radius << 1);
  6.     int yChange = 0;
  7.     int radiusError = 0;
  8.  
  9.     while (x >= y)
  10.     {
  11.         for (int i = x0 - x; i <= x0 + x; i++)
  12.         {
  13.             Engine::m_pRenderer->DrawRect ( i, y0 + y, 1, 1, color );
  14.             Engine::m_pRenderer->DrawRect ( i, y0 - y, 1, 1, color );
  15.         }
  16.         for (int i = x0 - y; i <= x0 + y; i++)
  17.         {
  18.             Engine::m_pRenderer->DrawRect ( i, y0 + x, 1, 1, color );
  19.             Engine::m_pRenderer->DrawRect ( i, y0 - x, 1, 1, color );
  20.         }
  21.  
  22.         y++;
  23.         radiusError += yChange;
  24.         yChange += 2;
  25.         if (((radiusError << 1) + xChange) > 0)
  26.         {
  27.             x--;
  28.             radiusError += xChange;
  29.             xChange += 2;
  30.         }
  31.     }
  32. }
  33.  
  34. void DrawRoundedRect ( int x, int y, int w, int h, int smooth, Engine::Color color )
  35. {
  36.     Engine::m_pRenderer->DrawRect ( x + smooth, y, w - smooth * 2, h, color );
  37.     Engine::m_pRenderer->DrawRect ( x, y + smooth, w, h - smooth * 2, color );
  38.  
  39.     DrawCircle ( x + smooth, y + smooth, smooth, color ); // left top
  40.     DrawCircle ( x + w - smooth, y + smooth, smooth - 1, color ); // right top
  41.     DrawCircle ( x + smooth, y + h - smooth, smooth - 1, color ); // left bottom
  42.     DrawCircle ( x + w - smooth, y + h - smooth, smooth - 1, color ); // right bottom
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement