Skip to content

Include Mac support and bugfixes. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Currently, the simplest way to use `GA::kit` is through [ofxGAkit](https://githu

Simply `git clone --recursive` the addon repo inside of your `openFrameworks/addons/` directory, then use the oF Project Generator to generate a project with the addon selected.

Full setup instructions can be found [here](https://github.com/gallagher-tech/ofxGAkit).
The addon works for both Windows and Mac. Full setup instructions can be found [here](https://github.com/gallagher-tech/ofxGAkit).

In this case, openFrameworks provides the windowing and rendering system (`glfw / openGL`), and automatically includes the necessary `nlohmann::json` and `glm` libraries.

### Bring Your Own Backend

We aim to make `GA::kit` "framework agnostic". This means that we would like it to play nicely with other C++ creative coding frameworks like Cinder - or it could be used on its own by including a few supporting libraries.

The only requirements beyond C++11 are including the `glm` and `nlohmann::json` libraries, and adding an openGL windowing library, like `glfw`.
The only requirements beyond C++14 are including the `glm` and `nlohmann::json` libraries, and adding an openGL windowing library, like `glfw`.

We could use your help:

Expand Down Expand Up @@ -64,7 +64,7 @@ We could use your help:

## Requirements

- C++11
- C++14
- OpenGL 3+
- [**glm**](https://github.com/g-truc/glm)
- [**nlohmann::json**](https://github.com/nlohmann/json)
Expand Down
32 changes: 24 additions & 8 deletions src/ga/graph/components/touchzone_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ class TouchZone : public ga::Component
if ( m_boundsInverted )
isInBounds = !isInBounds; // e.g. for click-off


switch ( touchEvt.type ) {
case TouchEvent::Type::PRESS: {
if ( isInBounds ) {
touchEvt.captured = true;
if ( m_isCapturingTouch ) {
touchEvt.captured = true;
}
// tap on
setState( State::ACTIVE );
event.type = TouchZone::Event::Type::PRESS;
Expand All @@ -73,10 +74,12 @@ class TouchZone : public ga::Component

case ga::TouchEvent::Type::DRAG: {
if ( isInBounds ) {
if ( m_isCapturingTouch ) {
touchEvt.captured = true;
}
if ( getState() == State::ACTIVE ) {
// dragged within bounds
event.type = TouchZone::Event::Type::DRAG_INSIDE;
std::cout << "dragged inside" << std::endl;
} else {
// drag into zone
// setState( State::ACTIVE );
Expand All @@ -97,6 +100,9 @@ class TouchZone : public ga::Component
case ga::TouchEvent::Type::RELEASE: {
if ( getState() == State::ACTIVE ) {
// tap release
if ( m_isCapturingTouch ) {
touchEvt.captured = true;
}
setState( State::INACTIVE );
event.type = TouchZone::Event::Type::RELEASE;
onTouchEvent( event );
Expand All @@ -108,6 +114,9 @@ class TouchZone : public ga::Component

case ga::TouchEvent::Type::CANCEL: {
// not sure how to handle this...
if ( m_isCapturingTouch ) {
touchEvt.captured = true;
}
setState( State::INACTIVE );
break;
}
Expand Down Expand Up @@ -135,14 +144,21 @@ class TouchZone : public ga::Component
m_state = State::DISABLED;
}

inline void setAllowLosingFocus( bool isAllowed = true ) {
inline void setAllowLosingFocus( bool isAllowed = true )
{
m_allowLosingFocus = isAllowed;
}

inline void setEnableCapturingTouch(bool isEnabled = true) {
inline void setEnableCapturingTouch( bool isEnabled = true )
{
m_isCapturingTouch = isEnabled;
}

inline bool getIsCapturingTouch()
{
return m_isCapturingTouch;
}

inline void invertBounds( bool invert = true )
{
m_boundsInverted = invert;
Expand Down Expand Up @@ -173,7 +189,7 @@ class TouchZone : public ga::Component
{
if ( !scene )
return;
m_touchConnection = scene->onTouchEvent.connect_scoped( [this]( TouchEvent& te ) { handleTouchEvent( te ); }, groupId );
m_touchConnection = scene->onTouchEvent.connect_scoped( [this]( TouchEvent& te ) { handleTouchEvent( te ); }, groupId );
}

void disconnectTouch()
Expand All @@ -194,8 +210,8 @@ class TouchZone : public ga::Component
State m_state;
ga::Connection m_touchConnection;
bool m_boundsInverted = false;
bool m_isCapturingTouch = true;
bool m_allowLosingFocus = false;
bool m_isCapturingTouch = true;
bool m_allowLosingFocus = false;
std::function<bool( TouchZone::Event )> m_customBoundsTest = nullptr;
};
} // namespace ga
44 changes: 43 additions & 1 deletion src/ga/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,49 @@ inline vec3 calcScaleToFit( const vec3& sourceSize, const vec3& containerSize, c

inline vec2 calcScaleToFit( const vec2& sourceSize, const vec2& containerSize, const FitMode& fitMode )
{
return calcScaleToFit( vec3( sourceSize, 1.f ), vec3( containerSize, 1.f ), fitMode );
vec2 scale = vec2( 1.f );

// calculate sizing based on fit mode
switch ( fitMode ) {

case FitMode::FIT: {
vec2 s = containerSize / sourceSize;
float s0 = std::min( s.x, s.y );
scale = vec2( s0 );
break;
}

case FitMode::STRETCH: {
scale = containerSize / sourceSize;
break;
}

case FitMode::COVER: {
vec2 s = containerSize / sourceSize;
float s1 = std::max( s.x, s.y );
scale = vec2( s1 );
break;
}

case FitMode::FIT_WIDTH: {
float sx = containerSize.x / sourceSize.x;
scale = vec2( sx );
break;
}

case FitMode::FIT_HEIGHT: {
float sy = containerSize.y / sourceSize.y;
scale = vec2( sy );
break;
}

case FitMode::FIT_DEPTH:
case FitMode::NONE:
default:
break;
}

return scale;
}

} // namespace ga