summaryrefslogtreecommitdiff
path: root/boards/ek-lm4f232/drivers/slidemenuwidget.c
blob: 805b77b261035808fce9c4e903ffa079f2301b14 (plain)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
//*****************************************************************************
//
// slidemenuwidget.c - A sliding menu drawing widget.
//
// Copyright (c) 2011-2014 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 2.1.0.12573 of the EK-LM4F232 Firmware Package.
//
//*****************************************************************************

#include <stdbool.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "utils/uartstdio.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "slidemenuwidget.h"

//*****************************************************************************
//
//! \addtogroup slidemenuwidget_api
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
// This is a custom widget for drawing a menu system on the display.  The
// widget presents the menus using a "sliding" animation.  The menu items
// are shown in a vertical list, and as the user scrolls through the list
// of menu items, the menu slides up and down the display.  When a menu item
// is selected to descend in the menu tree, the widget slides the old menu
// off the to left while the new menu slides in from the right.  Likewise,
// going up in the menu tree, the higher level menu slides back onto the
// screen from the left.
//
// Additional structures are provided to implement a menu, and menu items.
// Each menu contains menu items, and each menu item can have a child menu.
// These structures can be used to build a menu tree.  The menu widget will
// show one menu at any given time, the menu that is displayed on the screen.
//
// In addition to child menus, any menu item can have instead a child widget.
// If this is used, then when the user selects a menu item, a new widget can
// be activated to perform some function.  When the function of the child
// widget completes, then the widget slides back off the screen (to the right)
// and the parent menu is displayed again.
//
// A given menu can have menu items that are individually selectable or
// multiple-selectable.  For individually selectable menu items, the item
// is selected by leaving the menu with the focus on the selected item.  For
// example navigating down to a submenu with choices A, B and C, and then
// navigating until the focus is on item B will cause item B to be selected.
// The menu will remember that item B was selected even when navigating away
// from that menu.
//
// If a menu is configured to be multiple-selectable, then each menu item has
// a check box that is checked by pressing the select button.  When the item
// is selected the box will show an X.  Any or all or none can be selected in
// this way.  When a menu is configured to be multi-selectable, the menu items
// cannot have any child menus or widgets.
//
// The menu widget provides some visual clues to the user about how to
// navigate the menu tree.  Whenever a menu item has a child menu or child
// widget, then a small right arrow is shown on the right side of the menu
// item that has the focus.  This tells the user to press the "right" button
// to descend to the next menu or widget.  When it is possible to go up a
// level in the menu tree (when showing a child menu), a small left arrow
// will be shown on the menu item with the focus.  This is an indication to the
// user that they should press the "left" button.
//
// This widget is meant to work with key/button presses.  It expects there
// to be up/down/left/right and select buttons.  The widget will need to be
// modified in order to work with a pointer input.
//
// In order to perform the sliding animation, the menu widget requires that
// it be provided with two off-screen displays.  The menu widget renders the
// two menus (the old and the new) into the two buffers, and then repeatedly
// paints both to the physical display while adjusting the coordinates as
// appropriate.  This will cause the menus to appear animated and move across
// the display.  When the menus are being animated, the menu widget is taking
// all the non-interrupt processor time in order to draw the buffers to the
// display.  This operation occurs in response to the widget processing of the
// key/button events and will occur in the thread that calls
// WidgetMessageQueueProcess().  The programmer should be aware of this
// processing burden when designing an application that uses the sliding
// menu widget.
//
//*****************************************************************************

//*****************************************************************************
//
// A graphics image of a small right arrow icon.
//
//*****************************************************************************
const uint8_t g_ui8RtArrow[] =
{
    IMAGE_FMT_1BPP_UNCOMP,
    4, 0,
    8, 0,

    0x80,
    0xC0,
    0xE0,
    0xF0,
    0xE0,
    0xC0,
    0x80,
    0
};

