/**
  * @brief  Run speed test
  * @param  None
  * @retval Pixels per second
  */
static int Run_SpeedTest(void) {
  int      TimeStart, i;
  U32      PixelsPerSecond;
  unsigned aColorIndex[8];
  int      xSize, ySize, vySize;
  GUI_RECT Rect, ClipRect;
  xSize  = LCD_GetXSize();
  ySize  = LCD_GetYSize();
  vySize = LCD_GetVYSize();
#if GUI_SUPPORT_CURSOR
  GUI_CURSOR_Hide();
#endif
  if (vySize > ySize) {
    ClipRect.x0 = 0;
    ClipRect.y0 = 0;
    ClipRect.x1 = xSize;
    ClipRect.y1 = ySize;
    GUI_SetClipRect(&ClipRect);
  }

  Stop_Test = 0;

  for (i = 0; i< 8; i++) {
    aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  }
  TimeStart = GUI_GetTime();
  for (i = 0; ((GUI_GetTime() - TimeStart) < 5000) &&( Stop_Test == 0); i++) {
    GUI_SetColorIndex(aColorIndex[i&7]);

    /* Calculate random positions */
    Rect.x0 = rand() % xSize - xSize / 2;
    Rect.y0 = rand() % ySize - ySize / 2;
    Rect.x1 = Rect.x0 + 20 + rand() % xSize;
    Rect.y1 = Rect.y0 + 20 + rand() % ySize;
    GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);

    /* Clip rectangle to visible area and add the number of pixels (for speed computation) */
    if (Rect.x1 >= xSize) {
      Rect.x1 = xSize - 1;
    }
    if (Rect.y1 >= ySize) {
      Rect.y1 = ySize - 1;
    }
    if (Rect.x0 < 0 ) {
      Rect.x0 = 0;
    }
    if (Rect.y1 < 0) {
      Rect.y1 = 0;
    }
    GUI_Exec();
    /* Allow short breaks so we do not use all available CPU time ... */
  }
  PixelsPerSecond = _GetPixelsPerSecond();
  GUI_SetClipRect(NULL);
  return PixelsPerSecond;
}
Esempio n. 2
0
/*********************************************************************
*
*       _DrawDiagramAt
*/
static void _DrawDiagramAt(GUI_MEMDEV_Handle hMem, int xPos, int yPos, int * py, int xBlend) {
  GUI_MEMDEV_Handle hMemOld;
  GUI_RECT          Rect;
  int               IndexBmBar;
  int               ySizeBar;
  int               i;

  hMemOld = GUI_MEMDEV_Select(hMem);
  //
  // Draw blue background
  //
  GUI_SetColor(0x4a2210);
  GUI_FillRoundedRect(xPos, yPos, xPos + GRAPH_WIDTH, yPos + GRAPH_HEIGHT, 4);
  //
  // Draw grid lines
  //
  GUI_SetColor(0x774830);
  for (i = 0; i < 12; i++) {
    GUI_DrawHLine(yPos + 6 + i * 10, xPos + 2, xPos + GRAPH_WIDTH - 2);
  }
  //
  // Draw bars
  //
  for (i = 0; i < 10; i++) {
    IndexBmBar = (i < 6) ? i / 2 : 4 - (i / 2);
    ySizeBar = *(py + i);
    GUI_DrawBitmapMag(_apBmBar[IndexBmBar], xPos + 8 + i * 16, yPos + GRAPH_HEIGHT - ySizeBar - 6, 1, ySizeBar);
  }
  //
  // Draw alpha effect
  //
  Rect.x0 = xPos;
  Rect.x1 = xPos + 3;
  Rect.y0 = yPos;
  Rect.y1 = yPos + GRAPH_HEIGHT;
  GUI_SetClipRect(&Rect);
  GUI_SetColor(0xd99100);
  GUI_SetAlpha(168);
  GUI_FillRoundedRect(xPos, yPos, xPos + GRAPH_WIDTH, yPos + GRAPH_HEIGHT, 4);
  GUI_SetClipRect(NULL);
  GUI_FillRect(xPos + 4, yPos + 1, xPos + xBlend, yPos + GRAPH_HEIGHT - 1);
  GUI_SetAlpha(0);
  //
  // Draw orange frame
  //
  GUI_SetColor(0x0094f3);
  GUI_DrawRoundedRect(xPos, yPos, xPos + GRAPH_WIDTH, yPos + GRAPH_HEIGHT, 4);
  //
  // Label
  //
  _DrawLabel(hMem, xPos, yPos);
  GUI_MEMDEV_CopyToLCD(hMem);
  GUI_MEMDEV_Select(hMemOld);
}
Esempio n. 3
0
void DIGITAL_preview(void)
{
  /* Disable clipping. Needed because digital init will draw to a larger number buffer */
  GUI_SetClipRect(NULL);
  
  DIGITAL_init();
  
  /* Set clipping to avoid emWin overwriting frame buffer control signals */
  GUI_SetClipRect(&clipRect); 

  /* Use time for last second. This makes sliding
   * animations look smoother */
  struct tm *time = getTimeMinusOne();

  drawWatchFace(time);
}
Esempio n. 4
0
/*********************************************************************
*
*       GUIDEMO_Speed
*/
void GUIDEMO_Speed(void) {
  GUI_RECT ClipRect;
  GUI_RECT Rect;
  unsigned aColorIndex[8];
  char     cText[40] = { 0 };
  U32      PixelsPerSecond;
  int      TimeStart;
  int      vySize;
  int      xSize;
  int      ySize;
  int      i;

  xSize  = LCD_GetXSize();
  ySize  = LCD_GetYSize();
  vySize = LCD_GetVYSize();
  if (vySize > ySize) {
    ClipRect.x0 = 0;
    ClipRect.y0 = 0;
    ClipRect.x1 = xSize;
    ClipRect.y1 = ySize;
    GUI_SetClipRect(&ClipRect);
  }
  GUIDEMO_ShowIntro("High speed", "Multi layer clipping\nHighly optimized drivers");
  GUIDEMO_HideControlWin();
  for (i = 0; i< 8; i++) {
    aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  }
  TimeStart = GUIDEMO_GetTime();
  for (i = 0; ((GUIDEMO_GetTime() - TimeStart) < 5000) && (GUIDEMO_CheckCancel() == 0); i++) {
    GUI_SetColorIndex(aColorIndex[i&7]);
    //
    // Calculate random positions
    //
    Rect.x0 = rand() % xSize - xSize / 2;
    Rect.y0 = rand() % ySize - ySize / 2;
    Rect.x1 = Rect.x0 + 20 + rand() % xSize;
    Rect.y1 = Rect.y0 + 20 + rand() % ySize;
    GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
    //
    // Clip rectangle to visible area and add the number of pixels (for speed computation)
    //
    if (Rect.x1 >= xSize) {
      Rect.x1 = xSize - 1;
    }
    if (Rect.y1 >= ySize) {
      Rect.y1 = ySize - 1;
    }
    if (Rect.x0 < 0 ) {
      Rect.x0 = 0;
    }
    if (Rect.y1 < 0) {
      Rect.y1 = 0;
    }
    GUI_Exec();
    //
    // Allow short breaks so we do not use all available CPU time ...
    //
  }
  GUIDEMO_NotifyStartNext();
  PixelsPerSecond = _GetPixelsPerSecond();
  GUI_SetClipRect(NULL);
  GUIDEMO_DrawBk();
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextMode(GUI_TM_TRANS);
  GUI_SetFont(&GUI_FontRounded22);
  GUI_DrawBitmap(&bmSeggerLogo70x35, 5, 5);
  GUIDEMO_AddStringToString(cText, "Pixels/sec: ");
  GUIDEMO_AddIntToString(cText, PixelsPerSecond);
  GUI_DispStringHCenterAt(cText, xSize / 2, (ySize - GUI_GetFontSizeY()) / 2);
  GUIDEMO_Delay(4000);
}
/*********************************************************************
*
*       _DrawJPEGs
*
* Function description
*   Draws the given JPEG image.
*/
static void _DrawJPEGs(const char * sFileName) {
  static int      i;
  const char      acError[] = "There is possibly not enough memory to display this JPEG image.\n\nPlease assign more memory to emWin in GUIConf.c.";
  GUI_JPEG_INFO   Info;
  GUI_RECT        Rect;
  HANDLE          hFile;
  DWORD           NumBytesRead;
  DWORD           FileSize;
  char          * pFile;
  int             xSize,  ySize;
  int             xPos,   yPos;
  int             r;

  xSize = LCD_GetXSize();
  ySize = LCD_GetYSize();
  //
  // Display file name.
  //
  Rect.x0 = BORDER_SIZE;
  Rect.y0 = TITLE_HEIGHT;
  Rect.x1 = xSize - BORDER_SIZE - 1;
  Rect.y1 = YPOS_IMAGE - 1;
  GUI_ClearRectEx(&Rect);
  GUI_SetTextMode(GUI_TM_NORMAL);
  GUI_SetFont(&GUI_Font8x16);
  GUI_DispStringInRectWrap(sFileName, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_CHAR);
  //
  // Clear the area in which the JPEG files are displayed.
  //
  Rect.x0 = BORDER_SIZE;
  Rect.y0 = YPOS_IMAGE;
  Rect.x1 = xSize - BORDER_SIZE - 1;
  Rect.y1 = ySize - BORDER_SIZE - 1;
  GUI_ClearRectEx(&Rect);
  //
  // Load image.
  //
  hFile    = CreateFile(sFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  FileSize = GetFileSize(hFile, NULL);
  pFile    = malloc(FileSize);
  ReadFile(hFile, pFile, FileSize, &NumBytesRead, NULL);
  CloseHandle(hFile);
  //
  // Check if the current JPEG image fits on the screen.
  //
  GUI_JPEG_GetInfo(pFile, FileSize, &Info);
  xSize -= BORDER_SIZE * 2 + 1;
  ySize -= YPOS_IMAGE + BORDER_SIZE + 1;
  //
  // Display the image centered.
  //
  xPos = BORDER_SIZE + (xSize - Info.XSize) / 2;
  yPos = YPOS_IMAGE  + (ySize - Info.YSize) / 2;
  GUI_SetClipRect(&Rect);
  r = GUI_JPEG_Draw(pFile, FileSize, xPos, yPos);
  GUI_SetClipRect(NULL);
  if (r) {
    //
    // The image could not be displayed successfully. Show an error message.
    //
    GUI_DispStringInRectWrap(acError, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  } else {
    GUI_Delay(2000);
    if ((Info.XSize > xSize) || (Info.YSize > ySize)) {
      //
      // Inform the user about the possibility of scaling JPEG images.
      //
      if (i == 0) {
        GUI_ClearRectEx(&Rect);
        GUI_DispStringInRectWrap("JPEG images can be scaled as it is shown in 2DGL_JPEG_DrawScaled.c.",  &Rect, GUI_TA_BOTTOM | GUI_TA_HCENTER, GUI_WRAPMODE_WORD);
        GUI_Delay(3000);
      }
      i++;
      if (i == NUM_IMAGES_UNTIL_HINT) {
        i = 0;
      }
    }
  }
  free(pFile);
}
Esempio n. 6
0
/*********************************************************************
*
*       _DrawSample
*/
static void _DrawSample(GUI_RECT Rect, const GUI_FONT * pFont, const char * pText) {
  GUI_RECT CurrentRect;
  int      yDistDiv3;

  Rect.x0 += BORDER;
  Rect.y0 += BORDER;
  Rect.x1 -= BORDER;
  Rect.y1 -= BORDER;
  yDistDiv3      = (Rect.y1 - Rect.y0) / 3;
  CurrentRect.x0 = Rect.x0;
  CurrentRect.y0 = Rect.y0;
  CurrentRect.x1 = Rect.x0 + 59;
  CurrentRect.y1 = Rect.y0 + 3 * yDistDiv3;
  GUI_SetClipRect(&CurrentRect);
  //
  // Display info text
  //
  GUI_SetFont(GUI_FONT_13_ASCII);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringInRectWrap(pText, &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  //
  // Alpha circles
  //
  GUI_MoveRect(&CurrentRect, 63, 0);
  GUI_SetBkColor(GUI_BLACK);
  GUI_Clear();
  _DrawAlphaCircles((CurrentRect.x0 + CurrentRect.x1) / 2, (CurrentRect.y0 + CurrentRect.y1) / 2, 35, 0, 4);
  GUI_SetColor(GUI_WHITE);
  GUI_SetFont(pFont);
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  //
  // Black to white gradient
  //
  CurrentRect.y0 = Rect.y0;
  CurrentRect.y1 = Rect.y0 + 3 * yDistDiv3;
  GUI_MoveRect(&CurrentRect, 63, 0);
  GUI_DrawGradientH(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_BLACK, GUI_WHITE);
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_SetColor(GUI_RED);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_SetColor(GUI_GREEN);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_SetColor(GUI_BLUE);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  //
  // RGB
  //
  CurrentRect.y0 = Rect.y0;
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_MoveRect(&CurrentRect, 63, 0);
  GUI_SetBkColor(GUI_RED);
  GUI_Clear();
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_SetBkColor(GUI_GREEN);
  GUI_Clear();
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_SetBkColor(GUI_BLUE);
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);
  CurrentRect.y0 = Rect.y0;
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  //
  // RGB gradients
  //
  CurrentRect.y0 = Rect.y0;
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_MoveRect(&CurrentRect, 63, 0);
  GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_RED,   GUI_BLACK);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_GREEN, GUI_BLACK);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_BLUE,  GUI_BLACK);
  CurrentRect.y0 = Rect.y0;
  CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  //
  // Disable application defined clip rectangle
  //
  GUI_SetClipRect(NULL);
}
/*********************************************************************
*
*       _DrawSample
*/
static void _DrawSample(GUI_RECT * pRect, int yd) {
  GUI_RECT Rect;

  Rect = *pRect;
  //
  // Use application defined clip rectangle
  //
  GUI_SetClipRect(&Rect);
  //
  // Move clip rectangle
  //
  GUI_MoveRect(&Rect, 65, 0);
  //
  // Draw sample
  //
  _DrawAlphaCircles((Rect.x0 + Rect.x1) >> 1, (Rect.y0 + Rect.y1) >> 1, 35,   0, 4);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringInRectWrap("ABC\nABC\nABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  //
  // Move clip rectangle
  //
  GUI_MoveRect(&Rect, 65, 0);

  GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_WHITE);
  Rect.y1 = Rect.y0 + yd;
  GUI_SetColor(GUI_RED);
  GUI_DispStringInRect("ABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&Rect, 0, yd);
  GUI_SetColor(GUI_GREEN);
  GUI_DispStringInRect("ABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&Rect, 0, yd);
  GUI_SetColor(GUI_BLUE);
  GUI_DispStringInRect("ABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  GUI_MoveRect(&Rect, 0, -yd * 2);
  Rect.y1 = Rect.y0 + yd * 3;
  //
  // Move clip rectangle
  //
  GUI_MoveRect(&Rect, 65, 0);
  //
  // Draw sample
  //
  Rect.y1 = Rect.y0 + yd;
  GUI_SetBkColor(GUI_RED);
  GUI_Clear();
  GUI_MoveRect(&Rect, 0, yd);
  GUI_SetBkColor(GUI_GREEN);
  GUI_Clear();
  GUI_MoveRect(&Rect, 0, yd);
  GUI_SetBkColor(GUI_BLUE);
  GUI_Clear();
  GUI_MoveRect(&Rect, 0, -yd * 2);
  Rect.y1 = Rect.y0 + yd * 3;
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringInRectWrap("ABC\nABC\nABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  //
  // Move clip rectangle
  //
  GUI_MoveRect(&Rect, 65, 0);
  //
  // Draw sample
  //
  Rect.y1 = Rect.y0 + yd;
  GUI_DrawGradientV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_RED,   GUI_BLACK);
  GUI_MoveRect(&Rect, 0, yd);
  GUI_DrawGradientV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_GREEN, GUI_BLACK);
  GUI_MoveRect(&Rect, 0, yd);
  GUI_DrawGradientV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLUE,  GUI_BLACK);
  GUI_MoveRect(&Rect, 0, -yd * 2);
  Rect.y1 = Rect.y0 + yd * 3;
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringInRectWrap("ABC\nABC\nABC", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  //
  // Disable application defined clip rectangle
  //
  GUI_SetClipRect(NULL);
}
/*********************************************************************
*
*       GUI_DispStringInRectWrap
*/
void GUI_DispStringInRectWrap(const char GUI_UNI_PTR * s, GUI_RECT * pRect, int TextAlign, GUI_WRAPMODE WrapMode) {
  const GUI_RECT * pOldClipRect;
  GUI_RECT Rect;
  int xSize, ySizeFont, NumBytesToNextLine, NumCharsDisp;
  if (!s) {
    return;
  }
  GUI_LOCK();
  Rect      = *pRect;
  xSize     = Rect.x1 - Rect.x0 + 1;
  ySizeFont = GUI_GetFontDistY();
  /* Vertical alignment */
  if ((TextAlign & GUI_TA_VERTICAL) != GUI_TA_TOP) {
    int NumLines = 0;
    const char GUI_UNI_PTR * pText;
    pText = s;
    /* Count the number of lines */
    do {
      NumBytesToNextLine = GUI__WrapGetNumBytesToNextLine(pText, xSize, WrapMode);
      pText += NumBytesToNextLine;
      if (NumBytesToNextLine) {
        NumLines++;
      }
    } while (NumBytesToNextLine);
    /* Do the vertical alignment */
    switch (TextAlign & GUI_TA_VERTICAL) {
	  case GUI_TA_BASELINE:
	  case GUI_TA_BOTTOM:
      Rect.y0 = Rect.y1 - NumLines * ySizeFont + 1;
      break;
	  case GUI_TA_VCENTER:
		  Rect.y0 = Rect.y0 + (Rect.y1 - Rect.y0 + 1 - NumLines * ySizeFont) / 2;
      break;
	  }
  }
  pOldClipRect = GUI_SetClipRect(pRect);
  do {
    int xLineSize;
    GUI_RECT RectText;
    NumCharsDisp = GUI__WrapGetNumCharsDisp(s, xSize, WrapMode);
    Rect.y1      = Rect.y0 + ySizeFont - 1;
    RectText     = Rect;
    /* Horizontal alignment */
    xLineSize = GUI__GetLineDistX(s, NumCharsDisp);
    switch (TextAlign & GUI_TA_HORIZONTAL) {
    case GUI_TA_HCENTER:
      RectText.x0 = pRect->x0 + (pRect->x1 - pRect->x0 - xLineSize) / 2;
      break;
    case GUI_TA_LEFT:
      RectText.x0 = pRect->x0;
      break;
    case GUI_TA_RIGHT:
      RectText.x0 = pRect->x1 - xLineSize + 1;
      break;
    }
    GUI__DispLine(s, NumCharsDisp, &RectText);
    s += GUI__WrapGetNumBytesToNextLine(s, xSize, WrapMode);
    Rect.y0 += ySizeFont;
  } while (*s);
  GUI_SetClipRect(pOldClipRect);
  GUI_UNLOCK();
}