PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: AbstractMenu.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLGUI_ABSTRACTMENU_H__ 00024 #define __PLGUI_ABSTRACTMENU_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLGui/Widgets/Widget.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLGui { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class Menu; 00044 class MenuItem; 00045 class PopupMenu; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * Abstract base class for widgets that display a menu 00054 */ 00055 class AbstractMenu : public Widget { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Class definition ] 00060 //[-------------------------------------------------------] 00061 pl_class(PLGUI_RTTI_EXPORT, AbstractMenu, "PLGui", PLGui::Widget, "Abstract base class for widgets that display a menu") 00062 // Signals 00063 pl_signal_1(SignalItemSelected, int, "Current selection has been changed", "") 00064 pl_signal_1(SignalItemClicked, MenuItem*, "A menu item has been clicked", "") 00065 pl_signal_1(SignalSubmenuOpened, MenuItem*, "A submenu has been opened", "") 00066 pl_signal_1(SignalSubmenuClosed, MenuItem*, "A submenu has been closed", "") 00067 pl_class_end 00068 00069 00070 //[-------------------------------------------------------] 00071 //[ Public functions ] 00072 //[-------------------------------------------------------] 00073 public: 00074 /** 00075 * @brief 00076 * Constructor 00077 * 00078 * @param[in] pParent 00079 * Pointer to parent widget 00080 */ 00081 PLGUI_API AbstractMenu(Widget *pParent = nullptr); 00082 00083 /** 00084 * @brief 00085 * Destructor 00086 */ 00087 PLGUI_API virtual ~AbstractMenu(); 00088 00089 /** 00090 * @brief 00091 * Get menu 00092 * 00093 * @return 00094 * Menu data 00095 */ 00096 PLGUI_API Menu *GetMenu() const; 00097 00098 /** 00099 * @brief 00100 * Set menu 00101 * 00102 * @param[in] pMenu 00103 * Menu data 00104 */ 00105 PLGUI_API void SetMenu(Menu *pMenu); 00106 00107 /** 00108 * @brief 00109 * Get orientation of menu widget 00110 * 00111 * @return 00112 * Orientation (horizontal or vertical) 00113 */ 00114 PLGUI_API EOrientation GetOrientation() const; 00115 00116 /** 00117 * @brief 00118 * Set orientation of menu widget 00119 * 00120 * @param[in] nOrientation 00121 * Orientation (horizontal or vertical) 00122 */ 00123 PLGUI_API void SetOrientation(EOrientation nOrientation); 00124 00125 /** 00126 * @brief 00127 * Get side on which is submenu is opened 00128 * 00129 * @param[in] nOrientation 00130 * Orientation 00131 * 00132 * @return 00133 * Side 00134 */ 00135 PLGUI_API ESide GetOpenSide(EOrientation nOrientation) const; 00136 00137 /** 00138 * @brief 00139 * Set side on which is submenu is opened 00140 * 00141 * @param[in] nOrientation 00142 * Orientation 00143 * @param[in] nSide 00144 * Side 00145 */ 00146 PLGUI_API void SetOpenSide(EOrientation nOrientation, ESide nSide); 00147 00148 /** 00149 * @brief 00150 * Get currently selected menu item 00151 * 00152 * @return 00153 * Index of selected menu item, or -1 if no menu item is currently selected 00154 */ 00155 PLGUI_API int GetSelection() const; 00156 00157 /** 00158 * @brief 00159 * Set currently selected menu item 00160 * 00161 * @param[in] nItem 00162 * Index of selected menu item, or -1 if no menu item is currently selected 00163 */ 00164 PLGUI_API void SetSelection(int nItem); 00165 00166 /** 00167 * @brief 00168 * Click on a menu item 00169 * 00170 * @param[in] nItem 00171 * Index of selected menu item, or -1 if no menu item is currently selected 00172 */ 00173 PLGUI_API void ClickItem(int nItem); 00174 00175 00176 //[-------------------------------------------------------] 00177 //[ Protected virtual AbstractMenu functions ] 00178 //[-------------------------------------------------------] 00179 protected: 00180 /** 00181 * @brief 00182 * Called when a menu item has been clicked 00183 * 00184 * @param[in] pItem 00185 * Menu item 00186 */ 00187 PLGUI_API virtual void OnItemClicked(MenuItem *pItem); 00188 00189 00190 //[-------------------------------------------------------] 00191 //[ Protected virtual Widget functions ] 00192 //[-------------------------------------------------------] 00193 protected: 00194 PLGUI_API virtual PLMath::Vector2i OnPreferredSize(const PLMath::Vector2i &vRefSize) const override; 00195 PLGUI_API virtual void OnMouseMove(const PLMath::Vector2i &vPos) override; 00196 PLGUI_API virtual void OnMouseButtonDown(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override; 00197 PLGUI_API virtual void OnMouseButtonUp(PLCore::uint32 nButton, const PLMath::Vector2i &vPos) override; 00198 PLGUI_API virtual void OnKeyDown(PLCore::uint32 nKey, PLCore::uint32 nModifiers) override; 00199 PLGUI_API virtual void OnGetFocus() override; 00200 PLGUI_API virtual void OnLooseFocus() override; 00201 00202 00203 //[-------------------------------------------------------] 00204 //[ Protected functions ] 00205 //[-------------------------------------------------------] 00206 protected: 00207 /** 00208 * @brief 00209 * Open submenu 00210 * 00211 * @param[in] pItem 00212 * Menu item 00213 * @param[in] nItem 00214 * Menu item index 00215 */ 00216 PLGUI_API void OpenSubmenu(MenuItem *pItem, int nItem); 00217 00218 /** 00219 * @brief 00220 * Close submenu 00221 */ 00222 PLGUI_API void CloseSubmenu(); 00223 00224 /** 00225 * @brief 00226 * Activate menu shortcut 00227 * 00228 * @param[in] nShortcut 00229 * ASCII value of shortcut 00230 */ 00231 PLGUI_API void PressShortcut(char nShortcut); 00232 00233 /** 00234 * @brief 00235 * Update menu data 00236 */ 00237 PLGUI_API void UpdateMenuData(); 00238 00239 /** 00240 * @brief 00241 * Delete menu data 00242 */ 00243 PLGUI_API void DeleteMenuData(); 00244 00245 /** 00246 * @brief 00247 * Check which item is selected based on mouse position 00248 * 00249 * @param[in] vPos 00250 * Current mouse position 00251 * 00252 * @return 00253 * Index of selected item, -1 if none 00254 */ 00255 PLGUI_API int GetItemFromMousePos(const PLMath::Vector2i &vPos); 00256 00257 /** 00258 * @brief 00259 * Set currently active menu in the chain of sub-menus 00260 * 00261 * @param[in] pMenu 00262 * Menu that shall be controlled by the keyboard 00263 */ 00264 PLGUI_API void SetControlledMenu(AbstractMenu *pMenu); 00265 00266 /** 00267 * @brief 00268 * Calculate size of menu item 00269 * 00270 * @param[in] nOrientation 00271 * Orientation 00272 * @param[in] pItem 00273 * Menu item 00274 * 00275 * @return 00276 * Size 00277 */ 00278 PLGUI_API PLMath::Vector2i CalculateItemSize(EOrientation nOrientation, MenuItem *pItem); 00279 00280 00281 //[-------------------------------------------------------] 00282 //[ Protected data types ] 00283 //[-------------------------------------------------------] 00284 protected: 00285 /** 00286 * @brief 00287 * Position and state data for a menu item 00288 */ 00289 struct SItem { 00290 PLMath::Vector2i vPos1; /**< Upper left position */ 00291 PLMath::Vector2i vPos2; /**< Lower right position */ 00292 }; 00293 00294 00295 //[-------------------------------------------------------] 00296 //[ Protected data ] 00297 //[-------------------------------------------------------] 00298 protected: 00299 // Menu data 00300 Menu *m_pMenu; /**< Menu that is displayed */ 00301 EOrientation m_nOrientation; /**< Menu orientation */ 00302 ESide m_nOpenSideHorizontal; /**< Side on which a submenu is opened (horizontal) */ 00303 ESide m_nOpenSideVertical; /**< Side on which a submenu is opened (vertical) */ 00304 int m_nSelection; /**< Currently selected item */ 00305 00306 // Internal data 00307 SItem *m_pItems; /**< Items */ 00308 int m_nItems; /**< Size of m_pItems */ 00309 int m_nSize; /**< Size of all items */ 00310 int m_nMaxWidth; /**< Max width of all items */ 00311 int m_nMouseOver; /**< Index of currently selected item */ 00312 MenuItem *m_pSelectedItem; /**< Currently open item */ 00313 PopupMenu *m_pPopupMenu; /**< Currently open submenu */ 00314 int m_nIgnoreMouse; /**< Ignore mouse-move events for n times */ 00315 AbstractMenu *m_pParentMenu; /**< Menu widget that has opened this menu widget */ 00316 AbstractMenu *m_pController; /**< Menu widget that has the control (focus) */ 00317 AbstractMenu *m_pControlMenu; /**< Menu that is currently controlled by the keyboard */ 00318 bool m_bAllowButtonUp; /**< Only right after popup, the release of the mouse button can cause a click-event */ 00319 00320 00321 }; 00322 00323 00324 //[-------------------------------------------------------] 00325 //[ Namespace ] 00326 //[-------------------------------------------------------] 00327 } // PLGui 00328 00329 00330 #endif // __PLGUI_ABSTRACTMENU_H__
|