-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,414 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <Timer.h> | ||
#include <set> | ||
|
||
namespace NXKit { | ||
|
||
class UITouch; | ||
class UIEvent { | ||
public: | ||
std::set<std::shared_ptr<UITouch>> allTouches() { return _allTouches; } | ||
Timer timestamp() { return _timestamp; } | ||
|
||
UIEvent(); | ||
virtual ~UIEvent() {} | ||
private: | ||
UIEvent(std::shared_ptr<UITouch> touch); | ||
|
||
static std::vector<std::shared_ptr<UIEvent>> activeEvents; | ||
std::set<std::shared_ptr<UITouch>> _allTouches; | ||
Timer _timestamp = Timer(); | ||
|
||
friend class UIApplication; | ||
friend class UIWindow; | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include <functional> | ||
#include <tools/SharedBase.hpp> | ||
|
||
namespace NXKit { | ||
|
||
class UITouch; | ||
class UIPress; | ||
class UIPressesEvent; | ||
|
||
enum class UIGestureRecognizerState { | ||
possible, | ||
began, | ||
recognized, | ||
changed, | ||
ended, | ||
cancelled, | ||
failed | ||
}; | ||
|
||
class UIView; | ||
class UIEvent; | ||
class UIGestureRecognizer; | ||
class UIGestureRecognizerDelegate { | ||
public: | ||
virtual bool gestureRecognizerShouldRecognizeSimultaneouslyWith(std::shared_ptr<UIGestureRecognizer> gestureRecognizer, std::shared_ptr<UIGestureRecognizer> otherGestureRecognizer) { return false; } | ||
}; | ||
|
||
class UIGestureRecognizer: public enable_shared_from_this<UIGestureRecognizer> { | ||
public: | ||
std::weak_ptr<UIGestureRecognizerDelegate> delegate; | ||
std::function<void(UIGestureRecognizerState)> onStateChanged = [](auto state){}; | ||
|
||
UIGestureRecognizer(std::function<void(UIGestureRecognizerState)> onStateChanged = [](auto) {}); | ||
virtual ~UIGestureRecognizer(); | ||
|
||
bool isEnabled() { return _isEnabled; } | ||
void setEnabled(bool enabled); | ||
|
||
UIGestureRecognizerState state() { return _state; } | ||
void setState(UIGestureRecognizerState state); | ||
|
||
std::weak_ptr<UIView> view() { return _view; } | ||
|
||
virtual void touchesBegan(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
virtual void touchesMoved(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
virtual void touchesEnded(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
virtual void touchesCancelled(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
|
||
virtual void pressesBegan(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
virtual void pressesChanged(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
virtual void pressesEnded(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
virtual void pressesCancelled(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
|
||
private: | ||
bool _isEnabled = true; | ||
std::weak_ptr<UIView> _view; | ||
std::vector<std::shared_ptr<UITouch>> _allTouches; | ||
UIGestureRecognizerState _state = UIGestureRecognizerState::possible; | ||
|
||
void _touchesBegan(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
void _touchesMoved(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
void _touchesEnded(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
void _touchesCancelled(std::vector<std::shared_ptr<UITouch>> touches, std::shared_ptr<UIEvent> event); | ||
|
||
void _pressesBegan(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
void _pressesChanged(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
void _pressesEnded(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
void _pressesCancelled(std::vector<std::shared_ptr<UIPress>> presses, std::shared_ptr<UIPressesEvent> event); | ||
|
||
bool recognitionCondition(); | ||
|
||
void addTouch(std::shared_ptr<UITouch> touch); | ||
void removeTouch(std::shared_ptr<UITouch> touch); | ||
void cancelOtherGestureRecognizersThatShouldNotRecognizeSimultaneously(); | ||
|
||
friend class UIView; | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <UIKeyboardHIDUsage.h> | ||
#include <tools/Tools.hpp> | ||
|
||
namespace NXKit { | ||
|
||
enum class UIKeyModifierFlags { | ||
alphaShift = 1 << 0, | ||
shift = 1 << 1, | ||
control = 1 << 2, | ||
alternate = 1 << 3, | ||
command = 1 << 4, | ||
numericPad = 1 << 5, | ||
}; | ||
|
||
enum class UIPressType { | ||
none, | ||
upArrow, | ||
downArrow, | ||
leftArrow, | ||
rightArrow, | ||
select, | ||
menu, | ||
}; | ||
|
||
struct UIKey { | ||
public: | ||
UIPressType type(); | ||
std::string characters() { return _characters; } | ||
OptionSet<UIKeyModifierFlags> modifierFlags() { return _modifierFlags; } | ||
UIKeyboardHIDUsage keyCode() { return _keyCode; } | ||
|
||
private: | ||
std::string _characters; | ||
OptionSet<UIKeyModifierFlags> _modifierFlags; | ||
UIKeyboardHIDUsage _keyCode; | ||
|
||
friend class UIApplication; | ||
}; | ||
|
||
} | ||
|
Oops, something went wrong.