|
|
@@ -28,10 +28,17 @@ void InputSourceGameController::gameControllerDeleter(SDL_GameController * gameC
|
|
|
|
|
|
InputSourceGameController::InputSourceGameController():
|
|
|
lastCheckTime(0),
|
|
|
- axisValueX(0),
|
|
|
- axisValueY(0),
|
|
|
- planDisX(0.0),
|
|
|
- planDisY(0.0)
|
|
|
+ cursorAxisValueX(0),
|
|
|
+ cursorAxisValueY(0),
|
|
|
+ cursorPlanDisX(0.0),
|
|
|
+ cursorPlanDisY(0.0),
|
|
|
+ scrollAxisMoved(false),
|
|
|
+ scrollStart(Point(0,0)),
|
|
|
+ scrollCurrent(Point(0,0)),
|
|
|
+ scrollAxisValueX(0),
|
|
|
+ scrollAxisValueY(0),
|
|
|
+ scrollPlanDisX(0.0),
|
|
|
+ scrollPlanDisY(0.0)
|
|
|
{
|
|
|
tryOpenAllGameControllers();
|
|
|
}
|
|
|
@@ -156,25 +163,34 @@ void InputSourceGameController::dispatchTriggerRightClick(int axisValue)
|
|
|
|
|
|
void InputSourceGameController::handleEventAxisMotion(const SDL_ControllerAxisEvent & axis)
|
|
|
{
|
|
|
+ tryToConvertCursor();
|
|
|
if(axis.axis == SDL_CONTROLLER_AXIS_LEFTX)
|
|
|
{
|
|
|
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
|
|
|
- axisValueX = getRealAxisValue(axis.value);
|
|
|
+ cursorAxisValueX = getRealAxisValue(axis.value);
|
|
|
+ else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
|
|
|
+ scrollAxisValueX = getRealAxisValue(axis.value);
|
|
|
}
|
|
|
else if(axis.axis == SDL_CONTROLLER_AXIS_LEFTY)
|
|
|
{
|
|
|
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
|
|
|
- axisValueY = getRealAxisValue(axis.value);
|
|
|
+ cursorAxisValueY = getRealAxisValue(axis.value);
|
|
|
+ else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
|
|
|
+ scrollAxisValueY = getRealAxisValue(axis.value);
|
|
|
}
|
|
|
if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTX)
|
|
|
{
|
|
|
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
|
|
|
- axisValueX = getRealAxisValue(axis.value);
|
|
|
+ cursorAxisValueX = getRealAxisValue(axis.value);
|
|
|
+ else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
|
|
|
+ scrollAxisValueX = getRealAxisValue(axis.value);
|
|
|
}
|
|
|
else if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTY)
|
|
|
{
|
|
|
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
|
|
|
- axisValueY = getRealAxisValue(axis.value);
|
|
|
+ cursorAxisValueY = getRealAxisValue(axis.value);
|
|
|
+ else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
|
|
|
+ scrollAxisValueY = getRealAxisValue(axis.value);
|
|
|
}
|
|
|
else if(config.isLeftClickTrigger(axis.axis))
|
|
|
{
|
|
|
@@ -191,6 +207,17 @@ void InputSourceGameController::handleEventAxisMotion(const SDL_ControllerAxisEv
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void InputSourceGameController::tryToConvertCursor()
|
|
|
+{
|
|
|
+ if(CCS && CCS->curh && CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
|
|
|
+ {
|
|
|
+ const Point & cursorPosition = CCS->curh->getCursorPosition();
|
|
|
+ CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
|
|
|
+ CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
|
|
|
+ GH.input().setCursorPosition(cursorPosition);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void InputSourceGameController::handleEventButtonDown(const SDL_ControllerButtonEvent & button)
|
|
|
{
|
|
|
const Point & position = GH.input().getCursorPosition();
|
|
|
@@ -236,19 +263,13 @@ void InputSourceGameController::doCursorMove(int deltaX, int deltaY)
|
|
|
if(deltaX == 0 && deltaY == 0)
|
|
|
return;
|
|
|
const Point & screenSize = GH.screenDimensions();
|
|
|
-
|
|
|
- // if joystick is connected when intro video plays, using hardware position will move cursor to the right position.
|
|
|
- bool isHardwareCursor = CCS && CCS->curh && CCS->curh->getShowType() == Cursor::ShowType::HARDWARE;
|
|
|
- const Point & cursorPosition = isHardwareCursor ? CCS->curh->getCursorPosition() : GH.getCursorPosition();
|
|
|
+ const Point & cursorPosition = GH.getCursorPosition();
|
|
|
int newX = std::min(std::max(cursorPosition.x + deltaX, 0), screenSize.x);
|
|
|
int newY = std::min(std::max(cursorPosition.y + deltaY, 0), screenSize.y);
|
|
|
Point targetPosition{newX, newY};
|
|
|
GH.input().setCursorPosition(targetPosition);
|
|
|
- if(CCS && CCS->curh) {
|
|
|
- if(CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
|
|
|
- CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
|
|
|
+ if(CCS && CCS->curh)
|
|
|
CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
int InputSourceGameController::getMoveDis(float planDis)
|
|
|
@@ -263,28 +284,71 @@ void InputSourceGameController::handleUpdate()
|
|
|
{
|
|
|
auto now = std::chrono::high_resolution_clock::now();
|
|
|
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
|
|
- if(lastCheckTime == 0)
|
|
|
- {
|
|
|
+ if (lastCheckTime == 0) {
|
|
|
lastCheckTime = nowMs;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
long long deltaTime = nowMs - lastCheckTime;
|
|
|
+ handleCursorUpdate(deltaTime);
|
|
|
+ handleScrollUpdate(deltaTime);
|
|
|
+ lastCheckTime = nowMs;
|
|
|
+}
|
|
|
|
|
|
- if(axisValueX == 0)
|
|
|
- planDisX = 0;
|
|
|
+void InputSourceGameController::handleCursorUpdate(long long deltaTime)
|
|
|
+{
|
|
|
+ if(cursorAxisValueX == 0)
|
|
|
+ cursorPlanDisX = 0;
|
|
|
else
|
|
|
- planDisX += ((float)deltaTime / 1000) * ((float)axisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
+ cursorPlanDisX += ((float)deltaTime / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
|
|
|
- if(axisValueY == 0)
|
|
|
- planDisY = 0;
|
|
|
+ if(cursorAxisValueY == 0)
|
|
|
+ cursorPlanDisY = 0;
|
|
|
else
|
|
|
- planDisY += ((float)deltaTime / 1000) * ((float)axisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
+ cursorPlanDisY += ((float)deltaTime / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
|
|
|
- int moveDisX = getMoveDis(planDisX);
|
|
|
- int moveDisY = getMoveDis(planDisY);
|
|
|
- planDisX -= moveDisX;
|
|
|
- planDisY -= moveDisY;
|
|
|
+ int moveDisX = getMoveDis(cursorPlanDisX);
|
|
|
+ int moveDisY = getMoveDis(cursorPlanDisY);
|
|
|
+ cursorPlanDisX -= moveDisX;
|
|
|
+ cursorPlanDisY -= moveDisY;
|
|
|
doCursorMove(moveDisX, moveDisY);
|
|
|
- lastCheckTime = nowMs;
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+void InputSourceGameController::handleScrollUpdate(long long deltaTime)
|
|
|
+{
|
|
|
+ if(!scrollAxisMoved && isScrollAxisReleased())
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if(!scrollAxisMoved && !isScrollAxisReleased())
|
|
|
+ {
|
|
|
+ scrollAxisMoved = true;
|
|
|
+ scrollCurrent = scrollStart = GH.input().getCursorPosition();
|
|
|
+ GH.events().dispatchGesturePanningStarted(scrollStart);
|
|
|
+ }
|
|
|
+ else if(scrollAxisMoved && isScrollAxisReleased())
|
|
|
+ {
|
|
|
+ GH.events().dispatchGesturePanningEnded(scrollStart, scrollCurrent);
|
|
|
+ scrollAxisMoved = false;
|
|
|
+ scrollPlanDisX = scrollPlanDisY = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ scrollPlanDisX += ((float)deltaTime / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
+ scrollPlanDisY += ((float)deltaTime / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
|
|
|
+ int moveDisX = getMoveDis(scrollPlanDisX);
|
|
|
+ int moveDisY = getMoveDis(scrollPlanDisY);
|
|
|
+ if(moveDisX != 0 || moveDisY != 0)
|
|
|
+ {
|
|
|
+ scrollPlanDisX -= moveDisX;
|
|
|
+ scrollPlanDisY -= moveDisY;
|
|
|
+ scrollCurrent.x += moveDisX;
|
|
|
+ scrollCurrent.y += moveDisY;
|
|
|
+ Point distance(moveDisX, moveDisY);
|
|
|
+ GH.events().dispatchGesturePanning(scrollStart, scrollCurrent, distance);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool InputSourceGameController::isScrollAxisReleased()
|
|
|
+{
|
|
|
+ return scrollAxisValueX == 0 && scrollAxisValueY == 0;
|
|
|
+}
|