C Language Development Kit/Snippets/Menu/ShowGraphMenu

From OptiWiki

Jump to: navigation, search
Description Shows a graphical style menu that adjusts its layout depending on the terminal type.
Syntax
void ShowGraphMenu( sgraphMenu *menuItems, int nMax );
Arguments
sgrapMenu *menuItems
menuItems is a pointer to a structure that holds information about a menu item that is displayed in the menu. Besides the line of text of the menu item and a pointer to the image, this structure also contains a pointer to the function that needs to be executed when the menu item is selected.
typedef struct
{
    char text;                // the displayed line of text of the menu item
    unsigned char *picture;   // pointer the the image
    void (*funcitem)(void);   // pointer to the function that is executed on selection.
                              // the function must have the "void function( void )" format
                              // if the function pointer is set to NULL, then this
}sgraphMenu;                  // menu function returns on selection of this item.
int nMax
The number of menuItems that need to be displayed.
Returns None.
Remarks For OPL 97xx, DCL 153x, PHL 1300 and PHL 2700 the picture size that is used is 32*32 pixels. For PHL 1700 the images need to be 20*20 pixels.

For converting bitmaps to header file representations use the Bmpo2h tool. Set the options display size menu to Original, to keep the image original size settings.

Filling a menuItems[].funcitem with NULL causes the ShowGraphMenu() function to return (exit) when this menu item is selected. (Especially useful for terminals that have no CLR_KEY)

Important note when using the PHLxxxx:
Do not declare constant strings directly inside a structure, because the Microtec compiler will place such constant strings in RAM-memory instead of in ROM-memory. This means the string data will be lost as soon as the battery is empty or removed.

Therefore DO NOT declare strings inside a constant structure like in the following example:

const sgraphMenu mnuSetFont[] = {
    (char*)"Function 1", NULL, function1,    // This implementation causes "Function 1" to be
    (char*)"Function 2", NULL, function2     // placed in RAM-memory by the Microtec compiler
};                                           // (no matter what cast you use)!

Use the following implementation instead:

const char mnuTextFnc1[] = "Function 1";
const char mnuTextFnc2[] = "Function 2";
 
const stxtMenu mnuSetFont[] = {
    (char*)mnuTextFnc1, NULL, function1,     // This implementation causes "Function 1" to be
    (char*)mnuTextFnc2, NULL, function2      // placed in ROM-memory by the Microtec compiler, 
};                                           // so it can't be lost
Example
#include <stdio.h>
#include <stdlib.h>
 
#include "lib.h"
#include "menu.h"     //Holds the menu functions
#include "input.h"    //Holds the input functions
 
const char mnuTextA[] = "Menu item A";
const char mnuTextB[] = "Menu item B";
 
#if PHL
// 20*20 pixels images for the PHL1700
const unsigned char _disk[]=
{ 0x14, 0x14,
 0xFF, 0xFF, 0xEF, 0xA0, 0x00, 0xAF, 0xA0, 0x00, 
 0xAF, 0xA0, 0x00, 0xAF, 0xA0, 0x00, 0xAF, 0xA0, 
 0x00, 0xAF, 0xA0, 0x00, 0xAF, 0xA0, 0x00, 0xAF,
 0xA0, 0x00, 0xAF, 0xA0, 0x00, 0xAF, 0xBF, 0xFF, 
 0xAF, 0x80, 0x00, 0x2F, 0x80, 0x00, 0x2F, 0x87, 
 0xFF, 0xAF, 0x84, 0x02, 0xAF, 0x84, 0xC2, 0xAF,
 0x84, 0xC2, 0xAF, 0x84, 0xC2, 0xAF, 0x44, 0x02, 
 0xAF, 0x3F, 0xFF, 0xEF,
};
 
