Touch events are handled differently in GUI
This commit is contained in:
parent
fe37c3348b
commit
d38156ec26
13 changed files with 203 additions and 180 deletions
|
|
@ -201,7 +201,7 @@ void DrawCamera::input_mouse_wheel_callback(World& w, const InputManager::MouseW
|
|||
}
|
||||
}
|
||||
|
||||
void DrawCamera::input_multi_finger_touch_callback(World& w, const InputManager::MultiFingerTouchArgs& touch) {
|
||||
void DrawCamera::input_multi_finger_touch_callback(World& w, const InputManager::MultiFingerTouchCallbackArgs& touch) {
|
||||
if(!smoothMove.occurring && !isAccurateZooming && !isTouchTransforming && touch.down) {
|
||||
touchInitialPositions = touch.pos;
|
||||
touchInitialC = c;
|
||||
|
|
@ -211,7 +211,7 @@ void DrawCamera::input_multi_finger_touch_callback(World& w, const InputManager:
|
|||
isTouchTransforming = false;
|
||||
}
|
||||
|
||||
void DrawCamera::input_multi_finger_motion_callback(World& w, const InputManager::MultiFingerMotionArgs& motion) {
|
||||
void DrawCamera::input_multi_finger_motion_callback(World& w, const InputManager::MultiFingerMotionCallbackArgs& motion) {
|
||||
if(!smoothMove.occurring && !isAccurateZooming && isTouchTransforming) {
|
||||
c = touchInitialC;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ class DrawCamera {
|
|||
void input_mouse_button_on_canvas_callback(World& w, const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(World& w, const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(World& w, const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
void input_multi_finger_touch_callback(World& w, const InputManager::MultiFingerTouchArgs& touch);
|
||||
void input_multi_finger_motion_callback(World& w, const InputManager::MultiFingerMotionArgs& motion);
|
||||
void input_multi_finger_touch_callback(World& w, const InputManager::MultiFingerTouchCallbackArgs& touch);
|
||||
void input_multi_finger_motion_callback(World& w, const InputManager::MultiFingerMotionCallbackArgs& motion);
|
||||
private:
|
||||
struct SmoothMove {
|
||||
CoordSpaceHelper start;
|
||||
|
|
|
|||
|
|
@ -227,14 +227,6 @@ void DrawingProgram::input_key_callback(const InputManager::KeyCallbackArgs& key
|
|||
drawTool->input_key_callback(key);
|
||||
}
|
||||
|
||||
void DrawingProgram::input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
drawTool->input_pure_mouse_button_callback(button);
|
||||
}
|
||||
|
||||
void DrawingProgram::input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||
drawTool->input_pure_mouse_motion_callback(motion);
|
||||
}
|
||||
|
||||
void DrawingProgram::input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button) {
|
||||
pen_tool_switch_check();
|
||||
drawTool->input_pen_button_callback(button);
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ std::unique_ptr<DrawingProgramToolBase> DrawingProgramToolBase::allocate_tool_ty
|
|||
void DrawingProgramToolBase::input_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||
void DrawingProgramToolBase::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {}
|
||||
void DrawingProgramToolBase::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {}
|
||||
void DrawingProgramToolBase::input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {}
|
||||
void DrawingProgramToolBase::input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {}
|
||||
void DrawingProgramToolBase::input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button) {}
|
||||
void DrawingProgramToolBase::input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch) {}
|
||||
void DrawingProgramToolBase::input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion) {}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ class DrawingProgramToolBase {
|
|||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
virtual void input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
virtual void input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
virtual void input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
virtual void input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button);
|
||||
virtual void input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch);
|
||||
virtual void input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion);
|
||||
|
|
|
|||
|
|
@ -394,13 +394,13 @@ void InputManager::backend_mouse_button_up_update(const SDL_MouseButtonEvent& e)
|
|||
else if(e.button == 3)
|
||||
mouse.rightDown = false;
|
||||
MouseButtonCallbackArgs args{
|
||||
.deviceType = MouseDeviceType::MOUSE,
|
||||
.button = static_cast<MouseButton>(e.button),
|
||||
.down = e.down,
|
||||
.clicks = e.clicks,
|
||||
.pos = mousePos
|
||||
};
|
||||
main.input_mouse_button_callback(args);
|
||||
main.input_pure_mouse_button_callback(args);
|
||||
|
||||
isTouchDevice = false;
|
||||
}
|
||||
|
|
@ -422,13 +422,13 @@ void InputManager::backend_mouse_button_down_update(const SDL_MouseButtonEvent&
|
|||
mouse.rightClicks = e.clicks;
|
||||
}
|
||||
MouseButtonCallbackArgs args{
|
||||
.deviceType = MouseDeviceType::MOUSE,
|
||||
.button = static_cast<MouseButton>(e.button),
|
||||
.down = e.down,
|
||||
.clicks = e.clicks,
|
||||
.pos = mousePos
|
||||
};
|
||||
main.input_mouse_button_callback(args);
|
||||
main.input_pure_mouse_button_callback(args);
|
||||
|
||||
isTouchDevice = false;
|
||||
}
|
||||
|
|
@ -438,11 +438,8 @@ void InputManager::backend_mouse_motion_update(const SDL_MouseMotionEvent& e) {
|
|||
mouse.set_pos(mouseNewPos);
|
||||
|
||||
Vector2f mouseRel = {e.xrel * main.window.density, e.yrel * main.window.density};
|
||||
main.input_pure_mouse_motion_callback({
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
main.input_mouse_motion_callback({
|
||||
.deviceType = MouseDeviceType::MOUSE,
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
|
|
@ -476,6 +473,7 @@ void InputManager::backend_pen_button_down_update(const SDL_PenButtonEvent& e) {
|
|||
|
||||
if(e.button == main.toolbar.tabletOptions.middleClickButton) {
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::MIDDLE,
|
||||
.down = e.down,
|
||||
.clicks = 1,
|
||||
|
|
@ -484,6 +482,7 @@ void InputManager::backend_pen_button_down_update(const SDL_PenButtonEvent& e) {
|
|||
}
|
||||
else if(e.button == main.toolbar.tabletOptions.rightClickButton) {
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::RIGHT,
|
||||
.down = e.down,
|
||||
.clicks = 1,
|
||||
|
|
@ -510,6 +509,7 @@ void InputManager::backend_pen_button_up_update(const SDL_PenButtonEvent& e) {
|
|||
|
||||
if(e.button == main.toolbar.tabletOptions.middleClickButton) {
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::MIDDLE,
|
||||
.down = e.down,
|
||||
.clicks = 1,
|
||||
|
|
@ -518,6 +518,7 @@ void InputManager::backend_pen_button_up_update(const SDL_PenButtonEvent& e) {
|
|||
}
|
||||
else if(e.button == main.toolbar.tabletOptions.rightClickButton) {
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::RIGHT,
|
||||
.down = e.down,
|
||||
.clicks = 1,
|
||||
|
|
@ -549,6 +550,7 @@ void InputManager::backend_pen_touch_down_update(const SDL_PenTouchEvent& e) {
|
|||
pen.isEraser = e.eraser;
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::LEFT,
|
||||
.down = e.down,
|
||||
.clicks = mouse.leftClicks,
|
||||
|
|
@ -574,6 +576,7 @@ void InputManager::backend_pen_touch_up_update(const SDL_PenTouchEvent& e) {
|
|||
pen.pressure = 0.0;
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.button = MouseButton::LEFT,
|
||||
.down = e.down,
|
||||
.clicks = 0,
|
||||
|
|
@ -597,6 +600,7 @@ void InputManager::backend_pen_motion_update(const SDL_PenMotionEvent& e) {
|
|||
pen.isEraser = e.pen_state & SDL_PEN_INPUT_ERASER_TIP;
|
||||
|
||||
main.input_mouse_motion_callback({
|
||||
.deviceType = MouseDeviceType::PEN,
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
|
|
@ -640,21 +644,75 @@ std::vector<Vector2f> InputManager::get_multiple_finger_motions() {
|
|||
return pos;
|
||||
}
|
||||
|
||||
void InputManager::touch_finger_do_mouse_down() {
|
||||
auto& prevTouch = touch.fingers[0];
|
||||
Vector2f mouseNewPos = {prevTouch.x * main.window.size.x() * main.window.density, prevTouch.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
mouse.leftDown = true;
|
||||
|
||||
if((std::chrono::steady_clock::now() - touch.lastLeftClickTime) > std::chrono::milliseconds(500))
|
||||
touch.leftClicksSaved = 0;
|
||||
touch.leftClicksSaved++;
|
||||
touch.lastLeftClickTime = std::chrono::steady_clock::now();
|
||||
mouse.leftClicks = touch.leftClicksSaved;
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::TOUCH,
|
||||
.button = MouseButton::LEFT,
|
||||
.down = true,
|
||||
.clicks = mouse.leftClicks,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
}
|
||||
|
||||
void InputManager::touch_finger_do_mouse_up(const SDL_TouchFingerEvent& e) {
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
mouse.leftDown = false;
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.deviceType = MouseDeviceType::TOUCH,
|
||||
.button = MouseButton::LEFT,
|
||||
.down = false,
|
||||
.clicks = 0,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
}
|
||||
|
||||
void InputManager::touch_finger_do_mouse_motion(const SDL_TouchFingerEvent& e) {
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
Vector2f mouseRel = {e.dx * main.window.size.x() * main.window.density, e.dy * main.window.size.y() * main.window.density};
|
||||
main.input_mouse_motion_callback({
|
||||
.deviceType = MouseDeviceType::TOUCH,
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
}
|
||||
|
||||
void InputManager::backend_touch_finger_down_update(const SDL_TouchFingerEvent& e) {
|
||||
touch.fingers.emplace_back(e);
|
||||
auto fingerPosVec = get_multiple_finger_positions();
|
||||
switch(touch.touchEventType) {
|
||||
case Touch::NO_TOUCH_EVENT: {
|
||||
if(touch.fingers.size() == 2) {
|
||||
touch.isDown = true;
|
||||
touch.touchEventType = Touch::TWO_FINGER_EVENT;
|
||||
main.input_multi_finger_touch_callback({
|
||||
.down = true,
|
||||
.pos = get_multiple_finger_positions()
|
||||
.pos = fingerPosVec
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Touch::ONE_FINGER_EVENT: {
|
||||
if(touch.fingers.size() == 2) {
|
||||
touch_finger_do_mouse_up(e);
|
||||
touch.touchEventType = Touch::TWO_FINGER_EVENT;
|
||||
main.input_multi_finger_touch_callback({
|
||||
.down = true,
|
||||
.pos = fingerPosVec
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Touch::TWO_FINGER_EVENT: {
|
||||
|
|
@ -667,63 +725,41 @@ void InputManager::backend_touch_finger_down_update(const SDL_TouchFingerEvent&
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if((std::chrono::steady_clock::now() - touch.lastFingerTapTime) > std::chrono::milliseconds(500))
|
||||
touch.fingerTapsSaved = 0;
|
||||
touch.fingerTapsSaved++;
|
||||
touch.lastFingerTapTime = std::chrono::steady_clock::now();
|
||||
|
||||
main.input_finger_touch_callback({
|
||||
.fingerID = e.fingerID,
|
||||
.down = true,
|
||||
.pos = fingerPosVec.back(),
|
||||
.fingerDownCount = touch.fingers.size(),
|
||||
.fingerTapCount = touch.fingerTapsSaved
|
||||
});
|
||||
|
||||
isTouchDevice = true;
|
||||
}
|
||||
|
||||
void InputManager::backend_touch_finger_up_update(const SDL_TouchFingerEvent& e) {
|
||||
switch(touch.touchEventType) {
|
||||
case Touch::NO_TOUCH_EVENT: {
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
touch.isDown = false;
|
||||
mouse.leftDown = false;
|
||||
|
||||
if((std::chrono::steady_clock::now() - touch.lastLeftClickTime) > std::chrono::milliseconds(300))
|
||||
touch.leftClicksSaved = 0;
|
||||
touch.leftClicksSaved++;
|
||||
mouse.leftClicks = touch.leftClicksSaved;
|
||||
touch.lastLeftClickTime = std::chrono::steady_clock::now();
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.button = MouseButton::LEFT,
|
||||
.down = true,
|
||||
.clicks = mouse.leftClicks,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
main.input_mouse_button_callback({
|
||||
.button = MouseButton::LEFT,
|
||||
.down = false,
|
||||
.clicks = 0,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
|
||||
touch_finger_do_mouse_down();
|
||||
touch_finger_do_mouse_up(e);
|
||||
touch.touchEventType = Touch::EVENT_DONE;
|
||||
break;
|
||||
}
|
||||
case Touch::ONE_FINGER_EVENT: {
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
touch.isDown = false;
|
||||
mouse.leftDown = false;
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.button = MouseButton::LEFT,
|
||||
.down = false,
|
||||
.clicks = 0,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
|
||||
touch_finger_do_mouse_up(e);
|
||||
touch.touchEventType = Touch::EVENT_DONE;
|
||||
break;
|
||||
}
|
||||
case Touch::TWO_FINGER_EVENT: {
|
||||
touch.isDown = false;
|
||||
|
||||
main.input_multi_finger_touch_callback({
|
||||
.down = false,
|
||||
.pos = get_multiple_finger_positions()
|
||||
});
|
||||
|
||||
touch.touchEventType = Touch::EVENT_DONE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -731,6 +767,15 @@ void InputManager::backend_touch_finger_up_update(const SDL_TouchFingerEvent& e)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
main.input_finger_touch_callback({
|
||||
.fingerID = e.fingerID,
|
||||
.down = false,
|
||||
.pos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density},
|
||||
.fingerDownCount = touch.fingers.size(),
|
||||
.fingerTapCount = 0
|
||||
});
|
||||
|
||||
std::erase_if(touch.fingers, [&e](auto& tE) {
|
||||
return e.fingerID == tE.fingerID;
|
||||
});
|
||||
|
|
@ -741,46 +786,13 @@ void InputManager::backend_touch_finger_up_update(const SDL_TouchFingerEvent& e)
|
|||
void InputManager::backend_touch_finger_motion_update(const SDL_TouchFingerEvent& e) {
|
||||
switch(touch.touchEventType) {
|
||||
case Touch::NO_TOUCH_EVENT: {
|
||||
{
|
||||
auto& prevTouch = touch.fingers[0];
|
||||
Vector2f mouseNewPos = {prevTouch.x * main.window.size.x() * main.window.density, prevTouch.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
mouse.leftDown = true;
|
||||
|
||||
if((std::chrono::steady_clock::now() - touch.lastLeftClickTime) > std::chrono::milliseconds(300))
|
||||
touch.leftClicksSaved = 0;
|
||||
touch.leftClicksSaved++;
|
||||
mouse.leftClicks = touch.leftClicksSaved;
|
||||
touch.lastLeftClickTime = std::chrono::steady_clock::now();
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.button = MouseButton::LEFT,
|
||||
.down = true,
|
||||
.clicks = mouse.leftClicks,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
}
|
||||
{
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
Vector2f mouseRel = {e.dx * main.window.size.x() * main.window.density, e.dy * main.window.size.y() * main.window.density};
|
||||
main.input_mouse_motion_callback({
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
}
|
||||
|
||||
touch_finger_do_mouse_down();
|
||||
touch_finger_do_mouse_motion(e);
|
||||
touch.touchEventType = Touch::ONE_FINGER_EVENT;
|
||||
break;
|
||||
}
|
||||
case Touch::ONE_FINGER_EVENT: {
|
||||
Vector2f mouseNewPos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
Vector2f mouseRel = {e.dx * main.window.size.x() * main.window.density, e.dy * main.window.size.y() * main.window.density};
|
||||
main.input_mouse_motion_callback({
|
||||
.pos = mouseNewPos,
|
||||
.move = mouseRel
|
||||
});
|
||||
touch_finger_do_mouse_motion(e);
|
||||
break;
|
||||
}
|
||||
case Touch::TWO_FINGER_EVENT: {
|
||||
|
|
@ -801,6 +813,13 @@ void InputManager::backend_touch_finger_motion_update(const SDL_TouchFingerEvent
|
|||
}
|
||||
}
|
||||
|
||||
main.input_finger_motion_callback({
|
||||
.fingerID = e.fingerID,
|
||||
.pos = {e.x * main.window.size.x() * main.window.density, e.y * main.window.size.y() * main.window.density},
|
||||
.move = {e.dx * main.window.size.x() * main.window.density, e.dy * main.window.size.y() * main.window.density},
|
||||
.fingerDownCount = touch.fingers.size()
|
||||
});
|
||||
|
||||
isTouchDevice = true;
|
||||
}
|
||||
|
||||
|
|
@ -1134,25 +1153,8 @@ void InputManager::Mouse::set_pos(const Vector2f& newPos) {
|
|||
}
|
||||
|
||||
void InputManager::update() {
|
||||
|
||||
if(touch.touchEventType == Touch::NO_TOUCH_EVENT && (SDL_GetTicksNS() - touch.fingers[0].timestamp) > (100 * 1000000)) { // 100ms to determine whether touch is with a single finger
|
||||
auto& prevTouch = touch.fingers[0];
|
||||
Vector2f mouseNewPos = {prevTouch.x * main.window.size.x() * main.window.density, prevTouch.y * main.window.size.y() * main.window.density};
|
||||
mouse.set_pos(mouseNewPos);
|
||||
mouse.leftDown = true;
|
||||
|
||||
if((std::chrono::steady_clock::now() - touch.lastLeftClickTime) > std::chrono::milliseconds(300))
|
||||
touch.leftClicksSaved = 0;
|
||||
touch.leftClicksSaved++;
|
||||
mouse.leftClicks = touch.leftClicksSaved;
|
||||
touch.lastLeftClickTime = std::chrono::steady_clock::now();
|
||||
|
||||
main.input_mouse_button_callback({
|
||||
.button = MouseButton::LEFT,
|
||||
.down = true,
|
||||
.clicks = mouse.leftClicks,
|
||||
.pos = mouseNewPos
|
||||
});
|
||||
if(touch.touchEventType == Touch::NO_TOUCH_EVENT && (SDL_GetTicksNS() - touch.fingers[0].timestamp) > (200 * 1000000)) { // 200ms to determine whether touch is with a single finger
|
||||
touch_finger_do_mouse_down();
|
||||
touch.touchEventType = Touch::ONE_FINGER_EVENT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <Eigen/Dense>
|
||||
#include <SDL3/SDL_touch.h>
|
||||
#include <array>
|
||||
#include "RichText/TextStyleModifier.hpp"
|
||||
#include "RichText/TextBox.hpp"
|
||||
|
|
@ -75,9 +76,10 @@ struct InputManager {
|
|||
} mouse;
|
||||
|
||||
struct Touch {
|
||||
bool isDown = false;
|
||||
int leftClicksSaved = 0;
|
||||
int fingerTapsSaved = 0;
|
||||
std::chrono::steady_clock::time_point lastLeftClickTime;
|
||||
std::chrono::steady_clock::time_point lastFingerTapTime;
|
||||
std::vector<SDL_TouchFingerEvent> fingers;
|
||||
enum TypeOfTouchEvent {
|
||||
NO_TOUCH_EVENT,
|
||||
|
|
@ -220,6 +222,9 @@ struct InputManager {
|
|||
void set_key_down(const SDL_KeyboardEvent& e, KeyCode kCode);
|
||||
std::vector<Vector2f> get_multiple_finger_positions();
|
||||
std::vector<Vector2f> get_multiple_finger_motions();
|
||||
void touch_finger_do_mouse_down();
|
||||
void touch_finger_do_mouse_up(const SDL_TouchFingerEvent& f);
|
||||
void touch_finger_do_mouse_motion(const SDL_TouchFingerEvent& f);
|
||||
|
||||
void backend_drop_file_event(const SDL_DropEvent& e);
|
||||
void backend_drop_text_event(const SDL_DropEvent& e);
|
||||
|
|
@ -269,7 +274,14 @@ struct InputManager {
|
|||
RIGHT
|
||||
} button;
|
||||
|
||||
enum class MouseDeviceType {
|
||||
MOUSE,
|
||||
PEN,
|
||||
TOUCH
|
||||
};
|
||||
|
||||
struct MouseButtonCallbackArgs {
|
||||
MouseDeviceType deviceType;
|
||||
MouseButton button;
|
||||
bool down;
|
||||
uint8_t clicks;
|
||||
|
|
@ -277,6 +289,7 @@ struct InputManager {
|
|||
};
|
||||
|
||||
struct MouseMotionCallbackArgs {
|
||||
MouseDeviceType deviceType;
|
||||
Vector2f pos;
|
||||
Vector2f move;
|
||||
};
|
||||
|
|
@ -316,16 +329,31 @@ struct InputManager {
|
|||
const char* data;
|
||||
};
|
||||
|
||||
struct MultiFingerTouchArgs {
|
||||
struct MultiFingerTouchCallbackArgs {
|
||||
bool down;
|
||||
std::vector<Vector2f> pos;
|
||||
};
|
||||
|
||||
struct MultiFingerMotionArgs {
|
||||
struct MultiFingerMotionCallbackArgs {
|
||||
std::vector<Vector2f> pos;
|
||||
std::vector<Vector2f> move;
|
||||
};
|
||||
|
||||
struct FingerTouchCallbackArgs {
|
||||
SDL_FingerID fingerID;
|
||||
bool down;
|
||||
Vector2f pos;
|
||||
size_t fingerDownCount;
|
||||
int fingerTapCount;
|
||||
};
|
||||
|
||||
struct FingerMotionCallbackArgs {
|
||||
SDL_FingerID fingerID;
|
||||
Vector2f pos;
|
||||
Vector2f move;
|
||||
size_t fingerDownCount;
|
||||
};
|
||||
|
||||
MainProgram& main;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -350,16 +350,6 @@ void MainProgram::input_mouse_wheel_callback(const InputManager::MouseWheelCallb
|
|||
world->input_mouse_wheel_callback(wheel);
|
||||
}
|
||||
|
||||
void MainProgram::input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(world)
|
||||
world->input_pure_mouse_button_callback(button);
|
||||
}
|
||||
|
||||
void MainProgram::input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||
if(world)
|
||||
world->input_pure_mouse_motion_callback(motion);
|
||||
}
|
||||
|
||||
void MainProgram::input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button) {
|
||||
if(world)
|
||||
world->input_pen_button_callback(button);
|
||||
|
|
@ -380,16 +370,24 @@ void MainProgram::input_pen_axis_callback(const InputManager::PenAxisCallbackArg
|
|||
world->input_pen_axis_callback(axis);
|
||||
}
|
||||
|
||||
void MainProgram::input_multi_finger_touch_callback(const InputManager::MultiFingerTouchArgs& touch) {
|
||||
void MainProgram::input_multi_finger_touch_callback(const InputManager::MultiFingerTouchCallbackArgs& touch) {
|
||||
if(world)
|
||||
world->input_multi_finger_touch_callback(touch);
|
||||
}
|
||||
|
||||
void MainProgram::input_multi_finger_motion_callback(const InputManager::MultiFingerMotionArgs& motion) {
|
||||
void MainProgram::input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion) {
|
||||
if(world)
|
||||
world->input_multi_finger_motion_callback(motion);
|
||||
}
|
||||
|
||||
void MainProgram::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) {
|
||||
toolbar.input_finger_touch_callback(touch);
|
||||
}
|
||||
|
||||
void MainProgram::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) {
|
||||
toolbar.input_finger_motion_callback(motion);
|
||||
}
|
||||
|
||||
bool MainProgram::network_being_used() {
|
||||
for(auto& w : worlds) {
|
||||
if(w->netObjMan.is_connected())
|
||||
|
|
|
|||
|
|
@ -126,14 +126,14 @@ class MainProgram {
|
|||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
void input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button);
|
||||
void input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch);
|
||||
void input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion);
|
||||
void input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axis);
|
||||
void input_multi_finger_touch_callback(const InputManager::MultiFingerTouchArgs& touch);
|
||||
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionArgs& motion);
|
||||
void input_multi_finger_touch_callback(const InputManager::MultiFingerTouchCallbackArgs& touch);
|
||||
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion);
|
||||
void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch);
|
||||
void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
|
||||
|
||||
~MainProgram();
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -2348,47 +2348,64 @@ void Toolbar::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
}
|
||||
|
||||
void Toolbar::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
io->mouse.globalPos = button.pos / final_gui_scale();
|
||||
if(button.down) {
|
||||
switch(button.button) {
|
||||
case InputManager::MouseButton::LEFT: {
|
||||
io->mouse.leftClick = std::max<int>(io->mouse.leftClick, button.clicks);
|
||||
io->mouse.leftHeld = true;
|
||||
break;
|
||||
if(button.deviceType != InputManager::MouseDeviceType::TOUCH) {
|
||||
io->mouse.globalPos = button.pos / final_gui_scale();
|
||||
if(button.down) {
|
||||
switch(button.button) {
|
||||
case InputManager::MouseButton::LEFT: {
|
||||
io->mouse.leftClick = std::max<int>(io->mouse.leftClick, button.clicks);
|
||||
io->mouse.leftHeld = true;
|
||||
break;
|
||||
}
|
||||
case InputManager::MouseButton::RIGHT: {
|
||||
io->mouse.rightClick = std::max<int>(io->mouse.rightClick, button.clicks);
|
||||
io->mouse.rightHeld = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case InputManager::MouseButton::RIGHT: {
|
||||
io->mouse.rightClick = std::max<int>(io->mouse.rightClick, button.clicks);
|
||||
io->mouse.rightHeld = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch(button.button) {
|
||||
case InputManager::MouseButton::LEFT: {
|
||||
io->mouse.leftHeld = false;
|
||||
break;
|
||||
else {
|
||||
switch(button.button) {
|
||||
case InputManager::MouseButton::LEFT: {
|
||||
io->mouse.leftHeld = false;
|
||||
break;
|
||||
}
|
||||
case InputManager::MouseButton::RIGHT: {
|
||||
io->mouse.rightHeld = false;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case InputManager::MouseButton::RIGHT: {
|
||||
io->mouse.rightHeld = false;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||
io->mouse.globalPos = motion.pos / final_gui_scale();
|
||||
if(motion.deviceType != InputManager::MouseDeviceType::TOUCH)
|
||||
io->mouse.globalPos = motion.pos / final_gui_scale();
|
||||
}
|
||||
|
||||
void Toolbar::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) {
|
||||
io->mouse.scroll = wheel.amount;
|
||||
}
|
||||
|
||||
void Toolbar::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) {
|
||||
io->mouse.globalPos = touch.pos / final_gui_scale();
|
||||
if(touch.down) {
|
||||
io->mouse.leftClick = std::max<int>(io->mouse.leftClick, touch.fingerTapCount);
|
||||
io->mouse.leftHeld = true;
|
||||
}
|
||||
else
|
||||
io->mouse.leftHeld = false;
|
||||
}
|
||||
|
||||
void Toolbar::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) {
|
||||
io->mouse.globalPos = motion.pos / final_gui_scale();
|
||||
}
|
||||
|
||||
void Toolbar::start_gui() {
|
||||
SDL_Rect windowRect;
|
||||
if(SDL_GetWindowSafeArea(main.window.sdlWindow, &windowRect)) {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ class Toolbar {
|
|||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch);
|
||||
void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
|
||||
void update();
|
||||
void draw(SkCanvas* canvas);
|
||||
void color_selector_left(Vector4f* color);
|
||||
|
|
|
|||
|
|
@ -295,16 +295,6 @@ void World::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArg
|
|||
drawData.cam.input_mouse_wheel_callback(*this, wheel);
|
||||
}
|
||||
|
||||
void World::input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(!clientStillConnecting)
|
||||
drawProg.input_pure_mouse_button_callback(button);
|
||||
}
|
||||
|
||||
void World::input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||
if(!clientStillConnecting)
|
||||
drawProg.input_pure_mouse_motion_callback(motion);
|
||||
}
|
||||
|
||||
void World::input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button) {
|
||||
if(!clientStillConnecting)
|
||||
drawProg.input_pen_button_callback(button);
|
||||
|
|
@ -325,12 +315,12 @@ void World::input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axi
|
|||
drawProg.input_pen_axis_callback(axis);
|
||||
}
|
||||
|
||||
void World::input_multi_finger_touch_callback(const InputManager::MultiFingerTouchArgs& touch) {
|
||||
void World::input_multi_finger_touch_callback(const InputManager::MultiFingerTouchCallbackArgs& touch) {
|
||||
if(!clientStillConnecting)
|
||||
drawData.cam.input_multi_finger_touch_callback(*this, touch);
|
||||
}
|
||||
|
||||
void World::input_multi_finger_motion_callback(const InputManager::MultiFingerMotionArgs& motion) {
|
||||
void World::input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion) {
|
||||
if(!clientStillConnecting)
|
||||
drawData.cam.input_multi_finger_motion_callback(*this, motion);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,14 +107,12 @@ class World {
|
|||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
void input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
void input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button);
|
||||
void input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch);
|
||||
void input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion);
|
||||
void input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axis);
|
||||
void input_multi_finger_touch_callback(const InputManager::MultiFingerTouchArgs& touch);
|
||||
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionArgs& motion);
|
||||
void input_multi_finger_touch_callback(const InputManager::MultiFingerTouchCallbackArgs& touch);
|
||||
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion);
|
||||
private:
|
||||
void load_empty_canvas();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue