Skip to content

Commit

Permalink
Added a gesture calibration tool to help ignore small movements of th…
Browse files Browse the repository at this point in the history
…e fingers
  • Loading branch information
Aioros committed Aug 19, 2024
1 parent e1e13ec commit f1c957c
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 73 deletions.
59 changes: 59 additions & 0 deletions src/config/GestureCalibrationMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {MODULE_NAME, MODULE_DISPLAY_NAME} from './ModuleConstants.js'
import CanvasTouchPointerEventsManager from '../logic/CanvasTouchPointerEventsManager.js'
import {getSetting, ZOOM_THRESHOLD_SETTING, PAN_THRESHOLD_SETTING} from './TouchSettings.js'

export class GestureCalibrationMenu extends FormApplication {
constructor() {
super()
this.canvasTouchPointerEventsManager = null
}

static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ['form'],
popOut: true,
template: `/modules/${MODULE_NAME}/templates/gesture-calibration.hbs`,
id: `${MODULE_NAME}-gesture-calibration-form`,
title: `${MODULE_DISPLAY_NAME} - Gesture Calibration`,
resizable: true,
width: 800,
height: 600,
})
}

getData() {
return {
zoomThresholdSetting: getSetting(ZOOM_THRESHOLD_SETTING),
panThresholdSetting: getSetting(PAN_THRESHOLD_SETTING)
}
}

async _updateObject(event, formData) {
const data = expandObject(formData)
for (let setting in data) {
game.settings.set(MODULE_NAME, setting, data[setting])
}
}

async close(...args) {
super.close(...args)
this.canvasTouchPointerEventsManager = null
game.settings.sheet.maximize()
}

activateListeners(html) {
super.activateListeners(html)
Object.values(ui.windows).forEach(app => app.minimize())
this.canvasTouchPointerEventsManager = CanvasTouchPointerEventsManager.init($("#touch-vtt-calibration").get(0))

const zoomThresholdInput = html.find(`input[name="zoomThreshold"]`)
zoomThresholdInput.change(() => {
this.canvasTouchPointerEventsManager.setForcedZoomThreshold(zoomThresholdInput.val())
})

const panThresholdInput = html.find(`input[name="panThreshold"]`)
panThresholdInput.change(() => {
this.canvasTouchPointerEventsManager.setForcedPanThreshold(panThresholdInput.val())
})
}
}
54 changes: 36 additions & 18 deletions src/config/TouchSettings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MODULE_NAME, MODULE_DISPLAY_NAME} from './ModuleConstants.js'
import {updateButtonSize} from '../tools/EnlargeButtonsTool'
import {toggleUtilityControls} from '../tools/UtilityControls.js'
import {GestureCalibrationMenu} from './GestureCalibrationMenu.js'

export const CORE_FUNCTIONALITY = "core"

Expand All @@ -27,7 +28,8 @@ export const MEASUREMENT_HUD_OFF = "off"
export const MEASUREMENT_HUD_RIGHT = "right"
export const MEASUREMENT_HUD_LEFT = "left"

export const ZOOM_SENSITIVITY_SETTING = "zoomSensitivity"
export const ZOOM_THRESHOLD_SETTING = "zoomThreshold"
export const PAN_THRESHOLD_SETTING = "panThreshold"

export const DEBUG_MODE_SETTING = "debugMode"

Expand All @@ -48,9 +50,8 @@ export function getSetting(settingName) {
}

class SettingsOverrideMenu extends FormApplication {
constructor(exampleOption) {
constructor() {
super()
this.exampleOption = exampleOption
}

static get defaultOptions() {
Expand All @@ -64,20 +65,14 @@ class SettingsOverrideMenu extends FormApplication {
}

getData() {
var touchVttOverrideSettings = [...game.settings.settings].filter(s => s[0].startsWith(MODULE_NAME) && s[0].endsWith("_override"))
var data = {
const touchVttOverrideSettings = [...game.settings.settings].filter(s => s[0].startsWith(MODULE_NAME) && s[0].endsWith("_override"))
const data = {
settings: Object.fromEntries(
[...touchVttOverrideSettings]
.map(s => {
s[0] = s[0].split(".")[1]
var settingValue = game.settings.get(MODULE_NAME, s[0])
s[1].currentValue = settingValue
for (let choice in s[1].choices) {
if (typeof s[1].choices[choice] == "string") {
s[1].choices[choice] = {label: s[1].choices[choice]}
}
s[1].choices[choice].selected = (choice == settingValue)
}
return s
})
),
Expand Down Expand Up @@ -216,7 +211,7 @@ export function registerTouchSettings() {
// Client settings

game.settings.register(MODULE_NAME, CORE_FUNCTIONALITY, {
name: "Core Functionality",
name: "Core Functionality" + (game.settings.get(MODULE_NAME, CORE_FUNCTIONALITY + "_override") == "override_off" ? "" : " *"),
hint: "Caution: disabling this option will remove all TouchVTT functionality, and other options will be ignored",
scope: "client",
config: true,
Expand All @@ -239,18 +234,32 @@ export function registerTouchSettings() {
default: GESTURE_MODE_COMBINED,
})

game.settings.register(MODULE_NAME, ZOOM_SENSITIVITY_SETTING, {
game.settings.register(MODULE_NAME, ZOOM_THRESHOLD_SETTING, {
name: "Zoom Sensitivity",
hint: "Sensitivity of the zoom gesture (if enabled)",
scope: "client",
config: true,
config: false,
type: Number,
range: {
min: 0,
max: 2,
step: 0.1
max: 100,
step: 1
},
default: 1,
default: 100,
})

game.settings.register(MODULE_NAME, PAN_THRESHOLD_SETTING, {
name: "Pan Sensitivity",
hint: "Sensitivity of the pan gesture (if enabled)",
scope: "client",
config: false,
type: Number,
range: {
min: 0,
max: 100,
step: 1
},
default: 100,
})

game.settings.register(MODULE_NAME, DIRECTIONAL_ARROWS_SETTING, {
Expand Down Expand Up @@ -325,7 +334,6 @@ export function registerTouchSettings() {
})

// Override menu

game.settings.registerMenu(MODULE_NAME, "SettingsOverrideMenu", {
name: "Client Settings Overrides",
label: "Configure Overrides",
Expand All @@ -335,6 +343,16 @@ export function registerTouchSettings() {
restricted: true
})

// Testing new calibration menu
game.settings.registerMenu(MODULE_NAME, "GestureCalibrationMenu", {
name: "Touch Gesture Calibration",
label: "Calibrate Touch Gestures",
hint: "Gesture detection can be influenced by your display size and resolution. Use this tool to calibrate if you have issues with sensitivity.",
icon: "fas fa-wrench",
type: GestureCalibrationMenu,
restricted: true
})

// Hook to disable overridden settings
Hooks.on("renderSettingsConfig", (settingsConfig, settingsElem, settingsInfo) => {
var touchVttSettings = settingsInfo.categories.find(c => c.id == MODULE_NAME).settings
Expand Down
1 change: 1 addition & 0 deletions src/logic/AppTouchPointerEventsManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TouchPointerEventsManager from './TouchPointerEventsManager.js'
import {dispatchModifiedEvent} from "./FakeTouchEvent.js"

class AppTouchPointerEventsManager extends TouchPointerEventsManager {
constructor(selector) {
Expand Down
Loading

0 comments on commit f1c957c

Please sign in to comment.