Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Add logic for adding AOI objects to canvas screens
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHenninger committed May 16, 2019
1 parent 3c4eb4f commit 4891207
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ fabric.Image.fromObject = function(_object, callback) {
})
}

// Add AOI object type ---------------------------------------------------------

// (apparently fabric requires camelcased constructors)
fabric.Aoi = fabric.util.createClass(fabric.Rect, {
type: 'aoi',
initialize: function(options={}) {
options.fill = 'rgba(0, 0, 0, 0.2)'
this.callSuper('initialize', options)
},
})

fabric.Aoi.fromObject = function(object, callback, forceAsync) {
return fabric.Object._fromObject('Aoi', object, callback, forceAsync);
}

// Canvas component ------------------------------------------------------------

const handlePadding = 6
Expand Down Expand Up @@ -354,6 +369,11 @@ export default class FabricCanvas extends Component {
...defaults,
...options,
})
case 'aoi':
return new fabric.Aoi({
width: 50, height: 50,
...defaults,
})
default:
return undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ const AddDropDown = (
Image
</DropdownItem>
<DropdownItem divider />
<DropdownItem header>Interaction</DropdownItem>
<DropdownItem
onClick={ () => addHandler('aoi') }
>
AOI
</DropdownItem>
<DropdownItem divider />
<DropdownItem header>From selected</DropdownItem>
<DropdownItem
onClick={ cloneHandler }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ({ selection, changeHandler }) =>
model=".strokeWidth"
component={ StrokeWidthDropdown }
controlProps={{
disabled: ['image', undefined].includes(selection.type),
disabled: ['image', 'aoi', undefined].includes(selection.type),
}}
/>
<Control
Expand All @@ -26,7 +26,7 @@ export default ({ selection, changeHandler }) =>
controlProps={{
icon: 'circle',
iconFallbackWeight: 'r',
disabled: ['image', undefined].includes(selection.type),
disabled: ['image', 'aoi', undefined].includes(selection.type),
}}
/>
<Control
Expand All @@ -35,7 +35,7 @@ export default ({ selection, changeHandler }) =>
controlProps={{
icon: 'circle',
iconWeight: 's',
disabled: ['line', 'image', undefined].includes(selection.type),
disabled: ['line', 'image', 'aoi', undefined].includes(selection.type),
}}
/>
</ButtonGroup>

0 comments on commit 4891207

Please sign in to comment.