//*****************************************************************************
//
// A graphics image of a small left arrow icon.
//
//*****************************************************************************
const uint8_t g_ui8LtArrow[] =
{
    IMAGE_FMT_1BPP_UNCOMP,
    4, 0,
    8, 0,

    0x10,
    0x30,
    0x70,
    0xF0,
    0x70,
    0x30,
    0x10,
    0
};

//*****************************************************************************
//
// A graphics image of a small unchecked box icon.
//
//*****************************************************************************
const uint8_t g_ui8Unchecked[] =
{
    IMAGE_FMT_1BPP_UNCOMP,
    7, 0,
    8, 0,

    0xFE,
    0x82,
    0x82,
    0x82,
    0x82,
    0x82,
    0xFE,
    0
};

//*****************************************************************************
//
// A graphics image of a small checked box icon.
//
//*****************************************************************************
const uint8_t g_ui8Checked[] =
{
    IMAGE_FMT_1BPP_UNCOMP,
    7, 0,
    8, 0,

    0xFE,
    0xC6,
    0xAA,
    0x92,
    0xAA,
    0xC6,
    0xFE,
    0
};

//*****************************************************************************
//
//! Draws the current menu into a drawing context, off-screen buffer.
//!
//! \param psMenuWidget points at the SlideMenuWidget being processed.
//! \param psContext points to the context where all drawing should be done.
//! \param i32OffsetY is the Y offset for drawing the menu.
//!
//! This function renders a menu (set of menu items), into a drawing context.
//! It assumes that the drawing context is an off-screen buffer, and that
//! the entire buffer belongs to this widget.  The vertical position of the
//! menu can be adjusted by using the parameter i32OffsetY.  This value can be
//! positive or negative and can cause the menu to be rendered above or below
//! the normal position in the display.
//!
//! \return None.
//
//*****************************************************************************
void
SlideMenuDraw(tSlideMenuWidget *psMenuWidget, tContext *psContext,
              int32_t i32OffsetY)
{
    tSlideMenu *psMenu;
    uint32_t ui32Idx;
    tRectangle sRect;

    //
    // Check the arguments
    //
    ASSERT(psMenuWidget);
    ASSERT(psContext);

    //
    // Set the foreground color for the rectangle fill to match what we want
    // as the menu background.
    //
    GrContextForegroundSet(psContext, psMenuWidget->ui32ColorBackground);
    GrRectFill(psContext, &psContext->sClipRegion);

    //
    // Get the current menu that is being displayed
    //
    psMenu = psMenuWidget->psSlideMenu;

    //
    // Set the foreground to the color we want for the menu item boundaries
    // and text color, text font.
    //
    GrContextForegroundSet(psContext, psMenuWidget->ui32ColorForeground);
    GrContextFontSet(psContext, psMenuWidget->psFont);

    //
    // Set the rectangle bounds for the first menu item.
    // The starting Y value is calculated based on which menu item is currently
    // centered.  Y coordinates are subtracted to find the Y start location
    // of the first menu item, which could even be off the display.
    //
    // Set the X coords of the menu item to the extents of the display
    //
    sRect.i16XMin = 0;
    sRect.i16XMax = psContext->sClipRegion.i16XMax;

    //
    // Find the Y coordinate of the centered menu item
    //
    sRect.i16YMin = (psContext->psDisplay->ui16Height / 2) -
                    (psMenuWidget->ui32MenuItemHeight / 2);

    //
    // Adjust to find Y coordinate of first menu item
    //
    sRect.i16YMin -= psMenu->ui32CenterIndex * psMenuWidget->ui32MenuItemHeight;

    //
    // Now adjust for the offset that was passed in by caller.  This allows
    // for drawing menu items above or below the main display.
    //
    sRect.i16YMin += i32OffsetY;

    //
    // Find the ending Y coordinate of first menu item
    //
    sRect.i16YMax = sRect.i16YMin + psMenuWidget->ui32MenuItemHeight - 1;

    //
    // Start the index at the first menu item.  It is possible that this
    // menu item is off the display.
    //
    ui32Idx = 0;

    //
    // Loop through all menu items, drawing on the display.  Note that some
    // may not be on the screen, but they will be clipped.
    //
    while(ui32Idx < psMenu->ui32Items)
    {
        //
        // If this index is the one that is highlighted, then change the
        // background
        //
        if(ui32Idx == psMenu->ui32FocusIndex)
        {
            //
            // Set the foreground to the highlight color, and fill the
            // rectangle of the background of this menu item.
            //
            GrContextForegroundSet(psContext, psMenuWidget->ui32ColorHighlight);
            GrRectFill(psContext, &sRect);

            //
            // Set the new foreground to the normal foreground color, and
            // set the background to the highlight color.  This is so
            // remaining drawing operations will have the correct background
            // and foreground colors for this highlighted menu item cell.
            //
            GrContextForegroundSet(psContext, psMenuWidget->ui32ColorForeground);
            GrContextBackgroundSet(psContext, psMenuWidget->ui32ColorHighlight);

            //
            // If this menu has a parent, then draw a left arrow icon on the
            // focused menu item.
            //
            if(psMenu->psParent)
            {
                GrImageDraw(psContext, g_ui8LtArrow, sRect.i16XMin + 4,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }

            //
            // If this menu has a child menu or child widget, then draw a
            // right arrow icon on the focused menu item.
            //
            if(psMenu->psSlideMenuItems[ui32Idx].psChildMenu ||
               psMenu->psSlideMenuItems[ui32Idx].psChildWidget)
            {
                GrImageDraw(psContext, g_ui8RtArrow, sRect.i16XMax - 8,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }
        }

        //
        // Otherwise this is a normal, non-highlighted menu item cell,
        // so set the normal background color.
        //
        else
        {
            GrContextBackgroundSet(psContext, psMenuWidget->ui32ColorBackground);
        }

        //
        // If the current menu is multi-selectable, then draw a checkbox on
        // the menu item.  Draw a checked or unchecked box depending on whether
        // the item has been selected.
        //
        if(psMenu->bMultiSelectable)
        {
            if(psMenu->ui32SelectedFlags & (1 << ui32Idx))
            {
                GrImageDraw(psContext, g_ui8Checked, sRect.i16XMax - 12,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }
            else
            {
                GrImageDraw(psContext, g_ui8Unchecked, sRect.i16XMax - 12,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }

        }

        //
        // Draw the rectangle representing the menu item
        //
        GrRectDraw(psContext, &sRect);

        //
        // Draw the text for this menu item in the middle of the menu item
        // rectangle (cell).
        //
        GrStringDrawCentered(psContext,
                             psMenu->psSlideMenuItems[ui32Idx].pcText,
                             -1,
                             psMenuWidget->sBase.psDisplay->ui16Width / 2,
                             sRect.i16YMin + \
                             (psMenuWidget->ui32MenuItemHeight / 2) - 1, 0);

        //
        // Advance to the next menu item, and update the menu item rectangle
        // bounds to the next position
        //
        ui32Idx++;
        sRect.i16YMin += psMenuWidget->ui32MenuItemHeight;
        sRect.i16YMax += psMenuWidget->ui32MenuItemHeight;

        //
        // Note that this may attempt to render menu items that run off the
        // bottom of the drawing area, but these will just be clipped and a
        // little bit of processing time is wasted.
        //
    }
}

//*****************************************************************************
//
//! Paints a menu, menu items on a display.
//!
//! \param psWidget is a pointer to the slide menu widget to be drawn.
//!
//! This function draws the contents of a slide menu on the display.  This is
//! called in response to a \b WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
SlideMenuPaint(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tContext sContext;

    //
    // Check the arguments.
    //
    ASSERT(psWidget);

    //
    // If this widget has a child widget, that means that the menu has
    // slid off the screen and the child widget is in control.  Therefore
    // there is nothing to paint here.  Just exit and the child widget will
    // be painted.
    //
    if(psWidget->psChild)
    {
        return;
    }

    //
    // Convert the generic widget pointer into a slide menu widget pointer,
    // and get a pointer to its context.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer, using normal vertical
    // position.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Now copy the rendered menu into the physical display. This will show
    // the menu on the display.
    //
    GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                psWidget->sPosition.i16XMin, psWidget->sPosition.i16YMin);
}

//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "down" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move down.
//!
//! This function will respond to the "down" key/button event.  The down
//! button is used to select the next menu item down the list, and the effect
//! is that the menu itself slides up, leaving the highlighted menu item
//! in the middle of the screen.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuDown(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tContext sContext;
    uint32_t ui32MenuHeight;
    uint32_t ui32Y;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the menu that is currently
    // displayed.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;

    //
    // If we are already at the end of the list of menu items, then there
    // is nothing else to do.
    //
    if(psMenu->ui32FocusIndex >= (psMenu->ui32Items - 1))
    {
        return(1);
    }

    //
    // Increment focus menu item.  This has the effect of selecting the next
    // menu item in the list.
    //
    psMenu->ui32FocusIndex++;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the next menu item down.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Draw a continuation of this menu in the second offscreen buffer.
    // This is the part of the menu that would be drawn if the display were
    // twice as tall.  We are effectively creating a virtual display that is
    // twice as tall as the physical display.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);
    SlideMenuDraw(psMenuWidget, &sContext, -1 *
                  (psMenuWidget->sBase.sPosition.i16YMax -
                  psMenuWidget->sBase.sPosition.i16YMin));

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the height of the displayed part of the menu.
    //
    ui32MenuHeight = psMenuWidget->psDisplayA->ui16Height;

    //
    // Now copy the rendered menu into the physical display
    //
    // Iterate over the Y displacement of one menu item cell.  This loop
    // will repeatedly draw both off screen buffers to the physical display,
    // adjusting the position of each by one pixel each time it is drawn.  Each
    // time the offset is changed so that both buffers are drawn one higher
    // than the previous time.  This will have the effect of "sliding" the
    // entire menu up by the height of one menu item cell.
    // The speed of the animation is controlled entirely by the speed of the
    // processor and the speed of the interface to the physical display.
    //
    for(ui32Y = 0; ui32Y <= psMenuWidget->ui32MenuItemHeight; ui32Y++)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin - ui32Y);
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin + ui32MenuHeight - ui32Y);
    }

    //
    // Increment centered menu item.  This will now match the menu item with
    // the focus.  When the menu is repainted again, the newly selected
    // menu item will be centered and highlighted.
    //
    psMenu->ui32CenterIndex = psMenu->ui32FocusIndex;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the next menu item down.  Now when a repaint occurs the menu
    // will be redrawn with the newly highlighted menu item.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Return indication that we handled the key event.
    //
    return(1);
}

