| 1 | // Aseprite UI Library | 
|---|
| 2 | // Copyright (C) 2020-2022  Igara Studio S.A. | 
|---|
| 3 | // Copyright (C) 2001-2018  David Capello | 
|---|
| 4 | // | 
|---|
| 5 | // This file is released under the terms of the MIT license. | 
|---|
| 6 | // Read LICENSE.txt for more information. | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef UI_MENU_H_INCLUDED | 
|---|
| 9 | #define | 
|---|
| 10 | #pragma once | 
|---|
| 11 |  | 
|---|
| 12 | #include "obs/signal.h" | 
|---|
| 13 | #include "ui/register_message.h" | 
|---|
| 14 | #include "ui/separator.h" | 
|---|
| 15 | #include "ui/widget.h" | 
|---|
| 16 | #include "ui/window.h" | 
|---|
| 17 |  | 
|---|
| 18 | #include <memory> | 
|---|
| 19 |  | 
|---|
| 20 | namespace ui { | 
|---|
| 21 |  | 
|---|
| 22 | class MenuBoxWindow; | 
|---|
| 23 | class MenuItem; | 
|---|
| 24 | class Timer; | 
|---|
| 25 | struct ; | 
|---|
| 26 |  | 
|---|
| 27 | class  : public Widget { | 
|---|
| 28 | public: | 
|---|
| 29 | (); | 
|---|
| 30 | (); | 
|---|
| 31 |  | 
|---|
| 32 | void (const gfx::Point& pos, | 
|---|
| 33 | Display* parentDisplay); | 
|---|
| 34 | Widget* (const char* id) const; | 
|---|
| 35 |  | 
|---|
| 36 | // Returns the MenuItem that has as submenu this menu. | 
|---|
| 37 | MenuItem* () { | 
|---|
| 38 | return m_menuitem; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | obs::signal<void()> ; | 
|---|
| 42 |  | 
|---|
| 43 | protected: | 
|---|
| 44 | virtual void (PaintEvent& ev) override; | 
|---|
| 45 | virtual void (ResizeEvent& ev) override; | 
|---|
| 46 | virtual void (SizeHintEvent& ev) override; | 
|---|
| 47 | virtual void (); | 
|---|
| 48 |  | 
|---|
| 49 | private: | 
|---|
| 50 | void (MenuItem* ) { | 
|---|
| 51 | m_menuitem = ownerMenuItem; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | void (); | 
|---|
| 55 |  | 
|---|
| 56 | MenuItem* (); | 
|---|
| 57 | void (MenuItem* , bool click, bool , bool select_first_child); | 
|---|
| 58 | void (); | 
|---|
| 59 |  | 
|---|
| 60 | MenuItem* ;         // From where the menu was open | 
|---|
| 61 |  | 
|---|
| 62 | friend class MenuBox; | 
|---|
| 63 | friend class MenuItem; | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | class  : public Widget { | 
|---|
| 67 | public: | 
|---|
| 68 | (WidgetType type = kMenuBoxWidget); | 
|---|
| 69 | (); | 
|---|
| 70 |  | 
|---|
| 71 | Menu* (); | 
|---|
| 72 | void (Menu* ); | 
|---|
| 73 |  | 
|---|
| 74 | MenuBaseData* () { | 
|---|
| 75 | return m_base.get(); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | // Closes all menu-boxes and goes back to the normal state of the | 
|---|
| 79 | // menu-bar. | 
|---|
| 80 | void (); | 
|---|
| 81 |  | 
|---|
| 82 | protected: | 
|---|
| 83 | virtual bool (Message* msg) override; | 
|---|
| 84 | virtual void (ResizeEvent& ev) override; | 
|---|
| 85 | virtual void (SizeHintEvent& ev) override; | 
|---|
| 86 | MenuBaseData* (); | 
|---|
| 87 |  | 
|---|
| 88 | private: | 
|---|
| 89 | void (); | 
|---|
| 90 | void (); | 
|---|
| 91 | void (); | 
|---|
| 92 |  | 
|---|
| 93 | std::unique_ptr<MenuBaseData> ; | 
|---|
| 94 |  | 
|---|
| 95 | friend class Menu; | 
|---|
| 96 | friend class MenuItem; | 
|---|
| 97 | }; | 
|---|
| 98 |  | 
|---|
| 99 | class  : public MenuBox { | 
|---|
| 100 | public: | 
|---|
| 101 | enum class  { ,  }; | 
|---|
| 102 |  | 
|---|
| 103 | (ProcessTopLevelShortcuts processShortcuts); | 
|---|
| 104 |  | 
|---|
| 105 | bool () const { | 
|---|
| 106 | return m_processTopLevelShortcuts; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | static bool expandOnMouseover(); | 
|---|
| 110 | static void setExpandOnMouseover(bool state); | 
|---|
| 111 |  | 
|---|
| 112 | private: | 
|---|
| 113 | // True if we should open top-level menus with Alt+mnemonic (this | 
|---|
| 114 | // flag is not used by Aseprite), top-level menus are opened with | 
|---|
| 115 | // the ShowMenu command now. | 
|---|
| 116 | bool ; | 
|---|
| 117 | static bool m_expandOnMouseover; | 
|---|
| 118 | }; | 
|---|
| 119 |  | 
|---|
| 120 | class  : public Widget { | 
|---|
| 121 | public: | 
|---|
| 122 | (const std::string& text); | 
|---|
| 123 | (); | 
|---|
| 124 |  | 
|---|
| 125 | Menu* (); | 
|---|
| 126 | void (Menu* ); | 
|---|
| 127 |  | 
|---|
| 128 | // Open the submenu of this menu item (the menu item should be | 
|---|
| 129 | // positioned in a correct position on the screen). | 
|---|
| 130 | void (); | 
|---|
| 131 |  | 
|---|
| 132 | bool () const; | 
|---|
| 133 | void (bool state); | 
|---|
| 134 |  | 
|---|
| 135 | // Returns true if the MenuItem has a submenu. | 
|---|
| 136 | bool () const; | 
|---|
| 137 |  | 
|---|
| 138 | // Returns true if the submenu is opened. | 
|---|
| 139 | bool () const { | 
|---|
| 140 | return (m_submenu_menubox != nullptr); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | // Returns the menu-box where the sub-menu has been opened, or | 
|---|
| 144 | // just nullptr if the sub-menu is closed. | 
|---|
| 145 | MenuBox* () const { | 
|---|
| 146 | return m_submenu_menubox; | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 | void (); | 
|---|
| 150 | void (); | 
|---|
| 151 |  | 
|---|
| 152 | // Fired when the menu item is clicked. | 
|---|
| 153 | obs::signal<void()> ; | 
|---|
| 154 |  | 
|---|
| 155 | protected: | 
|---|
| 156 | bool (Message* msg) override; | 
|---|
| 157 | void (InitThemeEvent& ev) override; | 
|---|
| 158 | void (PaintEvent& ev) override; | 
|---|
| 159 | void (SizeHintEvent& ev) override; | 
|---|
| 160 | virtual void (); | 
|---|
| 161 | virtual void (); | 
|---|
| 162 |  | 
|---|
| 163 | bool () const; | 
|---|
| 164 |  | 
|---|
| 165 | private: | 
|---|
| 166 | void (bool select_first); | 
|---|
| 167 | void (bool last_of_close_chain); | 
|---|
| 168 | void (); | 
|---|
| 169 | void (); | 
|---|
| 170 |  | 
|---|
| 171 | bool ;           // Is it highlighted? | 
|---|
| 172 | Menu* ;              // The sub-menu | 
|---|
| 173 | MenuBox* ;   // The opened menubox for this menu-item | 
|---|
| 174 | std::unique_ptr<Timer> ; // Timer to open the submenu | 
|---|
| 175 |  | 
|---|
| 176 | friend class Menu; | 
|---|
| 177 | friend class MenuBox; | 
|---|
| 178 | friend class MenuBoxWindow; | 
|---|
| 179 | }; | 
|---|
| 180 |  | 
|---|
| 181 | class  : public Separator { | 
|---|
| 182 | public: | 
|---|
| 183 | () : Separator( "", HORIZONTAL) { | 
|---|
| 184 | } | 
|---|
| 185 | }; | 
|---|
| 186 |  | 
|---|
| 187 | class  : public Window { | 
|---|
| 188 | public: | 
|---|
| 189 | (MenuItem*  = nullptr); | 
|---|
| 190 | (); | 
|---|
| 191 | MenuBox* () { return &m_menubox; } | 
|---|
| 192 | protected: | 
|---|
| 193 | bool (Message* msg) override; | 
|---|
| 194 | private: | 
|---|
| 195 | MenuBox ; | 
|---|
| 196 | MenuItem* ; | 
|---|
| 197 | }; | 
|---|
| 198 |  | 
|---|
| 199 | extern RegisterMessage ; | 
|---|
| 200 | extern RegisterMessage ; | 
|---|
| 201 | extern RegisterMessage ; | 
|---|
| 202 | extern RegisterMessage ; | 
|---|
| 203 |  | 
|---|
| 204 | } // namespace ui | 
|---|
| 205 |  | 
|---|
| 206 | #endif | 
|---|
| 207 |  | 
|---|