Skip to content

Commit

Permalink
ソング:useCursorStateのcursorClassを使用するように変更 (#2274)
Browse files Browse the repository at this point in the history
useCursorStateのcursorClassを使うように変更
  • Loading branch information
sigprogramming authored Sep 29, 2024
1 parent 90c6023 commit 09958a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
64 changes: 28 additions & 36 deletions src/components/Sing/ScoreSequencer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import {
onMounted,
onActivated,
onDeactivated,
watch,
} from "vue";
import ContextMenu, {
ContextMenuItemData,
Expand Down Expand Up @@ -366,39 +367,7 @@ const sequencerBody = ref<HTMLElement | null>(null);
const cursorX = ref(0);
const cursorY = ref(0);
const { cursorState, setCursorState, resetCursorState } = useCursorState();
// カーソルCSSクラス
const cursorClass = computed(() => {
if (editTarget.value === "PITCH") {
if (ctrlKey.value) {
// ピッチ削除
return "cursor-erase";
} else {
// ピッチ描画
return "cursor-draw";
}
}
// 範囲選択
if (editTarget.value === "NOTE" && shiftKey.value) {
return "cursor-crosshair";
}
if (cursorState.value === CursorState.EW_RESIZE) {
return "cursor-ew-resize";
}
if (cursorState.value === CursorState.CROSSHAIR) {
return "cursor-crosshair";
}
if (cursorState.value === CursorState.MOVE) {
return "cursor-move";
}
if (cursorState.value === CursorState.DRAW) {
return "cursor-draw";
}
if (cursorState.value === CursorState.ERASE) {
return "cursor-erase";
}
return "";
});
const { cursorClass, setCursorState } = useCursorState();
// 歌詞入力
const { previewLyrics, commitPreviewLyrics, splitAndUpdatePreview } =
Expand Down Expand Up @@ -452,6 +421,31 @@ const editingLyricNote = computed(() => {
const showGuideLine = ref(true);
const guideLineX = ref(0);
// プレビュー中でないときの処理
// TODO: ステートパターンにして、この処理をIdleStateに移す
watch([ctrlKey, shiftKey, nowPreviewing, editTarget], () => {
if (nowPreviewing.value) {
return;
}
if (editTarget.value === "PITCH") {
if (ctrlKey.value) {
// ピッチ消去
setCursorState(CursorState.ERASE);
} else {
// ピッチ描画
setCursorState(CursorState.DRAW);
}
}
if (editTarget.value === "NOTE") {
if (shiftKey.value) {
// 範囲選択
setCursorState(CursorState.CROSSHAIR);
} else {
setCursorState(CursorState.UNSET);
}
}
});
const previewAdd = () => {
const cursorBaseX = (scrollX.value + cursorX.value) / zoomX.value;
const cursorTicks = baseXToTick(cursorBaseX, tpqn.value);
Expand Down Expand Up @@ -960,7 +954,6 @@ const endPreview = () => {
throw new ExhaustiveError(previewStartEditTarget);
}
previewMode.value = "IDLE";
resetCursorState();
};
const onNoteBarMouseDown = (event: MouseEvent, note: Note) => {
Expand Down Expand Up @@ -1070,7 +1063,6 @@ const onMouseUp = (event: MouseEvent) => {
}
if (isRectSelecting.value) {
rectSelect(isOnCommandOrCtrlKeyDown(event));
resetCursorState();
} else if (nowPreviewing.value) {
endPreview();
}
Expand Down Expand Up @@ -1648,7 +1640,7 @@ const contextMenuData = computed<ContextMenuItemData[]>(() => {
// TODO: ピッチ削除など消しゴム用のカーソル・画像がないためdefault
// カーソルが必要であれば画像を追加する
.cursor-erase {
cursor: pointer;
cursor: default;
}
.zoom-x-slider {
Expand Down
5 changes: 0 additions & 5 deletions src/composables/useCursorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ export const useCursorState = () => {
cursorState.value = state;
};

const resetCursorState = () => {
cursorState.value = CursorState.UNSET;
};

return {
cursorState,
cursorClass,
setCursorState,
resetCursorState,
};
};

0 comments on commit 09958a6

Please sign in to comment.