//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "up" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move up.
//!
//! This function will respond to the "up" key/button event.  The up
//! button is used to select the previous menu item down the list, and the
//! effect is that the menu itself slides down, leaving the highlighted menu
//! item in the middle of the screen.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the first position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuUp(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tContext sContext;
    uint32_t ui32MenuHeight;
    uint32_t ui32Y;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the menu that is currently
    // displayed.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;

    //
    // If we are already at the start of the list of menu items, then there
    // is nothing else to do.
    //
    if(psMenu->ui32FocusIndex == 0)
    {
        return(1);
    }

    //
    // Decrement the focus menu item.  This has the effect of selecting the
    // previous menu item in the list.
    //
    psMenu->ui32FocusIndex--;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the previous menu item up.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Draw a continuation of this menu in the second offscreen buffer.
    // This is the part of the menu that would be drawn above this menu if the
    // display were twice as tall.  We are effectively creating a virtual
    // display that is twice as tall as the physical display.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);
    SlideMenuDraw(psMenuWidget, &sContext,
                  (psMenuWidget->sBase.sPosition.i16YMax -
                  psMenuWidget->sBase.sPosition.i16YMin));

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the height of the displayed part of the menu.
    //
    ui32MenuHeight = psMenuWidget->psDisplayA->ui16Height;

    //
    // Now copy the rendered menu into the physical display
    //
    // Iterate over the Y displacement of one menu item cell.  This loop
    // will repeatedly draw both off screen buffers to the physical display,
    // adjusting the position of each by one pixel each time it is drawn.  Each
    // time the offset is changed so that both buffers are drawn one lower
    // than the previous time.  This will have the effect of "sliding" the
    // entire menu down by the height of one menu item cell.
    // The speed of the animation is controlled entirely by the speed of the
    // processor and the speed of the interface to the physical display.
    //
    for(ui32Y = 0; ui32Y <= psMenuWidget->ui32MenuItemHeight; ui32Y++)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin + ui32Y - ui32MenuHeight);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin + ui32Y);
    }

    //
    // Decrement the  centered menu item.  This will now match the menu item
    // with the focus.  When the menu is repainted again, the newly selected
    // menu item will be centered and highlighted.
    //
    psMenu->ui32CenterIndex = psMenu->ui32FocusIndex;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the next menu item up.  Now when a repaint occurs the menu
    // will be redrawn with the newly highlighted menu item.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Return indication that we handled the key event.
    //
    return(1);
}

