Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Mar 23, 2021
1 parent 10cfcec commit 8bb51a9
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion library/include/borealis/core/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <String>
#include <string>

namespace brls
{
Expand Down
4 changes: 3 additions & 1 deletion library/include/borealis/core/gesture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ enum class GestureState
class GestureRecognizer
{
public:
virtual ~GestureRecognizer() { }

// Main recognition loop, for internal usage only, should not be called anywhere, but Application
virtual GestureState recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound);
virtual GestureState recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound);

// Interrupt this recognizer
// If onlyIfUnsureState == true recognizer will be interupted
Expand Down
10 changes: 5 additions & 5 deletions library/include/borealis/core/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ enum class TouchPhase
};

// Contains raw touch data
struct RawTouch
struct RawTouchState
{
bool pressed;
Point position;
};

// Contains touch data filled with it's current phase
struct Touch
struct TouchState
{
TouchPhase phase;
Point position;
Expand All @@ -111,14 +111,14 @@ class InputManager
virtual void updateControllerState(ControllerState* state) = 0;

/**
* Called once every frame to fill the given Touch struct with the touch state.
* Called once every frame to fill the given RawTouchState struct with the raw touch data.
*/
virtual void updateTouchState(RawTouch* state) = 0;
virtual void updateTouchState(RawTouchState* state) = 0;

/**
* Calculate current touch phase based on it's previous state
*/
static Touch computeTouchState(RawTouch currentTouch, Touch lastFrameState);
static TouchState computeTouchState(RawTouchState currentTouch, TouchState lastFrameState);
};

}; // namespace brls
12 changes: 8 additions & 4 deletions library/include/borealis/core/touch/pan_gesture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <borealis/core/event.hpp>
#include <borealis/core/gesture.hpp>

namespace brls
Expand Down Expand Up @@ -44,7 +45,7 @@ struct PanGestureStatus
PanAcceleration acceleration;
};

typedef std::function<void(PanGestureStatus)> PanGestureRespond;
typedef Event<PanGestureStatus> PanGestureEvent;

// Axis of pan recognition start conditions
enum class PanAxis
Expand All @@ -63,17 +64,20 @@ enum class PanAxis
class PanGestureRecognizer : public GestureRecognizer
{
public:
PanGestureRecognizer(PanGestureRespond respond, PanAxis axis);
GestureState recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound) override;
PanGestureRecognizer(PanGestureEvent::Callback respond, PanAxis axis);
GestureState recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound) override;

// Get pan gesture axis
PanAxis getAxis() const { return this->axis; }

// Get current state of recognizer
PanGestureStatus getCurrentStatus();

// Get pan gesture event
PanGestureEvent getPanGestureEvent() const { return panEvent; }

private:
PanGestureRespond respond;
PanGestureEvent panEvent;
Point position;
Point startPosition;
Point delta;
Expand Down
2 changes: 1 addition & 1 deletion library/include/borealis/core/touch/tap_gesture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TapGestureRecognizer : public GestureRecognizer
{
public:
TapGestureRecognizer(TapGestureRespond respond, bool callbackOnEndOnly = true);
GestureState recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound) override;
GestureState recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound) override;

// Get current state of recognizer
TapGestureStatus getCurrentStatus();
Expand Down
2 changes: 1 addition & 1 deletion library/include/borealis/core/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ class View
* that needs to play it's own click sound,
* so play default is allowed
*/
bool gestureRecognizerRequest(Touch touch, View* firstResponder);
bool gestureRecognizerRequest(TouchState touch, View* firstResponder);

