Menu.h & MenuItem.h

Description: The following is code from GTest, and not part of the original Genesis3d engine

Source file: …\genesis3d\src\MENU.H and Source file: …\genesis3d\src\MENUITEM.H

Contents:

Types: Menu_T, MenuItem_T, Menu_ItemType, MenuItemText_T, MenuItemSlider_T, MenuItemField_T, MenuItemString_T, MenuItemGraphic_T, MenuItemToggle_T, MenuItemChecked_T

Functions: AddItem, Create, Destroy, Draw, FlagField, FlagString, GetCheckedData, GetIdentifier, GetSliderPercent, GetStringText, Key, SetFieldText SetSliderPercent, SetSliderText, SetStringText, ToggleItem

Notes: view

Constants:

#define MENUITEM_MAX_CHECKED_LABEL (100)

#define MENU_MAXSTRINGSIZE 64

Return to Contents

Types:

Menu_T

typedef struct {
    geEngine*              Engine; // engine in which menu will be drawn
    int32                      Width; // menu width
    int32                      Top,Bottom; // menu top and bottom (bottom-top = height)
    int32                      ItemWidth, ItemHeight; // dimensions of all menu items
    int32                      x, y; // menu location
    int32                      ItemCount; // how many items are in the menu
    int32                      Identifier; // numeric menu identifier
    MenuItem_T*        Head; // head of the menu
    MenuItem_T *      Current; // current active menu item
    int32                      MinimumSelectedY; // minimum allowed y value for top of selected menu item
    int32                      MaximumSelectedY; // maximum allowed y value for bottom of selected menu item
} Menu_T;

Return to Contents

 

MenuItem_T

generic menu item
typedef struct tag_MenuItem_T {
    // adjacent menu items
    struct tag_MenuItem_T*      Next;
    struct tag_MenuItem_T*      Prev;

    // data
    int32                                    Identifier; // unique menu item identifier
    Menu_ItemType                  ItemType; // what type of item it is
    int32                                    MaxWidth; // max item width
    int32                                    MaxHeight; // max item height
    void*                                   Data; // item data
} MenuItem_T;

Return to Contents

 

Menu_ItemType

Supported menu items.
typedef enum {
    Menu_ItemText = 0,
    Menu_ItemGraphic,
    Menu_ItemSlider,
    Menu_ItemField,
    Menu_ItemString,
    Menu_ItemToggle,
    Menu_ItemChecked
} Menu_ItemType;

Return to Contents

 

MenuItemText_T

Text menu item.
typedef struct {
    char*          Text; // text
    int32           TextLength; // length of text
    FontType    NormalFont; // regular font
    FontType    SelectFont; // selected font
} MenuItemText_T;

Return to Contents

 

MenuItemSlider_T

Slider menu item.
typedef struct {
    char*         Text; // text
    int32          TextLength; // length of text
    FontType   NormalFont; // regular font
    FontType   SelectFont; // selected font
    geBitmap*  Range; // slider range art
    geBitmap*  Bar; // slider bar art
    int32          Slack; // amount of dead pixels in slider range art
    float           Percent; // what percentage slider is at
    float           Increment; // increment amount
} MenuItemSlider_T;

Return to Contents

 

MenuItemField_T

Field menu item.
typedef struct {
    char*          FieldName; // field name text
    int32           FieldNameLength; // length of field name text
    char            FieldTextData[MENU_MAXSTRINGSIZE]; // data text
    int32           FieldTextDataLength; // length of data text
    FontType    NormalFont; // regular font
    FontType    SelectFont; // selected font
    geBoolean  AwaitingChange; // field is awaiting input flag
} MenuItemField_T;

Return to Contents

 

MenuItemString_T

String menu item.
typedef struct {
    char*         StringLabel; // string label text
    int32          StringLabelLength; // length of string label text
    char           StringData[MENU_MAXSTRINGSIZE]; // string data text
    int32          StringDataLength; // length of string data text
    FontType   NormalFont; // regular font
    FontType   SelectFont; // selected font
    geBoolean AwaitingInput; // string is awaiting input flag
} MenuItemString_T;

Return to Contents

 

MenuItemGraphic_T

// Graphic menu item.
typedef struct {
    geBitmap*   Art; // graphic art
    int32            x, y; // graphic location
} MenuItemGraphic_T;

Return to Contents

 

MenuItemToggle_T

// Toggle menu item.
typedef struct {
    char*         ToggleLabel; // toggle label text
    int32          ToggleLabelLength; // length of toggle label text
    char           ToggleData1[MENU_MAXSTRINGSIZE]; // toggle data text
    int32          ToggleData1Length; // length of toggle data text
    char           ToggleData2[MENU_MAXSTRINGSIZE]; // toggle data text
    int32          ToggleData2Length; // length of toggle data text
    FontType   NormalFont; // regular font
    FontType   SelectFont; // selected font
    int32          ActiveItem; // currently active item
} MenuItemToggle_T;

