Added pointer and tweaked the code
modified: css/reveal.css modified: css/reveal.min.css modified: plugin/leap/leap.js
This commit is contained in:
parent
a06c84e42a
commit
dbcbc7aa69
3 changed files with 81 additions and 16 deletions
|
@ -1605,3 +1605,12 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************
|
||||||
|
* LEAP PLUGIN
|
||||||
|
*********************************************/
|
||||||
|
|
||||||
|
#leap {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 50;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
6
css/reveal.min.css
vendored
6
css/reveal.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -22,27 +22,75 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var controller = new Leap.Controller({enableGestures: true}),
|
var controller = new Leap.Controller({enableGestures: true}),
|
||||||
config = Reveal.getConfig().leap ||
|
leapConfig = Reveal.getConfig().leap,
|
||||||
{
|
leapDOM = document.createElement('div'),
|
||||||
naturalSwipe: true
|
body = document.body,
|
||||||
|
config = {
|
||||||
|
naturalSwipe : true,
|
||||||
|
pointerDefault : 15,
|
||||||
|
pointerColor : '#00aaff',
|
||||||
|
pointerOpacity : 0.75
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Merge user defined settings with defaults
|
||||||
|
if ( leapConfig ) {
|
||||||
|
for (key in leapConfig) {
|
||||||
|
config[key] = leapConfig[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
leapDOM.id = 'leap';
|
||||||
|
|
||||||
|
leapDOM.style.filter = 'alpha(opacity="'+ config.pointerOpacity +'")';
|
||||||
|
leapDOM.style.opacity = config.pointerOpacity;
|
||||||
|
leapDOM.style.backgroundColor = config.pointerColor;
|
||||||
|
|
||||||
|
body.appendChild(leapDOM);
|
||||||
|
|
||||||
controller.on('frame', function (frame) {
|
controller.on('frame', function (frame) {
|
||||||
|
|
||||||
|
// Pointer code
|
||||||
|
if ( frame.hands.length === 1 && frame.fingers.length === 1 ) {
|
||||||
|
var size = -2 * frame.hands[0].palmPosition[2];
|
||||||
|
|
||||||
|
if ( size < config.pointerDefault ) {
|
||||||
|
size = config.pointerDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
leapDOM.style.bottom =
|
||||||
|
frame.hands[0].palmPosition[1] * (body.offsetHeight / 100) - body.offsetHeight + 'px';
|
||||||
|
|
||||||
|
leapDOM.style.left =
|
||||||
|
frame.hands[0].palmPosition[0] * (body.offsetWidth / 100) + (body.offsetWidth / 2) + 'px';
|
||||||
|
|
||||||
|
leapDOM.style.visibility = 'visible';
|
||||||
|
leapDOM.style.width = size + 'px';
|
||||||
|
leapDOM.style.height = size + 'px';
|
||||||
|
leapDOM.style.borderRadius = size - 5 + 'px';
|
||||||
|
} else {
|
||||||
|
// Hide pointer on exit
|
||||||
|
leapDOM.style.visibility = 'hidden';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestures
|
||||||
if ( frame.gestures.length > 0 ) {
|
if ( frame.gestures.length > 0 ) {
|
||||||
var gesture = frame.gestures[0],
|
var gesture = frame.gestures[0];
|
||||||
x = gesture.direction[0],
|
|
||||||
|
// One hand gestures
|
||||||
|
if( frame.hands.length === 1 ) {
|
||||||
|
// Swipe gestures. 2+ fingers.
|
||||||
|
if ( frame.fingers.length > 1 && gesture.speed > 1000 && gesture.state === 'start' && gesture.type === 'swipe' ) {
|
||||||
|
var x = gesture.direction[0],
|
||||||
y = gesture.direction[1];
|
y = gesture.direction[1];
|
||||||
|
|
||||||
|
// Left/right swipe gestures
|
||||||
if ( gesture.speed > 1000 && gesture.state === 'start' && gesture.type === 'swipe' ) {
|
|
||||||
if( frame.hands.length === 1 && frame.fingers.length > 1 ) {
|
|
||||||
if ( Math.abs(x) > Math.abs(y) ) {
|
if ( Math.abs(x) > Math.abs(y) ) {
|
||||||
if ( x > 0 ) {
|
if ( x > 0 ) {
|
||||||
config.naturalSwipe ? Reveal.left() : Reveal.right();
|
config.naturalSwipe ? Reveal.left() : Reveal.right();
|
||||||
} else {
|
} else {
|
||||||
config.naturalSwipe ? Reveal.right() : Reveal.left();
|
config.naturalSwipe ? Reveal.right() : Reveal.left();
|
||||||
}
|
}
|
||||||
|
// Up/down swipe gestures
|
||||||
} else {
|
} else {
|
||||||
if ( y > 0 ) {
|
if ( y > 0 ) {
|
||||||
config.naturalSwipe ? Reveal.down() : Reveal.up();
|
config.naturalSwipe ? Reveal.down() : Reveal.up();
|
||||||
|
@ -50,10 +98,12 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
|
||||||
config.naturalSwipe ? Reveal.up() : Reveal.down();
|
config.naturalSwipe ? Reveal.up() : Reveal.down();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( frame.hands.length == 2 ) {
|
|
||||||
if ( y > 0 ) {
|
|
||||||
Reveal.toggleOverview();
|
|
||||||
}
|
}
|
||||||
|
// Two hand gestures
|
||||||
|
} else if( frame.hands.length == 2 ) {
|
||||||
|
// All upwards 2 hand gestures = toggle overview
|
||||||
|
if ( gesture.direction[1] > 0 ) {
|
||||||
|
Reveal.toggleOverview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue