Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 0-360 range on the CompassHUD #500

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/components/widgets/CompassHUD.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
hide-details
@change="widget.options.showYawValue = !widget.options.showYawValue"
/>
<v-switch
class="ma-1"
label="Use -180/+180 range"
:color="widget.options.useNegativeRange ? 'rgb(0, 20, 80)' : undefined"
:model-value="widget.options.useNegativeRange"
hide-details
@change="widget.options.useNegativeRange = !widget.options.useNegativeRange"
/>
<v-expansion-panels>
<v-expansion-panel>
<v-expansion-panel-title>Color</v-expansion-panel-title>
Expand Down Expand Up @@ -52,15 +60,19 @@ const colorSwatches = ref([['#FFFFFF'], ['#FF2D2D'], ['#0ADB0ACC']])
// prettier-ignore
const angleRender = (angle: number): string => {
switch (angle) {
case -180: return 'S'
case -135: return 'SW'
case -90: return 'W'
case -45: return 'NW'
case 0: return 'N'
case 45: return 'NE'
case 90: return 'E'
case 135: return 'SE'
case 180: return 'S'
case -180: return 'S'
case -135: return 'SW'
case -90: return 'W'
case -45: return 'NW'
case 225: return 'SW'
case 270: return 'W'
case 315: return 'NW'
case 360: return 'N'
default:
return `${angle}°`
}
Expand Down Expand Up @@ -91,6 +103,7 @@ onBeforeMount(() => {
widget.value.options = {
showYawValue: true,
hudColor: colorSwatches.value[0][0],
useNegativeRange: false,
}
}
})
Expand Down Expand Up @@ -173,15 +186,24 @@ const renderCanvas = (): void => {
if (Number(angle) % 15 === 0) {
ctx.lineWidth = '2'
ctx.lineTo(anglePositionX, halfCanvasHeight * 2 - linesFontSize - stdPad)
ctx.fillText(angleRender(Number(angle)), anglePositionX, halfCanvasHeight * 2 - stdPad)
let finalAngle = Number(angle)
if (!widget.value.options.useNegativeRange) {
finalAngle = finalAngle < 0 ? finalAngle + 360 : finalAngle
}
ctx.fillText(angleRender(Number(finalAngle)), anglePositionX, halfCanvasHeight * 2 - stdPad)
}
ctx.stroke()
}

// Draw reference text
if (widget.value.options.showYawValue) {
ctx.font = `bold ${refFontSize}px Arial`
ctx.fillText(`${yaw.value.toFixed(2)}°`, halfCanvasWidth, refFontSize)

let finalAngle = Number(yaw.value)
if (!widget.value.options.useNegativeRange) {
finalAngle = finalAngle < 0 ? finalAngle + 360 : finalAngle
}
ctx.fillText(`${finalAngle.toFixed(1)}°`, halfCanvasWidth, refFontSize)
}

// Draw reference triangle
Expand Down
Loading