1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use {Action, InputRebind, InputTranslator, MouseTranslationData, to_act_bt_hashmap};
use input::Button;
use window::Size;
use std::convert::Into;
use std::collections::hash_map::RandomState;
use std::hash::BuildHasher;
use std::default::Default;
use std::marker::PhantomData;
#[derive(Debug)]
pub struct Builder<A: Action, S: BuildHasher = RandomState> {
input_remappings: Vec<(Button, A)>,
mouse_data: MouseTranslationData,
_hasher: PhantomData<S>
}
impl<A: Action, S: BuildHasher + Default> Builder<A, S> {
pub fn new<Sz: Into<Size>>(size: Sz) -> Self {
Builder {
input_remappings: vec![],
mouse_data: MouseTranslationData::new(size),
_hasher: PhantomData
}
}
pub fn x_scroll_inverted(mut self, invert: bool) -> Self {
self.mouse_data.x_axis_scroll_inverted = invert;
self
}
pub fn get_x_scroll_inverted(&self) -> bool {
self.mouse_data.x_axis_scroll_inverted
}
pub fn y_scroll_inverted(mut self, invert: bool) -> Self {
self.mouse_data.y_axis_scroll_inverted = invert;
self
}
pub fn get_y_scroll_inverted(&self) -> bool {
self.mouse_data.y_axis_scroll_inverted
}
pub fn x_motion_inverted(mut self, invert: bool) -> Self {
self.mouse_data.x_axis_motion_inverted = invert;
self
}
pub fn get_x_motion_inverted(&self) -> bool {
self.mouse_data.x_axis_motion_inverted
}
pub fn y_motion_inverted(mut self, invert: bool) -> Self {
self.mouse_data.y_axis_motion_inverted = invert;
self
}
pub fn get_y_motion_inverted(&self) -> bool {
self.mouse_data.y_axis_motion_inverted
}
pub fn mouse_sensitivity(mut self, sensitivity: f64) -> Self {
self.mouse_data.sensitivity = sensitivity;
self
}
pub fn get_mouse_sensitivity(&self) -> f64 {
self.mouse_data.sensitivity
}
pub fn viewport_size(mut self, size: Size) -> Self {
self.mouse_data.viewport_size = size;
self
}
pub fn get_viewport_size(&self) -> Size {
self.mouse_data.viewport_size
}
pub fn with_mapping(mut self, action: A, button: Button) -> Self {
self.input_remappings.push((button, action));
self
}
pub fn build_translator(self) -> InputTranslator<A, S> {
self.into()
}
pub fn build_rebind(self) -> InputRebind<A, S> {
self.into()
}
}
impl<A: Action, S: BuildHasher + Default> Default for Builder<A, S> {
fn default() -> Self {
Self::new((800, 600))
}
}
impl<A: Action, S: BuildHasher + Default> Into<InputTranslator<A, S>> for Builder<A, S> {
fn into(self) -> InputTranslator<A, S> {
let mut translator = InputTranslator::new(self.mouse_data.viewport_size);
translator.mouse_translator.data = self.mouse_data;
translator.keymap = self.input_remappings.iter().cloned().collect();
translator
}
}
impl<A: Action, S: BuildHasher + Default> Into<InputRebind<A, S>> for Builder<A, S> {
fn into(self) -> InputRebind<A, S> {
let mut rebind = InputRebind::new(self.mouse_data.viewport_size);
rebind.mouse_data = self.mouse_data;
rebind.keymap = to_act_bt_hashmap(self.input_remappings.iter().cloned());
rebind
}
}