ludic/packages/ludic.ui/controls_key_mouse.ludic

22 lines
1.1 KiB
Text

# controls_key_mouse.ludic - a key field listening takes a mouse button too: the left, right or
# middle button pressed anywhere is its value, as UI_MOUSE_LEFT, UI_MOUSE_RIGHT or UI_MOUSE_MIDDLE
# (past every key code, for the host to map), and that press does nothing else
export const UI_MOUSE_LEFT: int = 256
export const UI_MOUSE_RIGHT: int = 257
export const UI_MOUSE_MIDDLE: int = 258
function ct_key_mouse(ui_st: mut UiState, root: UiNode) -> bool {
if ui_st.ct_capture == "" or ui_st.ct_capture_at == ui_st.an_frame { return false }
let b = pe_pressed(ui_st.in_now, ui_st.in_last)
if b < 0 { return false }
let n = fr_node(root, ui_st.ct_capture)
ui_st.ct_capture = ""
ui_st.ct_capture_seen = ui_st.an_frame
ui_st.fr_press_key = ""
if n != null { ct_change(ui_st, n, Value.int(UI_MOUSE_LEFT + b)) }
return true
}
function ct_mouse_name(ui_st: UiState, v: int) -> string {
if v == UI_MOUSE_RIGHT { return ui_tk(ui_st, k"ui.right_click", "Right click") }
if v == UI_MOUSE_MIDDLE { return ui_tk(ui_st, k"ui.middle_click", "Middle click") }
return ui_tk(ui_st, k"ui.left_click", "Left click")
}