core/inputmanager
입력 관리자.
- 키 이름은 원본과 같이 KeyboardEvent.code 꼴이다. ("KeyA", "ArrowLeft", "Space" ...) winit 의 KeyCode 이름이 같은 W3C 규약을 따르므로 그대로 문자열로 바꿔 쓴다. 윈도우 키(커맨드 키)만 winit 이 SuperLeft, SuperRight 라 부르고 W3C 의 옛 Super 키를 Meta 라 불러서, 데스크탑 플랫폼이 MetaLeft, MetaRight, Super 로 바꿔 넣는다.
- KeyCode 의 상수 이름은 원본 KeyCode 의 키 이름을 러스트 상수 꼴로 바꾼 것이다. ("0" 처럼 이름이 될 수 없는 것은 DIGIT0) 원본에 없던 LEFT, UP, RIGHT, DOWN 은 ARROWLEFT 들과 같은 값으로 남긴다.
- 마우스 단추(또는 첫 손가락)를 터치로 다룬다. (원본은 마우스와 터치를 하나로 모은다) 원본처럼 처음에는 어느 단추든 터치이고, set_touch_from_left_button_only(true) 면 왼쪽 단추만 터치다. 캔버스의 오른쪽 클릭 메뉴를 막을지(set_context_menu_prevented, 처음은 참)는 웹에서 브라우저 문맥 메뉴를 막는다. 데스크탑 창에는 브라우저 문맥 메뉴가 없어 크롬에서 막은 것과 같은 결과다.
- 그 밖에 마우스 단추 셋(왼쪽, 가운데, 오른쪽)의 눌림, 닿아 있는 손가락 목록, 마지막 입력이 손가락인지, 휠을 Ctrl 과 함께 굴렸는지를 둔다. 카메라 손짓(CameraGestures)처럼 단추 하나 터치 밖의 입력을 쓰는 곳이 읽는다. 플랫폼이 채운다. (vanilla.js 는 캔버스 DOM 사건을 직접 읽던 것)
- 게임패드는 원본과 같이 InputManager 가 GamepadManager 를 들고 tick 에서 폴링한다. (core/gamepadmanager.rs)
- 글 입력(확정 글, IME 조합, 편집 키)은 TextInput 줄에 모은다. 입력 필드가 꺼내 쓴다. (core/textinput.rs, 원본에 없는 층)
- 키와 마우스 단추의 이번 프레임 누름과 뗌은 원본처럼 지난 프레임 끝 뒤로 온 사건을 쌓아 본다. 프레임 사이에 눌렀다 뗀 것도 잡힌다.
- 손가락은 원본처럼 닿음(begin_touch_point), 움직임, 뗌을 받아 단계(TouchPhase)를 매기고, 떨어진 손가락은 한 프레임 get_ended_touch_points 에 남는다.
- 마지막으로 쓴 장치(InputDevice)와 패드 종류, 막을 키(set_prevented_keys), 글자 입력칸에 쓰는 중인지(is_typing_in_text_field), 입력 동작(InputActions)을 둔다. 막을 키는 웹에서 브라우저 기본 동작(Tab 의 포커스 옮기기, Space 와 화살표의 스크롤, F5 새로 고침 같은 것)을 막는다. 데스크탑 창에는 그런 기본 동작이 없어 막은 것과 같은 결과다. 글자 입력칸은 엔진 입력 필드(TextInput 의 활성 필드)와, 웹에서는 문서의 초점(글자 input, textarea, contenteditable, select)을 본다.
Input manager.
- Key names are in KeyboardEvent.code form like the original. ("KeyA", "ArrowLeft", "Space" ...) winit's KeyCode names follow the same W3C convention, so they are converted to strings as is. Only for the Windows key (Command key), winit calls it SuperLeft, SuperRight and calls the old W3C Super key Meta, so the desktop platform puts in MetaLeft, MetaRight, Super instead.
- The constant names of KeyCode are the original KeyCode key names converted to Rust constant form. (DIGIT0 for things like "0" that cannot be a name) LEFT, UP, RIGHT, DOWN, which were not in the original, are kept with the same values as the ARROWLEFT family.
- The mouse button (or first finger) is handled as touch. (the original merges mouse and touch into one) Like the original, initially any button is touch, and with set_touch_from_left_button_only(true) only the left button is touch. Whether to block the canvas right-click menu (set_context_menu_prevented, initially true) blocks the browser context menu on the web. Desktop windows have no browser context menu, so the result is the same as blocking it in Chrome.
- It also holds the pressed state of the three mouse buttons (left, middle, right), the list of touching fingers, whether the last input was a finger, and whether the wheel was rolled with Ctrl. Places that use input beyond the single button touch, like camera gestures (CameraGestures), read them. The platform fills them in. (vanilla.js read canvas DOM events directly)
- Gamepads, like the original, are polled in tick by the GamepadManager that InputManager holds. (core/gamepadmanager.rs)
- Text input (committed text, IME composition, editing keys) is gathered in the TextInput queue. Input fields take it from there. (core/textinput.rs, a layer not in the original)
- This frame's presses and releases of keys and mouse buttons are seen by accumulating events that came after the end of the last frame, like the original. A press and release between frames is also caught.
- Fingers, like the original, receive touch (begin_touch_point), move and release and are given a phase (TouchPhase), and a lifted finger stays in get_ended_touch_points for one frame.
- It holds the last used device (InputDevice) and pad kind, the keys to block (set_prevented_keys), whether typing in a text field (is_typing_in_text_field), and input actions (InputActions). The keys to block prevent browser default actions on the web (such as Tab moving focus, Space and arrows scrolling, F5 refreshing). Desktop windows have no such default actions, so the result is the same as blocking them. For text fields it looks at the engine input field (the active field of TextInput) and, on the web, the document focus (text input, textarea, contenteditable, select).
use vanilla::{InputManager, KeyCode, MouseButton, TouchPhase, Vector2};
let mut input_manager = InputManager::new();
input_manager.push_key(KeyCode::SPACE);
input_manager.set_mouse_button_down(MouseButton::Left, true);
input_manager.begin_touch_point(1, Vector2::create(10.0, 20.0), Vector2::create(20.0, 40.0));
assert!(input_manager.is_key_just_pressed(KeyCode::SPACE));
assert!(input_manager.is_mouse_button_just_pressed(MouseButton::Left));
assert_eq!(input_manager.get_touch_points()[0].phase, TouchPhase::Began);
input_manager.update_frame_snapshot();
assert!(input_manager.is_key_pressed(KeyCode::SPACE));
assert!(!input_manager.is_key_just_pressed(KeyCode::SPACE));
assert!(input_manager.is_mouse_button_down(MouseButton::Left));
assert_eq!(input_manager.get_touch_points()[0].phase, TouchPhase::Stationary);KeyCodestruct
키 이름. (원본 KeyCode)
- 값은 KeyboardEvent.code 문자열이다. 상수에 없는 키는 그 이름 문자열("ShiftRight", "ControlRight" 같은)을 그대로 쓴다.
Key name. (the original KeyCode)
- The value is a KeyboardEvent.code string. Keys not among the constants use their name string (like "ShiftRight", "ControlRight") as is.
use vanilla::{InputManager, KeyCode};
assert_eq!(KeyCode::A, "KeyA");
assert_eq!(KeyCode::LEFT, KeyCode::ARROWLEFT);
let mut input_manager = InputManager::new();
input_manager.push_key(KeyCode::ENTER);
assert!(input_manager.is_key_pressed("Enter"));
assert!(!input_manager.is_key_pressed(KeyCode::NUMPAD_ENTER));숫자 0 키. (글자판 위쪽 줄, 텐키는 NUMPAD0)
Digit 0 key. (top row of the main keyboard, the numpad one is NUMPAD0)
반환Returns&'static str
숫자 1 키. (글자판 위쪽 줄, 텐키는 NUMPAD1)
Digit 1 key. (top row of the main keyboard, the numpad one is NUMPAD1)
반환Returns&'static str
숫자 2 키. (글자판 위쪽 줄, 텐키는 NUMPAD2)
Digit 2 key. (top row of the main keyboard, the numpad one is NUMPAD2)
반환Returns&'static str
숫자 3 키. (글자판 위쪽 줄, 텐키는 NUMPAD3)
Digit 3 key. (top row of the main keyboard, the numpad one is NUMPAD3)
반환Returns&'static str
숫자 4 키. (글자판 위쪽 줄, 텐키는 NUMPAD4)
Digit 4 key. (top row of the main keyboard, the numpad one is NUMPAD4)
반환Returns&'static str
숫자 5 키. (글자판 위쪽 줄, 텐키는 NUMPAD5)
Digit 5 key. (top row of the main keyboard, the numpad one is NUMPAD5)
반환Returns&'static str
숫자 6 키. (글자판 위쪽 줄, 텐키는 NUMPAD6)
Digit 6 key. (top row of the main keyboard, the numpad one is NUMPAD6)
반환Returns&'static str
숫자 7 키. (글자판 위쪽 줄, 텐키는 NUMPAD7)
Digit 7 key. (top row of the main keyboard, the numpad one is NUMPAD7)
반환Returns&'static str
숫자 8 키. (글자판 위쪽 줄, 텐키는 NUMPAD8)
Digit 8 key. (top row of the main keyboard, the numpad one is NUMPAD8)
반환Returns&'static str
숫자 9 키. (글자판 위쪽 줄, 텐키는 NUMPAD9)
Digit 9 key. (top row of the main keyboard, the numpad one is NUMPAD9)
반환Returns&'static str
엔터 키. (글자판 쪽, 텐키 엔터는 NUMPAD_ENTER)
Enter key. (main keyboard, the numpad Enter is NUMPAD_ENTER)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.enter
왼쪽 시프트 키. (오른쪽은 "ShiftRight")
Left Shift key. (the right one is "ShiftRight")
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.shift
왼쪽 컨트롤 키. (오른쪽은 "ControlRight")
Left Control key. (the right one is "ControlRight")
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.ctrl
왼쪽 알트 키. (오른쪽은 "AltRight")
Left Alt key. (the right one is "AltRight")
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.alt
왼쪽 화살표 키. (ARROWLEFT 와 같은 값)
Left arrow key. (same value as ARROWLEFT)
반환Returns&'static str
위쪽 화살표 키. (ARROWUP 과 같은 값)
Up arrow key. (same value as ARROWUP)
반환Returns&'static str
오른쪽 화살표 키. (ARROWRIGHT 와 같은 값)
Right arrow key. (same value as ARROWRIGHT)
반환Returns&'static str
아래쪽 화살표 키. (ARROWDOWN 과 같은 값)
Down arrow key. (same value as ARROWDOWN)
반환Returns&'static str
백쿼트 키. (숫자 1 왼쪽 키)
Backquote key. (the key left of digit 1)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.backquote
왼쪽 대괄호 키. ([)
Left bracket key. ([)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.bracketleft
오른쪽 대괄호 키. (])
Right bracket key. (])
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.bracketright
왼쪽 메타 키. (윈도우 키, 맥의 커맨드 키)
Left Meta key. (the Windows key, the Command key on Mac)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.meta
맥의 왼쪽 커맨드 키. (META 와 같은 값)
Left Command key on Mac. (same value as META)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.command
음소거. (W3C code 표의 이름 AudioVolumeMute)
Mute. (AudioVolumeMute, its name in the W3C code table)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.audiomute
재생/멈춤. (W3C code 표의 이름 MediaPlayPause, 표에 MediaPlay 는 없다)
Play/pause. (MediaPlayPause, its name in the W3C code table, the table has no MediaPlay)
반환Returns&'static str
짝Counterpart: vanilla.js KeyCode.audioplay
TouchPointstruct traits Clone, Copy, PartialEq, Debug
닿아 있는 손가락 하나. (플랫폼의 손가락 번호, 단계, 캔버스 논리 좌표와 뷰 좌표)
One touching finger. (the platform's finger number, phase, canvas logical coordinates and view coordinates)
use vanilla::{InputManager, TouchPhase, Vector2};
let mut input_manager = InputManager::new();
input_manager.begin_touch_point(3, Vector2::create(10.0, 10.0), Vector2::create(20.0, 20.0));
input_manager.begin_touch_point(4, Vector2::create(50.0, 10.0), Vector2::create(100.0, 20.0));
input_manager.end_touch_point(3, Vector2::create(12.0, 10.0), Vector2::create(24.0, 20.0), false);
let touch_point = input_manager.get_touch_points()[0];
assert_eq!(touch_point.identifier, 4);
assert_eq!(touch_point.view_position, Vector2::create(100.0, 20.0));
let ended_touch_point = input_manager.get_ended_touch_points()[0];
assert_eq!(ended_touch_point.phase, TouchPhase::Ended);
assert_eq!(ended_touch_point.canvas_native_position, Vector2::create(12.0, 10.0));플랫폼의 손가락 번호. (닿아 있는 동안 같다)
The platform's finger number. (stays the same while touching)
반환Returnsi64
짝Counterpart: vanilla.js TouchPoint.identifier
창(캔버스) 안쪽 논리 좌표의 자리. (캔버스 왼쪽 위가 0, 논리 픽셀)
Position in logical coordinates inside the window (canvas). (0 at the top left of the canvas, logical pixels)
반환ReturnsVector2
짝Counterpart: vanilla.js TouchPoint.canvasNativePosition
뷰 좌표의 자리. (ViewManager.canvas_position_to_view_position 으로 바꾼 것)
Position in view coordinates. (converted with ViewManager.canvas_position_to_view_position)
반환ReturnsVector2
짝Counterpart: vanilla.js TouchPoint.viewPosition
InputManagerstruct traits Default
입력 관리자. (원본 InputManager)
- 엔진이 하나 들고 플랫폼이 키, 마우스, 손가락, 휠 사건을 넣는다. 씬은 engine.get_input_manager() 로 읽는다.
- 이번 프레임의 누름과 뗌, 터치 Pressed / Released / Cancelled, 휠 이동량은 엔진이 프레임 끝에 비운다.
Input manager. (the original InputManager)
- The engine holds one and the platform puts in key, mouse, finger and wheel events. Scenes read it with engine.get_input_manager().
- This frame's presses and releases, touch Pressed / Released / Cancelled, and wheel deltas are cleared by the engine at the end of the frame.
use vanilla::{Engine, EngineConfiguration, KeyCode, MouseButton, Scene, SceneBase};
struct MainScene {
scene_base: SceneBase,
}
impl Scene for MainScene {
fn get_scene_base(&self) -> &SceneBase {
&self.scene_base
}
fn get_scene_base_mut(&mut self) -> &mut SceneBase {
&mut self.scene_base
}
fn load(&mut self, engine: &Engine) {
let mut input_manager = engine.get_input_manager_mut();
input_manager.set_prevented_keys(&[KeyCode::TAB, KeyCode::SPACE]);
input_manager.set_touch_from_left_button_only(true);
}
fn tick(&mut self, time_delta: f64) {
let engine = Engine::get_engine().unwrap();
self.scene_base.tick(time_delta);
let input_manager = engine.get_input_manager();
if input_manager.is_key_just_pressed(KeyCode::SPACE) {
println!("jump");
}
if input_manager.is_mouse_button_down(MouseButton::Right) {
println!("{:?}", input_manager.get_view_input_position());
}
if input_manager.has_wheel_delta() {
println!("{}", input_manager.get_wheel_delta_y());
}
}
}
let engine_configuration = EngineConfiguration::new();
let engine = Engine::new(engine_configuration);
let main_scene = MainScene {
scene_base: SceneBase::new(),
};
engine.run(Box::new(main_scene)).unwrap();생성.
- 오른쪽 클릭 메뉴는 막고, 어느 마우스 단추든 터치로 넘긴다. 손가락이 주된 입력인 기기면 마지막 장치가 Touch 로 시작한다.
Constructor.
- Blocks the right-click menu and passes any mouse button as touch. On devices whose main input is fingers, the last device starts as Touch.
반환ReturnsInputManager 아무 키도 눌리지 않은 입력 관리자.Input manager with no keys pressed.
짝Counterpart: vanilla.js InputManager.constructor
주기적 갱신. (게임패드 폴링, 패드를 썼으면 마지막 장치를 게임패드로, 입력 동작 갱신)
- 엔진이 프레임 첫머리에 부른다. 처음 부를 때 게임패드 입력원(데스크탑 gilrs)을 연다.
Periodic update. (polls gamepads, sets the last device to gamepad if a pad was used, updates input actions)
- The engine calls it at the start of a frame. On the first call it opens the gamepad input source (gilrs on desktop).
- time_deltaf64
- 지난 프레임 뒤로 흐른 초. (입력 동작의 반복 시간에 쓴다)Seconds elapsed since the last frame. (used for the repeat timing of input actions)
짝Counterpart: vanilla.js InputManager.tick
모든 입력 상태 비우기. (창이 포커스를 잃었을 때)
Clears all input state. (when the window loses focus)
짝Counterpart: vanilla.js InputManager.clear
휠 이동량 누적.
- 플랫폼이 휠 사건마다 부르고, 엔진이 프레임 끝에 clear_wheel_delta 로 비운다.
Accumulates wheel deltas.
- The platform calls it for every wheel event, and the engine clears it with clear_wheel_delta at the end of the frame.
- delta_xf64
- 가로 이동량. (픽셀, 브라우저 WheelEvent.deltaX 와 같은 방향)Horizontal delta. (pixels, same direction as the browser WheelEvent.deltaX)
- delta_yf64
- 세로 이동량. (픽셀, 브라우저 WheelEvent.deltaY 와 같은 방향, 내용을 아래로 넘기면 양수)Vertical delta. (pixels, same direction as the browser WheelEvent.deltaY, positive when scrolling the content down)
짝Counterpart: vanilla.js InputManager.addWheelDelta
use vanilla::InputManager;
let mut input_manager = InputManager::new();
input_manager.add_wheel_delta(0.0, 40.0);
input_manager.add_wheel_delta(0.0, 40.0);
assert!(input_manager.has_wheel_delta());
assert_eq!(input_manager.get_wheel_delta_y(), 80.0);
input_manager.clear_wheel_delta();
assert!(!input_manager.has_wheel_delta());이번 프레임의 가로 휠 이동량.
Horizontal wheel delta this frame.
반환Returnsf64 이번 프레임에 쌓인 가로 이동량. (픽셀, 오른쪽으로 넘기면 양수)Horizontal delta accumulated this frame. (pixels, positive when scrolling right)
짝Counterpart: vanilla.js InputManager.getWheelDeltaX
이번 프레임의 세로 휠 이동량.
Vertical wheel delta this frame.
반환Returnsf64 이번 프레임에 쌓인 세로 이동량. (픽셀, 내용을 아래로 넘기면 양수)Vertical delta accumulated this frame. (pixels, positive when scrolling the content down)
짝Counterpart: vanilla.js InputManager.getWheelDeltaY
이번 프레임에 휠을 굴렸는지.
Whether the wheel was rolled this frame.
반환Returnsbool 가로나 세로 이동량이 0 이 아니면 true.true if the horizontal or vertical delta is not 0.
짝Counterpart: vanilla.js InputManager.hasWheelDelta
휠 이동량 비우기. (엔진이 프레임 끝에 부른다)
Clears the wheel deltas. (called by the engine at the end of the frame)
짝Counterpart: vanilla.js InputManager.clearWheelDelta
키 눌림 기록.
- 이미 눌려 있으면(키 되풀이) 이번 프레임의 누름으로 세지 않는다.
Records a key press.
- If already pressed (key repeat), it is not counted as a press this frame.
- key&str
- 키 이름. (KeyboardEvent.code, KeyCode 의 값)Key name. (KeyboardEvent.code, a KeyCode value)
짝Counterpart: vanilla.js InputManager.pushKey
키 뗌 기록.
- 눌려 있지 않던 키면 아무것도 하지 않는다.
Records a key release.
- Does nothing if the key was not pressed.
- key&str
- 키 이름. (KeyboardEvent.code, KeyCode 의 값)Key name. (KeyboardEvent.code, a KeyCode value)
짝Counterpart: vanilla.js InputManager.popKey
키가 눌려 있는지.
Whether a key is pressed.
- key&str
- 키 이름. (KeyboardEvent.code, KeyCode 의 값)Key name. (KeyboardEvent.code, a KeyCode value)
반환Returnsbool 눌린 채면 true.true if held.
짝Counterpart: vanilla.js InputManager.isKeyPressed
이번 프레임에 눌렸는지. (지난 프레임 끝 뒤로 온 사건, 프레임 사이에 눌렀다 뗀 키도 참이고 그때는 is_key_pressed 가 거짓)
Whether pressed this frame. (events since the end of the last frame, also true for a key pressed and released between frames, in which case is_key_pressed is false)
- key&str
- 키 이름. (KeyboardEvent.code, KeyCode 의 값)Key name. (KeyboardEvent.code, a KeyCode value)
반환Returnsbool 지난 프레임 끝 뒤로 새로 눌렸으면 true. (키 되풀이는 세지 않는다)true if newly pressed since the end of the last frame. (key repeat is not counted)
짝Counterpart: vanilla.js InputManager.isKeyJustPressed
use vanilla::{InputManager, KeyCode};
let mut input_manager = InputManager::new();
input_manager.push_key(KeyCode::Z);
input_manager.pop_key(KeyCode::Z);
assert!(input_manager.is_key_just_pressed(KeyCode::Z));
assert!(input_manager.is_key_just_released(KeyCode::Z));
assert!(!input_manager.is_key_pressed(KeyCode::Z));
input_manager.update_frame_snapshot();
assert!(!input_manager.is_key_just_pressed(KeyCode::Z));이번 프레임에 떼졌는지.
Whether released this frame.
- key&str
- 키 이름. (KeyboardEvent.code, KeyCode 의 값)Key name. (KeyboardEvent.code, a KeyCode value)
반환Returnsbool 지난 프레임 끝 뒤로 떼어졌으면 true.true if released since the end of the last frame.
짝Counterpart: vanilla.js InputManager.isKeyJustReleased
프레임 끝 스냅샷. (쌓인 키와 마우스 단추의 누름과 뗌을 비우고, 떨어진 손가락을 지우고 남은 손가락을 가만히로)
End-of-frame snapshot. (clears accumulated presses and releases of keys and mouse buttons, removes lifted fingers and sets the remaining fingers to stationary)
짝Counterpart: vanilla.js InputManager.updateFrameSnapshot
마우스 단추 눌림 설정. (플랫폼이 부른다)
- 바뀐 때만 이번 프레임의 누름이나 뗌으로 쌓는다.
Sets a mouse button's pressed state. (called by the platform)
- Accumulated as a press or release this frame only when it changes.
- mouse_buttonMouseButton
- 단추.Button.
- is_downbool
- 눌렸으면 true, 뗐으면 false.true if pressed, false if released.
짝Counterpart: vanilla.js InputManager.setMouseButtonDown
마우스 단추가 눌려 있는지.
Whether the mouse button is pressed.
- mouse_buttonMouseButton
- 단추.Button.
반환Returnsbool 눌린 채면 true.true if held.
짝Counterpart: vanilla.js InputManager.isMouseButtonDown
이번 프레임에 마우스 단추를 눌렀는지.
Whether a mouse button was pressed this frame.
- mouse_buttonMouseButton
- 단추.Button.
반환Returnsbool 지난 프레임 끝 뒤로 눌렀으면 true. (프레임 사이에 눌렀다 뗀 것도)true if pressed since the end of the last frame. (including a press and release between frames)
짝Counterpart: vanilla.js InputManager.isMouseButtonJustPressed
이번 프레임에 마우스 단추를 뗐는지.
Whether the mouse button was released this frame.
- mouse_buttonMouseButton
- 단추.Button.
반환Returnsbool 지난 프레임 끝 뒤로 뗐으면 true.true if released since the end of the last frame.
짝Counterpart: vanilla.js InputManager.isMouseButtonJustReleased
마우스 왼쪽 단추만 터치로 넘길지 설정. (끄면(기본) 어느 단추든 터치다)
- 오른쪽이나 가운데 끌기를 카메라에 쓰는 게임이 켜면 그 단추로 UI 가 눌리지 않는다.
Sets whether to pass only the left mouse button as touch. (when off (default), any button is touch)
- When a game that uses right or middle dragging for the camera turns it on, the UI is not pressed by those buttons.
- is_left_button_onlybool
- 왼쪽 단추만 터치로 넘기려면 true.true to pass only the left button as touch.
짝Counterpart: vanilla.js InputManager.setTouchFromLeftButtonOnly
use vanilla::{InputManager, MouseButton};
let mut input_manager = InputManager::new();
assert!(input_manager.is_touch_button(MouseButton::Right));
input_manager.set_touch_from_left_button_only(true);
assert!(input_manager.is_touch_button(MouseButton::Left));
assert!(!input_manager.is_touch_button(MouseButton::Right));마우스 왼쪽 단추만 터치로 넘기는지 반환.
Returns whether only the left mouse button is passed as touch.
반환Returnsbool 왼쪽 단추만이면 true. (처음은 false)true if only the left button. (initially false)
짝Counterpart: vanilla.js InputManager.isTouchFromLeftButtonOnly
그 마우스 단추를 터치로 넘기는지. (플랫폼이 마우스 누름과 뗌에서 부른다)
Whether that mouse button is passed as touch. (called by the platform on mouse press and release)
- mouse_buttonMouseButton
- 단추.Button.
반환Returnsbool 터치로 넘기면 true. (왼쪽 단추만으로 정했으면 Left 만 true)true if passed as touch. (only Left is true if set to the left button only)
닿아 있는 손가락 찾기. (없으면 None)
Finds a touching finger. (None if none)
- identifieri64
- 플랫폼의 손가락 번호.The platform's finger number.
반환ReturnsOption<&TouchPoint> 그 번호의 닿아 있는 손가락. 없거나 이미 떨어졌으면 None.The touching finger with that number. None if it does not exist or has already lifted.
짝Counterpart: vanilla.js InputManager.findTouchPoint
use vanilla::{InputManager, Vector2};
let mut input_manager = InputManager::new();
input_manager.begin_touch_point(7, Vector2::create(1.0, 2.0), Vector2::create(3.0, 4.0));
let view_position = input_manager.find_touch_point(7).map(|touch_point| touch_point.view_position);
assert_eq!(view_position, Some(Vector2::create(3.0, 4.0)));
assert!(input_manager.find_touch_point(8).is_none());pub fn begin_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2)#손가락이 닿음. (플랫폼이 부른다, 이미 있는 번호면 움직임으로 본다)
A finger touches. (called by the platform, treated as a move if the number already exists)
- identifieri64
- 플랫폼의 손가락 번호.The platform's finger number.
- canvas_native_positionVector2
- 창(캔버스) 안쪽 논리 좌표의 자리.Position in logical coordinates inside the window (canvas).
- view_positionVector2
- 뷰 좌표의 자리.Position in view coordinates.
짝Counterpart: vanilla.js InputManager.beginTouchPoint
pub fn move_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2)#손가락이 움직임. (이번 프레임에 닿은 손가락은 Began 그대로)
- 닿아 있지 않은 번호면 아무것도 하지 않는다.
A finger moves. (a finger that touched this frame stays Began)
- Does nothing if the number is not touching.
- identifieri64
- 플랫폼의 손가락 번호.The platform's finger number.
- canvas_native_positionVector2
- 창(캔버스) 안쪽 논리 좌표의 새 자리.New position in logical coordinates inside the window (canvas).
- view_positionVector2
- 뷰 좌표의 새 자리.New position in view coordinates.
짝Counterpart: vanilla.js InputManager.moveTouchPoint
pub fn end_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2, is_cancelled: bool)#손가락이 떨어짐. (닿은 목록에서 빼서 이번 프레임의 떨어진 목록에 둔다)
- 닿아 있지 않은 번호면 아무것도 하지 않는다.
A finger lifts. (removed from the touching list and put in this frame's lifted list)
- Does nothing if the number is not touching.
- identifieri64
- 플랫폼의 손가락 번호.The platform's finger number.
- canvas_native_positionVector2
- 뗀 자리. (창 안쪽 논리 좌표)Lift position. (logical coordinates inside the window)
- view_positionVector2
- 뗀 자리. (뷰 좌표)Release position. (view coordinates)
- is_cancelledbool
- 취소면 true(단계 Cancelled), 뗌이면 false(단계 Ended).true if cancelled (phase Cancelled), false if released (phase Ended).
짝Counterpart: vanilla.js InputManager.endTouchPoint
이번 프레임에 떨어진 손가락 목록. (단계는 Ended, Cancelled, 자리는 뗀 자리)
List of fingers lifted this frame. (phase is Ended, Cancelled, position is the lift position)
반환Returns&[TouchPoint] 지난 프레임 끝 뒤로 떨어진 손가락들. (뗀 차례)Fingers lifted since the end of the last frame. (in lift order)
짝Counterpart: vanilla.js InputManager.getEndedTouchPoints
닿아 있는 손가락 목록 설정. (통째로 바꾼다, 단계는 넘긴 그대로)
Sets the list of touching fingers. (replaces it whole, phases as passed)
- touch_pointsVec<TouchPoint>
- 새 손가락 목록.New finger list.
닿아 있는 손가락 목록. (닿은 차례, 단계는 Began, Moved, Stationary)
List of touching fingers. (in touch order, phase is Began, Moved, Stationary)
반환Returns&[TouchPoint] 닿아 있는 손가락들. 없으면 빈 조각.Touching fingers. Empty slice if none.
짝Counterpart: vanilla.js InputManager.getTouchPoints
마지막 입력이 손가락인지 설정. (플랫폼이 부른다)
Sets whether the last input was a finger. (called by the platform)
- is_touch_inputbool
- 손가락이면 true, 마우스면 false.true for a finger, false for a mouse.
마지막 입력이 손가락인지. (마우스면 false, 처음에는 기기가 손가락이 주된 입력인지로. 원본 CameraGestures.isTouchInput 과 같다)
Whether the last input was a finger. (false for a mouse, initially whether the device's main input is fingers. Same as the original CameraGestures.isTouchInput)
반환Returnsbool 마지막 입력이 손가락이면 true.true if the last input was a finger.
짝Counterpart: vanilla.js InputManager.isTouchInput
마지막 휠을 Ctrl 과 함께 굴렸는지 설정. (노트북 터치패드의 오므리기도 Ctrl 휠로 온다)
Sets whether the last wheel was rolled with Ctrl. (a laptop touchpad pinch also comes as a Ctrl wheel)
- is_wheel_with_ctrlbool
- Ctrl 과 함께였으면 true.true if with Ctrl.
짝Counterpart: vanilla.js InputManager.setWheelWithCtrl
마지막 휠을 Ctrl 과 함께 굴렸는지.
Whether the last wheel was rolled with Ctrl.
반환Returnsbool 마지막 휠 사건이 Ctrl 과 함께였으면 true. (프레임 끝에 지우지 않는다)true if the last wheel event was with Ctrl. (not cleared at the end of the frame)
짝Counterpart: vanilla.js InputManager.isWheelWithCtrl
터치 상태. (Pressed / Released / Cancelled 는 그 프레임에만 켜진다, Moved 는 누른 동안 켜진다 set_touch_moved)
Touch state. (Pressed / Released / Cancelled are on only for that frame, Moved is on while pressed, set_touch_moved)
- valuebool
- 이번 프레임에 눌렀으면 true.true if pressed this frame.
짝Counterpart: vanilla.js InputManager.setTouchPressed
이번 프레임에 뗐는지 설정. (플랫폼이 켜고 엔진이 프레임 끝에 끈다)
Sets whether released this frame. (the platform turns it on and the engine turns it off at the end of the frame)
- valuebool
- 이번 프레임에 뗐으면 true.true if released this frame.
짝Counterpart: vanilla.js InputManager.setTouchReleased
이번 프레임에 터치가 취소됐는지 설정. (플랫폼이 켜고 엔진이 프레임 끝에 끈다)
Sets whether the touch was cancelled this frame. (the platform turns it on and the engine turns it off at the end of the frame)
- valuebool
- 이번 프레임에 취소됐으면 true.true if cancelled this frame.
짝Counterpart: vanilla.js InputManager.setTouchCancelled
누르고 있는지. (원본처럼 누를 때 켜고 뗄 때 끈다, 프레임마다 지우지 않는다, 원본 주석 "입력시 뗄 때까지 계속 눌림")
Whether being held. (on when pressed and off when released like the original, not cleared every frame, the original comment "pressed continuously until released after input")
- valuebool
- 누를 때 true, 떼거나 취소될 때 false.true when pressed, false when released or cancelled.
짝Counterpart: vanilla.js InputManager.setTouchMoved
이번 프레임에 터치를 눌렀는지.
Whether the touch was pressed this frame.
반환Returnsbool 이번 프레임에 눌렀으면 true. (첫 손가락이나 터치로 넘기는 마우스 단추)true if pressed this frame. (the first finger or a mouse button passed as touch)
짝Counterpart: vanilla.js InputManager.isTouchPressed
use vanilla::InputManager;
let mut input_manager = InputManager::new();
input_manager.set_touch_pressed(true);
input_manager.set_touch_moved(true);
input_manager.set_touch_down(true);
assert!(input_manager.is_touch_pressed());
input_manager.set_touch_pressed(false);
assert!(input_manager.is_touch_moved());
assert!(input_manager.is_touch_down());
input_manager.set_touch_moved(false);
input_manager.set_touch_released(true);
input_manager.set_touch_down(false);
assert!(input_manager.is_touch_released());
assert!(!input_manager.is_touch_down());이번 프레임에 터치를 뗐는지.
Whether the touch was released this frame.
반환Returnsbool 이번 프레임에 뗐으면 true.true if released this frame.
짝Counterpart: vanilla.js InputManager.isTouchReleased
이번 프레임에 터치가 취소됐는지.
Whether the touch was cancelled this frame.
반환Returnsbool 이번 프레임에 취소됐으면 true. (플랫폼이 손가락 입력을 거둔 때)true if cancelled this frame. (when the platform withdrew finger input)
짝Counterpart: vanilla.js InputManager.isTouchCancelled
누르고 있는지. (원본 isTouchMoved, 이름과 달리 움직이지 않아도 누른 동안 참)
Whether being held. (the original isTouchMoved, true while pressed even without moving, despite the name)
반환Returnsbool 누른 프레임부터 떼거나 취소될 때까지 true.true from the pressed frame until released or cancelled.
짝Counterpart: vanilla.js InputManager.isTouchMoved
터치가 눌린 채인지. (러스트 판에서 더한 것. 눌린 동안 계속 켜져 있다)
Whether the touch is held. (added in the Rust version. Stays on while pressed)
- valuebool
- 누를 때 true, 떼거나 취소될 때 false.true when pressed, false when released or cancelled.
짝Counterpart: vanilla.js InputManager.setTouchDown
터치가 눌린 채인지.
Whether the touch is held.
반환Returnsbool 누른 프레임부터 떼거나 취소될 때까지 true. (누른 채 움직이지 않아도)true from the pressed frame until released or cancelled. (even if held without moving)
짝Counterpart: vanilla.js InputManager.isTouchDown
입력 위치. (창 안쪽 논리 좌표 / 뷰 좌표)
- 창 안쪽 논리 좌표의 입력 위치 설정. (플랫폼이 마우스와 첫 손가락에서 부른다)
Input position. (logical coordinates inside the window / view coordinates)
- Sets the input position in logical coordinates inside the window. (called by the platform for the mouse and first finger)
- positionVector2
- 캔버스 왼쪽 위가 0 인 논리 픽셀 자리.Position in logical pixels with 0 at the top left of the canvas.
짝Counterpart: vanilla.js InputManager.setCanvasNativeInputPosition
창 안쪽 논리 좌표의 입력 위치.
Input position in logical coordinates inside the window.
반환ReturnsVector2 마지막 마우스나 첫 손가락의 자리. (캔버스 왼쪽 위가 0, 논리 픽셀, 처음은 0, 0)Position of the last mouse or first finger. (0 at the top left of the canvas, logical pixels, initially 0, 0)
짝Counterpart: vanilla.js InputManager.getCanvasNativeInputPosition
뷰 좌표의 입력 위치 설정. (플랫폼이 마우스와 첫 손가락에서 부른다)
Sets the input position in view coordinates. (called by the platform for the mouse and first finger)
- positionVector2
- 뷰 좌표의 자리.Position in view coordinates.
짝Counterpart: vanilla.js InputManager.setViewInputPosition
뷰 좌표의 입력 위치. (씬의 touch_press 들이 받는 자리)
Input position in view coordinates. (the position the scene's touch_press functions receive)
반환ReturnsVector2 마지막 마우스나 첫 손가락의 뷰 좌표 자리. (처음은 0, 0)View coordinate position of the last mouse or first finger. (initially 0, 0)
짝Counterpart: vanilla.js InputManager.getViewInputPosition
모든 게임패드 갱신.
Updates all gamepads.
짝Counterpart: vanilla.js InputManager.updateAllGamepads
게임패드 연결.
Gamepad connected.
- gamepad&Gamepad
- 붙일 패드. (같은 index 가 이미 붙어 있으면 건너뛴다)Pad to attach. (skipped if the same index is already attached)
짝Counterpart: vanilla.js InputManager.connectGamepad
게임패드 연결 해제.
Gamepad disconnected.
- gamepad&Gamepad
- 뗄 패드. (index 로 찾는다, 붙어 있지 않으면 건너뛴다)Pad to detach. (found by index, skipped if not attached)
짝Counterpart: vanilla.js InputManager.disconnectGamepad
게임패드 매니저 반환.
Returns the gamepad manager.
반환Returns&GamepadManager 들고 있는 게임패드 관리자.The held gamepad manager.
짝Counterpart: vanilla.js InputManager.getGamepadManager
게임패드 매니저 반환. (바꿀 때: set_callback, connect 들)
Returns the gamepad manager. (for changes: set_callback, connect and such)
반환Returns&mut GamepadManager 들고 있는 게임패드 관리자. (바꿀 수 있게)The held gamepad manager. (mutable)
짝Counterpart: vanilla.js InputManager.getGamepadManager
글 입력 줄 반환. (입력 필드가 꺼내 쓰고 상태를 올린다. &self 로 된다)
Returns the text input queue. (input fields take from it and update its state. Works with &self)
반환Returns&TextInput 들고 있는 글 입력 줄.The held text input queue.
글 입력 줄 반환. (플랫폼이 이벤트를 넣을 때)
Returns the text input queue. (for the platform putting in events)
반환Returns&mut TextInput 들고 있는 글 입력 줄. (바꿀 수 있게)The held text input queue. (mutable)
마지막으로 쓴 입력 장치 설정. (플랫폼이 키, 마우스, 손가락 입력에서 부른다, 게임이 바깥 입력원을 쓸 때도)
Sets the last used input device. (called by the platform on key, mouse and finger input, also when a game uses an outside input source)
- input_deviceInputDevice
- 장치.Device.
짝Counterpart: vanilla.js InputManager.setLastInputDevice
마지막으로 쓴 입력 장치. (처음은 손가락 기기면 Touch, 아니면 Keyboard)
Last used input device. (initially Touch on finger devices, otherwise Keyboard)
반환ReturnsInputDevice 마지막으로 쓴 장치. (단추 안내를 키보드나 패드 표기로 가를 때)Last used device. (for choosing keyboard or pad notation for button hints)
짝Counterpart: vanilla.js InputManager.getLastInputDevice
use vanilla::{GamepadKind, InputDevice, InputManager};
let mut input_manager = InputManager::new();
input_manager.set_last_input_device(InputDevice::Gamepad);
input_manager.set_last_gamepad_kind(GamepadKind::PlayStation);
let hint = match input_manager.get_last_input_device() {
InputDevice::Gamepad => {
match input_manager.get_last_gamepad_kind() {
GamepadKind::PlayStation => {
"Cross"
}
_ => {
"A"
}
}
}
_ => {
"Enter"
}
};
assert_eq!(hint, "Cross");마지막으로 쓴 게임패드의 종류 설정.
Sets the kind of the last used gamepad.
- gamepad_kindGamepadKind
- 패드 종류.Pad kind.
짝Counterpart: vanilla.js InputManager.setLastGamepadKind
마지막으로 쓴 게임패드의 종류. (단추를 누르거나 스틱을 크게 기울인 패드의 이름으로 가른다, 처음은 Other)
Kind of the last used gamepad. (told from the name of the pad that pressed a button or tilted a stick far, initially Other)
반환ReturnsGamepadKind 마지막으로 쓴 패드의 종류.Kind of the last used pad.
짝Counterpart: vanilla.js InputManager.getLastGamepadKind
브라우저 기본 동작을 막을 키 설정. (KeyboardEvent.code 목록, 웹에서만 뜻이 있다, 글자 입력칸에 쓰는 중이면 막지 않는다)
- 앞서 정한 목록을 통째로 바꾼다.
Sets the keys whose browser default action is blocked. (a KeyboardEvent.code list, meaningful only on the web, not blocked while typing in a text field)
- Replaces the previously set list whole.
- keys&[&str]
- 막을 키 이름 목록. (KeyCode 의 값)List of key names to block. (KeyCode values)
짝Counterpart: vanilla.js InputManager.setPreventedKeys
use vanilla::{InputManager, KeyCode};
let mut input_manager = InputManager::new();
input_manager.set_prevented_keys(&[KeyCode::TAB, KeyCode::SPACE]);
assert!(input_manager.is_key_prevented("Tab"));
assert!(!input_manager.is_key_prevented(KeyCode::F5));
assert_eq!(input_manager.get_prevented_keys().len(), 2);브라우저 기본 동작을 막을 키 목록.
List of keys whose browser default action is blocked.
반환ReturnsVec<String> 막을 키 이름의 사본. (차례는 정해지지 않는다)Copy of the key names to block. (order is undefined)
짝Counterpart: vanilla.js InputManager.getPreventedKeys
그 키의 기본 동작을 막는지.
Whether the key's default behavior is blocked.
- key&str
- 키 이름. (KeyboardEvent.code)Key name. (KeyboardEvent.code)
반환Returnsbool 막을 키 목록에 있으면 true.true if in the list of keys to block.
짝Counterpart: vanilla.js InputManager.isKeyPrevented
글자 입력칸에 쓰는 중인지. (엔진 입력 필드의 포커스, 웹은 문서의 초점이 글자 input, textarea, contenteditable, select 에 있음)
Whether typing in a text field. (engine input field focus, on the web the document focus is on a text input, textarea, contenteditable, select)
반환Returnsbool 엔진 입력 필드가 활성이거나 웹 문서의 초점이 글자 입력칸에 있으면 true.true if an engine input field is active or the web document focus is on a text field.
짝Counterpart: vanilla.js InputManager.isTypingInTextField
입력 동작. (동작 이름에 키, 패드 단추, 축을 묶어 읽는다, tick 마다 갱신된다)
Input actions. (binds keys, pad buttons and axes to action names to read them, updated every tick)
반환Returns&InputActions 들고 있는 입력 동작.The held input actions.
짝Counterpart: vanilla.js InputManager.getInputActions
입력 동작. (묶기, 반복, 바깥 입력원)
Input actions. (binding, repeat, outside input sources)
반환Returns&mut InputActions 들고 있는 입력 동작. (바꿀 수 있게)The held input actions. (mutable)
짝Counterpart: vanilla.js InputManager.getInputActions
MouseButtonenum traits Clone, Copy, PartialEq, Eq, Hash, Debug
마우스 단추.
Mouse button.
| 이름Name | 설명Description |
|---|---|
Left | 왼쪽 단추. (칸 번호 0)Left button. (slot index 0) |
Middle | 가운데 단추. (휠 누름, 칸 번호 1)Middle button. (wheel press, slot index 1) |
Right | 오른쪽 단추. (칸 번호 2)Right button. (slot index 2) |
단추 칸 번호.
Button slot index.
반환Returnsusize Left 0, Middle 1, Right 2.
TouchPhaseenum traits Clone, Copy, PartialEq, Eq, Hash, Debug
손가락의 단계. (Began 이번 프레임에 닿음, Moved 움직임, Stationary 가만히, Ended 뗌, Cancelled 취소)
Finger phase. (Began touched this frame, Moved moved, Stationary still, Ended released, Cancelled cancelled)
| 이름Name | 설명Description |
|---|---|
Began | 이번 프레임에 닿음. (닿은 프레임에는 움직여도 Began 그대로)Touched this frame. (stays Began in the frame it touched even if it moves) |
Moved | 지난 프레임 뒤로 움직임.Moved since the last frame. |
Stationary | 닿은 채 가만히. (프레임 끝 update_frame_snapshot 이 남은 손가락을 이것으로 바꾼다)Touching and still. (update_frame_snapshot at the end of the frame changes remaining fingers to this) |
Ended | 떨어짐. (get_ended_touch_points 에 한 프레임 남는다)Lifted. (stays in get_ended_touch_points for one frame) |
Cancelled | 취소됨. (플랫폼이 손가락 입력을 거둔 것, get_ended_touch_points 에 한 프레임 남는다)Cancelled. (the platform withdrew the finger input, stays in get_ended_touch_points for one frame) |
InputDeviceenum traits Clone, Copy, PartialEq, Eq, Hash, Debug
마지막으로 쓴 입력 장치.
Last used input device.
| 이름Name | 설명Description |
|---|---|
Keyboard | 키보드.Keyboard. |
Mouse | 마우스.Mouse. |
Touch | 손가락. (터치 화면)Finger. (touch screen) |
Gamepad | 게임패드. (바깥 입력원 InputActionSource 가 넣은 패드 입력도)Gamepad. (including pad input put in by the outside input source InputActionSource) |