GLOW API version 1.0 reference

Back to
Table of contents


class GlowMenu

General information

type: class
inherits: (none)
module: glow

GlowMenu encapsulates a menu. It provides facilities for manipulating the structure of the menu, as well as the type of notification desired when an item is chosen from it. A GlowMenu must be attached to a GlowSubwindow to be used.

There are two types of items that can be present in a menu: normal items and submenu items. Normal items are identified by a text label and an integer code, which is provided to the object receiving notification of the menu selection. Submenu items are identified by a text label and a pointer to another GlowMenu object. Items may also be marked, which prepends a short string to the label. Items are numbered starting at 0.

GLOW programs that make use of menus will utilize the GlowMenu class.

Constants

Binding settings
These constants specify the type of notification desired when a menu item is chosen. Defined as an enumeration of type GlowMenu::BindState.

enum GlowMenu::BindState bindNone

Perform no explicit notification. However, a subclass of GlowMenu may still override the OnHit() method to gain notification of menu choices.

enum GlowMenu::BindState bindNormal

Notify by binding Notifier() to GlowMenuReceiver(s).

enum GlowMenu::BindState bindSubwindow

Notify by invoking the OnDirectMenuHit() method of the appropriate GlowSubWindow.

Methods

Constructor and destructor

GlowMenu(void)

Creates a new GlowMenu with no items. Also creates the corresponding GLUT menu.

virtual ~GlowMenu(void)

The destructor for GlowMenu deletes the corresponding GLUT menu.

Adding and removing items

void AddEntry(const char* label, int code)

Appends a normal item to the menu, with the given label and code.

void AddSubmenu(const char* label, GlowMenu* menu)

Appends a submenu item to the menu, with the given label and menu.

void InsertEntry(int itemNum, const char* label, int code)

Inserts a normal item in the menu at the given itemNum position, with the given label and code.

void InsertSubmenu(int itemNum, const char* label, GlowMenu* menu)

Inserts a submenu item in the menu at the given itemNum position, with the given label and menu.

void RemoveItem(int itemNum)

Removes an item from the menu.

int NumItems(void) const

Returns the number of items in the menu.

Manipulating an item's label
These methods manipulate the label for a menu item. You may also specify a mark string that is prepended to the item label, mark and unmark items, and search for marked items.

const char* GetItemLabel(int itemNum) const

Returns the label associated with an item. Does not include the mark, if any.

void SetItemLabel(int itemNum, const char* label)

Sets the label associated with an item. Does not affect the mark, if any.

const char* GetItemMark(int itemNum) const

Returns the mark string associated with an item. If the item is not marked, returns 0.

void SetItemMark(int itemNum, const char* mark)

Sets the mark associated with an item. If mark == 0, unmarks the item.

void ToggleItemMark(int itemNum, const char* mark)

If the item is marked, unmarks it; otherwise, sets the mark to the given string.

void UnmarkItem(int itemNum)

Unmarks the specified item. Has no effect if the item is already unmarked.

void UnmarkAllItems(void)

Unmarks all items in the menu.

bool IsItemMarked(int itemNum) const

Returns true if and only if the given item is marked.

int NextMarkedItem(int itemNum) const

Returns the item number of the first marked item > itemNum. Pass -1 to return the first marked item. If no more items are marked, returns -1.

Manipulating an item's attributes
These methods manipulate the other attributes of an item, including changing its type.

bool IsEntry(int itemNum) const

Returns true if and only if the item is a normal item.

bool IsSubmenu(int itemNum) const

Returns true if and only if the item is a submenu.

int GetItemCode(int itemNum) const

Returns the code associated with the specified normal item. Throws an assertion if the item is a submenu.

void SetItemCode(int itemNum, int code)

Sets the code associated with the specified item. If the item is a submenu, changes it to a normal item. Does not affect the label or the mark.

GlowMenu* GetItemSubmenu(int itemNum) const

Returns the submenu associated with the specified submenu item. Throws an assertion if the item is a normal item.

void SetItemSubmenu(int itemNum, GlowMenu* submenu)

Sets the submenu associated with the specified item. If the item is a normal item, changes it to a submenu. Does not affect the label or the mark.

void ChangeToEntry(int itemNum, const char* label, int code)

Changes the specified item to a normal item, and sets the label and code. Does not affect the mark.

void ChangeToSubmenu(int itemNum, const char* label, GlowMenu* submenu)

Changes the specified item to a submenu and sets the label and submenu. Does not affect the mark.

Managing notification
Several different notification methods are available for GlowMenus. The menu can broadcast a message to a set of GlowMenuReceivers, it can invoke the OnDirectMenuHit() method of the appropriate GlowSubwindow, or it can do nothing. In addition, this behavior can be overridden by overriding OnHit().

void SetBindState(GlowMenu::BindState state)

Sets the bind state to the specified value. Use the constants provided in GlowMenu.

GlowMenu::BindState GetBindState(void)

Returns the current bind behavior.

TSender<const GlowMenuMessage&>& Notifier(void)

Accesses the sender used by bindNormal. You should bind this sender to receivers interested in menu selection events.

Overrideable methods

Menu hit events

virtual void OnHit(int code, GlowSubwindow* window, int x, int y)

Override this method to customize the type of notification done on a menu choice. The default method performs notification based on the current bind state.

Back to
Table of contents


The GLOW Toolkit