1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
| #include "GUI.h"
#include "WM.h"
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_LISTWHEEL_0 (GUI_ID_USER + 0x01)
#define ID_LISTWHEEL_1 (GUI_ID_USER + 0x02)
#define ID_LISTWHEEL_2 (GUI_ID_USER + 0x03)
/*******************************************************************
*
* Static variables
*
********************************************************************/
static char *_apYear[] = {
"1990","1991", "1992", "1993", "1994", "1995", "1996",
"1997", "1998", "1999", "2000", "2001", "2002", "2003",
"2004", "2005", "2006", "2007", "2008", "2009", "2010",
"2011", "2012", "2013", "2014", "2015", "2016", "2017",
"2018", "2019", "2020",
};
static char *_apMonth[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
};
static char *_apDay[] = {
"01", "02", "03", "04",
"05", "06", "07", "08",
"09", "10", "11", "12",
"13", "14", "15", "16",
"17", "18", "19", "20",
"21", "22", "23", "24",
"25", "26", "27", "28",
"29", "30", "31",
};
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 240, 320, 0, 0x0, 0 },
{ LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_0, 10, 50, 60, 178, WM_CF_MEMDEV, 0x0, 0 },
{ LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_1, 80, 50, 100, 178, WM_CF_MEMDEV, 0x0, 0 },
{ LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_2, 180, 50, 50, 178, WM_CF_MEMDEV, 0x0, 0 },
};
/*******************************************************************************
* static code
******************************************************************************/
/**
* @brief 用户绘制函数
* @note 无
* @param pDrawItemInfo:指向WIDGET_ITEM_DRAW_INFO结构的指针
* @retval 默认绘制函数 或 0
*/
static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo)
{
GUI_RECT aRect;
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_DRAW_OVERLAY:
/* 获取控件坐标 */
aRect.x0 = pDrawItemInfo->x0;
aRect.x1 = pDrawItemInfo->x1;
aRect.y1 = pDrawItemInfo->y1;
/* 画分割线 */
GUI_SetColor(GUI_GRAY_E7);
GUI_DrawLine(aRect.x0, (aRect.y1-19-16)/2, aRect.x1, (aRect.y1-19-16)/2);
GUI_DrawLine(aRect.x0, (aRect.y1+19+16)/2, aRect.x1, (aRect.y1+19+16)/2);
break;
default:
return LISTWHEEL_OwnerDraw(pDrawItemInfo);
}
return 0;
}
/**
* @brief 对话框回调函数
* @note 无
* @param pMsg:消息指针
* @retval 无
*/
static void _cbDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hItem;
int NCode;
int Id;
switch (pMsg->MsgId)
{
case WM_INIT_DIALOG:
/* 初始化框架窗口控件 */
hItem = pMsg->hWin;
FRAMEWIN_SetTitleHeight(hItem, 32);
FRAMEWIN_SetFont(hItem, &GUI_Font16B_ASCII);
FRAMEWIN_SetText(hItem, "STemWIN STM32F103");
/* 初始化LISTWHEEL */
for(int i=0; i < 3; i++)
{
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0 + i);
LISTWHEEL_SetLineHeight(hItem, 34);
LISTWHEEL_SetSnapPosition(hItem, (178-34)/2);
LISTWHEEL_SetFont(hItem, GUI_FONT_20B_ASCII);
LISTWHEEL_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_UNSEL, 0x191919);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
LISTWHEEL_SetDeceleration(hItem, 35);
LISTWHEEL_SetOwnerDraw(hItem, _OwnerDraw);
LISTWHEEL_SetSel(hItem, 0);
}
/* 添加LISTWHEEL0文本项 */
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
for(int i=0; i<GUI_COUNTOF(_apYear); i++)
{
LISTWHEEL_AddString(hItem, *(_apYear+i));
}
/* 添加LISTWHEEL1文本项 */
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
for(int i=0; i<GUI_COUNTOF(_apMonth); i++)
{
LISTWHEEL_AddString(hItem, *(_apMonth+i));
}
/* 添加LISTWHEEL2文本项 */
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
for(int i=0; i<GUI_COUNTOF(_apDay); i++)
{
LISTWHEEL_AddString(hItem, *(_apDay+i));
}
break;
case WM_NOTIFY_PARENT:
/* 获取控件ID */
Id = WM_GetId(pMsg->hWinSrc);
/* 获取通知代码 */
NCode = pMsg->Data.v;
switch(Id)
{
case ID_LISTWHEEL_0: // Notifications sent by 'Button'
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_SEL_CHANGED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
U8 index = LISTWHEEL_GetPos(hItem);
LISTWHEEL_SetSel(hItem, index);
break;
}
break;
case ID_LISTWHEEL_1: // Notifications sent by 'Button'
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_SEL_CHANGED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
U8 index = LISTWHEEL_GetPos(hItem);
LISTWHEEL_SetSel(hItem, index);
break;
}
break;
case ID_LISTWHEEL_2: // Notifications sent by 'Button'
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_SEL_CHANGED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
U8 index = LISTWHEEL_GetPos(hItem);
LISTWHEEL_SetSel(hItem, index);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/**
* @brief 以对话框方式间接创建控件
* @note 无
* @param 无
* @retval hWin:资源表中第一个控件的句柄
*/
WM_HWIN CreateFramewin(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/**
* @brief GUI主任务
* @note 无
* @param 无
* @retval 无
*/
void MainTask(void)
{
/* 创建对话框 */
CreateFramewin();
while (1)
{
GUI_Delay(200);
}
}
|