1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_GUI_CONTEXT_MENU_H_INCLUDED__
6
#define __C_GUI_CONTEXT_MENU_H_INCLUDED__
8
#include "IrrCompileConfig.h"
9
#ifdef _IRR_COMPILE_WITH_GUI_
11
#include "IGUIContextMenu.h"
12
#include "irrString.h"
21
//! GUI Context menu interface.
22
class CGUIContextMenu : public IGUIContextMenu
27
CGUIContextMenu(IGUIEnvironment* environment,
28
IGUIElement* parent, s32 id, core::rect<s32> rectangle,
29
bool getFocus = true, bool allowFocus = true);
32
virtual ~CGUIContextMenu();
34
//! set behaviour when menus are closed
35
virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose);
37
//! get current behaviour when the menue will be closed
38
virtual ECONTEXT_MENU_CLOSE getCloseHandling() const;
40
//! Returns amount of menu items
41
virtual u32 getItemCount() const;
44
virtual u32 addItem(const wchar_t* text, s32 commandid,
45
bool enabled, bool hasSubMenu, bool checked, bool autoChecking);
47
//! Insert a menu item at specified position.
48
virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled,
49
bool hasSubMenu, bool checked, bool autoChecking);
51
//! Find a item which has the given CommandId starting from given index
52
virtual s32 findItemWithCommandId(s32 commandId, u32 idxStartSearch) const;
54
//! Adds a separator item to the menu
55
virtual void addSeparator();
57
//! Returns text of the menu item.
58
virtual const wchar_t* getItemText(u32 idx) const;
60
//! Sets text of the menu item.
61
virtual void setItemText(u32 idx, const wchar_t* text);
63
//! Returns if a menu item is enabled
64
virtual bool isItemEnabled(u32 idx) const;
66
//! Sets if the menu item should be enabled.
67
virtual void setItemEnabled(u32 idx, bool enabled);
69
//! Returns if a menu item is checked
70
virtual bool isItemChecked(u32 idx) const;
72
//! Sets if the menu item should be checked.
73
virtual void setItemChecked(u32 idx, bool enabled);
75
//! Removes a menu item
76
virtual void removeItem(u32 idx);
78
//! Removes all menu items
79
virtual void removeAllItems();
81
//! called if an event happened.
82
virtual bool OnEvent(const SEvent& event);
84
//! draws the element and its children
87
//! Returns the selected item in the menu
88
virtual s32 getSelectedItem() const;
90
//! Returns a pointer to the submenu of an item.
91
//! \return Pointer to the submenu of an item.
92
virtual IGUIContextMenu* getSubMenu(u32 idx) const;
94
//! Sets the visible state of this element.
95
virtual void setVisible(bool visible);
97
//! should the element change the checked status on clicking
98
virtual void setItemAutoChecking(u32 idx, bool autoChecking);
100
//! does the element change the checked status on clicking
101
virtual bool getItemAutoChecking(u32 idx) const;
103
//! Returns command id of a menu item
104
virtual s32 getItemCommandId(u32 idx) const;
106
//! Sets the command id of a menu item
107
virtual void setItemCommandId(u32 idx, s32 id);
109
//! Adds a sub menu from an element that already exists.
110
virtual void setSubMenu(u32 index, CGUIContextMenu* menu);
112
//! When an eventparent is set it receives events instead of the usual parent element
113
virtual void setEventParent(IGUIElement *parent);
115
//! Writes attributes of the element.
116
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
118
//! Reads attributes of the element
119
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
123
void closeAllSubMenus();
124
bool hasOpenSubMenu() const;
133
core::dimension2d<u32> Dim;
135
CGUIContextMenu* SubMenu;
139
virtual void recalculateSize();
141
//! returns true, if an element was highlighted
142
virtual bool highlight(const core::position2d<s32>& p, bool canOpenSubMenu);
144
//! sends a click Returns:
145
//! 0 if click went outside of the element,
146
//! 1 if a valid button was clicked,
147
//! 2 if a nonclickable element was clicked
148
virtual u32 sendClick(const core::position2d<s32>& p);
150
//! returns the item highlight-area
151
virtual core::rect<s32> getHRect(const SItem& i, const core::rect<s32>& absolute) const;
153
//! Gets drawing rect of Item
154
virtual core::rect<s32> getRect(const SItem& i, const core::rect<s32>& absolute) const;
157
core::array<SItem> Items;
158
core::position2d<s32> Pos;
159
IGUIElement* EventParent;
161
ECONTEXT_MENU_CLOSE CloseHandling;
168
} // end namespace gui
169
} // end namespace irr
171
#endif // _IRR_COMPILE_WITH_GUI_
173
#endif // __C_GUI_CONTEXT_MENU_H_INCLUDED__