ludic/packages/ludic.ui/controls_key_mouse.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

22 lines
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_tr(ui_st, "Right click") }
if v == UI_MOUSE_MIDDLE { return ui_tr(ui_st, "Middle click") }
return ui_tr(ui_st, "Left click")
}