Skip to content

Commit 9336372

Browse files
committed
Adds One- functions and params to mouse as well
1 parent 1ae77a9 commit 9336372

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

InputStateManager/Inputs/Mouse.cs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal void Update()
7979
State = provider.GetState();
8080
}
8181

82-
internal static bool IsUp(MouseState state, Button button)
82+
internal static bool Up(MouseState state, Button button)
8383
{
8484
switch (button)
8585
{
@@ -98,7 +98,7 @@ internal static bool IsUp(MouseState state, Button button)
9898
}
9999
}
100100

101-
internal static bool IsDown(MouseState state, Button button)
101+
internal static bool Down(MouseState state, Button button)
102102
{
103103
switch (button)
104104
{
@@ -129,11 +129,35 @@ internal IsSub(Func<MouseState> mapping, Func<MouseState> oldMapping) : base(map
129129
OldState = oldMapping;
130130
}
131131

132-
public bool Press(Button button)
133-
=> IsDown(State(), button) && IsUp(OldState(), button);
132+
public bool Press(params Button[] buttons)
133+
{
134+
foreach (var button in buttons)
135+
if (Mouse.Up(State(), button) || Mouse.Down(OldState(), button))
136+
return false;
137+
return true;
138+
}
139+
public bool OnePress(params Button[] buttons)
140+
{
141+
foreach (var button in buttons)
142+
if (Mouse.Down(State(), button) && Mouse.Up(OldState(), button))
143+
return true;
144+
return false;
145+
}
134146

135-
public bool Release(Button button)
136-
=> IsDown(OldState(), button) && IsUp(State(), button);
147+
public bool Release(params Button[] buttons)
148+
{
149+
foreach (var button in buttons)
150+
if (Mouse.Up(OldState(), button) || Mouse.Down(State(), button))
151+
return false;
152+
return true;
153+
}
154+
public bool OneRelease(params Button[] buttons)
155+
{
156+
foreach (var button in buttons)
157+
if (Mouse.Down(OldState(), button) && Mouse.Up(State(), button))
158+
return false;
159+
return true;
160+
}
137161

138162
public Point PositionDelta => OldState().Position - State().Position;
139163
public int ScrollWheelDelta => State().ScrollWheelValue - OldState().ScrollWheelValue;
@@ -152,8 +176,35 @@ internal WasSub(Func<MouseState> mapping)
152176
State = mapping;
153177
}
154178

155-
public bool Up(Button button) => IsUp(State(), button);
156-
public bool Down(Button button) => IsDown(State(), button);
179+
public bool Up(params Button[] buttons)
180+
{
181+
foreach (var button in buttons)
182+
if (Mouse.Down(State(), button))
183+
return false;
184+
return true;
185+
}
186+
public bool OneUp(params Button[] buttons)
187+
{
188+
foreach (var button in buttons)
189+
if (Mouse.Up(State(), button))
190+
return true;
191+
return false;
192+
}
193+
194+
public bool Down(params Button[] buttons)
195+
{
196+
foreach (var button in buttons)
197+
if (Mouse.Up(State(), button))
198+
return false;
199+
return true;
200+
}
201+
public bool OneDown(params Button[] buttons)
202+
{
203+
foreach (var button in buttons)
204+
if (Mouse.Down(State(), button))
205+
return true;
206+
return false;
207+
}
157208

158209
public Point Position => State().Position;
159210
public int ScrollWheelValue => State().ScrollWheelValue;

0 commit comments

Comments
 (0)