SLIDER - Usage (Sample)
SLIDER_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | SLIDER_Usage.c |
This sample demonstrates the usage of a SLIDER 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 : SLIDER_Usage.c
Purpose : Sample that demonstrates the usage of a SLIDER widget
in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
static void _cbWin(WM_MESSAGE * pMsg) {
static WM_HWIN hSlider;
int NCode, Id;
int Value;
char acBuffer[32];
switch(pMsg->MsgId) {
case WM_CREATE:
//
// Create horizonzal slider. A vertical slider can be created with SLIDER_CF_VERTICAL instead.
//
hSlider = SLIDER_CreateEx(10, 10, 150, 30, pMsg->hWin, WM_CF_SHOW, SLIDER_CF_HORIZONTAL, GUI_ID_SLIDER0);
//
// Set range of slider
//
SLIDER_SetRange(hSlider, 0, 100);
//
// Set number of tick marks
//
SLIDER_SetNumTicks(hSlider, 10);
//
// Set value of slider
//
SLIDER_SetValue(hSlider, 20);
//
// Set width of thumb
//
SLIDER_SetWidth(hSlider, 20);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetFont(&GUI_Font13B_1);
GUI_SetColor(GUI_BLACK);
//
// Display slider value
//
Value = SLIDER_GetValue(hSlider);
sprintf(acBuffer, "Value: %d", Value);
GUI_DispStringAt(acBuffer, 10, 50);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case GUI_ID_SLIDER0:
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
//
// Redraw the window when a value has changed so the displayed value will be updated.
//
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init emWin.
//
GUI_Init();
WM_MULTIBUF_Enable(1);
//
// Create parent window.
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/