Skip to content

Commit

Permalink
ref #34 : add mouse wheel support for ncurses
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Nov 6, 2021
1 parent bd5a9f0 commit 35cab31
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/imtui-impl-ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ bool ImTui_ImplNcurses_NewFrame() {
static unsigned long mstate = 0;
static char input[3];

int wheel = 0;
input[2] = 0;

auto & keysDown = ImGui::GetIO().KeysDown;
Expand All @@ -203,14 +204,25 @@ bool ImTui_ImplNcurses_NewFrame() {
} else if (c == KEY_MOUSE) {
MEVENT event;
if (getmouse(&event) == OK) {
mstate = event.bstate;

if (mstate == 0x00080000) {
wheel = 1;
}

if (mstate == 0x08000000 && mx == event.x && my == event.y) {
wheel = -1;
}

mx = event.x;
my = event.y;
mstate = event.bstate;

if ((mstate & 0x000f) == 0x0002) lbut = 1;
if ((mstate & 0x000f) == 0x0001) lbut = 0;
if ((mstate & 0xf000) == 0x2000) rbut = 1;
if ((mstate & 0xf000) == 0x1000) rbut = 0;
//printf("mstate = 0x%016lx\n", mstate);

//printf("mstate = 0x%016lx id = %d, x = %d, y = %d, z = %d\n", mstate, event.id, event.x, event.y, event.z);
ImGui::GetIO().KeyCtrl |= ((mstate & 0x0F000000) == 0x01000000);
}
} else {
Expand Down Expand Up @@ -266,6 +278,7 @@ bool ImTui_ImplNcurses_NewFrame() {

ImGui::GetIO().MousePos.x = mx;
ImGui::GetIO().MousePos.y = my;
ImGui::GetIO().MouseWheel = wheel;
ImGui::GetIO().MouseDown[0] = lbut;
ImGui::GetIO().MouseDown[1] = rbut;

Expand Down

0 comments on commit 35cab31

Please sign in to comment.