-
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.
- Loading branch information
Showing
15 changed files
with
237 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { ShapeBlock } from './ShapeBlock' | ||
import { BasicPropName } from '@BlockHub/Block/Block' | ||
import { Square, Triangle, Round, Star, HexagonOne } from '@icon-park/vue-next' | ||
const { block } = defineProps<{ | ||
block: ShapeBlock | ||
}>() | ||
const { x, y, width, height, rotate, shape } = block | ||
const props = ref({ x, y, width, height, rotate }) | ||
block.props.events.update.on(({ key, to }) => { | ||
if (['x', 'y', 'width', 'height', 'rotate'].includes(key)) { | ||
const name = key as BasicPropName | ||
props.value[name] = to as number | ||
} | ||
}) | ||
const ShapeComponent = { | ||
rect: Square, | ||
triangle: Triangle, | ||
circle: Round, | ||
star: Star, | ||
hexagon: HexagonOne, | ||
}[shape] | ||
</script> | ||
|
||
<template> | ||
<component | ||
class="absolute" | ||
:is="ShapeComponent" | ||
:size="props.width" | ||
theme="filled" | ||
fill="#4f71be" | ||
:style="{ | ||
left: `${props.x}px`, | ||
top: `${props.y}px`, | ||
width: `${props.width}px`, | ||
height: `${props.height}px`, | ||
rotate: `${props.rotate}deg`, | ||
}" | ||
></component> | ||
</template> |
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,32 @@ | ||
import { Block } from '../Block/Block' | ||
|
||
export type Shape = 'rect' | 'triangle' | 'circle' | 'star' | 'hexagon' | ||
|
||
export class ShapeBlock extends Block { | ||
constructor(shape: string, x: number, y: number) { | ||
super('Shape', x, y, 0, 0) | ||
this.props.set('shape', shape) | ||
} | ||
|
||
get width() { | ||
return this.props.get('width') as number | ||
} | ||
|
||
set width(value: number) { | ||
this.props.set('width', value) | ||
this.props.set('height', value) | ||
} | ||
|
||
get height() { | ||
return this.props.get('height') as number | ||
} | ||
|
||
set height(value: number) { | ||
this.props.set('height', value) | ||
this.props.set('width', value) | ||
} | ||
|
||
get shape() { | ||
return this.props.get('shape') as Shape | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export const TEXT_BOX_DEFAULT_WIDTH = 300 | ||
export const TEXT_BOX_DEFAULT_HEIGHT = 100 | ||
|
||
export const SHAPE_DEFAULT_WIDTH = 200 | ||
export const SHAPE_DEFAULT_HEIGHT = 200 |
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
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,58 @@ | ||
import { Shape, ShapeBlock } from '@BlockHub/ShapeBlock/ShapeBlock' | ||
import { toSlideCoords } from '@Utils/toSlideCoords' | ||
import { selectionManager, slideManager, toolBox } from '@Kernel/index' | ||
import { SHAPE_DEFAULT_HEIGHT, SHAPE_DEFAULT_WIDTH } from '@Const/block' | ||
import { ToolController } from './_ToolController' | ||
import { ToolConfig } from '../ToolBox' | ||
|
||
export class ShapeToolController extends ToolController { | ||
private _dragging = false | ||
private _currentBlock?: ShapeBlock | ||
private _startX = 0 | ||
private _startY = 0 | ||
|
||
handleClick(event: MouseEvent) {} | ||
|
||
handleMouseDown(event: MouseEvent) { | ||
const { x, y } = toSlideCoords(event.currentTarget as HTMLElement, event.clientX, event.clientY) | ||
const shape = (toolBox.currentTool.config as ToolConfig).shape as Shape | ||
this._startX = x | ||
this._startY = y | ||
this._currentBlock = new ShapeBlock(shape, x, y) | ||
slideManager.currentSlide.addBlock(this._currentBlock) | ||
} | ||
|
||
handleMouseMove(event: MouseEvent): void { | ||
const { x, y } = toSlideCoords(event.currentTarget as HTMLElement, event.clientX, event.clientY) | ||
const block = this._currentBlock | ||
if (block) { | ||
this._dragging = true | ||
const left = Math.min(this._startX, x) | ||
const top = Math.min(this._startY, y) | ||
const right = Math.max(this._startX, x) | ||
const bottom = Math.max(this._startY, y) | ||
const width = right - left | ||
const height = bottom - top | ||
const edge = Math.min(width, height) | ||
block.x = left | ||
block.y = top | ||
block.width = edge | ||
block.height = edge | ||
} | ||
} | ||
|
||
handleMouseUp(event: MouseEvent): void { | ||
const block = this._currentBlock | ||
if (!block) { | ||
return | ||
} | ||
if (!this._dragging) { | ||
block.width = SHAPE_DEFAULT_WIDTH | ||
block.height = SHAPE_DEFAULT_HEIGHT | ||
} | ||
this._currentBlock = undefined | ||
this._dragging = false | ||
selectionManager.focus(block) | ||
toolBox.changeTool('Default') | ||
} | ||
} |
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
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
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
12 changes: 3 additions & 9 deletions
12
src/UserInterface/ToolBar/components/Insert/Illustration.vue
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
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,57 @@ | ||
<script setup lang="ts"> | ||
import { toolBox } from '@Kernel/index' | ||
import ToolButton from '../ToolButton.vue' | ||
import { GraphicDesign, Square, Triangle, Round, Star, HexagonOne } from '@icon-park/vue-next' | ||
</script> | ||
<template> | ||
<ToolButton :hasMenu="true"> | ||
<template #icon> | ||
<GraphicDesign theme="two-tone" size="32" :fill="['#333', '#83BEEC']" :strokeWidth="1" /> | ||
</template> | ||
<template #name>{{ $t('ToolBar.insert.illustration.shapes') }}</template> | ||
<template #menu> | ||
<div class="p-[10px] flex flex-wrap items-center gap-[10px] w-[172px]"> | ||
<Square | ||
class="menu-btn cursor-pointer" | ||
theme="filled" | ||
size="36" | ||
fill="#4d4d4d" | ||
:strokeWidth="2" | ||
@click="toolBox.changeTool('Shape', { shape: 'rect' })" | ||
/> | ||
<Triangle | ||
class="menu-btn cursor-pointer" | ||
theme="filled" | ||
size="36" | ||
fill="#4d4d4d" | ||
:strokeWidth="2" | ||
@click="toolBox.changeTool('Shape', { shape: 'triangle' })" | ||
/> | ||
<Round | ||
class="menu-btn cursor-pointer" | ||
theme="filled" | ||
size="36" | ||
fill="#4d4d4d" | ||
:strokeWidth="2" | ||
@click="toolBox.changeTool('Shape', { shape: 'circle' })" | ||
/> | ||
<Star | ||
class="menu-btn cursor-pointer" | ||
theme="filled" | ||
size="36" | ||
fill="#4d4d4d" | ||
:strokeWidth="2" | ||
@click="toolBox.changeTool('Shape', { shape: 'star' })" | ||
/> | ||
<HexagonOne | ||
class="menu-btn cursor-pointer" | ||
theme="filled" | ||
size="36" | ||
fill="#4d4d4d" | ||
:strokeWidth="2" | ||
@click="toolBox.changeTool('Shape', { shape: 'hexagon' })" | ||
/> | ||
</div> | ||
</template> | ||
</ToolButton> | ||
</template> |