vanilladocs
vanillapunch.com
API / core/viewmanager

core/viewmanager

뷰 매니저.

View manager.

ViewManagerextends Object

짝Counterpart: vanilla-engine ViewManager

뷰 매니저.

  • clientNativeSize: 웹브라우저 전체 해상도 크기. (0,0 ~ canvasNativeSize.x, )
  • canvasNativeSize: 현재 렌더링되는 캔버스 요소의 해상도 크기. (웹브라우저 기준)
  • canvasPixelSize: 캔버스 요소 내부의 실제 렌더링 픽셀 해상도 크기. (캔버스의 크기 * 장치화면배율)
  • viewNativeRect: 실제 사용되는 뷰 영역. (클라이언트 영역 기준의 부분 영역)
  • viewSize: 실제 사용되는 뷰 크기.

View manager.

  • clientNativeSize: Full web browser resolution size. (0,0 ~ canvasNativeSize.x, )
  • canvasNativeSize: Resolution size of the currently rendered canvas element. (web browser based)
  • canvasPixelSize: Actual rendering pixel resolution size inside the canvas element. (canvas size * device pixel ratio)
  • viewNativeRect: The view area actually used. (sub-area relative to the client area)
  • viewSize: The view size actually used.
예제Example뷰 스케일 모드를 정하고 좌표 바꾸기Set the view scale mode and convert coordinates
import { Engine, EngineConfiguration, Scene, Vector2, ViewScaleMode } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(1280, 720);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
const viewManager = engine.getViewManager();
viewManager.setViewScaleMode(ViewScaleMode.stretchShort);
engine.run(new Scene());
const viewSize = viewManager.getViewSize();
const viewNativeRect = viewManager.getViewNativeRect();
console.log(viewSize.x, viewSize.y, viewNativeRect.size.x, viewNativeRect.size.y);
const viewPosition = viewManager.convertClientToView(100, 100);
console.log(viewPosition.x, viewPosition.y);
생성자constructorconstructor(engine)#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

engineEngine
기준 해상도를 읽을 엔진. (엔진 설정의 referenceResolutionSize)Engine to read the reference resolution from. (referenceResolutionSize of the engine configuration)

짝Counterpart: vanilla-engine ViewManager.new

메서드methodcalculateViewRect()#0.0.8 부터since 0.0.8소스source

뷰 영역 계산.

Calculates the view area.

짝Counterpart: vanilla-engine ViewManager.calculate_view_rect

메서드methodapplyTransform(graphic, scaleX, scaleY, skewX, skewY, translateX, translateY)#0.0.8 부터since 0.0.8소스source

좌표계 적용.

Applies the coordinate system.

graphicGraphic
변환을 걸 그래픽.Graphic to apply the transform to.
scaleXnumber
가로 배율. (a)Horizontal scale. (a)
scaleYnumber
세로 배율. (d)Vertical scale. (d)
skewXnumber
가로 기울임. (c)Horizontal skew. (c)
skewYnumber
세로 기울임. (b)Vertical skew. (b)
translateXnumber
가로 이동. (e, 캔버스 픽셀)Horizontal translation. (e, canvas pixels)
translateYnumber
세로 이동. (f, 캔버스 픽셀)Vertical translation. (f, canvas pixels)

짝Counterpart: vanilla-engine ViewManager.apply_transform

메서드methodapplyCanvasNativeRect(graphic)#0.0.8 부터since 0.0.8소스source

화면 전체 영역 적용.

  • ViewScaleMode.none 이 아닐 경우 출력 전 해당 화면 해상도를 처리하기 위한 초기화.
  • getCanvasNativeSize()

Applies the full screen area.

  • If not ViewScaleMode.none, initialization to handle that screen resolution before output.
  • getCanvasNativeSize()
graphicGraphic
변환을 걸 그래픽.Graphic to apply the transform to.

짝Counterpart: vanilla-engine ViewManager.apply_canvas_native_rect

메서드methodapplyViewRect(graphic)#0.0.8 부터since 0.0.8소스source

