-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from projectstorm/feature_scale_selection
selection boxes keep the same border thickness as the scale changes
- Loading branch information
Showing
5 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...frontend/src/routes/content/widgets/react-canvas/controls-layer/ControlsElementWidget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from 'react'; | ||
import { ImageElement } from '../image-element/ImageElementFactory'; | ||
import { styled } from '../../../../../theme/theme'; | ||
import { useForceUpdate } from '../../../../../hooks/useForceUpdate'; | ||
import { useEffect } from 'react'; | ||
import { ImageLayerModel } from '../image-layer/ImageLayerFactory'; | ||
|
||
export interface ControlsElementWidgetProps { | ||
model: ImageElement; | ||
} | ||
|
||
export const ControlsElementWidget: React.FC<ControlsElementWidgetProps> = (props) => { | ||
const forceUpdate = useForceUpdate(); | ||
useEffect(() => { | ||
const l = props.model.registerListener({ | ||
selectionChanged: () => { | ||
forceUpdate(); | ||
} | ||
}); | ||
return l.deregister; | ||
}, []); | ||
if (!props.model.isSelected()) { | ||
return null; | ||
} | ||
|
||
const canvas = (props.model.getParent() as ImageLayerModel).getParent(); | ||
const zoom = canvas.getZoomLevel() / 100; | ||
|
||
return ( | ||
<S.Container | ||
style={{ | ||
left: props.model.getX() * zoom + canvas.getOffsetX(), | ||
top: props.model.getY() * zoom + canvas.getOffsetY(), | ||
width: props.model.width * zoom, | ||
height: props.model.height * zoom | ||
}} | ||
/> | ||
); | ||
}; | ||
namespace S { | ||
export const Container = styled.div` | ||
position: absolute; | ||
border: solid 2px ${(p) => p.theme.editor.selected}; | ||
box-shadow: 0 0 20px ${(p) => p.theme.editor.selectedShadow}; | ||
box-sizing: border-box; | ||
pointer-events: none; | ||
`; | ||
} |
54 changes: 54 additions & 0 deletions
54
...-frontend/src/routes/content/widgets/react-canvas/controls-layer/ControlsLayerFactory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import { | ||
AbstractReactFactory, | ||
FactoryBank, | ||
GenerateModelEvent, | ||
GenerateWidgetEvent, | ||
LayerModel, | ||
LayerModelGenerics | ||
} from '@projectstorm/react-canvas-core'; | ||
import { ImageElement, ImageElementFactory } from '../image-element/ImageElementFactory'; | ||
import * as _ from 'lodash'; | ||
import { ConceptCanvasEngine } from '../ConceptCanvasEngine'; | ||
import { ConceptCanvasModel } from '../ConceptCanvasModel'; | ||
import { ControlsElementWidget } from './ControlsElementWidget'; | ||
|
||
export class ControlsLayerFactory extends AbstractReactFactory<ControlsLayerModel, ConceptCanvasEngine> { | ||
static TYPE = 'concept/controls/layer'; | ||
|
||
constructor() { | ||
super(ControlsLayerFactory.TYPE); | ||
} | ||
|
||
generateModel(event: GenerateModelEvent): ControlsLayerModel { | ||
return new ControlsLayerModel(); | ||
} | ||
|
||
generateReactWidget(event: GenerateWidgetEvent<ControlsLayerModel>): JSX.Element { | ||
return ( | ||
<> | ||
{_.map(event.model.getParent().getLayers()[0].getModels(), (m: ImageElement) => { | ||
return <ControlsElementWidget model={m} key={m.getID()} />; | ||
})} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export type ControlsLayerGenerics = LayerModelGenerics & { | ||
ENGINE: ConceptCanvasEngine; | ||
PARENT: ConceptCanvasModel; | ||
}; | ||
|
||
export class ControlsLayerModel extends LayerModel<ControlsLayerGenerics> { | ||
constructor() { | ||
super({ | ||
type: ControlsLayerFactory.TYPE, | ||
transformed: false | ||
}); | ||
} | ||
|
||
getChildModelFactoryBank(engine: ControlsLayerGenerics['ENGINE']): FactoryBank<ImageElementFactory> { | ||
return engine.elementBank; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters