PROGBAR - Custom (Sample)
PROGBAR_Custom.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | PROGBAR_Custom.c |
This sample demonstrates custom drawing of a PROGBAR widget.
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : PROGBAR_Custom.c
Purpose : Sample that demonstrates how to give a PROGBAR widget
a custom appearance.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbProgbar
*/
static void _cbProgbar(WM_MESSAGE * pMsg) {
GUI_RECT Rect;
float ValueF;
int Value;
char acBuffer[16];
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
//
// Draw progress bar
//
WM_GetClientRect(&Rect);
GUI_SetColor(GUI_BLACK);
GUI_AA_DrawRoundedRectEx(&Rect, 3);
Value = PROGBAR_GetValue(pMsg->hWin);
ValueF = Value / 100.0F;
sprintf(acBuffer, "Progress: %d%%", Value);
Rect.x0 += 2;
Rect.y0 += 2;
Rect.x1 -= 2;
Rect.y1 -= 2;
Rect.x1 = Rect.x1 * (ValueF);
GUI_SetColor(GUI_GRAY_9A);
GUI_AA_FillRoundedRectEx(&Rect, 1);
WM_GetClientRect(&Rect);
Rect.x0 += 2;
Rect.y0 += 2;
Rect.x1 -= 2;
Rect.y1 -= 2;
GUI_SetColor(GUI_BLACK);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetFont(&GUI_Font16B_1);
GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
break;
default:
PROGBAR_Callback(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
PROGBAR_Handle hProg;
int Cnt;
//
// Init GUI, clear background and enable multi-buffering
//
GUI_Init();
WM_MULTIBUF_Enable(1);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
Cnt = 0;
//
// Create PROGBAR handle
//
hProg = PROGBAR_CreateEx(10, 10, 200, 30, WM_HBKWIN, WM_CF_SHOW, PROGBAR_CF_HORIZONTAL, GUI_ID_PROGBAR0);
//
// Set custom callback routine
//
WM_SetCallback(hProg, _cbProgbar);
//
// Continuously fill progress bar
//
while (1) {
//
// Fill the progress bar
//
if (Cnt == 100) {
Cnt = 0;
}
if (Cnt < 100) {
Cnt++;
}
PROGBAR_SetValue(hProg, Cnt);
//
// Make sure the entire PROGBAR gets redrawn
//
WM_InvalidateWindow(hProg);
GUI_Delay(100);
}
}
/*************************** End of file ****************************/