뷰 영역 적용.

  • ViewScaleMode.none 이 아닐 경우 출력 전 해당 화면 해상도를 처리하기 위한 초기화.
  • ViewScaleMode.none은 getCanvasNativeSize()를 사용하고 그 외의 모드에서는 getReferenceResolutionSize()를 사용한다.
  • getViewSize()를 사용하면 모드를 구분하지 않아도 자동으로 항상 모드에 적합한 뷰포트 해상도를 얻을 수 있다.

Applies the view area.

  • If not ViewScaleMode.none, initialization to handle that screen resolution before output.
  • ViewScaleMode.none uses getCanvasNativeSize(), and the other modes use getReferenceResolutionSize().
  • With getViewSize(), you always get the viewport resolution suited to the mode automatically, without distinguishing modes.
graphicGraphic
변환을 걸 그래픽.Graphic to apply the transform to.

짝Counterpart: vanilla-engine ViewManager.apply_view_rect

메서드methodapplyReferenceResolutionSize(referenceResolutionSize)#0.0.11 부터since 0.0.11소스source

기준 해상도 크기 재설정.

Resets the reference resolution size.

referenceResolutionSizeVector2
새 기준 해상도.New reference resolution.

짝Counterpart: vanilla-engine ViewManager.apply_reference_resolution_size

메서드methodsetCanvas(canvas)#0.0.8 부터since 0.0.8소스source

캔버스 설정.

Sets the canvas.

canvasHTMLCanvasElement
엔진이 그리는 캔버스.The canvas the engine draws to.
메서드methodgetCanvas()#0.0.8 부터since 0.0.8소스source

캔버스 반환.

Returns the canvas.

반환ReturnsHTMLCanvasElement 엔진이 그리는 캔버스.The canvas the engine draws to.

메서드methodgetDevicePixelRatio()#0.0.8 부터since 0.0.8소스source

디바이스의 실제 픽셀 개수 비율을 반환.

Returns the device's actual pixel ratio.

반환Returnsnumber 렌더에 쓰는 장치 화면 배율. (상한을 걸었으면 그 값까지)Device pixel ratio used for rendering. (up to the cap if one is set)

짝Counterpart: vanilla-engine ViewManager.get_device_pixel_ratio

메서드methodsetViewScaleMode(viewScaleMode)#0.0.8 부터since 0.0.8소스source

뷰 스케일 모드 설정.

Sets the view scale mode.

viewScaleModeViewScaleMode
ViewScaleMode 의 값. (같으면 아무것도 하지 않고, 바뀌면 뷰 영역을 다시 셈한다)A ViewScaleMode value. (does nothing if unchanged; recomputes the view area if changed)

짝Counterpart: vanilla-engine ViewManager.set_view_scale_mode

메서드methodgetViewScaleMode()#0.0.8 부터since 0.0.8소스source

뷰 스케일 모드 반환.

Returns the view scale mode.

반환ReturnsViewScaleMode ViewScaleMode 의 값.A ViewScaleMode value.

짝Counterpart: vanilla-engine ViewManager.get_view_scale_mode

메서드methodgetClientNativeSize()#0.0.8 부터since 0.0.8소스source

웹페이지의 전체 크기 반환.

Returns the full size of the web page.

반환ReturnsVector2 창의 안쪽 크기. (CSS 픽셀, innerWidth, innerHeight)Inner size of the window. (CSS pixels, innerWidth, innerHeight)

짝Counterpart: vanilla-engine ViewManager.get_client_native_size

메서드methodgetCanvasNativeSize()#0.0.8 부터since 0.0.8소스source

캔버스의 요소 크기 반환.

Returns the canvas element size.

반환ReturnsVector2 캔버스 요소의 크기. (CSS 픽셀, 반올림)Size of the canvas element. (CSS pixels, rounded)

짝Counterpart: vanilla-engine ViewManager.get_canvas_native_size

메서드methodgetCanvasPixelSize()#0.0.8 부터since 0.0.8소스source