/**
* Called each frame
Expand Down
2 changes: 1 addition & 1 deletion library/include/borealis/platforms/glfw/glfw_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GLFWInputManager : public InputManager

void updateControllerState(ControllerState* state) override;

void updateTouchState(RawTouch* state) override;
void updateTouchState(RawTouchState* state) override;

private:
GLFWwindow* window;
Expand Down
6 changes: 3 additions & 3 deletions library/include/borealis/platforms/switch/switch_input.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2021 natinusala
Copyright (C) 2021 XITRIX
Copyright (C) 2021 XITRIX
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,11 +32,11 @@ class SwitchInputManager : public InputManager

void updateControllerState(ControllerState* state);

void updateTouchState(RawTouch* state);
void updateTouchState(RawTouchState* state);

private:
PadState padState;
Touch oldTouch;
TouchState oldTouch;
};

} // namespace brls
18 changes: 8 additions & 10 deletions library/lib/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ bool Application::mainLoop()

// Input
ControllerState controllerState = {};
RawTouch rawTouch = {};
RawTouchState rawTouch = {};

InputManager* inputManager = Application::platform->getInputManager();
inputManager->updateTouchState(&rawTouch);
inputManager->updateControllerState(&controllerState);

static Touch oldTouch;
Touch touchState = InputManager::computeTouchState(rawTouch, oldTouch);
oldTouch = touchState;
static TouchState oldTouch;
TouchState touchState = InputManager::computeTouchState(rawTouch, oldTouch);
oldTouch = touchState;

// Touch controller events
switch (touchState.phase)
Expand All @@ -181,9 +181,10 @@ bool Application::mainLoop()
Application::setInputType(InputType::TOUCH);

// Search for first responder, which will be the root of recognition tree
firstResponder = Application::activitiesStack[Application::activitiesStack.size() - 1]
->getContentView()
->hitTest(touchState.position);
if (Application::activitiesStack.size() > 0)
firstResponder = Application::activitiesStack[Application::activitiesStack.size() - 1]
->getContentView()
->hitTest(touchState.position);
break;
case TouchPhase::NONE:
firstResponder = nullptr;
Expand Down Expand Up @@ -366,9 +367,7 @@ bool Application::setInputType(InputType type)
Application::inputType = type;

if (type == InputType::GAMEPAD)
{
Application::currentFocus->onFocusGained();
}

return true;
}
Expand Down Expand Up @@ -405,7 +404,6 @@ bool Application::handleAction(char button)

if (action.available)
{

if (action.actionListener(hintParent))
{
if (button == BUTTON_A)
Expand Down
2 changes: 1 addition & 1 deletion library/lib/core/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ View* Box::getDefaultFocus()
View* Box::hitTest(Point point)
{
// Check if touch fits in view frame
if (getFrame().pointInside(point))
if (this->getFrame().pointInside(point))
{
Logger::debug(describe() + ": --- X: " + std::to_string((int)getX()) + ", Y: " + std::to_string((int)getY()) + ", W: " + std::to_string((int)getWidth()) + ", H: " + std::to_string((int)getHeight()));
for (View* child : this->children)
Expand Down
2 changes: 1 addition & 1 deletion library/lib/core/geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 natinusala
Copyright 2021 XITRIX
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion library/lib/core/gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace brls
{

GestureState GestureRecognizer::recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound)
GestureState GestureRecognizer::recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound)
{
return GestureState::FAILED;
}
Expand Down
10 changes: 1 addition & 9 deletions library/lib/core/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,22 @@
namespace brls
{

Touch InputManager::computeTouchState(RawTouch currentTouch, Touch lastFrameState)
TouchState InputManager::computeTouchState(RawTouchState currentTouch, TouchState lastFrameState)
{
if (currentTouch.pressed)
{
lastFrameState.position = currentTouch.position;
if (lastFrameState.phase == TouchPhase::START || lastFrameState.phase == TouchPhase::STAY)
{
lastFrameState.phase = TouchPhase::STAY;
}
else
{
lastFrameState.phase = TouchPhase::START;
}
}
else
{
if (lastFrameState.phase == TouchPhase::END || lastFrameState.phase == TouchPhase::NONE)
{
lastFrameState.phase = TouchPhase::NONE;
}
else
{
lastFrameState.phase = TouchPhase::END;
}
}

return lastFrameState;
Expand Down
14 changes: 7 additions & 7 deletions library/lib/core/touch/pan_gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
namespace brls
{

PanGestureRecognizer::PanGestureRecognizer(PanGestureRespond respond, PanAxis axis)
: respond(respond)
, axis(axis)
PanGestureRecognizer::PanGestureRecognizer(PanGestureEvent::Callback respond, PanAxis axis)
: axis(axis)
{
panEvent.subscribe(respond);
}

GestureState PanGestureRecognizer::recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound)
GestureState PanGestureRecognizer::recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound)
{
if (!enabled)
return GestureState::FAILED;
Expand All @@ -41,8 +41,8 @@ GestureState PanGestureRecognizer::recognitionLoop(Touch touch, View* view, bool
{
if (this->state == GestureState::INTERRUPTED || this->state == GestureState::FAILED)
{
if (respond && this->state != lastState)
this->respond(getCurrentStatus());
if (this->state != lastState)
this->panEvent.fire(getCurrentStatus());

lastState = this->state;
return this->state;
Expand Down Expand Up @@ -117,7 +117,7 @@ GestureState PanGestureRecognizer::recognitionLoop(Touch touch, View* view, bool
{
PanGestureStatus state = getCurrentStatus();
state.acceleration = acceleration;
this->respond(state);
this->panEvent.fire(state);
}

break;
Expand Down
2 changes: 1 addition & 1 deletion library/lib/core/touch/tap_gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TapGestureRecognizer::TapGestureRecognizer(TapGestureRespond respond, bool callb
{
}

GestureState TapGestureRecognizer::recognitionLoop(Touch touch, View* view, bool* shouldPlayDefaultSound)
GestureState TapGestureRecognizer::recognitionLoop(TouchState touch, View* view, bool* shouldPlayDefaultSound)
{
if (!enabled)
return GestureState::FAILED;
Expand Down
2 changes: 1 addition & 1 deletion library/lib/core/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void View::addGestureRecognizer(GestureRecognizer* recognizer)
this->gestureRecognizers.push_back(recognizer);
}

bool View::gestureRecognizerRequest(Touch touch, View* firstResponder)
bool View::gestureRecognizerRequest(TouchState touch, View* firstResponder)
{
bool shouldPlayDefaultSound = touch.phase == TouchPhase::START;

Expand Down
2 changes: 1 addition & 1 deletion library/lib/platforms/glfw/glfw_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void GLFWInputManager::updateControllerState(ControllerState* state)
}
}

void GLFWInputManager::updateTouchState(RawTouch* state)
void GLFWInputManager::updateTouchState(RawTouchState* state)
{
// Get touchscreen state
double x, y;
Expand Down
2 changes: 1 addition & 1 deletion library/lib/platforms/switch/switch_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void SwitchInputManager::updateControllerState(ControllerState* state)
}
}

void SwitchInputManager::updateTouchState(RawTouch* state)
void SwitchInputManager::updateTouchState(RawTouchState* state)
{
// Get touchscreen state
static HidTouchScreenState hidState = { 0 };
Expand Down

0 comments on commit 8bb51a9

Please sign in to comment.