aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol/ControlMultiplexer.hpp
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
committerJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
commit46efbf05fcade8199035f956e20a63ca91fc88fd (patch)
tree9e3f3e297ea66e442e1a11b5ad16ad8ed6fc7fb7 /sons_of_sol/ControlMultiplexer.hpp
parent306bb687414f54177eb37ab7cd744e491c397c31 (diff)
downloadSonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.gz
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.bz2
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.zip
Run clang-format and add .clang-format
Diffstat (limited to 'sons_of_sol/ControlMultiplexer.hpp')
-rw-r--r--sons_of_sol/ControlMultiplexer.hpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/sons_of_sol/ControlMultiplexer.hpp b/sons_of_sol/ControlMultiplexer.hpp
index 33ae28d..025fdd0 100644
--- a/sons_of_sol/ControlMultiplexer.hpp
+++ b/sons_of_sol/ControlMultiplexer.hpp
@@ -19,77 +19,77 @@
#include <map>
#include <vector>
-class ControlMultiplexer :
- public slox::SloxKeyListener,
- public slox::SloxMouseMotionListener {
-public:
- /* Construct a new control multiplexer */
- ControlMultiplexer();
-
- /* Adds a listener to this ControlMultiplexer */
- inline void addControlMotionListener( ControlMotionListener* listener ) {
- m_motion_listeners.push_back( listener );
- }
-
- /* Called when a key is released. This event will be converted
+class ControlMultiplexer : public slox::SloxKeyListener,
+ public slox::SloxMouseMotionListener {
+ public:
+ /* Construct a new control multiplexer */
+ ControlMultiplexer();
+
+ /* Adds a listener to this ControlMultiplexer */
+ inline void addControlMotionListener(ControlMotionListener* listener) {
+ m_motion_listeners.push_back(listener);
+ }
+
+ /* Called when a key is released. This event will be converted
* into ControlMotionEvent and sent */
- virtual void onKeyUp( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyUp(const SDL_KeyboardEvent& evt);
- /* Called when there was a key press. This event may be converted
+ /* Called when there was a key press. This event may be converted
* into ControlMotionEvent which is then sent off to all
* the listeners. If there is no mapping then the motion
* event is not sent */
- virtual void onKeyDown( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyDown(const SDL_KeyboardEvent& evt);
- /* Called when the mouse is moved. This
+ /* Called when the mouse is moved. This
* is interpreted as a joystick event */
- virtual void onMouseMoved( const SDL_MouseMotionEvent& evt );
+ virtual void onMouseMoved(const SDL_MouseMotionEvent& evt);
- /* Called when there is an event that is called */
- void fireControlEvent( const ControlMotionEvent& evt );
+ /* Called when there is an event that is called */
+ void fireControlEvent(const ControlMotionEvent& evt);
- /* Adds a mapping from a key to a MotionEventType. Keys are represented
+ /* Adds a mapping from a key to a MotionEventType. Keys are represented
* as a 1 for pressed and 0 for not pressed, so some normalization must
* be done with a joystick in order to received the desired results */
- inline void setKeyMapping( SDLKey key, ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_keysym_map[ key ] = M_MapVal( to, mult );;
- }
+ inline void setKeyMapping(SDLKey key, ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_keysym_map[key] = M_MapVal(to, mult);
+ ;
+ }
- /* Removes a mapping from this multiplexer, such that
+ /* Removes a mapping from this multiplexer, such that
* a key of this type pressed will no longer fire that
* event */
- inline void removeKeyMapping( SDLKey key ) {
- m_keysym_map.erase( key );
- }
+ inline void removeKeyMapping(SDLKey key) { m_keysym_map.erase(key); }
- /* Sets a joystick axis mapping. If the joystick_index = 255 then it
+ /* Sets a joystick axis mapping. If the joystick_index = 255 then it
* is interpreted as the mouse */
- inline void setJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index,
- ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_joy_axis_map[ joystick_index << 8 | axis_index ] = M_MapVal( to, mult );
- }
-
- inline void removeJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index ) {
- m_joy_axis_map.erase( joystick_index << axis_index );
- }
-
-private:
- struct M_MapVal {
- inline M_MapVal( ControlMotionEvent::MotionEventType typ, float mult ) :
- type( typ ), multiplier( mult ) {}
- inline M_MapVal( ) : type( ControlMotionEvent::NONE ), multiplier( 0.0f ) {}
- ControlMotionEvent::MotionEventType type;
- float multiplier;
- };
- /* The listeners on this multiplexer */
- std::vector< ControlMotionListener* > m_motion_listeners;
-
- /* The keysym map */
- std::map< SDLKey, M_MapVal > m_keysym_map;
-
- /* Mapping of a bit oring of joystick index and axis index to
+ inline void setJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index,
+ ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_joy_axis_map[joystick_index << 8 | axis_index] = M_MapVal(to, mult);
+ }
+
+ inline void removeJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index) {
+ m_joy_axis_map.erase(joystick_index << axis_index);
+ }
+
+ private:
+ struct M_MapVal {
+ inline M_MapVal(ControlMotionEvent::MotionEventType typ, float mult)
+ : type(typ), multiplier(mult) {}
+ inline M_MapVal() : type(ControlMotionEvent::NONE), multiplier(0.0f) {}
+ ControlMotionEvent::MotionEventType type;
+ float multiplier;
+ };
+ /* The listeners on this multiplexer */
+ std::vector<ControlMotionListener*> m_motion_listeners;
+
+ /* The keysym map */
+ std::map<SDLKey, M_MapVal> m_keysym_map;
+
+ /* Mapping of a bit oring of joystick index and axis index to
* an event type */
- std::map< uint16_t, M_MapVal > m_joy_axis_map;
+ std::map<uint16_t, M_MapVal> m_joy_axis_map;
};
#endif /* CONTROLMULTIPLEXER_HPP_ */