캔버스의 픽셀 렌더링용 화면 크기 반환. (실제 캔버스 내부 해상도. 엔진, 컨텐츠 로직에서는 사용할 필요 없음)

Returns the screen size for canvas pixel rendering. (The actual internal canvas resolution. Not needed in engine or content logic)

반환ReturnsVector2 캔버스의 렌더 픽셀 크기. (CSS 크기 x 장치 화면 배율)Render pixel size of the canvas. (CSS size x device pixel ratio)

짝Counterpart: vanilla-engine ViewManager.get_canvas_pixel_size

메서드methodgetReferenceResolutionSize()#0.0.8 부터since 0.0.8소스source

기준 해상도 크기 반환.

Returns the reference resolution size.

반환ReturnsVector2 기준 해상도.Reference resolution.

짝Counterpart: vanilla-engine ViewManager.get_reference_resolution_size

메서드methodgetViewSize()#0.0.11 부터since 0.0.11소스source

실제 사용 해상도 크기 반환.

Returns the resolution size actually in use.

반환ReturnsVector2 뷰 크기. (뷰 좌표, 뷰 스케일 모드에 따라 정해진다)View size. (view coordinates, decided by the view scale mode)

짝Counterpart: vanilla-engine ViewManager.get_view_size

메서드methodgetCssPixelScale()#0.4.0 부터since 0.4.0소스source

뷰 한 단위가 화면에서 몇 CSS 픽셀인지 반환. (캔버스의 CSS 높이 / 뷰 높이, 못 재면 1)

  • 뷰의 고정된 쪽은 늘 같은 길이라, 작은 화면(포털의 PC iframe 등)에서는 한 단위가 1 CSS 픽셀보다 한참 작아져 글자가 읽히지 않는다. UI 층만 키울 배율을 셈할 때 쓴다. (예: 최소 CSS 배율 / 이 값)

