|
51 | 51 | </v-item> |
52 | 52 | </v-item-group> |
53 | 53 | </v-row> |
54 | | - <v-row no-gutters align="center"> |
55 | | - <v-slider |
56 | | - v-if="mode === PaintMode.CirclePaint || mode === PaintMode.Erase" |
57 | | - :model-value="brushSize" |
58 | | - @update:model-value="setBrushSize" |
59 | | - density="compact" |
60 | | - hide-details |
61 | | - label="Size" |
62 | | - min="1" |
63 | | - max="50" |
64 | | - > |
65 | | - <template v-slot:append> |
66 | | - <v-text-field |
67 | | - :model-value="brushSize" |
68 | | - @input="setBrushSize" |
69 | | - variant="plain" |
70 | | - class="mt-n3 pt-0 pl-2" |
71 | | - style="width: 60px" |
72 | | - density="compact" |
73 | | - hide-details |
74 | | - type="number" |
75 | | - min="1" |
76 | | - max="50" |
77 | | - /> |
78 | | - </template> |
79 | | - </v-slider> |
80 | | - |
81 | | - <FillBetweenControls v-if="mode === PaintMode.FillBetween" /> |
82 | | - </v-row> |
| 54 | + <template v-if="mode === PaintMode.CirclePaint || mode === PaintMode.Erase"> |
| 55 | + <v-row no-gutters>Size (pixels)</v-row> |
| 56 | + <v-row no-gutters align="center"> |
| 57 | + <v-slider |
| 58 | + :model-value="brushSize" |
| 59 | + @update:model-value="setBrushSize" |
| 60 | + density="compact" |
| 61 | + hide-details |
| 62 | + min="1" |
| 63 | + max="50" |
| 64 | + > |
| 65 | + <template v-slot:append> |
| 66 | + <v-text-field |
| 67 | + :model-value="brushSize" |
| 68 | + @input="setBrushSize" |
| 69 | + variant="underlined" |
| 70 | + class="mt-n3 pt-0 pl-2 opacity-70" |
| 71 | + style="width: 60px" |
| 72 | + density="compact" |
| 73 | + hide-details |
| 74 | + type="number" |
| 75 | + min="1" |
| 76 | + max="50" |
| 77 | + /> |
| 78 | + </template> |
| 79 | + </v-slider> |
| 80 | + </v-row> |
| 81 | + <v-row no-gutters class="mb-1">Threshold </v-row> |
| 82 | + <v-row v-if="currentImageStats" no-gutters align="center"> |
| 83 | + <v-range-slider |
| 84 | + v-model="threshold" |
| 85 | + :min="currentImageStats.scalarMin" |
| 86 | + :max="currentImageStats.scalarMax" |
| 87 | + :step="thresholdStepGranularity" |
| 88 | + > |
| 89 | + <template #prepend> |
| 90 | + <v-text-field |
| 91 | + :model-value="thresholdRange[0].toFixed(2)" |
| 92 | + @input="setMinThreshold($event.target.value)" |
| 93 | + variant="underlined" |
| 94 | + class="mt-n3 pt-0 pl-2 opacity-70" |
| 95 | + style="width: 80px" |
| 96 | + density="compact" |
| 97 | + hide-details |
| 98 | + type="number" |
| 99 | + precision="2" |
| 100 | + :min="currentImageStats.scalarMin" |
| 101 | + :max="thresholdRange[1]" |
| 102 | + /> |
| 103 | + </template> |
| 104 | + <template #append> |
| 105 | + <v-text-field |
| 106 | + :model-value="thresholdRange[1].toFixed(2)" |
| 107 | + @input="setMaxThreshold($event.target.value)" |
| 108 | + variant="underlined" |
| 109 | + class="mt-n3 pt-0 pl-2 opacity-70" |
| 110 | + style="width: 80px" |
| 111 | + density="compact" |
| 112 | + hide-details |
| 113 | + type="number" |
| 114 | + precision="2" |
| 115 | + :min="thresholdRange[0]" |
| 116 | + :max="currentImageStats.scalarMax" |
| 117 | + /> |
| 118 | + </template> |
| 119 | + </v-range-slider> |
| 120 | + </v-row> |
| 121 | + </template> |
| 122 | + <template v-if="mode === PaintMode.FillBetween"> |
| 123 | + <v-row no-gutters align="center"> |
| 124 | + <FillBetweenControls /> |
| 125 | + </v-row> |
| 126 | + </template> |
83 | 127 | </v-container> |
84 | 128 | </template> |
85 | 129 |
|
86 | | -<script lang="ts"> |
87 | | -import { defineComponent, computed } from 'vue'; |
| 130 | +<script setup lang="ts"> |
| 131 | +import { computed } from 'vue'; |
88 | 132 | import { storeToRefs } from 'pinia'; |
89 | 133 | import { PaintMode } from '@/src/core/tools/paint'; |
90 | | -import { usePaintToolStore } from '../store/tools/paint'; |
91 | | -import FillBetweenControls from './FillBetweenControls.vue'; |
| 134 | +import { usePaintToolStore } from '@/src/store/tools/paint'; |
| 135 | +import FillBetweenControls from '@/src/components/FillBetweenControls.vue'; |
| 136 | +import { useCurrentImage } from '@/src/composables/useCurrentImage'; |
| 137 | +import { useImageStatsStore } from '@/src/store/image-stats'; |
92 | 138 |
|
93 | | -export default defineComponent({ |
94 | | - name: 'PaintControls', |
| 139 | +const paintStore = usePaintToolStore(); |
| 140 | +const imageStatsStore = useImageStatsStore(); |
| 141 | +const { brushSize, activeMode, thresholdRange } = storeToRefs(paintStore); |
| 142 | +const { currentImageID } = useCurrentImage(); |
95 | 143 |
|
96 | | - components: { |
97 | | - FillBetweenControls, |
| 144 | +const currentImageStats = computed(() => { |
| 145 | + if (!currentImageID.value) return null; |
| 146 | + return imageStatsStore.stats[currentImageID.value] ?? null; |
| 147 | +}); |
| 148 | +const thresholdStepGranularity = computed(() => { |
| 149 | + if (!currentImageStats.value) return 1; |
| 150 | + const { scalarMin, scalarMax } = currentImageStats.value; |
| 151 | + return Math.min(1, (scalarMax - scalarMin) / 256); |
| 152 | +}); |
| 153 | +const threshold = computed({ |
| 154 | + get: () => thresholdRange.value, |
| 155 | + set: (range) => { |
| 156 | + paintStore.setThresholdRange(range); |
98 | 157 | }, |
| 158 | +}); |
99 | 159 |
|
100 | | - setup() { |
101 | | - const paintStore = usePaintToolStore(); |
102 | | - const { brushSize, activeMode } = storeToRefs(paintStore); |
| 160 | +const setMinThreshold = (n: string) => { |
| 161 | + threshold.value = [+n, threshold.value[1]]; |
| 162 | +}; |
103 | 163 |
|
104 | | - const setBrushSize = (size: number) => { |
105 | | - paintStore.setBrushSize(Number(size)); |
106 | | - }; |
| 164 | +const setMaxThreshold = (n: string) => { |
| 165 | + threshold.value = [threshold.value[0], +n]; |
| 166 | +}; |
107 | 167 |
|
108 | | - const mode = computed({ |
109 | | - get: () => activeMode.value, |
110 | | - set: (m) => { |
111 | | - paintStore.setMode(m); |
112 | | - }, |
113 | | - }); |
| 168 | +const setBrushSize = (size: number) => { |
| 169 | + paintStore.setBrushSize(Number(size)); |
| 170 | +}; |
114 | 171 |
|
115 | | - return { |
116 | | - brushSize, |
117 | | - setBrushSize, |
118 | | - mode, |
119 | | - PaintMode, |
120 | | - }; |
| 172 | +const mode = computed({ |
| 173 | + get: () => activeMode.value, |
| 174 | + set: (m) => { |
| 175 | + paintStore.setMode(m); |
121 | 176 | }, |
122 | 177 | }); |
123 | 178 | </script> |
|
0 commit comments