From 5bd965b075f2fde5c0bbb2288ba450181c3fc68a Mon Sep 17 00:00:00 2001 From: Jean Michel Date: Tue, 26 Nov 2024 14:39:33 +0100 Subject: [PATCH] :sparkles: New NCurses funcs and mouse support (#17) --- src/submodules/NCurses/ncurses_functions.jl | 82 +++++++++++++++++++-- src/submodules/NCurses/ncurses_keys.jl | 47 ++++++++++++ src/submodules/NCurses/ncurses_mouse.jl | 52 +++++++++++++ src/submodules/NCurses/types.jl | 2 + 4 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 src/submodules/NCurses/ncurses_keys.jl create mode 100644 src/submodules/NCurses/ncurses_mouse.jl diff --git a/src/submodules/NCurses/ncurses_functions.jl b/src/submodules/NCurses/ncurses_functions.jl index 7ee9026..a5f63e6 100644 --- a/src/submodules/NCurses/ncurses_functions.jl +++ b/src/submodules/NCurses/ncurses_functions.jl @@ -56,6 +56,13 @@ end for (f, r, v, j, c) in ( + ( + :beep, + Cint, + [], + [], + [] + ), ( :can_change_color, Cbool, @@ -65,7 +72,7 @@ for (f, r, v, j, c) in ), ( :cbreak, - Cvoid, + Cint, [], [], [] @@ -91,6 +98,13 @@ for (f, r, v, j, c) in [], [] ), + ( + :def_prog_mode, + Cint, + [], + [], + [] + ), ( :delwin, Cvoid, @@ -168,6 +182,13 @@ for (f, r, v, j, c) in ["Ptr{WINDOW}"], ["Ptr{WINDOW}"] ), + ( + :getmouse, + Cint, + ["event"], + ["Ptr{MEVENT}"], + ["Ptr{MEVENT}"] + ), ( :has_colors, Cbool, @@ -175,6 +196,13 @@ for (f, r, v, j, c) in [], [] ), + ( + :winch, + Cint, + ["win"], + ["Ptr{WINDOW}"], + ["Ptr{WINDOW}"] + ), ( :initscr, Ptr{WINDOW}, @@ -197,11 +225,11 @@ for (f, r, v, j, c) in ["Ptr{WINDOW}", "Cuchar"] ), ( - :scrollok, - Cvoid, - ["win", "bf"], - ["Ptr{WINDOW}", "Bool"], - ["Ptr{WINDOW}", "Cuchar"] + :mousemask, + Culong, + ["newmask", "oldmask"], + ["UInt", "Ptr{UInt}"], + ["Culong", "Ptr{Culong}"] ), ( :nodelay, @@ -224,6 +252,13 @@ for (f, r, v, j, c) in ["Ptr{WINDOW}", "Bool"], ["Ptr{WINDOW}", "Cuchar"] ), + ( + :overwrite, + Cint, + ["scr", "dest"], + ["Ptr{WINDOW}", "Ptr{WINDOW}"], + ["Ptr{WINDOW}", "Ptr{WINDOW}"] + ), ( :refresh, Cvoid, @@ -231,6 +266,20 @@ for (f, r, v, j, c) in [], [] ), + ( + :reset_prog_mode, + Cint, + [], + [], + [] + ), + ( + :scrollok, + Cvoid, + ["win", "bf"], + ["Ptr{WINDOW}", "Bool"], + ["Ptr{WINDOW}", "Cuchar"] + ), ( :start_color, Cint, @@ -361,6 +410,13 @@ for (f, r, v, j, c) in ["Ptr{WINDOW}", ["T" for _ = 1:4]...], ["Ptr{WINDOW}", ["Cint" for _ = 1:4]...] ), + ( + :halfdelay, + Cint, + ["tenths"], + ["T"], + ["Cint"] + ), ( :init_color, Cint, @@ -696,6 +752,20 @@ for (f, r, v, j, c) in ["T"], ["Cstring"] ), + ( + :waddstr, + Cvoid, + ["win", "str"], + ["Ptr{WINDOW}", "T"], + ["Ptr{WINDOW}", "Cstring"] + ), + ( + :addstr, + Cvoid, + ["str"], + ["T"], + ["Cstring"] + ), ) fb = Meta.quot(f) diff --git a/src/submodules/NCurses/ncurses_keys.jl b/src/submodules/NCurses/ncurses_keys.jl new file mode 100644 index 0000000..75ae246 --- /dev/null +++ b/src/submodules/NCurses/ncurses_keys.jl @@ -0,0 +1,47 @@ +## Description ################################################################# +# +# This file contains the definition of keys in libncurses. +# +################################################################################ + +KEY_CTRL(c::Char)=UInt8(c-'A'+1) +const KEY_DOWN=0o402 +const KEY_LEFT=0o404 +const KEY_UP=0o403 +const KEY_RIGHT=0o405 +const KEY_HOME=0o406 +const KEY_BACKSPACE=0o407 +KEY_F(i)=0o410+i +const KEY_DC=0o512 +const KEY_IC=0o513 +const KEY_SF=0o520 +const KEY_SR=0o521 +const KEY_NPAGE=0o522 +const KEY_PPAGE=0o523 +const KEY_ENTER=0o527 +const KEY_BTAB=0o541 +const KEY_BEG=0o542 +const KEY_END=0o550 +const KEY_SDELETE=0o577 +const KEY_SEND=0o602 +const KEY_SHOME=0o607 +const KEY_SIC=0o610 +const KEY_SLEFT=0o611 +const KEY_SNEXT=0o614 +const KEY_SPREVIOUS=0o616 +const KEY_SRIGHT=0o622 +const KEY_MOUSE=0o631 +KEY_ALT(c::Char)=0o641+c-'A' +const KEY_CTRL_DC=0o1020 +const KEY_CTRL_DOWN=0o1026 +const KEY_CTRL_END=0o1033 +const KEY_CTRL_LEFT=0o1052 +const KEY_CTRL_HOME=0o1040 +const KEY_CTRL_NPAGE=0o1057 +const KEY_CTRL_PPAGE=0o1064 +const KEY_CTRL_RIGHT=0o1071 +const KEY_CTRL_UP=0o1077 +const KEY_PAD_PLUS=0o1107 +const KEY_PAD_DIV=0o1111 +const KEY_PAD_TIMES=0o1113 +const KEY_PAD_MINUS=0o1114 diff --git a/src/submodules/NCurses/ncurses_mouse.jl b/src/submodules/NCurses/ncurses_mouse.jl new file mode 100644 index 0000000..82b9aaa --- /dev/null +++ b/src/submodules/NCurses/ncurses_mouse.jl @@ -0,0 +1,52 @@ +## Description ################################################################# +# +# This file contains the definition of mouse events in libncurses. +# +################################################################################ + +""" + struct MEVENT + +represents a mouse event + +""" +mutable struct MEVENT + id::Cshort + x::Cint + y::Cint + z::Cint + bstate::Culong +end + +NCURSES_MOUSE_MASK(b,m)=m<<((b-1)*6) +const NCURSES_BUTTON_RELEASED=1 +const NCURSES_BUTTON_PRESSED=2 +const NCURSES_BUTTON_CLICKED=4 +const NCURSES_DOUBLE_CLICKED=8 + +const BUTTON1_RELEASED= NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED) +const BUTTON1_PRESSED= NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED) +const BUTTON1_CLICKED= NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_CLICKED) +const BUTTON1_DOUBLE_CLICKED= NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED) +const BUTTON2_RELEASED= NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_RELEASED) +const BUTTON2_PRESSED= NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED) +const BUTTON2_CLICKED= NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_CLICKED) +const BUTTON2_DOUBLE_CLICKED= NCURSES_MOUSE_MASK(2, NCURSES_DOUBLE_CLICKED) +const BUTTON3_RELEASED= NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_RELEASED) +const BUTTON3_PRESSED= NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_PRESSED) +const BUTTON3_CLICKED= NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_CLICKED) +const BUTTON3_DOUBLE_CLICKED= NCURSES_MOUSE_MASK(3, NCURSES_DOUBLE_CLICKED) +const REPORT_MOUSE_POSITION= NCURSES_MOUSE_MASK(6, 10) +const ALL_MOUSE_EVENTS= REPORT_MOUSE_POSITION-1 + +# two useful methods which also show the proper use of +# getmouse and mousemask + +function getmouse() + me=MEVENT(1,0,0,0,0) + getmouse(Ptr{MEVENT}(pointer_from_objref(me))) + me +end + +mousemask(x::Integer)=mousemask(UInt(x),Ptr{UInt}(C_NULL)) + diff --git a/src/submodules/NCurses/types.jl b/src/submodules/NCurses/types.jl index facd9dc..f331d68 100644 --- a/src/submodules/NCurses/types.jl +++ b/src/submodules/NCurses/types.jl @@ -44,6 +44,8 @@ const ncurses = NCURSES() include("ncurses_types.jl") include("ncurses_attributes.jl") +include("ncurses_keys.jl") +include("ncurses_mouse.jl") include("./form/form_types.jl") include("./menu/menu_types.jl") include("./panel/panel_types.jl")