//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "right" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move to the right.
//!
//! This function will respond to the "right" key/button event.  The right
//! button is used to select the next menu level below the current menu item,
//! or a widget that is activated by the menu item.  The effect is that the
//! menu itself slides off to the left, and the new menu or widget slides in
//! from the right.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuRight(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tSlideMenu *psChildMenu;
    tContext sContext;
    tWidget *psChildWidget;
    uint32_t ui32X;
    uint32_t ui32MenuWidth;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the current menu, and the
    // child menu and widget if they exist.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;
    psChildMenu = psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].psChildMenu;
    psChildWidget = psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].psChildWidget;

    //
    // Initialize a context for the secondary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);

    //
    // Render the current menu into off-screen buffer B.  This
    // will be the same menu appearance as is already being shown.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Now set up context for drawing into off-screen buffer A
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Process child menu of this menu item
    //
    if(psChildMenu)
    {
        //
        // Switch the active menu for this SlideMenuWidget to be the child
        // menu
        //
        psMenuWidget->psSlideMenu = psChildMenu;

        //
        // Draw the new (child) menu into off-screen buffer A
        //
        SlideMenuDraw(psMenuWidget, &sContext, 0);
    }

    //
    // Process child widget of this menu item.  This only happens if there
    // is no child menu.
    //
    else if(psChildWidget)
    {
        //
        // Call the widget activated callback function.  This will notify
        // the application that a child widget has been activated by the
        // menu system.
        //
        if(psMenuWidget->pfnActive)
        {
            psMenuWidget->pfnActive(psChildWidget,
                                   &psMenu->psSlideMenuItems[psMenu->ui32FocusIndex],
                                   1);
        }

        //
        // Link the new child widget into this SlideMenuWidget so
        // it appears as a child to this widget.  Normally the menu widget
        // has no child widget.
        //
        psWidget->psChild = psChildWidget;
        psChildWidget->psParent = psWidget;

        //
        // Fill a rectangle with the new child widget background color.
        // This is done in off-screen buffer A.  When the menu slides off,
        // it will be replaced by a blank background that will then be
        // controlled by the new child widget.
        //
        GrContextForegroundSet(
            &sContext,
            psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].ui32ChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);

        //
        // Request a repaint for the child widget so it can draw itself once
        // the menu slide is done.
        //
        WidgetPaint(psChildWidget);
    }

    //
    // There is no child menu or child widget, so there is nothing to change
    // on the display.
    //
    else
    {
        return(1);
    }

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the width of the menu widget which is used in calculations below
    //
    ui32MenuWidth = psMenuWidget->psDisplayA->ui16Width;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a right-to-left-wipe.  This will provide an appearance
    // of sliding to the left.  The new child menu, or child widget background
    // will slide in from the right.  The "old" menu is being held in
    // off-screen buffer B and the new one is in buffer A.  So when we are
    // done, the correct image will be in buffer A.
    //
    for(ui32X = 0; ui32X <= ui32MenuWidth; ui32X += 8)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin - ui32X,
                    psWidget->sPosition.i16YMin);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32MenuWidth - ui32X,
                    psWidget->sPosition.i16YMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}

