📄 ncurses_functions.c
字号:
Pushes mouse event to queue */PHP_FUNCTION(ncurses_ungetmouse){ zval **arg, **pvalue; MEVENT mevent; ulong retval; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE){ WRONG_PARAM_COUNT; } IS_NCURSES_INITIALIZED(); if (Z_TYPE_PP(arg) != IS_ARRAY){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected mevent as array"); RETURN_FALSE; } if (zend_hash_find(Z_ARRVAL_PP(arg), "id", sizeof("id"), (void **) &pvalue)== SUCCESS) { convert_to_long_ex(pvalue); mevent.id = Z_LVAL_PP(pvalue); } if (zend_hash_find(Z_ARRVAL_PP(arg), "x", sizeof("x"), (void **) &pvalue)== SUCCESS) { convert_to_long_ex(pvalue); mevent.x = Z_LVAL_PP(pvalue); } if (zend_hash_find(Z_ARRVAL_PP(arg), "y", sizeof("y"), (void **) &pvalue)== SUCCESS) { convert_to_long_ex(pvalue); mevent.y = Z_LVAL_PP(pvalue); } if (zend_hash_find(Z_ARRVAL_PP(arg), "z", sizeof("z"), (void **) &pvalue)== SUCCESS) { convert_to_long_ex(pvalue); mevent.z = Z_LVAL_PP(pvalue); } if (zend_hash_find(Z_ARRVAL_PP(arg), "mmask", sizeof("mmask"), (void **) &pvalue)== SUCCESS) { convert_to_long_ex(pvalue); mevent.bstate = Z_LVAL_PP(pvalue); } retval = ungetmouse(&mevent); RETURN_LONG(retval);}/* }}} *//* {{{ proto bool ncurses_mouse_trafo(int y, int x, bool toscreen) Transforms coordinates */PHP_FUNCTION(ncurses_mouse_trafo){ zval **x, **y, **toscreen; int nx, ny, retval; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &y, &x, &toscreen) == FAILURE){ WRONG_PARAM_COUNT; } IS_NCURSES_INITIALIZED(); convert_to_long_ex(x); convert_to_long_ex(y); convert_to_boolean_ex(toscreen); ny = Z_LVAL_PP(y); nx = Z_LVAL_PP(x); retval = mouse_trafo (&ny, &nx, Z_LVAL_PP(toscreen)); Z_LVAL_PP(y) = ny; Z_LVAL_PP(x) = nx; RETURN_BOOL(retval);}/* }}} *//* {{{ proto bool ncurses_wmouse_trafo(resource window, int y, int x, bool toscreen) Transforms window/stdscr coordinates */PHP_FUNCTION(ncurses_wmouse_trafo){ zval **handle, **x, **y, **toscreen; int nx, ny, retval; WINDOW **win; if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &handle, &y, &x, &toscreen) == FAILURE){ WRONG_PARAM_COUNT; } FETCH_WINRES(win, handle); convert_to_long_ex(x); convert_to_long_ex(y); convert_to_boolean_ex(toscreen); ny = Z_LVAL_PP(y); nx = Z_LVAL_PP(x); retval = wmouse_trafo (*win, &ny, &nx, Z_LVAL_PP(toscreen)); Z_LVAL_PP(y) = ny; Z_LVAL_PP(x) = nx; RETURN_BOOL(retval);}/* }}} *//* {{{ proto void ncurses_getyx(resource window, int &y, int &x) Returns the current cursor position for a window */PHP_FUNCTION(ncurses_getyx){ zval **handle, **x, **y; WINDOW **win; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &handle, &y, &x) == FAILURE){ WRONG_PARAM_COUNT; } FETCH_WINRES(win, handle); convert_to_long_ex(x); convert_to_long_ex(y); getyx(*win, Z_LVAL_PP(y), Z_LVAL_PP(x));}/* }}} *//* {{{ proto void ncurses_getmaxyx(resource window, int &y, int &x) Returns the size of a window */PHP_FUNCTION(ncurses_getmaxyx){ zval **handle, **x, **y; WINDOW **win; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &handle, &y, &x) == FAILURE){ WRONG_PARAM_COUNT; } FETCH_WINRES(win, handle); convert_to_long_ex(x); convert_to_long_ex(y); getmaxyx(*win, Z_LVAL_PP(y), Z_LVAL_PP(x));}/* }}} *//* {{{ proto int ncurses_wmove(resource window, int y, int x) Moves windows output position */PHP_FUNCTION(ncurses_wmove){ zval **handle, **x, **y; WINDOW **win; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &handle, &y, &x) == FAILURE){ WRONG_PARAM_COUNT; } FETCH_WINRES(win, handle); convert_to_long_ex(x); convert_to_long_ex(y); RETURN_LONG(wmove(*win, Z_LVAL_PP(y), Z_LVAL_PP(x)));}/* }}} *//* {{{ proto int ncurses_keypad(resource window, bool bf) Turns keypad on or off */PHP_FUNCTION(ncurses_keypad){ zval **handle, **bf; WINDOW **win; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &handle, &bf) == FAILURE){ WRONG_PARAM_COUNT; } FETCH_WINRES(win, handle); convert_to_long_ex(bf); RETURN_LONG(keypad(*win, Z_LVAL_PP(bf)));}/* }}} *//* {{{ proto int ncurses_wcolor_set(resource window, int color_pair) Sets windows color pairings */PHP_FUNCTION(ncurses_wcolor_set){ zval **handle, **color_pair; WINDOW **win;#ifdef HAVE_NCURSES_COLOR_SET if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2,&handle, &color_pair) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); convert_to_long_ex(color_pair); RETURN_LONG(wcolor_set(*win, Z_LVAL_PP(color_pair), 0));#else php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in this build"); RETURN_FALSE;#endif}/* }}} *//* {{{ proto int ncurses_wclear(resource window) Clears window */PHP_FUNCTION(ncurses_wclear){ zval **handle; WINDOW **win; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); RETURN_LONG(wclear(*win));}/* }}} *//* {{{ proto int ncurses_wnoutrefresh(resource window) Copies window to virtual screen */PHP_FUNCTION(ncurses_wnoutrefresh){ zval **handle; WINDOW **win; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); RETURN_LONG(wnoutrefresh(*win));}/* }}} *//* {{{ proto int ncurses_waddstr(resource window, string str [, int n]) Outputs text at current postion in window */PHP_FUNCTION(ncurses_waddstr){ zval **handle, **str, **n; WINDOW **win; if (ZEND_NUM_ARGS() == 2) { if (zend_get_parameters_ex(2, &handle, &str) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); RETURN_LONG(waddstr(*win, Z_STRVAL_PP(str))); } else if (ZEND_NUM_ARGS() == 3) { if (zend_get_parameters_ex(3, &handle, &str, &n) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); RETURN_LONG(waddnstr(*win, Z_STRVAL_PP(str), Z_LVAL_PP(n))); } else WRONG_PARAM_COUNT;}/* }}} *//* {{{ proto int ncurses_wgetch(resource window) Reads a character from keyboard (window) */PHP_FUNCTION(ncurses_wgetch){ zval **handle; WINDOW **win; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); RETURN_LONG(wgetch(*win));}/* }}} *//* {{{ proto int wattroff(resource window, int attrs) Turns off attributes for a window */PHP_FUNCTION(ncurses_wattroff){ zval *handle; WINDOW **win; long attrs; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == FAILURE) { return; } FETCH_WINRES(win, &handle); RETURN_LONG(wattroff(*win, attrs));}/* }}} *//* {{{ proto int wattron(resource window, int attrs) Turns on attributes for a window */PHP_FUNCTION(ncurses_wattron){ zval *handle; WINDOW **win; long attrs; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == FAILURE) { return; } FETCH_WINRES(win, &handle); RETURN_LONG(wattron(*win, attrs));}/* }}} *//* {{{ proto int wattrset(resource window, int attrs) Set the attributes for a window */PHP_FUNCTION(ncurses_wattrset){ zval *handle; WINDOW **win; long attrs; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &handle, &attrs) == FAILURE) { return; } FETCH_WINRES(win, &handle); RETURN_LONG(wattrset(*win, attrs));}/* }}} *//* {{{ proto int wstandend(resource window) End standout mode for a window */PHP_FUNCTION(ncurses_wstandend){ zval *handle; WINDOW **win; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &handle) == FAILURE) { return; } FETCH_WINRES(win, &handle); RETURN_LONG(wstandend(*win));}/* }}} *//* {{{ proto int wstandout(resource window) Enter standout mode for a window */PHP_FUNCTION(ncurses_wstandout){ zval *handle; WINDOW **win; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &handle) == FAILURE) { return; } FETCH_WINRES(win, &handle); RETURN_LONG(wstandout(*win));}/* }}} */#if HAVE_NCURSES_PANEL/* {{{ proto resource ncurses_new_panel(resource window) Create a new panel and associate it with window */PHP_FUNCTION(ncurses_new_panel){ zval **handle; WINDOW **win; PANEL **panel; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_WINRES(win, handle); panel = (PANEL **)emalloc(sizeof(PANEL *)); *panel = new_panel(*win); if (*panel == NULL) { efree(panel); RETURN_FALSE; } else { long id = ZEND_REGISTER_RESOURCE(return_value, panel, le_ncurses_panels); set_panel_userptr(*panel, (void*)id); }}/* }}} *//* {{{ proto int ncurses_del_panel(resource panel) Remove panel from the stack and delete it (but not the associated window) */PHP_FUNCTION(ncurses_del_panel){ zval **handle; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; zend_list_delete(Z_RESVAL_PP(handle)); RETURN_TRUE;}/* }}} *//* {{{ proto int ncurses_hide_panel(resource panel) Remove panel from the stack, making it invisible */PHP_FUNCTION(ncurses_hide_panel){ zval **handle; PANEL **panel; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_PANEL(panel, handle); RETURN_LONG(hide_panel(*panel));}/* }}} *//* {{{ proto int ncurses_show_panel(resource panel) Places an invisible panel on top of the stack, making it visible */PHP_FUNCTION(ncurses_show_panel){ zval **handle; PANEL **panel; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_PANEL(panel, handle); RETURN_LONG(show_panel(*panel));}/* }}} *//* {{{ proto int ncurses_top_panel(resource panel) Moves a visible panel to the top of the stack */PHP_FUNCTION(ncurses_top_panel){ zval **handle; PANEL **panel; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_PANEL(panel, handle); RETURN_LONG(top_panel(*panel));}/* }}} *//* {{{ proto int ncurses_bottom_panel(resource panel) Moves a visible panel to the bottom of the stack */PHP_FUNCTION(ncurses_bottom_panel){ zval **handle; PANEL **panel; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) WRONG_PARAM_COUNT; FETCH_PANEL(panel, handle); RETURN_LONG(bottom_panel(*panel));}/* }}} *//* {{{ proto int ncurses_move_panel(resource panel, int startx, int starty) Moves a panel so that it's upper-left corner is at [startx, starty] */PHP_FUNCTION(ncurses_move_panel){ zval *handle; PANEL **panel; long startx, starty; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &handle, &startx, &starty)) { return; } FETCH_PANEL(panel, &handle); RETURN_LONG(move_panel(*panel, startx, starty));}/* }}} *//* {{{ proto int ncurses_replace_panel(resource panel, resource window) Replaces the window associated with panel */PHP_FUNCTION(ncurses_replace_panel){ zval *phandle, *whandle; PANEL **panel; WINDOW **window; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &phandle, &whandle)) { return; } FETCH_PANEL(panel, &phandle); FETCH_WINRES(window, &whandle); RETURN_LONG(replace_panel(*panel, *window));}/* }}} *//* {{{ proto int ncurses_panel_above(resource panel) Returns the panel above panel. If panel is null, returns the bottom panel in the stack */PHP_FUNCTION(ncurses_panel_above){ zval *phandle = NULL; PANEL **panel; PANEL *above; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r!", &phandle)) { return; } if (phandle) { FETCH_PANEL(panel, &phandle); above = panel_above(*panel); } else { above = panel_above((PANEL *)0); } if (above) { long id = (long)panel_userptr(above); zend_list_addref(id); RETURN_RESOURCE(id); } else { RETURN_FALSE; }}/* }}} *//* {{{ proto int ncurses_panel_below(resource panel) Returns the panel below panel. If panel is null, returns the top panel in the stack */PHP_FUNCTION(ncurses_panel_below){ zval *phandle = NULL; PANEL **panel; PANEL *below; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r!", &phandle)) { return; } if (phandle) { FETCH_PANEL(panel, &phandle); below = panel_below(*panel); } else { below = panel_below((PANEL *)0); } if (below) { long id = (long)panel_userptr(below); zend_list_addref(id); RETURN_RESOURCE(id); } else { RETURN_FALSE; }}/* }}} *//* {{{ proto int ncurses_panel_window(resource panel) Returns the window associated with panel */PHP_FUNCTION(ncurses_panel_window){ zval *phandle = NULL; PANEL **panel; WINDOW **win; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &phandle)) { return; } FETCH_PANEL(panel, &phandle); win = (WINDOW **)emalloc(sizeof(WINDOW *)); *win = panel_window(*panel); if (*win == NULL) { efree(win); RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, win, le_ncurses_windows);}/* }}} *//* {{{ proto void ncurses_update_panels(void) Refreshes the virtual screen to reflect the relations between panels in the stack. */PHP_FUNCTION(ncurses_update_panels){ if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } IS_NCURSES_INITIALIZED(); update_panels();}/* }}} */#endif /* HAVE_NCURSES_PANEL *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -