2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#ifndef IRR_C_GUI_CONTEXT_MENU_H_INCLUDED
|
|
|
|
#define IRR_C_GUI_CONTEXT_MENU_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#include "IrrCompileConfig.h"
|
|
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
|
|
|
#include "IGUIContextMenu.h"
|
|
|
|
#include "irrString.h"
|
|
|
|
#include "irrArray.h"
|
|
|
|
#include "IGUIFont.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
|
|
|
//! GUI Context menu interface.
|
|
|
|
class CGUIContextMenu : public IGUIContextMenu
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CGUIContextMenu(IGUIEnvironment* environment,
|
|
|
|
IGUIElement* parent, s32 id, core::rect<s32> rectangle,
|
|
|
|
bool getFocus = true, bool allowFocus = true);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CGUIContextMenu();
|
|
|
|
|
|
|
|
//! set behavior when menus are closed
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! get current behavior when the menue will be closed
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ECONTEXT_MENU_CLOSE getCloseHandling() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns amount of menu items
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual u32 getItemCount() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Adds a menu item.
|
|
|
|
virtual u32 addItem(const wchar_t* text, s32 commandid,
|
2021-08-27 14:55:10 +02:00
|
|
|
bool enabled, bool hasSubMenu, bool checked, bool autoChecking) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Insert a menu item at specified position.
|
|
|
|
virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled,
|
2021-08-27 14:55:10 +02:00
|
|
|
bool hasSubMenu, bool checked, bool autoChecking) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Find a item which has the given CommandId starting from given index
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 findItemWithCommandId(s32 commandId, u32 idxStartSearch) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Adds a separator item to the menu
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void addSeparator() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns text of the menu item.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const wchar_t* getItemText(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets text of the menu item.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setItemText(u32 idx, const wchar_t* text) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns if a menu item is enabled
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isItemEnabled(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the menu item should be enabled.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setItemEnabled(u32 idx, bool enabled) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns if a menu item is checked
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isItemChecked(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the menu item should be checked.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setItemChecked(u32 idx, bool enabled) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Removes a menu item
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void removeItem(u32 idx) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Removes all menu items
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void removeAllItems() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! called if an event happened.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool OnEvent(const SEvent& event) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! draws the element and its children
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void draw() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the selected item in the menu
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getSelectedItem() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns a pointer to the submenu of an item.
|
|
|
|
//! \return Pointer to the submenu of an item.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUIContextMenu* getSubMenu(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the visible state of this element.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setVisible(bool visible) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! should the element change the checked status on clicking
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setItemAutoChecking(u32 idx, bool autoChecking) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! does the element change the checked status on clicking
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getItemAutoChecking(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns command id of a menu item
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getItemCommandId(u32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the command id of a menu item
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setItemCommandId(u32 idx, s32 id) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Adds a sub menu from an element that already exists.
|
|
|
|
virtual void setSubMenu(u32 index, CGUIContextMenu* menu);
|
|
|
|
|
|
|
|
//! When an eventparent is set it receives events instead of the usual parent element
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setEventParent(IGUIElement *parent) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Writes attributes of the element.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Reads attributes of the element
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void closeAllSubMenus();
|
|
|
|
bool hasOpenSubMenu() const;
|
|
|
|
|
|
|
|
struct SItem
|
|
|
|
{
|
|
|
|
core::stringw Text;
|
|
|
|
bool IsSeparator;
|
|
|
|
bool Enabled;
|
|
|
|
bool Checked;
|
|
|
|
bool AutoChecking;
|
|
|
|
core::dimension2d<u32> Dim;
|
|
|
|
s32 PosY;
|
|
|
|
CGUIContextMenu* SubMenu;
|
|
|
|
s32 CommandId;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void recalculateSize();
|
|
|
|
|
|
|
|
//! returns true, if an element was highlighted
|
|
|
|
virtual bool highlight(const core::position2d<s32>& p, bool canOpenSubMenu);
|
|
|
|
|
|
|
|
//! sends a click Returns:
|
|
|
|
//! 0 if click went outside of the element,
|
|
|
|
//! 1 if a valid button was clicked,
|
|
|
|
//! 2 if a nonclickable element was clicked
|
|
|
|
virtual u32 sendClick(const core::position2d<s32>& p);
|
|
|
|
|
|
|
|
//! returns the item highlight-area
|
|
|
|
virtual core::rect<s32> getHRect(const SItem& i, const core::rect<s32>& absolute) const;
|
|
|
|
|
|
|
|
//! Gets drawing rect of Item
|
|
|
|
virtual core::rect<s32> getRect(const SItem& i, const core::rect<s32>& absolute) const;
|
|
|
|
|
|
|
|
|
|
|
|
core::array<SItem> Items;
|
|
|
|
core::position2d<s32> Pos;
|
|
|
|
IGUIElement* EventParent;
|
|
|
|
IGUIFont *LastFont;
|
|
|
|
ECONTEXT_MENU_CLOSE CloseHandling;
|
|
|
|
s32 HighLighted;
|
|
|
|
u32 ChangeTime;
|
|
|
|
bool AllowFocus;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#endif // IRR_C_GUI_CONTEXT_MENU_H_INCLUDED
|