Custom widget callback (Sample)
WIDGET_CustomCallback.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | WIDGET_CustomCallback.c |
This sample demonstrates how a custom callback can be set for a widget. This is shown by setting a callback to a BUTTON widget and overriding its WM_PAINT case.
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 : WIDGET_CustomCallback.c
Purpose : This sample shows how to give widgets a custom look
by overwriting the callback routine.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define BUTTON_SIZE 50
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbButton
*/
static void _cbButton(WM_MESSAGE * pMsg) {
static GUI_RECT Rect;
switch (pMsg->MsgId) {
case WM_PAINT:
//
// Draw button
//
if (BUTTON_IsPressed(pMsg->hWin)) {
GUI_SetColor(GUI_LIGHTRED);
}
else {
GUI_SetColor(GUI_GRAY_C8);
}
GUI_FillCircle(BUTTON_SIZE / 2, BUTTON_SIZE / 2, BUTTON_SIZE / 2 - 1);
GUI_SetColor(GUI_BLACK);
GUI_SetPenSize(2);
GUI_AA_DrawCircle(BUTTON_SIZE / 2, BUTTON_SIZE / 2, BUTTON_SIZE / 2 - 1);
GUI_SetPenSize(5);
GUI_AA_DrawLine(16, 16, 33, 33);
GUI_AA_DrawLine(33, 16, 16, 33);
break;
default:
BUTTON_Callback(pMsg);
break;
}
}
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
WM_HWIN hButton;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Create a button
//
hButton = BUTTON_Create(10, 10, BUTTON_SIZE, BUTTON_SIZE, GUI_ID_BUTTON0, WM_CF_SHOW);
//
// Set callback routine
//
WM_SetCallback(hButton, _cbButton);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init emWin.
//
GUI_Init();
//
// Create parent window.
//
WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/