//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "left" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move to the left.
//!
//! This function will respond to the "left" key/button event.  The left
//! button is used to ascend to the next menu up in the menu tree.  The effect
//! is that the current menu, or active widget, slides off to the right, while
//! the parent menu slides in from the left.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuLeft(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tSlideMenu *psParentMenu;
    tContext sContext;
    uint32_t ui32X;
    uint32_t ui32MenuWidth;

    //
    // Get handy pointers to the menu widget and active menu, and the parent
    // menu if there is one.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;
    psParentMenu = psMenu->psParent;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);

    //
    // If this widget has a child, that means that the child widget is in
    // control, and we are requested to go back to the previous menu item.
    // Process the child widget.
    //
    if(psWidget->psChild)
    {
        //
        // Call the widget de-activated callback function.  This notifies the
        // application that the widget is being deactivated.
        //
        if(psMenuWidget->pfnActive)
        {
            psMenuWidget->pfnActive(psWidget->psChild,
                                   &psMenu->psSlideMenuItems[psMenu->ui32FocusIndex],
                                   0);
        }

        //
        // Unlink the child widget from the slide menu widget.  The menu
        // widget will now no longer have a child widget.
        //
        psWidget->psChild->psParent = 0;
        psWidget->psChild = 0;

        //
        // Fill a rectangle with the child widget background color.  This will
        // erase everything else that is shown on the widget but leave the
        // background, which will make the change visually less jarring.
        // This is done in off-screen buffer B, which is the buffer that is
        // going to be slid off the screen.
        //
        GrContextForegroundSet(
            &sContext,
            psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].ui32ChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);
    }

    //
    // Otherwise there is not a child widget in control, so process the parent
    // menu, if there is one.
    //
    else if(psParentMenu)
    {
        //
        // Render the current menu into the off-screen buffer B.  This will be
        // the same menu appearance that is currently on the display.
        //
        SlideMenuDraw(psMenuWidget, &sContext, 0);

        //
        // Now switch the widget to the parent menu
        //
        psMenuWidget->psSlideMenu = psParentMenu;
    }

    //
    // Otherwise, we are already at the top level menu and there is nothing
    // else to do.
    //
    else
    {
        return(1);
    }

    //
    // Draw the new menu in the second offscreen buffer.  This is the menu
    // that will be on the display when the animation is over.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the width of the menu widget.
    //
    ui32MenuWidth = psMenuWidget->psDisplayA->ui16Width;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a left-to-right.  This will provide an appearance
    // of sliding to the right.  The parent menu will slide in from the left.
    // The "old" child menu is being held in off-screen buffer B and the new
    // one is in buffer A.  So when we are done, the correct image will be in
    // buffer A.
    //
    for(ui32X = 0; ui32X <= ui32MenuWidth; ui32X += 8)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32X,
                    psWidget->sPosition.i16YMin);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32X - ui32MenuWidth,
                    psWidget->sPosition.i16YMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}

