LISTWHEEL - Custom (Sample)
LISTWHEEL_Custom.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | LISTWHEEL_Custom.c |
This sample demonstrates custom drawing of a LISTWHEEL widget.
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 : LISTWHEEL_Custom.c
Purpose : Sample that demonstrates how custom drawing works for
the LISTWHEEL widget in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define LINE_HEIGHT 20
#define Y_SIZE 110
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const char * _acText[] = {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
NULL
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _OwnerDrawListwheel
*/
static int _OwnerDrawListwheel(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
char acBuffer[32];
GUI_RECT Rect;
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_GET_XSIZE:
//
// Return x-size of item
//
return LISTWHEEL_OwnerDraw(pDrawItemInfo);
case WIDGET_ITEM_GET_YSIZE:
//
// Return y-size of item
//
return LISTWHEEL_OwnerDraw(pDrawItemInfo);
case WIDGET_ITEM_DRAW:
//
// Draw an item
//
//
// Get drawing rect
//
Rect.x0 = pDrawItemInfo->x0;
Rect.x1 = pDrawItemInfo->x1;
Rect.y0 = pDrawItemInfo->y0;
Rect.y1 = pDrawItemInfo->y1;
//
// Draw selected item in a different color
//
if (LISTWHEEL_GetSel(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
GUI_SetColor(GUI_BLUE);
} else {
GUI_SetColor(GUI_WHITE);
}
//
// Display item text centered
//
GUI_SetTextMode(GUI_TM_TRANS);
LISTWHEEL_GetItemText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex, acBuffer, sizeof(acBuffer));
GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_CENTER);
return 0;
case WIDGET_ITEM_DRAW_BACKGROUND:
//
// Draw background
//
GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_GRAY_7C, GUI_GRAY_AA);
GUI_SetColor(GUI_BLACK);
GUI_SetPenSize(2);
GUI_DrawRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
return 0;
case WIDGET_ITEM_DRAW_OVERLAY:
GUI_SetColor(GUI_RED);
GUI_DrawHLine(pDrawItemInfo->y0 + (LINE_HEIGHT * 2) + 1, pDrawItemInfo->x0, pDrawItemInfo->x1);
GUI_DrawHLine(pDrawItemInfo->y1 - (LINE_HEIGHT * 2) + 2, pDrawItemInfo->x0, pDrawItemInfo->x1);
return 0;
default:
return LISTWHEEL_OwnerDraw(pDrawItemInfo);
}
}
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
int NCode;
int Sel;
char acBuffer[64];
char acTemp[32];
static LISTWHEEL_Handle hListwheel;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Create listwheel widget
//
hListwheel = LISTWHEEL_CreateEx(10, 10, Y_SIZE, 100, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_LISTWHEEL0, _acText);
//
// Set snap position (position where the wheel stops)
//
LISTWHEEL_SetSnapPosition(hListwheel, (Y_SIZE - LINE_HEIGHT) / 2);
//
// Set some properties about the listwheel
//
LISTWHEEL_SetLineHeight(hListwheel, LINE_HEIGHT);
LISTWHEEL_SetTextAlign(hListwheel, GUI_TA_CENTER);
//
// Set OwnerDraw function
//
LISTWHEEL_SetOwnerDraw(hListwheel, _OwnerDrawListwheel);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
//
// Draw currently selected day
//
GUI_SetColor(GUI_BLACK);
Sel = LISTWHEEL_GetSel(hListwheel);
LISTWHEEL_GetItemText(hListwheel, Sel, acTemp, sizeof(acTemp));
sprintf(acBuffer, "Selected item: %s", acTemp);
GUI_DispStringAt(acBuffer, 150, 10);
break;
case WM_NOTIFY_PARENT:
NCode = pMsg->Data.v;
switch (NCode) {
case WM_NOTIFICATION_SEL_CHANGED:
//
// Get current selection
//
Sel = LISTWHEEL_GetPos(hListwheel);
LISTWHEEL_SetSel(hListwheel, Sel);
break;
}
WM_InvalidateWindow(pMsg->hWin);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init GUI
//
GUI_Init();
//
// Enable multi-buffering
//
WM_MULTIBUF_Enable(1);
//
// Create a window
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/