Skip to content

Commit

Permalink
Add webcam rotation buttons (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Mar 20, 2017
1 parent 350c106 commit 13812be
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/web/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ export const defaultState = {
// The URL field is required for the M-JPEG stream
url: '',

centerFocus: false,
geometry: {
scale: 1.0,
rotation: 0, // 0: 0, 1: 90, 2: 180, 3: 270
flipHorizontally: false,
flipVertically: false,
scale: 1.0
}
flipVertically: false
},
crosshair: false
}
}
};
Expand Down
70 changes: 53 additions & 17 deletions src/web/widgets/Webcam/Webcam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class Webcam extends Component {
disabled,
mediaSource,
url,
centerFocus,
scale,
rotation,
flipHorizontally,
flipVertically,
scale
crosshair
} = state;

if (disabled) {
Expand All @@ -61,16 +62,20 @@ class Webcam extends Component {
);
}

const transformStyle = [
'translate(-50%, -50%)',
`rotateX(${flipVertically ? 180 : 0}deg)`,
`rotateY(${flipHorizontally ? 180 : 0}deg)`,
`rotate(${(rotation % 4) * 90}deg)`
].join(' ');

return (
<div className={styles['webcam-on-container']}>
{mediaSource === MEDIA_SOURCE_LOCAL &&
<div style={{ width: '100%' }}>
<WebcamMedia
className={classNames(
styles.center,
{ [styles.flipHorizontally]: flipHorizontally },
{ [styles.flipVertically]: flipVertically }
)}
className={styles.center}
style={{ transform: transformStyle }}
width={(100 * scale).toFixed(0) + '%'}
height="auto"
/>
Expand All @@ -83,16 +88,13 @@ class Webcam extends Component {
}}
src={url}
style={{
width: (100 * scale).toFixed(0) + '%'
width: (100 * scale).toFixed(0) + '%',
transform: transformStyle
}}
className={classNames(
styles.center,
{ [styles.flipHorizontally]: flipHorizontally },
{ [styles.flipVertically]: flipVertically }
)}
className={styles.center}
/>
}
{centerFocus &&
{crosshair &&
<div>
<Line
className={classNames(
Expand Down Expand Up @@ -128,6 +130,40 @@ class Webcam extends Component {
<div className={styles.toolbar}>
<div className={styles['scale-text']}>{scale}x</div>
<div className="pull-right">
<OverlayTrigger
overlay={<Tooltip>{i18n._('Rotate Left')}</Tooltip>}
placement="top"
>
<Anchor
className={styles.btnIcon}
onClick={actions.rotateLeft}
>
<i
className={classNames(
styles.icon,
styles.inverted,
styles.iconRotateLeft
)}
/>
</Anchor>
</OverlayTrigger>
<OverlayTrigger
overlay={<Tooltip>{i18n._('Rotate Right')}</Tooltip>}
placement="top"
>
<Anchor
className={styles.btnIcon}
onClick={actions.rotateRight}
>
<i
className={classNames(
styles.icon,
styles.inverted,
styles.iconRotateRight
)}
/>
</Anchor>
</OverlayTrigger>
<OverlayTrigger
overlay={<Tooltip>{i18n._('Flip Horizontally')}</Tooltip>}
placement="top"
Expand Down Expand Up @@ -163,18 +199,18 @@ class Webcam extends Component {
</Anchor>
</OverlayTrigger>
<OverlayTrigger
overlay={<Tooltip>{i18n._('Center Focus')}</Tooltip>}
overlay={<Tooltip>{i18n._('Crosshair')}</Tooltip>}
placement="top"
>
<Anchor
className={styles.btnIcon}
onClick={actions.toggleCenterFocus}
onClick={actions.toggleCrosshair}
>
<i
className={classNames(
styles.icon,
styles.inverted,
styles.iconCenterFocus
styles.iconCrosshair
)}
/>
</Anchor>
Expand Down
Binary file removed src/web/widgets/Webcam/images/128x128/webcam.png
Binary file not shown.
Binary file removed src/web/widgets/Webcam/images/16x16/webcam.png
Binary file not shown.
Binary file removed src/web/widgets/Webcam/images/24x24/webcam.png
Binary file not shown.
Binary file removed src/web/widgets/Webcam/images/32x32/webcam.png
Binary file not shown.
Binary file removed src/web/widgets/Webcam/images/64x64/webcam.png
Binary file not shown.
7 changes: 0 additions & 7 deletions src/web/widgets/Webcam/images/center-focus.svg

This file was deleted.

98 changes: 98 additions & 0 deletions src/web/widgets/Webcam/images/mono-rotate-left.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions src/web/widgets/Webcam/images/mono-rotate-right.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/web/widgets/Webcam/images/rotate-left.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/web/widgets/Webcam/images/rotate-right.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 13812be

Please sign in to comment.