1
0

menu.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef _MILKDROP_MENU_H_
  25. #define _MILKDROP_MENU_H_ 1
  26. //----------------------------------------
  27. #include <windows.h>
  28. //----------------------------------------
  29. typedef enum {
  30. MENUITEMTYPE_BUNK,
  31. MENUITEMTYPE_BOOL,
  32. MENUITEMTYPE_INT,
  33. MENUITEMTYPE_FLOAT,
  34. MENUITEMTYPE_LOGFLOAT,
  35. MENUITEMTYPE_BLENDABLE,
  36. MENUITEMTYPE_LOGBLENDABLE,
  37. MENUITEMTYPE_STRING,
  38. MENUITEMTYPE_UIMODE,
  39. //MENUITEMTYPE_OSC,
  40. } MENUITEMTYPE;
  41. #define MAX_CHILD_MENUS 16
  42. typedef void (*MilkMenuCallbackFnPtr)(LPARAM param1, LPARAM param2); // MilkMenuCallbackFnPtr is synonym for "pointer to function returning void, and taking 2 lparams"
  43. //----------------------------------------
  44. class CMilkMenuItem
  45. {
  46. public:
  47. CMilkMenuItem();
  48. ~CMilkMenuItem();
  49. wchar_t m_szName[64];
  50. wchar_t m_szToolTip[1024];
  51. MENUITEMTYPE m_type;
  52. float m_fMin; // note: has different meanings based on the MENUITEMTYPE
  53. float m_fMax; // note: has different meanings based on the MENUITEMTYPE
  54. unsigned int m_wParam;
  55. unsigned int m_lParam;
  56. MilkMenuCallbackFnPtr m_pCallbackFn; // Callback Function pointer; if non-NULL, this functino will be called whenever the menu item is modified by the user.
  57. ptrdiff_t m_var_offset; // dist of variable's mem loc., in bytes, from pg->m_pState.
  58. LPARAM m_original_value; // can hold a float or int
  59. int m_nLastCursorPos; // for strings; remembers most recent pos. of the cursor
  60. bool m_bEnabled;
  61. // special data used for MENUITEMTYPE_OSCILLATOR:
  62. //int m_nSubSel;
  63. //bool m_bEditingSubSel;
  64. CMilkMenuItem *m_pNext;
  65. };
  66. //----------------------------------------
  67. //----------------------------------------
  68. class CMilkMenu
  69. {
  70. public:
  71. CMilkMenu();
  72. ~CMilkMenu();
  73. void Init(wchar_t *szName);
  74. void Finish();
  75. void AddChildMenu(CMilkMenu *pChildMenu);
  76. void AddItem(wchar_t *szName, void *var, MENUITEMTYPE type, wchar_t *szToolTip,
  77. float min=0, float max=0, MilkMenuCallbackFnPtr pCallback=NULL,
  78. unsigned int wParam=0, unsigned int lParam=0);
  79. void SetParentPointer(CMilkMenu *pParentMenu) { m_pParentMenu = pParentMenu; }
  80. LRESULT HandleKeydown(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  81. void DrawMenu(RECT rect, int xR, int yB, int bCalcRect=0, RECT* pCalcRect=NULL);
  82. void OnWaitStringAccept(wchar_t *szNewString);
  83. void EnableItem(wchar_t* szName, bool bEnable);
  84. CMilkMenuItem* GetCurItem() // NOTE: ONLY WORKS IF AN *ITEM* IS HIGHLIGHTED; NOT A CHILD MENU
  85. {
  86. CMilkMenuItem *pItem = m_pFirstChildItem;
  87. for (int i=m_nChildMenus; i < m_nCurSel; i++)
  88. pItem = pItem->m_pNext;
  89. return pItem;
  90. }
  91. const wchar_t* GetName() { return m_szMenuName; }
  92. void Enable(bool bEnabled) { m_bEnabled = bEnabled; }
  93. bool IsEnabled() { return m_bEnabled; }
  94. bool ItemIsEnabled(int i);
  95. protected:
  96. void Reset();
  97. CMilkMenu *m_pParentMenu;
  98. CMilkMenu *m_ppChildMenu[MAX_CHILD_MENUS]; // pointers are kept here, but these should be cleaned up by the app.
  99. CMilkMenuItem *m_pFirstChildItem; // linked list; these are dynamically allocated, and automatically cleaned up in destructor
  100. wchar_t m_szMenuName[64];
  101. int m_nChildMenus;
  102. int m_nChildItems;
  103. int m_nCurSel;
  104. bool m_bEditingCurSel;
  105. bool m_bEnabled;
  106. };
  107. //----------------------------------------
  108. #endif //_MILKDROP_MENU_H_