//*****************************************************************************
//
//! Handles menu selection, in response to the "select" button.
//!
//! \param psWidget is a pointer to the slide menu widget to use for a
//! select operation.
//!
//! This function will allow for checking or unchecking multi-selectable
//! menu items.  If the menu does not allow multiple selection, then it
//! treats it as a "right" button press.
//!
//! \return Returns a non-zero value if the key was handled.  Returns 0 if the
//! key was not handled.
//
//*****************************************************************************
static int32_t
SlideMenuClick(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;

    //
    // If a child widget is in control then there is nothing to do.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget and current menu.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;

    //
    // Check to see if this menu allows multiple selection.
    //
    if(psMenu->bMultiSelectable)
    {
        //
        // Toggle the selection status of the currently highlighted menu
        // item, and then repaint it.
        //
        psMenu->ui32SelectedFlags ^= 1 << psMenu->ui32FocusIndex;
        SlideMenuPaint(psWidget);

        //
        // We are done so return indication that we handled the key event.
        //
        return(1);
    }

    //
    // Otherwise, treat the select button the same as a right button.
    //
    return(SlideMenuRight(psWidget));
}

//*****************************************************************************
//
//! Process key/button event to decide how to move the sliding menu.
//!
//! \param psWidget is a pointer to the slide menu widget to process.
//! \param ui32Msg is the message containing the key event.
//!
//! This function is used to specifically handle key events destined for the
//! slide menu widget.  It decides which menu movement function should be
//! called for each key event.
//!
//! \return Returns an indication if the key was handled.  Non-zero if the
//! key event was handled or else 0.
//
//*****************************************************************************
static int32_t
SlideMenuMove(tWidget *psWidget, uint32_t ui32Msg)
{
    //
    // Process the key event.
    //
    switch(ui32Msg)
    {
        //
        // User presses select button.
        //
        case WIDGET_MSG_KEY_SELECT:
        {
            return(SlideMenuClick(psWidget));
        }

        //
        // User presses up button.
        //
        case WIDGET_MSG_KEY_UP:
        {
            return(SlideMenuUp(psWidget));
        }

        //
        // User presses down button.
        //
        case WIDGET_MSG_KEY_DOWN:
        {
            return(SlideMenuDown(psWidget));
        }

        //
        // User presses left button.
        //
        case WIDGET_MSG_KEY_LEFT:
        {
            return(SlideMenuLeft(psWidget));
        }

        //
        // User presses right button.
        //
        case WIDGET_MSG_KEY_RIGHT:
        {
            return(SlideMenuRight(psWidget));
        }

        //
        // This is an unexpected event.  Return an indication that the event
        // was not handled.
        //
        default:
        {
            return(0);
        }
    }
}