Return to Contents

 

MenuItemChecked_T

// Checked menu item.

typedef struct {
    char           Label[MENUITEM_MAX_CHECKED_LABEL]; // label text
    int32          LabelLength; // length of label text
    FontType   NormalFont; // regular font
    FontType   SelectFont; // selected font
    int32          ActiveItem; // currently active item
    int32          LabelPosition; // left edge of label text ('check' is to the left)
    int32          UserData; // misc data.
} MenuItemChecked_T;

Return to Contents

 

Functions:

 

geBoolean  Menu_AddItem (Menu_T* Menu, Menu_ItemType ItemType, int32 Identifier, void* Data );

Add an item to a menu.

Creates an internal linked list MenuItem_T that stores information for Item.

Menu: menu to add item to
ItemType: what type of item to add
Identifier: user specified unique item identifier. Used for referencing menu item.
Data: item data. This should be a pointer to one of the following data structures, and should correspond to the type specified in ItemType parameter:
MenuItemText_T, MenuItemSlider_T, MenuItemField_T, MenuItemString_T, MenuItemGraphic_T, MenuItemToggle_T, MenuItemChecked_T

Note: based on GMenu code, I believe that the information in Data is copied to memory managed by Menu. Also, bitmaps associated with various types of menu items (i.e. the graphic for a slider bar) should be loaded, added to engine, and linked to the Data parameter prior to calling this function.

Return to Contents

Menu_T* Menu_Create (geEngine* Engine, int32 Width, int32 Top, int32 Bottom, int32 x, int32 y, int32 Identifier );

Create a new menu.

Engine: engine in which menu exists
Width: menu width
Top: top of menu
Bottom: bottom of menu (bottom-top = menu height)
x: x position
y: y position
Identifier: A user specified unique menu identifier. Used for referencing menu.

Return to Contents

geBoolean  Menu_Destroy (Menu_T** Menu );

Destroy a menu.

Menu: menu to destroy

Return to Contents

geBoolean  Menu_Draw (Menu_T* Menu );

Draw a new menu.

This must be called after each frame world rendering. Will draw the passed menu to the screen.

Return: GE_TRUE if successful

Menu: menu to draw

Return to Contents

geBoolean  Menu_FlagField (Menu_T* Menu, int32 Identifier, geBoolean  Flag );

Marks a field for change.

Menu: menu to search through
Identifier: field to be marked for change
Flag: new setting

Return to Contents

geBoolean  Menu_FlagString (Menu_T* Menu, int32 Identifier, geBoolean Flag );

Marks a string item for change or no change.

Menu: menu to search through
Identifier: string to be marked for change
Flag: new setting

Return to Contents

geBoolean Menu_GetCheckedData (Menu_T* Menu, int32 Identifier, int32* UserData );

Get extra data associated with menu item

Menu: menu to search through
Identifier: check item we want to get info from,
UserData: store the data here

Return to Contents

int32 Menu_GetIdentifier (Menu_T* Menu );

Gets a menu's identifier.

Menu: menu whose identifier we want

Return to Contents

float Menu_GetSliderPercent (Menu_T* Menu, int32 Identifier );

Get what percentage a slider is set at.

Menu: menu to search through
Identifier: slider whose percentage we want

Return to Contents

geBoolean  Menu_GetStringText (Menu_T* Menu, int32 Identifier, char* NewText );

Get a string items data.

Menu: menu to search through
Identifier: field whose text we want to set
NewText: text to set in string data

Return to Contents

int32 Menu_Key (Menu_T* Menu, int32 Key );

Pass a keystroke to a menu.

Handles arrow key keystrokes, and will move between menu elements, switch to submenus, adjust slider bars etc.

Returns: returns id of currently selected item

Menu: menu to receive the keystroke
Key: input keystroke

Return to Contents

geBoolean  Menu_SetFieldText (Menu_T* Menu, int32 Identifier, char* NewText );

Sets a fields text data.

Menu; menu to search through
Identifier: slider whose percentage we want
NewText: text to set in field text data

Return to Contents

float Menu_SetSliderPercent (Menu_T* Menu, int32 Identifier, float Percent);

Set what percentage

Menu: menu to search through
Identifier: slider whose percentage we want to set
Percent: new value

Return to Contents

float Menu_SetSliderText (Menu_T* Menu, int32 Identifier, char* NewText);

Change Slider Text

Menu: menu to search through
Identifier: slider whose text we want to set
NewText: new text

Return to Contents

geBoolean  Menu_SetStringText (Menu_T* Menu, int32 Identifier, char* NewText );

Sets a string items data.

Menu: menu to search through
Identifier: field whose text we want to set
NewText: text to set in string data

Return to Contents

geBoolean  Menu_ToggleItem (Menu_T* Menu, int32 Identifier );

Toggle a menu item.

Menu: menu to search through
Identifier: toggle to be toggled

Return to Contents

Notes:

 

 

Return to Contents