summaryrefslogtreecommitdiff
path: root/boards/dk-tm4c129x/lang_demo/lang_demo.c
blob: 26ce3b6e7045866845212ab6f8720eb88d735a75 (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
//*****************************************************************************
//
// lang_demo.c - Demonstration of the TivaWare Graphics Library's string
//               table support.
//
// Copyright (c) 2013-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 DK-TM4C129X Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/container.h"
#include "grlib/pushbutton.h"
#include "grlib/radiobutton.h"
#include "utils/ustdlib.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "drivers/touch.h"
#include "drivers/pinout.h"
#include "images.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Graphics Library String Table Demonstration (lang_demo)</h1>
//!
//! This application provides a demonstration of the capabilities of the
//! TivaWare Graphics Library's string table functions.  Two panels show
//! different implementations of features of the string table functions.
//! For each panel, the bottom provides a forward and back button
//! (when appropriate).
//!
//! The first panel provides a large string with introductory text and basic
//! instructions for operation of the application.
//!
//! The second panel shows the available languages and allows them to be
//! switched between English, German, Spanish and Italian.
//!
//! The string table and custom fonts used by this application can be found
//! under /third_party/fonts/lang_demo.  The original strings that the
//! application intends displaying are found in the language.csv file (encoded
//! in UTF8 format to allow accented characters and Asian language ideographs
//! to be included.  The mkstringtable tool is used to generate two versions
//! of the string table, one which remains encoded in UTF8 format and the other
//! which has been remapped to a custom codepage allowing the table to be
//! reduced in size compared to the original UTF8 text.  The tool also produces
//! character map files listing each character used in the string table.  These
//! are then provided as input to the ftrasterize tool which generates two
//! custom fonts for the application, one indexed using Unicode and a smaller
//! one indexed using the custom codepage generated for this string table.
//!
//! The command line parameters required for mkstringtable and ftrasterize
//! can be found in the makefile in third_party/fonts/lang_demo.
//!
//! By default, the application builds to use the custom codepage version of
//! the string table and its matching custom font.  To build using the UTF8
//! string table and Unicode-indexed custom font, ensure that the definition of
//! \b USE_REMAPPED_STRINGS at the top of the lang_demo.c source file is
//! commented out.
//!
//*****************************************************************************

//*****************************************************************************
//
// Comment the following line to use a version of the string table and custom
// font that does not use codepage remapping.  In this version, the font is
// somewhat larger and character lookup will be slower but it has the advantage
// that the strings you retrieve from the string table are encoded exactly
// as they were in the original CSV file and are generally readable in your
// debugger (since they use a standard codepage like ISO8859-1 or UTF8).
//
//*****************************************************************************
#define USE_REMAPPED_STRINGS

#ifdef USE_REMAPPED_STRINGS
#include "langremap.h"
extern const unsigned char g_pui8Customr14pt[];
extern const unsigned char g_pui8Customr20pt[];

#define SPACE_CHAR MAP8000_CHAR_000020
#define FONT_20PT (const tFont *)g_pui8Customr20pt
#define FONT_14PT (const tFont *)g_pui8Customr14pt
#define STRING_TABLE g_pui8Tablelangremap
#define GRLIB_INIT_STRUCT g_sGrLibDefaultlangremap

#else

#include "language.h"

extern const unsigned char g_pui8Custom14pt[];
extern const unsigned char g_pui8Custom20pt[];

#define SPACE_CHAR 0x20
#define FONT_20PT (const tFont *)g_pui8Custom20pt
#define FONT_14PT (const tFont *)g_pui8Custom14pt

#define STRING_TABLE g_pui8Tablelanguage
#define GRLIB_INIT_STRUCT g_sGrLibDefaultlanguage

#endif

//*****************************************************************************
//
// The names for each of the panels, which is displayed at the bottom of the
// screen.
//
//*****************************************************************************
static const uint32_t g_ui32PanelNames[3] =
{
    STR_INTRO,
    STR_CONFIG,
    STR_UPDATE
};

//*****************************************************************************
//
// This string holds the title of the group of languages.  The size is fixed
// by LANGUAGE_MAX_SIZE since the names of the languages in this application
// are not larger than LANGUAGE_MAX_SIZE bytes.
//
//*****************************************************************************
#define LANGUAGE_MAX_SIZE       16
char g_pcLanguage[LANGUAGE_MAX_SIZE];

//*****************************************************************************
//
// This is a generic buffer that is used to retrieve strings from the string
// table.  This forces its size to be at least as big as the largest string
// in the string table which is defined by the SCOMP_MAX_STRLEN value.
//
//*****************************************************************************
char g_pcBuffer[SCOMP_MAX_STRLEN];

//*****************************************************************************
//
// This string holds the title of each "panel" in the application.  The size is
// fixed by TITLE_MAX_SIZE since the names of the panels in this application
// are not larger than TITLE_MAX_SIZE bytes.
//
//*****************************************************************************
#define TITLE_MAX_SIZE          20
char g_pcTitle[TITLE_MAX_SIZE];

//*****************************************************************************
//
// This table holds the array of languages supported.
//
//*****************************************************************************
typedef struct
{
    uint16_t ui16Language;
    bool bBreakOnSpace;
}
tLanguageParams;

const tLanguageParams g_psLanguageTable[] =
{
    { GrLangEnUS, true },
    { GrLangDe, true },
    { GrLangEsSP, true },
    { GrLangIt, true },
    { GrLangZhPRC, false },
    { GrLangKo, true },
    { GrLangJp, false }
};

#define NUM_LANGUAGES (sizeof(g_LanguageTable) / sizeof(tLanguageParams))

//*****************************************************************************
//
// The index of the current language in the g_psLanguageTable array.
//
//*****************************************************************************
uint32_t g_ui32LangIdx;

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// Forward declarations for the globals required to define the widgets at
// compile-time.
//
//*****************************************************************************
void OnPrevious(tWidget *psWidget);
void OnNext(tWidget *psWidget);
void OnIntroPaint(tWidget *psWidget, tContext *psContext);
void OnRadioChange(tWidget *psWidget, uint32_t bSelected);
extern tCanvasWidget g_psPanels[];

//*****************************************************************************
//
// The first panel, which contains introductory text explaining the
// application.
//
//*****************************************************************************
Canvas(g_sIntroduction, g_psPanels, 0, 0, &g_sKentec320x240x16_SSD2119, 8, 26,
       300, 154, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnIntroPaint);

//*****************************************************************************
//
// Storage for language name strings.  Note that we could hardcode these into
// the relevant widget initialization macros but since we may be using a
// custom font and remapped codepage, keeping the strings in the string table
// and loading them when the app starts is likely to create less confusion and
// prevents the risk of seeing garbled output if you accidentally use ASCII or
// ISO8859-1 text strings with the custom font.
//
//*****************************************************************************
#define MAX_LANGUAGE_NAME_LEN 10
char g_pcEnglish[MAX_LANGUAGE_NAME_LEN];
char g_pcDeutsch[MAX_LANGUAGE_NAME_LEN];
char g_pcEspanol[MAX_LANGUAGE_NAME_LEN];
char g_pcItaliano[MAX_LANGUAGE_NAME_LEN];
char g_pcChinese[MAX_LANGUAGE_NAME_LEN];
char g_pcKorean[MAX_LANGUAGE_NAME_LEN];
char g_pcJapanese[MAX_LANGUAGE_NAME_LEN];

//*****************************************************************************
//
// The language selection panel, which contains a selection of radio buttons
// for each language.
//
//*****************************************************************************
tContainerWidget g_psRadioContainers[];

tRadioButtonWidget g_psRadioButtons1[] =
{
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 1, 0,
                      &g_sKentec320x240x16_SSD2119, 18, 54, 120, 25,
                      RB_STYLE_TEXT | RB_STYLE_SELECTED, 16, 0, ClrSilver,
                      ClrSilver, FONT_20PT, g_pcEnglish, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 2, 0,
                      &g_sKentec320x240x16_SSD2119, 18, 82, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcDeutsch, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 3, 0,
                      &g_sKentec320x240x16_SSD2119, 180, 54, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcEspanol, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 4, 0,
                      &g_sKentec320x240x16_SSD2119, 180, 82, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcItaliano, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 5, 0,
                      &g_sKentec320x240x16_SSD2119, 18, 110, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcChinese, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 6, 0,
                      &g_sKentec320x240x16_SSD2119, 180, 110, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcKorean, 0, OnRadioChange),
    RadioButtonStruct(g_psRadioContainers, 0, 0,
                      &g_sKentec320x240x16_SSD2119, 18, 138, 120, 25,
                      RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, FONT_20PT,
                      g_pcJapanese, 0, OnRadioChange),
};

