Memory Device - Fading (Sample)
GUI_MEMDEV_Fading.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | GUI_MEMDEV_Fading.c |
This sample demonstrates how a fading animation between two windows can be executed using memory devices.
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 : GUI_MEMDEV_Fading.c
Purpose : Sample that demonstrates how a fading animation between
two windows can be executed using memory devices.
Requirements: WindowManager - (x)
MemoryDevices - (x)
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define LCD_X LCD_GetXSize()
#define LCD_Y LCD_GetYSize()
#define ANIM_PERIOD 1000
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
GUI_RECT Rect;
int StrLength;
static GUI_MEMDEV_Handle hMem1;
static GUI_MEMDEV_Handle hMem2;
static int Device;
static WM_HTIMER hTimer;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Create memory devices
// A fixed color depth with 32bpp is necessary for animations
// Two fading memory devices have to be at the same position on the screen
//
hMem1 = GUI_MEMDEV_CreateFixed32(0, 0, LCD_X, LCD_Y);
hMem2 = GUI_MEMDEV_CreateFixed32(0, 0, LCD_X, LCD_Y);
//
// Select first memory device
//
GUI_MEMDEV_Select(hMem1);
//
// Execute drawing operations
//
WM_GetClientRect(&Rect);
GUI_SetColor(GUI_RED);
GUI_FillRectEx(&Rect);
GUI_SetFont(GUI_FONT_20_1);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetColor(GUI_BLACK);
StrLength = GUI_GetStringDistX("Memory Device 1");
GUI_DispStringAt("Memory Device 1", LCD_X / 2 - StrLength / 2, LCD_Y / 2 - GUI_GetFontDistY() / 2);
//
// Select second memory device
//
GUI_MEMDEV_Select(hMem2);
//
// Execute drawing operations
//
GUI_SetColor(GUI_BLUE);
GUI_FillRectEx(&Rect);
GUI_SetColor(GUI_BLACK);
GUI_DispStringAt("Memory Device 2", LCD_X / 2 - StrLength / 2, LCD_Y / 2 - GUI_GetFontDistY() / 2);
//
// Clear selection of memory device
//
GUI_MEMDEV_Select(0);
hTimer = WM_CreateTimer(pMsg->hWin, 0, ANIM_PERIOD * 2, 0);
break;
case WM_PAINT:
//
// Perform fade-in operation
//
if (Device) {
GUI_MEMDEV_FadeInDevices(hMem1, hMem2, ANIM_PERIOD);
} else {
GUI_MEMDEV_FadeInDevices(hMem2, hMem1, ANIM_PERIOD);
}
break;
case WM_TIMER:
Device ^= 1;
WM_RestartTimer(hTimer, ANIM_PERIOD * 2);
WM_InvalidateWindow(pMsg->hWin);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
GUI_Init();
//
// Create window
//
WM_CreateWindow(0, 0, LCD_X, LCD_Y, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/