Skinning properties (Sample)
WIDGET_SkinningProps.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | WIDGET_SkinningProps.c |
This sample demonstrates how the appearance of widgets can be customized using skinning properties.
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_SkinningProps.c
Purpose : This sample shows how to give widgets a custom look
by setting the skinning properties.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
#include <string.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define BUTTON_SIZE 50
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _PropsEnabled: Properties for enabled state of button
*/
static BUTTON_SKINFLEX_PROPS _PropsEnabled = {
{ GUI_MAKE_COLOR(0xFF431422), GUI_MAKE_COLOR(0xFFF4D3CC), GUI_MAKE_COLOR(0xFFDF9587) }, // [0] Outer color of surrounding frame, [1] Inner color of surrounding frame, [2] Color of area between frame and inner area
{ GUI_MAKE_COLOR(0xFFE9A99C), GUI_MAKE_COLOR(0xFFDF9587) }, // [0] First (upper) color of upper gradient, [1] Second (lower) color of upper gradient
{ GUI_MAKE_COLOR(0xFFD37E6F), GUI_MAKE_COLOR(0xFFDF9587) }, // [0] First (upper) color of lower gradient, [1] Second(lower) color of lower gradient
5 // Radius of rounded corner
};
/*********************************************************************
*
* _PropsPressed: Properties for pressed state of button
*/
static BUTTON_SKINFLEX_PROPS _PropsPressed = {
{ GUI_RED, GUI_MAKE_COLOR(0xFF9EB0BA), GUI_MAKE_COLOR(0xFF98D1EF) }, // [0] Outer color of surrounding frame, [1] Inner color of surrounding frame, [2] Color of area between frame and inner area
{ GUI_MAKE_COLOR(0xFFE5F4FC), GUI_MAKE_COLOR(0xFFC4E5F6) }, // [0] First (upper) color of upper gradient, [1] Second (lower) color of upper gradient
{ GUI_MAKE_COLOR(0xFF98D1EF), GUI_MAKE_COLOR(0xFF68B3DB) }, // [0] First (upper) color of lower gradient, [1] Second(lower) color of lower gradient
5 // Radius of rounded corner
};
/*********************************************************************
*
* _PropsFocussed: Properties for focussed state of button
*/
static BUTTON_SKINFLEX_PROPS _PropsFocussed = {
{ GUI_YELLOW, GUI_MAKE_COLOR(0xFF46D8FB), GUI_MAKE_COLOR(0xFFDFDFDF) }, // [0] Outer color of surrounding frame, [1] Inner color of surrounding frame, [2] Color of area between frame and inner area
{ GUI_MAKE_COLOR(0xFFF3F3F3), GUI_MAKE_COLOR(0xFFECECEC) }, // [0] First (upper) color of upper gradient, [1] Second (lower) color of upper gradient
{ GUI_MAKE_COLOR(0xFFDFDFDF), GUI_MAKE_COLOR(0xFFD0D0D0) }, // [0] First (upper) color of lower gradient, [1] Second(lower) color of lower gradient
5 // Radius of rounded corner
};
/*********************************************************************
*
* _PropsDisabled: Properties for disabled state of button
*/
static BUTTON_SKINFLEX_PROPS _PropsDisabled = {
{ GUI_MAKE_COLOR(0xFFADB2B5), GUI_MAKE_COLOR(0xFFFCFCFC), GUI_MAKE_COLOR(0xFFF4F4F4) }, // [0] Outer color of surrounding frame, [1] Inner color of surrounding frame, [2] Color of area between frame and inner area
{ GUI_MAKE_COLOR(0xFFF4F4F4), GUI_MAKE_COLOR(0xFFF4F4F4) }, // [0] First (upper) color of upper gradient, [1] Second (lower) color of upper gradient
{ GUI_MAKE_COLOR(0xFFF4F4F4), GUI_MAKE_COLOR(0xFFF4F4F4) }, // [0] First (upper) color of lower gradient, [1] Second(lower) color of lower gradient
5 // Radius of rounded corner
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
static WM_HWIN hButton;
char acBuffer[32];
int NCode, Id;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Set BUTTON_SKINFLEX_PROPS for different states
// (Not all states have to be set.)
//
BUTTON_SetSkinFlexProps(&_PropsEnabled, BUTTON_SKINFLEX_PI_ENABLED);
BUTTON_SetSkinFlexProps(&_PropsDisabled, BUTTON_SKINFLEX_PI_DISABLED);
BUTTON_SetSkinFlexProps(&_PropsFocussed, BUTTON_SKINFLEX_PI_FOCUSSED);
BUTTON_SetSkinFlexProps(&_PropsPressed, BUTTON_SKINFLEX_PI_PRESSED);
//
// Create sample button.
//
hButton = BUTTON_CreateEx(10, 10, BUTTON_SIZE, BUTTON_SIZE, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
//
// Display state of the button.
//
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font16B_1);
sprintf(acBuffer, "BUTTON state: ");
if (WM_IsEnabled(hButton) == 0) {
strcat(acBuffer, "disabled.");
} else if (BUTTON_IsPressed(hButton)) {
strcat(acBuffer, "pressed.");
} else if(WM_HasFocus(hButton)) {
strcat(acBuffer, "focussed.");
} else {
strcat(acBuffer, "enabled.");
}
GUI_DispStringAt(acBuffer, 10, 70);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case GUI_ID_BUTTON0:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
case WM_NOTIFICATION_RELEASED:
//
// We're going to redraw the parent window when the button was interacted with to update the display of the state.
//
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
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 ****************************/