| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #ifndef CONTEXT_MENU_HXX |
| 19 | #define |
| 20 | |
| 21 | #include "bspf.hxx" |
| 22 | #include "Command.hxx" |
| 23 | #include "Dialog.hxx" |
| 24 | #include "Variant.hxx" |
| 25 | |
| 26 | /** |
| 27 | * Popup context menu which, when clicked, "pop up" a list of items and |
| 28 | * lets the user pick on of them. |
| 29 | * |
| 30 | * Implementation wise, when the user selects an item, then the given 'cmd' |
| 31 | * is broadcast, with data being equal to the tag value of the selected entry. |
| 32 | * |
| 33 | * There are also several utility methods (named as sendSelectionXXX) that |
| 34 | * allow to cycle through the current items without actually opening the dialog. |
| 35 | */ |
| 36 | class : public Dialog, public CommandSender |
| 37 | { |
| 38 | public: |
| 39 | enum { |
| 40 | = 'CMsl' |
| 41 | }; |
| 42 | |
| 43 | public: |
| 44 | (GuiObject* boss, const GUI::Font& font, |
| 45 | const VariantList& items, int cmd = 0, int width = 0); |
| 46 | virtual () = default; |
| 47 | |
| 48 | /** Add the given items to the widget. */ |
| 49 | void (const VariantList& items); |
| 50 | |
| 51 | /** Show context menu onscreen at the specified coordinates */ |
| 52 | void (uInt32 x, uInt32 y, const Common::Rect& bossRect, int item = -1); |
| 53 | |
| 54 | /** Select the first entry matching the given tag. */ |
| 55 | void (const Variant& tag, const Variant& defaultTag); |
| 56 | |
| 57 | /** Select the entry at the given index. */ |
| 58 | void (int idx); |
| 59 | |
| 60 | /** Select the highest/last entry in the internal list. */ |
| 61 | void (); |
| 62 | |
| 63 | /** Clear selection (reset to default). */ |
| 64 | void (); |
| 65 | |
| 66 | /** Accessor methods for the currently selected item. */ |
| 67 | int () const; |
| 68 | const string& () const; |
| 69 | const Variant& () const; |
| 70 | |
| 71 | /** This dialog uses its own positioning, so we override Dialog::center() */ |
| 72 | void () override; |
| 73 | |
| 74 | /** The following methods are used when we want to select *and* |
| 75 | send a command for the new selection. They are only to be used |
| 76 | when the dialog *isn't* open, and are basically a shortcut so |
| 77 | that a PopUpWidget has some basic functionality without forcing |
| 78 | to open its associated ContextMenu. */ |
| 79 | bool (); |
| 80 | bool (); |
| 81 | bool (); |
| 82 | bool (); |
| 83 | |
| 84 | private: |
| 85 | void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; |
| 86 | void handleMouseMoved(int x, int y) override; |
| 87 | bool handleMouseClicks(int x, int y, MouseButton b) override; |
| 88 | void handleMouseWheel(int x, int y, int direction) override; |
| 89 | void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override; |
| 90 | void handleJoyDown(int stick, int button, bool longPress) override; |
| 91 | void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; |
| 92 | bool handleJoyHat(int stick, int hat, JoyHatDir vahdirlue, int button) override; |
| 93 | void handleEvent(Event::Type e); |
| 94 | |
| 95 | void () override; |
| 96 | |
| 97 | void (const Common::Rect& image); |
| 98 | |
| 99 | int (int x, int y) const; |
| 100 | void (int item); |
| 101 | |
| 102 | void (); |
| 103 | void (); |
| 104 | void (); |
| 105 | void (); |
| 106 | void (); |
| 107 | void (); |
| 108 | void (); |
| 109 | void (int distance = 1); |
| 110 | void (int distance = 1); |
| 111 | void (); |
| 112 | |
| 113 | private: |
| 114 | VariantList ; |
| 115 | |
| 116 | int ; |
| 117 | int , ; |
| 118 | int , ; |
| 119 | bool ; |
| 120 | bool ; |
| 121 | ColorId , ; |
| 122 | |
| 123 | int ; |
| 124 | |
| 125 | uInt32 , ; |
| 126 | uInt32 ; |
| 127 | |
| 128 | private: |
| 129 | // Following constructors and assignment operators not supported |
| 130 | () = delete; |
| 131 | (const ContextMenu&) = delete; |
| 132 | (ContextMenu&&) = delete; |
| 133 | ContextMenu& (const ContextMenu&) = delete; |
| 134 | ContextMenu& (ContextMenu&&) = delete; |
| 135 | }; |
| 136 | |
| 137 | #endif |
| 138 | |