| 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 TOGGLE_WIDGET_HXX |
| 19 | #define TOGGLE_WIDGET_HXX |
| 20 | |
| 21 | #include "Widget.hxx" |
| 22 | #include "Command.hxx" |
| 23 | |
| 24 | /* ToggleWidget */ |
| 25 | class ToggleWidget : public Widget, public CommandSender |
| 26 | { |
| 27 | public: |
| 28 | // Commands emitted by this commandsender |
| 29 | enum { |
| 30 | kItemDataChangedCmd = 'TWch', |
| 31 | kSelectionChangedCmd = 'TWsc' |
| 32 | }; |
| 33 | |
| 34 | public: |
| 35 | ToggleWidget(GuiObject* boss, const GUI::Font& font, |
| 36 | int x, int y, int cols, int rows, |
| 37 | int clicksToChange = 2); |
| 38 | virtual ~ToggleWidget() = default; |
| 39 | |
| 40 | const BoolArray& getState() { return _stateList; } |
| 41 | bool getSelectedState() const { return _stateList[_selectedItem]; } |
| 42 | |
| 43 | bool wantsFocus() const override { return true; } |
| 44 | |
| 45 | int colWidth() const { return _colWidth; } |
| 46 | void setEditable(bool editable) { _editable = editable; } |
| 47 | bool isEditable() const { return _editable; } |
| 48 | |
| 49 | protected: |
| 50 | |
| 51 | protected: |
| 52 | int _rows; |
| 53 | int _cols; |
| 54 | int _currentRow; |
| 55 | int _currentCol; |
| 56 | int _rowHeight; // explicitly set in child classes |
| 57 | int _colWidth; // explicitly set in child classes |
| 58 | int _selectedItem; |
| 59 | int _clicksToChange; // number of clicks to register a change |
| 60 | bool _editable; |
| 61 | |
| 62 | BoolArray _stateList; |
| 63 | BoolArray _changedList; |
| 64 | |
| 65 | private: |
| 66 | void drawWidget(bool hilite) override = 0; |
| 67 | int findItem(int x, int y); |
| 68 | |
| 69 | void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; |
| 70 | void handleMouseUp(int x, int y, MouseButton b, int clickCount) override; |
| 71 | void handleMouseEntered() override; |
| 72 | void handleMouseLeft() override; |
| 73 | bool handleKeyDown(StellaKey key, StellaMod mod) override; |
| 74 | void handleCommand(CommandSender* sender, int cmd, int data, int id) override; |
| 75 | |
| 76 | // Following constructors and assignment operators not supported |
| 77 | ToggleWidget() = delete; |
| 78 | ToggleWidget(const ToggleWidget&) = delete; |
| 79 | ToggleWidget(ToggleWidget&&) = delete; |
| 80 | ToggleWidget& operator=(const ToggleWidget&) = delete; |
| 81 | ToggleWidget& operator=(ToggleWidget&&) = delete; |
| 82 | }; |
| 83 | |
| 84 | #endif |
| 85 | |