Skip to content

Commit ad6c1e0

Browse files
committed
refactor: getAppWidth/Height
1 parent 88bd8c6 commit ad6c1e0

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

packages/app-frontend/src/features/timeline/TimelineView.vue

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default defineComponent({
109109
* Get pixel position for giver time
110110
*/
111111
function getTimePosition (time: number) {
112-
return (time - nonReactiveState.minTime.value) / (nonReactiveState.endTime.value - nonReactiveState.startTime.value) * app.view.width
112+
return (time - nonReactiveState.minTime.value) / (nonReactiveState.endTime.value - nonReactiveState.startTime.value) * getAppWidth()
113113
}
114114
115115
// Reset
@@ -178,8 +178,8 @@ export default defineComponent({
178178
// Manual painting
179179
if (app.renderer.type === PIXI.RENDERER_TYPE.WEBGL) {
180180
mainRenderTexture = PIXI.RenderTexture.create({
181-
width: app.view.width / window.devicePixelRatio,
182-
height: app.view.height / window.devicePixelRatio,
181+
width: getAppWidth(),
182+
height: getAppHeight(),
183183
resolution: window.devicePixelRatio,
184184
})
185185
mainRenderTexture.framebuffer.multisample = PIXI.MSAA_QUALITY.LOW
@@ -197,6 +197,14 @@ export default defineComponent({
197197
app.destroy()
198198
})
199199
200+
function getAppWidth () {
201+
return app.view.width / window.devicePixelRatio
202+
}
203+
204+
function getAppHeight () {
205+
return app.view.height / window.devicePixelRatio
206+
}
207+
200208
// Manual painting (draw)
201209
202210
let drawScheduled = false
@@ -287,7 +295,7 @@ export default defineComponent({
287295
const x = getTimePosition(marker.time)
288296
marker.x = x
289297
markerContainer.moveTo(x, 0)
290-
markerContainer.lineTo(x, app.view.height)
298+
markerContainer.lineTo(x, getAppHeight())
291299
}
292300
markerContainer.x = horizontalScrollingContainer.x
293301
}
@@ -419,7 +427,7 @@ export default defineComponent({
419427
function drawLayerBackground (layerId: Layer['id'], alpha = 1) {
420428
const { layer } = layersMap[layerId]
421429
layerHoverEffect.beginFill(layer.color, alpha)
422-
layerHoverEffect.drawRect(0, getLayerY(layer), app.view.width, (layer.height + 1) * LAYER_SIZE)
430+
layerHoverEffect.drawRect(0, getLayerY(layer), getAppWidth(), (layer.height + 1) * LAYER_SIZE)
423431
}
424432
425433
watch(hoverLayerId, () => {
@@ -1092,14 +1100,14 @@ export default defineComponent({
10921100
timeCursor.clear()
10931101
timeCursor.lineStyle(1, 0x888888, 0.2)
10941102
timeCursor.moveTo(0.5, 0)
1095-
timeCursor.lineTo(0.5, app.view.height)
1103+
timeCursor.lineTo(0.5, getAppHeight())
10961104
}
10971105
10981106
function updateCursorPosition (event: FederatedPointerEvent) {
10991107
const { globalX } = event
11001108
timeCursor.x = globalX
11011109
timeCursor.visible = true
1102-
cursorTime.value = globalX / app.view.width * (endTime.value - startTime.value) + startTime.value
1110+
cursorTime.value = globalX / getAppWidth() * (endTime.value - startTime.value) + startTime.value
11031111
}
11041112
11051113
function clearCursor () {
@@ -1122,7 +1130,7 @@ export default defineComponent({
11221130
if (!timeGrid.visible || !app.view.width) return
11231131
11241132
const size = endTime.value - startTime.value
1125-
const ratio = size / app.view.width
1133+
const ratio = size / getAppWidth()
11261134
let timeInterval = 10
11271135
let width = timeInterval / ratio
11281136
@@ -1141,9 +1149,9 @@ export default defineComponent({
11411149
11421150
timeGrid.clear()
11431151
timeGrid.lineStyle(1, 0x888888, 0.075)
1144-
for (let x = -offset; x < app.view.width; x += width) {
1152+
for (let x = -offset; x < getAppWidth(); x += width) {
11451153
timeGrid.moveTo(x + 0.5, 0)
1146-
timeGrid.lineTo(x + 0.5, app.view.height)
1154+
timeGrid.lineTo(x + 0.5, getAppHeight())
11471155
}
11481156
}
11491157
@@ -1168,7 +1176,7 @@ export default defineComponent({
11681176
}
11691177
11701178
function updateCamera () {
1171-
horizontalScrollingContainer.x = -(startTime.value - minTime.value) / (endTime.value - startTime.value) * app.view.width
1179+
horizontalScrollingContainer.x = -getTimePosition(nonReactiveState.startTime.value)
11721180
drawLayerBackgroundEffects()
11731181
drawTimeGrid()
11741182
drawMarkers()
@@ -1185,7 +1193,7 @@ export default defineComponent({
11851193
11861194
function onMouseWheel (event: FederatedWheelEvent) {
11871195
const size = endTime.value - startTime.value
1188-
const viewWidth = app.view.width
1196+
const viewWidth = getAppWidth()
11891197
11901198
if (!event.ctrlKey && !event.altKey) {
11911199
const centerRatio = event.globalX / viewWidth
@@ -1295,7 +1303,7 @@ export default defineComponent({
12951303
12961304
// Horizontal
12971305
const size = endTime.value - startTime.value
1298-
const viewWidth = app.view.width
1306+
const viewWidth = getAppWidth()
12991307
const delta = deltaX / viewWidth * size
13001308
let start = startTime.value = startDragTime + delta
13011309
if (start < minTime.value) {
@@ -1333,12 +1341,12 @@ export default defineComponent({
13331341
// @ts-expect-error PIXI type is missing queueResize
13341342
app.queueResize()
13351343
setTimeout(() => {
1336-
mainRenderTexture?.resize(app.view.width / window.devicePixelRatio, app.view.height / window.devicePixelRatio)
1337-
queueEventsUpdate()
1338-
drawLayerBackgroundEffects()
1339-
drawTimeCursor()
1340-
drawTimeGrid()
1341-
draw()
1344+
mainRenderTexture?.resize(getAppWidth(), getAppHeight())
1345+
queueEventsUpdate()
1346+
drawLayerBackgroundEffects()
1347+
drawTimeCursor()
1348+
drawTimeGrid()
1349+
draw()
13421350
}, 100)
13431351
}
13441352

0 commit comments

Comments
 (0)