Difference between revisions of "SCROLLER - Custom (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...") |
(No difference)
|
Latest revision as of 13:18, 11 May 2022
SCROLLER_Custom.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | SCROLLER_Custom.c |
This sample demonstrates how the look of a SCROLLER widget can be customized using its owner draw function.
Demo
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2022 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.26 - 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 : SCROLLER_Custom.c
Purpose : Sample that demonstrates how the appearance of a
SCROLLER widget can be customized.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - (x)
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
Wiki link : https://wiki.segger.com/SCROLLER_-_Custom_%28Sample%29
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
#include <stdlib.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
//
// SCROLLER uses a anti-aliasing factor of 4
//
#define HIRES_FACTOR 4
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _acContent_Listview
*/
static const char * _acContent[][6] = {
{ "1002", "Murphy", "Diane", "x5800", "President", "dmurphy@classicmodelcars.com" },
{ "1056", "Patterson", "Mary", "x4611", "VP Sales", "mpatterso@classicmodelcars.com" },
{ "1076", "Firrelli", "Jeff", "x9273", "VP Marketing", "jfirrelli@classicmodelcars.com" },
{ "1088", "Patterson", "William", "x4871", "Sales Manager (APAC)", "wpatterson@classicmodelcars.com" },
{ "1102", "Bondur", "Gerard", "x5408", "Sale Manager (EMEA)", "gbondur@classicmodelcars.com" },
{ "1143", "Bow", "Anthony", "x5428", "Sales Manager (NA)", "abow@classicmodelcars.com" },
{ "1165", "Jennings", "Leslie", "x3291", "Sales Rep", "ljennings@classicmodelcars.com" },
{ "1166", "Thompson", "Leslie", "x4065", "Sales Rep", "lthompson@classicmodelcars.com" },
{ "1188", "Firrelli", "Julie", "x2173", "Sales Rep", "jfirrelli@classicmodelcars.com" },
{ "1216", "Patterson", "Steve", "x4334", "Sales Rep", "spatterson@classicmodelcars.com" },
{ "1286", "Tseng", "Foon Yue", "x2248", "Sales Rep", "ftseng@classicmodelcars.com" },
{ "1002", "Murphy", "Diane", "x5800", "President", "dmurphy@classicmodelcars.com" },
{ "1056", "Patterson", "Mary", "x4611", "VP Sales", "mpatterso@classicmodelcars.com" },
{ "1076", "Firrelli", "Jeff", "x9273", "VP Marketing", "jfirrelli@classicmodelcars.com" },
{ "1088", "Patterson", "William", "x4871", "Sales Manager (APAC)", "wpatterson@classicmodelcars.com" },
{ "1102", "Bondur", "Gerard", "x5408", "Sale Manager (EMEA)", "gbondur@classicmodelcars.com" },
{ "1143", "Bow", "Anthony", "x5428", "Sales Manager (NA)", "abow@classicmodelcars.com" },
{ "1165", "Jennings", "Leslie", "x3291", "Sales Rep", "ljennings@classicmodelcars.com" },
{ "1166", "Thompson", "Leslie", "x4065", "Sales Rep", "lthompson@classicmodelcars.com" },
{ "1188", "Firrelli", "Julie", "x2173", "Sales Rep", "jfirrelli@classicmodelcars.com" },
{ "1216", "Patterson", "Steve", "x4334", "Sales Rep", "spatterson@classicmodelcars.com" },
{ "1286", "Tseng", "Foon Yue", "x2248", "Sales Rep", "ftseng@classicmodelcars.com" },
{ "1002", "Murphy", "Diane", "x5800", "President", "dmurphy@classicmodelcars.com" },
{ "1056", "Patterson", "Mary", "x4611", "VP Sales", "mpatterso@classicmodelcars.com" },
{ "1076", "Firrelli", "Jeff", "x9273", "VP Marketing", "jfirrelli@classicmodelcars.com" },
{ "1088", "Patterson", "William", "x4871", "Sales Manager (APAC)", "wpatterson@classicmodelcars.com" },
{ "1102", "Bondur", "Gerard", "x5408", "Sale Manager (EMEA)", "gbondur@classicmodelcars.com" },
{ "1143", "Bow", "Anthony", "x5428", "Sales Manager (NA)", "abow@classicmodelcars.com" },
{ "1165", "Jennings", "Leslie", "x3291", "Sales Rep", "ljennings@classicmodelcars.com" },
{ "1166", "Thompson", "Leslie", "x4065", "Sales Rep", "lthompson@classicmodelcars.com" },
{ "1188", "Firrelli", "Julie", "x2173", "Sales Rep", "jfirrelli@classicmodelcars.com" },
{ "1216", "Patterson", "Steve", "x4334", "Sales Rep", "spatterson@classicmodelcars.com" },
{ "1286", "Tseng", "Foon Yue", "x2248", "Sales Rep", "ftseng@classicmodelcars.com" },
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _CreateListview
*/
static LISTVIEW_Handle _CreateListview(void) {
LISTVIEW_Handle hListview;
int i;
//
// Create listview widget
//
hListview = LISTVIEW_CreateEx(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0);
//
// Add columns to listview
//
LISTVIEW_AddColumn(hListview, 45, "Emp. Nr.", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 60, "Last Name", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 60, "First Name", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 40, "Ext.", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 110, "Title", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 180, "Email", GUI_TA_LEFT);
//
// Add rows to listview
//
for (i = 0; i < GUI_COUNTOF(_acContent); i++) {
LISTVIEW_AddRow(hListview, _acContent[i]);
}
//
// Set compare functions
//
LISTVIEW_SetCompareFunc(hListview, 0, LISTVIEW_CompareDec);
LISTVIEW_SetCompareFunc(hListview, 1, LISTVIEW_CompareText);
LISTVIEW_SetCompareFunc(hListview, 2, LISTVIEW_CompareText);
LISTVIEW_SetCompareFunc(hListview, 3, LISTVIEW_CompareText);
LISTVIEW_SetCompareFunc(hListview, 4, LISTVIEW_CompareText);
LISTVIEW_SetCompareFunc(hListview, 5, LISTVIEW_CompareText);
//
// Enable sorting
//
LISTVIEW_EnableSort(hListview);
//
// Enable motion
//
LISTVIEW_EnableMotion(hListview, LISTVIEW_CF_MOTION_V);
return hListview;
}
/*********************************************************************
*
* _OwnerDrawScroller
*/
static int _OwnerDrawScroller(const WIDGET_ITEM_DRAW_INFO * pInfo) {
int r;
GUI_COLOR OldColor, Color;
GUI_COLOR aColor[2];
U8 Intens;
I16 * pPos;
int x0, x1;
int d;
int Off;
int xPos;
I16 PosInv;
LCD_COLOR (* pfMixColors)(LCD_COLOR, LCD_COLOR, U8);
switch(pInfo->Cmd) {
case WIDGET_ITEM_DRAW:
//
// Draw thumb rectangle only for active state
//
if (pInfo->ItemIndex == SCROLLER_CI_ACTIVE) {
r = SCROLLER_GetRadius(pInfo->hWin) * HIRES_FACTOR;
Color = SCROLLER_GetColor(pInfo->hWin, pInfo->ItemIndex);
OldColor = GUI_GetColor();
GUI_EnableAlpha(1);
GUI_SetColor(Color);
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(HIRES_FACTOR);
GUI_AA_FillRoundedRect(pInfo->x0, pInfo->y0, pInfo->x1, pInfo->y1, r);
GUI_AA_DisableHiRes();
GUI_SetColor(OldColor);
GUI_EnableAlpha(0);
}
//
// Draw thumb rectangle during fading
//
else if (pInfo->ItemIndex == -1) {
r = SCROLLER_GetRadius(pInfo->hWin) * HIRES_FACTOR;
pPos = (I16 *)pInfo->p;
//
// Calculate new rectangle position.
//
xPos = WM_GetWinOrgX(pInfo->hWin);
d = (LCD_GetXSize() - 1) - (pInfo->x0 + xPos);
PosInv = (~(*pPos)) & 0x7FFF;
Off = ((PosInv * d) / GUI_ANIM_RANGE);
x0 = pInfo->x0 - (Off * HIRES_FACTOR);
x1 = pInfo->x1 - (Off * HIRES_FACTOR);
//
// Retrieve pointer to color mixing routine.
//
pfMixColors = GUI_SetFuncMixColors(NULL);
GUI_SetFuncMixColors(pfMixColors);
//
// Mix colors.
//
Intens = (*pPos * 255) / GUI_ANIM_RANGE;
aColor[0] = SCROLLER_GetColor(pInfo->hWin, SCROLLER_CI_ACTIVE);
aColor[1] = SCROLLER_GetColor(pInfo->hWin, SCROLLER_CI_INACTIVE);
Color = pfMixColors(aColor[0], aColor[1], Intens);
OldColor = GUI_GetColor();
//
// Draw rectangle.
//
GUI_EnableAlpha(1);
GUI_SetColor(Color);
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(HIRES_FACTOR);
GUI_AA_FillRoundedRect(x0, pInfo->y0, x1, pInfo->y1, r);
GUI_AA_DisableHiRes();
GUI_SetColor(OldColor);
GUI_EnableAlpha(0);
}
return 0;
default:
return SCROLLER_OwnerDraw(pInfo);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
LISTVIEW_Handle hListview;
SCROLLER_Handle hScroller;
//
// Init GUI
//
GUI_Init();
WM_SetDesktopColor(GUI_WHITE);
//
// Enable multi-buffering
//
WM_MULTIBUF_Enable(1);
//
// Create LISTVIEW
//
hListview = _CreateListview();
//
// Attach SCROLLER to LISTVIEW.
//
hScroller = SCROLLER_CreateAttached(hListview, SCROLLER_CF_VERTICAL | SCROLLER_CF_TOUCH | SCROLLER_CF_FADING);
SCROLLER_SetOwnerDraw(hScroller, _OwnerDrawScroller);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/