Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
physical_controller.h
Go to the documentation of this file.
1#ifndef PHYSICAL_CONTROLLER_H
2#define PHYSICAL_CONTROLLER_H
3
4#include "ccfwd.h"
5#include "key_bindings.h"
6#include "mouse_bindings.h"
8#include "side.h"
9
10#include <iosfwd>
11
19{
20public:
21 explicit physical_controller(
24 const mouse_bindings& mbs = mouse_bindings()
25 );
26
28 [[nodiscard]] const key_bindings& get_key_bindings() const;
29
31 [[nodiscard]] const mouse_bindings& get_mouse_bindings() const;
32
33 [[nodiscard]] const physical_controller_type& get_type() const noexcept { return m_type; }
34
37 [[nodiscard]] user_inputs process_input(
38 const sf::Event& event,
39 const side player_side,
40 const game_view_layout& layout
41 ) const;
42
43 void set_type(const physical_controller_type t) noexcept { m_type = t; }
44
45private:
46
48 key_bindings m_key_bindings;
49
51 mouse_bindings m_mouse_bindings;
52
54
56 user_inputs process_key_press(
57 const sf::Event& event,
58 const side player_side
59 ) const;
60
62 user_inputs process_mouse_pressed(
63 const sf::Event& event,
64 const side player_side
65 ) const;
66
68 user_inputs process_mouse_moved(
69 const sf::Event& event,
70 const side player_side,
71 const game_view_layout& layout
72 ) const;
73};
74
78
81
83[[nodiscard]] sf::Event create_key_pressed_event(const sf::Keyboard::Key k);
84
88
90[[nodiscard]] sf::Event create_mouse_button_pressed_event(
91 const screen_coordinate& cursor_pos,
92 const sf::Mouse::Button mouse_button
93);
94
96[[nodiscard]] sf::Event create_mouse_moved_event(const screen_coordinate& cursor_pos);
97
101
103[[nodiscard]] sf::Keyboard::Key get_key_for_action(const physical_controller& c, const action_number& action);
104
109[[nodiscard]] std::string get_text_for_action(
110 const physical_controller& c,
111 const bool has_selected_units,
112 const bool is_promoting_pawn,
113 const bool is_king_that_may_castle_kingside,
114 const bool is_king_that_may_castle_queenside,
115 const action_number& action_key_number
116) noexcept;
117
119void test_controller();
120
121[[nodiscard]] bool operator==(const physical_controller& lhs, const physical_controller& rhs) noexcept;
122[[nodiscard]] bool operator!=(const physical_controller& lhs, const physical_controller& rhs) noexcept;
123
124std::ostream& operator<<(std::ostream& os, const physical_controller& c) noexcept;
125
126#endif // PHYSICAL_CONTROLLER_H
The number of an action.
Definition action_number.h:12
The layout of the Game dialog.
Definition game_view_layout.h:61
The key bindings.
Definition key_bindings.h:19
The mouse bindings.
Definition mouse_bindings.h:19
A physical controller.
Definition physical_controller.h:19
const mouse_bindings & get_mouse_bindings() const
Get the mouse bindings, if this is a mouse.
Definition physical_controller.cpp:102
const key_bindings & get_key_bindings() const
Get the key bindings, if this is a keyboard.
Definition physical_controller.cpp:85
const physical_controller_type & get_type() const noexcept
Definition physical_controller.h:33
user_inputs process_input(const sf::Event &event, const side player_side, const game_view_layout &layout) const
Process the input for this controller.
Definition physical_controller.cpp:181
void set_type(const physical_controller_type t) noexcept
Definition physical_controller.h:43
The coordinate on a screen.
Definition screen_coordinate.h:12
A collection of user inputs.
Definition user_inputs.h:26
key_bindings create_left_keyboard_key_bindings() noexcept
Create the key bindings for a player at the left side of a keyboard.
Definition key_bindings.cpp:67
sf::Event create_mouse_moved_event(const screen_coordinate &cursor_pos)
Create an sf::Event with type sf::Event::MouseMoved.
Definition physical_controller.cpp:67
physical_controller create_default_mouse_controller() noexcept
Create a mouse controller.
Definition physical_controller.cpp:28
sf::Event create_mouse_button_pressed_event(const screen_coordinate &cursor_pos, const sf::Mouse::Button mouse_button)
Create an sf::Event with type sf::Event::MouseButtonPressed.
Definition physical_controller.cpp:54
void test_controller()
Test this class and its free functions.
Definition physical_controller.cpp:271
physical_controller create_default_keyboard_controller() noexcept
Create a default keyboard controller, which is the left keyboard controller.
Definition physical_controller.cpp:23
sf::Keyboard::Key get_key_for_action(const physical_controller &c, const action_number &action)
Get the key for a action 1, 2, 3 or 4 for a controller.
Definition physical_controller.cpp:97
physical_controller create_right_keyboard_controller() noexcept
Create a keyboard controller for a user at the right side of the keyboard.
Definition physical_controller.cpp:76
physical_controller create_left_keyboard_controller() noexcept
Create a keyboard controller for a user at the left side of the keyboard.
Definition physical_controller.cpp:45
sf::Event create_key_pressed_event(const sf::Keyboard::Key k)
Create an sf::Event with type sf::Event::KeyPressed.
Definition physical_controller.cpp:37
std::string get_text_for_action(const physical_controller &c, const bool has_selected_units, const bool is_promoting_pawn, const bool is_king_that_may_castle_kingside, const bool is_king_that_may_castle_queenside, const action_number &action_key_number) noexcept
Get the text for action 1, 2, 3 or 4, e.g.
Definition physical_controller.cpp:108
physical_controller_type
The type of controller.
Definition physical_controller_type.h:15
side
The side the player/piece is on.
Definition side.h:11