Skip to content

Commit c32758d

Browse files
committed
ios input updates
1 parent 0f45624 commit c32758d

6 files changed

Lines changed: 98 additions & 30 deletions

File tree

Editor/Editor.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ bool CheckInput(EditorActions action)
189189
std::string GetInputString(EditorActions action)
190190
{
191191
const HotkeyInfo& hotkey = hotkeyActions[size_t(action)];
192-
std::string ret = wi::input::ButtonToString(hotkey.button).text;
192+
std::string ret = wi::input::ButtonToString(hotkey.button).chars;
193193
if (hotkey.shift)
194194
{
195195
ret = "Shift + " + ret;
@@ -1994,16 +1994,19 @@ void EditorComponent::Update(float dt)
19941994
currentMouse.x -= renderPath->PhysicalToLogical((uint32_t)viewport3D.top_left_x);
19951995
currentMouse.y -= renderPath->PhysicalToLogical((uint32_t)viewport3D.top_left_y);
19961996

1997+
static constexpr float tweak60 = 0.1f / 60.0f;
19971998
float xDif = 0, yDif = 0;
19981999
const wi::input::MouseState& mouse = wi::input::GetMouseState();
2000+
const wi::input::Pinch pinch = wi::input::GetTouchPinch();
2001+
const XMFLOAT2& pan = wi::input::GetTouchPan();
19992002

20002003
if (wi::input::Down(wi::input::MOUSE_BUTTON_RIGHT))
20012004
{
20022005
camControlStart = false;
20032006
xDif = mouse.delta_position.x;
20042007
yDif = mouse.delta_position.y;
2005-
xDif = 0.1f * xDif * (1.0f / 60.0f);
2006-
yDif = 0.1f * yDif * (1.0f / 60.0f);
2008+
xDif *= tweak60;
2009+
yDif *= tweak60;
20072010
if (!is_2D_mode)
20082011
{
20092012
wi::input::SetPointer(originalMouse);
@@ -2041,6 +2044,9 @@ void EditorComponent::Update(float dt)
20412044
const float joystickrotspeed = 0.05f;
20422045
xDif += rightStick.x * joystickrotspeed;
20432046
yDif += rightStick.y * joystickrotspeed;
2047+
2048+
xDif += pan.x * tweak60;
2049+
yDif += pan.y * tweak60;
20442050

20452051
xDif *= cameraWnd.rotationspeedSlider.GetValue();
20462052
yDif *= cameraWnd.rotationspeedSlider.GetValue();
@@ -2111,13 +2117,18 @@ void EditorComponent::Update(float dt)
21112117

21122118
// Mouse pan works completely differently in 2D mode, it "grabs canvas"
21132119
XMFLOAT2 grabdiff = XMFLOAT2(0, 0);
2120+
const float units_per_pixel = camera.ortho_vertical_size / viewport3D.height * 0.5f;
21142121
if (wi::input::Down(wi::input::MOUSE_BUTTON_RIGHT))
21152122
{
21162123
wi::input::SetCursor(wi::input::CURSOR_RESIZEALL);
2117-
const float units_per_pixel = camera.ortho_vertical_size / viewport3D.height * 0.5f;
21182124
grabdiff = XMFLOAT2(-mouse.delta_position.x * units_per_pixel, mouse.delta_position.y * units_per_pixel);
21192125
move = XMVectorZero();
21202126
}
2127+
else if(std::abs(pan.x) > 0.0001f || std::abs(pan.y) > 0.0001f)
2128+
{
2129+
grabdiff = XMFLOAT2(pan.x * units_per_pixel, -pan.y * units_per_pixel);
2130+
move = XMVectorZero();
2131+
}
21212132

21222133
if (std::abs(grabdiff.x) > 0.0001f || std::abs(grabdiff.y) > 0.0001f || moveLength > 0.0001f)
21232134
{
@@ -2133,6 +2144,7 @@ void EditorComponent::Update(float dt)
21332144
{
21342145
camera.ortho_vertical_size -= currentMouse.z;
21352146
}
2147+
camera.ortho_vertical_size *= 1.0f + pinch.delta_scale;
21362148

21372149
camera.ortho_vertical_size = std::max(0.01f, camera.ortho_vertical_size);
21382150
}
@@ -2154,6 +2166,7 @@ void EditorComponent::Update(float dt)
21542166
if (CheckInput(EditorActions::MOVE_CAMERA_BACKWARD) || wi::input::Down(wi::input::GAMEPAD_BUTTON_DOWN)) { moveNew += XMVectorSet(0, 0, -1, 0); camera.ortho_vertical_size += 0.1f; }
21552167
if (CheckInput(EditorActions::MOVE_CAMERA_UP) || wi::input::Down(wi::input::GAMEPAD_BUTTON_2)) { moveNew += XMVectorSet(0, 1, 0, 0); }
21562168
if (CheckInput(EditorActions::MOVE_CAMERA_DOWN) || wi::input::Down(wi::input::GAMEPAD_BUTTON_1)) { moveNew += XMVectorSet(0, -1, 0, 0); }
2169+
moveNew += XMVectorSet(0, 0, pinch.delta_scale, 0);
21572170
moveNew = XMVector3Normalize(moveNew);
21582171
}
21592172
moveNew += XMVectorSet(leftStick.x, 0, leftStick.y, 0);

Editor/Editor_iOS/AppIcon.icon/icon.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{
22
"fill" : {
3-
"automatic-gradient" : "extended-srgb:0.00000,0.53333,1.00000,1.00000"
3+
"linear-gradient" : [
4+
"display-p3:0.44334,0.57928,0.81559,1.00000",
5+
"display-p3:0.13708,0.17734,0.29549,1.00000"
6+
],
7+
"orientation" : {
8+
"start" : {
9+
"x" : 0.5,
10+
"y" : 0
11+
},
12+
"stop" : {
13+
"x" : 0.5,
14+
"y" : 0.7
15+
}
16+
}
417
},
518
"groups" : [
619
{

WickedEngine/CommonInclude.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ struct StackString
109109
constexpr unsigned size() const { return capacity; }
110110
constexpr unsigned length() const { return cnt; }
111111
constexpr bool empty() const { return cnt == 0; }
112+
constexpr StackString() = default;
113+
constexpr StackString(const StackString&) = default;
114+
constexpr StackString(StackString&&) = default;
115+
constexpr StackString(const char* str) { push_back(str); }
112116
};
113117

114118
// Stack allocated simplified vector container:

WickedEngine/wiInput.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ namespace wi::input
8989
KeyboardState keyboard;
9090
MouseState mouse;
9191
Pen pen;
92+
Pinch pinch;
93+
XMFLOAT2 pan;
9294
bool pen_override = false;
9395
bool double_click = false;
9496
wi::Timer doubleclick_timer;
@@ -278,21 +280,52 @@ namespace wi::input
278280
#endif // PLATFORM_IOS
279281

280282
// Primary touch can act as mouse pointer override:
283+
static bool pan_continue = false; // helps avoid non-continuous delta jump on pan begin
281284
if (!touches.empty())
282285
{
283286
const Touch& primary_touch = touches.front();
284-
if (primary_touch.state == Touch::TOUCHSTATE_PINCHED)
287+
if (primary_touch.state == Touch::TOUCHSTATE_PRESSED)
285288
{
286-
mouse.right_button_press = true;
287-
mouse.delta_position.x = mouse.position.x - primary_touch.pos.x;
288-
mouse.delta_position.y = mouse.position.y - primary_touch.pos.y;
289+
mouse.left_button_press = true;
290+
pan_continue = false;
291+
}
292+
else if (primary_touch.state == Touch::TOUCHSTATE_MOVED)
293+
{
294+
if (pan_continue)
295+
{
296+
mouse.delta_position.x = mouse.position.x - primary_touch.pos.x;
297+
mouse.delta_position.y = mouse.position.y - primary_touch.pos.y;
298+
}
299+
pan_continue = true;
289300
}
290301
else
291302
{
292-
mouse.left_button_press = true;
303+
pan_continue = false;
293304
}
294305
mouse.position = primary_touch.pos;
295306
}
307+
else
308+
{
309+
pan_continue = false;
310+
}
311+
312+
// Find pinch and pan gesture:
313+
float prev_pinch_scale = pinch.scale;
314+
pinch = {};
315+
pan = XMFLOAT2(0, 0);
316+
for (auto& touch : touches)
317+
{
318+
if (touch.state == Touch::TOUCHSTATE_PINCHED)
319+
{
320+
pinch.position = touch.pos;
321+
pinch.scale = touch.scale;
322+
pinch.delta_scale = prev_pinch_scale - pinch.scale;
323+
}
324+
else if (touch.state == Touch::TOUCHSTATE_MOVED)
325+
{
326+
pan = mouse.delta_position;
327+
}
328+
}
296329

297330
// Check if low-level XINPUT controller is not registered for playerindex slot and register:
298331
for (int i = 0; i < wi::input::xinput::GetMaxControllerCount(); ++i)
@@ -1592,7 +1625,7 @@ namespace wi::input
15921625
return BUTTON_NONE;
15931626
}
15941627

1595-
ShortReturnString ButtonToString(BUTTON button, CONTROLLER_PREFERENCE preference)
1628+
StackString<32> ButtonToString(BUTTON button, CONTROLLER_PREFERENCE preference)
15961629
{
15971630
#ifdef PLATFORM_PS5
15981631
preference = CONTROLLER_PREFERENCE_PLAYSTATION;
@@ -1737,8 +1770,8 @@ namespace wi::input
17371770

17381771
if (button >= DIGIT_RANGE_START && button < GAMEPAD_RANGE_START)
17391772
{
1740-
ShortReturnString str;
1741-
str.text[0] = (char)button;
1773+
StackString<32> str;
1774+
str.chars[0] = (char)button;
17421775
return str;
17431776
}
17441777

@@ -1766,4 +1799,14 @@ namespace wi::input
17661799
touches.push_back(scaledTouch);
17671800
}
17681801

1802+
const Pinch& GetTouchPinch()
1803+
{
1804+
return pinch;
1805+
}
1806+
1807+
const XMFLOAT2& GetTouchPan()
1808+
{
1809+
return pan;
1810+
}
1811+
17691812
}

WickedEngine/wiInput.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,25 +286,20 @@ namespace wi::input
286286
CONTROLLER_PREFERENCE_PLAYSTATION,
287287
CONTROLLER_PREFERENCE_XBOX,
288288
};
289-
struct ShortReturnString
290-
{
291-
char text[32] = {};
292-
constexpr ShortReturnString() = default;
293-
constexpr ShortReturnString(const char* str)
294-
{
295-
int i = 0;
296-
while (str[i] && i < arraysize(text))
297-
{
298-
text[i] = str[i];
299-
i++;
300-
}
301-
}
302-
constexpr operator const char*() const { return text; }
303-
};
304-
ShortReturnString ButtonToString(BUTTON button, CONTROLLER_PREFERENCE preference = CONTROLLER_PREFERENCE_GENERIC);
289+
StackString<32> ButtonToString(BUTTON button, CONTROLLER_PREFERENCE preference = CONTROLLER_PREFERENCE_GENERIC);
305290

306291

307292
void AddMouseScrollEvent(float value);
308293
void AddMouseMoveDeltaEvent(XMFLOAT2 value);
294+
295+
struct Pinch
296+
{
297+
XMFLOAT2 position = XMFLOAT2(0, 0);
298+
float scale = 1;
299+
float delta_scale = 0;
300+
};
301+
const Pinch& GetTouchPinch();
302+
303+
const XMFLOAT2& GetTouchPan();
309304
};
310305

WickedEngine/wiVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace wi::version
99
// minor features, major updates, breaking compatibility changes
1010
const int minor = 72;
1111
// minor bug fixes, alterations, refactors, updates
12-
const int revision = 87;
12+
const int revision = 88;
1313

1414
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
1515

0 commit comments

Comments
 (0)