Skip to content

Commit 1c3c9a3

Browse files
committed
fix(paint): update threshold on image switch
1 parent b57987a commit 1c3c9a3

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/store/tools/paint.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Manifest, StateFile } from '@/src/io/state-file/schema';
44
import type { Maybe } from '@/src/types';
55
import { useImageStatsStore } from '@/src/store/image-stats';
66
import { computed, ref } from 'vue';
7+
import { watchImmediate } from '@vueuse/core';
78
import { vec3 } from 'gl-matrix';
89
import { defineStore } from 'pinia';
910
import { PaintMode } from '@/src/core/tools/paint';
@@ -212,6 +213,26 @@ export const usePaintToolStore = defineStore('paint', () => {
212213
doPaintStroke.call(this, axisIndex);
213214
}
214215

216+
const currentImageStats = computed(() => {
217+
if (!currentImageID.value) return null;
218+
return imageStatsStore.stats[currentImageID.value];
219+
});
220+
221+
function resetThresholdRange(imageID: Maybe<string>) {
222+
if (imageID) {
223+
const stats = imageStatsStore.stats[imageID];
224+
if (stats) {
225+
thresholdRange.value = [stats.scalarMin, stats.scalarMax];
226+
} else {
227+
thresholdRange.value = [...DEFAULT_THRESHOLD_RANGE];
228+
}
229+
}
230+
}
231+
232+
watchImmediate([currentImageID, currentImageStats], ([id]) => {
233+
resetThresholdRange(id);
234+
});
235+
215236
// --- setup and teardown --- //
216237

217238
function activateTool(this: _This) {
@@ -222,13 +243,6 @@ export const usePaintToolStore = defineStore('paint', () => {
222243
ensureActiveSegmentGroupForImage(imageID);
223244
this.$paint.setBrushSize(this.brushSize);
224245

225-
const stats = imageStatsStore.stats[imageID];
226-
if (stats) {
227-
thresholdRange.value = [stats.scalarMin, stats.scalarMax];
228-
} else {
229-
thresholdRange.value = [...DEFAULT_THRESHOLD_RANGE];
230-
}
231-
232246
isActive.value = true;
233247
return true;
234248
}

0 commit comments

Comments
 (0)