Spaces:
Runtime error
Runtime error
UI mask drag buttons
Browse files
frontend/src/lib/Buttons/MaskButton.svelte
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
<button
|
7 |
on:click
|
8 |
class="bg-white rounded-full p-2 {isActive ? 'text-blue-700' : 'text-gray-800'}"
|
9 |
-
title="Enable
|
10 |
>
|
11 |
<Mask />
|
12 |
</button>
|
|
|
6 |
<button
|
7 |
on:click
|
8 |
class="bg-white rounded-full p-2 {isActive ? 'text-blue-700' : 'text-gray-800'}"
|
9 |
+
title="Enable Masking"
|
10 |
>
|
11 |
<Mask />
|
12 |
</button>
|
frontend/src/lib/Frame.svelte
CHANGED
@@ -18,30 +18,23 @@
|
|
18 |
</script>
|
19 |
|
20 |
<div
|
21 |
-
class="frame
|
22 |
-
{!interactive ? 'pointer-events-none touch-none' : ''}
|
23 |
-
{isDragging ? 'cursor-grabbing' : 'cursor-grab'}"
|
24 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); border-color: ${color};`}
|
25 |
>
|
26 |
-
{
|
27 |
-
|
28 |
-
<
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
<div class="absolute top-full">
|
41 |
-
<slot name="bottom" />
|
42 |
-
</div>
|
43 |
-
<div class="absolute left-full bottom-0">
|
44 |
-
<slot name="right" />
|
45 |
</div>
|
46 |
</div>
|
47 |
|
@@ -50,8 +43,4 @@
|
|
50 |
@apply absolute top-0 left-0 grid grid-cols-3 grid-rows-3 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
|
51 |
transform-origin: 0 0;
|
52 |
}
|
53 |
-
.small-frame {
|
54 |
-
@apply pointer-events-none touch-none absolute top-1/2 left-1/2 border-2 border-spacing-3 w-[256px] h-[256px];
|
55 |
-
transform: translateX(-50%) translateY(-50%);
|
56 |
-
}
|
57 |
</style>
|
|
|
18 |
</script>
|
19 |
|
20 |
<div
|
21 |
+
class="frame {isDragging ? 'cursor-grabbing' : 'cursor-grab'}"
|
|
|
|
|
22 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); border-color: ${color};`}
|
23 |
>
|
24 |
+
<div class={!interactive ? 'pointer-events-none touch-none' : ''}>
|
25 |
+
{#if loadingState}
|
26 |
+
<div class="col-span-2 row-start-1">
|
27 |
+
<span class="text-white drop-shadow-lg">{loadingState}</span>
|
28 |
+
</div>
|
29 |
+
{/if}
|
30 |
+
{#if isLoading}
|
31 |
+
<div class="col-start-2 row-start-2">
|
32 |
+
<LoadingIcon />
|
33 |
+
</div>
|
34 |
+
{/if}
|
35 |
|
36 |
+
<h2 class="text-lg">Click to paint</h2>
|
37 |
+
<div class="absolute bottom-0 font-bold text-lg">{prompt}</div>
|
|
|
|
|
|
|
|
|
|
|
38 |
</div>
|
39 |
</div>
|
40 |
|
|
|
43 |
@apply absolute top-0 left-0 grid grid-cols-3 grid-rows-3 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
|
44 |
transform-origin: 0 0;
|
45 |
}
|
|
|
|
|
|
|
|
|
46 |
</style>
|
frontend/src/lib/PaintFrame.svelte
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
import PPButton from '$lib/Buttons/PPButton.svelte';
|
4 |
import DragButton from '$lib/Buttons/DragButton.svelte';
|
5 |
import MaskButton from '$lib/Buttons/MaskButton.svelte';
|
|
|
6 |
|
7 |
import { drag } from 'd3-drag';
|
8 |
import { select } from 'd3-selection';
|
@@ -27,10 +28,16 @@
|
|
27 |
};
|
28 |
|
29 |
let frameElement: HTMLDivElement;
|
|
|
30 |
let isDragging = false;
|
31 |
$: prompt = $myPresence?.currentPrompt;
|
32 |
$: isLoading = $myPresence?.isLoading || false;
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
let offsetX = 0;
|
35 |
let offsetY = 0;
|
36 |
onMount(() => {
|
@@ -93,36 +100,59 @@
|
|
93 |
.on('pointermove', handlePointerMove)
|
94 |
.on('pointerleave', handlePointerLeave);
|
95 |
});
|
|
|
|
|
|
|
|
|
96 |
</script>
|
97 |
|
98 |
-
<div
|
99 |
-
<
|
100 |
-
|
101 |
-
{
|
102 |
-
loadingState={$loadingState}
|
103 |
-
{prompt}
|
104 |
-
{transform}
|
105 |
-
{isLoading}
|
106 |
-
{isDragging}
|
107 |
-
{interactive}
|
108 |
>
|
109 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
{#if !isDragging}
|
111 |
-
<div class="
|
112 |
-
<
|
|
|
|
|
113 |
</div>
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
<DragButton />
|
120 |
-
<MaskButton />
|
121 |
</div>
|
122 |
{/if}
|
123 |
</div>
|
124 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
</div>
|
126 |
|
127 |
<style lang="postcss" scoped>
|
|
|
|
|
|
|
128 |
</style>
|
|
|
3 |
import PPButton from '$lib/Buttons/PPButton.svelte';
|
4 |
import DragButton from '$lib/Buttons/DragButton.svelte';
|
5 |
import MaskButton from '$lib/Buttons/MaskButton.svelte';
|
6 |
+
import LoadingIcon from '$lib/Icons/LoadingIcon.svelte';
|
7 |
|
8 |
import { drag } from 'd3-drag';
|
9 |
import { select } from 'd3-selection';
|
|
|
28 |
};
|
29 |
|
30 |
let frameElement: HTMLDivElement;
|
31 |
+
let dragEnabled = true;
|
32 |
let isDragging = false;
|
33 |
$: prompt = $myPresence?.currentPrompt;
|
34 |
$: isLoading = $myPresence?.isLoading || false;
|
35 |
|
36 |
+
$: coord = {
|
37 |
+
x: transform.applyX(position.x),
|
38 |
+
y: transform.applyY(position.y)
|
39 |
+
};
|
40 |
+
|
41 |
let offsetX = 0;
|
42 |
let offsetY = 0;
|
43 |
onMount(() => {
|
|
|
100 |
.on('pointermove', handlePointerMove)
|
101 |
.on('pointerleave', handlePointerLeave);
|
102 |
});
|
103 |
+
|
104 |
+
function DragMask() {
|
105 |
+
dragEnabled = !dragEnabled;
|
106 |
+
}
|
107 |
</script>
|
108 |
|
109 |
+
<div>
|
110 |
+
<div
|
111 |
+
class="absolute top-0 left-0"
|
112 |
+
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); border-color: ${color}; transform-origin: 0 0;`}
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
>
|
114 |
+
<div class="frame">
|
115 |
+
<div class="pointer-events-none touch-none">
|
116 |
+
{#if $loadingState}
|
117 |
+
<div class="col-span-2 row-start-1">
|
118 |
+
<span class="text-white drop-shadow-lg">{$loadingState}</span>
|
119 |
+
</div>
|
120 |
+
{/if}
|
121 |
+
{#if isLoading}
|
122 |
+
<div class="col-start-2 row-start-2">
|
123 |
+
<LoadingIcon />
|
124 |
+
</div>
|
125 |
+
{/if}
|
126 |
+
|
127 |
+
<h2 class="text-lg">Click to paint</h2>
|
128 |
+
<div class="absolute bottom-0 font-bold text-lg">{prompt}</div>
|
129 |
+
</div>
|
130 |
{#if !isDragging}
|
131 |
+
<div class="absolute top-full">
|
132 |
+
<div class="py-2">
|
133 |
+
<PPButton on:click={() => dispatch('paintMode', { mode: 'paint' })} />
|
134 |
+
</div>
|
135 |
</div>
|
136 |
+
<div class="absolute left-full bottom-0">
|
137 |
+
<div class="px-2 flex flex-col gap-2">
|
138 |
+
<DragButton isActive={dragEnabled} on:click={() => (dragEnabled = true)} />
|
139 |
+
<MaskButton isActive={!dragEnabled} on:click={() => (dragEnabled = false)} />
|
140 |
+
</div>
|
|
|
|
|
141 |
</div>
|
142 |
{/if}
|
143 |
</div>
|
144 |
+
</div>
|
145 |
+
<div
|
146 |
+
bind:this={frameElement}
|
147 |
+
class="absolute top-0 left-0 w-[512px] h-[512px] border-2 border-black
|
148 |
+
{isDragging ? 'cursor-grabbing' : 'cursor-grab'}
|
149 |
+
{dragEnabled ? 'block' : 'hidden'}"
|
150 |
+
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); border-color: ${color}; transform-origin: 0 0;`}
|
151 |
+
/>
|
152 |
</div>
|
153 |
|
154 |
<style lang="postcss" scoped>
|
155 |
+
.frame {
|
156 |
+
@apply relative grid grid-cols-3 grid-rows-3 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
|
157 |
+
}
|
158 |
</style>
|