Returns how many CSS pixels one view unit is on screen. (canvas CSS height / view height, 1 if it cannot be measured)

  • The fixed side of the view is always the same length, so on small screens (a portal's PC iframe, etc.) one unit becomes much smaller than 1 CSS pixel and text becomes unreadable. Used to calculate a scale that enlarges only the UI layer. (e.g. minimum CSS scale / this value)

반환Returnsnumber 뷰 한 단위의 CSS 픽셀 수. (못 재면 1)CSS pixels per view unit. (1 if it cannot be measured)

짝Counterpart: vanilla-engine ViewManager.get_css_pixel_scale

메서드methodgetViewNativeRect()#0.0.11 부터since 0.0.11소스source

캔버스 안에서 뷰가 존재하는 실제 영역 반환. (값은 canvasNativeSize 기준)

Returns the actual area within the canvas where the view exists. (values relative to canvasNativeSize)

반환ReturnsRect 캔버스 안의 뷰 영역. (CSS 픽셀, 캔버스 왼쪽 위가 원점)View area inside the canvas. (CSS pixels, origin at the canvas top-left)

짝Counterpart: vanilla-engine ViewManager.get_view_native_rect

메서드methodgetTargetResolutionScale()#0.0.8 부터since 0.0.8소스source

배율 반환.

Returns the scale.

반환Returnsnumber 기준 해상도에서 캔버스로 늘인 배율. (none, referenceResolution 은 1)Scale from the reference resolution to the canvas. (1 for none and referenceResolution)

짝Counterpart: vanilla-engine ViewManager.get_target_resolution_scale

메서드methodcanvasPositionToViewPosition(canvasPosition)#0.0.9 부터since 0.0.9소스source

캔버스 좌표를 뷰 좌표로 변환.

Converts canvas coordinates to view coordinates.

canvasPositionVector2
캔버스 좌표. (캔버스 왼쪽 위가 원점, CSS 픽셀)Canvas coordinates. (origin at the canvas top-left, CSS pixels)

반환ReturnsVector2 뷰 좌표. (반올림한 정수, 배율이 0 이면 (0, 0))View coordinates. (rounded integers, (0, 0) if the scale is 0)

짝Counterpart: vanilla-engine ViewManager.canvas_position_to_view_position

메서드methodconvertClientToView(clientX, clientY)#0.4.0 부터since 0.4.0소스source

화면(client) 좌표를 뷰 좌표로. (DOM 사건의 clientX, clientY 를 캔버스의 지금 자리로 빼서 canvasPositionToViewPosition 으로 바꾼다)

Screen (client) coordinates to view coordinates. (Subtracts the canvas's current position from a DOM event's clientX, clientY and converts with canvasPositionToViewPosition)

clientXnumber
클라이언트 X 좌표. (CSS 픽셀, clientX)Client X coordinate. (CSS pixels, clientX)
clientYnumber
클라이언트 Y 좌표. (CSS 픽셀, clientY)Client Y coordinate. (CSS pixels, clientY)

반환ReturnsVector2 뷰 좌표. (반올림한 정수, 배율이 0 이면 (0, 0))View coordinates. (rounded integers, (0, 0) if the scale is 0)

짝Counterpart: vanilla-engine ViewManager.convert_client_to_view

메서드methodsetMaxRenderPixelRatio(maxRenderPixelRatio)#0.3.0 부터since 0.3.0소스source

렌더 배율 상한 설정.

  • 고DPI 기기에서 캔버스가 과대해지는 것을 막는다. 0 이면 제한하지 않는다.
  • 캔버스 크기는 다음 프레임 머리에서 엔진이 창 크기 바뀜과 같은 길(Engine.resize)로 맞춘다. (씬도 화면 영역이 바뀐 것을 받는다) 프레임 가운데(tick, draw)에서 캔버스 크기를 바꾸면 그리기 버퍼가 비워지는데 그 프레임은 앞서 맞춘 뷰포트로 그려 한 프레임이 까맸다.

Set the render pixel ratio cap.

  • Keeps the canvas from growing too large on high-DPI devices. 0 means no cap.
  • The engine applies the canvas size at the start of the next frame through the same path as a window resize (Engine.resize). (scenes also receive the screen area change) Resizing the canvas in the middle of a frame (tick, draw) clears the drawing buffer while that frame still draws with the earlier viewport, which made one frame black.
maxRenderPixelRationumber
렌더 배율 상한. (0 이면 제한하지 않고, 음수는 0)Render pixel ratio cap. (0 means no limit, negative becomes 0)

짝Counterpart: vanilla-engine ViewManager.set_max_render_pixel_ratio

메서드methodisViewRectPending()#0.4.0 부터since 0.4.0소스source

다음 프레임 머리에 뷰 영역을 다시 셈할지 반환. (렌더 배율 상한을 바꾼 뒤 아직 맞추지 않았으면 true)

Return whether the view area is recalculated at the start of the next frame. (true after the render pixel ratio cap changed and before it is applied)

반환Returnsboolean 다시 셈할 것이 남았으면 참. (calculateViewRect 가 맞추면 거짓)True when a recalculation is still pending. (false once calculateViewRect applies it)

짝Counterpart: vanilla-engine ViewManager.is_view_rect_pending

예제Example렌더 배율 상한을 바꾼 뒤 맞출 것이 남았는지 보기Check whether applying a changed render pixel ratio cap is still pending
import { Engine, EngineConfiguration } from "./build/vanilla.js";

const engine = new Engine(new EngineConfiguration());
const viewManager = engine.getViewManager();
viewManager.setMaxRenderPixelRatio(1);
console.log(viewManager.isViewRectPending());
메서드methodgetMaxRenderPixelRatio()#0.3.0 부터since 0.3.0소스source

렌더 배율 상한 반환.

Returns the render scale upper limit.

반환Returnsnumber 렌더 배율 상한. (0 이면 제한 없음)Render pixel ratio cap. (0 means no limit)

짝Counterpart: vanilla-engine ViewManager.get_max_render_pixel_ratio

메서드methodlimitRenderPixelRatio(devicePixelRatio)#0.4.0 부터since 0.4.0소스source

상한을 건 배율.

  • 상한이 0 보다 크고 장치 배율이 상한을 넘으면 상한을, 아니면 장치 배율을 그대로 돌려준다. (calculateViewRect 가 쓰는 셈)

The ratio with the cap applied.

  • Returns the cap if the cap is greater than 0 and the device ratio exceeds it, otherwise returns the device ratio as is. (the calculation calculateViewRect uses)
devicePixelRationumber
장치 화면 배율. (window.devicePixelRatio 꼴)Device pixel ratio. (in the form of window.devicePixelRatio)

반환Returnsnumber 상한을 건 배율.The ratio with the cap applied.

짝Counterpart: vanilla-engine ViewManager.limit_render_pixel_ratio

예제Example상한 2 를 걸면 배율 3 은 2 로With a cap of 2, a ratio of 3 becomes 2
import { Engine, EngineConfiguration } from "./build/vanilla.js";

const engine = new Engine(new EngineConfiguration());
const viewManager = engine.getViewManager();
viewManager.setMaxRenderPixelRatio(2);
console.log(viewManager.limitRenderPixelRatio(3), viewManager.limitRenderPixelRatio(1.5));
메서드methodapplyAspectViewScaleMode()#0.3.0 부터since 0.3.0소스source

종횡비에 맞는 뷰 스케일 모드 자동 선택.

  • 화면이 기준 해상도보다 세로로 길면 가로를 고정하고 세로를 늘리고, 가로로 길면 세로를 고정하고 가로를 늘린다. (여러 게임이 복붙하던 로직)

Automatically selects the view scale mode matching the aspect ratio.

  • If the screen is taller than the reference resolution, fixes the width and extends the height, and if it is wider, fixes the height and extends the width. (Logic several games kept copy-pasting)

짝Counterpart: vanilla-engine ViewManager.apply_aspect_view_scale_mode

메서드methodsetSafeAreaOverride(insets)#0.3.0 부터since 0.3.0소스source

세이프에어리어 강제값 설정. (CSS px, 데스크톱에서 노치를 흉내 낼 때)

Sets a forced safe area value. (CSS px, for emulating a notch on desktop)

insetsobject | null
{ top, right, bottom, left }

짝Counterpart: vanilla-engine ViewManager.set_safe_area_override

메서드methodgetSafeAreaInsets()#0.3.0 부터since 0.3.0소스source

세이프에어리어 인셋 반환. (뷰 좌표)

  • env(safe-area-inset-*) 를 숨은 요소의 padding 으로 실측해 뷰 좌표로 환산한다.
  • 우선순위: setSafeAreaOverride() > URL ?safeArea=top,right,bottom,left > env() 실측.

Returns the safe area insets. (view coordinates)

  • Measures env(safe-area-inset-*) through the padding of a hidden element and converts it to view coordinates.
  • Priority: setSafeAreaOverride() > URL ?safeArea=top,right,bottom,left > env() measurement.

반환Returnsobject { top, right, bottom, left }

짝Counterpart: vanilla-engine ViewManager.get_safe_area_insets

예제Example세이프에어리어를 흉내 내고 뷰 좌표로 읽기Simulate a safe area and read it in view coordinates
import { Engine, EngineConfiguration, Vector2, ViewScaleMode } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(1280, 720);
const engine = new Engine(engineConfiguration);
const viewManager = engine.getViewManager();
viewManager.setViewScaleMode(ViewScaleMode.stretchShortExpandLong);
viewManager.setSafeAreaOverride({ top: 44, right: 0, bottom: 34, left: 0 });
viewManager.setIgnoredSafeAreaSides(["bottom"]);
const insets = viewManager.getSafeAreaInsets();
console.log(insets.top, insets.right, insets.bottom, insets.left);
메서드methodsetIgnoredSafeAreaSides(sides)#0.4.0 부터since 0.4.0소스source

무시할 세이프에어리어 쪽 설정. (getSafeAreaInsets 가 그 쪽을 0 으로 돌려준다, 빈 목록이면 모두 쓴다)

  • 플랫폼의 앱이 그 쪽을 이미 비켜 그리는 웹뷰처럼, 어느 쪽을 무시할지는 게임이 정해 넘긴다.

Sets the safe area sides to ignore. (getSafeAreaInsets returns 0 for those sides, an empty list uses all)

  • The game decides which sides to ignore and passes them in, as with a webview whose platform app already draws clear of that side.
sidesstring[]
"top", "right", "bottom", "left" 가운데.One of "top", "right", "bottom", "left".

짝Counterpart: vanilla-engine ViewManager.set_ignored_safe_area_sides

메서드methodgetIgnoredSafeAreaSides()#0.4.0 부터since 0.4.0소스source

무시할 세이프에어리어 쪽 반환.

Returns the safe area sides to ignore.

반환Returnsstring[] 무시할 쪽 목록. ("top", "right", "bottom", "left" 가운데)List of sides to ignore. (among "top", "right", "bottom", "left")

짝Counterpart: vanilla-engine ViewManager.get_ignored_safe_area_sides

ViewScaleModeenum

짝Counterpart: vanilla-engine ViewScaleMode

뷰 스케일 모드.

View scale mode.

이름Name값Value설명Description
nonenone사용안함 (웹브라우저 크기가 변경되면 뷰 영역도 변경됨)Not used (the view area changes when the web browser size changes)
referenceResolutionreferenceResolution기준해상도로 뷰 영역 정의 (양쪽 축이 잘리거나 남을 수 있음)Defines the view area by the reference resolution (both axes may be cropped or have leftover space)
stretchWidthstretchWidth기준해상도로 뷰 영역 정의 + 뷰의 비율을 유지한채 가로축으로 늘여붙임. (반대 축은 잘리거나 남을 수 있음)Defines the view area by the reference resolution + stretches to fit along the horizontal axis while keeping the view's aspect ratio. (The opposite axis may be cropped or have leftover space)
stretchHeightstretchHeight기준해상도로 뷰 영역 정의 + 뷰의 비율을 유지한채 세로축으로 늘여붙임. (반대 축은 잘리거나 남을 수 있음)Defines the view area by the reference resolution + stretches to fit along the vertical axis while keeping the view's aspect ratio. (The opposite axis may be cropped or have leftover space)
stretchShortstretchShort기준해상도로 뷰 영역 정의 + 뷰의 비율을 유지한채 가로세로 중에서 짧은 축으로 늘여붙임. (반대 축은 남을 수 있음)Defines the view area by the reference resolution + stretches to fit along the shorter of the two axes while keeping the view's aspect ratio. (The opposite axis may have leftover space)
stretchWidthExpandHeightstretchWidthExpandHeight가로를 화면 전체에 늘여붙임 (기준해상도 가로 = 항상 고정). 세로는 화면 비율에 따라 자동 산출. 양쪽 여백 없음. (대신 세로 해상도는 디스플레이에 따라 바뀜)Stretches the width across the whole screen (reference resolution width = always fixed). The height is computed automatically from the screen ratio. No margins on either side. (Instead, the vertical resolution varies by display)
stretchHeightExpandWidthstretchHeightExpandWidth세로를 화면 전체에 늘여붙임 (기준해상도 세로 = 항상 고정). 가로는 화면 비율에 따라 자동 산출. 양쪽 여백 없음. (대신 가로 해상도는 디스플레이에 따라 바뀜)Stretches the height across the whole screen (reference resolution height = always fixed). The width is computed automatically from the screen ratio. No margins on either side. (Instead, the horizontal resolution varies by display)
stretchShortExpandLongstretchShortExpandLong짧은 축 기준 스케일. 긴 축도 화면 전체에 늘여붙임. 양쪽 여백 없음. (대신 긴 축 해상도는 디스플레이에 따라 바뀜)Scale based on the short axis. The long axis is also stretched across the whole screen. No margins on either side. (Instead, the long axis resolution varies by display)