/*********************************************************************
*
*       _OnPaint
*
* Purpose: Paints the owner drawn button
*/
static void _OnPaint(BUTTON_Handle hObj) {
  int Index;
  char ac[50];
  GUI_RECT Rect;
  Index = (WIDGET_GetState(hObj) & BUTTON_STATE_PRESSED) ? 1 : 0;
  WM_GetClientRect(&Rect);
  //
  // Draw filled ellipse with button background color
  //
  GUI_SetColor(BUTTON_GetBkColor(hObj, Index));
  GUI_FillEllipse(Rect.x1 / 2, Rect.y1 / 2, Rect.x1 / 2, Rect.y1 / 2);
  //
  // Draw black shape
  //
  GUI_SetColor(GUI_BLACK);
  GUI_DrawEllipse(Rect.x1 / 2, Rect.y1 / 2, Rect.x1 / 2, Rect.y1 / 2);
  //
  // Draw button text with widget attributes
  //
  GUI_SetColor(BUTTON_GetTextColor(hObj, Index));
  GUI_SetBkColor(BUTTON_GetBkColor(hObj, Index));
  GUI_SetFont(BUTTON_GetFont(hObj));
  BUTTON_GetText(hObj, ac, sizeof(ac));
  if (_Pressed) {
    strcpy(ac + strlen(ac), "\npressed");
  }
  GUI_DispStringInRect(ac, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
}
/*******************************************************************
*
*       _DrawEye
*/
static void _DrawEye(int xPos0, int yPos0, int xPos1, int yPos1, int rx, int ry) {
  int Hyp;
  int dx;
  int dy;
  int x;
  int y;

  GUI_SetColor(GUI_WHITE);
  GUI_FillEllipse(xPos0, yPos0, rx, ry);
  GUI_SetColor(GUI_BLACK);
  GUI_DrawEllipse(xPos0, yPos0, rx, ry);
  //
  // Calculate the coordinates
  //
  dx  = xPos1 - xPos0 + 1;
  dy  = yPos1 - yPos0 + 1;
  Hyp = GUI__sqrt32(dx * dx + dy * dy);
  x   = (dx * _Min(rx - 5, abs(dx)) * FACTOR / Hyp) + xPos0 * FACTOR;
  y   = (dy * _Min(ry - 5, abs(dy)) * FACTOR / Hyp) + yPos0 * FACTOR;
  //
  // Draw the pupil
  //
  GUI_AA_SetFactor(FACTOR);
  GUI_AA_EnableHiRes();
  GUI_SetColor(0xD00000);
  GUI_AA_FillCircle(x, y, (int)(5.75 * FACTOR));
  GUI_SetColor(GUI_BLACK);
  GUI_AA_FillCircle(x, y, (int)(3.75 * FACTOR));
  GUI_SetColor(GUI_GRAY);
  GUI_AA_FillCircle(x - (int)(1.25 * FACTOR), y - (int)(1.25 * FACTOR), (int)(1.25 * FACTOR));
  GUI_AA_DisableHiRes();
}