//*****************************************************************************
//
//! Handles messages for a slide menu widget.
//!
//! \param psWidget is a pointer to the slide menu widget.
//! \param ui32Msg is the message.
//! \param ui32Param1 is the first parameter to the message.
//! \param ui32Param2 is the second parameter to the message.
//!
//! This function receives messages intended for this slide menu widget and
//! processes them accordingly.  The processing of the message varies based on
//! the message in question.
//!
//! Unrecognized messages are handled by calling WidgetDefaultMsgProc().
//!
//! \return Returns a value appropriate to the supplied message.
//
//*****************************************************************************
int32_t
SlideMenuMsgProc(tWidget *psWidget, uint32_t ui32Msg, uint32_t ui32Param1,
              uint32_t ui32Param2)
{
    //
    // Check the arguments.
    //
    ASSERT(psWidget);

    //
    // Determine which message is being sent.
    //
    switch(ui32Msg)
    {
        //
        // The widget paint request has been sent.
        //
        case WIDGET_MSG_PAINT:
        {
            //
            // Handle the widget paint request.
            //
            SlideMenuPaint(psWidget);

            //
            // Return one to indicate that the message was successfully
            // processed.
            //
            return(1);
        }

        //
        // A key event has been received.  By convention, this widget will
        // process the key events if ui32Param1 is set to this widget.
        // Otherwise a different widget has the "focus" for key events.
        //
        case WIDGET_MSG_KEY_SELECT:
        case WIDGET_MSG_KEY_UP:
        case WIDGET_MSG_KEY_DOWN:
        case WIDGET_MSG_KEY_LEFT:
        case WIDGET_MSG_KEY_RIGHT:
        {
            //
            // If this key event is for us, then process the event.
            //
            if((tWidget *)ui32Param1 == psWidget)
            {
                return(SlideMenuMove(psWidget, ui32Msg));
            }
        }

        //
        // An unknown request has been sent.  This widget does not handle
        // pointer events, so they get dumped here if they occur.
        //
        default:
        {
            //
            // Let the default message handler process this message.
            //
            return(WidgetDefaultMsgProc(psWidget, ui32Msg, ui32Param1,
                                        ui32Param2));
        }
    }
}

