-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
11 changed files
with
169 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup lang="ts"> | ||
import { drauuMode, drauu, drauuBrush, brushColors, drauuEnabled, canUndo, canRedo } from '../logic/drauu' | ||
import VerticalDivider from './VerticalDivider.vue' | ||
function clear() { | ||
if (confirm('Clear the drawing?')) | ||
drauu.clear() | ||
} | ||
function undo() { | ||
drauu.undo() | ||
} | ||
function redo() { | ||
drauu.redo() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="m-auto rounded-md bg-main shadow dark:(border border-gray-400 border-opacity-10)"> | ||
<div class="flex text-xl p-2 gap-1"> | ||
<button | ||
v-for="color of brushColors" | ||
:key="color" | ||
class="icon-btn" | ||
:class="drauuBrush.color === color ? 'active' : 'shallow'" | ||
@click="drauuBrush.color = color" | ||
> | ||
<div | ||
class="w-5 h-5 transition-all border border-gray-400/50" | ||
:class="drauuBrush.color !== color ? 'rounded-full' : 'rounded'" | ||
:style="{ background: color }" | ||
/> | ||
</button> | ||
|
||
<VerticalDivider /> | ||
|
||
<button class="icon-btn" :class="{ shallow: drauuMode != 'draw' }" @click="drauuMode = 'draw'"> | ||
<carbon:draw /> | ||
</button> | ||
<button class="icon-btn" :class="{ shallow: drauuMode != 'line' }" @click="drauuMode = 'line'"> | ||
<carbon:scalpel /> | ||
</button> | ||
<button class="icon-btn" :class="{ shallow: drauuMode != 'ellipse' }" @click="drauuMode = 'ellipse'"> | ||
<carbon:radio-button /> | ||
</button> | ||
<button class="icon-btn" :class="{ shallow: drauuMode != 'rectangle' }" @click="drauuMode = 'rectangle'"> | ||
<carbon:checkbox /> | ||
</button> | ||
|
||
<VerticalDivider /> | ||
|
||
<button class="icon-btn" @click="clear()"> | ||
<carbon:clean /> | ||
</button> | ||
<button class="icon-btn" :class="{ disabled: !canUndo }" @click="undo()"> | ||
<carbon:undo /> | ||
</button> | ||
<button class="icon-btn" :class="{ disabled: !canRedo }" @click="redo()"> | ||
<carbon:redo /> | ||
</button> | ||
|
||
<template v-if="drauuEnabled"> | ||
<VerticalDivider /> | ||
<button class="icon-btn" @click="drauuEnabled = false"> | ||
<carbon:close /> | ||
</button> | ||
</template> | ||
</div> | ||
</div> | ||
</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 |
---|---|---|
@@ -1,27 +1,25 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, ref, watch, inject } from 'vue' | ||
import { createDrauu } from 'drauu' | ||
import { drauuBrush, drauuMode } from '../state/drauu' | ||
import { onMounted, ref, watch, inject, onBeforeUnmount } from 'vue' | ||
import { drauuEnabled, drauu } from '../logic/drauu' | ||
import { injectionSlideScale } from '../constants' | ||
defineProps<{ enabled?: boolean }>() | ||
const scale = inject(injectionSlideScale)! | ||
const svg = ref<SVGSVGElement>() | ||
onMounted(() => { | ||
const drauu = createDrauu({ | ||
el: svg.value, | ||
brush: drauuBrush, | ||
mode: drauuMode.value, | ||
corrdinateScale: 1 / scale.value, | ||
}) | ||
drauu.mount(svg.value!) | ||
watch(scale, scale => drauu.options.corrdinateScale = 1 / scale, { immediate: true }) | ||
}) | ||
watch(drauuMode, mode => drauu.mode = mode) | ||
watch(scale, scale => drauu.options.corrdinateScale = 1 / scale) | ||
onBeforeUnmount(() => { | ||
drauu.unmount() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<svg ref="svg" :class="{ 'pointer-events-none': !enabled }"></svg> | ||
<svg | ||
ref="svg" | ||
class="w-full h-full absolute top-0" | ||
:class="{ 'pointer-events-none': !drauuEnabled }" | ||
></svg> | ||
</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
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,3 @@ | ||
<template> | ||
<div class="w-1px m-2 opacity-10 bg-current" /> | ||
</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,30 @@ | ||
import { markRaw, reactive, ref, watch } from 'vue' | ||
import { Brush, createDrauu, DrawingMode } from 'drauu' | ||
|
||
export const brushColors = [ | ||
'#ff595e', | ||
'#ffca3a', | ||
'#8ac926', | ||
'#1982c4', | ||
'#6a4c93', | ||
'#ffffff', | ||
'#000000', | ||
] | ||
|
||
export const drauuBrush = reactive<Brush>({ color: brushColors[0], size: 4 }) | ||
export const drauuMode = ref<DrawingMode>('draw') | ||
export const drauuEnabled = ref(false) | ||
export const canUndo = ref(false) | ||
export const canRedo = ref(false) | ||
|
||
export const drauu = markRaw(createDrauu({ | ||
brush: drauuBrush, | ||
mode: drauuMode.value, | ||
})) | ||
|
||
drauu.on('changed', () => { | ||
canRedo.value = drauu.canRedo() | ||
canUndo.value = drauu.canUndo() | ||
}) | ||
|
||
watch(drauuMode, mode => drauu.mode = mode) |
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 was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.