Skip to content

Commit 70eeba1

Browse files
committed
[Editor] Improve indices rendering
1 parent 03c00fe commit 70eeba1

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/editor/render/indices.ts

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,21 @@ export const indicesRenderer = ( indicesCanvas: Ref<HTMLCanvasElement | null> )
7777

7878
const draw = ( fixation: EditorFixation, idx: number, col: string ) => {
7979
// Drop shadow
80-
if ( dropShadowSize.value > 0 && dropShadowPasses.value > 0 ) {
81-
// TODO: Start at smaller scale
82-
const movePerIterOutside = dropShadowSize.value / dropShadowPasses.value;
83-
const movePerIterInside = dropShadowInnerSize.value / dropShadowPasses.value;
84-
const opacityPerStep = ( dropShadowOpacityStart.value - dropShadowOpacityEnd.value ) / dropShadowPasses.value;
85-
const fontScaleUpPerIterOutside = 2 * movePerIterOutside;
86-
const fontScaleUpPerIterInside = 2 * movePerIterInside;
87-
const numberToShow = ( idx + 1 ).toString();
88-
89-
let totalOffset = 0;
90-
91-
for ( let j = 0; j < numberToShow.length; j++ ) {
92-
const toDisplay = numberToShow[ j ]!;
93-
const width = ctx!.measureText( toDisplay ).width;
94-
95-
// Outer shadow
80+
const movePerIterOutside = dropShadowSize.value / dropShadowPasses.value;
81+
const movePerIterInside = dropShadowInnerSize.value / dropShadowPasses.value;
82+
const opacityPerStep = ( dropShadowOpacityStart.value - dropShadowOpacityEnd.value ) / dropShadowPasses.value;
83+
const fontScaleUpPerIterOutside = 2 * movePerIterOutside;
84+
const fontScaleUpPerIterInside = 2 * movePerIterInside;
85+
const numberToShow = ( idx + 1 ).toString();
86+
87+
let totalOffset = 0;
88+
89+
for ( let j = 0; j < numberToShow.length; j++ ) {
90+
const toDisplay = numberToShow[ j ]!;
91+
const width = ctx!.measureText( toDisplay ).width;
92+
93+
// Outer shadow
94+
if ( dropShadowSize.value > 0 && dropShadowPasses.value > 0 )
9695
for ( let i = 0; i < dropShadowPasses.value; i++ ) {
9796
const fontSize = scale( indicesFontSize.value + ( fontScaleUpPerIterOutside * i ) );
9897

@@ -107,9 +106,11 @@ export const indicesRenderer = ( indicesCanvas: Ref<HTMLCanvasElement | null> )
107106
);
108107
}
109108

110-
// Inner shadow
109+
// Inner shadow
110+
if ( dropShadowInnerSize.value !== 0 )
111111
for ( let i = 0; i < dropShadowPasses.value; i++ ) {
112-
const fontSize = scale( indicesFontSize.value - ( 2 * dropShadowInnerSize.value ) + ( fontScaleUpPerIterInside * i ) );
112+
const fontSize = scale( indicesFontSize.value
113+
- ( 2 * dropShadowInnerSize.value ) + ( fontScaleUpPerIterInside * i ) );
113114

114115
ctx!.font = fontSize + 'px ' + indicesFontFamily.value;
115116
ctx!.fillStyle = `rgba( 0, 0, 0, ${ dropShadowOpacityEnd.value - ( opacityPerStep * i ) } )`;
@@ -122,27 +123,17 @@ export const indicesRenderer = ( indicesCanvas: Ref<HTMLCanvasElement | null> )
122123
);
123124
}
124125

125-
// Draw the actual number
126-
ctx!.font = 'bold ' + scale( indicesFontSize.value ) + 'px ' + indicesFontFamily.value;
127-
ctx!.fillStyle = col;
128-
129-
ctx!.fillText(
130-
toDisplay,
131-
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ) + totalOffset,
132-
scale( originalToCanvasCoordinates( fixation.y! - fixationRadius.value, 'y' ) )
133-
);
134-
135-
totalOffset += width;
136-
}
137-
} else {
126+
// Draw the actual number
138127
ctx!.font = 'bold ' + scale( indicesFontSize.value ) + 'px ' + indicesFontFamily.value;
139128
ctx!.fillStyle = col;
140129

141130
ctx!.fillText(
142-
( idx + 1 ).toString(),
143-
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ),
131+
toDisplay,
132+
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ) + totalOffset,
144133
scale( originalToCanvasCoordinates( fixation.y! - fixationRadius.value, 'y' ) )
145134
);
135+
136+
totalOffset += width;
146137
}
147138
};
148139

0 commit comments

Comments
 (0)