void display_markerline(NEWWIN *win, const char *msg) { char *line = (char *)calloc(1, win -> ncols + 1), *msg_use = NULL; int len = 0, len_msg = 0; if (getcurx(win -> win)) waddch(win -> win, '\n'); color_on(win, markerline_colorpair); mywattron(win -> win, A_REVERSE); memset(line, '-', win -> ncols); len_msg = asprintf(&msg_use, "%s", msg); msg_use[min(len_msg, win -> ncols)] = 0x00; len = strlen(msg_use); memcpy(&line[win -> ncols / 2 - len / 2], msg_use, len); waddstr(win -> win, line); mywattroff(win -> win, A_REVERSE); free(line); free(msg_use); color_off(win, markerline_colorpair); color_on(win, default_colorpair); }
static int lua_likwid_pinProcess(lua_State* L) { int cpuID = luaL_checknumber(L,-2); int silent = luaL_checknumber(L,-1); luaL_argcheck(L, cpuID >= 0, 1, "CPU ID must be greater or equal 0"); if (affinity_isInitialized == 0) { affinity_init(); affinity_isInitialized = 1; affinity = get_affinityDomains(); } affinity_pinProcess(cpuID); if (!silent) { #ifdef COLOR color_on(BRIGHT, COLOR); #endif printf("[likwid-pin] Main PID -> core %d - OK", cpuID); #ifdef COLOR color_reset(); #endif printf("\n"); } return 0; }
void render_bar(Rect * bar, int * step, char * chr,int color_pairs) { int i, n; int top_row = bar->left_top.row; int bottom_row = bar->right_bottom.row; int left_col = bar->left_top.col; int right_col = bar->right_bottom.col; if (right_col + *step <= RIGHTEDGE && left_col + *step >= LEFTEDGE) i = *step; else if (right_col + *step > RIGHTEDGE) i = RIGHTEDGE - right_col; else i = LEFTEDGE - left_col; bar->left_top.col += i; bar->right_bottom.col += i; left_col = bar->left_top.col; right_col = bar->right_bottom.col ; for (i = top_row; i <= bottom_row; ++i){ for (n = left_col; n <= right_col; ++n){ color_on(color_pairs); mvaddstr(i, n, chr); color_off(color_pairs); move(0, 0); } } *step = 0; }
//render the point appear in the next position //p(col + vcol, row + vrow) and make sure this does't collide with borders void render_point(Point * p, int * vcol, int * vrow,char * chr, int color_pairs) { int i, r, c; c = *vcol; r = *vrow; p->col += c; if (p->col <= LEFTEDGE){ p->col = LEFTEDGE; *vcol = -c; } if (p->col >= RIGHTEDGE){ p->col = RIGHTEDGE; *vcol = -c; } p->row += r; if (p->row <= TOP){ p->row = TOP; *vrow = -r; } if (p->row >= BOTTOM){ p->row = BOTTOM; *vrow = 0; *vcol = 0; printw("GAMEOVER!!!!!!!"); } color_on(color_pairs); mvaddstr(p->row, p->col, chr); color_off(color_pairs); move(0,0); }
/* * 显示登录界面 */ void show_login_window() { clear_win(); move_to(0, 0); printf("┌────────────────────────────────────┐\n"); printf("│ 图书销售系统 │\n"); printf("│ ──────────── │\n"); printf("│ │\n"); printf("│ "); color_on(INVERSE, BLACK, WHITE); printf("┌───────────────────┐ "); color_off(); printf(" │\n"); printf("│ "); color_on(INVERSE, BLACK, WHITE); printf("│ 用户名: │ "); color_off(); printf(" │\n"); printf("│ "); color_on(INVERSE, BLACK, WHITE); printf("│ 密 码: │ "); color_off(); printf(" │\n"); printf("│ "); color_on(INVERSE, BLACK, WHITE); printf("└───────────────────┘ "); color_off(); printf(" │\n"); printf("│ │\n"); printf("│ │\n"); printf("│ │\n"); printf("│ │\n"); printf("│ 时间: 按TAB键退出 │\n"); printf("└────────────────────────────────────┘\n"); }
/* * 打印错误信息 */ void print_err(int status) { KEY_T key; if (status == LOGIN_ERROR_INCORRECT) { move_to(7, 10); color_on(INVERSE, WHITE, RED); printf("用户名或密码错误!"); move_to(7, 11); printf("请按任意键继续"); color_off(); }else{ move_to(7, 10); color_on(INVERSE, WHITE, RED); printf("输入不能为空!"); move_to(7, 11); printf("请按任意键继续"); color_off(); } getch(); }
void render_piles(Piles * p, char * chr, int color_pairs) { int i, n; int * b; for (i = 0; i < p->height; ++i){ for (n = 0; n < p->width; ++n){ if (0 != p->point[i][n]){ color_on(color_pairs); mvaddstr(i + p->left_top.row,n + p->left_top.col,chr); color_off(color_pairs); move(0,0); } } } }
/* * 显示商品列表 */ static void show_list() { int i, cnt; list_t *list; line_item_t *item; list = &cur_sale->item_list; /* * 遍历商品列表 */ i = cur_page * ITEM_PER_PAGE; for (cnt = 0; i < list_len(list) && cnt < ITEM_PER_PAGE; i++,cnt++) { list_get(list, i, &item); move_to(2, 8+cnt); printf(" "); if (cnt == item_selected) { color_on(INVERSE, BLACK, WHITE); } printf("%3d%6s %-6s%6.2lf%5.1lf%4d %6.2lf", cnt, item->code, item->name, item->price, item->discount, item->count, item->total); if (cnt == item_selected) { color_off(); } } }
void draw_border(int top, int bottom, int left, int right, int color_pairs) { int i; color_on(color_pairs); for(i = left; i <= right; i++){ move(top - 1, i); addstr(" "); } for(i = left; i <= right; i++){ move(bottom + 1, i); addstr(" "); } for(i = top - 1; i <= bottom + 1; i++){ move(i, left - 1); addstr(" "); } for(i = top - 1; i <= bottom + 1; i++){ move(i, right + 1); addstr(" "); } color_off(color_pairs); }
void BoardPrint(struct board_t *board) { clear(); int i, j; for (i = BOARD_ROWS - 1; i >= 0; --i) { for (j = 0; j < BOARD_COLS; ++j) { move(startY + BOARD_ROWS - i - 1, startX + 2*j); color_on(board->a[i][j]); addch(board->a[i][j]); color_off(board->a[i][j]); } } for (j = 0; j < BOARD_COLS; ++j) { move(startY + BOARD_ROWS, startX + 2*j); addch(j + '1'); } move(startY + BOARD_ROWS + 1, startX); refresh(); return; }
int selection_box(void **list, char *needs_mark, int nlines, selbox_type_t type, int what_help, char *heading) { NEWWIN *mywin; int wlines = min(nlines, (max_y - 1) - 4); int total_win_size = wlines + 4; int win_width = max(32, max_x / 3); int wcols = win_width - 4; int pos = 0, ppos = -1, offs = 0, poffs = -1; int loop = 0, sel = -1; char first = 1; char *dummy = (char *)mymalloc(wcols + 1); int path_max = find_path_max(); char *selstr = (char *)mymalloc(path_max + 1), selfound = 0; selstr[0] = 0x00; mywin = create_popup(total_win_size, win_width); for(;;) { int c; /* draw list */ if (pos != ppos) { int entries_left = (nlines - pos); werase(mywin -> win); if (heading) win_header(mywin, heading); else if (type == SEL_WIN) win_header(mywin, "Select window"); else if (type == SEL_SUBWIN) win_header(mywin, "Select subwindow"); else if (type == SEL_FILES) win_header(mywin, "Select file"); else if (type == SEL_CSCHEME) win_header(mywin, "Select color scheme"); else if (type == SEL_HISTORY) win_header(mywin, "Select string from history"); for(loop=0; loop<min(entries_left, wlines); loop++) { char invert = generate_string(dummy, list, type, wcols, loop + pos); if (loop == offs) ui_inverse_on(mywin); if (invert) color_on(mywin, find_colorpair(COLOR_YELLOW, -1, 0)); if (needs_mark && needs_mark[loop + pos]) mvwprintw(mywin -> win, loop + 2, 1, "*"); mvwprintw(mywin -> win, loop + 2, 2, "%s", dummy); if (invert) color_off(mywin, find_colorpair(COLOR_YELLOW, -1, 0)); if (loop == offs) ui_inverse_off(mywin); } draw_border(mywin); ppos = pos; poffs = offs; } else if (poffs != offs) { int yellow_cp = find_colorpair(COLOR_YELLOW, -1, 0); char invert = generate_string(dummy, list, type, wcols, poffs + pos); if (invert) color_on(mywin, yellow_cp); mvwprintw(mywin -> win, poffs + 2, 2, "%s", dummy); if (invert) color_off(mywin, yellow_cp); invert = generate_string(dummy, list, type, wcols, offs + pos); ui_inverse_on(mywin); if (invert) color_on(mywin, yellow_cp); if (needs_mark && needs_mark[offs + pos]) mvwprintw(mywin -> win, loop + 2, 1, "*"); mvwprintw(mywin -> win, offs + 2, 2, "%s", dummy); if (invert) color_off(mywin, yellow_cp); ui_inverse_off(mywin); poffs = offs; } if (first) { first = 0; color_on(mywin, find_colorpair(COLOR_GREEN, -1, 0)); mvwprintw(mywin -> win, total_win_size - 2, 2, "Press ^G to abort"); color_off(mywin, find_colorpair(COLOR_GREEN, -1, 0)); } else { int loop, len = strlen(selstr); for(loop=0; loop<wcols; loop++) mvwprintw(mywin -> win, total_win_size - 2, 1 + loop, " "); if (!selfound) color_on(mywin, find_colorpair(COLOR_RED, -1, 0)); mvwprintw(mywin -> win, total_win_size - 2, 1, "%s", &selstr[max(0, len - wcols)]); if (!selfound) color_off(mywin, find_colorpair(COLOR_RED, -1, 0)); } mydoupdate(); c = wait_for_keypress(what_help, 0, mywin, 1); if (c == KEY_UP) { if ((offs + pos) > 0) { if (offs) offs--; else pos--; } else { wrong_key(); } } else if (c == KEY_DOWN) { if ((pos + offs) < (nlines-1)) { if (offs < (wlines-1)) offs++; else pos++; } else { wrong_key(); } } else if (c == KEY_NPAGE) { if ((pos + offs) < (nlines - 1)) { pos += min(wlines, (nlines - 1) - (pos + offs)); } else { wrong_key(); } } else if (c == KEY_PPAGE) { if ((pos + offs - wlines) >= 0) { if (pos > wlines) { pos -= wlines; } else { pos -= (wlines - offs); offs = 0; } } else if (offs > 0) { offs = 0; } else if (pos > 0) { pos = 0; } else { wrong_key(); } } else if (c == KEY_ENTER || c == 13 || c == 10) { sel = pos + offs; break; } else if (c == abort_key || c == -1) { break; } else if ((c > 31 && c != 127) || (c == KEY_BACKSPACE)) { int index, curlen; curlen = strlen(selstr); if (c == KEY_BACKSPACE) { if (curlen > 0) selstr[curlen - 1] = 0x00; else wrong_key(); } else if (curlen < path_max) { selstr[curlen] = c; selstr[curlen + 1] = 0x00; } else wrong_key(); curlen = strlen(selstr); if (curlen > 0) { index = find_sb_string(list, type, nlines, selstr); if (index != -1) { ppos = -1; sel = pos = index; selfound = 1; } else { selfound = 0; } } } else { wrong_key(); } } delete_popup(mywin); myfree(dummy); myfree(selstr); return sel; }
void text_box_x11(textbox *t) { int i; float x,y, sx, sy; int len, xlen, cwidth, cheight, ascent; XWindow *xw; XFontStruct *font; if(!t || t->n == 0) { return; } len = 0; cmgdm.ihjust = 1; cmgdm.ivjust = 1; xw = plot_window( CURRENT ); xwindow_font_load(xw); if(xw->font->type == XFONT_TYPE_SOFTWARE) { font = NULL; /* All relative lengths scaled by window width */ cwidth = view_to_x11_x( cmgdm.twidth, xw ); cheight = view_to_x11_x( cmgdm.thgt, xw ); ascent = view_to_x11_x( cmgdm.thgt * 1.10, xw ); } if(xw->font->type == XFONT_TYPE_CORE) { font = xw->font->font_core; cwidth = font->max_bounds.width; cheight = font->ascent + font->descent; ascent = font->ascent; } #ifdef HAVE_XFT else if(xw->font->type == XFONT_TYPE_XFT) { cwidth = xw->font->font_xft->max_advance_width; cheight = xw->font->font_xft->ascent + xw->font->font_xft->descent; ascent = xw->font->font_xft->ascent; } #endif /* HAVE_XFT */ x = view_to_x11_x(t->x, xw); y = view_to_x11_y(t->y, xw); /* Adjust for Text Length */ if(t->location & TEXT_BOX_RIGHT) { for(i = 0; i < t->n; i++) { xlen = xwindow_text_width(xw, t->text[i]); if(xlen > len) { len = xlen; } } x = x - len; } /* Adjust for Text Height */ if(t->location & TEXT_BOX_LOWER) { y -= cheight * (t->n - 1); } else { y += cheight; } if(t->use_style && t->location & TEXT_BOX_LEFT) { x += 0.5 * cwidth + TEXTBOX_LINE_LENGTH_PIXELS; } /* Show Text in correct color */ for(i = 0; i < t->n; i++) { setcolor3(t->color[i]); XSetForeground(DISPLAY(xw), xw->gc, color3); if(t->text[i]) { xwindow_draw_string(xw, t->text[i], (int)x, (int)y); } sx = x11_to_view_x(x, xw); sy = x11_to_view_y(y, xw); if(t->use_style) { text_box_line(&x11, sx, sy, t->width[i], t->style[i], cwidth / (float)xw->width, ascent / (float)xw->width); } if(t->use_symbol) { text_box_symbol(&x11, sx, sy, t->symbol[i], t->use_style, cwidth / (float)xw->width, ascent / (float)xw->width); } y += cheight; } /* Return Color for Skeleton */ setcolor3( ( color_on() ) ? color_skeleton() : color_foreground_default() ); }