Skip to content

Commit 03c00fe

Browse files
committed
[Editor] Drop shadow inside
1 parent 2b41927 commit 03c00fe

File tree

2 files changed

+61
-19
lines changed

2 files changed

+61
-19
lines changed

src/editor/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const machineAssignedFixationColor = ref( rs.getPropertyValue( '--theme-i
4848
// Drop shadow for fixations. In pixels
4949
export const dropShadowSize = ref( 2 ); // Zero disables it
5050

51+
export const dropShadowInnerSize = ref( 1 );
52+
5153
export const dropShadowPasses = ref( 20 );
5254

5355
export const dropShadowOpacityStart = ref( 1 );

src/editor/render/indices.ts

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from 'vue';
66
import {
77
assignedFixationColor,
8+
dropShadowInnerSize,
89
dropShadowOpacityEnd,
910
dropShadowOpacityStart,
1011
dropShadowPasses,
@@ -77,33 +78,72 @@ export const indicesRenderer = ( indicesCanvas: Ref<HTMLCanvasElement | null> )
7778
const draw = ( fixation: EditorFixation, idx: number, col: string ) => {
7879
// Drop shadow
7980
if ( dropShadowSize.value > 0 && dropShadowPasses.value > 0 ) {
80-
const movePerIter = dropShadowSize.value / dropShadowPasses.value;
81+
// TODO: Start at smaller scale
82+
const movePerIterOutside = dropShadowSize.value / dropShadowPasses.value;
83+
const movePerIterInside = dropShadowInnerSize.value / dropShadowPasses.value;
8184
const opacityPerStep = ( dropShadowOpacityStart.value - dropShadowOpacityEnd.value ) / dropShadowPasses.value;
82-
const fontScaleUpPerIter = 2 * movePerIter;
85+
const fontScaleUpPerIterOutside = 2 * movePerIterOutside;
86+
const fontScaleUpPerIterInside = 2 * movePerIterInside;
87+
const numberToShow = ( idx + 1 ).toString();
8388

84-
for ( let i = 0; i < dropShadowPasses.value; i++ ) {
85-
const fontSize = scale( indicesFontSize.value + ( fontScaleUpPerIter * i ) );
89+
let totalOffset = 0;
8690

87-
ctx!.font = fontSize + 'px ' + indicesFontFamily.value;
88-
ctx!.fillStyle = `rgba( 0, 0, 0, ${ dropShadowOpacityStart.value + ( opacityPerStep * i ) } )`;
89-
const aspect = ctx!.measureText( ( idx + 1 ).toString() ).width / fontSize;
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
96+
for ( let i = 0; i < dropShadowPasses.value; i++ ) {
97+
const fontSize = scale( indicesFontSize.value + ( fontScaleUpPerIterOutside * i ) );
98+
99+
ctx!.font = fontSize + 'px ' + indicesFontFamily.value;
100+
ctx!.fillStyle = `rgba( 0, 0, 0, ${ dropShadowOpacityStart.value + ( opacityPerStep * i ) } )`;
101+
const aspect = ctx!.measureText( toDisplay ).width / fontSize;
102+
103+
ctx!.fillText(
104+
toDisplay,
105+
scale( originalToCanvasCoordinates( ( fixation.x! + fixationRadius.value ) - ( movePerIterOutside * i * aspect ), 'x' ) ) + totalOffset,
106+
scale( originalToCanvasCoordinates( ( fixation.y! - fixationRadius.value ) + ( movePerIterOutside * i ), 'y' ) )
107+
);
108+
}
109+
110+
// Inner shadow
111+
for ( let i = 0; i < dropShadowPasses.value; i++ ) {
112+
const fontSize = scale( indicesFontSize.value - ( 2 * dropShadowInnerSize.value ) + ( fontScaleUpPerIterInside * i ) );
113+
114+
ctx!.font = fontSize + 'px ' + indicesFontFamily.value;
115+
ctx!.fillStyle = `rgba( 0, 0, 0, ${ dropShadowOpacityEnd.value - ( opacityPerStep * i ) } )`;
116+
const aspect = ctx!.measureText( toDisplay ).width / fontSize;
117+
118+
ctx!.fillText(
119+
toDisplay,
120+
scale( originalToCanvasCoordinates( ( fixation.x! + fixationRadius.value ) - ( movePerIterInside * i * aspect ), 'x' ) ) + totalOffset,
121+
scale( originalToCanvasCoordinates( ( fixation.y! - fixationRadius.value ) + ( movePerIterInside * i ), 'y' ) )
122+
);
123+
}
124+
125+
// Draw the actual number
126+
ctx!.font = 'bold ' + scale( indicesFontSize.value ) + 'px ' + indicesFontFamily.value;
127+
ctx!.fillStyle = col;
90128

91129
ctx!.fillText(
92-
( idx + 1 ).toString(),
93-
scale( originalToCanvasCoordinates( ( fixation.x! + fixationRadius.value ) - ( movePerIter * i * aspect ), 'x' ) ),
94-
scale( originalToCanvasCoordinates( ( fixation.y! - fixationRadius.value ) + ( movePerIter * i ), 'y' ) )
130+
toDisplay,
131+
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ) + totalOffset,
132+
scale( originalToCanvasCoordinates( fixation.y! - fixationRadius.value, 'y' ) )
95133
);
134+
135+
totalOffset += width;
96136
}
137+
} else {
138+
ctx!.font = 'bold ' + scale( indicesFontSize.value ) + 'px ' + indicesFontFamily.value;
139+
ctx!.fillStyle = col;
140+
141+
ctx!.fillText(
142+
( idx + 1 ).toString(),
143+
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ),
144+
scale( originalToCanvasCoordinates( fixation.y! - fixationRadius.value, 'y' ) )
145+
);
97146
}
98-
99-
ctx!.font = 'bold ' + scale( indicesFontSize.value ) + 'px ' + indicesFontFamily.value;
100-
ctx!.fillStyle = col;
101-
102-
ctx!.fillText(
103-
( idx + 1 ).toString(),
104-
scale( originalToCanvasCoordinates( fixation.x! + fixationRadius.value, 'x' ) ),
105-
scale( originalToCanvasCoordinates( fixation.y! - fixationRadius.value, 'y' ) )
106-
);
107147
};
108148

109149
watch( [

0 commit comments

Comments
 (0)