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 EVENT_MAPPING_WIDGET_HXX |
19 | #define EVENT_MAPPING_WIDGET_HXX |
20 | |
21 | class DialogContainer; |
22 | class CommandSender; |
23 | class ButtonWidget; |
24 | class EditTextWidget; |
25 | class StaticTextWidget; |
26 | class StringListWidget; |
27 | class ; |
28 | class GuiObject; |
29 | class ComboDialog; |
30 | class InputDialog; |
31 | |
32 | #include "Widget.hxx" |
33 | #include "Command.hxx" |
34 | #include "bspf.hxx" |
35 | |
36 | class EventMappingWidget : public Widget, public CommandSender |
37 | { |
38 | friend class InputDialog; |
39 | |
40 | public: |
41 | EventMappingWidget(GuiObject* boss, const GUI::Font& font, |
42 | int x, int y, int w, int h, |
43 | EventMode mode); |
44 | virtual ~EventMappingWidget() = default; |
45 | |
46 | bool remapMode() { return myRemapStatus; } |
47 | |
48 | void setDefaults(); |
49 | |
50 | private: |
51 | enum { |
52 | kFilterCmd = 'filt', |
53 | kStartMapCmd = 'map ', |
54 | kStopMapCmd = 'smap', |
55 | kEraseCmd = 'eras', |
56 | kResetCmd = 'rest', |
57 | kComboCmd = 'cmbo' |
58 | }; |
59 | |
60 | bool handleKeyDown(StellaKey key, StellaMod mod) override; |
61 | bool handleKeyUp(StellaKey key, StellaMod mod) override; |
62 | void handleJoyDown(int stick, int button, bool longPress = false) override; |
63 | void handleJoyUp(int stick, int button) override; |
64 | void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; |
65 | bool handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) override; |
66 | |
67 | void loadConfig() override; |
68 | void saveConfig(); |
69 | |
70 | void handleCommand(CommandSender* sender, int cmd, int data, int id) override; |
71 | |
72 | void updateActions(); |
73 | void startRemapping(); |
74 | void eraseRemapping(); |
75 | void resetRemapping(); |
76 | void stopRemapping(); |
77 | |
78 | bool isRemapping() { return myRemapStatus; } |
79 | |
80 | void drawKeyMapping(); |
81 | void enableButtons(bool state); |
82 | |
83 | private: |
84 | ButtonWidget* myMapButton; |
85 | ButtonWidget* myCancelMapButton; |
86 | ButtonWidget* myEraseButton; |
87 | ButtonWidget* myResetButton; |
88 | ButtonWidget* myComboButton; |
89 | PopUpWidget* ; |
90 | StringListWidget* myActionsList; |
91 | EditTextWidget* myKeyMapping; |
92 | |
93 | ComboDialog* myComboDialog; |
94 | |
95 | // Since this widget can be used for different collections of events, |
96 | // we need to specify exactly which group of events we are remapping |
97 | EventMode myEventMode; |
98 | |
99 | // Since we can filter events, the event mode is not specific enough |
100 | Event::Group myEventGroup; |
101 | |
102 | // Indicates the event that is currently selected |
103 | int myActionSelected; |
104 | |
105 | // Indicates if we're currently in remap mode |
106 | // In this mode, the next event received is remapped to some action |
107 | bool myRemapStatus; |
108 | |
109 | // Joystick axes and hats can be more problematic than ordinary buttons |
110 | // or keys, in that there can be 'drift' in the values |
111 | // Therefore, we map these events when they've been 'released', rather |
112 | // than on their first occurrence (aka, when they're 'pressed') |
113 | // As a result, we need to keep track of their old values |
114 | int myLastStick, myLastHat; |
115 | JoyAxis myLastAxis; |
116 | JoyDir myLastDir; |
117 | JoyHatDir myLastHatDir; |
118 | |
119 | // Aggregates the modifier flags of the mapping |
120 | int myMod; |
121 | // Saves the last *pressed* key |
122 | int myLastKey; |
123 | // Saves the last *pressed* button |
124 | int myLastButton; |
125 | |
126 | bool myFirstTime; |
127 | |
128 | private: |
129 | // Following constructors and assignment operators not supported |
130 | EventMappingWidget() = delete; |
131 | EventMappingWidget(const EventMappingWidget&) = delete; |
132 | EventMappingWidget(EventMappingWidget&&) = delete; |
133 | EventMappingWidget& operator=(const EventMappingWidget&) = delete; |
134 | EventMappingWidget& operator=(EventMappingWidget&&) = delete; |
135 | }; |
136 | |
137 | #endif |
138 | |