Difference between revisions of "Skinning routine (Sample)"
(Created page with "{| class="wikitable" style="float:right; margin-left: 10px; background-color: #f9f9f9;" ! colspan="2" style="font-weight:bold; font-size:17px; font-family:Arial, Helvetica, sa...") |
|||
Line 20: | Line 20: | ||
This sample demonstrates how the appearance of a widget can be customized with a skinning routine. A skinning routine is similar to OwnerDraw routines, in that it also receives different draw commands that are processed by the routine. |
This sample demonstrates how the appearance of a widget can be customized with a skinning routine. A skinning routine is similar to OwnerDraw routines, in that it also receives different draw commands that are processed by the routine. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/WIDGET_SkinningRoutine/WIDGET_SkinningRoutine.html" width="480" height="272" style="border: 1px #c0c0c0 solid;" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="no"> </iframe></html> |
||
== Code == |
== Code == |
Latest revision as of 16:38, 7 March 2022
WIDGET_SkinningRoutine.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | WIDGET_SkinningRoutine.c |
This sample demonstrates how the appearance of a widget can be customized with a skinning routine. A skinning routine is similar to OwnerDraw routines, in that it also receives different draw commands that are processed by the routine.
Demo
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_SkinningRoutine.c
Purpose : This sample shows how to give widgets a custom look
using a skinning routine.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define BUTTON_SIZE 50
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbButtonSkin
*/
static int _cbButtonSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
GUI_RECT Rect;
char acBuffer[32];
//
// Get size of button
//
Rect.x0 = pDrawItemInfo->x0;
Rect.y0 = pDrawItemInfo->y0;
Rect.x1 = pDrawItemInfo->x1;
Rect.y1 = pDrawItemInfo->y1;
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_DRAW_TEXT:
//
// Draw text of button
//
GUI_SetFont(&GUI_Font13_1);
GUI_SetTextMode(GUI_TM_TRANS);
if (BUTTON_IsPressed(pDrawItemInfo->hWin)) {
GUI_SetColor(GUI_RED);
} else {
GUI_SetColor(GUI_BLUE);
}
BUTTON_GetText(pDrawItemInfo->hWin, acBuffer, sizeof(acBuffer));
GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
return 0;
case WIDGET_ITEM_DRAW_BACKGROUND:
//
// Draw background of button
//
if(BUTTON_IsPressed(pDrawItemInfo->hWin)) {
GUI_DrawGradientRoundedVEx(&Rect, 3, GUI_GRAY_D0, GUI_GRAY_E7);
} else {
GUI_DrawGradientRoundedVEx(&Rect, 3, GUI_GRAY_C0, GUI_GRAY_C8);
}
GUI_SetColor(GUI_BLACK);
GUI_DrawRoundedRectEx(&Rect, 3);
return 0;
default:
return BUTTON_DrawSkinFlex(pDrawItemInfo);
}
}
/*********************************************************************
*
* _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);
BUTTON_SetText(hButton, "Button");
//
// Set skinning routine
//
BUTTON_SetSkin(hButton, _cbButtonSkin);
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 window
//
WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/