MCPcopy Create free account
hub / github.com/NetHack/NetHack / curses_get_mouse

Function curses_get_mouse

win/curses/cursmisc.c:934–976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

932movement. */
933
934int
935curses_get_mouse(coordxy *mousex, coordxy *mousey, int *mod)
936{
937 int key = '\033';
938
939#ifdef NCURSES_MOUSE_VERSION
940 MEVENT event;
941
942 if (getmouse(&event) == OK) { /* True if user has clicked */
943 if ((event.bstate & MOUSEBUTTONS) != 0) {
944 /*
945 * The ncurses man page documents wmouse_trafo() incorrectly.
946 * It says that last argument 'TRUE' translates from screen
947 * to window and 'FALSE' translates from window to screen,
948 * but those are backwards. The mouse_trafo() macro calls
949 * last argument 'to_screen', suggesting that the backwards
950 * implementation is the intended behavior and the man page
951 * is describing it wrong.
952 */
953 /* See if coords are in map window & convert coords */
954 if (wmouse_trafo(mapwin, &event.y, &event.x, FALSE)) {
955 key = '\0'; /* core uses this to detect a mouse click */
956 *mousex = event.x + 1; /* +1: screen 0..78 is map 1..79 */
957 *mousey = event.y;
958
959 if (curses_window_has_border(MAP_WIN)) {
960 (*mousex)--;
961 (*mousey)--;
962 }
963
964 *mod = ((event.bstate & (BUTTON1_CLICKED | BUTTON_CTRL))
965 == BUTTON1_CLICKED) ? CLICK_1 : CLICK_2;
966 }
967 }
968 }
969#else
970 nhUse(mousex);
971 nhUse(mousey);
972 nhUse(mod);
973#endif /* NCURSES_MOUSE_VERSION */
974
975 return key;
976}
977
978void
979curses_mouse_support(int mode) /* 0: off, 1: on, 2: alternate on */

Callers 1

curses_nh_poskeyFunction · 0.85

Calls 1

curses_window_has_borderFunction · 0.85

Tested by

no test coverage detected