//*****************************************************************************
//
//! Initializes a slide menu widget.
//!
//! \param psWidget is a pointer to the slide menu widget to initialize.
//! \param psDisplay is a pointer to the display on which to draw the menu.
//! \param i32X is the X coordinate of the upper left corner of the canvas.
//! \param i32Y is the Y coordinate of the upper left corner of the canvas.
//! \param i32Width is the width of the canvas.
//! \param i32Height is the height of the canvas.
//! \param psDisplayOffA is one of two off-screen displays used for rendering.
//! \param psDisplayOffB is one of two off-screen displays used for rendering.
//! \param ui32ItemHeight is the height of a menu item
//! \param ui32Foreground is the foreground color used for menu item boundaries
//! and text.
//! \param ui32Background is the background color of a menu item.
//! \param ui32Highlight is the color of a highlighted menu item.
//! \param psFont is a pointer to the font that should be used for text.
//! \param psMenu is the initial menu to display
//!
//! This function initializes the caller provided slide menu widget.
//!
//! \return None.
//
//*****************************************************************************
void
SlideMenuInit(tSlideMenuWidget *psWidget, const tDisplay *psDisplay,
              int32_t i32X, int32_t i32Y, int32_t i32Width, int32_t i32Height,
              tDisplay *psDisplayOffA, tDisplay *psDisplayOffB,
              uint32_t ui32ItemHeight, uint32_t ui32Foreground,
              uint32_t ui32Background, uint32_t ui32Highlight,
              tFont *psFont, tSlideMenu *psMenu)
{
    uint32_t ui32Idx;

    //
    // Check the arguments.
    //
    ASSERT(psWidget);
    ASSERT(psDisplay);
    ASSERT(psDisplayOffA);
    ASSERT(psDisplayOffB);
    ASSERT(psFont);
    ASSERT(psMenu);

    //
    // Clear out the widget structure.
    //
    for(ui32Idx = 0; ui32Idx < sizeof(tSlideMenuWidget); ui32Idx += 4)
    {
        ((uint32_t *)psWidget)[ui32Idx / 4] = 0;
    }

    //
    // Set the size of the widget structure.
    //
    psWidget->sBase.i32Size = sizeof(tSlideMenuWidget);

    //
    // Mark this widget as fully disconnected.
    //
    psWidget->sBase.psParent = 0;
    psWidget->sBase.psNext = 0;
    psWidget->sBase.psChild = 0;

    //
    // Save the display pointer.
    //
    psWidget->sBase.psDisplay = psDisplay;

    //
    // Set the extents of the display area.
    //
    psWidget->sBase.sPosition.i16XMin = i32X;
    psWidget->sBase.sPosition.i16YMin = i32Y;
    psWidget->sBase.sPosition.i16XMax = i32X + i32Width - 1;
    psWidget->sBase.sPosition.i16YMax = i32Y + i32Height - 1;

    //
    // Initialize the widget fields
    //
    psWidget->psDisplayA = psDisplayOffA;
    psWidget->psDisplayB = psDisplayOffB;
    psWidget->ui32MenuItemHeight = ui32ItemHeight;
    psWidget->ui32ColorForeground = ui32Foreground;
    psWidget->ui32ColorBackground = ui32Background;
    psWidget->ui32ColorHighlight = ui32Highlight;
    psWidget->psFont = psFont;
    psWidget->psSlideMenu = psMenu;

    //
    // Use the slide menu message handler to process messages to this widget.
    //
    psWidget->sBase.pfnMsgProc = SlideMenuMsgProc;
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************