]> git.r.bdr.sh - rbdr/canvas/blame - src/lib/components/sensor.svelte
Update project, improve sensor/render logic
[rbdr/canvas] / src / lib / components / sensor.svelte
CommitLineData
2df937df 1<script>
e4e4b520 2 import { browser } from '$app/environment';
2df937df 3 import { maxSize } from '$lib/config';
e4e4b520 4 import { modulo } from '$lib/math';
d7cea969 5 import { canvas } from '$lib/stores/canvas';
c30e6881 6 import { sensor } from '$lib/stores/widgets';
2df937df 7
2df937df
RBR
8 const kSensorSize = 2;
9
10 let left;
11 let right;
12 let top;
13 let bottom;
14
15 let timer;
16 const fetchItems = function fetchItems( left, top, right, bottom ) {
17 clearTimeout(timer);
18 timer = setTimeout(() => {
c30e6881 19 sensor.set({ left, top, right, bottom });
2df937df
RBR
20 }, 50);
21 }
22
23 $: {
24 if (browser) {
e4e4b520
RBR
25 left = modulo($canvas.x - window.screen.width * kSensorSize, maxSize);
26 top = modulo($canvas.y - window.screen.height * kSensorSize, maxSize);
27 right = left + 2 * window.screen.width * kSensorSize;
28 bottom = top + 2 * window.screen.height * kSensorSize;
2df937df
RBR
29
30 fetchItems(left, top, right, bottom);
31 }
32 }
33
34</script>