Skip to content

Commit 57b58a1

Browse files
authored
Merge pull request #7 from gallagher-tech/develop
Include Mac support and bugfixes.
2 parents 93c6a99 + af39250 commit 57b58a1

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Currently, the simplest way to use `GA::kit` is through [ofxGAkit](https://githu
2626

2727
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.
2828

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

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

3333
### Bring Your Own Backend
3434

3535
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.
3636

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

3939
We could use your help:
4040

@@ -64,7 +64,7 @@ We could use your help:
6464

6565
## Requirements
6666

67-
- C++11
67+
- C++14
6868
- OpenGL 3+
6969
- [**glm**](https://github.com/g-truc/glm)
7070
- [**nlohmann::json**](https://github.com/nlohmann/json)

src/ga/graph/components/touchzone_component.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ class TouchZone : public ga::Component
5858
if ( m_boundsInverted )
5959
isInBounds = !isInBounds; // e.g. for click-off
6060

61-
6261
switch ( touchEvt.type ) {
6362
case TouchEvent::Type::PRESS: {
6463
if ( isInBounds ) {
65-
touchEvt.captured = true;
64+
if ( m_isCapturingTouch ) {
65+
touchEvt.captured = true;
66+
}
6667
// tap on
6768
setState( State::ACTIVE );
6869
event.type = TouchZone::Event::Type::PRESS;
@@ -73,10 +74,12 @@ class TouchZone : public ga::Component
7374

7475
case ga::TouchEvent::Type::DRAG: {
7576
if ( isInBounds ) {
77+
if ( m_isCapturingTouch ) {
78+
touchEvt.captured = true;
79+
}
7680
if ( getState() == State::ACTIVE ) {
7781
// dragged within bounds
7882
event.type = TouchZone::Event::Type::DRAG_INSIDE;
79-
std::cout << "dragged inside" << std::endl;
8083
} else {
8184
// drag into zone
8285
// setState( State::ACTIVE );
@@ -97,6 +100,9 @@ class TouchZone : public ga::Component
97100
case ga::TouchEvent::Type::RELEASE: {
98101
if ( getState() == State::ACTIVE ) {
99102
// tap release
103+
if ( m_isCapturingTouch ) {
104+
touchEvt.captured = true;
105+
}
100106
setState( State::INACTIVE );
101107
event.type = TouchZone::Event::Type::RELEASE;
102108
onTouchEvent( event );
@@ -108,6 +114,9 @@ class TouchZone : public ga::Component
108114

109115
case ga::TouchEvent::Type::CANCEL: {
110116
// not sure how to handle this...
117+
if ( m_isCapturingTouch ) {
118+
touchEvt.captured = true;
119+
}
111120
setState( State::INACTIVE );
112121
break;
113122
}
@@ -135,14 +144,21 @@ class TouchZone : public ga::Component
135144
m_state = State::DISABLED;
136145
}
137146

138-
inline void setAllowLosingFocus( bool isAllowed = true ) {
147+
inline void setAllowLosingFocus( bool isAllowed = true )
148+
{
139149
m_allowLosingFocus = isAllowed;
140150
}
141151

142-
inline void setEnableCapturingTouch(bool isEnabled = true) {
152+
inline void setEnableCapturingTouch( bool isEnabled = true )
153+
{
143154
m_isCapturingTouch = isEnabled;
144155
}
145156

157+
inline bool getIsCapturingTouch()
158+
{
159+
return m_isCapturingTouch;
160+
}
161+
146162
inline void invertBounds( bool invert = true )
147163
{
148164
m_boundsInverted = invert;
@@ -173,7 +189,7 @@ class TouchZone : public ga::Component
173189
{
174190
if ( !scene )
175191
return;
176-
m_touchConnection = scene->onTouchEvent.connect_scoped( [this]( TouchEvent& te ) { handleTouchEvent( te ); }, groupId );
192+
m_touchConnection = scene->onTouchEvent.connect_scoped( [this]( TouchEvent& te ) { handleTouchEvent( te ); }, groupId );
177193
}
178194

179195
void disconnectTouch()
@@ -194,8 +210,8 @@ class TouchZone : public ga::Component
194210
State m_state;
195211
ga::Connection m_touchConnection;
196212
bool m_boundsInverted = false;
197-
bool m_isCapturingTouch = true;
198-
bool m_allowLosingFocus = false;
213+
bool m_isCapturingTouch = true;
214+
bool m_allowLosingFocus = false;
199215
std::function<bool( TouchZone::Event )> m_customBoundsTest = nullptr;
200216
};
201217
} // namespace ga

src/ga/layout.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,49 @@ inline vec3 calcScaleToFit( const vec3& sourceSize, const vec3& containerSize, c
106106

107107
inline vec2 calcScaleToFit( const vec2& sourceSize, const vec2& containerSize, const FitMode& fitMode )
108108
{
109-
return calcScaleToFit( vec3( sourceSize, 1.f ), vec3( containerSize, 1.f ), fitMode );
109+
vec2 scale = vec2( 1.f );
110+
111+
// calculate sizing based on fit mode
112+
switch ( fitMode ) {
113+
114+
case FitMode::FIT: {
115+
vec2 s = containerSize / sourceSize;
116+
float s0 = std::min( s.x, s.y );
117+
scale = vec2( s0 );
118+
break;
119+
}
120+
121+
case FitMode::STRETCH: {
122+
scale = containerSize / sourceSize;
123+
break;
124+
}
125+
126+
case FitMode::COVER: {
127+
vec2 s = containerSize / sourceSize;
128+
float s1 = std::max( s.x, s.y );
129+
scale = vec2( s1 );
130+
break;
131+
}
132+
133+
case FitMode::FIT_WIDTH: {
134+
float sx = containerSize.x / sourceSize.x;
135+
scale = vec2( sx );
136+
break;
137+
}
138+
139+
case FitMode::FIT_HEIGHT: {
140+
float sy = containerSize.y / sourceSize.y;
141+
scale = vec2( sy );
142+
break;
143+
}
144+
145+
case FitMode::FIT_DEPTH:
146+
case FitMode::NONE:
147+
default:
148+
break;
149+
}
150+
151+
return scale;
110152
}
111153

112154
} // namespace ga

0 commit comments

Comments
 (0)