core/pointercursor
마우스 커서.
Mouse cursor.
PointerCursorextends Singleton
마우스 커서.
- 켜면(setEnabled(true)) 엔진이 프레임 끝마다 캔버스의 커서를 정한다. 꺼져 있으면(기본) 아무것도 하지 않아 지금까지와 같다.
- UIButton 위에 마우스가 있으면 단추의 커서(처음은 손가락 pointer), 아니면 화면이 setScreenCursor 로 정한 커서다.
- 값은 CSS cursor 의 이름이거나 registerImageCursor 로 더한 그림 커서의 이름이다. 바뀔 때만 캔버스에 쓴다.
- default 는 기본 커서(처음은 브라우저의 기본 화살표)이고, 모르는 이름은 캔버스의 커서 값을 비워 브라우저의 기본 화살표가 보이게 한다.
- 그림 커서는 1 배와 2 배 그림을 같이 주고(-webkit-image-set), 그것을 못 읽는 브라우저는 1 배 그림, 그림을 못 받으면 함께 준 CSS 커서다.
- 손가락 기기(pointer: coarse)에서는 캔버스를 건드리지 않는다.
Mouse cursor.
- When on (setEnabled(true)), the engine sets the canvas cursor at the end of every frame. When off (default), it does nothing, same as before.
- If the mouse is over a UIButton, the button's cursor (initially the pointing-finger pointer), otherwise the cursor the screen set with setScreenCursor.
- The value is a CSS cursor name or the name of an image cursor added with registerImageCursor. Written to the canvas only when it changes.
- default is the default cursor (initially the browser's default arrow), and an unknown name clears the canvas's cursor value so the browser's default arrow shows.
- Image cursors give 1x and 2x images together (-webkit-image-set), browsers that cannot read that get the 1x image, and if the image cannot be loaded, the CSS cursor given with it.
- On finger devices (pointer: coarse), the canvas is not touched.
import { Engine, EngineConfiguration, Scene, PointerCursor } from "./build/vanilla.js";
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const pointerCursor = PointerCursor.getInstance();
pointerCursor.registerImageCursor("hand", "assets/icons/icon.png", "", 4, 4, "pointer");
pointerCursor.setCursorNames("hand", "default");
pointerCursor.setScreenCursor("crosshair");
pointerCursor.setEnabled(true);
engine.run(new Scene());
const cursorValue = pointerCursor.readCursorValue("crosshair");
console.log(cursorValue);주된 손이 손가락인지 반환.
Returns whether the primary pointer is a finger.
반환Returnsboolean 주된 손이 손가락이면 참.True if the primary pointer is a finger.
짝Counterpart: vanilla-engine PointerCursor.is_coarse_pointer
엔진의 캔버스 읽기. (엔진은 전역 접근자로 얻어 순환 참조를 만들지 않는다, 없으면 null)
Reads the engine's canvas. (Obtained through the engine's global accessor to avoid circular references, null if none)
반환ReturnsHTMLCanvasElement | null 엔진의 캔버스. (엔진이 없으면 null)The engine's canvas. (null if there is no engine)
켜기 설정. (끄면 캔버스의 커서를 비운다)
Sets enabled. (Turning it off clears the canvas's cursor)
- isEnabledboolean
- 참이면 켠다.Enables it if true.
짝Counterpart: vanilla-engine PointerCursor.set_enabled
켜져 있는지 반환.
Returns whether enabled.
반환Returnsboolean 켜져 있으면 참.True if enabled.
짝Counterpart: vanilla-engine PointerCursor.is_enabled
마우스가 단추 위에 있다고 알리기. (올려 둔 단추가 매 프레임 부른다)
Notifies that the mouse is over a button. (The hovered button calls it every frame)
짝Counterpart: vanilla-engine PointerCursor.mark_over_button
화면의 커서 설정. (단추 위가 아닐 때 보일 커서)
Sets the screen cursor. (The cursor shown when not over a button)
- cursorNamestring
- CSS cursor 이름이나 더한 그림 커서의 이름.A CSS cursor name or the name of an added image cursor.
짝Counterpart: vanilla-engine PointerCursor.set_screen_cursor
화면의 커서 반환.
Returns the screen cursor.
반환Returnsstring 화면의 커서 이름.The screen cursor name.
짝Counterpart: vanilla-engine PointerCursor.get_screen_cursor
단추 위와 기본의 커서 설정. (CSS cursor 의 이름이나 더한 그림 커서의 이름)
Sets the button-hover and default cursors. (A CSS cursor name or the name of an added image cursor)
- buttonCursorNamestring
- 단추 위의 커서.Cursor over a button.
- defaultCursorNamestring
- 화면의 커서가 default 일 때의 커서.Cursor used when the screen cursor is default.
짝Counterpart: vanilla-engine PointerCursor.set_cursor_names
단추 위의 커서 반환.
Returns the button-hover cursor.
반환Returnsstring 단추 위의 커서 이름.The cursor name over buttons.
짝Counterpart: vanilla-engine PointerCursor.get_button_cursor_name
기본의 커서 반환.
Returns the default cursor.
반환Returnsstring 화면의 커서가 default 일 때의 커서 이름.The cursor name used when the screen cursor is default.
짝Counterpart: vanilla-engine PointerCursor.get_default_cursor_name
그림 커서 더하기. (1 배와 2 배 그림, 1 배 그림 기준의 핫스팟, 그림을 못 쓸 때의 CSS 커서)
- 마우스가 있는 기기면 처음 올렸을 때 깜빡이지 않게 그림을 미리 받는다.
Adds an image cursor. (1x and 2x images, hotspot relative to the 1x image, CSS cursor for when the image cannot be used)
- On devices with a mouse, preloads the images so it does not flicker on the first hover.
- namestring
- 커서 이름.Cursor name.
- urlstring
- 1 배 그림의 주소.URL of the 1x image.
- url2xstring
- 2 배 그림의 주소. (없으면 "")URL of the 2x image. ("" if none)
- hotspotXnumber
- 1 배 그림의 핫스팟. (픽셀)Hotspot of the 1x image. (pixels)
- hotspotYnumber
- 핫스팟의 Y. (픽셀, 1 배 그림 기준, 반올림)Hotspot Y. (pixels, based on the 1x image, rounded)
- fallbackCursorNamestring
- 그림을 못 쓸 때의 CSS cursor 이름.CSS cursor name used when the image cannot be used.
짝Counterpart: vanilla-engine PointerCursor.register_image_cursor
커서 이름을 캔버스에 쓸 값으로. (그림 커서면 그 CSS 값, 쓸 수 있는 CSS 이름이면 그대로, 아니면 "")
Converts a cursor name to the value to write to the canvas. (The CSS value for an image cursor, a usable CSS name as is, otherwise "")
- cursorNamestring
- 커서 이름.Cursor name.
반환Returnsstring 캔버스의 style.cursor 에 쓸 값. (모르는 이름이면 "")Value to write to the canvas style.cursor. ("" for an unknown name)
짝Counterpart: vanilla-engine PointerCursor.read_cursor_value
커서 정하기. (엔진이 프레임 끝마다 부른다, 단추 표시를 비운다)
Applies the cursor. (The engine calls it at the end of every frame, clears the button mark)