#define NUM_RADIO1_BUTTONS      (sizeof(g_psRadioButtons1) /   \
                                 sizeof(g_psRadioButtons1[0]))

tContainerWidget g_psRadioContainers[] =
{
    ContainerStruct(g_psPanels + 1, 0, g_psRadioButtons1,
                    &g_sKentec320x240x16_SSD2119, 8, 30, 300, 140,
                    CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrGray, ClrSilver,
                    FONT_20PT, g_pcLanguage),
};

//*****************************************************************************
//
// An array of canvas widgets, one per panel.  Each canvas is filled with
// black, overwriting the contents of the previous panel.
//
//*****************************************************************************
tCanvasWidget g_psPanels[] =
{
    CanvasStruct(0, 0, &g_sIntroduction, &g_sKentec320x240x16_SSD2119, 8, 22,
                 300, 158, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
    CanvasStruct(0, 0, g_psRadioContainers, &g_sKentec320x240x16_SSD2119, 8,
                 22, 300, 158, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
};

//*****************************************************************************
//
// The number of panels.
//
//*****************************************************************************
#define NUM_PANELS              (sizeof(g_psPanels) / sizeof(g_psPanels[0]))

//*****************************************************************************
//
// The buttons and text across the bottom of the screen.
//
//*****************************************************************************
char g_pcPlus[2];
char g_pcMinus[2];

RectangularButton(g_sPrevious, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 8, 180,
                  50, 50, PB_STYLE_FILL, ClrBlack, ClrBlack, 0, ClrSilver,
                  FONT_20PT, g_pcMinus, g_pui8Blue50x50, g_pui8Blue50x50Press,
                  0, 0, OnPrevious);
Canvas(g_sTitle, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 58, 180, 200, 50,
       CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE | CANVAS_STYLE_FILL, 0, 0,
       ClrSilver, FONT_20PT, 0, 0, 0);
RectangularButton(g_sNext, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 260, 180,
                  50, 50, PB_STYLE_IMG | PB_STYLE_TEXT, ClrBlack, ClrBlack, 0,
                  ClrSilver, FONT_20PT, g_pcPlus, g_pui8Blue50x50,
                  g_pui8Blue50x50Press, 0, 0, OnNext);

//*****************************************************************************
//
// The panel that is currently being displayed.
//
//*****************************************************************************
uint32_t g_ui32Panel;

//*****************************************************************************
//
// Handles presses of the previous panel button.
//
//*****************************************************************************
void
OnPrevious(tWidget *psWidget)
{
    //
    // There is nothing to be done if the first panel is already being
    // displayed.
    //
    if(g_ui32Panel == 0)
    {
        return;
    }

    //
    // Remove the current panel.
    //
    WidgetRemove((tWidget *)(g_psPanels + g_ui32Panel));

    //
    // Decrement the panel index.
    //
    g_ui32Panel--;

    //
    // Add and draw the new panel.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ui32Panel));
    WidgetPaint((tWidget *)(g_psPanels + g_ui32Panel));

    //
    // Set the title of this panel.
    //
    GrStringGet(g_ui32PanelNames[g_ui32Panel], g_pcTitle, TITLE_MAX_SIZE);
    WidgetPaint((tWidget *)&g_sTitle);

    //
    // See if this is the first panel.
    //
    if(g_ui32Panel == 0)
    {
        //
        // Clear the previous button from the display since the first panel is
        // being displayed.
        //
        PushButtonImageOff(&g_sPrevious);
        PushButtonTextOff(&g_sPrevious);
        PushButtonFillOn(&g_sPrevious);
        WidgetPaint((tWidget *)&g_sPrevious);
    }

    //
    // See if the previous panel was the last panel.
    //
    if(g_ui32Panel == (NUM_PANELS - 2))
    {
        //
        // Display the next button.
        //
        PushButtonImageOn(&g_sNext);
        PushButtonTextOn(&g_sNext);
        PushButtonFillOff(&g_sNext);
        WidgetPaint((tWidget *)&g_sNext);
    }
}

//*****************************************************************************
//
// Handles presses of the next panel button.
//
//*****************************************************************************
void
OnNext(tWidget *psWidget)
{
    //
    // There is nothing to be done if the last panel is already being
    // displayed.
    //
    if(g_ui32Panel == (NUM_PANELS - 1))
    {
        return;
    }

    //
    // Remove the current panel.
    //
    WidgetRemove((tWidget *)(g_psPanels + g_ui32Panel));

    //
    // Increment the panel index.
    //
    g_ui32Panel++;

    //
    // Add and draw the new panel.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ui32Panel));
    WidgetPaint((tWidget *)(g_psPanels + g_ui32Panel));

    //
    // Set the title of this panel.
    //
    GrStringGet(g_ui32PanelNames[g_ui32Panel], g_pcTitle, TITLE_MAX_SIZE);
    WidgetPaint((tWidget *)&g_sTitle);

    //
    // See if the previous panel was the first panel.
    //
    if(g_ui32Panel == 1)
    {
        //
        // Display the previous button.
        //
        PushButtonImageOn(&g_sPrevious);
        PushButtonTextOn(&g_sPrevious);
        PushButtonFillOff(&g_sPrevious);
        WidgetPaint((tWidget *)&g_sPrevious);
    }

    //
    // See if this is the last panel.
    //
    if(g_ui32Panel == (NUM_PANELS - 1))
    {
        //
        // Clear the next button from the display since the last panel is being
        // displayed.
        //
        PushButtonImageOff(&g_sNext);
        PushButtonTextOff(&g_sNext);
        PushButtonFillOn(&g_sNext);
        WidgetPaint((tWidget *)&g_sNext);
    }
}

//*****************************************************************************
//
// Switch out all of the dynamic strings.
//
//*****************************************************************************
void
ChangeLanguage(uint16_t ui16Language)
{
    //
    // Change the language.
    //
    GrStringLanguageSet(ui16Language);

    //
    // Update the Language string.
    //
    GrStringGet(STR_LANGUAGE, g_pcLanguage, LANGUAGE_MAX_SIZE);

    //
    // Update the title string.
    //
    GrStringGet(g_ui32PanelNames[g_ui32Panel], g_pcTitle, TITLE_MAX_SIZE);
}

//*****************************************************************************
//
// Handles wrapping a string within an area.
//
// \param psContext is the context of the area to update.
// \param pcString is the string to print out.
// \param i32LineHeight is the height of a character in the currrent font.
// \param i32X is the x position to start printing this string.
// \param i32Y is the y position to start printing this string.
// \param bSplitOnSpace is true if strings in the current language must be
// split only on space characters or false if they may be split between any
// two characters.
//
// \return Returns the number of lines that were printed due to this string.
//
//*****************************************************************************
uint32_t
DrawStringWrapped(tContext *psContext, char *pcString,
                  int32_t i32LineHeight, int32_t i32X, int32_t i32Y,
                  bool bSplitOnSpace)
{
    uint32_t ui32Width, ui32CharWidth, ui32StrWidth, ui32Char;
    uint32_t ui32Lines, ui32Skip;
    char *pcStart, *pcEnd;
    char *pcLastSpace;

    ui32Lines = 0;

    //
    // Get the number of pixels we have to fit the string into across the
    // screen.
    //
    ui32Width = GrContextDpyWidthGet(psContext) - 16 - i32X;

    //
    // Get a pointer to the terminating zero.
    //
    pcEnd = pcString;
    while(*pcEnd)
    {
        pcEnd++;
    }

    //
    // The first substring we draw will start at the beginning of the string.
    //
    pcStart = pcString;
    pcLastSpace = pcString;
    ui32StrWidth = 0;

    //
    // Keep processing until we have no more characters to display.
    //
    do
    {
        //
        // Get the next character in the string.
        //
        ui32Char = GrStringNextCharGet(psContext, pcString,
                                       (pcEnd - pcString), &ui32Skip);

        //
        // Did we reach the end of the string?
        //
        if(ui32Char)
        {
            //
            // No - how wide is this character?
            //
            ui32CharWidth = GrStringWidthGet(psContext, pcString, ui32Skip);

            //
            // Have we run off the edge of the display?
            //
            if((ui32StrWidth + ui32CharWidth) > ui32Width)
            {
                //
                // If we are splitting on spaces, rewind the string pointer to
                // the byte after the last space.
                //
                if(bSplitOnSpace)
                {
                    pcString = pcLastSpace;
                }

                //
                // Yes - draw the substring.
                //
                GrStringDraw(psContext, pcStart, (pcString - pcStart),
                             i32X, i32Y, 0);

                //
                // Increment the line count and move the y position down by the
                // current font's line height.
                //
                ui32Lines++;
                i32Y += i32LineHeight;
                ui32StrWidth = 0;

                //
                // The next string we draw will start at the current position.
                //
                pcStart = pcString;
            }
            else
            {
                //
                // No - update the width and move on to the next character.
                //
                ui32StrWidth += ui32CharWidth;
                pcString += ui32Skip;

                //
                // If this is a space, remember where we are.
                //
                if(ui32Char == SPACE_CHAR)
                {
                    pcLastSpace = pcString;
                }
            }
        }
        else
        {
            //
            // Do we have any remaining chunk of string to draw?
            //
            if(pcStart != pcString)
            {
                //
                // Yes - draw the last section of string.
                //
                GrStringDraw(psContext, pcStart, -1, i32X, i32Y, 0);
                ui32Lines++;
            }
        }
    } while(ui32Char);

    return(ui32Lines);
}

//*****************************************************************************
//
// Handles paint requests for the introduction canvas widget.
//
//*****************************************************************************
void
OnIntroPaint(tWidget *psWidget, tContext *psContext)
{
    int32_t i32LineHeight, i32Offset;
    uint32_t ui32Lines;

    i32LineHeight = GrFontHeightGet(FONT_14PT);
    i32Offset = 28;

    //
    // Display the introduction text in the canvas.
    //
    GrContextFontSet(psContext, FONT_14PT);
    GrContextForegroundSet(psContext, ClrSilver);

    //
    // Write the first paragraph of the introduction page.
    //
    GrStringGet(STR_INTRO_1, g_pcBuffer, SCOMP_MAX_STRLEN);
    ui32Lines = DrawStringWrapped(psContext, g_pcBuffer, i32LineHeight, 8,
                              i32Offset,
                              g_psLanguageTable[g_ui32LangIdx].bBreakOnSpace);
    //
    // Move down by 1/4 of a line between paragraphs.
    //
    i32Offset += i32LineHeight/4;

    //
    // Write the second paragraph of the introduction page.
    //
    GrStringGet(STR_INTRO_2, g_pcBuffer, SCOMP_MAX_STRLEN);
    ui32Lines += DrawStringWrapped(psContext, g_pcBuffer, i32LineHeight, 8,
                              i32Offset + (ui32Lines * i32LineHeight),
                              g_psLanguageTable[g_ui32LangIdx].bBreakOnSpace);
    //
    // Move down by 1/4 of a line between paragraphs.
    //
    i32Offset += i32LineHeight/4;

    //
    // Write the third paragraph of the introduction page.
    //
    GrStringGet(STR_INTRO_3, g_pcBuffer, SCOMP_MAX_STRLEN);
    DrawStringWrapped(psContext, g_pcBuffer, i32LineHeight, 8, i32Offset +
        (ui32Lines * i32LineHeight),
        g_psLanguageTable[g_ui32LangIdx].bBreakOnSpace );
}

//*****************************************************************************
//
// Handles change notifications for the radio button widgets.
//
//*****************************************************************************
void
OnRadioChange(tWidget *psWidget, uint32_t bSelected)
{
    //
    // Find the index of this radio button in the first group.
    //
    for(g_ui32LangIdx = 0; g_ui32LangIdx < NUM_RADIO1_BUTTONS; g_ui32LangIdx++)
    {
        if(psWidget == (tWidget *)(g_psRadioButtons1 + g_ui32LangIdx))
        {
            break;
        }
    }

    //
    // Change any dynamic language strings.
    //
    ChangeLanguage(g_psLanguageTable[g_ui32LangIdx].ui16Language);

    //
    // Issue the initial paint request to the widgets.
    //
    WidgetPaint(WIDGET_ROOT);
}

//*****************************************************************************
//
// A simple demonstration of the features of the TivaWare Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Set graphics library text rendering defaults.
    //
    GrLibInit(&GRLIB_INIT_STRUCT);

    //
    // Set the string table and the default language.
    //
    GrStringTableSet(STRING_TABLE);

    //
    // Set the default language.
    //
    ChangeLanguage(GrLangEnUS);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "lang-demo");

    //
    // Load the static strings from the string table.  These strings are
    // independent of the language in use but we store them in the string
    // table nonetheless since (a) we may be using codepage remapping in
    // which case it would be difficult to hardcode them into the app source
    // anyway (ASCII or ISO8859-1 text would not render properly with the
    // remapped custom font) and (b) even if we're not using codepage remapping,
    // we may have generated a custom font from the string table output and
    // we want to make sure that all glyphs required by the application are
    // present in that font.  If we hardcode some text in the application
    // source and don't put it in the string table, we run the risk of having
    // characters missing in the font.
    //
    GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN);
    GrStringGet(STR_PLUS, g_pcPlus, 2);
    GrStringGet(STR_MINUS, g_pcMinus, 2);

    //
    // Initialize the touch screen driver and have it route its messages to the
    // widget tree.
    //
    TouchScreenInit(ui32SysClock);
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the title block and the previous and next buttons to the widget
    // tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext);

    //
    // Add the first panel to the widget tree.
    //
    g_ui32Panel = 0;
    WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels);

    //
    // Set the string for the title.
    //
    CanvasTextSet(&g_sTitle, g_pcTitle);

    //
    // Issue the initial paint request to the widgets.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Loop forever, processing widget messages.
    //
    while(1)
    {
        //
        // Process any messages in the widget message queue.
        //
        WidgetMessageQueueProcess();
    }

}