const unsigned char _version[]=
{ 0x14, 0x14,
 0x00, 0x7F, 0x0F, 0x00, 0x80, 0x8F, 0x01, 0x00, 
 0x4F, 0x01, 0x0C, 0x4F, 0x01, 0x12, 0x4F, 0x01, 
 0xF2, 0x4F, 0x00, 0x04, 0x4F, 0x3F, 0xD8, 0x4F,
 0x20, 0x20, 0x8F, 0x20, 0x21, 0x0F, 0x2F, 0xBE, 
 0x0F, 0x20, 0x00, 0x0F, 0x2F, 0xBE, 0x0F, 0x20, 
 0x22, 0x0F, 0x2F, 0xA2, 0x0F, 0x20, 0x3E, 0x0F,
 0x2F, 0xC8, 0x0F, 0x20, 0x08, 0x0F, 0x20, 0x08, 
 0x0F, 0x3F, 0xF8, 0x0F,
};
 
#else
// 32*32 pixels images for the PHL1300, PHL2700, OPL97xx and DCL153x
const unsigned char _disk[]=
{ 0x20, 0x20,
 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFE,
 0x42, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x42,
 0x5A, 0x00, 0x00, 0x5A, 0x5A, 0x00, 0x00, 0x5A,
 0x42, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x42,
 0x42, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x42,
 0x42, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x42,
 0x42, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x42,
 0x43, 0x00, 0x00, 0xC2, 0x41, 0xFF, 0xFF, 0x82,
 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
 0x40, 0x00, 0x00, 0x02, 0x40, 0xFF, 0xFF, 0x02,
 0x41, 0x80, 0x11, 0x02, 0x41, 0x00, 0x11, 0x02,
 0x41, 0x38, 0x11, 0x02, 0x41, 0x38, 0x11, 0x02,
 0x41, 0x38, 0x11, 0x02, 0x41, 0x38, 0x11, 0x02,
 0x61, 0x38, 0x11, 0x02, 0x31, 0x00, 0x11, 0x02,
 0x1F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00,
};
 
const unsigned char _version[]=
{ 0x20, 0x20,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0xFE, 0x00, 0x00, 0x03, 0x01, 0x80,
 0x00, 0x06, 0x00, 0xC0, 0x00, 0x08, 0x00, 0x40,
 0x00, 0x08, 0x38, 0x20, 0x00, 0x08, 0x44, 0x20,
 0x00, 0x08, 0x44, 0x20, 0x00, 0x0F, 0xC4, 0x20,
 0x00, 0x00, 0x08, 0x20, 0x07, 0xFF, 0xB0, 0x20,
 0x04, 0x00, 0x40, 0x40, 0x04, 0x00, 0x80, 0x80,
 0x04, 0x00, 0x81, 0x00, 0x04, 0x00, 0x82, 0x00,
 0x04, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x20, 0x00,
 0x04, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x82, 0x00,
 0x04, 0xFF, 0x82, 0x00, 0x04, 0x00, 0x82, 0x00,
 0x04, 0xFF, 0x82, 0x00, 0x04, 0x00, 0xFE, 0x00,
 0x04, 0xFF, 0x20, 0x00, 0x04, 0x00, 0x20, 0x00,
 0x04, 0x00, 0x20, 0x00, 0x04, 0x00, 0x20, 0x00,
 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#endif
 
void MenuA( void )
{
    setfont( LARGE_FONT, NULL );
    putchar('\f');
    printf("Menu A \Selected\nPress a key");
    WaitForKey();
}
 
void MenuB( void )
{
    setfont( LARGE_FONT, NULL );
    putchar('\f');
    printf("Menu B \Selected\nPress a key");
    WaitForKey();
}
 
const sgraphMenu graphMenu[] = {
        (char*)mnuTextA, _disk,    MenuA,
        (char*)mnuTextB, _version, MenuB,
        };
 
void main( void )
{
    InitGraphMenu();
    for(;;)
    {
        ShowGraphMenu( (sgraphMenu*) graphMenu, sizeof( graphMenu ) / sizeof( sgraphMenu ));
    }
}


Views
Personal tools